📄 booter.c
字号:
#include "booter.h"#include "example.h"#include "util.h"#include "filesystem.h"#include "flash.h"#include "srec.h"#include "elf.h"#include "bin.h"#include "pcmcia.h"#include "util.h"#ifdef LCD_STATUS#include "lcd_control.h"#endif#define APP_NAME "AutoBoot"#define APP_REVISION "01.02"void displayWelcomeScreen(){ printf("\n\n%s, Revision %s\n", APP_NAME, APP_REVISION); #ifdef _LCD_OUTPUT_ lcdDisplayWelcomeScreen(); #endif}void displayNoImage(){ printf("Unable to locate any bootable images\n"); #ifdef _LCD_OUTPUT_ lcdDisplayNoImage(); #endif}void displayEntryPoint(void* entryPoint){ printf("Program Entry Point: %X\n", entryPoint); printf("Executing Application\n"); #ifdef _LCD_OUTPUT_ lcdDisplayEntryPoint(entryPoint); #endif}char * t_argv[] = {0};#ifdef SECUREBOOTchar * t_envp[] = {"MAC=0","bootfile=/booter.rec","bootprot=tftp","bootserport=tty0","bootserver=192.168.0.1","ethaddr=00.00.1a.19.0b.f7","gateway=192.168.0.1","ipaddr=192.168.0.2","memsize=0x08000000","modetty0=115200,n,8,1,none","modetty1=115200,n,8,1,none","prompt=YAMON","subnetmask=255.255.255.0",0,};#elsechar * t_envp[] = {0};#endifint execute(void* address, int argc, char* argv[], char* env[]){ typedef int(*EXECUTE)(int, char**, char**); EXECUTE executeFunction = (EXECUTE) address; if( argc == NULL) { argc = 1; argv = t_argv; env = t_envp; } cpuDisableIrqs(); return executeFunction(argc, (char**) argv, (char**) env);}void* findImage(const char** files, const char** addresses, void* jumpAddress){ void* entryPoint;#if defined(CONFIG_HWBLOCK_SD) (entryPoint = loadSDMS (files)) ||#endif#if defined(CONFIG_HWBLOCK_PCMCIA) (entryPoint = loadPCMCIA(files)) ||#endif#if defined(CONFIG_HWBLOCK_IDE) (entryPoint = loadIDE(files)) ||#endif#if defined(CONFIG_HWBLOCK_NOR_FLASH) // | defined(CONFIG_HWBLOCK_NAND_FLASH) (entryPoint = loadFlash(addresses)) ||#endif (entryPoint = jumpAddress); return entryPoint;}void* loadImage(DataFunctions functions, const char* fileName){ void* entryPoint; if( (entryPoint = binLoadImage(functions, fileName)) || (entryPoint = srecLoadImage(functions, fileName)) || (entryPoint = elfLoadImage(functions, fileName)) ) return entryPoint; return (void*) 0;}#if defined(CONFIG_HWBLOCK_NOR_FLASH) | defined(CONFIG_HWBLOCK_NAND_FLASH)void* loadFlash(const char** addresses){ int i; void* entryPoint = 0; for(i = 0; addresses[i] != 0 && !entryPoint; ++i) { if(addresses[i][0] == 'N') //Nand image { #ifdef CONFIG_HWBLOCK_NAND_FLASH entryPoint = loadImage(getNandFunctions(), addresses[i]); #endif } else entryPoint = loadImage(getFlashFunctions(), addresses[i]); } return entryPoint;}#endif#if defined(CONFIG_HWBLOCK_PCMCIA)void* loadPCMCIA(const char** files){ int i, j, slots; void* entryPoint = 0; for(i = 0; i < 2 && !entryPoint; ++i) { if(filesystemLoad(PCMCIA, i)) for(j = 0; files[j] != 0 && !entryPoint; ++j) entryPoint = loadImage(getFilesystemFunctions(), files[j]); filesystemClose (PCMCIA, i); } return entryPoint;}#endif#if defined(CONFIG_HWBLOCK_IDE)void* loadIDE(const char** files){ int i, j, disks; void* entryPoint = 0; if(filesystemLoad(IDE, 0)) for(j = 0; files[j] != 0 && !entryPoint; ++j) entryPoint = loadImage(getFilesystemFunctions(), files[j]); filesystemClose (IDE, 0); return entryPoint;}#endif#if defined(CONFIG_HWBLOCK_SD)void* loadSDMS (const char** files){ int i, j, slots; void* entryPoint = 0; for (i = 0; i < 2 && !entryPoint; ++i) { if (filesystemLoad (SDMS, i)) for (j = 0; files[j] != 0 && !entryPoint; ++j) entryPoint = loadImage (getFilesystemFunctions (), files[j]); filesystemClose (SDMS, i); } return entryPoint;}#endifvoid* loadBootImage(){ const char** files; const char** addresses; void* jumpAddress;#ifdef SECUREBOOT if(HSSGetBootData(&files, &addresses, &jumpAddress))#else if(platformGetBootData(&files, &addresses, &jumpAddress))#endif { //printf("files: %X, address: %X, jump: %X\n", files, addresses, jumpAddress); return findImage(files, addresses, jumpAddress); }}int main(int argc, char* argv[], char* env[]){ void* entryPoint; displayWelcomeScreen();#ifdef SECUREBOOT if(authenticate()) return(1); /* authentication failed */#endif while(!(entryPoint = loadBootImage())) { displayNoImage(); return 0; usdelay(10000); } displayEntryPoint(entryPoint); return execute(entryPoint, argc, argv, env);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -