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

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.6 ! misho      11:        int f, rlen, ret = 0;
1.1.2.5   misho      12:        const char *str;
1.1.2.6 ! misho      13:        size_t siz;
1.1.2.3   misho      14: 
                     15:        FTRACE(4);
                     16: 
1.1.2.6 ! misho      17:        str = cfg_getAttribute(&cfg, csSec, "size");
        !            18:        siz = strtol(str, NULL, 0);
        !            19:        if (!siz)
        !            20:                return -1;
1.1.2.5   misho      21:        str = cfg_getAttribute(&cfg, csSec, "drive");
                     22:        if (!str) {
                     23:                printf("Error:: drive not found!\n");
                     24:                return -1;
                     25:        }
                     26: 
                     27:        f = open(str, mode);
1.1.2.3   misho      28:        if (f == -1) {
1.1.2.5   misho      29:                printf("Error:: Can't access u-boot-env device %s\n", str);
1.1.2.3   misho      30:                return -1;
                     31:        }
                     32: 
                     33:        if (mode & O_RDWR) {
1.1.2.6 ! misho      34:                rlen = write(f, env, siz);
        !            35:                if (rlen != siz)
        !            36:                        printf("Error:: written %d bytes != %d\n", rlen, siz);
        !            37:                else
        !            38:                        VERB(3) printf("Written %d bytes\n", rlen);
        !            39:                lseek(f, 0, SEEK_SET);
1.1.2.3   misho      40:        }
                     41: 
1.1.2.6 ! misho      42:        rlen = read(f, env, siz);
        !            43:        if (rlen != siz)
        !            44:                printf("Error:: readed %d bytes != %d\n", rlen, siz);
        !            45:        else
        !            46:                VERB(3) printf("Readed %d bytes\n", rlen);
        !            47: 
1.1.2.3   misho      48:        close(f);
                     49:        return ret;
                     50: }
                     51: 
1.1.2.4   misho      52: int
                     53: ub_load(const char *csSec)
                     54: {
                     55:        const char *str;
                     56:        size_t siz;
                     57: 
1.1.2.5   misho      58:        FTRACE(4);
                     59: 
1.1.2.4   misho      60:        str = cfg_getAttribute(&cfg, csSec, "size");
                     61:        siz = strtol(str, NULL, 0);
                     62:        if (!siz)
                     63:                return -1;
                     64: 
                     65:        env = e_malloc(siz);
                     66:        if (!env) {
                     67:                ELIBERR(elwix);
                     68:                return -1;
                     69:        }
                     70: 
                     71:        return 0;
                     72: }
                     73: 
                     74: void
                     75: ub_unload()
                     76: {
1.1.2.5   misho      77:        FTRACE(4);
                     78: 
1.1.2.4   misho      79:        if (env)
                     80:                e_free(env);
                     81: }
                     82: 
1.1.2.2   misho      83: const char*
1.1.2.5   misho      84: ub_getenv(const char *csSec, const char *csName)
1.1.2.2   misho      85: {
                     86:        const char *str = NULL;
                     87: 
1.1.2.3   misho      88:        FTRACE(3);
                     89: 
1.1.2.2   misho      90:        return str;
                     91: }
                     92: 
                     93: int
1.1.2.5   misho      94: ub_setenv(const char *csSec, const char *csName, const char *csValue)
1.1.2.2   misho      95: {
1.1.2.3   misho      96:        FTRACE(3);
                     97: 
1.1.2.2   misho      98:        return 0;
                     99: }

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