BT_ERROR BT_ShellScript(const BT_i8 *path) { BT_ERROR Error; BT_HANDLE hFile = BT_Open(path, "rb", &Error); if(!hFile) { BT_kPrint("Could not open shell script %s\n", path); return BT_ERR_GENERIC; } BT_i8 *line = BT_kMalloc(256); if(!line) { BT_CloseHandle(hFile); return BT_ERR_NO_MEMORY; } BT_u32 linelen; while((linelen = BT_GetS(hFile, 256, line)) > 0) { BT_i8 *p = line; while(isspace((int) *p)) { p++; } if(*p == '#') { continue; // commented line! } if(p == (line + linelen)) { continue; } Error = BT_ShellCommand(p); } BT_kFree(line); BT_CloseHandle(hFile); return BT_ERR_NONE; }
int main(void) { BT_ERROR Error; BT_HANDLE hUART = BT_DeviceOpen("uart1", &Error); uart_config(hUART); BT_UartEnable(hUART); BT_SetStandardHandle(hUART); BT_kPrint("BootThunder started..."); BT_HANDLE hVolume = BT_DeviceOpen("mmc00", &Error); while(!hVolume) { BT_ThreadSleep(5); hVolume = BT_DeviceOpen("mmc00", &Error); } BT_Mount(hVolume, "/sd0/"); signal_booted(); Error = BT_ShellScript("/sd0/boot.cfg"); if(Error) { BT_kPrint("No kernel shell script found, jumping to terminal shell"); } // If we got here then script wasn't found, or didn't boot! Create a shell. sprintf(buffer, "boot --core 0 %08x", jtag_loop); BT_ShellCommand(buffer); while(1) { BT_ThreadSleep(1000); } return 0; }