diff --git a/NSPE/WIFI_IOT/app/cmd_shell.c b/NSPE/WIFI_IOT/app/cmd_shell.c index 1c09245..756c0a0 100644 --- a/NSPE/WIFI_IOT/app/cmd_shell.c +++ b/NSPE/WIFI_IOT/app/cmd_shell.c @@ -58,6 +58,7 @@ OF SUCH DAMAGE. #include "wifi_management.h" #include "uart.h" #include "console.h" +#include "flash_api.h" #ifdef CONFIG_TELNET_SERVER #include "telnet_main.h" @@ -1076,6 +1077,65 @@ Usage: DEBUGPRINT(" 1 # support 20/40MHz\r\n"); } +typedef void (*img_fptr_t) (void); +#define IMAGE_HEADER_SIZE 0 + +/*! + \brief set bw to support 20MHz only or 20/40MHz + \param[in] argc: number of parameters + \param[in] argv: the pointer to the array that holds the parameters + \param[out] none + \retval none +*/ +static void cmd_boot(int argc, char **argv) +{ + static img_fptr_t img_reset; + uint32_t arm_vector[2] = {0}; + uint32_t boot_idx = 0, image_offset = 0, version; + + if (argc > 2) { + DEBUGPRINT("jump_bml: command format error!\r\n"); + goto Usage; + } + + /* Read the MSP and Reset_Handler of the main image */ + flash_read((image_offset + IMAGE_HEADER_SIZE), arm_vector, 8); + if (!is_valid_flash_addr(arm_vector[1])) { + DEBUGPRINT("Error, image vector reset is invalid (%08x).\r\n", arm_vector[1]); + goto BootFailed; + } + + __disable_irq(); + + /* Jump to main image */ + img_reset = (img_fptr_t)arm_vector[1]; +#if defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8M_BASE__) + /* Restore the Main Stack Pointer Limit register's reset value + * before passing execution to runtime firmware to make the + * bootloader transparent to it. + */ + __set_MSPLIM(0); +#endif + __set_MSP(arm_vector[0]); + + __DSB(); + __ISB(); + + img_reset(); + +BootFailed: + DEBUGPRINT("\r[%s|%u] Jump to MBL failed.\r\n", __FUNCTION__, __LINE__); + while(1); + +Usage: + DEBUGPRINT("\rUsage:\r\n"); + DEBUGPRINT(" jm [0/1]\r\n"); + DEBUGPRINT(" 0 # dry run.\r\n"); + DEBUGPRINT(" 1 # show the verbosity of messages.\r\n"); + + +} + static const cmd_entry cmd_table[] = { #ifdef CONFIG_BASECMD {"wifi_open", cmd_wifi_open}, @@ -1121,6 +1181,7 @@ static const cmd_entry cmd_table[] = { {"wifi_set_bw", cmd_bw_set}, #endif {"reboot", cmd_reboot}, + {"bootm", cmd_boot}, {"help", cmd_help} };