⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nvstart.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
字号:
/*
	nvstart.c

*/
#include <stdtypes.h>
#include <stdio.h>
#include <stdlib.h>

/* non-standard includes... */
#include <lib.h>
#include <clib1.h>
#include <main.h>
#include <nvram.h>
#include <typedefs.h>

#include <amcclib.h>

extern UINT8 boot_nvram[];
extern CHAR errstring[];
extern struct _chip chip_uut;


static int nvwrite( int write_flag, UINT8 *data );
static UINT8 buffer[NVRAM_SIZE_BYTES];

int nvstart( char *file1, char *file2, int write_flag )
/*
	Compare <file1> (usually "bootnv") against <file2>.
	Read <filel> into boot_nvram[] array.
	Compare against actual nvram contents.
	If all OK, read and save all 5 base address registers.

	Entry:	if write_flag, write file2 to nvram if miscompares
	Return:	0 if all compares OK - no reboot required
			1 files miscompared, but no other errors (e.g. wrote nvram OK if asked)
			2 files compared, but nvram did not match the files
			3 fatal error (file or read/write nvram)
*/
{
	int status, region;

	status = buffer_load( file1, &boot_nvram, NVRAM_SIZE_BYTES );
	if ( status ) return 3;
	status = buffer_load( file2, buffer, NVRAM_SIZE_BYTES );
	if ( status ) return 3;
	if ( !compare( NVRAM_SIZE_BYTES, boot_nvram, buffer, errstring, \
			ERR_STR_SIZE, SIZE_LONG ) )
	{
		sprintf( errstring, "Files \"%s\" and  \"%s\" do not compare.\n", \
				file1, file2 );
		if ( nvwrite( write_flag, buffer ) )  return 1;
		return 3;
	}
	
	// read actual nvram to boot_nvram...
	status = nvram_read( boot_nvram, 0, NVRAM_SIZE_BYTES, \
		chip_uut.reg[0].base, chip_uut.type );
	if ( status != NVRAM_OK )
	{
		nvfail( status );
		return 3;
	}

	if ( !compare( NVRAM_SIZE_BYTES, boot_nvram, buffer, errstring, \
			ERR_STR_SIZE, SIZE_LONG ) )
	{
		sprintf( errstring, "NVRAM contents do not match \"%s\".\n", \
				file1 );
		if ( nvwrite( write_flag, buffer ) )  return 2;
		return 3;
	}

	// read and store base address values...
	for ( region = 0; region <= MAX_PT_REGION; region++ )
	{
		status = pci_config_read32( &chip_uut, PCI_CS_BASE_ADDRESS_0 + (region * 4), &chip_uut.reg[region].base);
		if ( status != PCI_SUCCESSFUL )
		{
			pci_bios_fail( status );
			return FALSE;
		}
	}

	return 0;		
}

static int nvwrite( int write_flag, UINT8 *data )
/*
	if write_flag, write data[] to nvram 
	Return:	TRUE if OK, else FALSE and errstring updated.
*/
{
	int status;

	if ( !write_flag )  return TRUE;
	status = nvram_write( data, 0, NVRAM_SIZE_BYTES, chip_uut.reg[0].base, \
		chip_uut.type );
	if ( status != NVRAM_OK )
		return nvfail( status );
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -