We are using serial bootloader of TI’s CC2530. We are facing problem with CRC calculation and following are the details problem
- We are using TI’s CC2530F256 serial bootloader code for firmware upgrade.
- We are using CRC16 with 2 byte checksum.
- First 8KB flash of CC2530 i.e. memory location 0x0000 to 0x1FFF is reserved for bootloader code
- Bootloader calculates CRC of remaining flash excluding 6 pages of NV storage and 1 page of lock bits and 4 bytes of CRC locations (2 for CRC and 2 for shadow). PFA xcl file for the application.
- Once image is upgraded over serial, bootloader calculates its CRC and then writes it to CRC shadow location.
- We found that CRC calculated and CRC in flash never matches. But still jump to application image occurs.
- After digging more into bootloader code we found that, bootloader never calculates the CRC and it directly writes to CRC shadow location without checking it. Please look at the following code snippet where one can see that CRC is directly written to shadow. (sb_exec.c)
/***********************************************************************************************/
static uint8 sbCmnd(void)
{
uint16 tmp = BUILD_UINT16(sbBuf[SB_DATA_STATE], sbBuf[SB_DATA_STATE+1]) + SB_IMG_OSET;
uint16 crc[2];
uint8 len = 1;
uint8 rsp = SB_SUCCESS;
uint8 rtrn = FALSE;
switch (sbCmd2)
{
.
.
.
case SB_ENABLE_CMD:
HalFlashRead(HAL_SB_CRC_ADDR / HAL_FLASH_PAGE_SIZE,
HAL_SB_CRC_ADDR % HAL_FLASH_PAGE_SIZE,
(uint8 *)crc, sizeof(crc));
// Bootload master must have verified extra checks to be issuing the SB_ENABLE_CMD.
//if ((crc[0] != crc[1]) && (crc[0] != 0xFFFF) && (crc[0] != 0x0000))
if (crc[1] != crc[0])
{
crc[1] = crc[0];
HalFlashWrite((HAL_SB_CRC_ADDR / HAL_FLASH_WORD_SIZE), (uint8 *)crc, 1);
HalFlashRead( HAL_SB_CRC_ADDR / HAL_FLASH_PAGE_SIZE,
HAL_SB_CRC_ADDR % HAL_FLASH_PAGE_SIZE,
(uint8 *)crc, sizeof(crc));
}
// Bootload master must have verified extra checks to be issuing the SB_ENABLE_CMD.
//if ((crc[0] == crc[1]) && (crc[0] != 0xFFFF) && (crc[0] != 0x0000))
if (crc[0] == crc[1])
{
rtrn = TRUE;
}
else
{
rsp = SB_VALIDATE_FAILED;
}
break;
/***********************************************************************************************/
- Please let me know if my understanding is correct.
- We even tried to use the arithmetic sum option for CRC but in this case also CRC never matches.
- We need to add CRC check in our firmware upgrade scheme so as to check the integrity of the image.
We are stuck with this and your timely help onto this will be highly appreciated.
Thanks in advance.
Thanks and regards,
Vikas Javkar