?? u2440mon.c
字號:
/****************************************************************
NAME: u2440mon.c
DESC: u2440mon entry point,menu,download
HISTORY:
Mar.25.2002:purnnamu: S3C2400X profile.c is ported for S3C2410X.
Mar.27.2002:purnnamu: DMA is enabled.
Apr.01.2002:purnnamu: isDownloadReady flag is added.
Apr.10.2002:purnnamu: - Selecting menu is available in the waiting loop.
So, isDownloadReady flag gets not needed
- UART ch.1 can be selected for the console.
Aug.20.2002:purnnamu: revision number change 0.2 -> R1.1
Sep.03.2002:purnnamu: To remove the power noise in the USB signal, the unused CLKOUT0,1 is disabled.
****************************************************************/
//#include "windows.h"
#include <stdlib.h>
#include <string.h>
#include "includes.h"
/*
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"
*/
#include "profile.h"
#include "usbmain.h"
#include "usbout.h"
#include "usblib.h"
#include "2440usb.h"
#include "cfnand.h"
#include "loader.h"
#include "fmd.h"
#include "terminal.h"
#include "rsa.h"
#include "fs_api.h"
#include "framewin.h"
#include "progbar.h"
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Lcd_Off(void);
void WaitDownload(void);
void Menu(void);
void ClearMemory(void);
void Clk0_Enable(int clock_sel);
void Clk1_Enable(int clock_sel);
void Clk0_Disable(void);
void Clk1_Disable(void);
//#define DOWNLOAD_ADDRESS _RAM_STARTADDRESS
volatile U32 downloadAddress;
void (*restart)(void)=(void (*)(void))0x0;
void (*run)(void);
void loadboot(void);
volatile unsigned char *downPt;
volatile U32 downloadFileSize;
volatile U16 checkSum;
volatile unsigned int err=0;
volatile U32 totalDmaCount;
volatile int isUsbdSetConfiguration;
volatile int isSerSetConfiguration;
int download_run=0;
U32 tempDownloadAddress;
int menuUsed=0;
#define DMABUFFER 0x32000000
volatile unsigned int downPtIndex = DMABUFFER;
volatile unsigned int readPtIndex = DMABUFFER;
extern char Image$$RW$$Limit[];
U32 *pMagicNum=(U32 *)Image$$RW$$Limit;
extern U32 Fclk, Hclk, Pclk;
extern const PTOC g_pTOC;
extern U8 serial_num[8];
extern U8 serial_num_rev[8];
extern TERMINAL_Handle hTerm;
extern PROGBAR_Handle hProgBar;
extern FRAMEWIN_Handle hFrameWin;
int consoleNum;
#define SIGN_ON "| S3C2440A USB Downloader ver R0.03 |\n" __DATE__ " " __TIME__ "\n"
static int delayLoopCount = 400;
const U8 plaintext_b[55] = "\xD7\xE6\xF7\x2F\xAA\xF8\xE6\x77\x4B\xA6\xB2\x87\x63\xA9\xB0\xEC" \
"\xF5\x35\xBA\x78\x7A\x2A\xDD\x46\xA2\xC3\x55\x0F\x43\xA3\x87\xA9" \
"\xED\xB5\x10\xF4\xDC\x6A\xA6\xB3\x39\x0F\x4F\x61\x5D\xA3\xC7\xE1" \
"\xB0\xD3\xB8\xD6\x8B\x97";
U8 output_decrypt[8+54*2];
extern U8 plaintext_a[];
extern void Uart_Printf(const char *fmt,...);
void Delay(int time)
{
// time=0: adjust the Delay function by WatchDog timer.
// time>0: the number of loop time
// resolution of time is 100us.
int i,adjust=0;
if(time==0)
{
time = 200;
adjust = 1;
delayLoopCount = 400;
//PCLK/1M,Watch-dog disable,1/64,interrupt disable,reset disable
rWTCON = ((Pclk/1000000-1)<<8)|(2<<3);
rWTDAT = 0xffff; //for first update
rWTCNT = 0xffff; //resolution=64us @any PCLK
rWTCON = ((Pclk/1000000-1)<<8)|(2<<3)|(1<<5); //Watch-dog timer start
}
for(;time>0;time--)
for(i=0;i<delayLoopCount;i++);
if(adjust==1)
{
rWTCON = ((Pclk/1000000-1)<<8)|(2<<3); //Watch-dog timer stop
i = 0xffff - rWTCNT; //1count->64us, 200*400 cycle runtime = 64*i us
delayLoopCount = 8000000/(i*64); //200*400:64*i=1*x:100 -> x=80000*100/(64*i)
}
}
//**************************[ BOARD LED ]*********************************
void Led_Display(int data)
{
//Active is low.(LED On)
// GPF7 GPF6 GPF5 GPF4
//nLED_8 nLED4 nLED_2 nLED_1
// rGPFDAT = (rGPFDAT & 0xf) | !((data & 0xf)<<4);
if(data == 6)
{
rGPGDAT |= (1<<7);
rGPBDAT &= ~(1<<1);
}
else
{
rGPGDAT &= ~(1<<7);
rGPBDAT |= 1<<1;
}
// rGPFDAT = (rGPFDAT & ~(0xf<<4)) | ((~data & 0xf)<<4);
}
#if 0
//*************************[ Timer ]********************************
void Timer_Start(int divider) //0:16us,1:32us 2:64us 3:128us
{
rWTCON = ((Pclk/1000000-1)<<8)|(divider<<3); //Watch-dog timer control register
rWTDAT = 0xffff; //Watch-dog timer data register
rWTCNT = 0xffff; //Watch-dog count register
// Watch-dog timer enable & interrupt disable
rWTCON = (rWTCON & ~(1<<5) & ~(1<<2)) |(1<<5);
}
//=================================================================
int Timer_Stop(void)
{
rWTCON = ((Pclk/1000000-1)<<8);
return (0xffff - rWTCNT);
}
#endif
#if 0
static void _UpdateCmdWin(FRAMEWIN_Handle hInfoWin, const char *info ) {
#if GUI_WINSUPPORT
/* Update info in command window */
WM_HWIN hWin;
GUI_CONTEXT ContextOld;
GUI_SaveContext(&ContextOld);
hWin = WM_SelectWindow(hInfoWin);
GUI_SetDefault();
GUI_SetBkColor(GUI_GRAY);
GUI_Clear();
GUI_DispStringAt(info, 0, 0);
WM_SelectWindow(hWin);
GUI_RestoreContext(&ContextOld);
#endif
}
#endif
void usbInit()
{
static int first_enter=1;
if(!first_enter)
return;
Isr_Init();
rMISCCR=rMISCCR&~(1<<3); // USBD is selected instead of USBH1
rMISCCR=rMISCCR&~(1<<13); // USB port 1 is enabled.
//
// USBD should be initialized first of all.
//
isUsbdSetConfiguration=0;
Uart_Printf("enter in umon2440\n");
UsbdMain();
Delay(0); //calibrate Delay()
pISR_SWI=(_ISR_STARTADDRESS+0xf0); //for pSOS
first_enter = 0;
}
static void GUI_TIMER_UpdateTime(/*const*/ GUI_TIMER_MESSAGE* pTM)
{
GUI_StoreKeyMsg(GUI_KEY_ENTER,1);
}
BOOL check_license_stored_and_valid()
{
int i;
U32 calc_crc;
// FMD_Init();
rsa_context rsa;
if ( !TOC_Read( ) ) {
// use default settings
TOC_Init(DEFAULT_IMAGE_DESCRIPTOR, (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS), 0, 0, 0);
return FALSE;
}
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]);
}
if((g_pTOC->license_signature != LICENSE_SIG)||(calc_crc!=g_pTOC->license_crc)||(g_pTOC->license_crc==0))
{
goto Cleanup;
}
else
{
uint len = 8+54*2;
memset(&rsa,0x00,sizeof(rsa));
rsa_init(&rsa);
if( rsa_pkcs1_decrypt_public( &rsa, g_pTOC->license_dat, 128,
output_decrypt, &len ) != 0)
{
rsa_free( &rsa );
goto Cleanup;
}
if(memcmp(output_decrypt,serial_num_rev,8)!=0)
{
rsa_free( &rsa );
goto Cleanup;
}
Uart_Printf("license is valid\n");
rsa_free( &rsa );
return TRUE;//
}
Cleanup:
{
CHAR ID[16+4];
char buffer[128];
int i;
GUI_TIMER_Handle hUpdateTimer;
for(i=0;i<4;i++)
{
ID[i*5+0]='A'+(serial_num[i*2]>>4);
ID[i*5+1]='Z'-(serial_num[i*2]&0x0F);
ID[i*5+2]='A'+(serial_num[i*2+1]>>4);
ID[i*5+3]='Z'-(serial_num[i*2+1]&0x0F);
ID[i*5+4]='-';
}
ID[19]=0;
sprintf(buffer,"You need Got a license from \nwww.allnicetech.com.cn \nwith the Device ID[%s]\n",ID);
hUpdateTimer=GUI_TIMER_Create(GUI_TIMER_UpdateTime, 0, (U32)&hUpdateTimer, 0);
GUI_TIMER_SetPeriod(hUpdateTimer, 100);
GUI_TIMER_Restart(hUpdateTimer);
GUI_MessageBox(buffer, "Warning", GUI_MB_OK);
}
return FALSE;
}
int umon_proc()
{
while(1)
{
isSerSetConfiguration = 0;
downloadFileSize = 0;
if(menuUsed==1)Menu();
WaitDownload();
}
}
void usbMain(void)
{
char *mode;
int i;
U8 key;
U32 mpll_val, divn_upll=0;
char buffer[100];
int FontDistY=GUI_GetFontDistY();
WM_ShowWindow(hTerm);
usbInit();
Led_Display(0x6);
#if USBDMA
mode="DMA";
#else
mode="Int";
#endif
// CLKOUT0/1 select.
//Uart_Printf("CLKOUT0:MPLL in, CLKOUT1:RTC clock.\n");
//Clk0_Enable(0); // 0:MPLLin, 1:UPLL, 2:FCLK, 3:HCLK, 4:PCLK, 5:DCLK0
//Clk1_Enable(2); // 0:MPLLout, 1:UPLL, 2:RTC, 3:HCLK, 4:PCLK, 5:DCLK1
Clk0_Disable();
Clk1_Disable();
#if 0
GUI_Clear();
mpll_val = rMPLLCON;
sprintf(buffer,"DIVN_UPLL%x",divn_upll);
GUI_DispStringAt(buffer, 0,0);
sprintf(buffer,"MPLLVal [M:%xh,P:%xh,S:%xh]\n", (mpll_val&(0xff<<12))>>12,(mpll_val&(0x3f<<4))>>4,(mpll_val&0x3));
GUI_DispStringAt(buffer, 0,1*FontDistY);
sprintf(buffer,"CLKDIVN:%xh\n", rCLKDIVN);
GUI_DispStringAt(buffer, 0,2*FontDistY);
GUI_DispStringAt("+----------------------------------------+",0,4*FontDistY);
GUI_DispStringAt("| S3C2440A USB Downloader ver R0.03 |\n",0,5*FontDistY);
sprintf(buffer, "| build date:%s time:%s |",__DATE__,__TIME__);
GUI_DispStringAt(buffer,0,6*FontDistY);
GUI_DispStringAt("+----------------------------------------+",0,7*FontDistY);
sprintf(buffer,"FCLK=%4.1fMHz,%s mode\n",FCLK/1000000.,mode);
GUI_DispStringAt(buffer, 0,8*FontDistY);
GUI_DispStringAt("USB: IN_ENDPOINT:1 OUT_ENDPOINT:3",0,9*FontDistY);
GUI_DispStringAt("FORMAT: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>",0,10*FontDistY);
GUI_DispStringAt("NOTE: 1. Power off/on or press the reset button for 1 sec",0,11*FontDistY);
GUI_DispStringAt(" in order to get a valid USB device address.",0,12*FontDistY);
GUI_DispStringAt(" 2. For additional menu, Press any key. \n",0,13*FontDistY);
#else
mpll_val = rMPLLCON;
Uart_Printf("DIVN_UPLL%x\n", divn_upll);
Uart_Printf("MPLLVal [M:%xh,P:%xh,S:%xh]\n", (mpll_val&(0xff<<12))>>12,(mpll_val&(0x3f<<4))>>4,(mpll_val&0x3));
Uart_Printf("CLKDIVN:%xh\n", rCLKDIVN);
Uart_Printf("\n\n");
Uart_Printf("+---------------------------------------------+\n");
// Uart_Printf("| S3C2440A USB Downloader ver R0.03 2004 Jan |\n");
Uart_Printf(SIGN_ON);
Uart_Printf("+---------------------------------------------+\n");
Uart_Printf("FCLK=%4.1fMHz,%s mode\n",Fclk/1000000.,mode);
Uart_Printf("USB: IN_ENDPOINT:1 OUT_ENDPOINT:3\n");
Uart_Printf("FORMAT: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>\n");
Uart_Printf("NOTE: 1. Power off/on or press the reset button for 1 sec\n");
Uart_Printf(" in order to get a valid USB device address.\n");
Uart_Printf(" 2. For additional menu, Press any key. \n");
Uart_Printf("\n");
#endif
// NF_Init();
download_run=1; //The default menu is the Download & Run mode.
menuUsed=1;
#if 0
WM_SetCreateFlags(WM_CF_MEMDEV); /* Automatically use memory devices on all windows */
/* Calculate position and size of FrameWin[1] */
FrameWinSizeX = 240;
FrameWinSizeY = 100;
FrameWinPosX = LCD_GetXSize() - FrameWinSizeX;
FrameWinPosY = LCD_GetYSize() - FrameWinSizeY;
ButtonSizeX = (FrameWinSizeX - 20) / 2;
ButtonSizeY = 20;
/* Create the control window incl. buttons */
_usbhFrameWin = FRAMEWIN_Create("Select Menu", NULL, WM_CF_SHOW | WM_CF_STAYONTOP,
FrameWinPosX, FrameWinPosY,
FrameWinSizeX, FrameWinSizeY);
_usbhInfoWin = WM_GetClientWindow(_usbhFrameWin);/*WM_CreateWindowAsChild(0, 0, 0, 0, _usbhFrameWin,
WM_CF_SHOW | WM_CF_STAYONTOP, 0, 0);*/
_usbhButton[0] = BUTTON_CreateAsChild(FrameWinSizeX / 20,
+ 15, ButtonSizeX, ButtonSizeY, _usbhFrameWin,
'0' , WM_CF_SHOW | WM_CF_STAYONTOP | WM_CF_MEMDEV);
_usbhButton[1] = BUTTON_CreateAsChild(FrameWinSizeX / 20,
+ 40, ButtonSizeX, ButtonSizeY, _usbhFrameWin,
'1' , WM_CF_SHOW | WM_CF_STAYONTOP | WM_CF_MEMDEV);
_usbhButton[2] = BUTTON_CreateAsChild(FrameWinSizeX / 20,
+ 65, ButtonSizeX, ButtonSizeY, _usbhFrameWin,
'2' , WM_CF_SHOW | WM_CF_STAYONTOP | WM_CF_MEMDEV);
BUTTON_SetText(_usbhButton[0], "Download & Run");
BUTTON_SetText(_usbhButton[1], "Download Only");
BUTTON_SetText(_usbhButton[2], "eboot usb");
_UpdateCmdWin(_usbhInfoWin, "usb start");
WM_ExecIdle();
#endif
hFrameWin = FRAMEWIN_Create("Upgrade image from SD", NULL, WM_CF_HIDE|WM_CF_STAYONTOP|WM_CF_MEMDEV,
10, 100, 300, 40);
hProgBar=PROGBAR_CreateEx(10, 5, 280, 15,hFrameWin,1, WM_CF_HIDE|WM_CF_STAYONTOP|WM_CF_MEMDEV);
//hProgBar=PROGBAR_Create(10, 100, 300, 20, WM_CF_SHOW|WM_CF_STAYONTOP|WM_CF_MEMDEV);
PROGBAR_SetBarColor(hProgBar, 0, GUI_BLUE);
PROGBAR_SetBarColor(hProgBar, 1, GUI_LIGHTGRAY);
Show_ExecKeyboard(umon_proc,1);
// WM_DeleteWindow(_usbhFrameWin);
}
U32 gBlockIndex=2;
char * _strupr(char *pstr) {
/* Performance note: use unsigned char on RISC machines to avoid sign extension in 4-byte regs. */
char *pTrav;
for (pTrav = pstr; *pTrav; pTrav++)
*pTrav = toupper(*pTrav);
return pstr;
}
FS_FILE *SelectFile()
{
FS_FILE *fp=NULL;
FS_DIR *dirp;
int i,file_num=0;
struct FS_DIRENT *direntp;
char file_name_array[512][16];
char currfilename[256];
Uart_Printf("Directory of \\\n");
dirp = FS_OpenDir("");
if (dirp) {
do {
direntp = FS_ReadDir(dirp);
if (direntp) {
strcpy(file_name_array[file_num],direntp->d_name);
file_num++;
if(file_num%3==0)
Uart_Printf("%s\n",direntp->d_name);
else
Uart_Printf("%s ",direntp->d_name);
}
} while (direntp);
FS_CloseDir(dirp);
Uart_Printf("\nPlease Select a file\n");
Uart_GetString(currfilename);
_strupr(currfilename);
for(i=0;i<file_num;i++)
{
if(strstr(file_name_array[i],currfilename))
break;
}
if(i<file_num)
{
fp=FS_FOpen(file_name_array[i],"rb");
if(fp)
{
Uart_Printf("Open file %s Successful\n",file_name_array[i]);
}
}
else
fp=FS_FOpen(currfilename,"rb");
}
return fp;
}
int upgrade_keyproc()
{
int KeySelect = 0;
U32 block_index[]={NBOOT_BLOCK,0,TOC_BLOCK,0};
// char *file_name[]={"nboot.bin","eboot.bin","license.dat","bkscn.bmp"};
// char *currfilename;
block_index[1] = EBOOT_BLOCK;
block_index[3] = BOOT_PICTURE_BLOCK;
while(1)
{
KeySelect = 0;
// GUI_Clear();
Uart_Printf ( "\r\nDownload and Save:\r\n");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -