static void usb_rx_cmd_complete(struct usb_request *req, unsigned actual, int status) { if(status != 0) return; if(actual > 4095) actual = 4095; cmdbuf[actual] = 0; dprintf("\n> %s\n",cmdbuf); // dprintf("usb_rx_cmd_complete() '%s'\n", cmdbuf); if(memcmp(cmdbuf, "reboot", 6) == 0) { tx_status("OKAY"); rx_cmd(); mdelay(100); board_reboot(); } #if 0 if(memcmp(cmdbuf, "debug:", 6) == 0) { void debug(char *cmd, char *resp); memcpy(cmdbuf, "OKAY", 5); tx_status(cmdbuf); rx_cmd(); mdelay(5000); dprintf("NOW!\n"); debug(cmdbuf + 6, cmdbuf + 4); return; } #endif if(memcmp(cmdbuf, "getvar:", 7) == 0) { char response[64]; strcpy(response,"OKAY"); if(!strcmp(cmdbuf + 7, "version")) { strcpy(response + 4, VERSION); } else if(!strcmp(cmdbuf + 7, "product")) { strcpy(response + 4, PRODUCTNAME); } else if(!strcmp(cmdbuf + 7, "serialno")) { strcpy(response + 4, serialno); } else { board_getvar(cmdbuf + 7, response + 4); } tx_status(response); rx_cmd(); return; } if(memcmp(cmdbuf, "download:", 9) == 0) { char status[16]; rx_addr = kernel_addr; rx_length = hex2unsigned(cmdbuf + 9); if (rx_length > (64*1024*1024)) { tx_status("FAILdata too large"); rx_cmd(); return; } kernel_size = rx_length; dprintf("recv data addr=%x size=%x\n", rx_addr, rx_length); strcpy(status,"DATA"); num_to_hex8(rx_length, status + 4); tx_status(status); rx_data(); return; } if(memcmp(cmdbuf, "erase:", 6) == 0){ struct ptentry *ptn; ptn = flash_find_ptn(cmdbuf + 6); if(ptn == 0) { tx_status("FAILpartition does not exist"); rx_cmd(); return; } dprintf("erasing '%s'\n", ptn->name); cprintf("erasing '%s'", ptn->name); if(flash_erase(ptn)) { tx_status("FAILfailed to erase partition"); rx_cmd(); cprintf(" - FAIL\n"); return; } else { dprintf("partition '%s' erased\n", ptn->name); cprintf(" - OKAY\n"); } tx_status("OKAY"); rx_cmd(); return; } if(memcmp(cmdbuf, "flash:", 6) == 0){ struct ptentry *ptn; int extra = 0; ptn = flash_find_ptn(cmdbuf + 6); if(kernel_size == 0) { tx_status("FAILno image downloaded"); rx_cmd(); return; } if(ptn == 0) { tx_status("FAILpartition does not exist"); rx_cmd(); return; } if(!strcmp(ptn->name,"boot") || !strcmp(ptn->name,"recovery")) { if(memcmp((void*) kernel_addr, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { tx_status("FAILimage is not a boot image"); rx_cmd(); return; } } #if REQUIRE_SIGNATURE { unsigned char digest[DIGEST_SIZE]; compute_digest((void*) kernel_addr, kernel_size, digest); if (is_signature_okay(digest, signature, key_engineering)) { dprintf("verified by engineering key\n"); } else { tx_status("FAILsignature did not verify"); rx_cmd(); return; } } #endif if(!strcmp(ptn->name,"system") || !strcmp(ptn->name,"userdata")) { extra = 64; } else { kernel_size = (kernel_size + 2047) & (~2047); } dprintf("writing %d bytes to '%s'\n", kernel_size, ptn->name); cprintf("writing '%s' (%d bytes)", ptn->name, kernel_size); if(flash_write(ptn, extra, (void*) kernel_addr, kernel_size)) { tx_status("FAILflash write failure"); rx_cmd(); cprintf(" - FAIL\n"); return; } else { dprintf("partition '%s' updated\n", ptn->name); cprintf(" - OKAY\n"); } tx_status("OKAY"); rx_cmd(); return; } if(memcmp(cmdbuf, "boot", 4) == 0) { if(init_boot_linux()) { tx_status("FAILinvalid boot image"); rx_cmd(); return; } dprintf("booting linux...\n"); cprintf("\nbooting linux...\n"); tx_status("OKAY"); mdelay(10); usb_shutdown(); boot_linux(); return; } if(memcmp(cmdbuf, "signature", 9) == 0) { if (kernel_size != SIGNATURE_SIZE) { tx_status("FAILsignature not 256 bytes long"); rx_cmd(); return; } memcpy(signature, (void*)kernel_addr, SIGNATURE_SIZE); tx_status("OKAY"); rx_cmd(); return; } tx_status("FAILinvalid command"); rx_cmd(); }
void console_rx_cmd_complete(char* cmd) { /*lint --e{718} */ if(memcmp(cmd, "boot", 4) == 0){ boot_rtx_cm3_from_flash(); boot_linux_from_flash(); } else if(memcmp(cmd, "showflash", 9) == 0){ bsp_show_nand_info(); } else if(memcmp(cmd, "flash_erase_force", 17) == 0){ flash_erase_force(cmd + 18); } else if(memcmp(cmd, "flash_scan_bad", 14) == 0){ flash_scan_bad(cmd + 14); } else if(memcmp(cmd, "nand_markbad", 12) == 0){ bsp_nand_markbad(cmd + 13); } else if(memcmp(cmd, "nand_erase_force", 16) == 0){ bsp_nand_erase_force(cmd + 17); } else if(memcmp(cmd, "io", 2) == 0){ ios_list_echo(); } else if(memcmp(cmd, "jtag1", 5) == 0){ jtag1_config(); } else if(memcmp(cmd, "chiptem", 7) == 0){ cprintf("chip temperature is %d.\n ", chip_tem_get()); } else if(memcmp(cmd, "efuse", 5) == 0){ efuse_info_show(); } else if(memcmp(cmd, "cboot", 5) == 0){ /* coverity[check_return] */ boot_vxworks_from_flash(); } else if(memcmp(cmd, "mboot", 5) == 0){ boot_rtx_cm3_from_flash(); } else if(memcmp(cmd, "mem", 3) == 0){ cprintf(" section size: start size \n"); cprintf(" first: 0x%x %d\n",&BOOTLOADER_START, &BOOTLOADER_SIZE); cprintf(" bss:0x%x -- 0x%x, %d\n",&BOOTLOADER_BSS, &BOOTLOADER_BSS_END , (unsigned)(&BOOTLOADER_BSS_END- &BOOTLOADER_BSS)); cprintf(" heap:0x%x -- 0x%x, %d\n",BOOTLOADER_HEAP_ADDR, get_heap_next() , (unsigned)(get_heap_next()- BOOTLOADER_HEAP_ADDR)); } else if(memcmp(cmd, "help", 4) == 0){ cprintf(" help print the list.\n"); cprintf(" boot boot kernel from flash.\n"); cprintf(" boot cshell boot with cshell.\n"); cprintf(" mem show memory statis.\n"); } else if(memcmp(cmd, "recovery", 8) == 0) { boot_recovery_from_flash(); } else if(memcmp(cmd, "flash", 5) == 0) { flash_main(); } else if(memcmp(cmd, "reboot", 6) == 0) { board_reboot(); } else if(memcmp(cmd, "cstest", 6) == 0) { cstest(); } else if(memcmp(cmd, "astest", 6) == 0) { astest(); } else if(memcmp(cmd, "i2cdebug", 8) == 0) { bsp_i2c_debug(); } else if(memcmp(cmd, "pcie", 4) == 0) { pcie_fastboot_console(cmd + 5); } else if((0 == memcmp(cmd, "m", 1)) || (0 == memcmp(cmd, "M", 1)) || (0 == memcmp(cmd, "v", 1)) || (0 == memcmp(cmd, "V", 1)) || (0 == memcmp(cmd, "l", 1)) || (0 == memcmp(cmd, "L", 1)) || (0 == memcmp(cmd, "k", 1)) || (0 == memcmp(cmd, "K", 1))) { uart_sele_set(cmd[0]); } else if(*cmd == '\r' || *cmd == '\n'){ } else { cprintf(" unknown command %s.\n", cmd); } cprintf("/ # "); }