File:  [ELWIX - Embedded LightWeight unIX -] / embedtools / src / ub_env.c
Revision 1.1.2.6: download - view: text, annotated - select for diffs - revision graph
Tue Jan 28 22:50:37 2014 UTC (10 years, 5 months ago) by misho
Branches: tools2_0
flush io

    1: #include "global.h"
    2: #include "ub_env.h"
    3: 
    4: 
    5: env_t *env;
    6: 
    7: 
    8: static int
    9: ub_flash_io(const char *csSec, int mode)
   10: {
   11: 	int f, rlen, ret = 0;
   12: 	const char *str;
   13: 	size_t siz;
   14: 
   15: 	FTRACE(4);
   16: 
   17: 	str = cfg_getAttribute(&cfg, csSec, "size");
   18: 	siz = strtol(str, NULL, 0);
   19: 	if (!siz)
   20: 		return -1;
   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);
   28: 	if (f == -1) {
   29: 		printf("Error:: Can't access u-boot-env device %s\n", str);
   30: 		return -1;
   31: 	}
   32: 
   33: 	if (mode & O_RDWR) {
   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);
   40: 	}
   41: 
   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: 
   48: 	close(f);
   49: 	return ret;
   50: }
   51: 
   52: int
   53: ub_load(const char *csSec)
   54: {
   55: 	const char *str;
   56: 	size_t siz;
   57: 
   58: 	FTRACE(4);
   59: 
   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: {
   77: 	FTRACE(4);
   78: 
   79: 	if (env)
   80: 		e_free(env);
   81: }
   82: 
   83: const char*
   84: ub_getenv(const char *csSec, const char *csName)
   85: {
   86: 	const char *str = NULL;
   87: 
   88: 	FTRACE(3);
   89: 
   90: 	return str;
   91: }
   92: 
   93: int
   94: ub_setenv(const char *csSec, const char *csName, const char *csValue)
   95: {
   96: 	FTRACE(3);
   97: 
   98: 	return 0;
   99: }

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