Annotation of embedtools/src/ub_env.c, revision 1.1.2.8

1.1.2.1   misho       1: #include "global.h"
                      2: #include "ub_env.h"
                      3: 
                      4: 
1.1.2.4   misho       5: env_t *env;
                      6: 
                      7: 
1.1.2.3   misho       8: static int
1.1.2.5   misho       9: ub_flash_io(const char *csSec, int mode)
1.1.2.3   misho      10: {
1.1.2.7   misho      11:        int f, l, rlen;
1.1.2.5   misho      12:        const char *str;
1.1.2.6   misho      13:        size_t siz;
1.1.2.7   misho      14:        ait_val_t v;
1.1.2.3   misho      15: 
                     16:        FTRACE(4);
                     17: 
1.1.2.6   misho      18:        str = cfg_getAttribute(&cfg, csSec, "size");
                     19:        siz = strtol(str, NULL, 0);
                     20:        if (!siz)
                     21:                return -1;
1.1.2.5   misho      22:        str = cfg_getAttribute(&cfg, csSec, "drive");
                     23:        if (!str) {
                     24:                printf("Error:: drive not found!\n");
                     25:                return -1;
                     26:        }
                     27: 
1.1.2.7   misho      28:        cfg_loadAttribute(&cfg, "ube", "lock", &v, UBE_LOCK);
1.1.2.8 ! misho      29:        l = open(AIT_GET_STR(&v), O_CREAT | O_EXCL | O_WRONLY, 0644);
1.1.2.7   misho      30:        if (l == -1) {
1.1.2.8 ! misho      31:                printf("Error:: Locked u-boot-env map %s\n", AIT_GET_STR(&v));
1.1.2.7   misho      32:                AIT_FREE_VAL(&v);
                     33:                return -1;
                     34:        }
                     35: 
1.1.2.5   misho      36:        f = open(str, mode);
1.1.2.3   misho      37:        if (f == -1) {
1.1.2.5   misho      38:                printf("Error:: Can't access u-boot-env device %s\n", str);
1.1.2.7   misho      39:                close(l);
                     40:                unlink(AIT_GET_STR(&v));
                     41:                AIT_FREE_VAL(&v);
1.1.2.3   misho      42:                return -1;
                     43:        }
                     44: 
                     45:        if (mode & O_RDWR) {
1.1.2.6   misho      46:                rlen = write(f, env, siz);
                     47:                if (rlen != siz)
                     48:                        printf("Error:: written %d bytes != %d\n", rlen, siz);
                     49:                else
                     50:                        VERB(3) printf("Written %d bytes\n", rlen);
                     51:                lseek(f, 0, SEEK_SET);
1.1.2.3   misho      52:        }
                     53: 
1.1.2.6   misho      54:        rlen = read(f, env, siz);
                     55:        if (rlen != siz)
                     56:                printf("Error:: readed %d bytes != %d\n", rlen, siz);
                     57:        else
                     58:                VERB(3) printf("Readed %d bytes\n", rlen);
                     59: 
1.1.2.3   misho      60:        close(f);
1.1.2.7   misho      61:        close(l);
                     62:        unlink(AIT_GET_STR(&v));
                     63:        AIT_FREE_VAL(&v);
                     64:        return 0;
1.1.2.3   misho      65: }
                     66: 
1.1.2.4   misho      67: int
                     68: ub_load(const char *csSec)
                     69: {
                     70:        const char *str;
                     71:        size_t siz;
                     72: 
1.1.2.5   misho      73:        FTRACE(4);
                     74: 
1.1.2.4   misho      75:        str = cfg_getAttribute(&cfg, csSec, "size");
                     76:        siz = strtol(str, NULL, 0);
                     77:        if (!siz)
                     78:                return -1;
                     79: 
                     80:        env = e_malloc(siz);
                     81:        if (!env) {
                     82:                ELIBERR(elwix);
                     83:                return -1;
                     84:        }
                     85: 
1.1.2.7   misho      86:        return ub_flash_io(csSec, O_RDONLY);
1.1.2.4   misho      87: }
                     88: 
                     89: void
                     90: ub_unload()
                     91: {
1.1.2.5   misho      92:        FTRACE(4);
                     93: 
1.1.2.4   misho      94:        if (env)
                     95:                e_free(env);
                     96: }
                     97: 
1.1.2.2   misho      98: const char*
1.1.2.5   misho      99: ub_getenv(const char *csSec, const char *csName)
1.1.2.2   misho     100: {
                    101:        const char *str = NULL;
                    102: 
1.1.2.3   misho     103:        FTRACE(3);
                    104: 
1.1.2.2   misho     105:        return str;
                    106: }
                    107: 
                    108: int
1.1.2.5   misho     109: ub_setenv(const char *csSec, const char *csName, const char *csValue)
1.1.2.2   misho     110: {
1.1.2.3   misho     111:        FTRACE(3);
                    112: 
1.1.2.2   misho     113:        return 0;
                    114: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>