--- embedtools/src/ub_env.c 2014/01/28 22:37:07 1.1.2.5 +++ embedtools/src/ub_env.c 2014/01/28 22:50:37 1.1.2.6 @@ -8,11 +8,16 @@ env_t *env; static int ub_flash_io(const char *csSec, int mode) { - int f, ret = 0; + int f, rlen, ret = 0; const char *str; + size_t siz; FTRACE(4); + str = cfg_getAttribute(&cfg, csSec, "size"); + siz = strtol(str, NULL, 0); + if (!siz) + return -1; str = cfg_getAttribute(&cfg, csSec, "drive"); if (!str) { printf("Error:: drive not found!\n"); @@ -26,8 +31,19 @@ ub_flash_io(const char *csSec, int mode) } if (mode & O_RDWR) { - } else { + rlen = write(f, env, siz); + if (rlen != siz) + printf("Error:: written %d bytes != %d\n", rlen, siz); + else + VERB(3) printf("Written %d bytes\n", rlen); + lseek(f, 0, SEEK_SET); } + + rlen = read(f, env, siz); + if (rlen != siz) + printf("Error:: readed %d bytes != %d\n", rlen, siz); + else + VERB(3) printf("Readed %d bytes\n", rlen); close(f); return ret;