📄 ui_menu.c
字号:
/***************************************************************************** Copyright Storlink Corp 2005. All rights reserved. *--------------------------------------------------------------------------* Name : ui_menu.c* Description : * Handle UI menu** History** Date Writer Description* ----------- ----------- -------------------------------------------------* 04/20/2005 Gary Chen Create*****************************************************************************/#include <define.h>#include <board_config.h>static void ui_show_boot_menu(void);static int ui_set_mac_addr(void);char ui_getc(void);typedef struct { char key; void (*handler)(int); int arg; char *msg;} MENU_T;static void ui_reset(int);static void ui_load_kernel(int);extern void cli_main(int arg);static void ui_set_ip(int);static void ui_set_mac(int);extern void ui_upgrade(int);extern void ui_config(int);#ifdef BOARD_SUPPORT_IDE static void ui_ide_init_cmd(int);#endif#ifdef LOAD_FROM_IDEstatic void ui_update_boot_file(int);#endif#ifdef BOARD_SUPPORT_FIS extern void fis_ui_list(int);extern void fis_ui_delete_image(int);extern void fis_ui_create_image(int);extern void fis_ui_create_default(int);extern void fis_ui_over_write_image(int);#endifMENU_T boot_menu_table[]={ {'0', (void *)ui_reset, 0, "Reboot"}, {'1', (void *)ui_load_kernel, 0, "Start the Kernel Code"},#ifdef BOARD_SUPPORT_FIS {'2', (void *)fis_ui_list, 0, "List Image"}, {'3', (void *)fis_ui_delete_image, 0, "Delete Image"}, {'4', (void *)fis_ui_create_image, 0, "Create New Image"},#endif {'5', (void *)cli_main, 0, "Enter Command Line Interface"}, {'6', (void *)ui_set_ip, 0, "Set IP Address"}, {'7', (void *)ui_set_mac, 0, "Set MAC Address"}, {'8', (void *)ui_config, 0, "Show Configuration"},//#ifdef BOARD_SUPPORT_FIS// {'9', (void *)fis_ui_over_write_image, 0, "Over Write Image"},//#endif #ifdef LOAD_FROM_IDE {'B', (void *)ui_update_boot_file, 0, "Set Booting File"},#endif#ifdef BOARD_SUPPORT_FIS {'F', (void *)fis_ui_create_default, 0, "Create Default FIS"},#endif #ifdef BOARD_SUPPORT_IDE {'I', (void *)ui_ide_init_cmd, 0, "Initialize IDE"},#endif {'X', (void *)ui_upgrade, 0, "Upgrade Boot"},#ifndef LOAD_FROM_IDE {'Y', (void *)ui_upgrade, 1, "Upgrade Kernel"}, {'Z', (void *)ui_upgrade, 2, "Upgrade Firmware"}, {'A', (void *)ui_upgrade, 4, "Upgrade Application"}, {'R', (void *)ui_upgrade, 3, "Upgrade RAM Disk"},#endif {0, NULL, 0, NULL},};#define MENU_TOTAL_ITEMS (sizeof(boot_menu_table)/sizeof(MENU_T))/*----------------------------------------------------------------------* ui_menu*----------------------------------------------------------------------*/void ui_menu(void){ int res = 0; char line[20]; char command; int show_menu; MENU_T *menu; while (1) { ui_show_boot_menu(); while (uart_scanc()); command = ui_getc(); command = toupper(command); if (command <= 0x20 || command >= 0x7f) continue; printf("%c\n\n", command); menu = (MENU_T *)&boot_menu_table[0]; while (menu->key) { if (menu->key == command) { menu->handler(menu->arg); break; } menu++; } }}/*----------------------------------------------------------------------* ui_show_same_char(char data, int size)*----------------------------------------------------------------------*/static void ui_show_same_char(char c, int size){ char data[81], *cp; if (size > 80) size = 80; cp = data; while (size--) *cp++ = c; *cp = 0x00; printf(data);} /*----------------------------------------------------------------------* ui_show_boot_menu*----------------------------------------------------------------------*/// SJC#define ___FLASH_SIZE "8M"#define ___RAM_SIZE "64M"#if SIZE_16M#undef ___FLASH_SIZE#define ___FLASH_SIZE "16M"#endif#if _RAM_SIZE_128M#undef ___RAM_SIZE#define ___RAM_SIZE "128M"#endifstatic void ui_show_boot_menu(void){ MENU_T *menu; int count; printf("\n"); ui_show_same_char(' ', 30); printf("Boot Menu (%s+%s version %s)\n", ___FLASH_SIZE, ___RAM_SIZE, __VER); // SJC ui_show_same_char('=', 78); printf("\n"); menu = (MENU_T *)&boot_menu_table[0]; count = 0; while (menu->key) { printf("%c: ", menu->key); printf(menu->msg); if (MENU_TOTAL_ITEMS < 10) { printf("\n"); } else { if (count & 1) printf("\n"); else ui_show_same_char(' ', 41-strlen(menu->msg)); } count++; menu++; } if (count & 1) printf("\n"); printf("\n"); printf("=> Select: ");}/*----------------------------------------------------------------------* ui_reset*----------------------------------------------------------------------*/static void ui_reset(int arg){ printf("Reboot system...\n"); hal_reset();}/*----------------------------------------------------------------------* ui_load_kernel*----------------------------------------------------------------------*/static void ui_load_kernel(int arg){#ifdef LOAD_FROM_IDE ide_init(); ext2fs_init();#endif sys_load_kernel();}/*----------------------------------------------------------------------* ui_set_ip*----------------------------------------------------------------------*/static void ui_set_ip(int arg){ int rc; UINT32 ipaddr, netmask, gateway; char ip_str[20]; ipaddr = (UINT32)sys_get_ip_addr(); printf("Old IP Address: %d.%d.%d.%d\n", IP1(ipaddr), IP2(ipaddr), IP3(ipaddr), IP4(ipaddr)); printf("Input new IP : "); sprintf(ip_str, "%d.%d.%d.%d", IP1(ipaddr), IP2(ipaddr), IP3(ipaddr), IP4(ipaddr)); rc = ui_gets(ip_str, sizeof(ip_str)); ipaddr = str2ip(ip_str); if (rc == 0 || ipaddr == 0 || ipaddr == 0xffffffff) { printf("Illegal IP address!\n"); return; } sys_set_ip_addr(ipaddr); netmask = sys_get_ip_netmask(); // sys_set_ip_netmask(0xffffff00); // class C gateway = sys_get_ip_gateway(); sys_set_ip_gateway((ipaddr & netmask) | (gateway & ~netmask));#ifdef BOARD_SUPPORT_VCTL printf("Write New IP Address to Flash!\n"); sys_save_ip_cfg();#endif ipaddr = sys_get_ip_addr(); printf("New IP Address: %d.%d.%d.%d\n", IP1(ipaddr), IP2(ipaddr), IP3(ipaddr), IP4(ipaddr));} /*----------------------------------------------------------------------* ui_set_mac*----------------------------------------------------------------------*/static void ui_set_mac(int arg){ char *mac, new_mac[6]; char new_mac_str[18], *cp; int k, i, rc; UINT32 data; for (k=0; k<SYS_MAC_NUM; k++) { mac = (char *)sys_get_mac_addr(k); printf("MAC %d Address = %02X:%02X:%02X:%02X:%02X:%02X\n", k+1, mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]); printf("Input New MAC = "); sprintf(new_mac_str, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]); rc = ui_gets(new_mac_str, 18); if (rc == 0 || rc != 17 || new_mac_str[2] !=':') { printf("Illegal MAC address!\nSyntax: xx:xx:xx:xx:xx:xx\n"); return; } cp = (char *)&new_mac_str[0]; for (i=0; i<6; i++) { cp[2] = 0; data = str2hex(cp); new_mac[i] = data; cp += 3; } if (new_mac[0] & 1) { printf("MAC address could not be multicast/broadcast address!\n"); return; } printf("New MAC %d = %02X:%02X:%02X:%02X:%02X:%02X\n", k+1, new_mac[0],new_mac[1],new_mac[2],new_mac[3],new_mac[4],new_mac[5]); sys_set_mac_addr(k, new_mac); } printf("Write new MAC address to Flash!\n"); sys_save_mac();}#ifdef BOARD_SUPPORT_IDEextern int ide_initialized;static void ui_ide_init_cmd(int arg){ ide_initialized = 0; ide_init();}#endif#ifdef LOAD_FROM_IDEstatic void ui_update_boot_file(int arg){ int rc, change; char buf[60]; unsigned long data; // kernel File strcpy(buf, (char *)sys_get_kernel_name()); printf("Old Kernel File: %s\n", buf); printf("New Kernel File: "); rc = ui_gets(buf, sizeof(buf)); if (rc == 0) { printf("Illegal filename!\n"); return; } sys_set_kernel_name(buf, 0); change = 1; sprintf(buf, "0x%08X", sys_get_kernel_addr()); printf("Old Kernel Location: %s\n", buf); printf("New Kernel Location: "); rc = ui_gets(buf, sizeof(buf)); data = str2hex(buf); if (rc == 0 || data < 0x1000 || data >= BOARD_DRAM_BOOT2_ADDR) { printf("Illegal location!\n"); return; } sys_set_kernel_addr(data, 0); change = 1; // initrd File strcpy(buf, (char *)sys_get_initrd_name()); printf("Old initrd file: %s\n", buf); printf("New initrd file: "); rc = ui_gets(buf, sizeof(buf)); if (rc == 0) { printf("Illegal filename!\n"); return; } sys_set_initrd_name(buf, 0); change = 1; sprintf(buf, "0x%08X", sys_get_initrd_addr()); printf("Old initrd location: %s\n", buf); printf("New initrd location: "); rc = ui_gets(buf, sizeof(buf)); data = str2hex(buf); if (rc == 0 || data < 0x1000 || data >= BOARD_DRAM_BOOT2_ADDR) { printf("Illegal location!\n"); return; } sys_set_initrd_addr(data, 0); change = 1;update_end: if (change) { printf("Write new booting files to Flash!\n"); sys_save_boot_file(); }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -