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 memcpy(&metaBuf[0],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; }