⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 44box的bootloader原代码及其分析。
💻 C
字号:
#include <string.h>#include ".\Target\option.h"#include ".\Target\def.h"#include ".\Target\44b.h"#include ".\Target\44blib.h"#include ".\usb\usbdrv.h"#include ".\usb\Usb_reg.h"#include ".\fat16\fat16.h"#include ".\flashtest\flash.h"//////////////////board test/////////////////////#include ".\armsystest\Nandflash.h"#include ".\armsystest\rtc.h"#include ".\armsystest\keyboard.h"#include ".\armsystest\eint.h"#include ".\armsystest\iic.h"#include ".\armsystest\adc.h"#include ".\armsystest\lcd.h"#include ".\armsystest\touch.h"#include ".\armsystest\timer.h"#include ".\armsystest\uart.h"//#include ".\tcpipsrc\ping.h"extern void Ping_test(void);#include <stdio.h>void __irq MEint4567Isr(void);void (*runinram)(void)=(void (*)(void))RAM_ADDRESS;extern byte USBN9604_init(void);volatile byte code_loaded=0;volatile byte flash_exist=1;volatile byte filesys_exist=0;volatile char exeLoadedcode=0;volatile char Mwhich_int=0;volatile byte save_file=0;INT32U ram_addr=RAM_ADDRESS;INT32U src_addr,des_addr,length;int Uart_Getaddress(char *str,  INT32U *address);//////////////test function///////////////////////void * function[][2]={	(void *)Read_ID,	      "Nandflash-Read ID",	(void *)Test_Iic,	  	  "IIC(24LCxx)-Test ",	(void *)Display_Rtc,	  "RTC-Display      ",	(void *)Keyboard_test,  "Keyboard-Test    ",	(void *)Test_Eint,		  "Ext.Int-Test     ",	(void *)Test_Adc,		    "ADC-Test         ",	(void *)Test_TimerInt,  "Timer.Int-Test   ",	(void *)Test_LCD,		    "LCD-Test         ",	(void *)Test_Touch,		  "TouchScreen-Test ",	(void *)Ping_test,	    "Ping diagnose tool",	//(void *)Test_Uart0,     "UART0-Test       ",	0,0};int Main(void){	int handle,i=0,j=0,time,breakflag;        char aa=0;	char *buff,argv[256];	char addrbuf[4];	unsigned short nandflashid;		rSYSCFG=CACHECFG;// Using 8KB Cache//	Port_Init();	Uart_Init(0,115200);		Beep(0x01);	Led_Display(0xf);	Delay(0);		Uart_Select(0); //Select UART0//	Uart_Printf("\n---------------------------------------------------------------");	Beep(0x00);	Uart_Printf("\nOEM name   :     HangZhou LiYuTai elec. www.hzlitai.com.cn      ");	Uart_Printf("\nFunction   :     ARMSys's BootLoader for Linux                  ");	Uart_Printf("\nEmail      :     support@hzlitai.com.cn                         ");	Uart_Printf("\nUART comfig:     115.2kbps,8Bit,NP,UART0                       ");	Uart_Printf("\nusing USB  :     Yes                                            ");		nandflashid=Check_Flash_Id();	if(nandflashid==0xec73)	    Uart_Printf("\nNand-flash :     K9F2808                                       ");	else if(nandflashid==0xec75)	    Uart_Printf("\nNand-flash :     K9F5608                                       ");	else	{ 	    Uart_Printf("\nNand-flash :     None                                    ");	    flash_exist=0;	}	    	Led_Display(0x0);	Uart_Printf("\nInitializing system... ...");		if(flash_exist)	{	    if(fatInit()==0)//如果文件系统存在,就可以通过exint4~6键启动保存的程序,或通过exint7键设置保存file模式	    {	     /* Uart_Printf("\n---------------------------------------------------------------");	        Uart_Printf("\n按下EXINTx键自动进入对应功能:     ");	        Uart_Printf("\nEXINT4:");	        Uart_Printf("\nEXINT5:载入uClinux运行.");	        Uart_Printf("\nEXINT6:载入保存在Nandflash中的程序并运行(仅用于从0xc000000运行).");	        Uart_Printf("\nEXINT7:准备好将从USB口下载的程序保存到Nandflash。\n等待按键");	     */	        filesys_exist=1;	    	    	  rINTCON=0x1;//disable fiq, enable irq	        pISR_EINT4567=(int)MEint4567Isr;		        rPCONG|=0xff00;	//EINT7~0	        rPUPG=0x0;		//pull up enable	  	        rEXTINT=0x22222222; //Falling edge mode 	        rINTMSK&=~(BIT_GLOBAL|BIT_EINT4567); 		        while((i<10)&&(exeLoadedcode==0))	        {	          	Delay(1500); 	        	  Uart_Printf(" ...");	            i++;	         }	        if(exeLoadedcode)		      {	    	       switch(Mwhich_int)               {	              case 1:	              case 3:	              case 5:	              case 7:	                  break;	              case 2:	                  Uart_Printf("\nStart uClinux...\n");		                ram_addr=0x10000;		                ((void (*)(void))ram_addr)();	                  break;	              case 4:                    Uart_Printf("EXINT5/EXINT6 is Pressed!  ");		                handle=fat_open("\\code\\44bapp.bin");			  						if((handle==(-1))||(handle==(-2)))										{				              Uart_Printf("\nOpen 44bapp.bin failed!");			                //return -1;			              }										else										{											buff=(char *)RAM_ADDRESS;											fat_read(handle, buff, 0x5f0000);											fat_close(handle);											Uart_Printf("\nCompleted download, turn to execute the code!\n");											Delay(1000);  //it should be delay a long time for pc software stable											runinram();										}										break;		      			case 8:		       				 	save_file=1;		        				break;			   				}//switch		      }//if(exe...)		  }//if(fatinit...)   }//if(flash_...)//==================================================================================================        while(1)  {  	breakflag=0;  	code_loaded=0;		Uart_Printf("\n---------------------------------------------------------------");		Uart_Printf("\n1.Use USB-downloader download code to SDRAM.");		Uart_Printf("\n2.Use USB-downloader download code to SDRAM & Nandflash.");		Uart_Printf("\n3.Use USB-downloader burn flashROM.");		Uart_Printf("\n4.Copy code from flashROM to SDRAM.");		Uart_Printf("\n5.Run at specify address.");		Uart_Printf("\n6.Run code in Nandflash.");		Uart_Printf("\n7.Start uClinux.");		Uart_Printf("\n8.Format Nandflash.");		Uart_Printf("\n9.Test hardware");	aa = Uart_Getch();	switch(aa)	{		case '2':		    if(filesys_exist==1)		      save_file=1;		    else		    {		      Uart_Printf("\nError: Nandflash has not been formatted!");		      break;		    }		case '1':			Uart_Printf("\nInput the address to put the code (Default address is 0xc008000):");		       while(Uart_Getaddress(argv,&ram_addr));					   								if(USBN9604_init())		  {		        Uart_Printf("\nReset the USB controller failed, active USB interface failed.");				return 1;			}			else			{				Uart_Printf("\nUSB Interface is active!\nYou can use USBdownload.exe to download *.bin file!");			}		       rINTCON=0x5;//fiq disable			while (!code_loaded);			Uart_Printf("\nCompleted Download!");		    break;		case '3':		    Uart_Printf("\n\nPlease refer 3 step below and use function 1&5 to program flash:");		    Uart_Printf("\nStep1: Download *.bin (the binary code you want to burn to flash) to address 0x0c200000.");		    Uart_Printf("\nStep2: Download flashpgm.bin to 0x0c008000.");		    Uart_Printf("\nStep3: Run at address 0x0c008000.\n");		    break;		case '4':		    Uart_Printf("\nInput source address:");		    while(Uart_Getaddress(argv,&src_addr));		    Uart_Printf("\nInput destination address:");		    while(Uart_Getaddress(argv,&des_addr));		    Uart_Printf("\nInput the length (BYTE):");		    while(Uart_Getaddress(argv,&length));		    Uart_Printf("\nDo you confirm to copy? (Y/N)");		    aa = Uart_Getch();		    if((aa=='Y')||(aa=='y'))		    {		        Uart_Printf("\nBegin copy ...");		        j=1;		        for(i=0;i<length;i++)		           *(unsigned char *)des_addr++ = *(unsigned char *)src_addr++;		        if((i%0x100)==0)		        {		           Led_Display(j);		           j<<1;		           if(j==0x10)		           j=1;		        }		        Uart_Printf("\nComplete copy.");		   }		         		    break;	  case '5':		    Uart_Printf("\nInput the address (Default address is 0xc008000):");		    ram_addr=RAM_ADDRESS;		    while(Uart_Getaddress(argv,&ram_addr));								   			    		    Uart_Printf("\nPlese wait a moment to start running...");		    /*对USBN9603进行一次软件复位*/		    write_usb(MCNTRL, SRST);		    Delay(1000);//it should be delay a long time for pc software stable		    ((void (*)(void))ram_addr)();		    break;		case '6':	       write_usb(MCNTRL, SRST);         Delay(1000);//it should be delay a long time for pc software stable		     if((flash_exist==1) && (filesys_exist==1))		     {						handle=fat_open("\\code\\44bapp.bin");						if((handle==(-1))||(handle==(-2)))						{						    Uart_Printf("\nOpen 44bapp.bin file faild!");						    //return -1;						}						else						{	              Uart_Printf("\nInput the running address (Default address is 0xc008000):");								ram_addr=RAM_ADDRESS;								while(Uart_Getaddress(argv,&ram_addr));								   														buff=(char *)ram_addr;//RAM_ADDRESS;								i=fat_read(handle, buff, 0x5f0000);								i=fat_close(handle);													Uart_Printf("\nComplete download, turn to execute the code!\n");								Delay(1000);//it should be delay a long time for pc software stable								((void (*)(void))ram_addr)();////////runinram();						}		    }		    break;		 case '7':		    Uart_Printf("\nLoad image.rom...\n");		    src_addr=0x20000;		    des_addr=0xc100000;		    for(i=0;i<0xdffff;i++)		           *(unsigned char *)des_addr++ = *(unsigned char *)src_addr++;		    Uart_Printf("\nLoad romfs.img...\n");		    src_addr=0x100000;		    des_addr=0xc500000;		    for(i=0;i<0xf0000;i++)		           *(unsigned char *)des_addr++ = *(unsigned char *)src_addr++;		    Uart_Printf("\nStart uClinux\n");		    ram_addr=0xc100000;		    ((void (*)(void))ram_addr)();		 case '8':				    if(flash_exist)		    {	          Uart_Printf("\nThe content in Nandflash will be lost, confirm to format?(Y/N)");	          aa= Uart_Getch();	          if((aa=='Y')||(aa=='y'))            {               fat_format(NAND_FLASH_Drv,16,0x06);               filesys_exist=1;            }	       }         else            Uart_Printf("\nCan't find Nandflash!"); 		   break; 		case '9': 			 //Uart_Printf("\nUSB接口失效。");			 /*对USBN9603进行一次软件复位*/			 write_usb(MCNTRL,SRST);				 Delay(1000);//it should be delay a long time for pc software stable			 //Functions test				while(1)				{			      i=0;						Uart_Printf("\n\n");						while(1)						{   //display menu							Uart_Printf("%2d:%s",i+1,function[i][1]);							i++;							if((int)(function[i][0])==0)							{								Uart_Printf("\n");								break;							}							if((i%2)==0)								Uart_Printf("\n");						}						Uart_Printf("\nSelect the function to test?(Press Reset button to restart)");						i=Uart_GetIntNum();						i--;						Uart_Printf("\n");						if(i>=0 && (i<(sizeof(function)/8)) ) 							( (void (*)(void)) (function[i][0]) )();			     }	         break;         }//switch    }//while (1)	return 0;}void __irq MEint4567Isr(void){    rINTMSK|=(BIT_GLOBAL|BIT_EINT4567);    exeLoadedcode=1;    Mwhich_int=rEXTINTPND;    rEXTINTPND=0x0f;		//clear EXTINTPND reg.		    rI_ISPC=BIT_EINT4567;	//clear pending_bit    rINTMSK&=~(BIT_GLOBAL|BIT_EINT4567); }int Uart_Getaddress(char *str, INT32U *address){  char aa;  char *buff;  INT32U tempaddress=RAM_ADDRESS;  int result=0;  buff=str;  Uart_GetString(buff);  buff=str;    while(*buff++!='\0')	  {	      aa=*buff;	      result=0;		if(aa=='x'||aa=='X')		{	        tempaddress=0;	        buff++;	        result=0;			while(*buff!='\0')			{		           		     aa=*buff;		     buff++;		     if((aa>=0x30)&&(aa<=0x39))          /* Destination IP address */		     {		       	  aa=aa-'0';		     }			   else if ((aa>='A')&&(aa<='F'))			   {				  aa=aa-'A'+10;			   }			   else if((aa>='a')&&(aa<='f'))			   {				  aa=aa-'a'+10;			   }			   else			   {			   	result=-1;			   	break;			   }			   tempaddress=(tempaddress<<4)+aa;			}		}			   }	   if(result!=0)	   {				Uart_Printf("\nPlease input Hex value, example: 0xc008000\n");				result=-1;	   }	   *address=tempaddress;	   return(result);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -