/* * .KB_C_FN_DEFINITION_START * void ParseCommand(char *) * This private function executes matching functions. * .KB_C_FN_DEFINITION_END */ static void ParseCommand(char *buffer) { int argc, i; if ((argc = BreakCommand(buffer)) < 1) return; switch (StringToCommand(argv[0])) { case COMMAND_COPY: { // "c <to> <from> <size in bytes>" // copy memory char *to, *from; unsigned size; if (argc > 3) { to = (char *)p_ASCIIToHex(argv[1]); from = (char *)p_ASCIIToHex(argv[2]); size = p_ASCIIToHex(argv[3]); memcpy(to, from, size); } break; } case COMMAND_DUMP: // display boot commands DumpBootCommands(); break; case COMMAND_EXEC: { // "e <address>" // execute at address void (*execAddr)(unsigned, unsigned, unsigned); if (argc > 1) { /* in future, include machtypes (MACH_KB9200 = 612) */ execAddr = (void (*)(unsigned, unsigned, unsigned)) p_ASCIIToHex(argv[1]); (*execAddr)(0, 612, tagAddress); } break; } case COMMAND_TFTP: { // "tftp <local_dest_addr filename>" // tftp download unsigned address = 0; if (argc > 2) address = p_ASCIIToHex(argv[1]); TFTP_Download(address, argv[2]); break; } case COMMAND_SERVER_IP: // "server_ip <server IP 192 200 1 20>" // set download server address if (argc > 4) SetServerIPAddress(BuildIP()); break; case COMMAND_HELP: // dump command info printf("Commands:\n" "\tc\n" "\td\n" "\te\n" "\tip\n" "\tserver_ip\n" "\tm\n" "\ttftp\n" "\ts\n" #ifdef SUPPORT_TAG_LIST "\tt\n" #endif "\tw\n" "\tx\n"); break; case COMMAND_LOCAL_IP: // "local_ip <local IP 192 200 1 21> // set ip of this module if (argc > 4) SetLocalIPAddress(BuildIP()); break; case COMMAND_MAC: { // "m <mac address 12 34 56 78 9a bc> // set mac address using 6 byte values unsigned char mac[6]; if (argc > 6) { for (i = 0; i < 6; i++) mac[i] = p_ASCIIToHex(argv[i + 1]); EMAC_SetMACAddress(mac); } break; } case COMMAND_SET: { // s <index> <new boot command> // set the boot command at index (0-based) unsigned index; if (argc > 1) { RestoreSpace(2); index = p_ASCIIToHex(argv[1]); SetBootCommand(index, argv[2]); } break; } #ifdef SUPPORT_TAG_LIST case COMMAND_TAG: // t <address> <boot command line> // create tag-list for linux boot if (argc > 2) { RestoreSpace(2); tagAddress = p_ASCIIToHex(argv[1]); InitTagList(argv[2], (void*)tagAddress); } break; #endif case COMMAND_WRITE: // write the command table to non-volatile WriteCommandTable(); break; case COMMAND_XMODEM: { // "x <address>" // download X-modem record at address if (argc > 1) xmodem_rx((char *)p_ASCIIToHex(argv[1])); break; } default: break; } printf("\n"); }
/* * .KB_C_FN_DEFINITION_START * void ParseCommand(char *) * This private function executes matching functions. * .KB_C_FN_DEFINITION_END */ static void ParseCommand(char *buffer) { int argc, i; if ((argc = BreakCommand(buffer)) < 1) return; switch (StringToCommand(argv[0])) { case COMMAND_DUMP: // display boot commands DumpBootCommands(); break; case COMMAND_EXEC: { // "e <address>" // execute at address void (*execAddr)(unsigned, unsigned); if (argc > 1) { /* in future, include machtypes (MACH_KB9200 = 612) */ execAddr = (void (*)(unsigned, unsigned)) p_ASCIIToHex(argv[1]); (*execAddr)(0, 612); } break; } case COMMAND_TFTP: { // "tftp <local_dest_addr filename>" // tftp download unsigned address = 0; if (argc > 2) address = p_ASCIIToHex(argv[1]); TFTP_Download(address, argv[2]); break; } case COMMAND_SERVER_IP: // "server_ip <server IP 192 200 1 20>" // set download server address if (argc > 4) SetServerIPAddress(BuildIP()); break; case COMMAND_LOCAL_IP: // "local_ip <local IP 192 200 1 21> // set ip of this module if (argc > 4) SetLocalIPAddress(BuildIP()); break; case COMMAND_MAC: { // "m <mac address 12 34 56 78 9a bc> // set mac address using 6 byte values unsigned char mac[6]; if (argc > 6) { for (i = 0; i < 6; i++) mac[i] = p_ASCIIToHex(argv[i + 1]); EMAC_SetMACAddress(mac); } break; } case COMMAND_LOAD_SPI_KERNEL: // "k <address>" if (argc > 1) LoadKernelFromSpi((char *)p_ASCIIToHex(argv[1])); break; case COMMAND_XMODEM: // "x <address>" // download X-modem record at address if (argc > 1) xmodem_rx((char *)p_ASCIIToHex(argv[1])); break; case COMMAND_RESET: printf("Reset\n"); reset(); while (1) continue; break; case COMMAND_REPLACE_KERNEL_VIA_XMODEM: printf("Updating KERNEL image\n"); UpdateFlash(KERNEL_OFFSET); break; case COMMAND_REPLACE_FLASH_VIA_XMODEM: printf("Updating FLASH image\n"); UpdateFlash(FLASH_OFFSET); break; case COMMAND_REPLACE_ID_EEPROM: { char buf[25]; printf("Testing Config EEPROM\n"); EEWrite(0, "This is a test", 15); EERead(0, buf, 15); printf("Found '%s'\n", buf); break; } default: break; } printf("\n"); }