修复mico-sdk错误

This commit is contained in:
nhkefus
2025-03-11 15:54:45 +08:00
parent 3422912129
commit 2ccb892a1c
2152 changed files with 664341 additions and 702636 deletions

View File

@@ -1,163 +1,163 @@
/**
******************************************************************************
* @file BootloaderEntrance.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief MICO bootloader main entrance.
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#include "mico.h"
#include "platform.h"
#include "platform_internal.h"
#include "platform_config.h"
#include "bootloader.h"
#define boot_log(M, ...) custom_log("BOOT", M, ##__VA_ARGS__)
#define boot_log_trace() custom_log_trace("BOOT")
extern void Main_Menu(void);
extern OSStatus update(void);
#ifdef SIZE_OPTIMIZE
char menu[] =
"\r\n"
"MICO bootloader for %s, %s, HARDWARE_REVISION: %s\r\n"
"0:BOOTUPDATE,"
"1:FWUPDATE,"
"2:DRIVERUPDAT,"
"3:PARAUPDATE,"
"4:FLASHUPDATE,"
"5:MEMORYMAP,"
"6:BOOT,"
"7:REBOOT";
#else
char menu[] =
"\r\n"
"MICO bootloader for %s, %s, HARDWARE_REVISION: %s\r\n"
"+ command -------------------------+ function ------------+\r\n"
"| 0:BOOTUPDATE <-r> | Update bootloader |\r\n"
"| 1:FWUPDATE <-r> | Update application |\r\n"
"| 2:DRIVERUPDATE <-r> | Update RF driver |\r\n"
"| 3:PARUPDATE <-id n><-r><-e> | Update MICO partition|\r\n"
"| 4:FLASHUPDATE <-dev device> | |\r\n"
"| <-e><-r><-start addr><-end addr>| Update flash content |\r\n"
"| 5:MEMORYMAP | List flash memory map|\r\n"
"| 6:BOOT | Excute application |\r\n"
"| 7:REBOOT | Reboot |\r\n"
#ifdef MICO_USE_BT_PARTITION
"| 8:BT DRIVERUPDATE <-r> | Update BT driver |\r\n"
#endif
"+----------------------------------+----------------------+\r\n"
"| (C) COPYRIGHT 2015 MXCHIP Corporation By William Xu |\r\n"
" Notes:\r\n"
" -e Erase only -r Read from flash -dev flash device number\r\n"
" -start flash start address -end flash start address\r\n"
" Example: Input \"4 -dev 0 -start 0x400 -end 0x800\": Update \r\n"
" flash device 0 from 0x400 to 0x800\r\n";
#endif
#ifdef MICO_ENABLE_STDIO_TO_BOOT
extern int stdio_break_in(void);
#endif
static void enable_protection( void )
{
mico_partition_t i;
mico_logic_partition_t *partition;
for( i = MICO_PARTITION_BOOTLOADER; i < MICO_PARTITION_MAX; i++ ){
partition = MicoFlashGetInfo( i );
if( PAR_OPT_WRITE_DIS == ( partition->partition_options & PAR_OPT_WRITE_MASK ) )
MicoFlashEnableSecurity( i, 0x0, MicoFlashGetInfo(i)->partition_length );
}
}
WEAK bool MicoShouldEnterBootloader( void )
{
return false;
}
WEAK bool MicoShouldEnterMFGMode( void )
{
return false;
}
WEAK bool MicoShouldEnterATEMode( void )
{
return false;
}
void bootloader_start_app( uint32_t app_addr )
{
enable_protection( );
startApplication( app_addr );
}
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
printf ( menu, MODEL, Bootloader_REVISION, HARDWARE_REVISION );
while(1){
Main_Menu ();
}
}
/**
******************************************************************************
* @file BootloaderEntrance.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief MICO bootloader main entrance.
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#include "mico.h"
#include "platform.h"
#include "platform_internal.h"
#include "platform_config.h"
#include "bootloader.h"
#define boot_log(M, ...) custom_log("BOOT", M, ##__VA_ARGS__)
#define boot_log_trace() custom_log_trace("BOOT")
extern void Main_Menu(void);
extern OSStatus update(void);
#ifdef SIZE_OPTIMIZE
char menu[] =
"\r\n"
"MICO bootloader for %s, %s, HARDWARE_REVISION: %s\r\n"
"0:BOOTUPDATE,"
"1:FWUPDATE,"
"2:DRIVERUPDAT,"
"3:PARAUPDATE,"
"4:FLASHUPDATE,"
"5:MEMORYMAP,"
"6:BOOT,"
"7:REBOOT";
#else
char menu[] =
"\r\n"
"MICO bootloader for %s, %s, HARDWARE_REVISION: %s\r\n"
"+ command -------------------------+ function ------------+\r\n"
"| 0:BOOTUPDATE <-r> | Update bootloader |\r\n"
"| 1:FWUPDATE <-r> | Update application |\r\n"
"| 2:DRIVERUPDATE <-r> | Update RF driver |\r\n"
"| 3:PARUPDATE <-id n><-r><-e> | Update MICO partition|\r\n"
"| 4:FLASHUPDATE <-dev device> | |\r\n"
"| <-e><-r><-start addr><-end addr>| Update flash content |\r\n"
"| 5:MEMORYMAP | List flash memory map|\r\n"
"| 6:BOOT | Excute application |\r\n"
"| 7:REBOOT | Reboot |\r\n"
#ifdef MICO_USE_BT_PARTITION
"| 8:BT DRIVERUPDATE <-r> | Update BT driver |\r\n"
#endif
"+----------------------------------+----------------------+\r\n"
"| (C) COPYRIGHT 2015 MXCHIP Corporation By William Xu |\r\n"
" Notes:\r\n"
" -e Erase only -r Read from flash -dev flash device number\r\n"
" -start flash start address -end flash start address\r\n"
" Example: Input \"4 -dev 0 -start 0x400 -end 0x800\": Update \r\n"
" flash device 0 from 0x400 to 0x800\r\n";
#endif
#ifdef MICO_ENABLE_STDIO_TO_BOOT
extern int stdio_break_in(void);
#endif
static void enable_protection( void )
{
mico_partition_t i;
mico_logic_partition_t *partition;
for( i = MICO_PARTITION_BOOTLOADER; i < MICO_PARTITION_MAX; i++ ){
partition = MicoFlashGetInfo( i );
if( PAR_OPT_WRITE_DIS == ( partition->partition_options & PAR_OPT_WRITE_MASK ) )
MicoFlashEnableSecurity( i, 0x0, MicoFlashGetInfo(i)->partition_length );
}
}
WEAK bool MicoShouldEnterBootloader( void )
{
return false;
}
WEAK bool MicoShouldEnterMFGMode( void )
{
return false;
}
WEAK bool MicoShouldEnterATEMode( void )
{
return false;
}
void bootloader_start_app( uint32_t app_addr )
{
enable_protection( );
startApplication( app_addr );
}
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
printf ( menu, MODEL, Bootloader_REVISION, HARDWARE_REVISION );
while(1){
Main_Menu ();
}
}

View File

@@ -1,99 +1,99 @@
/**
******************************************************************************
* @file Getline.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief Line Edited Character Input
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#include <stdio.h>
#include "common.h" /* global project definition file */
#include "mico.h"
#include "platform_config.h"
#define CNTLQ 0x11
#define CNTLS 0x13
#define DEL 0x7F
#define BACKSPACE 0x08
#define CR 0x0D
#define LF 0x0A
static void uart_putchar( int c )
{
MicoUartSend( STDIO_UART, &c, 1 );
}
/***************/
/* Line Editor */
/***************/
void getline (char *line, int n) {
int cnt = 0;
char c;
do {
MicoUartRecv( STDIO_UART, &c, 1, MICO_NEVER_TIMEOUT );
if (c == CR) c = LF; /* read character */
if (c == BACKSPACE || c == DEL) { /* process backspace */
if (cnt != 0) {
cnt--; /* decrement count */
line--; /* and line pointer */
uart_putchar (BACKSPACE); /* echo backspace */
uart_putchar (' ');
uart_putchar (BACKSPACE);
}
}
else if (c != CNTLQ && c != CNTLS) { /* ignore Control S/Q */
uart_putchar (*line = c); /* echo and store character */
line++; /* increment line pointer */
cnt++; /* and count */
}
} while (cnt < n - 1 && c != LF); /* check limit and line feed */
*(line - 1) = 0; /* mark end of string */
}
#ifdef MICO_ENABLE_STDIO_TO_BOOT
int stdio_break_in(void)
{
uint8_t c;
int i, j;
for(i=0, j=0;i<10;i++) {
if (kNoErr != MicoUartRecv( STDIO_UART, &c, 1, 10))
continue;
if (c == 0x20) {
j++;
if (j > 3)
return 1;
} else {
j = 0;
}
}
return 0;
}
#endif
/**
******************************************************************************
* @file Getline.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief Line Edited Character Input
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#include <stdio.h>
#include "common.h" /* global project definition file */
#include "mico.h"
#include "platform_config.h"
#define CNTLQ 0x11
#define CNTLS 0x13
#define DEL 0x7F
#define BACKSPACE 0x08
#define CR 0x0D
#define LF 0x0A
static void uart_putchar( int c )
{
MicoUartSend( STDIO_UART, &c, 1 );
}
/***************/
/* Line Editor */
/***************/
void getline (char *line, int n) {
int cnt = 0;
char c;
do {
MicoUartRecv( STDIO_UART, &c, 1, MICO_NEVER_TIMEOUT );
if (c == CR) c = LF; /* read character */
if (c == BACKSPACE || c == DEL) { /* process backspace */
if (cnt != 0) {
cnt--; /* decrement count */
line--; /* and line pointer */
uart_putchar (BACKSPACE); /* echo backspace */
uart_putchar (' ');
uart_putchar (BACKSPACE);
}
}
else if (c != CNTLQ && c != CNTLS) { /* ignore Control S/Q */
uart_putchar (*line = c); /* echo and store character */
line++; /* increment line pointer */
cnt++; /* and count */
}
} while (cnt < n - 1 && c != LF); /* check limit and line feed */
*(line - 1) = 0; /* mark end of string */
}
#ifdef MICO_ENABLE_STDIO_TO_BOOT
int stdio_break_in(void)
{
uint8_t c;
int i, j;
for(i=0, j=0;i<10;i++) {
if (kNoErr != MicoUartRecv( STDIO_UART, &c, 1, 10))
continue;
if (c == 0x20) {
j++;
if (j > 3)
return 1;
} else {
j = 0;
}
}
return 0;
}
#endif

