📄 bootmenu.c.v1
字号:
/***************************************** Copyright (c) 2001-2002 Sigma Designs, Inc. All Rights Reserved Proprietary and Confidential *****************************************//* This file is part of the Jasper DVD boot loader *//* * bootmenu.c * * process loader menu loop * * first revision by Ho Lee 10/10/2002 * configuration support by Ho Lee 10/30/2002 */#include "config.h"#include "uart.h"#include "util.h"#include "specific.h"#include "bootconfig.h"#include "timer.h"#include "io.h"#include "flash.h"#include "net.h"#include "net_ipv4.h"#ifdef SUPPORT_BOOT_MENU#define BOOTPROMPT "boot> "//// external function// // from bootflash.cunsigned int try_boot_flash(unsigned int kload, unsigned int addr);// from main.cunsigned int try_boot_disc_pass(unsigned int kload, int pass);// from uucodec.cint serial_uudecode(unsigned char *buf, int maxlen);// // each menu functions//int bootmenu(unsigned int kload);int bootmenu_command(char *_str, unsigned int kload);int bootmenu_help(int argc, char *argv[], unsigned int kload);int bootmenu_boot(int argc, char *argv[], unsigned int kload);int bootmenu_config(int argc, char *argv[], unsigned int kload);int bootmenu_download(int argc, char *argv[], unsigned int kload);int bootmenu_dump(int argc, char *argv[], unsigned int kload);int bootmenu_flash(int argc, char *argv[], unsigned int kload);int bootmenu_mem(int argc, char *argv[], unsigned int kload);int bootmenu_memcmp(int argc, char *argv[], unsigned int kload);int bootmenu_memcpy(int argc, char *argv[], unsigned int kload);int bootmenu_net(int argc, char *argv[], unsigned int kload);int bootmenu_update(int argc, char *argv[], unsigned int kload);int bootmenu_net_up(int force);void dump_memory(void *memptr, unsigned int addr, int num, int unit);int bootmenu_mtest (int argc, char *argv[], unsigned int kload);//// command table//static char s_help_help_brief[] = " help : show list of commands\r\n" " help [command] : help on command\r\n";static char s_help_help[] = ""; static char s_help_boot_brief[] = " boot [target] : boot kernel\r\n";static char s_help_boot[] = " flash : boot from flash (0x00006000)\r\n" " kernel : boot kernel on RAM (0x01008000)\r\n"#ifdef SUPPORT_BOOT_FROM_CD " cd : boot from CD\r\n"#endif " [addr] : jump to specified address\r\n" ; static char s_help_config_brief[] = " config <name> [options] : configure boot loader\r\n";static char s_help_config[] = " load : load configuration\r\n" // " save : save configuration\r\n" " serial <baudrate> : UART configuration\r\n" " valid baud rate : 9600, 19200, 38400 (default), 57600, 115200\r\n"#ifdef SUPPORT_NETWORK " net : network configuration\r\n" " file : download filename setting\r\n"#endif ;static char s_help_download_brief[] = " download [media] <target> : download image via various media\r\n";static char s_help_download[] = " [media] : serial"#ifdef SUPPORT_NETWORK " / net (network)\r\n"#endif " <target> : boot / romfs / kernel / [addr]\r\n" ;static char s_help_dump_brief[] = " dump [option] <addr> <len> : dump memory area\r\n";static char s_help_dump[] = " [option] : -d (4 bytes), -w (2 bytes), -b (1 byte)\r\n" ;#ifdef SUPPORT_FLASH static char s_help_flash_brief[] = " flash [command] <options> : flash commands\r\n"; static char s_help_flash[] = " probe <addr> : probe flash\r\n" " list : show flash chip information\r\n" " erase [addr] <len> : erase one or more sectors of flash memory\r\n" " eraseall : erase all flash memory\r\n" " writeb [addr] [data] : write one byte of data into specified address\r\n" " writew [addr] [data] : write one word of data into specified even address\r\n" " write [to] [from] [len] : write block of data into specified address\r\n" " boot : write boot loader image on RAM into FLASH\r\n" " romfs : write ROMFS image on RAM into FLASH\r\n" ;#endifstatic char s_help_mem_brief[] = " mem [op] <args> : read from or write to memory\r\n";static char s_help_mem[] = " rb [addr] : read one byte of data\r\n" " rw [addr] : read two bytes of data\r\n" " rl [addr] : read four bytes of data\r\n" " wb [addr] [data] : write one byte of data\r\n" " ww [addr] [data] : write two bytes of data\r\n" " wl [addr] [data] : write four bytes of data\r\n" ;static char s_help_memcmp_brief[] = " memcmp [addr1] [addr2] <len> : compare memory region\r\n";static char s_help_memcmp[] = "";static char s_help_memcpy_brief[] = " memcpy [to] [from] <len> : copy memory region\r\n";static char s_help_memcpy[] = "";#ifdef SUPPORT_NETWORKstatic char s_help_net_brief[] = " net [command] <args> : network commands\r\n";static char s_help_net[] = " config : show current network configuration\r\n" " up : enable networking\r\n" " down : disable networking\r\n" " arp : show entire ARP table\r\n" " arp [IP addr] : get the hardware address of specfied host\r\n" " ping [IP addr] : send ICMP echo message to specified host\r\n" " dhcp : request DHCP\r\n" " tftp [loader/romfs/kernel] : download via TFTP from server\r\n" " tftp [IP addr] [filename] : download specified file from specified server\r\n" " eeprom [command] : manipulate EEPROM connected to Ethernet chipset\r\n" " dump : dump EEPROM contents\r\n" " ww [reg] [data] : update EEPROM contents\r\n" " dump : dump ethernet RX buffer contents\r\n" ;#endifstatic char s_help_update_brief[] = "";static char s_help_update[] = "";// Ray Addedstatic unsigned short default_eeprom[8] = {0x1100, 0x3322, 0x4455, // MAC addr 0x0000, // Auto Load Control 0x0a46, // Vendor ID 0x9000, // Procudt ID 0x001e, // Pin control 0x8000 }; // Wake-up modestatic struct { char *cmd; // command string int (*func)(int argc, char *argv[], unsigned int kload); // return nonzero if it want to jumpt to kernel // argc : number of parameters // argv : parameter list // kload : address of kernel to be loaded char *helpbrief; // help message (brief) char *helpmsg; // help message (detail)} s_cmdtable[] = { { "help", bootmenu_help, s_help_help_brief, s_help_help }, { "boot", bootmenu_boot, s_help_boot_brief, s_help_boot }, { "config", bootmenu_config, s_help_config_brief, s_help_config }, { "download", bootmenu_download, s_help_download_brief, s_help_download }, { "dump", bootmenu_dump, s_help_dump_brief, s_help_dump },#ifdef SUPPORT_FLASH { "flash", bootmenu_flash, s_help_flash_brief, s_help_flash },#endif { "mem", bootmenu_mem, s_help_mem_brief, s_help_mem }, { "memcmp", bootmenu_memcmp, s_help_memcmp_brief, s_help_memcmp }, { "memcpy", bootmenu_memcpy, s_help_memcpy_brief, s_help_memcpy },#ifdef SUPPORT_NETWORK { "net", bootmenu_net, s_help_net_brief, s_help_net },#endif#ifdef SUPPORT_FLASH { "update", bootmenu_update, s_help_update_brief, s_help_update }, { "mtest", bootmenu_mtest, s_help_update_brief, s_help_update },#endif { NULL, NULL, NULL },};//// global variables// enum { DOWNLOAD_NONE, DOWNLOAD_BOOT, DOWNLOAD_ROMFS, DOWNLOAD_KERNEL, DOWNLOAD_MISC, DOWNLOAD_MAX };static struct { int download; int len;} g_download_info[DOWNLOAD_MAX];struct net_device netdevHost;//// Main Menu Loop//int bootmenu(unsigned int kload){ char str[256]; PrintUart("\r\n", -1); timer_init();#ifdef SUPPORT_FLASH flash_init(FLASH_BASE_ADDRESS, 0); flash_init(FLASH_BASE_ADDRESS+0x200000, 0); bootconfig_load(0);#endif#ifdef SUPPORT_NETWORK net_init(); if (net_found() && g_bootconfig.protocol != BOOTNET_NONE) net_dev_up();#endif PrintUart("\r\nWelcome to JASPER boot loader\r\n\n", -1); memset(&g_download_info, 0, sizeof g_download_info); for (;;) { // show prompt PrintUart(BOOTPROMPT, -1); // get input from serial GetCommand(str); if (bootmenu_command(str, kload)) return 1; }}int bootmenu_command(char *_str, unsigned int kload){ int i, argc; char str[256], *cp; char *argv[256]; strcpy(str, _str); trim(str); if (str[0] != 0) { // parsing command memset(argv, 0, sizeof argv); argc = 0; cp = strtok(str, " "); while (cp != NULL) { argv[argc++] = cp; cp = strtok(NULL, " "); } // lookup the command table for (i = 0; s_cmdtable[i].cmd != NULL; ++i) if (strcmp(argv[0], s_cmdtable[i].cmd) == 0) if (s_cmdtable[i].func(argc, argv, kload)) return 1; } return 0;}//// each menu functions//int bootmenu_help(int argc, char *argv[], unsigned int kload){ static char s_helpstr[] = "Jasper boot loader\r\n" "Copyright (C) 2002 by Sigma Designs, Inc\r\n" "\r\n" "Command List :\r\n" ; int i; if (argc == 1) { // help on all PrintUart(s_helpstr, -1); for (i = 0; s_cmdtable[i].cmd != NULL; ++i) PrintUart(s_cmdtable[i].helpbrief, -1); } else { // help on command for (i = 0; s_cmdtable[i].cmd != NULL; ++i) if (strcmp(s_cmdtable[i].cmd, argv[1]) == 0) { PrintUart(s_cmdtable[i].helpbrief, -1); PrintUart(s_cmdtable[i].helpmsg, -1); return 0; } PrintUart("Unknown command\r\n", -1); } return 0;}int bootmenu_boot(int argc, char *argv[], unsigned int kload){ unsigned int addr = 0; if (argc == 1) { PrintUart(s_help_boot_brief, -1); PrintUart(s_help_boot, -1); return 0; } if (strcmp(argv[1], "flash") == 0) { addr = ROMFS_START_ADDRESS; return try_boot_flash(kload, addr); } else if (strcmp(argv[1], "kernel") == 0) { if (g_download_info[DOWNLOAD_KERNEL].download) return 1; else { PrintUart("Download kernel to RAM first\r\n", -1); return 0; } }#ifdef SUPPORT_BOOT_FROM_CD else if (strcmp(argv[1], "cd") == 0) return try_boot_disc_pass(kload, 1);#endif else if (argv[1][0] >= '0' && argv[1][0] <= '9') { void (*code)(void); addr = atoi(argv[1]); PrintUart("Jump to address : ", -1); PrintLong(addr); code = (void (*)(void)) addr; code(); } else PrintUart("Unknown target\r\n", -1); return 0;}int bootmenu_config(int argc, char *argv[], unsigned int kload){ bootconfig_t curconfig; if (argc == 1) { PrintUart(s_help_config_brief, -1); PrintUart(s_help_config, -1); return 0; } memcpy(&curconfig, &g_bootconfig, sizeof(bootconfig_t)); if (strcmp(argv[1], "load") == 0) { int idx = 0; if (argc > 2) idx = atoi(argv[2]); if (bootconfig_load(idx) == 0) PrintUart("Configuration loaded\r\n", -1); else PrintUart("Can not load congiguration\r\n", -1); return 0; } else if (strcmp(argv[1], "save") == 0) { if (bootconfig_save() == 0) PrintUart("Configuration saved\r\n", -1); else PrintUart("Can not save configuration\r\n", -1); return 0; } else if (strcmp(argv[1], "serial") == 0) { static int s_validbaudrate[] = { 9600, 19200, 38400, 57600, 115200, 230400, 0 }; int i, baudrate = DEFAULT_BAUDRATE; if (argc == 2) PrintFormat("Setup UART as default baud rate %d\n", baudrate); else { baudrate = atoi(argv[2]); for (i = 0; s_validbaudrate[i] != 0; ++i) if (s_validbaudrate[i] == baudrate) break; if (s_validbaudrate[i] == 0) { PrintFormat("Invalid baud rate %d\n", baudrate); baudrate = 0; } else PrintFormat("Setup UART baud rate as %d\n", baudrate); } if (baudrate) InitUartPort(DEFAULT_UART_PORT, baudrate); }#ifdef SUPPORT_NETWORK else if (strcmp(argv[1], "net") == 0) { char str[128]; unsigned char addr[8]; int i; while (1) { PrintFormat(" Protocol : (0) None (1) Static IP (2) BOOTP (3) DHCP : (%d) ", g_bootconfig.protocol); GetString(str, sizeof str, 0); if ((trim(str))[0] == 0) break; i = atoi(str); if (i >= BOOTNET_NONE && i <= BOOTNET_DHCP) { g_bootconfig.protocol = i; break; } } while (g_bootconfig.protocol != BOOTNET_NONE) { PrintFormat(" MAC Address : (%02x:%02x:%02x:%02x:%02x:%02x) ", g_bootconfig.macaddr[0], g_bootconfig.macaddr[1], g_bootconfig.macaddr[2], g_bootconfig.macaddr[3], g_bootconfig.macaddr[4], g_bootconfig.macaddr[5]); GetString(str, sizeof str, 0); if ((trim(str))[0] == 0) break;// for(i=0;i<20;++i)// PrintFormat("[%x] ", str[i]);// PrintFormat("\n"); if (parse_netaddr(str, addr, 6) == 0) {// memcpy(g_bootconfig.macaddr, addr, 6); for(i=0;i<8;++i) PrintFormat("[%x] ", addr[i]); PrintFormat("\n"); memcpy(&default_eeprom[0], addr, 6); break; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -