コード例 #1
0
ファイル: nvram_rw.c プロジェクト: Antares84/asuswrt-merlin
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
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;
}
コード例 #3
0
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;
}