?? u2440mon.c
字號:
Uart_Printf ( "-------------------------------------\r\n");
Uart_Printf ( "1) Upgrade NBOOT\r\n");
Uart_Printf ( "2) Upgrade EBOOT\r\n");
Uart_Printf ( "3) Save License\r\n");
Uart_Printf ( "4) Change the Boot Picture\r\n");
Uart_Printf ( "5) Back\r\n");
/* Uart_Printf ( "6) Upgrade NBOOT through Serial\r\n");
Uart_Printf ( "7) Upgrade EBOOT through Serial\r\n");
Uart_Printf ( "8) Save License through Serial\r\n");
Uart_Printf ( "9) Change the Boot Picture through Serial\r\n");
*/ Uart_Printf ( "\r\nEnter your selection: ");
loop:
KeySelect=GUI_WaitKey();
if(default_keyproc(KeySelect)==0)
goto loop;
Out2TerminalChar((char)KeySelect);
switch(KeySelect)
{
case '1':
//gBlockIndex=NBOOT_BLOCK;
//return 0;
case '2':
//gBlockIndex=EBOOT_BLOCK;
//return 0;
case '3':
//gBlockIndex=TOC_BLOCK;
//return 0;
case '4':
//gBlockIndex=BOOT_PICTURE_BLOCK;
gBlockIndex=block_index[KeySelect-'1'];
//currfilename = file_name[KeySelect-'1'];
do{
Uart_Printf ( "Select Upgrade through path\r\n");
Uart_Printf ( "1) Through USB\r\n");
Uart_Printf ( "2) Through Serial\r\n");
Uart_Printf ( "3) Through SD Card Files\r\n");
Uart_Printf ( "\r\nEnter your selection: ");
loop1:
KeySelect=GUI_WaitKey();
if(default_keyproc(KeySelect)==0)
goto loop1;
Out2TerminalChar((char)KeySelect);
if(KeySelect == '2')
{
uartInit();
return 0;
}
if(KeySelect == '3')
{
FS_FILE *fp;
fp=SelectFile();//FS_FOpen(currfilename,"rb");
if(fp)
{
downloadFileSize=fp->size;
downloadAddress = DMABUFFER;
downPtIndex = DMABUFFER;
readPtIndex = DMABUFFER;
downPt = (unsigned char*)downPtIndex;
FS_FRead((void *) downPt, downloadFileSize, 1, fp);
FS_FClose(fp);
return 0;
}
}
if(KeySelect == '1')
return 0;
}
while(1);
case '5':
return 0;
#if 0
case '6':
gBlockIndex=NBOOT_BLOCK;
uartInit();
return 0;
case '7':
gBlockIndex=EBOOT_BLOCK;
uartInit();
return 0;
case '8':
gBlockIndex=TOC_BLOCK;
uartInit();
return 0;
case '9':
gBlockIndex=BOOT_PICTURE_BLOCK;
uartInit();
return 0;
#endif
default:
default_keyproc(KeySelect);
break;
}
}
return 0;
}
void Menu(void)
{
int i,j;
U8 key;
U32 curr_ticks;
while(1)
{
Uart_Printf("\n###### Main Menu ######\n");
Uart_Printf(" [0] Download & Run\n");
Uart_Printf(" [1] Download and Save-->\n");
Uart_Printf(" [2] EBOOT-->\n");
Uart_Printf(" [3] Self Test-->\n");
Uart_Printf(" [4] NandFlash Block Read\n");
// Uart_Printf(" [4] Touch Calibration\n");
Uart_Printf(" [5] NandFlash Block Write\n");
Uart_Printf ( "\r\nEnter your selection: ");
loop:
key=GUI_WaitKey();
if(default_keyproc(key)==0)
goto loop;
Out2TerminalChar((char)key);
switch(key)
{
case '0':
Uart_Printf("\nDownload&Run is selected.\n\n");
download_run=1;
do{
Uart_Printf ( "Select Download through path\r\n");
Uart_Printf ( "1) Through USB\r\n");
Uart_Printf ( "2) Through Serial\r\n");
Uart_Printf ( "3) Through SD Card Files\r\n");
Uart_Printf ( "\r\nEnter your selection: ");
loop1:
key=GUI_WaitKey();
if(default_keyproc(key)==0)
goto loop1;
Out2TerminalChar((char)key);
if(key == '2')
{
uartInit();
Uart_Printf("Enter a download address(0x3...):");
downloadAddress=Uart_GetIntNum();
downPt = (unsigned char*)downloadAddress;
return ;
}
if(key == '3')
{
FS_FILE *fp;
fp=SelectFile();
if(fp)
{
downloadFileSize=fp->size;
Uart_Printf("Enter a download address(0x3...):");
downloadAddress = Uart_GetIntNum();
downPt = (unsigned char*)downloadAddress;
FS_FRead((void *) downPt, downloadFileSize, 1, fp);
FS_FClose(fp);
return ;
}
}
if(key == '1')
return ;
}while(1);
// MMU_DeInit();
return;
case '1':
// Uart_Printf("\nDownload and Write to Nand Flash is selected.\n");
// Uart_Printf("Enter a new temporary download address(0x3...):");
// tempDownloadAddress=Uart_GetIntNum();
download_run=0;
upgrade_keyproc();
// Uart_Printf("The temporary download address is 0x%x.\n\n",tempDownloadAddress);
return;
case '2':
download_run=2;
eboot_main();
break;
case '3':
test_keyproc();
break;
case '4':
{
U32 block,sector;
U8 buffer[2048+16];
Uart_Printf("buffer %p size=%d\n",buffer,sizeof(buffer));
Uart_Printf("Input target block number:");
block=Uart_GetIntNum();
Uart_Printf("Input target page number:");
sector=Uart_GetIntNum();
Uart_Printf("block=%d,page=%d:",block,sector);
sector=sector+BLOCK_TO_SECTOR(block);//block<<5;
FMD_ReadSector(sector, (LPBYTE) buffer, (PSectorInfo)(buffer+SECTOR_SIZE), 1);
for(i=0;i<SECTOR_SIZE;i++)
{
if(i%16==0)
Uart_Printf("\n%3xh:",i);
Uart_Printf("%02x ",buffer[i]);
}
Uart_Printf("\nS.A.:",i);
for(i=0;i<8;i++)
{
Uart_Printf("%02x ",buffer[i+SECTOR_SIZE]);
}
Uart_Printf("\n");
}
break;
case '5':
{
U32 block,sector;
U8 buffer[2048+16];
Uart_Printf("buffer %p size=%d\n",buffer,sizeof(buffer));
Uart_Printf("Input target block number:");
block=Uart_GetIntNum();
Uart_Printf("Input target page number:");
sector=Uart_GetIntNum();
Uart_Printf("block=%d,page=%d:",block,sector);
sector=sector+BLOCK_TO_SECTOR(block);//block<<5;
memset(buffer,0x55,sizeof(buffer));
FMD_WriteSector(sector, (LPBYTE) NULL, (PSectorInfo)(buffer+SECTOR_SIZE), 1);
FMD_ReadSector(sector, (LPBYTE) buffer, (PSectorInfo)(buffer+SECTOR_SIZE), 1);
for(i=0;i<SECTOR_SIZE;i++)
{
if(i%16==0)
Uart_Printf("\n%3xh:",i);
Uart_Printf("%02x ",buffer[i]);
}
Uart_Printf("\nS.A.:",i);
for(i=0;i<8;i++)
{
Uart_Printf("%02x ",buffer[i+SECTOR_SIZE]);
}
Uart_Printf("\n");
}
break;
/* case '4':
WM_HideWindow(hTerm);
Show_ExecKeyboard(NULL,0);
_ExecCalibration() ;
WM_ShowWindow(hTerm);
Show_ExecKeyboard(NULL,1);
break;
case '5':
curr_ticks = OSTimeGet();
srand(curr_ticks);
rsa_self_test();
Uart_Printf("rsa test spent time %dms",(OSTimeGet()-curr_ticks)*10);
break;
*/ default:
default_keyproc(key);
break;
}
}
}
int AfterRcvFirstDataPacket();
BOOL check_license_valid(U8 *license_dat)
{
rsa_context rsa;
uint len = 8+54*2;
memset(&rsa,0x00,sizeof(rsa));
rsa_init(&rsa);
if( rsa_pkcs1_decrypt_public( &rsa, license_dat, 128,
output_decrypt, &len ) != 0)
goto Cleanup;
if(memcmp(output_decrypt,serial_num_rev,8)!=0)
goto Cleanup;
if(memcmp(&output_decrypt[8],plaintext_a,54)!=0)
goto Cleanup;
if(memcmp(&output_decrypt[8+54],plaintext_b,54)!=0)
goto Cleanup;
rsa_free(&rsa);
return TRUE;
Cleanup:
rsa_free(&rsa);
return FALSE;
}
void WaitDownload(void)
{
U32 i;
U32 j;
U16 cs;
U32 temp;
U16 dnCS;
int first=1;
float time;
U8 tempMem[16];
U8 key;
checkSum=0;
// downloadAddress=(U32)tempMem; //_RAM_STARTADDRESS;
downPt=(unsigned char *)downPtIndex;//downloadAddress;
//This address is used for receiving first 8 byte.
//downloadFileSize=0;
#if 0
MMU_DisableICache();
//For multi-ICE.
//If ICache is not turned-off, debugging is started with ICache-on.
#endif
/*******************************/
/* Test program download */
/*******************************/
j=0;
if(isUsbdSetConfiguration==0)
{
Uart_Printf("USB host is not connected yet.\n");
// _UpdateCmdWin(_usbhInfoWin, "USB host is not connected yet.");
// WM_ExecIdle();
}
while(downloadFileSize==0)
{
if(first==1 && isUsbdSetConfiguration!=0)
{
Uart_Printf("USB host is connected. Waiting a download.\n");
// _UpdateCmdWin(_usbhInfoWin, "USB host is connected. Waiting a download.");
// WM_ExecIdle();
first=0;
}
if(j%0x280000==0)Led_Display(0x6);
if(j%0x280000==0x14000)Led_Display(0x9);
j++;
key=GUI_GetKey();
if(key!=0)
{
Menu();
first=1; //To display the message,"USB host ...."
}
// GUI_Exec();
}
if(isSerSetConfiguration)
{
if(SERAfterRcvFirstDataPacket()==-1)
return ;
}
else if(isUsbdSetConfiguration)
{
if(AfterRcvFirstDataPacket()==-1)
return ;
}
else
{/* upgrade from SD card*/
//if(SERAfterRcvFirstDataPacket()==-1)
// return ;
}
// Uart_TxEmpty(consoleNum);
if(download_run==1)
{
rINTMSK=BIT_ALLMSK;
Launch(downloadAddress);
//run=(void (*)(void))downloadAddress;
//run();
}
if(download_run == 0)
{/*download successful, then try to program to nand flash*/
U32 targetSize;
U32 blockIndex;
SectorInfo si,si1;
U8 *srcPt;
U32 progSize=0;
Uart_Printf("\n[SMC(K9S1208V0M) NAND Flash Writing Program]\n");
Uart_Printf("\nSource size:0h~%xh\n",downloadFileSize-1);
// Uart_Printf("\nAvailable target block number: 0~4095\n");
// Uart_Printf("Input target block number:");
// blockIndex=Uart_GetIntNum();//scanf("%d",&targetBlock);
blockIndex = gBlockIndex;
if(blockIndex == 1)
{/* this is for save license data,we need check the license is valid then save to flash.*/
U8 license_dat[128];
U32 calc_crc;
if(isSerSetConfiguration)//from Serial Port.
memcpy(license_dat,(U8*)downloadAddress,downloadFileSize-6);
else if(isUsbdSetConfiguration)
{
if(downloadFileSize != 128+10)
{
Uart_Printf("1 it is not valid license file,please try again\n");
return ;
}
memcpy(license_dat,(U8*)downloadAddress,downloadFileSize-10);
}
else//from SD Card..
memcpy(license_dat,(U8*)downloadAddress,downloadFileSize);
//check the license is valid or not...
if(check_license_valid(license_dat)== FALSE)
{
Uart_Printf("2 it is not valid license file,please try again\n");
return ;
}
{
TOC_Read();
g_pTOC->license_signature=LICENSE_SIG;
memcpy((LPVOID)g_pTOC->license_dat,license_dat,128);//fix save license from SD card invalid issue,use the fixed length 128.
for(i=0,calc_crc=0;i<128;i+=4)
{
calc_crc=(U32)(calc_crc+g_pTOC->license_dat[i]+g_pTOC->license_dat[i+1]+g_pTOC->license_dat[i+2]+g_pTOC->license_dat[i+3]);
}
g_pTOC->license_crc = calc_crc;
TOC_Write();
}
return ;
}
if((blockIndex == NBOOT_BLOCK)||(blockIndex == EBOOT_BLOCK))
{
while((key != 'y')&&(key != 'Y')&&(key != 'n')&&(key != 'N'))
{
Uart_Printf("\nAre you make sure to upgrade the %s[Y/N]?",blockIndex==0?"NBOOT":"EBOOT");
key = GUI_WaitKey();
Out2TerminalChar(key);
if(key == '\r')
break;
}
if((key=='n')||(key=='N'))
return;
}
// if(blockIndex>IMAGE_START_SECTOR)
targetSize=((downloadFileSize+PAGES_PER_BLOCK*SECTOR_SIZE-1)/(PAGES_PER_BLOCK*SECTOR_SIZE))*(PAGES_PER_BLOCK*SECTOR_SIZE);
Uart_Printf("target start block number =%d\n",blockIndex);
Uart_Printf("target size (0x20000*n) =0x%x\n",targetSize);
Uart_Printf("STATUS:");
// 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;
si1.bOEMReserved &= ~OEM_BLOCK_READONLY;
#define SECTOR_WRITE_COMPLETED 0x0004 // Indicates data is valid for the FAL
si1.wReserved2 &= ~SECTOR_WRITE_COMPLETED;
si1.bBadBlock = 0xff;
si1.dwReserved1 = 0;
srcPt=(U8*)downloadAddress;
while(1)
{
if(blockIndex>IMAGE_START_BLOCK)
{
if(IsBlockBad(blockIndex) == TRUE)
{
Uart_Printf("block %d is Bad,skip it\n",blockIndex);
blockIndex++;
continue;
}
FMD_ReadSector(BLOCK_TO_SECTOR(blockIndex), NULL,&si1,1);
si1.bOEMReserved &= ~OEM_BLOCK_READONLY;
si1.wReserved2 &= ~SECTOR_WRITE_COMPLETED;
}
FMD_EraseBlock(blockIndex);
Uart_Printf("\nE");
//for(i=0;i<PAGES_PER_BLOCK;i++) // 16K size only
{
FMD_WriteSector((BLOCK_TO_SECTOR(blockIndex))+0,srcPt,blockIndex<IMAGE_START_BLOCK?&si:&si1,PAGES_PER_BLOCK);// block num, page num, buffer
srcPt+=SECTOR_SIZE*PAGES_PER_BLOCK; // Increase buffer addr one pase size
Uart_Printf("b");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -