1 Reply Latest reply on Jul 24, 2017 7:00 AM by user_274318315

    [Solved] Flash metadata ...

    user_274318315

      I'd be eternally grateful if someone could help me out here. I am trying to write bootable application metadata directly to flash for an SD card based bootloader. The system has ECC disabled and uses a CY8C5888LTQ-LP097 (one of the USB stick parts). Whatever I seem to do with flash is failing.

         

      Comments on the code are in-line. First is a snippet showing how writing metadata is tested, then the code for flashing the metadata structure itself.

         

      TAIA

         

      Jerry.

         
              // structure to manage metadata as per http://www.cypress.com/file/44531/download P21         PSOC5_Metadata metadata;         // fill with checkbyte         memset(&metadata,0xEE,sizeof(PSOC5_Metadata));         // first get existing metadata. this works, we get valid numbers.         uint32 length = Bootloader_GetMetadata(Bootloader_GET_BTLDB_LENGTH,0);         uint32 checksum = Bootloader_GetMetadata(Bootloader_GET_BTLDB_CHECKSUM,0);         // update using our own API         metadata.ActiveApplication = 1;         metadata.AppCheckSum = checksum;         metadata.AppLength = length;         metadata.AppAddress = Bootloader_GetMetadata(Bootloader_GET_BTLDB_ADDR,0);         // status returns CYRET_SUCCESS         status = UpdateMetadata(0,&metadata);         // and check again. these values now come back as zero (!)         length = Bootloader_GetMetadata(Bootloader_GET_BTLDB_LENGTH,0);         checksum = Bootloader_GetMetadata(Bootloader_GET_BTLDB_CHECKSUM,0);         // this (predictably) fails         status = Bootloader_ValidateBootloadable(0);  
         

       

         
      // full row buffer uint8 metaBuf[CYDEV_FLS_ROW_SIZE];  cystatus UpdateMetadata(int appId,PSOC5_Metadata* metadata) {     PSOC5_Metadata* pc = 0;     cystatus status = CySetTemp();     if (status != CYRET_SUCCESS)     {         return status;     }     //     size_t bytes = sizeof(PSOC5_Metadata);     // clear buffer     memset(&metaBuf[0],0,CYDEV_FLS_ROW_SIZE);     // copy in metadata. See      // memcpy(&metaBuf[0],metadata,bytes);     // See AN60137 section A.3. Data is _not_ aligned to block start     memcpy(&metabuf[CYDEV_FLS_ROW_SIZE - 64],metadata,bytes);     // choose which row to update     uint16 row = Bootloader_MD_ROW_NUM(appId);     // Update metadata in flash     status = CyWriteRowData(Bootloader_MD_FLASH_ARRAY_NUM, row, metaBuf);     //     CyFlushCache();     // sanity check ...     pc = (PSOC5_Metadata*) &metaBuf[0];     //     return status; }  
        • 1. Re: [Solved] Flash metadata ...
          user_274318315

          OK, it's all in the spec. The metadata block is aligned 64 byes from the end, not to the block start ...

             
          A.3  Metadata Layout in Flash The metadata section is the highest 64-byte block of flash, and is used as a common area for both bootloader and bootloadable projects, as Figure 28 shows. Various parameters, depending upon the device used, are stored in this block, as Table 6 shows. For the multi-application bootloader, there are two sets of metadata. The metadata of application 1 occupies the highest 64-byte block of flash and the metadata of application 2 occupies 64 bytes from the subsequent flash row.