📄 ebootmain.c
字号:
/*
@func BOOL | BootMonitor | Manages the bootloader monitor.
@rdesc TRUE = user selected download image, FALSE = user selected launch stored image.
@comm
@xref
*/
int eboot_keyproc()
{
int KeySelect = 0;
BOOLEAN bConfigChanged = FALSE;
BOOLEAN bDownload = TRUE;
while(1)
{
KeySelect = 0;
// GUI_Clear();
EdbgOutputDebugString ( "\r\nEthernet Boot Loader Configuration:\r\n");
EdbgOutputDebugString ( "-------------------------------------\r\n");
EdbgOutputDebugString ( "1) Boot delay: %d seconds\r\n", g_pBootCfg->BootDelay);
EdbgOutputDebugString ( "2) Reset TOC to default\r\n");
EdbgOutputDebugString ( "3) Startup image: %s\r\n", (g_pBootCfg->ConfigFlags & BOOT_TYPE_DIRECT) ? "LAUNCH EXISTING" : "DOWNLOAD NEW");
EdbgOutputDebugString ( "4) Program RAM image into Boot Media: %s\r\n", (g_pBootCfg->ConfigFlags & TARGET_TYPE_NAND) ? "ENABLED" : "DISABLED");
EdbgOutputDebugString ( "5) Format Boot Media for BinFS\r\n");
// EdbgOutputDebugString ( "\r\n");
// N.B: we need this option here since BinFS is really a RAM image, where you "format" the media
// with an MBR. There is no way to parse the image to say it's ment to be BinFS enabled.
EdbgOutputDebugString ( "6) Support BinFS: %s\r\n", (g_pTOC->id[g_dwTocEntry].dwImageType & IMAGE_TYPE_BINFS) ? "ENABLED" : "DISABLED");
EdbgOutputDebugString ( "7) Low-level FORMAT Boot Media\r\n");
EdbgOutputDebugString ( "8) LAUNCH existing Boot Media image\r\n");
EdbgOutputDebugString ( "9) DOWNLOAD image now(USB)\r\n");
EdbgOutputDebugString ( "A) Update image from SD Card\r\n");
EdbgOutputDebugString ( "C) Launch image from SD Card\r\n");
EdbgOutputDebugString ( "S) DOWNLOAD image now(SERIAL)\r\n");
EdbgOutputDebugString ( "R) Read Configuration \r\n");
EdbgOutputDebugString ( "W) Write Configuration Right Now\r\n");
EdbgOutputDebugString ( "B) Back\r\n");
EdbgOutputDebugString ( "-------------------------------------\r\n");
EdbgOutputDebugString ( "\r\nEnter your selection: ");
loop:
KeySelect=GUI_WaitKey();
if(default_keyproc(KeySelect)==0)
goto loop;
Out2TerminalChar((char)KeySelect);
switch(KeySelect)
{
case '1': // Change autoboot delay.
SetDelay(g_pBootCfg);
bConfigChanged = TRUE;
continue;
break;
case '2': // Reset TOC configuration.
// RETAILMSG(1, (TEXT("Resetting default TOC...\r\n")));
TOC_Init(DEFAULT_IMAGE_DESCRIPTOR, (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS), 0, 0, 0);
if ( !TOC_Write() ) {
// RETAILMSG(1, (TEXT("TOC_Write Failed!\r\n")));
}
// RETAILMSG(1, (TEXT("...TOC complete\r\n")));
continue;
break;
case '3': // Toggle download/launch status.
g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ BOOT_TYPE_DIRECT);
bConfigChanged = TRUE;
break;
case '4': // Toggle boot media image store.
g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ TARGET_TYPE_NAND);
bConfigChanged = TRUE;
break;
case '5':
// format the boot media for BinFS
// N.B: this does not destroy our OEM reserved sections (TOC, bootloaders, etc)
if ( !g_bBootMediaExist ) {
// RETAILMSG(1, (TEXT("ERROR: BootMonitor: boot media does not exist.\r\n")));
continue;
}
// N.B: format offset by # of reserved blocks,
// decrease the ttl # blocks available by that amount.
if ( !BP_LowLevelFormat( g_dwImageStartBlock,
NAND_BLOCK_CNT - g_dwImageStartBlock,
0) )
{
// RETAILMSG(1, (TEXT("ERROR: BootMonitor: Low-level boot media format failed.\r\n")));
continue;
}
break;
case '6':
g_pTOC->id[g_dwTocEntry].dwImageType = (g_pTOC->id[g_dwTocEntry].dwImageType ^ IMAGE_TYPE_BINFS);
g_ImageType = g_pTOC->id[g_dwTocEntry].dwImageType;
bConfigChanged = TRUE;
break;
case '7':
// low-level format
// N.B: this erases images, BinFs, FATFS, user data, etc.
// However, we don't format Bootloaders & TOC bolcks; use JTAG for this.
if ( !g_bBootMediaExist ) {
// RETAILMSG(1, (TEXT("ERROR: BootMonitor: boot media does not exist.\r\n")));
continue;
} else {
DWORD i;
SectorInfo si;
// to keep bootpart off of our reserved blocks we must mark it as bad, reserved & read-only
si.bOEMReserved = OEM_BLOCK_RESERVED | OEM_BLOCK_READONLY;
si.bBadBlock = BADBLOCKMARK;
si.dwReserved1 = 0;
si.wReserved2 = 0;
EdbgOutputDebugString("Reserving Blocks [0x%x - 0x%x] ...\r\n", 0, IMAGE_START_BLOCK-1);
for (i = 0; i < IMAGE_START_SECTOR; i++) {
FMD_WriteSector(i, NULL, &si, 1);
}
EdbgOutputDebugString("...reserve complete.\r\n");
EdbgOutputDebugString("Low-level format Blocks [0x%x - 0x%x] ...\r\n", IMAGE_START_BLOCK, NAND_BLOCK_CNT-1);
for (i = IMAGE_START_BLOCK; i < NAND_BLOCK_CNT; i++) {
FMD_EraseBlock(i);
}
EdbgOutputDebugString("...erase complete.\r\n");
} break;
case '8': // Download? No.
bDownload = FALSE;
goto MENU_DONE;
case '9': // Download? No.
g_bWaitForConnect = FALSE;
// bConfigChanged = TRUE;
g_bUSBDownload = TRUE;
usbInit();
download_run = 2;
bDownload = TRUE;
goto MENU_DONE;
case 'A':
case 'a':
if((NKFp=FS_FOpen("nk.bin", "rb"))==NULL)
{
EdbgOutputDebugString("There is no NK.BIN file in SD Card\r\n");
break;
}
readPtIndex=0x32000000;
g_bUSBDownload = FALSE;
g_bSERDownload = FALSE;
recv_length=0;
WM_ShowWindow(hFrameWin);
PROGBAR_SetMinMax(hProgBar, 0, NKFp->size/1024);//for value*xsize should less than a integer.
// FS_FRead((void *)0x32000000, NKFp->size, 1, NKFp);
bDownload = TRUE;
goto MENU_DONE;
case 'C':
case 'c':
{
FS_FILE *fp;
DWORD dwImageStart,dwImageLength,dwLaunchAddr;
if((fp=FS_FOpen("nk.nb0","rb")) == NULL)
{
if((NKFp=FS_FOpen("nk.bin","rb")) == NULL)
break;
//FS_FRead((void *)0x32000000, fp->size, 1, fp);
recv_length=0;
WM_ShowWindow(hFrameWin);
PROGBAR_SetMinMax(hProgBar, 0, NKFp->size/1024);
if(DownloadImage (&dwImageStart, &dwImageLength, &dwLaunchAddr))
{
dwLaunchAddr = ToPhysicalAddr(dwLaunchAddr);
Launch(dwLaunchAddr);
}
break;
}
else
{
FS_size_t block_size=1024*512;
recv_length=0;
WM_ShowWindow(hFrameWin);
PROGBAR_SetMinMax(hProgBar, 0, fp->size/1024);
for(;recv_length<fp->size;)
{
FS_FRead((void *)(0x30200000+recv_length), block_size, 1, fp);
recv_length+=512*1024;
if(hProgBar)
PROGBAR_SetValue(hProgBar, recv_length/1024);
if(recv_length+512*1024>fp->size)
block_size=fp->size-recv_length;
}
GUI_Exec();
}
Launch(0x30201000);
}
case 'R':
case 'r':
TOC_Read();
continue;
// TODO
break;
case 's':
case 'S':
g_bWaitForConnect = FALSE;
g_bSERDownload = TRUE;
//uartInit();
SER_Init();
bDownload = TRUE;
goto MENU_DONE;
case 'W': // Configuration Write
case 'w':
{
DWORD i;
SectorInfo si;
// to keep bootpart off of our reserved blocks we must mark it as bad, reserved & read-only
si.bOEMReserved = OEM_BLOCK_RESERVED | OEM_BLOCK_READONLY;
si.bBadBlock = BADBLOCKMARK;
si.dwReserved1 = 0;
si.wReserved2 = 0;
// RETAILMSG(1, (TEXT("Reserving Blocks [0x%x - 0x%x] ...\r\n"), 0, IMAGE_START_BLOCK-1));
for (i = 0; i < IMAGE_START_SECTOR; i++) {
FMD_WriteSector(i, NULL, &si, 1);
}
// RETAILMSG(1, (TEXT("...reserve complete.\r\n")));
}
if (!TOC_Write())
{
;// RETAILMSG(1, (TEXT("WARNING: MainMenu: Failed to store updated eboot configuration in flash.\r\n")));
}
else
{
// RETAILMSG(1, (TEXT("Successfully Written\r\n")));
bConfigChanged = FALSE;
}
break;
case 'b':
case 'B':
return 2;
default:
default_keyproc(KeySelect);
break;
}
}
MENU_DONE:
// If eboot settings were changed by user, save them.
//
if (bConfigChanged && !TOC_Write( ) )
{
;// RETAILMSG(1, (TEXT("WARNING: BootMonitor: Failed to store updated eboot configuration in flash.\r\n")));
}
return(bDownload);
}
static BOOLEAN BootMonitor( )
{
// int KeySelect = 0;
// BOOLEAN bConfigChanged = FALSE;
// BOOLEAN bDownload = TRUE;
return eboot_keyproc();//Show_ExecKeyboard(eboot_keyproc,1);
}
/*
@func BOOL | OEMPlatformInit | Initialize the platform hardware.
@rdesc TRUE = Success, FALSE = Failure.
@comm
@xref
*/
extern U8 serial_num[];
extern BOOL license_valid;
#define OAL_KITL_ID_SIZE 16
VOID OALKitlCreateName(CHAR *pPrefix, UINT16 mac[3], CHAR *pBuffer)
{
UINT32 count;
UINT16 base, code;
EdbgOutputDebugString("+OALKitlCreateName('%hs', 0x%04x, 0x%08x)\r\n", pPrefix, mac, pBuffer);
count = 0;
code = (mac[2] >> 8) | ((mac[2] & 0x00ff) << 8);
while (count < OAL_KITL_ID_SIZE - 6 && pPrefix[count] != '\0') {
pBuffer[count] = pPrefix[count];
count++;
}
/* base = 10000;
while (base > code && base != 0) base /= 10;
if (base == 0) {
pBuffer[count++] = '0';
} else {
while (base > 0) {
pBuffer[count++] = code/base + '0';
code %= base;
base /= 10;
}
}
pBuffer[count] = '\0';
*/
sprintf(&pBuffer[count],"%02X%02X%02X%02X%02X%02X",mac[0]&0xff,(mac[0]>>8)&0xff,mac[1]&0xff,mac[1]>>8,mac[2]&0x00ff,mac[2]>>8);
EdbgOutputDebugString("-OALKitlCreateName(pBuffer = '%hs')\r\n", pBuffer);
}
extern GUI_BITMAP bmbootpicture;
extern BOOL boot_picture_exist;
extern U8 output_decrypt[];
extern const U8 plaintext_a[];
extern const U8 plaintext_b[];
BOOL IsNKOpen()
{
return (NKFp==NULL)?FALSE:TRUE;
}
int eboot_mainproc()
{
DWORD dwStartTime, dwPrevTime, dwCurrTime;
int cKeySelect = 0;
DWORD dwBootDelay = 10; // seconds. N.B: change for retail device!
DWORD dwImageStart = 0, dwImageLength = 0, dwLaunchAddr = 0;
GUI_HWIN oldh;
int xpos;
g_dwImageStartBlock = IMAGE_START_BLOCK;
// Try to initialize the boot media block driver and BinFS partition.
//
if ( !BP_Init((LPBYTE)0x30080000, BINFS_RAM_LENGTH, NULL, NULL, NULL) )
{
EdbgOutputDebugString("WARNING: OEMPlatformInit failed to initialize Boot Media.\r\n\r\n");
g_bBootMediaExist = FALSE;
}
else
g_bBootMediaExist = TRUE;
memset((LPVOID)pBSPArgs, 0, sizeof(BSP_ARGS));
if(license_valid == TRUE)
{
pBSPArgs->header.signature = OAL_ARGS_SIGNATURE;
pBSPArgs->header.oalVersion = OAL_ARGS_VERSION;
pBSPArgs->header.bspVersion = BSP_ARGS_VERSION;
pBSPArgs->kitl.flags = 0;
pBSPArgs->kitl.devLoc.IfcType = Internal;
pBSPArgs->kitl.devLoc.BusNumber = 0;
pBSPArgs->kitl.devLoc.LogicalLoc = 0;
memcpy((LPVOID)pBSPArgs->serialnum,serial_num,8);
if(memcmp(&output_decrypt[8],plaintext_a,54)==0)
{
memcpy((LPVOID)pBSPArgs->license_dat,(LPVOID)g_pTOC->license_dat,128);
memcpy((LPVOID)pBSPArgs->kitl.mac,&serial_num[1],6);
}
else
EdbgOutputDebugString("1 license is not valid\n");
pBSPArgs->license_sig = g_pTOC->license_signature;
pBSPArgs->license_crc = g_pTOC->license_crc;
OALKitlCreateName(BSP_DEVICE_PREFIX, (UINT16*)&pBSPArgs->kitl.mac[0], (CHAR*)pBSPArgs->deviceId);
}
else
EdbgOutputDebugString("0 license is not valid\n");
dwBootDelay = g_pBootCfg->BootDelay;
dwStartTime = OSTimeGet();//OEMEthGetSecs();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -