Esempio n. 1
0
/*********************************************************************
 * @fn      HalOADChkDL
 *
 * @brief   Run the CRC16 Polynomial calculation over the DL image.
 *
 * @param   dlImagePreambleOffset - Offset into the monolithic DL image to read the preamble.
 *
 * @return  SUCCESS or FAILURE.
 *********************************************************************/
uint8 HalOADChkDL(uint8 dlImagePreambleOffset)
{
  preamble_t preamble;
  uint32 oset;
  uint16 crc = 0, crc2;

  HalOADRead(dlImagePreambleOffset, (uint8 *)&preamble, sizeof(preamble_t), HAL_OAD_DL);

  // Run the CRC calculation over the downloaded image.
  for (oset = 0; oset < preamble.len; oset++)
  {
    if ((oset < HAL_OAD_CRC_OSET) || (oset >= HAL_OAD_CRC_OSET+4))
    {
      uint8 buf;
      HalOADRead(oset, &buf, 1, HAL_OAD_DL);
      crc = runPoly(crc, buf);
    }
  }

  // IAR note explains that poly must be run with value zero for each byte of crc.
  crc = runPoly(crc, 0);
  crc = runPoly(crc, 0);

  HalOADRead(HAL_OAD_CRC_OSET, (uint8 *)&crc2, sizeof(crc2), HAL_OAD_DL);
  return (crc2 == crc) ? SUCCESS : FAILURE;
}
Esempio n. 2
0
/*********************************************************************
 * @fn      crcCalc
 *
 * @brief   Run the CRC16 Polynomial calculation over the RC image.
 *
 * @param   None.
 *
 * @return  The CRC16 calculated.
 */
static uint16 crcCalc(void)
{
  preamble_t preamble;
  uint32 oset;
  uint16 crc = 0;

  HalOADRead(PREAMBLE_OFFSET, (uint8 *)&preamble, sizeof(preamble_t), HAL_OAD_RC);

  // Run the CRC calculation over the active body of code.
  for (oset = 0; oset < preamble.len; oset++)
  {
    if ((oset < HAL_OAD_CRC_OSET) || (oset >= HAL_OAD_CRC_OSET+4))
    {
      uint8 buf;
      HalOADRead(oset, &buf, 1, HAL_OAD_RC);
      crc = runPoly(crc, buf);
    }
  }

  // IAR note explains that poly must be run with value zero for each byte of crc.
  crc = runPoly(crc, 0);
  crc = runPoly(crc, 0);

  return crc;
}
Esempio n. 3
0
/**************************************************************************************************
 * @fn          calcCRC
 *
 * @brief       Run the CRC16 Polynomial calculation over the RC image.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      The CRC16 calculated.
 **************************************************************************************************
 */
static uint16 calcCRC(void)
{
  uint32 addr;
  uint16 crc = 0;

  // Run the CRC calculation over the active body of code.
  for (addr = HAL_SB_IMG_ADDR; addr < HAL_SB_IMG_ADDR + HAL_SB_IMG_SIZE; addr++)
  {
    if (addr == HAL_SB_CRC_ADDR)
    {
      addr += 3;
    }
    else
    {
      uint8 buf;
      HalFlashRead(addr / HAL_FLASH_PAGE_SIZE, addr % HAL_FLASH_PAGE_SIZE, &buf, 1);
      crc = runPoly(crc, buf);
    }
  }

  // IAR note explains that poly must be run with value zero for each byte of crc.
  crc = runPoly(crc, 0);
  crc = runPoly(crc, 0);

  return crc;
}
Esempio n. 4
0
/******************************************************************************
 * @fn      crcCalc
 *
 * @brief   Run the CRC16 Polynomial calculation over the RC image.
 *
 * @param   None.
 *
 * @return  The CRC16 calculated.
 */
static uint16 crcCalc(void)
{
  preamble_t preamble;
  uint32 oset;
  uint8 *ptr;
  uint16 crc = 0;

  HalOTARead(PREAMBLE_OFFSET, (uint8 *)&preamble, sizeof(preamble_t), HAL_OTA_RC);
  preamble.programLength = HI_ROM_BEG + preamble.programLength - (LO_ROM_END - LO_ROM_BEG + 1);

  // Skipping 2-byte CRC and CRC shadow at the beginning of image.
  for (ptr = (uint8 *)LO_ROM_BEG+4; ptr <= (uint8 *)LO_ROM_END; ptr++)
  {
    crc = runPoly(crc, *ptr);
  }

  for (oset = HI_ROM_BEG; oset < preamble.programLength; oset++)
  {
    crc = runPoly(crc, __data20_read_char(oset));
  }

  return crc;
}
uint16_t calcCRC(uint8_t *firmwareBuffer)
{
  uint32_t addr;
  uint16_t crc = 0;

  // Run the CRC calculation over the active body of code.
  for (addr = 0; addr < HAL_SB_IMG_SIZE; addr++)
  {
	  if (addr == HAL_SB_CRC_ADDR - HAL_SB_IMG_ADDR)
	  {
		  addr += 3;
	  }
	  else
	  {
		  crc = runPoly(crc, firmwareBuffer[addr]);
	  }
  }
  // IAR note explains that poly must be run with value zero for each byte of crc.
  crc = runPoly(crc, 0);
  crc = runPoly(crc, 0);

  return crc;
}
Esempio n. 6
0
/******************************************************************************
 * @fn      crcCalc
 *
 * @brief   Run the CRC16 Polynomial calculation over the RC image.
 *
 * @param   None.
 *
 * @return  The CRC16 calculated.
 */
static uint16 crcCalc()
{
  uint32 oset;
  uint16 crc = 0;

  // Run the CRC calculation over the active body of code.
  for (oset = 0; oset < OTA_crcControl.programSize; oset++)
  {
    if ((oset < HAL_OTA_CRC_OSET) || (oset >= HAL_OTA_CRC_OSET + 4))
    {
      uint8 buf;
      HalOTARead(oset, &buf, 1, HAL_OTA_RC);
      crc = runPoly(crc, buf);
    }
  }

  return crc;
}
Esempio n. 7
0
/******************************************************************************
 * @fn      HalOTAChkDL
 *
 * @brief   Run the CRC16 Polynomial calculation over the DL image.
 *
 * @param   None
 *
 * @return  SUCCESS or FAILURE.
 */
uint8 HalOTAChkDL(uint8 dlImagePreambleOffset)
{
 (void)dlImagePreambleOffset;  // Intentionally unreferenced parameter

  uint32 oset;
  uint16 crc = 0;
  OTA_CrcControl_t crcControl;
  OTA_ImageHeader_t header;
  uint32 programStart;

#if HAL_OTA_XNV_IS_SPI
  XNV_SPI_INIT();
#endif

  // Read the OTA File Header
  HalOTARead(0, (uint8 *)&header, sizeof(OTA_ImageHeader_t), HAL_OTA_DL);

  // Calculate the update image start address
  programStart = header.headerLength + OTA_SUB_ELEMENT_HDR_LEN;

  // Get the CRC Control structure
  HalOTARead(programStart + HAL_OTA_CRC_OSET, (uint8 *)&crcControl, sizeof(crcControl), HAL_OTA_DL);

  if ((crcControl.programSize > HAL_OTA_DL_MAX) || (crcControl.programSize == 0))
  {
    return FAILURE;
  }

  // Run the CRC calculation over the downloaded image.
  for (oset = 0; oset < crcControl.programSize; oset++)
  {
    if ((oset < HAL_OTA_CRC_OSET) || (oset >= HAL_OTA_CRC_OSET+4))
    {
      uint8 buf;
      HalOTARead(oset + programStart, &buf, 1, HAL_OTA_DL);
      crc = runPoly(crc, buf);
    }
  }

  return (crcControl.crc[0] == crc) ? SUCCESS : FAILURE;
}
Esempio n. 8
0
/******************************************************************************
 * @fn      HalOTAChkDL
 *
 * @brief   Run the CRC16 Polynomial calculation over the DL image.
 *
 * @param   dlImagePreambleOffset - Offset into the monolithic DL image to read the preamble.
 *
 * @return  SUCCESS or FAILURE.
 */
uint8 HalOTAChkDL(uint8 dlImagePreambleOffset)
{
  preamble_t preamble;
  uint32 oset;
  uint16 crc = 0, crc2;

  HalXNVRead(DATA_OFFSET + PREAMBLE_OFFSET, (uint8 *)&preamble, sizeof(preamble_t));

  if (preamble.programLength == 0 || preamble.programLength == 0xFFFFFFFF)
    return FAILURE;

  // Run the CRC calculation over the downloaded image.
  for (oset = 4; oset < preamble.programLength; oset++)
  {
    uint8 buf;
    HalXNVRead(oset+DATA_OFFSET, &buf, 1);
    crc = runPoly(crc, buf);
  }

  HalXNVRead(DATA_OFFSET, (uint8 *)&crc2, 2);  // Read the CRC from the XNV.
  return (crc2 == crc) ? SUCCESS : FAILURE;
}