View File

@@ -1,255 +1,255 @@
/**
******************************************************************************
* @file update_for_OTA.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief This file provides functions to overwrite the target flash contents
* using according the stored in OTA temporary storage
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#include "mico.h"
#include "platform.h"
#include "platform_config.h"
#include "CheckSumUtils.h"
typedef int Log_Status;
#define Log_NotExist (1)
#define Log_NeedUpdate (2)
#define Log_UpdateTagNotExist (3)
#define Log_contentTypeNotExist (4)
#define Log_dataLengthOverFlow (5)
#define Log_StartAddressERROR (6)
#define Log_UnkonwnERROR (7)
#define Log_CRCERROR (8)
#define SizePerRW 4096 /* Bootloader need 2xSizePerRW RAM heap size to operate,
but it can boost the setup. */
static uint8_t data[SizePerRW];
static uint8_t newData[SizePerRW];
uint8_t paraSaveInRam[16*1024];
#define update_log(M, ...) custom_log("UPDATE", M, ##__VA_ARGS__)
#define update_log_trace() custom_log_trace("UPDATE")
static OSStatus checkcrc(uint16_t crc_in, int partition_type, int total_len)
{
uint16_t crc = 0;
mico_logic_partition_t* part;
int len;
OSStatus err = kNoErr;
uint32_t update_data_offset = 0x0;
CRC16_Context contex;
CRC16_Init( &contex );
if (crc_in == 0xFFFF)
goto exit;
part = MicoFlashGetInfo((mico_partition_t)partition_type);
if (part == NULL)
goto exit;
while(total_len > 0){
if( SizePerRW < total_len ){
len = SizePerRW;
} else {
len = total_len;
}
err = MicoFlashRead( MICO_PARTITION_OTA_TEMP, &update_data_offset, data , len);
require_noerr(err, exit);
total_len -= len;
CRC16_Update( &contex, data, len );
}
CRC16_Final( &contex, &crc );
if (crc == crc_in)
err = kNoErr;
exit:
update_log("CRC check return %d, got crc %x, calcuated crc %x", err, crc_in, crc);
return err;
}
Log_Status updateLogCheck( boot_table_t *updateLog, mico_partition_t *dest_partition_type )
{
uint32_t i;
for ( i = 0; i < sizeof(boot_table_t); i++ )
{
if ( *((uint8_t *) updateLog + i) != 0xff )
break;
}
if ( i == sizeof(boot_table_t) )
return Log_NotExist;
if ( updateLog->upgrade_type != 'U' )
return Log_UpdateTagNotExist;
if ( updateLog->start_address
!= MicoFlashGetInfo( MICO_PARTITION_OTA_TEMP )->partition_start_addr )
return Log_StartAddressERROR;
if ( updateLog->type == 'B' )
*dest_partition_type = MICO_PARTITION_BOOTLOADER;
else if ( updateLog->type == 'A' )
*dest_partition_type = MICO_PARTITION_APPLICATION;
else if ( updateLog->type == 'D' )
*dest_partition_type = MICO_PARTITION_RF_FIRMWARE;
else
return Log_contentTypeNotExist;
if ( updateLog->length > MicoFlashGetInfo( *dest_partition_type )->partition_length )
return Log_dataLengthOverFlow;
if ( checkcrc( updateLog->crc, *dest_partition_type, updateLog->length ) != kNoErr )
return Log_CRCERROR;
return Log_NeedUpdate;
}
OSStatus update(void)
{
boot_table_t updateLog;
uint32_t i, j, size;
uint32_t update_data_offset = 0x0;
uint32_t dest_offset;
uint32_t boot_table_offset = 0x0;
uint32_t para_offset = 0x0;
uint32_t copyLength;
//uint8_t *paraSaveInRam = NULL;
mico_logic_partition_t *ota_partition_info, *dest_partition_info, *para_partition_info;
mico_partition_t dest_partition;
OSStatus err = kNoErr;
ota_partition_info = MicoFlashGetInfo(MICO_PARTITION_OTA_TEMP);
require_action( ota_partition_info->partition_owner != MICO_FLASH_NONE, exit, err = kUnsupportedErr );
para_partition_info = MicoFlashGetInfo(MICO_PARTITION_PARAMETER_1);
require_action( para_partition_info->partition_owner != MICO_FLASH_NONE, exit, err = kUnsupportedErr );
memset(data, 0xFF, SizePerRW);
memset(newData, 0xFF, SizePerRW);
//paraSaveInRam = malloc( para_partition_info->partition_length );
//require_action( paraSaveInRam, exit, err = kNoMemoryErr );
memset(paraSaveInRam, 0xFF, para_partition_info->partition_length);
err = MicoFlashRead( MICO_PARTITION_PARAMETER_1, &boot_table_offset, (uint8_t *)&updateLog, sizeof(boot_table_t));
require_noerr(err, exit);
/*Not a correct record*/
if(updateLogCheck( &updateLog, &dest_partition) != Log_NeedUpdate){
size = ( ota_partition_info->partition_length )/SizePerRW;
for(i = 0; i <= size; i++){
if( i==size ){
err = MicoFlashRead( MICO_PARTITION_OTA_TEMP , &update_data_offset, data , ( ota_partition_info->partition_length )%SizePerRW );
require_noerr(err, exit);
}
else{
err = MicoFlashRead( MICO_PARTITION_OTA_TEMP, &update_data_offset, data , SizePerRW);
require_noerr(err, exit);
}
for(j=0; j<SizePerRW; j++){
if(data[j] != 0xFF){
update_log("Update data need to be erased");
err = MicoFlashDisableSecurity( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashErase( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition_info->partition_length );
require_noerr(err, exit);
goto exit;
}
}
}
goto exit;
}
dest_partition_info = MicoFlashGetInfo( dest_partition );
require_action( dest_partition_info->partition_owner != MICO_FLASH_NONE, exit, err = kUnsupportedErr );
update_log("Write OTA data to partition: %s, length %ld",
dest_partition_info->partition_description, updateLog.length);
dest_offset = 0x0;
update_data_offset = 0x0;
err = MicoFlashDisableSecurity( dest_partition, 0x0, dest_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashErase( dest_partition, 0x0, dest_partition_info->partition_length );
require_noerr(err, exit);
size = (updateLog.length)/SizePerRW;
for(i = 0; i <= size; i++){
if( i == size ){
if( (updateLog.length)%SizePerRW )
copyLength = (updateLog.length)%SizePerRW;
else
break;
}else{
copyLength = SizePerRW;
}
err = MicoFlashRead( MICO_PARTITION_OTA_TEMP, &update_data_offset, data , copyLength);
require_noerr(err, exit);
err = MicoFlashWrite( dest_partition, &dest_offset, data, copyLength);
require_noerr(err, exit);
dest_offset -= copyLength;
err = MicoFlashRead( dest_partition, &dest_offset, newData , copyLength);
require_noerr(err, exit);
err = memcmp(data, newData, copyLength);
require_noerr_action(err, exit, err = kWriteErr);
}
update_log("Update start to clear data...");
para_offset = 0x0;
err = MicoFlashDisableSecurity( MICO_PARTITION_PARAMETER_1, 0x0, para_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashRead( MICO_PARTITION_PARAMETER_1, &para_offset, paraSaveInRam, para_partition_info->partition_length );
require_noerr(err, exit);
memset(paraSaveInRam, 0xff, sizeof(boot_table_t));
err = MicoFlashErase( MICO_PARTITION_PARAMETER_1, 0x0, para_partition_info->partition_length );
require_noerr(err, exit);
para_offset = 0x0;
err = MicoFlashWrite( MICO_PARTITION_PARAMETER_1, &para_offset, paraSaveInRam, para_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashDisableSecurity( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashErase( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition_info->partition_length );
require_noerr(err, exit);
update_log("Update success");
exit:
if(err != kNoErr) update_log("Update exit with err = %d", err);
return err;
}
/**
******************************************************************************
* @file update_for_OTA.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief This file provides functions to overwrite the target flash contents
* using according the stored in OTA temporary storage
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#include "mico.h"
#include "platform.h"
#include "platform_config.h"
#include "CheckSumUtils.h"
typedef int Log_Status;
#define Log_NotExist (1)
#define Log_NeedUpdate (2)
#define Log_UpdateTagNotExist (3)
#define Log_contentTypeNotExist (4)
#define Log_dataLengthOverFlow (5)
#define Log_StartAddressERROR (6)
#define Log_UnkonwnERROR (7)
#define Log_CRCERROR (8)
#define SizePerRW 4096 /* Bootloader need 2xSizePerRW RAM heap size to operate,
but it can boost the setup. */
static uint8_t data[SizePerRW];
static uint8_t newData[SizePerRW];
uint8_t paraSaveInRam[16*1024];
#define update_log(M, ...) custom_log("UPDATE", M, ##__VA_ARGS__)
#define update_log_trace() custom_log_trace("UPDATE")
static OSStatus checkcrc(uint16_t crc_in, int partition_type, int total_len)
{
uint16_t crc = 0;
mico_logic_partition_t* part;
int len;
OSStatus err = kNoErr;
uint32_t update_data_offset = 0x0;
CRC16_Context contex;
CRC16_Init( &contex );
if (crc_in == 0xFFFF)
goto exit;
part = MicoFlashGetInfo((mico_partition_t)partition_type);
if (part == NULL)
goto exit;
while(total_len > 0){
if( SizePerRW < total_len ){
len = SizePerRW;
} else {
len = total_len;
}
err = MicoFlashRead( MICO_PARTITION_OTA_TEMP, &update_data_offset, data , len);
require_noerr(err, exit);
total_len -= len;
CRC16_Update( &contex, data, len );
}
CRC16_Final( &contex, &crc );
if (crc == crc_in)
err = kNoErr;
exit:
update_log("CRC check return %d, got crc %x, calcuated crc %x", err, crc_in, crc);
return err;
}
Log_Status updateLogCheck( boot_table_t *updateLog, mico_partition_t *dest_partition_type )
{
uint32_t i;
for ( i = 0; i < sizeof(boot_table_t); i++ )
{
if ( *((uint8_t *) updateLog + i) != 0xff )
break;
}
if ( i == sizeof(boot_table_t) )
return Log_NotExist;
if ( updateLog->upgrade_type != 'U' )
return Log_UpdateTagNotExist;
if ( updateLog->start_address
!= MicoFlashGetInfo( MICO_PARTITION_OTA_TEMP )->partition_start_addr )
return Log_StartAddressERROR;
if ( updateLog->type == 'B' )
*dest_partition_type = MICO_PARTITION_BOOTLOADER;
else if ( updateLog->type == 'A' )
*dest_partition_type = MICO_PARTITION_APPLICATION;
else if ( updateLog->type == 'D' )
*dest_partition_type = MICO_PARTITION_RF_FIRMWARE;
else
return Log_contentTypeNotExist;
if ( updateLog->length > MicoFlashGetInfo( *dest_partition_type )->partition_length )
return Log_dataLengthOverFlow;
if ( checkcrc( updateLog->crc, *dest_partition_type, updateLog->length ) != kNoErr )
return Log_CRCERROR;
return Log_NeedUpdate;
}
OSStatus update(void)
{
boot_table_t updateLog;
uint32_t i, j, size;
uint32_t update_data_offset = 0x0;
uint32_t dest_offset;
uint32_t boot_table_offset = 0x0;
uint32_t para_offset = 0x0;
uint32_t copyLength;
//uint8_t *paraSaveInRam = NULL;
mico_logic_partition_t *ota_partition_info, *dest_partition_info, *para_partition_info;
mico_partition_t dest_partition;
OSStatus err = kNoErr;
ota_partition_info = MicoFlashGetInfo(MICO_PARTITION_OTA_TEMP);
require_action( ota_partition_info->partition_owner != MICO_FLASH_NONE, exit, err = kUnsupportedErr );
para_partition_info = MicoFlashGetInfo(MICO_PARTITION_PARAMETER_1);
require_action( para_partition_info->partition_owner != MICO_FLASH_NONE, exit, err = kUnsupportedErr );
memset(data, 0xFF, SizePerRW);
memset(newData, 0xFF, SizePerRW);
//paraSaveInRam = malloc( para_partition_info->partition_length );
//require_action( paraSaveInRam, exit, err = kNoMemoryErr );
memset(paraSaveInRam, 0xFF, para_partition_info->partition_length);
err = MicoFlashRead( MICO_PARTITION_PARAMETER_1, &boot_table_offset, (uint8_t *)&updateLog, sizeof(boot_table_t));
require_noerr(err, exit);
/*Not a correct record*/
if(updateLogCheck( &updateLog, &dest_partition) != Log_NeedUpdate){
size = ( ota_partition_info->partition_length )/SizePerRW;
for(i = 0; i <= size; i++){
if( i==size ){
err = MicoFlashRead( MICO_PARTITION_OTA_TEMP , &update_data_offset, data , ( ota_partition_info->partition_length )%SizePerRW );
require_noerr(err, exit);
}
else{
err = MicoFlashRead( MICO_PARTITION_OTA_TEMP, &update_data_offset, data , SizePerRW);
require_noerr(err, exit);
}
for(j=0; j<SizePerRW; j++){
if(data[j] != 0xFF){
update_log("Update data need to be erased");
err = MicoFlashDisableSecurity( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashErase( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition_info->partition_length );
require_noerr(err, exit);
goto exit;
}
}
}
goto exit;
}
dest_partition_info = MicoFlashGetInfo( dest_partition );
require_action( dest_partition_info->partition_owner != MICO_FLASH_NONE, exit, err = kUnsupportedErr );
update_log("Write OTA data to partition: %s, length %ld",
dest_partition_info->partition_description, updateLog.length);
dest_offset = 0x0;
update_data_offset = 0x0;
err = MicoFlashDisableSecurity( dest_partition, 0x0, dest_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashErase( dest_partition, 0x0, dest_partition_info->partition_length );
require_noerr(err, exit);
size = (updateLog.length)/SizePerRW;
for(i = 0; i <= size; i++){
if( i == size ){
if( (updateLog.length)%SizePerRW )
copyLength = (updateLog.length)%SizePerRW;
else
break;
}else{
copyLength = SizePerRW;
}
err = MicoFlashRead( MICO_PARTITION_OTA_TEMP, &update_data_offset, data , copyLength);
require_noerr(err, exit);
err = MicoFlashWrite( dest_partition, &dest_offset, data, copyLength);
require_noerr(err, exit);
dest_offset -= copyLength;
err = MicoFlashRead( dest_partition, &dest_offset, newData , copyLength);
require_noerr(err, exit);
err = memcmp(data, newData, copyLength);
require_noerr_action(err, exit, err = kWriteErr);
}
update_log("Update start to clear data...");
para_offset = 0x0;
err = MicoFlashDisableSecurity( MICO_PARTITION_PARAMETER_1, 0x0, para_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashRead( MICO_PARTITION_PARAMETER_1, &para_offset, paraSaveInRam, para_partition_info->partition_length );
require_noerr(err, exit);
memset(paraSaveInRam, 0xff, sizeof(boot_table_t));
err = MicoFlashErase( MICO_PARTITION_PARAMETER_1, 0x0, para_partition_info->partition_length );
require_noerr(err, exit);
para_offset = 0x0;
err = MicoFlashWrite( MICO_PARTITION_PARAMETER_1, &para_offset, paraSaveInRam, para_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashDisableSecurity( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition_info->partition_length );
require_noerr(err, exit);
err = MicoFlashErase( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition_info->partition_length );
require_noerr(err, exit);
update_log("Update success");
exit:
if(err != kNoErr) update_log("Update exit with err = %d", err);
return err;
}

View File

@@ -1,49 +1,49 @@
/**
******************************************************************************
* @file bootloader.h
* @author William Xu
* @version V1.0.0
* @date 16-Sep-2014
* @brief This file provides all the headers of MICO bootloader.
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#ifndef __BOOTLOADER_H__
#define __BOOTLOADER_H__
#ifdef __cplusplus
extern "C" {
#endif
#define Bootloader_REVISION "v3.0"
void bootloader_start_app( uint32_t app_addr );
#ifdef __cplusplus
} /*extern "C" */
#endif
#endif
/**
******************************************************************************
* @file bootloader.h
* @author William Xu
* @version V1.0.0
* @date 16-Sep-2014
* @brief This file provides all the headers of MICO bootloader.
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#ifndef __BOOTLOADER_H__
#define __BOOTLOADER_H__
#ifdef __cplusplus
extern "C" {
#endif
#define Bootloader_REVISION "v3.0"
void bootloader_start_app( uint32_t app_addr );
#ifdef __cplusplus
} /*extern "C" */
#endif
#endif

View File

@@ -1,42 +1,42 @@
###############################################################################
#
# The MIT License
# Copyright (c) 2016 MXCHIP Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###############################################################################
NAME := APP_bootloader
GLOBAL_INCLUDES := .
$(NAME)_SOURCES := BootloaderEntrance.c \
Getline.c \
menu.c \
Update_for_OTA.c \
ymodem.c
$(NAME)_CFLAGS += -Wno-char-subscripts
GLOBAL_DEFINES := MICO_NO_WIFI
NoRTOS_START_STACK := 4000
GLOBAL_LDFLAGS += $$(CLIB_LDFLAGS_NANO)
###############################################################################
#
# The MIT License
# Copyright (c) 2016 MXCHIP Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###############################################################################
NAME := APP_bootloader
GLOBAL_INCLUDES := .
$(NAME)_SOURCES := BootloaderEntrance.c \
Getline.c \
menu.c \
Update_for_OTA.c \
ymodem.c
$(NAME)_CFLAGS += -Wno-char-subscripts
GLOBAL_DEFINES := MICO_NO_WIFI
NoRTOS_START_STACK := 4000
GLOBAL_LDFLAGS += $$(CLIB_LDFLAGS_NANO)
GLOBAL_DEFINES += BOOTLOADER

View File

@@ -1,410 +1,410 @@
/**
******************************************************************************
* @file menu.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief his file provides the software which contains the main menu routine.
* The main menu gives the options of:
* - downloading a new binary file,
* - uploading internal flash memory,
* - executing the binary file already loaded
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "mico.h"
#include "ymodem.h"
#include "platform_config.h"
#include "platform_internal.h"
#include "StringUtils.h"
#include "bootloader.h"
#include <ctype.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define CMD_STRING_SIZE 128
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern platform_flash_t platform_flash_peripherals[];
uint8_t tab_1024[1024] =
{
0
};
char FileName[FILE_NAME_LENGTH];
char ERROR_STR [] = "\n\r*** ERROR: %s\n\r"; /* ERROR message string in code */
extern char menu[];
extern void getline (char *line, int n); /* input line */
extern void startApplication( uint32_t app_addr );
/* Private function prototypes -----------------------------------------------*/
void SerialDownload(mico_flash_t flash, uint32_t flashdestination, int32_t maxRecvSize);
void SerialUpload(mico_flash_t flash, uint32_t flashdestination, char * fileName, int32_t maxRecvSize);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Analyse a command parameter
* @param commandBody: command string address
* @param para: The para we are looking for
* @param paraBody: A pointer to the buffer to receive the para body.
* @param paraBodyLength: The length, in bytes, of the buffer pointed to by the paraBody parameter.
* @retval the actual length of the paraBody received, -1 means failed to find this paras
*/
int findCommandPara(char *commandBody, char *para, char *paraBody, int paraBodyLength)
{
int i = 0;
int k, j;
int retval = -1;
char para_in_ram[100];
strncpy(para_in_ram, para, 100);
for (i = 0; para_in_ram[i] != 0; i++) { /* convert to upper characters */
para_in_ram[i] = toupper(para_in_ram[i]);
}
i = 0;
while(commandBody[i] != 0) {
if(commandBody[i] == '-' ){
for(j=i+1, k=0; *(para_in_ram+k)!=0x0; j++, k++ ){
if(commandBody[j] != *(para_in_ram+k)){
break;
}
}
if(*(para+k)!=0x0 || (commandBody[j]!=' '&& commandBody[j]!=0x0)){ /* para not found! */
i++;
continue;
}
retval = 0;
for (k = j+1; commandBody[k] == ' '; k++); /* skip blanks */
for(j = 0; commandBody[k] != ' ' && commandBody[k] != 0 && commandBody[k] != '-'; j++, k++){ /* para body found! */
if(paraBody) paraBody[j] = commandBody[k];
retval ++;
if( retval == paraBodyLength) goto exit;
}
goto exit;
}
i++;
}
exit:
if(paraBody) paraBody[retval] = 0x0;
return retval;
}
/**
* @brief Download a file via serial port
* @param None
* @retval None
*/
void SerialDownload(mico_flash_t flash, uint32_t flashdestination, int32_t maxRecvSize)
{
char Number[10] = " ";
int32_t Size = 0;
printf("Waiting for the file to be sent ... (press 'a' to abort)\r\n");
Size = Ymodem_Receive( &tab_1024[0], flash, flashdestination, maxRecvSize );
if (Size > 0)
{
printf("\n\n\r Successfully!\n\r\r\n Name: %s", FileName);
Int2Str((uint8_t *)Number, Size);
printf("\n\r Size: %s Bytes\r\n", Number);
}
else if (Size == -1)
{
printf("\n\n\rImage size is higher than memory!\n\r");
}
else if (Size == -2)
{
printf("\n\n\rVerification failed!\r\n");
}
else if (Size == -3)
{
printf("\r\n\nAborted.\r\n");
}
else
{
printf("\n\rReceive failed!\r\n");
}
}
/**
* @brief Upload a file via serial port.
* @param None
* @retval None
*/
void SerialUpload(mico_flash_t flash, uint32_t flashdestination, char * fileName, int32_t maxRecvSize)
{
uint8_t status = 0;
uint8_t key;
printf("Select Receive File\n\r");
MicoUartRecv( STDIO_UART, &key, 1, MICO_NEVER_TIMEOUT );
if (key == CRC16)
{
/* Transmit the flash image through ymodem protocol */
status = Ymodem_Transmit(flash, flashdestination, (uint8_t *)fileName, maxRecvSize);
if (status != 0)
{
printf("\n\rError while Transmitting\n\r");
}
else
{
printf("\n\rSuccessfully\n\r");
}
}
}
/**
* @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 idStr[4], startAddressStr[10], endAddressStr[10], flash_dev_str[4];
int32_t id, 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> ");
#if defined __GNUC__
fflush(stdout);
#endif
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, "PARUPDATE") == 0 || strcmp(cmdname, "3") == 0) {
if (findCommandPara(cmdbuf, "id", idStr, 0) != -1){
if(Str2Int((uint8_t *)idStr, &id)==0 && id > 0 && id < MICO_PARTITION_MAX ){ //Found Flash start address
printf ("\n\rIllegal start address.\n\r");
continue;
}
partition = MicoFlashGetInfo( (mico_partition_t)id );
}else{
printf ("\n\rPlease input correct MiCO partition id.\n\r");
continue;
}
if( findCommandPara(cmdbuf, "e", NULL, 0) != -1 ){
printf( "\n\rErasing %s...\n\r", partition->partition_description );
err = MicoFlashDisableSecurity( (mico_partition_t)id, 0x0, partition->partition_length );
require_noerr( err, exit);
MicoFlashErase( (mico_partition_t)id, 0x0, partition->partition_length );
continue;
}
if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){
printf ( "\n\rRead %s...\n\r", partition->partition_description );
SerialUpload( partition->partition_owner, partition->partition_start_addr, "Image.bin", partition->partition_length );
continue;
}
printf ("\n\rUpdating %s...\n\r", partition->partition_description );
err = MicoFlashDisableSecurity( (mico_partition_t)id, 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%lx to 0x%lx\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%lx to 0x%lx\n\r", flash_dev, startAddress, endAddress);
SerialUpload(flash_dev, startAddress, "FlashImage.bin", endAddress-startAddress+1);
continue;
}
printf ("\n\rUpdating dev%d content From 0x%lx to 0x%lx\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_MAX - 1; i++ ){
partition = MicoFlashGetInfo( (mico_partition_t)i );
if (partition->partition_owner == MICO_FLASH_NONE || partition->partition_description == NULL )
continue;
printf( "|ID:%d| %11s | Dev:%d | 0x%08lx | 0x%08lx |\r\n", i, 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;
}
}
/**
******************************************************************************
* @file menu.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief his file provides the software which contains the main menu routine.
* The main menu gives the options of:
* - downloading a new binary file,
* - uploading internal flash memory,
* - executing the binary file already loaded
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "mico.h"
#include "ymodem.h"
#include "platform_config.h"
#include "platform_internal.h"
#include "StringUtils.h"
#include "bootloader.h"
#include <ctype.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define CMD_STRING_SIZE 128
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern platform_flash_t platform_flash_peripherals[];
uint8_t tab_1024[1024] =
{
0
};
char FileName[FILE_NAME_LENGTH];
char ERROR_STR [] = "\n\r*** ERROR: %s\n\r"; /* ERROR message string in code */
extern char menu[];
extern void getline (char *line, int n); /* input line */
extern void startApplication( uint32_t app_addr );
/* Private function prototypes -----------------------------------------------*/
void SerialDownload(mico_flash_t flash, uint32_t flashdestination, int32_t maxRecvSize);
void SerialUpload(mico_flash_t flash, uint32_t flashdestination, char * fileName, int32_t maxRecvSize);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Analyse a command parameter
* @param commandBody: command string address
* @param para: The para we are looking for
* @param paraBody: A pointer to the buffer to receive the para body.
* @param paraBodyLength: The length, in bytes, of the buffer pointed to by the paraBody parameter.
* @retval the actual length of the paraBody received, -1 means failed to find this paras
*/
int findCommandPara(char *commandBody, char *para, char *paraBody, int paraBodyLength)
{
int i = 0;
int k, j;
int retval = -1;
char para_in_ram[100];
strncpy(para_in_ram, para, 100);
for (i = 0; para_in_ram[i] != 0; i++) { /* convert to upper characters */
para_in_ram[i] = toupper(para_in_ram[i]);
}
i = 0;
while(commandBody[i] != 0) {
if(commandBody[i] == '-' ){
for(j=i+1, k=0; *(para_in_ram+k)!=0x0; j++, k++ ){
if(commandBody[j] != *(para_in_ram+k)){
break;
}
}
if(*(para+k)!=0x0 || (commandBody[j]!=' '&& commandBody[j]!=0x0)){ /* para not found! */
i++;
continue;
}
retval = 0;
for (k = j+1; commandBody[k] == ' '; k++); /* skip blanks */
for(j = 0; commandBody[k] != ' ' && commandBody[k] != 0 && commandBody[k] != '-'; j++, k++){ /* para body found! */
if(paraBody) paraBody[j] = commandBody[k];
retval ++;
if( retval == paraBodyLength) goto exit;
}
goto exit;
}
i++;
}
exit:
if(paraBody) paraBody[retval] = 0x0;
return retval;
}
/**
* @brief Download a file via serial port
* @param None
* @retval None
*/
void SerialDownload(mico_flash_t flash, uint32_t flashdestination, int32_t maxRecvSize)
{
char Number[10] = " ";
int32_t Size = 0;
printf("Waiting for the file to be sent ... (press 'a' to abort)\r\n");
Size = Ymodem_Receive( &tab_1024[0], flash, flashdestination, maxRecvSize );
if (Size > 0)
{
printf("\n\n\r Successfully!\n\r\r\n Name: %s", FileName);
Int2Str((uint8_t *)Number, Size);
printf("\n\r Size: %s Bytes\r\n", Number);
}
else if (Size == -1)
{
printf("\n\n\rImage size is higher than memory!\n\r");
}
else if (Size == -2)
{
printf("\n\n\rVerification failed!\r\n");
}
else if (Size == -3)
{
printf("\r\n\nAborted.\r\n");
}
else
{
printf("\n\rReceive failed!\r\n");
}
}
/**
* @brief Upload a file via serial port.
* @param None
* @retval None
*/
void SerialUpload(mico_flash_t flash, uint32_t flashdestination, char * fileName, int32_t maxRecvSize)
{
uint8_t status = 0;
uint8_t key;
printf("Select Receive File\n\r");
MicoUartRecv( STDIO_UART, &key, 1, MICO_NEVER_TIMEOUT );
if (key == CRC16)
{
/* Transmit the flash image through ymodem protocol */
status = Ymodem_Transmit(flash, flashdestination, (uint8_t *)fileName, maxRecvSize);
if (status != 0)
{
printf("\n\rError while Transmitting\n\r");
}
else
{
printf("\n\rSuccessfully\n\r");
}
}
}
/**
* @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 idStr[4], startAddressStr[10], endAddressStr[10], flash_dev_str[4];
int32_t id, 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> ");
#if defined __GNUC__
fflush(stdout);
#endif
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, "PARUPDATE") == 0 || strcmp(cmdname, "3") == 0) {
if (findCommandPara(cmdbuf, "id", idStr, 0) != -1){
if(Str2Int((uint8_t *)idStr, &id)==0 && id > 0 && id < MICO_PARTITION_MAX ){ //Found Flash start address
printf ("\n\rIllegal start address.\n\r");
continue;
}
partition = MicoFlashGetInfo( (mico_partition_t)id );
}else{
printf ("\n\rPlease input correct MiCO partition id.\n\r");
continue;
}
if( findCommandPara(cmdbuf, "e", NULL, 0) != -1 ){
printf( "\n\rErasing %s...\n\r", partition->partition_description );
err = MicoFlashDisableSecurity( (mico_partition_t)id, 0x0, partition->partition_length );
require_noerr( err, exit);
MicoFlashErase( (mico_partition_t)id, 0x0, partition->partition_length );
continue;
}
if (findCommandPara(cmdbuf, "r", NULL, 0) != -1){
printf ( "\n\rRead %s...\n\r", partition->partition_description );
SerialUpload( partition->partition_owner, partition->partition_start_addr, "Image.bin", partition->partition_length );
continue;
}
printf ("\n\rUpdating %s...\n\r", partition->partition_description );
err = MicoFlashDisableSecurity( (mico_partition_t)id, 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%lx to 0x%lx\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%lx to 0x%lx\n\r", flash_dev, startAddress, endAddress);
SerialUpload(flash_dev, startAddress, "FlashImage.bin", endAddress-startAddress+1);
continue;
}
printf ("\n\rUpdating dev%d content From 0x%lx to 0x%lx\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_MAX - 1; i++ ){
partition = MicoFlashGetInfo( (mico_partition_t)i );
if (partition->partition_owner == MICO_FLASH_NONE || partition->partition_description == NULL )
continue;
printf( "|ID:%d| %11s | Dev:%d | 0x%08lx | 0x%08lx |\r\n", i, 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;
}
}

View File

@@ -1,73 +1,73 @@
/**
******************************************************************************
* @file MICODefine.h
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief This file provide empty header file for MiCO project build.
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#pragma once
#define APP_INFO "Bootloader"
#define FIRMWARE_REVISION "MICO_BASIC_1_0"
#define MANUFACTURER "MXCHIP Inc."
#define SERIAL_NUMBER "20140606"
#define PROTOCOL "com.mxchip.basic"
/************************************************************************
* Application thread stack size */
#define MICO_DEFAULT_APPLICATION_STACK_SIZE (1500)
/************************************************************************
* Enable wlan connection, start easylink configuration if no wlan settings are existed */
//#define MICO_WLAN_CONNECTION_ENABLE
#define MICO_WLAN_CONFIG_MODE CONFIG_MODE_EASYLINK_WITH_SOFTAP
#define EasyLink_TimeOut 60000 /**< EasyLink timeout 60 seconds. */
#define EasyLink_ConnectWlan_Timeout 20000 /**< Connect to wlan after configured by easylink.
Restart easylink after timeout: 20 seconds. */
/************************************************************************
* Device enter MFG mode if MICO settings are erased. */
//#define MFG_MODE_AUTO
/************************************************************************
* Command line interface */
#define MICO_CLI_ENABLE
/************************************************************************
* Start a system monitor daemon, application can register some monitor
* points, If one of these points is not executed in a predefined period,
* a watchdog reset will occur. */
#define MICO_SYSTEM_MONITOR_ENABLE
/************************************************************************
* MiCO TCP server used for configuration and ota. */
//#define MICO_CONFIG_SERVER_ENABLE
#define MICO_CONFIG_SERVER_PORT 8000
/**
******************************************************************************
* @file MICODefine.h
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief This file provide empty header file for MiCO project build.
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#pragma once
#define APP_INFO "Bootloader"
#define FIRMWARE_REVISION "MICO_BASIC_1_0"
#define MANUFACTURER "MXCHIP Inc."
#define SERIAL_NUMBER "20140606"
#define PROTOCOL "com.mxchip.basic"
/************************************************************************
* Application thread stack size */
#define MICO_DEFAULT_APPLICATION_STACK_SIZE (1500)
/************************************************************************
* Enable wlan connection, start easylink configuration if no wlan settings are existed */
//#define MICO_WLAN_CONNECTION_ENABLE
#define MICO_WLAN_CONFIG_MODE CONFIG_MODE_EASYLINK_WITH_SOFTAP
#define EasyLink_TimeOut 60000 /**< EasyLink timeout 60 seconds. */
#define EasyLink_ConnectWlan_Timeout 20000 /**< Connect to wlan after configured by easylink.
Restart easylink after timeout: 20 seconds. */
/************************************************************************
* Device enter MFG mode if MICO settings are erased. */
//#define MFG_MODE_AUTO
/************************************************************************
* Command line interface */
#define MICO_CLI_ENABLE
/************************************************************************
* Start a system monitor daemon, application can register some monitor
* points, If one of these points is not executed in a predefined period,
* a watchdog reset will occur. */
#define MICO_SYSTEM_MONITOR_ENABLE
/************************************************************************
* MiCO TCP server used for configuration and ota. */
//#define MICO_CONFIG_SERVER_ENABLE
#define MICO_CONFIG_SERVER_PORT 8000

File diff suppressed because it is too large Load Diff

View File

@@ -1,75 +1,75 @@
/**
******************************************************************************
* @file ymodem.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief This file provides all the software function headers related to the
* Ymodem protocol.
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __YMODEM_H_
#define __YMODEM_H_
/* Includes ------------------------------------------------------------------*/
#include "platform.h"
#include "common.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
#define PACKET_SEQNO_INDEX (1)
#define PACKET_SEQNO_COMP_INDEX (2)
#define PACKET_HEADER (3)
#define PACKET_TRAILER (2)
#define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER)
#define PACKET_SIZE (128)
#define PACKET_1K_SIZE (1024)
#define FILE_NAME_LENGTH (256)
#define FILE_SIZE_LENGTH (16)
#define SOH (0x01) /* start of 128-byte data packet */
#define STX (0x02) /* start of 1024-byte data packet */
#define EOT (0x04) /* end of transmission */
#define ACK (0x06) /* acknowledge */
#define NAK (0x15) /* negative acknowledge */
#define CA (0x18) /* two of these in succession aborts transfer */
#define CRC16 (0x43) /* 'C' == 0x43, request 16-bit CRC */
#define ABORT1 (0x41) /* 'A' == 0x41, abort by user */
#define ABORT2 (0x61) /* 'a' == 0x61, abort by user */
#define NAK_TIMEOUT (1000)
#define MAX_ERRORS (20)
/* Exported functions ------------------------------------------------------- */
int32_t Ymodem_Receive (uint8_t *buf, mico_flash_t flash, uint32_t flashdestination, int32_t maxRecvSize);
uint8_t Ymodem_Transmit (mico_flash_t, uint32_t, const uint8_t* , uint32_t );
#endif /* __YMODEM_H_ */
/**
******************************************************************************
* @file ymodem.c
* @author William Xu
* @version V2.0.0
* @date 05-Oct-2014
* @brief This file provides all the software function headers related to the
* Ymodem protocol.
******************************************************************************
*
* The MIT License
* Copyright (c) 2014 MXCHIP Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __YMODEM_H_
#define __YMODEM_H_
/* Includes ------------------------------------------------------------------*/
#include "platform.h"
#include "common.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
#define PACKET_SEQNO_INDEX (1)
#define PACKET_SEQNO_COMP_INDEX (2)
#define PACKET_HEADER (3)
#define PACKET_TRAILER (2)
#define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER)
#define PACKET_SIZE (128)
#define PACKET_1K_SIZE (1024)
#define FILE_NAME_LENGTH (256)
#define FILE_SIZE_LENGTH (16)
#define SOH (0x01) /* start of 128-byte data packet */
#define STX (0x02) /* start of 1024-byte data packet */
#define EOT (0x04) /* end of transmission */
#define ACK (0x06) /* acknowledge */
#define NAK (0x15) /* negative acknowledge */
#define CA (0x18) /* two of these in succession aborts transfer */
#define CRC16 (0x43) /* 'C' == 0x43, request 16-bit CRC */
#define ABORT1 (0x41) /* 'A' == 0x41, abort by user */
#define ABORT2 (0x61) /* 'a' == 0x61, abort by user */
#define NAK_TIMEOUT (1000)
#define MAX_ERRORS (20)
/* Exported functions ------------------------------------------------------- */
int32_t Ymodem_Receive (uint8_t *buf, mico_flash_t flash, uint32_t flashdestination, int32_t maxRecvSize);
uint8_t Ymodem_Transmit (mico_flash_t, uint32_t, const uint8_t* , uint32_t );
#endif /* __YMODEM_H_ */