int main(void) { //mico_logic_partition_t *partition; init_clocks(); init_memory(); init_architecture(); init_platform_bootloader(); mico_set_bootload_ver(); //update(); enable_protection(); #ifdef MICO_ENABLE_STDIO_TO_BOOT if (stdio_break_in() == 1) goto BOOT; #endif if( MicoShouldEnterBootloader() == false ) bootloader_start_app( (MicoFlashGetInfo(MICO_PARTITION_APPLICATION))->partition_start_addr ); /*else if( MicoShouldEnterMFGMode() == true ) bootloader_start_app( (MicoFlashGetInfo(MICO_PARTITION_APPLICATION))->partition_start_addr ); else if( MicoShouldEnterATEMode() ){ partition = MicoFlashGetInfo( MICO_PARTITION_ATE ); if (partition->partition_owner != MICO_FLASH_NONE) { bootloader_start_app( partition->partition_start_addr ); } }*/ #ifdef MICO_ENABLE_STDIO_TO_BOOT BOOT: #endif _mount(); printf ( menu, MODEL, Bootloader_REVISION, HARDWARE_REVISION ); while(1){ Main_Menu (); } }
/** * @brief Display the Main Menu on HyperTerminal * @param None * @retval None */ void Main_Menu(void) { char cmdbuf [CMD_STRING_SIZE] = {0}, cmdname[15] = {0}; /* command input buffer */ int i, j; /* index for command buffer */ char startAddressStr[10], endAddressStr[10], flash_dev_str[4]; int32_t startAddress, endAddress; bool inputFlashArea = false; mico_logic_partition_t *partition; mico_flash_t flash_dev; OSStatus err = kNoErr; while (1) { /* loop forever */ printf ("\n\rMXCHIP> "); getline (&cmdbuf[0], sizeof (cmdbuf)); /* input command line */ for (i = 0; cmdbuf[i] == ' '; i++); /* skip blanks on head */ for (; cmdbuf[i] != 0; i++) { /* convert to upper characters */ cmdbuf[i] = toupper(cmdbuf[i]); } for (i = 0; cmdbuf[i] == ' '; i++); /* skip blanks on head */ for(j=0; cmdbuf[i] != ' '&&cmdbuf[i] != 0; i++,j++) { /* find command name */ cmdname[j] = cmdbuf[i]; } cmdname[j] = '\0'; /***************** Command "0" or "BOOTUPDATE": Update the application *************************/ if(strcmp(cmdname, "BOOTUPDATE") == 0 || strcmp(cmdname, "0") == 0) { partition = MicoFlashGetInfo( MICO_PARTITION_BOOTLOADER ); if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead Bootloader...\n\r"); SerialUpload( partition->partition_owner, partition->partition_start_addr, "BootLoaderImage.bin", partition->partition_length ); continue; } printf ("\n\rUpdating Bootloader...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_BOOTLOADER, 0x0, partition->partition_length ); require_noerr( err, exit); SerialDownload( partition->partition_owner, partition->partition_start_addr, partition->partition_length ); } /***************** Command "1" or "FWUPDATE": Update the MICO application *************************/ else if(strcmp(cmdname, "FWUPDATE") == 0 || strcmp(cmdname, "1") == 0) { partition = MicoFlashGetInfo( MICO_PARTITION_APPLICATION ); if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead application...\n\r"); SerialUpload( partition->partition_owner, partition->partition_start_addr, "ApplicationImage.bin", partition->partition_length ); continue; } printf ("\n\rUpdating application...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_APPLICATION, 0x0, partition->partition_length ); require_noerr( err, exit); SerialDownload( partition->partition_owner, partition->partition_start_addr, partition->partition_length ); } /***************** Command "2" or "DRIVERUPDATE": Update the RF driver *************************/ else if(strcmp(cmdname, "DRIVERUPDATE") == 0 || strcmp(cmdname, "2") == 0) { partition = MicoFlashGetInfo( MICO_PARTITION_RF_FIRMWARE ); if( partition == NULL ){ printf ("\n\rNo flash memory for RF firmware, exiting...\n\r"); continue; } if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead RF firmware...\n\r"); SerialUpload( partition->partition_owner, partition->partition_start_addr, "DriverImage.bin", partition->partition_length ); continue; } printf ("\n\rUpdating RF driver...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_RF_FIRMWARE, 0x0, partition->partition_length ); require_noerr( err, exit); SerialDownload( partition->partition_owner, partition->partition_start_addr, partition->partition_length ); } /***************** Command "3" or "PARAUPDATE": Update the application *************************/ else if(strcmp(cmdname, "PARAUPDATE") == 0 || strcmp(cmdname, "3") == 0) { partition = MicoFlashGetInfo( MICO_PARTITION_PARAMETER_1 ); if (findCommandPara(cmdbuf, "e", NULL, 0) != -1){ printf ("\n\rErasing settings...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_PARAMETER_1, 0x0, partition->partition_length ); require_noerr( err, exit); MicoFlashErase( MICO_PARTITION_PARAMETER_1, 0x0, partition->partition_length ); continue; } if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead settings...\n\r"); SerialUpload( partition->partition_owner, partition->partition_start_addr, "DriverImage.bin", partition->partition_length ); continue; } printf ("\n\rUpdating settings...\n\r"); err = MicoFlashDisableSecurity( MICO_PARTITION_PARAMETER_1, 0x0, partition->partition_length ); require_noerr( err, exit); SerialDownload( partition->partition_owner, partition->partition_start_addr, partition->partition_length ); } /***************** Command "4" or "FLASHUPDATE": : Update the Flash *************************/ else if(strcmp(cmdname, "FLASHUPDATE") == 0 || strcmp(cmdname, "4") == 0) { if (findCommandPara(cmdbuf, "dev", flash_dev_str, 1) == -1 ){ printf ("\n\rUnkown target type! Exiting...\n\r"); continue; } if(Str2Int((uint8_t *)flash_dev_str, (int32_t *)&flash_dev)==0){ printf ("\n\rDevice Number Err! Exiting...\n\r"); continue; } if( flash_dev >= MICO_FLASH_MAX ){ printf ("\n\rDevice Err! Exiting...\n\r"); continue; } inputFlashArea = false; if (findCommandPara(cmdbuf, "start", startAddressStr, 10) != -1){ if(Str2Int((uint8_t *)startAddressStr, &startAddress)==0){ //Found Flash start address printf ("\n\rIllegal start address.\n\r"); continue; }else{ if (findCommandPara(cmdbuf, "end", endAddressStr, 10) != -1){ //Found Flash end address if(Str2Int((uint8_t *)endAddressStr, &endAddress)==0){ printf ("\n\rIllegal end address.\n\r"); continue; }else{ inputFlashArea = true; } }else{ printf ("\n\rFlash end address not found.\n\r"); continue; } } } if(endAddress<startAddress && inputFlashArea == true) { printf ("\n\rIllegal address.\n\r"); continue; } if(inputFlashArea != true){ startAddress = platform_flash_peripherals[ flash_dev ].flash_start_addr ; endAddress = platform_flash_peripherals[ flash_dev ].flash_start_addr + platform_flash_peripherals[ flash_dev ].flash_length - 1; } if (findCommandPara(cmdbuf, "e", NULL, 0) != -1){ printf ("\n\rErasing dev%d content From 0x%x to 0x%x\n\r", flash_dev, startAddress, endAddress); platform_flash_init( &platform_flash_peripherals[ flash_dev ] ); platform_flash_disable_protect( &platform_flash_peripherals[ flash_dev ], startAddress, endAddress ); platform_flash_erase( &platform_flash_peripherals[ flash_dev ], startAddress, endAddress ); continue; } if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){ printf ("\n\rRead dev%d content From 0x%x to 0x%x\n\r", flash_dev, startAddress, endAddress); SerialUpload(flash_dev, startAddress, "FlashImage.bin", endAddress-startAddress+1); continue; } printf ("\n\rUpdating dev%d content From 0x%x to 0x%x\n\r", flash_dev, startAddress, endAddress); platform_flash_disable_protect( &platform_flash_peripherals[ flash_dev ], startAddress, endAddress ); SerialDownload(flash_dev, startAddress, endAddress-startAddress+1); } /***************** Command: MEMORYMAP *************************/ else if(strcmp(cmdname, "MEMORYMAP") == 0 || strcmp(cmdname, "5") == 0) { printf("\r"); for( i = 0; i <= MICO_PARTITION_PARAMETER_2; i++ ){ partition = MicoFlashGetInfo( (mico_partition_t)i ); if (partition->partition_owner == MICO_FLASH_NONE) continue; printf( "| %11s | Dev:%d | 0x%08x | 0x%08x |\r\n", partition->partition_description, partition->partition_owner, partition->partition_start_addr, partition->partition_length); } } /***************** Command: Excute the application *************************/ else if(strcmp(cmdname, "BOOT") == 0 || strcmp(cmdname, "6") == 0) { printf ("\n\rBooting.......\n\r"); partition = MicoFlashGetInfo( MICO_PARTITION_APPLICATION ); bootloader_start_app( partition->partition_start_addr ); } /***************** Command: Reboot *************************/ else if(strcmp(cmdname, "REBOOT") == 0 || strcmp(cmdname, "7") == 0) { printf ("\n\rReBooting.......\n\r"); MicoSystemReboot(); break; } else if(strcmp(cmdname, "HELP") == 0 || strcmp(cmdname, "?") == 0) { printf ( menu, MODEL, Bootloader_REVISION, HARDWARE_REVISION ); /* display command menu */ break; } else if(strcmp(cmdname, "") == 0 ) { break; } else{ printf (ERROR_STR, "UNKNOWN COMMAND"); break; } exit: continue; } }