引用 28 楼 amorous 的回复:
eboot相关代码贴出看看
MAIN 函数
//
// Type definitions.
//
typedef VOID (*PFN_LAUNCH)(VOID);
typedef enum // Supported image load/download methods.
{
BL_ENET = 0, // Ethernet.
BL_ATAHDD // ATA/IDE hard drive.
} IMG_LOC_ID;
typedef BOOL (*PFN_PLATFORM_INIT)(VOID);
typedef DWORD (*PFN_PRE_DOWNLOAD)(VOID);
typedef BOOL (*PFN_READ_DATA)(DWORD cbData, LPBYTE pbData);
//
// Definitions
//
//
// Function prototypes.
//
void OEMInitDebugSerial(void) ;
//
// Varaibles.
//
DWORD EdbgDebugZone;
static EDBG_ADDR MyAddr;
BOOL bEthLaunch =FALSE;
static PFN_PLATFORM_INIT pfnPlatformInit2 = NULL;
static PFN_PRE_DOWNLOAD pfnPreDownload = NULL;
static PFN_READ_DATA pfnReadData = NULL;
extern void OEMUartStop(void);
//****************************************************************************
// SpinForever
//****************************************************************************
// Spin forever.
//
//
static void SpinForever(void)
{
EdbgOutputDebugString("SpinForever...\r\n");
while(1)
{
;
}
}
//****************************************************************************
// OEMLaunch
//****************************************************************************
// dwImage - Image Start
// dwImageLength - Image Length
// dwLaunchAddr - Launch Address
// pRomHdr - Pointer to the bin header. Used to copy uninitialized
// data to ram.
//
void OEMLaunch
(
DWORD dwImageStart,
DWORD dwImageLength,
DWORD dwLaunchAddr,
const ROMHDR *pRomHdr
)
{
EDBG_OS_CONFIG_DATA *pCfgData;
EDBG_ADDR EshellHostAddr;
if (bEthLaunch) // Wait for host connection?
{
memset (&EshellHostAddr, 0, sizeof (EshellHostAddr));
//pDriverGlobals->eth.EdbgAddr
if (!(pCfgData = EbootWaitForHostConnect(&pDriverGlobals->eth.EdbgAddr, &EshellHostAddr)))
{
EdbgOutputDebugString("ERROR: EbootWaitForHostConenct failed, spin forever\r\n");
SpinForever();
}
EdbgOutputDebugString
(
"EBOOT: pCfgData = 0x%x, pCfgData->Flags\n",
(ULONG)pCfgData,
(ULONG)pCfgData->Flags
);
if (pCfgData->Flags & EDBG_FL_DBGMSG)
{
EdbgOutputDebugString("Enabling debug messages over Ethernet, IP: %s, port:%u\n",
inet_ntoa(pCfgData->DbgMsgIPAddr),ntohs(pCfgData->DbgMsgPort));
memcpy((void *)&pDriverGlobals->eth.DbgHostAddr.wMAC, (void *)&EshellHostAddr.wMAC,6);
pDriverGlobals->eth.DbgHostAddr.dwIP = pCfgData->DbgMsgIPAddr;
pDriverGlobals->eth.DbgHostAddr.wPort = pCfgData->DbgMsgPort;
}
if (pCfgData->Flags & EDBG_FL_PPSH)
{
EdbgOutputDebugString("Enabling CESH over Ethernet, IP: %s, port:%u\n",
inet_ntoa(pCfgData->PpshIPAddr),ntohs(pCfgData->PpshPort));
memcpy((void *)&pDriverGlobals->eth.PpshHostAddr.wMAC, (void *)&EshellHostAddr.wMAC,6);
pDriverGlobals->eth.PpshHostAddr.dwIP = pCfgData->PpshIPAddr;
pDriverGlobals->eth.PpshHostAddr.wPort = pCfgData->PpshPort;
}
if (pCfgData->Flags & EDBG_FL_KDBG)
{
EdbgOutputDebugString("Enabling KDBG over Ethernet, IP: %s, port:%u\n",
inet_ntoa(pCfgData->KdbgIPAddr),ntohs(pCfgData->KdbgPort));
memcpy((void *)&pDriverGlobals->eth.KdbgHostAddr.wMAC, (void *)&EshellHostAddr.wMAC,6);
pDriverGlobals->eth.KdbgHostAddr.dwIP = pCfgData->KdbgIPAddr;
pDriverGlobals->eth.KdbgHostAddr.wPort = pCfgData->KdbgPort;
}
pDriverGlobals->eth.etherFlags = pCfgData->Flags;
//
// This is also referred to the "ODO" mac address. Only the MAC is valid in this variable.
//
memcpy((void *)&pDriverGlobals->eth.EshellHostAddr, (void *)&EshellHostAddr,sizeof(EDBG_ADDR));
}
else
{
//
// It is ether a parallel port or a hard driver download.
//
}
// If no jump address is specified, choose the default (flash address).
//
if (!dwLaunchAddr)
{
//dwLaunchAddr = DEFAULT_JUMP_ADDR;
SpinForever();
}
EdbgOutputDebugString("INFO: Jumping to image at 0x%X...\r\n", dwLaunchAddr);
//
// Delay 1 Millisecond to flush the Uart fifo and stop the UART.
//
if(bEthLaunch)
{
DelayInuSec(1000);
// OEMUartStop();
}
((PFN_LAUNCH)(dwLaunchAddr))();
// Should never be reached...
SpinForever();
}
//****************************************************************************
// OEMShowProgress
//****************************************************************************
// Show download progress.
//
// dwPacketNum - Shows the number of packets. I don't know how to get
// the total number of packets.
//
// TODO - show packet progress.
//
void OEMShowProgress(DWORD dwPacketNum)
{
return;
}
//****************************************************************************
// OEMReadData
//****************************************************************************
// cbData - Buffer size
// pbData - Pointer to buffer.
//
// return - TRUE Success
// FALSE Failure
BOOL OEMReadData(DWORD cbData, LPBYTE pbData)
{
BOOL bReturnValue = FALSE;
//
// Read the data in from the device.
//
if(pfnReadData)
bReturnValue = pfnReadData(cbData, pbData);
return bReturnValue;
}
//****************************************************************************
// EbootMain
//****************************************************************************
// Called from startup. First C routine to be called.
//
//
void EbootMain(void)
{
//
// Write protect the flash.
//
*SMC_SMCBCR6 = 0x2000FBFF;
//
// Turn off the Green LED as recommended in the SDB
// documentation 3.2.4.
//
OEMWriteDebugLED(0,0);
//
// Common bootloader main routine.
//
BootloaderMain();
//
// Should never get here.
//
SpinForever();
}
//****************************************************************************
// OEMDebugInit
//****************************************************************************
// Callback to initialize serial debug hardware.
//
//
BOOL OEMDebugInit(void)
{
//
// Initialize our debug UART.
//
OEMInitDebugSerial();
//
// Initialize the debug timer.
//
DebugTimerInit();
//
// Initialize a PCMCIA card. Temporarily comment out.
//
OEMPCMCIAInitialize();
return(TRUE);
}
//****************************************************************************
// OEMPlatformInit
//****************************************************************************
// Called to detect the download type and initialize the platform.
//
// TRUE indicates success. FALSE indicates failure.
//
// Callback to initialize the platform.
//
BOOL OEMPlatformInit(void)
{
BOOL fRet = FALSE;
UCHAR i = 0;
EdbgOutputDebugString("\n============================================================\n"
"EP931x Windows CE Ethernet Bootloader \n"
"(Built on %s %s)"
"\n============================================================\n",
__DATE__, __TIME__);
//
// RLG temp.
//
#if 0
//
// Initiailize the parallel port
//
OEMInitParallelPort();
//
// Check to see if the parallel port is ready.
//
if (OEMIsParallelReady())
{
EdbgOutputDebugString("Downloading BIN file using parallel port.\r\n");
pfnPlatformInit2 = NULL;
pfnPreDownload = ParallelPreDownload;
pfnReadData = ParallelPortRead;
bEthLaunch = FALSE;
fRet = TRUE;
} else
#endif // 0
if(OEMHDDDetect())
{
EdbgOutputDebugString("Downloading BIN file using Hard Drive/CF card.\r\n");
pfnPlatformInit2 = OEMHDDPlatformInit;
pfnPreDownload = OEMHDDPreDownload;
pfnReadData = OEMHDDReadData;
bEthLaunch = FALSE;
fRet = TRUE;
}
else
{
EdbgOutputDebugString("Downloading BIN file using Ethernet.\r\n");
pfnPlatformInit2 = OEMEthHardwareInit;
pfnPreDownload = OEMEthPreDownload;
pfnReadData = EbootEtherReadData;
//
// This tells the kernel to connect to the ethernet debugger.
//
pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM;
bEthLaunch = TRUE;
fRet = TRUE;
}
//
// Initialize ethernet.
//
if(pfnPlatformInit2)
pfnPlatformInit2();
return(fRet);
}
//****************************************************************************
// OEMPreDownload
//****************************************************************************
// Sets up a device before a download.
//
// Return BL_ERROR, BL_JUMP, BL_DOWNLOAD
//
DWORD OEMPreDownload()
{
DWORD dwReturnValue = BL_ERROR;
//
// Read the data in from the device.
//
if(pfnReadData)
dwReturnValue = pfnPreDownload();
return dwReturnValue;
}