/* (Re)initialize the hash table. Should be locked. */ static int BCMINITFN(nvram_rehash)(struct nvram_header *header) { char buf[] = "0xXXXXXXXX", *name, *value, *end, *eq; /* (Re)initialize hash table */ BCMINIT(nvram_free)(); /* Parse and set "name=value\0 ... \0\0" */ name = (char *) &header[1]; end = (char *) header + NVRAM_SPACE - 2; end[0] = end[1] = '\0'; for (; *name; name = value + strlen(value) + 1) { if (!(eq = strchr(name, '='))) break; *eq = '\0'; value = eq + 1; BCMINIT(_nvram_set)(name, value); *eq = '='; } /* Set special SDRAM parameters */ if (!BCMINIT(_nvram_get)("sdram_init")) { sprintf(buf, "0x%04X", (uint16)(header->crc_ver_init >> 16)); BCMINIT(_nvram_set)("sdram_init", buf); }
int BCMINITFN(nvram_unset)(const char *name) { int ret; NVRAM_LOCK(); ret = BCMINIT(_nvram_unset)(name); 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; }
/* Free all tuples. Should be locked. */ static void BCMINITFN(nvram_free)(void) { uint i; struct nvram_tuple *t, *next; /* Free hash table */ for (i = 0; i < ARRAYSIZE(BCMINIT(nvram_hash)); i++) { for (t = BCMINIT(nvram_hash)[i]; t; t = next) { next = t->next; BCMINIT(_nvram_free)(t); } BCMINIT(nvram_hash)[i] = NULL; } /* Free dead table */ for (t = nvram_dead; t; t = next) { next = t->next; BCMINIT(_nvram_free)(t); } nvram_dead = NULL; /* Indicate to per-port code that all tuples have been freed */ BCMINIT(_nvram_free)(NULL); }
/* * Search the name=value vars for a specific one and return its value. * Returns NULL if not found. */ char* getvar(char *vars, char *name) { char *s; int len; len = strlen(name); /* first look in vars[] */ for (s = vars; s && *s; ) { if ((bcmp(s, name, len) == 0) && (s[len] == '=')) return (&s[len+1]); while (*s++) ; } /* then query nvram */ return (BCMINIT(nvram_get)(name)); }
int BCMINITFN(nvram_commit)(void) { struct nvram_header *header; int ret; uint32 *src, *dst; uint i; if (!(header = (struct nvram_header *) MALLOC(NULL, NVRAM_SPACE))) { printf("nvram_commit: out of memory\n"); return -12; /* -ENOMEM */ } NVRAM_LOCK(); /* Regenerate NVRAM */ ret = BCMINIT(_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 _CFE_ if ((ret = cfe_open("flash0.nvram")) >= 0) { cfe_writeblk(ret, 0, (unsigned char *) header, header->len); cfe_close(ret); } #else if (sysFlashInit(NULL) == 0) nvWrite((unsigned short *) header, NVRAM_SPACE); #endif done: NVRAM_UNLOCK(); MFREE(NULL, header, NVRAM_SPACE); return ret; }
static bool BCMINITFN(nvram_reset)(void *sbh) { chipcregs_t *cc; char *value; uint32 watchdog = 0, gpio; uint idx, msec; idx = sb_coreidx(sbh); /* Check if we were soft reset */ if ((cc = sb_setcore(sbh, SB_CC, 0))) { watchdog = R_REG(&cc->intstatus) & CI_WDRESET; sb_setcoreidx(sbh, idx); } if (watchdog) return FALSE; value = BCMINIT(nvram_get)("reset_gpio"); if (!value) return FALSE; gpio = (uint32) bcm_atoi(value); if (gpio > 7) return FALSE; /* Setup GPIO input */ sb_gpioouten(sbh, (1 << gpio), 0); /* GPIO reset is asserted low */ for (msec = 0; msec < 5000; msec++) { if (sb_gpioin(sbh) & (1 << gpio)) return FALSE; OSL_DELAY(1000); } return TRUE; }
int BCMINITFN(nvram_init)(void *sbh) { uint idx; bool isemb; int ret; idx = sb_coreidx(sbh); if (sb_setcore(sbh, SB_CC, 0) != NULL) { flash_base = SB_FLASH2; sb_setcoreidx(sbh, idx); } else flash_base = SB_FLASH1; /* Temporarily initialize with embedded NVRAM */ nvram_header = BCMINIT(find_nvram)(TRUE, &isemb); ret = BCMINIT(_nvram_init)(); if (ret == 0) { /* Restore defaults from embedded NVRAM if button held down */ if (BCMINIT(nvram_reset)(sbh)) { return 1; } BCMINIT(_nvram_exit)(); } /* Find NVRAM */ nvram_header = BCMINIT(find_nvram)(FALSE, &isemb); ret = BCMINIT(_nvram_init)(); if (ret == 0) { /* Restore defaults if embedded NVRAM used */ if (nvram_header && isemb) { ret = 1; } } return ret; }
void BCMINITFN(nvram_exit)(void) { BCMINIT(_nvram_exit)(); }