?? 2410loader.c
字號:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
--*/
/************************************************
* NAME : 2410loader.C *
* DESC : *
* History : 2002.02.25 ver 0.0 *
************************************************/
#include <stdlib.h>
#include <string.h>
#include "option.h"
#include "def.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "2410addr.h"
#include "nand.h"
#include "loader.h"
#define SIGN_ON "\nWinCE NAND Boot v1.00\n" __DATE__ " " __TIME__ "\n"
// HMSEO : Please check UUID memory location from inc\drv_glob.h file.
unsigned char * pbUUID = ((unsigned char *) (0x30030000 + 0x4608));
//
// Globals
//
DWORD JumpAddr;
TOC toc; // made global because it's too big for our tiny stack
// -----------------------------------------------------------------------------
// ReadImageFromNand:
// Reads nk.nb0 off NAND
// Returns ERR_Xxx
// -----------------------------------------------------------------------------
DWORD
ReadImageFromNand()
{
DWORD dwSectorsNeeded;
DWORD dwSector, dwLength; // Start Sector & Length
DWORD dwRAM, i;
DWORD dwEntry,dwCount;
int key;
if ( !FMD_ReadSector(TOC_SECTOR,
(LPBYTE)&toc,
NULL, 1) )
{
return ERR_DISK_OP_FAIL1;
}
if ( !VALID_TOC(&toc) ) {
Uart_SendString("Read From Nand: ");
Uart_SendDWORD(toc.dwSignature, TRUE);
return ERR_INVALID_TOC;
}
dwEntry = 1;
//Uart_SendString("Press [ENTER] to launch image stored on boot media, or [SPACE] to eboot.\r\n");
while(dwCount > 10000)
{
key = Uart_RecvByte();
if (key == 0x20)
{
dwEntry = 0;
break;
}else if(key == 0x0d)
break;
dwCount++;
}
if ( !(toc.id[dwEntry].dwImageType & IMAGE_TYPE_RAMIMAGE) ) {
// Uart_SendString("ERR_INVALID_FILE_TYPE: ");
Uart_SendDWORD(toc.id[dwEntry].dwImageType, TRUE);
return ERR_INVALID_FILE_TYPE;
}
dwSectorsNeeded = toc.id[dwEntry].dwTtlSectors;
//Uart_SendString("Sector addr on NAND: ");
//Uart_SendDWORD(toc.id[dwEntry].sgList[0].dwSector, TRUE);
//Uart_SendString("TotalSector: ");
//Uart_SendDWORD(dwSectorsNeeded, TRUE);
dwRAM = VIRTUAL_TO_PHYSICAL(toc.id[dwEntry].dwLoadAddress);
JumpAddr = toc.id[dwEntry].dwJumpAddress ? VIRTUAL_TO_PHYSICAL(toc.id[
dwEntry].dwJumpAddress) : VIRTUAL_TO_PHYSICAL(toc.id[dwEntry].dwLoadAddress);
// Uart_SendDWORD(JumpAddr, TRUE); hc test
// Uart_SendString("123123123"); hc test
// Uart_SendDWORD(dwRAM, TRUE); hc test
// Load the disk image directly into RAM
// BUGBUG: recover from read failures
//
i = 0;
while (dwSectorsNeeded && i < MAX_SG_SECTORS)
{
dwSector = toc.id[dwEntry].sgList[i].dwSector;
dwLength = toc.id[dwEntry].sgList[i].dwLength;
// Uart_SendDWORD(dwLength, TRUE); hc test
// read each sg segment
while (dwLength) {
if ( !FMD_ReadSector(dwSector,
(LPBYTE)dwRAM,
NULL, 1) )
{
Uart_SendString("ERR_DISK_OP_FAIL2: ");
Uart_SendDWORD(dwSector, TRUE);
dwSector++;
continue;
}
dwSector++;
dwLength--;
dwRAM += SECTOR_SIZE;
}
dwSectorsNeeded -= toc.id[dwEntry].sgList[i].dwLength;
i++;
}
// We only do this if the dwRAM is not zero (The default tocblock1
// set the dwRAM to be 0)
if (toc.chainInfo.dwLoadAddress == 0) {
// Uart_SendString("ERR_SUCCESS:LoadAddress == 0000");-->hc test
return ERR_SUCCESS;
}
// Load the Chain.bin stored on NAND to the SDRAM
if ( toc.id[dwEntry].dwImageType == 6 ) // For WinCE 4.2 Image
{
// Uart_SendString("ERR_SUCCESS:ImageType == 6");-->hc test
return ERR_SUCCESS;
}
else
{
dwRAM = VIRTUAL_TO_PHYSICAL(toc.chainInfo.dwLoadAddress);
dwSectorsNeeded = toc.chainInfo.dwLength;
dwSector = toc.chainInfo.dwFlashAddress;
}
// Copy UUID to SDRAM drv_glob area from NAND
Uart_SendString("Reading UUID from NAND : ");
for ( i = 0; i < 8; i++ )
{
*pbUUID = toc.udid[i];
pbUUID++;
}
Uart_SendString("\r\n");
Uart_SendString("Reading Chain from NAND\r\n");
Uart_SendString("LoadAddr: ");
Uart_SendDWORD(dwRAM, TRUE);
Uart_SendString("NAND SectorAddr: ");
Uart_SendDWORD(dwSector, TRUE);
Uart_SendString("Length: ");
Uart_SendDWORD(dwSectorsNeeded, TRUE);
Uart_SendString("\r\n ");
while(dwSectorsNeeded) {
if (!FMD_ReadSector(dwSector,
(LPBYTE) dwRAM,
NULL, 1) ) {
Uart_SendString("Failed reading Chain.bin:");
Uart_SendDWORD(dwSector, TRUE);
dwSector++;
continue;
}
dwSector++;
dwSectorsNeeded--;
dwRAM += SECTOR_SIZE;
}
return ERR_SUCCESS;
}
////////////////////////////////////////////////////////////////////////////////////
DWORD JumpAddr;
TOC toc; // made global because it's too big for our tiny stack
DWORD ReadEbootFromNand()
{
DWORD dwSectorsNeeded;
DWORD dwSector, dwLength; // Start Sector & Length
DWORD dwRAM, i;
//////////////////////////////////////////////////
//Init Toc
toc.id[0].dwVersion = (EBOOT_VERSION_MAJOR << 16) | EBOOT_VERSION_MINOR;
toc.id[0].dwSignature = IMAGE_EBOOT_SIG;
// memcpy(toc.id[0].ucString, "eboot.nb0", sizeof("eboot.nb0")+1); // NUll terminate
toc.id[0].dwImageType = IMAGE_TYPE_RAMIMAGE;
toc.id[0].dwLoadAddress = EBOOT_RAM_IMAGE_BASE;
toc.id[0].dwJumpAddress = EBOOT_RAM_IMAGE_BASE;
toc.id[0].dwTtlSectors = FILE_TO_SECTOR_SIZE(EBOOT_RAM_IMAGE_SIZE);
// 1 contigious segment
toc.id[0].sgList[0].dwSector = BLOCK_TO_SECTOR(EBOOT_BLOCK);
toc.id[0].sgList[0].dwLength = toc.id[0].dwTtlSectors;
dwSectorsNeeded = toc.id[0].dwTtlSectors;
////////////////////////////////////////////////
dwRAM = VIRTUAL_TO_PHYSICAL(toc.id[0].dwLoadAddress);
JumpAddr = toc.id[0].dwJumpAddress ? VIRTUAL_TO_PHYSICAL(toc.id[0].dwJumpAddress) :
VIRTUAL_TO_PHYSICAL(toc.id[0].dwLoadAddress);
i = 0;
while (dwSectorsNeeded && i < MAX_SG_SECTORS)
{
dwSector = toc.id[0].sgList[i].dwSector;
dwLength = toc.id[0].sgList[i].dwLength;
// read each sg segment
while (dwLength) {
if ( !FMD_ReadSector(dwSector, (LPBYTE)dwRAM, NULL, 1) )
{
// Uart_SendString("ERR_DISK_OP_FAIL2: ");
// Uart_SendDWORD(dwSector, TRUE);
}
dwSector++;
dwLength--;
dwRAM += SECTOR_SIZE;
}
dwSectorsNeeded -= toc.id[0].sgList[i].dwLength;
i++;
}
return ERR_SUCCESS;
}
/////////////////////////////////////////////////////////////////////////////////////
void Main(void)
{
DWORD err;
int sign = 0;
// By default, we launch image CE image. If you want to launch
// Eboot, you need to hold down APP4 button (sw803) when it boots.
MMU_EnableICache();
Uart_Init();
NF_Init();
if (!(rGPFDAT & (1 << 0)))
{
Delay (200);
if (!(rGPFDAT & (1 << 0)))
{
sign = 1;
}
}
if (sign == 1)
{
Uart_SendString(SIGN_ON);
ReadEbootFromNand();
}
else
{
err = ReadImageFromNand();
if (ERR_SUCCESS == err)
{
err = ERR_JUMP_FAILED;
}
}
// err = ReadImageFromNand();
// if (ERR_SUCCESS == err) {
Launch(JumpAddr);
// err = ERR_JUMP_FAILED;
// }
Uart_SendString("\nBoot ERROR:");
Uart_SendDWORD(err, TRUE);
while (1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -