コード例 #1
0
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 );
  }
}
コード例 #2
0
ファイル: file.c プロジェクト: fritsjek/MICO-1
//-----------------------
void lua_spiffs_mount() {
    mico_logic_partition_t* part;
    spiffs_config cfg;    

    part = MicoFlashGetInfo( MICO_PARTITION_LUA );
	
    cfg.phys_size = part->partition_length;
    cfg.phys_addr = part->partition_start_addr; // start spiffs at start of spi flash
    cfg.phys_erase_block = 65536/2;             // according to datasheet
    cfg.log_block_size = 65536;                 // let us not complicate things
    cfg.log_page_size = LOG_PAGE_SIZE;          // as we said */
    
    cfg.hal_read_f = lspiffs_read;
    cfg.hal_write_f = lspiffs_write;
    cfg.hal_erase_f = lspiffs_erase;
    
    //if (part == NULL)
    //    goto exit;
    //MicoFlashInitialize(MICO_FLASH_FOR_LUA);
    
    if(SPIFFS_mounted(&fs)) return;
    
    int res = SPIFFS_mount(&fs,
      &cfg,
      spiffs_work_buf,
      spiffs_fds,
      sizeof(spiffs_fds),
      spiffs_cache_buf,
      sizeof(spiffs_cache_buf),
      0);
}
コード例 #3
0
//---------------
void _mount(void)
{
  mico_logic_partition_t* part;
  spiffs_config cfg;    

  part = MicoFlashGetInfo( MICO_PARTITION_LUA );
      
  cfg.phys_size = part->partition_length;
  cfg.phys_addr = 0;                        // start at beginning of the LUA partition
  cfg.log_block_size = LOG_BLOCK_SIZE;      // logical block size
  cfg.phys_erase_block = PHYS_ERASE_BLOCK;  // logical erase block size
  cfg.log_page_size = LOG_PAGE_SIZE;        // logical page size
  
  cfg.hal_read_f = lspiffs_read;
  cfg.hal_write_f = lspiffs_write;
  cfg.hal_erase_f = lspiffs_erase;

  int res = SPIFFS_mount(&fs,
    &cfg,
    spiffs_work_buf,
    spiffs_fds,
    sizeof(spiffs_fds),
    NULL,
    0,
    NULL);
}
コード例 #4
0
uint32_t platform_get_wifi_image_size(void)
{
#define READ_LEN 2048
    mico_logic_partition_t *driver_partition = MicoFlashGetInfo( MICO_PARTITION_RF_FIRMWARE );
    uint32_t offset = driver_partition->partition_length;
    uint32_t *p;
    uint32_t *buf = (uint32_t *)malloc(READ_LEN);

    uint32_t image_size = driver_partition->partition_length;
    do {
        offset -= READ_LEN; // Next block
        MicoFlashRead( MICO_PARTITION_RF_FIRMWARE, &offset, (uint8_t *)buf, READ_LEN);
        offset -= READ_LEN; // MicoFlashRead will increase FlashAddress READ_LEN, move back.
        p = buf + (READ_LEN - 4)/sizeof(uint32_t);
        while(p >= buf) {
            if (*p != 0xFFFFFFFF) {
                goto EXIT;
            }
            p--;
            image_size -= 4;
        }
    } while (offset > 0);

EXIT:
    free(buf);
    return image_size;
}
コード例 #5
0
ファイル: system_factory_test.c プロジェクト: yangk/Mico
void app_crc (char *str,int len)
{
  mico_logic_partition_t *partition_flash;
  CRC16_Context mfg_context;
  uint8_t *mfgbuf;
  uint16_t crc = 0;
  uint32_t flash_addr = 0x0;
  int flash_len,buf_len;
  mfgbuf = malloc (1024);
  partition_flash = MicoFlashGetInfo (MICO_PARTITION_APPLICATION);
  flash_len = partition_flash->partition_length;
  CRC16_Init (&mfg_context);

  while (flash_len > 0) {
    if (flash_len > 1024) {
      buf_len = 1024;
    }  else {
      buf_len = flash_len;
    }

    flash_len -= buf_len;
    MicoFlashRead (MICO_PARTITION_APPLICATION, &flash_addr, (uint8_t *)mfgbuf, buf_len);
    CRC16_Update (&mfg_context, (uint8_t *)mfgbuf, buf_len);
  }

  CRC16_Final (&mfg_context, &crc);

  snprintf (str, len, "%04X", crc);

}
コード例 #6
0
ファイル: zc_mx_adpter.c プロジェクト: yinhongxing/mico
u32 MX_FirmwareUpdateFinish(u32 u32TotalLen)
{
#if 1
    mico_logic_partition_t* part;
    int len;
    OSStatus err = kNoErr;
    uint32_t update_data_offset = 0x0;
    CRC16_Context crc_context;
    u32 total_len = u32TotalLen;

    CRC16_Init( &crc_context );
    
    mico_logic_partition_t  *para_partition_info;
    para_partition_info = MicoFlashGetInfo(MICO_PARTITION_OTA_TEMP);
    memset(&(context->flashContentInRam.bootTable), 0, sizeof(boot_table_t));
    context->flashContentInRam.bootTable.length = u32TotalLen;
    context->flashContentInRam.bootTable.start_address = para_partition_info->partition_start_addr;
    context->flashContentInRam.bootTable.type = 'A';
    context->flashContentInRam.bootTable.upgrade_type = 'U';
    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);
      total_len -= len;
      CRC16_Update( &crc_context, data, len );
    }
    CRC16_Final( &crc_context, &context->flashContentInRam.bootTable.crc );
    MICOUpdateConfiguration(context);
    return ZC_RET_OK;
#endif
}
コード例 #7
0
uint32_t platform_get_wifi_image(unsigned char* buffer, uint32_t size, uint32_t offset)
{
    uint32_t buffer_size;
    uint32_t read_address = offset;
    mico_logic_partition_t *driver_partition = MicoFlashGetInfo( MICO_PARTITION_RF_FIRMWARE );
    
    if( image_size == 0)
      image_size = driver_partition->partition_length;
    
    buffer_size = MIN(size, (image_size - offset));

    MicoFlashRead( MICO_PARTITION_RF_FIRMWARE, &read_address, buffer, buffer_size);
    return buffer_size;
}
コード例 #8
0
ファイル: zc_mx_adpter.c プロジェクト: yinhongxing/mico
/*************************************************
* Function: HF_WriteDataToFlash
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void MX_WriteDataToFlash(u8 *pu8Data, u16 u16Len)
{
    mico_logic_partition_t  *para_partition_info;
    OSStatus err = kNoErr;
    uint32_t para_offset = PARA_OFFSET;
    para_partition_info = MicoFlashGetInfo(MICO_PARTITION_PARAMETER_2);
    require_action( para_partition_info->partition_owner != MICO_FLASH_NONE, exit, err = kUnsupportedErr );
    err = MicoFlashErase(MICO_PARTITION_PARAMETER_2 ,para_offset, para_partition_info->partition_length-PARA_OFFSET);
    require_noerr(err, exit);
    err = MicoFlashWrite( MICO_PARTITION_PARAMETER_2, &para_offset, pu8Data, u16Len );
    require_noerr(err, exit);
 exit:
  if(err != kNoErr) update_log("Update exit with err = %d", err);
    
}
コード例 #9
0
void mico_set_bootload_ver(void)
{
   char ver[33];
   mico_logic_partition_t *boot_partition = MicoFlashGetInfo( MICO_PARTITION_BOOTLOADER );
   uint32_t flashaddr =  boot_partition->partition_length - 0x20;
   int i;

   memset(ver, 0, sizeof(ver));
   MicoFlashRead( MICO_PARTITION_BOOTLOADER, &flashaddr, (uint8_t *)ver , 32);
   for(i=0;i<32;i++) {
       if (ver[i] != 0xFF)
           return;
   }
   snprintf(ver, 33, "%s %s %d", MODEL, Bootloader_REVISION , STDIO_UART_BAUDRATE);
   flashaddr =  boot_partition->partition_length - 0x20;
   MicoFlashDisableSecurity( MICO_PARTITION_BOOTLOADER, 0x0, boot_partition->partition_length );
   MicoFlashWrite( MICO_PARTITION_BOOTLOADER, &flashaddr, (uint8_t *)ver , 32);
}
コード例 #10
0
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 ();
  }
}
コード例 #11
0
ファイル: zc_mx_adpter.c プロジェクト: yinhongxing/mico
/*************************************************
* Function: MX_FirmwareUpdate
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
u32 MX_FirmwareUpdate(u8 *pu8FileData, u32 u32Offset, u32 u32DataLen)
{
#if 1
    mico_logic_partition_t  *para_partition_info;
    OSStatus err = kNoErr;
    if (0 == u32Offset)
    {   
        para_partition_info = MicoFlashGetInfo(MICO_PARTITION_OTA_TEMP);
        require_action( para_partition_info->partition_owner != MICO_FLASH_NONE, exit, err = kUnsupportedErr );
        err = MicoFlashErase(MICO_PARTITION_OTA_TEMP , 0, para_partition_info->partition_length );
        require_noerr(err, exit);
    } 
    err = MicoFlashWrite( MICO_PARTITION_OTA_TEMP, &u32Offset, pu8FileData, u32DataLen );
    require_noerr(err, exit);
    return ZC_RET_OK;
exit:
  if(err != kNoErr) update_log("Update exit with err = %d", err);
    return ZC_RET_ERROR;
#endif
}
コード例 #12
0
teZcbStatus ePDM_Init(mico_Context_t* mico_context)
{
    OSStatus err;
    user_zigbeePDM_log("Create PDM lock");
    mico_rtos_init_mutex(&sLock);
    mico_logic_partition_t *zigbeePDM_partition_info;
    //mico_logic_partition_t *p1_info;
    uint8_t read_test[100]= {0};
    uint8_t i = 0;
    uint32_t dest_offset = 0;
    uint8_t data_write[6]= {0x06,0x05,0x04,0x03,0x02,0x01};

    mico_rtos_lock_mutex(&sLock);

#if 0
    //init  MICO_PARTITION_ZIGBEEPDM_TEMP
    err = MicoFlashInitialize(MICO_PARTITION_ZIGBEEPDM_TEMP);
    require_noerr(err, exit);

    // Get Info  MICO_PARTITION_ZIGBEEPDM_TEMP
    zigbeePDM_partition_info = MicoFlashGetInfo(MICO_PARTITION_ZIGBEEPDM_TEMP);
    user_zigbeePDM_log("ZigBee PDM Partition info:start_addr:%x ,length:%x",zigbeePDM_partition_info->partition_start_addr,zigbeePDM_partition_info->partition_length);

    //Erase MICO_PARTITION_ZIGBEEPDM_TEMP
    err = MicoFlashErase( MICO_PARTITION_ZIGBEEPDM_TEMP, 0x0, zigbeePDM_partition_info->partition_length);
    require_noerr(err, exit);


    mico_thread_msleep(100);	//sleep


    //MicoFlashWrite(mico_partition_t partition, volatile uint32_t * off_set, uint8_t * inBuffer, uint32_t inBufferLength);

    //Write MICO_PARTITION_ZIGBEEPDM_TEMP
    err = MicoFlashWrite(MICO_PARTITION_ZIGBEEPDM_TEMP, &dest_offset, (uint8_t *)data_write, sizeof(data_write));
    require_noerr(err, exit);
#endif

#if 0
    mico_context -> user_config_data = (void*)data_write;
    mico_context -> user_config_data_size = 10;
    err = mico_system_context_update(mico_context);
    require_noerr(err, exit);
    mico_thread_msleep(1000);
#endif

#if 0
    //Read
    dest_offset = 0;
    err = MicoFlashRead(MICO_PARTITION_ZIGBEEPDM_TEMP, &dest_offset, read_test, 5);
    require_noerr(err, exit);
#endif

#if 0
    err = MicoFlashErase( MICO_PARTITION_PARAMETER_1, 0x0, 60);
    require_noerr(err, exit);
    mico_thread_msleep(10);

    err = MicoFlashWrite( MICO_PARTITION_PARAMETER_1, &dest_offset, "aaaaa", 5);
    require_noerr(err, exit);


    p1_info = MicoFlashGetInfo(MICO_PARTITION_PARAMETER_1);
    err = MicoFlashRead(MICO_PARTITION_PARAMETER_1, &dest_offset, read_test, 60);
    require_noerr(err, exit);
#endif

#if 0
    //Output
    for(i = 0; i<5; i++)
    {
        printf("0x%x ",read_test[i]);
    }
    printf("\r\n");
#endif
    //MicoFlashWrite( MICO_PARTITION_OTA_TEMP, &context->offset, (uint8_t *)inData, inLen);

    //MicoFlashRead(MICO_PARTITION_OTA_TEMP, &flashaddr, (uint8_t *)md5_recv, 16);

    //err = MicoFlashDisableSecurity( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition_info->partition_length );



    //if (sqlite3_open_v2(pcPDMFile, &pDb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) != SQLITE_OK)
    //{
    //    daemon_log(LOG_ERR, "Error initialising PDM database (%s)", sqlite3_errmsg(pDb));
    //    return E_ZCB_ERROR;
    //}
    //user_zigbeePDM_log("PDM Database opened\n");
    {
        //const char *pcTableDef = "CREATE TABLE IF NOT EXISTS pdm (id INTEGER, size INTEGER, numblocks INTEGER, block INTEGER, blocksize INTEGER, data BLOB, PRIMARY KEY (id,block))";
        //char *pcErr;

        //user_zigbeePDM_log("Execute SQL: '%s'\n", pcTableDef);

        //if (sqlite3_exec(pDb, pcTableDef, NULL, NULL, &pcErr) != SQLITE_OK)
        //{
        //    mico_log("Error creating table (%s)", pcErr);
        //sqlite3_free(pcErr);
        //mico_rtos_unlock_mutex(&sLock);
        //return E_ZCB_ERROR;
        //}
    }
    //user_zigbeePDM_log("PDM Database initialised\n");

    //eSL_AddListener(E_SL_MSG_PDM_AVAILABLE_REQUEST,         PDM_HandleAvailableRequest,     NULL);
    //eSL_AddListener(E_SL_MSG_PDM_LOAD_RECORD_REQUEST,       PDM_HandleLoadRequest,          NULL);
    //eSL_AddListener(E_SL_MSG_PDM_SAVE_RECORD_REQUEST,       PDM_HandleSaveRequest,          NULL);
    //eSL_AddListener(E_SL_MSG_PDM_DELETE_ALL_RECORDS_REQUEST,PDM_HandleDeleteAllRequest,     NULL);


    mico_rtos_unlock_mutex(&sLock);
    return E_ZCB_OK;
exit:
    mico_rtos_unlock_mutex(&sLock);
    return err;
}
コード例 #13
0
/**
* @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;
  }
}
コード例 #14
0
void init_platform_bootloader( void )
{
  CRC8_Context crc;
  OSStatus err = kNoErr;
  mico_logic_partition_t *rf_partition = MicoFlashGetInfo( MICO_PARTITION_RF_FIRMWARE );
  
  MicoGpioInitialize( (mico_gpio_t)MICO_SYS_LED, OUTPUT_PUSH_PULL );
  MicoGpioOutputLow( (mico_gpio_t)MICO_SYS_LED );
  MicoGpioInitialize( (mico_gpio_t)MICO_RF_LED, OUTPUT_OPEN_DRAIN_NO_PULL );
  MicoGpioOutputHigh( (mico_gpio_t)MICO_RF_LED );
  
  MicoGpioInitialize((mico_gpio_t)BOOT_SEL, INPUT_PULL_UP);
  MicoGpioInitialize((mico_gpio_t)MFG_SEL, INPUT_PULL_UP);
  
#ifdef USE_MiCOKit_EXT
  dc_motor_init( );
  dc_motor_set( 0 );
  
  rgb_led_init();
  rgb_led_open(0, 0, 0);
#endif
  
  /* Specific operations used in EMW3165 production */
#define NEED_RF_DRIVER_COPY_BASE    ((uint32_t)0x08008000)
#define TEMP_RF_DRIVER_BASE         ((uint32_t)0x08040000)
#define TEMP_RF_DRIVER_END          ((uint32_t)0x0807FFFF)
  
  const uint8_t isDriverNeedCopy = *(uint8_t *)(NEED_RF_DRIVER_COPY_BASE);
  const uint32_t totalLength = rf_partition->partition_length;
  const uint8_t crcResult = *(uint8_t *)(TEMP_RF_DRIVER_END);
  uint8_t targetCrcResult = 0;
  
  uint32_t copyLength;
  uint32_t destStartAddress_tmp = rf_partition->partition_start_addr;
  uint32_t sourceStartAddress_tmp = TEMP_RF_DRIVER_BASE;
  uint32_t i;
  
  if ( isDriverNeedCopy != 0x0 )
    return;
  
  platform_log( "Bootloader start to copy RF driver..." );
  /* Copy RF driver to SPI flash */

  err = platform_flash_init( &platform_flash_peripherals[ MICO_FLASH_SPI ] );
  require_noerr(err, exit);
  err = platform_flash_init( &platform_flash_peripherals[ MICO_FLASH_EMBEDDED ] );
  require_noerr(err, exit);
  err = platform_flash_erase( &platform_flash_peripherals[ MICO_FLASH_SPI ], 
    rf_partition->partition_start_addr, rf_partition->partition_start_addr + rf_partition->partition_length - 1 );
  require_noerr(err, exit);
  platform_log( "Time: %d", mico_get_time_no_os() );
  
  for(i = 0; i <= totalLength/SizePerRW; i++){
    if( i == totalLength/SizePerRW ){
      if(totalLength%SizePerRW)
        copyLength = totalLength%SizePerRW;
      else
        break;
    }else{
      copyLength = SizePerRW;
    }
    printf(".");
    err = platform_flash_read( &platform_flash_peripherals[ MICO_FLASH_EMBEDDED ], &sourceStartAddress_tmp, data , copyLength );
    require_noerr( err, exit );
    err = platform_flash_write( &platform_flash_peripherals[ MICO_FLASH_SPI ], &destStartAddress_tmp, data, copyLength );
    require_noerr(err, exit);
  }
  
  printf("\r\n");
  /* Check CRC-8 check-sum */
  platform_log( "Bootloader start to verify RF driver..." );
  sourceStartAddress_tmp = TEMP_RF_DRIVER_BASE;
  destStartAddress_tmp = rf_partition->partition_start_addr;
  
  CRC8_Init( &crc );
  for(i = 0; i <= totalLength/SizePerRW; i++){
    if( i == totalLength/SizePerRW ){
      if(totalLength%SizePerRW)
        copyLength = totalLength%SizePerRW;
      else
        break;
    }else{
      copyLength = SizePerRW;
    }
    printf(".");
    err = platform_flash_read( &platform_flash_peripherals[ MICO_FLASH_SPI ], &destStartAddress_tmp, data, copyLength );
    require_noerr( err, exit );   
      
    CRC8_Update( &crc, data, copyLength);
  }
  CRC8_Final( &crc, &targetCrcResult );
  
  printf("\r\n");
  //require_string( crcResult == targetCrcResult, exit, "Check-sum error" ); 
  if( crcResult != targetCrcResult ){
    platform_log("Check-sum error");
    while(1);
  }
  /* Clear RF driver from temperary storage */
  platform_log("Bootloader start to clear RF driver temporary storage...");
  
  /* Clear copy tag */
  err = platform_flash_erase( &platform_flash_peripherals[ MICO_FLASH_EMBEDDED ], NEED_RF_DRIVER_COPY_BASE, NEED_RF_DRIVER_COPY_BASE);
  require_noerr(err, exit);
  
exit:
  return;
}