Exemple #1
0
/* 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(nvram_hash); i++) {
		for (t = nvram_hash[i]; t; t = next) {
			next = t->next;
			_nvram_free(t);
		}
		nvram_hash[i] = NULL;
	}

	/* Free dead table */
	for (t = nvram_dead; t; t = next) {
		next = t->next;
		_nvram_free(t);
	}
	nvram_dead = NULL;

	/* Indicate to per-port code that all tuples have been freed */
	_nvram_free(NULL);
}
Exemple #2
0
/* (Re)initialize the hash table. */
static int _nvram_rehash(nvram_handle_t *h)
{
	nvram_header_t *header = nvram_header(h);
	char buf[] = "0xXXXXXXXX", *name, *value, *eq;

	/* (Re)initialize hash table */
	_nvram_free(h);

	/* Parse and set "name=value\0 ... \0\0" */
	name = (char *) &header[1];

	for (; *name; name = value + strlen(value) + 1) {
		if (!(eq = strchr(name, '=')))
			break;
		*eq = '\0';
		value = eq + 1;
		nvram_set(h, name, value);
		*eq = '=';
	}

	/* Set special SDRAM parameters */
	if (!nvram_get(h, "sdram_init")) {
		sprintf(buf, "0x%04X", (uint16_t)(header->crc_ver_init >> 16));
		nvram_set(h, "sdram_init", buf);
	}
Exemple #3
0
/* Close NVRAM and free memory. */
int nvram_close(nvram_handle_t *h)
{
	_nvram_free(h);
	munmap(h->mmap, h->length);
	close(h->fd);
	free(h);

	return 0;
}
Exemple #4
0
/* (Re)initialize the hash table. */
static int _nvram_rehash(nvram_handle_t *h)
{
	/* (Re)initialize hash table */
	_nvram_free(h);

	/* Parse and set "name=value\0 ... \0\0" */
	char *name = (char *) &header[1];

	for (; *name; name = value + strlen(value) + 1) {
		if (!(eq = strchr(name, '=')))
			break;
		*eq = '\0';
		value = eq + 1;
		hash_nvram_set(h, name, value);
		*eq = '=';
	}

	return 0;
}
Exemple #5
0
/* (Re)initialize the hash table. */
static int _nvram_rehash(nvram_handle_t *h)
{
	nvram_header_t *header =(nvram_header_t *) &h->mmap[0]; 
	char *name, *value, *eq;

	_nvram_free(h);
	name = (char *) &header[1];
	for (; *name; name = value + strlen(value) + 1)
	{
		if (!(eq = strchr(name, '=')))  //。第一个形参就是要搜索的字符串,第二个是被搜索的字符。
			//如果找到了该字符就返回该字符第一次出现的内存地址。如果没有找到就返回NULL(也就是0)。
			break;
		*eq = '\0';
		value = eq + 1;
		_nvram_set(h, name, value);
		*eq = '=';
	}
	return 0;
}
Exemple #6
0
int hash_nvram_close(nvram_handle_t *h)
{
	_nvram_free(h);
	return 0;
}