示例#1
0
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;
}
示例#2
0
static int ui_cmd_erasenvram(ui_cmdline_t *cmd,int argc,char *argv[])
{
    char *dev;
    int fd;
    uint8_t buffer[2048];
    int res;
    char *tok;
    int offset;
    int length;
    uint8_t data;

    dev = cmd_getarg(cmd,0);
    if (!dev) return ui_showusage(cmd);

    offset = 0;
    if ((tok = cmd_getarg(cmd,1))) offset = xtoi(tok);
    length = 512; 

    if ((tok = cmd_getarg(cmd,2))) length = xtoi(tok);
    if (length > 2048) length = 2048;

    data = 0xFF;
    if ((tok = cmd_getarg(cmd,3))) data = xtoi(tok);

    fd = cfe_open(dev);
    if (fd < 0) {
	ui_showerror(fd,"could not open NVRAM");
	return fd;
	}

    if (cmd_sw_isset(cmd,"-pattern")) {
	memset(buffer,0,sizeof(buffer));
	for (res = 0; res < 2048; res++) {
	    buffer[res] = res & 0xFF;
	    }
	}
    else memset(buffer,data,sizeof(buffer));

    printf("Fill offset %04X length %04X\n",offset,length);

    res = cfe_writeblk(fd,offset,buffer,length);

    printf("write returned %d\n",res);

    cfe_close(fd);
    return 0;
	
}
示例#3
0
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;
}
示例#4
0
int
cfe_write(int handle, unsigned char *buffer, int length)
{
    return cfe_writeblk(handle, 0, buffer, length);
}