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

📄 main.c

📁 S3C2450BSP开发包,里面有很多资料。可以提供大家参考下。有什么需要解决问题。可以联系我QQ:314661
💻 C
字号:
#include <windows.h>
#include <pehdr.h>
#include <romldr.h>
#include "option.h"
#include "s2450addr.h"
#include "nand.h"
#include "utils.h"

#define MESSAGE_ON		(1)
#define NAND_BYTE_PER_PAGE	(2048)
#ifdef SUPPORTSLC
#define NAND_PAGE_PER_BLOCK	(64)
#endif
#ifdef SUPPORTMLC
#define NAND_PAGE_PER_BLOCK	(128)
#endif
#define NAND_BYTE_PER_BLOCK	(NAND_PAGE_PER_BLOCK*NAND_BYTE_PER_PAGE)

#define LOAD_ADDRESS_PHYSICAL		(0x30000000)//(0x30038000)									// 2nd loader address
#define LOAD_BYTE_SIZE				(0x00010000)									// 64 KB
#define LOAD_PAGE_SIZE				(LOAD_BYTE_SIZE/NAND_BYTE_PER_PAGE)
#define LOAD_IMAGE_BYTE_OFFSET	(0x00001000)									// 4096 byte
#define LOAD_IMAGE_PAGE_OFFSET	(LOAD_IMAGE_BYTE_OFFSET/NAND_BYTE_PER_PAGE)

// Function prototypes.
void MMU_EnableICache(void);

// Globals variables.
ROMHDR * volatile const pTOC = (ROMHDR *)-1;

typedef void (*PFN_IMAGE_LAUNCH)();

static BOOLEAN SetupCopySection(ROMHDR *const pTOC)
{
	// This code doesn't make use of global variables so there are no copy sections.  To reduce code size, this is a stub function...
	//
	return(TRUE);
}

BOOL b4KPage = FALSE;


void main(void)
{
	register nPage;
	unsigned char *pBuf;
	unsigned char ucDID, ucHID;
	unsigned char nCnt;
	unsigned char uNumOfLoadPage = LOAD_PAGE_SIZE;

	// Set up copy section (initialized globals).
	//
	// NOTE: after this call, globals become valid.
	//
//	SetupCopySection(pTOC);


	//Uart_Init();
	//Uart_SendString("\r\n\r\nWince 5.0 1st NAND Bootloader (NBL1) for SMDK2450\r\n");


//	Uart_SendString("NAND Initialize\r\n");
	// Enable the ICache.
//	Uart_SendString("B Cache \r\n");
	MMU_EnableICache();
	//Uart_SendString("A Cache \r\n");

	// Set up all GPIO ports.
	//Port_Init();

	// UART initialize
	Uart_Init();
	//Uart_SendString("\r\n\r\nWince 5.0 1st NAND Bootloader (NBL1) for SMDK2450\r\n");

	// Initialize the NAND flash interface.
	Uart_SendString("NAND Initialize\r\n");
	NAND_Init();

	Read_DeviceID(0, &ucDID, &ucHID);
	Uart_SendString("Device ID : 0x");
	Uart_SendBYTE(ucDID, 1);
	Uart_SendString("Hidden ID : 0x");
	Uart_SendBYTE(ucHID, 1);


	if ((ucDID == 0xd5 && ucHID == 0x14) || (ucDID == 0xd7 && ucHID == 0x55)  // for MLC
		|| (ucDID == 0xd3 && ucHID == 0x10))  // for SLC
	{
		b4KPage = TRUE;
		uNumOfLoadPage = LOAD_PAGE_SIZE/2;
	}

	// Turn the LEDs off.
//	Led_Display(LED_OFF);
//
	pBuf = (unsigned char *)LOAD_ADDRESS_PHYSICAL;
//	while(1);
	// MLC
	// Page 0, 1 : Steploader
	// Page 2 ~ 5 : empty page
	// Page 6 ~ PAGES_PER_BLOCK-3 : effective page
	// read pages with 0, 1 and 6 to PAGES_PER_BLOCK-3
#ifdef SUPPORTSLC
	nPage = LOAD_IMAGE_PAGE_OFFSET;
#endif
#ifdef SUPPORTMLC
#if (BSP_TYPE == BSP_SMDK2443)
	nPage = 6;
#elif (BSP_TYPE == BSP_SMDK2450)
   nPage = 10;
#endif
    
#endif
	for (nCnt = 0; nCnt < uNumOfLoadPage; nCnt++)
	{
		if (nPage >= (NAND_PAGE_PER_BLOCK-2) || (NAND_Read(0, nPage, pBuf) == FALSE))
		{
			// Uncorrectable ECC Error
			//Uart_SendString("ECC Error @ Page 0x");
			//Uart_SendBYTE(nPage, 1);
			//Led_Display(0x9);
			while(1);
		}

		nPage++;

		if (b4KPage == TRUE)
			pBuf += NAND_BYTE_PER_PAGE*2;
		else
			pBuf += NAND_BYTE_PER_PAGE;
	}

//	Uart_SendString("2nd Bootloader Loaded @ ");
//	Uart_SendDWORD(LOAD_ADDRESS_PHYSICAL, 1);

	// Turn the LEDs on.
	//
//	Led_Display(0x5);

		Uart_SendString("Jump to 2nd Bootloader...\r\n");

	//while(1);

	((PFN_IMAGE_LAUNCH)(LOAD_ADDRESS_PHYSICAL))();
}

⌨️ 快捷键说明

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