📄 main.c
字号:
#include "2440addr.h"
#include "Port.h"
#include "Clock_PLL.h"
#include "UART.h"
#include "SD.h"
#include "Fat.h"
#include "PaRAM.h"
#include <string.h>
#include <stdlib.h>
volatile struct
{
unsigned char Name[8];
unsigned char Point[1];
unsigned char Ext[3];
unsigned char FullName[12];
}Kernel;
//////////////////////////////////////////////////////////
#define Boot_Linux 1 //
unsigned int Linux_RunningBase = 0x30008000; //
unsigned int RamDisk_RunningBase = 0x30800000; //
unsigned int Linux_ParamsBase = 0x30000100; //
//////////////////////////////////////////////////////////
#define Boot_Wince 0 //
unsigned int EBoot_RunningBase = 0x30038000; //
unsigned int WinCE_RunningBase = 0x30200000; //
//////////////////////////////////////////////////////////
void Call_OS(unsigned int Zero,unsigned int Machine_Type,unsigned int Kernel_Params_Base,unsigned int RunningBase)
{
void (*run)(void);
__asm
{
MOV R0,Zero
MOV R1,Machine_Type
MOV R2,Kernel_Params_Base
}
run=(void(*)(void))RunningBase;
run();
}
int main(void)
{
unsigned int i;
//char *linuxC;
Port_Init();
ChangeMPllValue(92,1,1); //200MHz
ChangeUPllValue(120,2,3); //48MHz
Get_cpu_bus_clk();
Uart_Init(115200); //配置串口0
Uart_Printf(0,"=================================\n");
Uart_Printf(0,"= =\n");
Uart_Printf(0,"= This is CANA'S BootLoader. =\n");
Uart_Printf(0,"= =\n");
Uart_Printf(0,"=================================\n");
SD_card_init(); //初始化SD卡
if(Fat_Init()) //初始化FAT文件系统
{
Uart_Printf(0,"FAT FileSystem is Ready!\n\n");
}
else
{
Uart_Printf(0,"FAT FileSystem is Bad!!!\n");
while(1);
}
#if 1==0
Uart_Printf(0,"List BootDir.\n");
DIR(); //列出根目录文件
Uart_Printf(0,"Enter CANA.\n");
i=CD((unsigned char *)"CANA"); //进入 CANA 文件夹
Uart_Printf(0,"List CANA.\n");
DIR(); //列出 CANA 文件夹里面的文件
Uart_Printf(0,"Back to BootDir.\n");
i=CD((unsigned char *)".."); //返回上一层,即根目录
Uart_Printf(0,"List BootDir.\n");
DIR(); //列出根目录文件
#endif
////////////////////////////////////////////////////////////////////////
//linuxC=ReadCmd((unsigned char *)"CmdLine",(unsigned char *)"ini");
//Uart_Printf(0,"linux command line is: \"%s\"\n\n", linuxC);
//while(1);
////////////////////////////////////////////////////////////////////////
#if Boot_Linux
/////////////////////////////////////////////////////////////
i=CD((unsigned char *)"Linux"); //进入 Linux 文件夹
//加载内核
Uart_Printf(0,"Load Kernel ...\n");
if(LoadFile((unsigned int *)Linux_RunningBase,(unsigned char *)"zImage",(unsigned char *)"bin"))
{
Uart_Printf(0,"Done!\n\n");
}
else
{
Uart_Printf(0,"Copy Linux Kernel ...... Fail!\nAnd death here!!!\n");
while(1);
}
/////////////////////////////////////////////////////////////
//加载RAMDISK文件系统
Uart_Printf(0,"Now,Load FileSystem ...\n");
if(LoadFile((unsigned int *)RamDisk_RunningBase,(unsigned char *)"RamDisk",(unsigned char *)"img"))
{
Uart_Printf(0,"Done!\n\n");
}
else
{
Uart_Printf(0,"Fail!And death here!!!\n");
while(1);
}
/////////////////////////////////////////////////////////////
//加载启动参数
setup_linux_param(Linux_ParamsBase);
/////////////////////////////////////////////////////////////
Uart_Printf(0,"Run Kernel ......\n\n");
Call_OS(0,193,Linux_ParamsBase,Linux_RunningBase);
/////////////////////////////////////////////////////////////
#endif
#if Boot_Wince
/////////////////////////////////////////////////////////////
Uart_Printf(0,"Now,Load EBoot ...\n");
if(LoadFile((unsigned int *)(EBoot_RunningBase),(unsigned char *)"EBoot",(unsigned char *)"nb0"))
{
Uart_Printf(0,"Done!\n");
}
else
{
Uart_Printf(0,"Fail!And death here!!!\n");
while(1);
}
/////////////////////////////////////////////////////////////
/* Uart_Printf(0,"Now,Load WinCE ...\n");
if(LoadFile((unsigned int *)(WinCE_RunningBase),(unsigned char *)"WinCE",(unsigned char *)"nb0"))
{
Uart_Printf(0,"Done!\n");
}
else
{
Uart_Printf(0,"Fail!And death here!!!\n");
while(1);
}*/
/////////////////////////////////////////////////////////////
Uart_Printf(0,"Run EBoot ......\n");
Call_OS(0,193,Linux_ParamsBase,EBoot_RunningBase);
/////////////////////////////////////////////////////////////
#endif
while(1)
{
//rGPBDAT ^= 0x01;
for(i=0;i<2000;i++);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -