int BCMINITFN(nvram_commit_internal)(bool nvram_corrupt) { struct nvram_header *header; int ret; uint32 *src, *dst; uint i; if (!(header = (struct nvram_header *) MALLOC(NULL, MAX_NVRAM_SPACE))) { printf("nvram_commit: out of memory\n"); return -12; /* -ENOMEM */ } NVRAM_LOCK(); /* Regenerate NVRAM */ ret = _nvram_commit(header); if (ret) goto done; src = (uint32 *) &header[1]; dst = src; for (i = sizeof(struct nvram_header); i < header->len && i < MAX_NVRAM_SPACE; i += 4) *dst++ = htol32(*src++); #ifdef _CFE_ if ((ret = cfe_open(flashdrv_nvram)) >= 0) { if (nvram_corrupt) { printf("Corrupting NVRAM...\n"); header->magic = NVRAM_INVALID_MAGIC; } cfe_writeblk(ret, 0, (unsigned char *) header, header->len); cfe_close(ret); } #else if (sysFlashInit(NULL) == 0) { /* set/write invalid MAGIC # (in case writing image fails/is interrupted) * write the NVRAM image to flash(with invalid magic) * set/write valid MAGIC # */ header->magic = NVRAM_CLEAR_MAGIC; nvWriteChars((unsigned char *)&header->magic, sizeof(header->magic)); header->magic = NVRAM_INVALID_MAGIC; nvWrite((unsigned short *) header, MAX_NVRAM_SPACE); header->magic = NVRAM_MAGIC; nvWriteChars((unsigned char *)&header->magic, sizeof(header->magic)); } #endif /* ifdef _CFE_ */ done: NVRAM_UNLOCK(); MFREE(NULL, header, MAX_NVRAM_SPACE); return ret; }
int nvram_unset(const char *name) { int ret; NVRAM_LOCK(); ret = _nvram_unset(name); NVRAM_UNLOCK(); return ret; }
int nvram_set(const char *name, const char *value) { int ret; NVRAM_LOCK(); ret = _nvram_set(name, value); NVRAM_UNLOCK(); return ret; }
int nvram_getall(char *buf, int count) { int ret; NVRAM_LOCK(); ret = _nvram_getall(buf, count); NVRAM_UNLOCK(); return ret; }
char * nvram_get(const char *name) { char *value; NVRAM_LOCK(); value = _nvram_get(name); NVRAM_UNLOCK(); return value; }
int BCMINITFN(nvram_unset)(const char *name) { int ret; NVRAM_LOCK(); ret = _nvram_unset(name); NVRAM_UNLOCK(); return ret; }
int BCMINITFN(nvram_set)(const char *name, const char *value) { int ret; NVRAM_LOCK(); ret = BCMINIT(_nvram_set)(name, value); NVRAM_UNLOCK(); return ret; }
int BCMINITFN(nvram_getall)(char *buf, int count) { int ret; NVRAM_LOCK(); ret = BCMINIT(_nvram_getall)(buf, count); NVRAM_UNLOCK(); return ret; }
char * BCMINITFN(nvram_get)(const char *name) { char *value; NVRAM_LOCK(); value = BCMINIT(_nvram_get)(name); NVRAM_UNLOCK(); return value; }
char * nvram_get(const char *name) { char *value; if (nvram_header == NULL) { return (char *)0; } NVRAM_LOCK(); value = _nvram_get(name); NVRAM_UNLOCK(); return value; }
int nvram_commit(void) { struct nvram_header *header; int ret; uint32 *src, *dst; uint i; uint32 err_addr; if (!(header = (struct nvram_header *) MALLOC(NULL, NVRAM_SPACE))) { printf("nvram_commit: out of memory\n"); return -12; } NVRAM_LOCK(); ret = _nvram_commit(header); if (ret) goto done; src = (uint32 *) &header[1]; dst = src; for (i = sizeof(struct nvram_header); i < header->len && i < NVRAM_SPACE; i += 4) *dst++ = htol32(*src++); if (sysFlashInit(NULL) == 0) { /* set/write invalid MAGIC # (in case writing image fails/is interrupted) * write the NVRAM image to flash(with invalid magic) * set/write valid MAGIC # */ header->magic = NVRAM_CLEAR_MAGIC; nvWriteChars((unsigned char *)&header->magic, sizeof(header->magic)); header->magic = NVRAM_INVALID_MAGIC; nvWrite((unsigned short *) header, NVRAM_SPACE); header->magic = NVRAM_MAGIC; nvWriteChars((unsigned char *)&header->magic, sizeof(header->magic)); } done: NVRAM_UNLOCK(); MFREE(NULL, header, NVRAM_SPACE); return ret; }
char * nvram_get(const char *name) { char *value; #ifdef __ECOS if (!kernel_initial) return NULL; #endif NVRAM_LOCK(); value = _nvram_get(name); NVRAM_UNLOCK(); return value; }
int nvram_getall(char* buf, int count) { int ret; if (nvram_header == NULL) { buf[0] = 0; return 0; } NVRAM_LOCK(); ret = _nvram_getall(buf, count); NVRAM_UNLOCK(); return ret; }
int nvram_commit(void) { struct nvram_header *header; int ret; uint32 *src, *dst; uint i; if (!(header = (struct nvram_header *) MALLOC(NVRAM_SPACE))) { printf("nvram_commit: out of memory\n"); return -12; /* -ENOMEM */ } NVRAM_LOCK(); /* Regenerate NVRAM */ ret = _nvram_commit(header); if (ret) goto done; src = (uint32 *) &header[1]; dst = src; for (i = sizeof(struct nvram_header); i < header->len && i < NVRAM_SPACE; i += 4) *dst++ = htol32(*src++); #ifdef ASUS #else #ifdef _CFE_ if ((ret = cfe_open("flash0.nvram")) >= 0) { cfe_writeblk(ret, 0, (unsigned char *) header, NVRAM_SPACE); cfe_close(ret); } #else if (flash_init((void *) FLASH_BASE, NULL) == 0) nvWrite((unsigned short *) header, NVRAM_SPACE); #endif #endif done: NVRAM_UNLOCK(); MFREE(header, NVRAM_SPACE); return ret; }
int BCMINITFN(nvram_reinit_hash)(void) { struct nvram_header *header; int ret; if (!(header = (struct nvram_header *) MALLOC(NULL, MAX_NVRAM_SPACE))) { printf("nvram_reinit_hash: out of memory\n"); return -12; /* -ENOMEM */ } NVRAM_LOCK(); /* Regenerate NVRAM */ ret = _nvram_commit(header); NVRAM_UNLOCK(); MFREE(NULL, header, MAX_NVRAM_SPACE); return ret; }
int _nvram_read(void *buf) { volatile uint32 *src, *dst; uint i; src = (uint32 *) nvram_header; dst = (uint32 *) buf; printf ("_nvram_read: source address is 0x%x 0x%x\n", src, dst); NVRAM_LOCK(); for (i=0; i< sizeof(struct nvram_header); i +=4) { *dst++ = *src++; } for (;i < nvram_header->len && i < NVRAM_SPACE; i+= 4) *dst++ = ltoh32(*src++); NVRAM_UNLOCK(); return 0; }