diff --git a/aqhome/hexfile/flashrecord.c b/aqhome/hexfile/flashrecord.c index 2d7469e..27afdc9 100644 --- a/aqhome/hexfile/flashrecord.c +++ b/aqhome/hexfile/flashrecord.c @@ -22,7 +22,7 @@ GWEN_LIST_FUNCTIONS(AQH_FLASHRECORD, AQH_FlashRecord) -AQH_HEXFILERECORD *_sampleAdjacentHexfileRecords(AQH_FLASHRECORD *fr, AQH_HEXFILERECORD *hrStart); +const AQH_HEXFILERECORD *_sampleAdjacentHexfileRecords(AQH_FLASHRECORD *fr, const AQH_HEXFILERECORD *hrStart); @@ -124,10 +124,10 @@ void AQH_FlashRecord_CopyAndSetData(AQH_FLASHRECORD *fr, uint32_t dataLength, co -AQH_FLASHRECORD_LIST *AQH_FlashRecord_fromHexfileRecords(AQH_HEXFILERECORD_LIST *hexFileRecordList) +AQH_FLASHRECORD_LIST *AQH_FlashRecord_fromHexfileRecords(const AQH_HEXFILERECORD_LIST *hexFileRecordList) { AQH_FLASHRECORD_LIST *flashRecordList; - AQH_HEXFILERECORD *hr; + const AQH_HEXFILERECORD *hr; uint32_t currentOffset=0; flashRecordList=AQH_FlashRecord_List_new(); @@ -154,7 +154,18 @@ AQH_FLASHRECORD_LIST *AQH_FlashRecord_fromHexfileRecords(AQH_HEXFILERECORD_LIST return NULL; } ptr=AQH_HexfileRecord_GetDataPointer(hr); - currentOffset=((ptr[0]<<8)+ptr[1])<<4; + currentOffset=((ptr[1]<<8)+ptr[0])<<4; + } + else if (t==AQH_HEXFILERECORD_TYPE_EXTLINEARADDR) { + const uint8_t *ptr; + + if (AQH_HexfileRecord_GetByteCount(hr)<2) { + DBG_ERROR(AQH_LOGDOMAIN, "Invalid EXTLINEARADDR record (04) in file (too few data bytes)"); + AQH_FlashRecord_List_free(flashRecordList); + return NULL; + } + ptr=AQH_HexfileRecord_GetDataPointer(hr); + currentOffset=((ptr[1]<<8)+ptr[0])<<16; } else if (t==AQH_HEXFILERECORD_TYPE_EOF) { break; @@ -173,10 +184,10 @@ AQH_FLASHRECORD_LIST *AQH_FlashRecord_fromHexfileRecords(AQH_HEXFILERECORD_LIST -AQH_HEXFILERECORD *_sampleAdjacentHexfileRecords(AQH_FLASHRECORD *fr, AQH_HEXFILERECORD *hrStart) +const AQH_HEXFILERECORD *_sampleAdjacentHexfileRecords(AQH_FLASHRECORD *fr, const AQH_HEXFILERECORD *hrStart) { - AQH_HEXFILERECORD *hrNext; - AQH_HEXFILERECORD *hr; + const AQH_HEXFILERECORD *hrNext; + const AQH_HEXFILERECORD *hr; uint32_t len=0; hrNext=AQH_HexfileRecord_List_FindNonAdjacentDataRecord(hrStart); diff --git a/aqhome/hexfile/flashrecord.h b/aqhome/hexfile/flashrecord.h index 1d485a4..98579c0 100644 --- a/aqhome/hexfile/flashrecord.h +++ b/aqhome/hexfile/flashrecord.h @@ -21,7 +21,7 @@ GWEN_LIST_FUNCTION_LIB_DEFS(AQH_FLASHRECORD, AQH_FlashRecord, AQHOME_API) AQHOME_API AQH_FLASHRECORD *AQH_FlashRecord_new(); -AQHOME_API AQH_FLASHRECORD_LIST *AQH_FlashRecord_fromHexfileRecords(AQH_HEXFILERECORD_LIST *hexFileRecordList); +AQHOME_API AQH_FLASHRECORD_LIST *AQH_FlashRecord_fromHexfileRecords(const AQH_HEXFILERECORD_LIST *hexFileRecordList); AQHOME_API void AQH_FlashRecord_free(AQH_FLASHRECORD *fr); diff --git a/aqhome/hexfile/hexfile.c b/aqhome/hexfile/hexfile.c index 20cd902..4702113 100644 --- a/aqhome/hexfile/hexfile.c +++ b/aqhome/hexfile/hexfile.c @@ -24,7 +24,7 @@ static const char *_readRecord(AQH_HEXFILERECORD *hr, const char *s); static void _writeRecord(AQH_HEXFILERECORD *hr, GWEN_BUFFER *buffer); static int _sumValuesForChecksum(const AQH_HEXFILERECORD *hr); -static int _readWord(const char *s); +static int _readWord(const char *s); /* big endian */ static int _readByte(const char *s); static int _readNibble(const char *s); diff --git a/aqhome/hexfile/hexfile.h b/aqhome/hexfile/hexfile.h index 216c79f..482814c 100644 --- a/aqhome/hexfile/hexfile.h +++ b/aqhome/hexfile/hexfile.h @@ -17,6 +17,10 @@ #include +/** + * Reader and writer for INTEL HEX files (see https://en.wikipedia.org/wiki/Intel_HEX). + */ + typedef struct AQH_HEXFILE AQH_HEXFILE; diff --git a/aqhome/hexfile/hexfilerecord.c b/aqhome/hexfile/hexfilerecord.c index 25c11a1..9d8a020 100644 --- a/aqhome/hexfile/hexfilerecord.c +++ b/aqhome/hexfile/hexfilerecord.c @@ -143,7 +143,7 @@ void AQH_HexfileRecord_SetData(AQH_HEXFILERECORD *hr, const uint8_t *ptr, uint8_ -AQH_HEXFILERECORD *AQH_HexfileRecord_List_FindNonAdjacentDataRecord(AQH_HEXFILERECORD *hr) +const AQH_HEXFILERECORD *AQH_HexfileRecord_List_FindNonAdjacentDataRecord(const AQH_HEXFILERECORD *hr) { uint16_t expectedAddr; int cnt=0; diff --git a/aqhome/hexfile/hexfilerecord.h b/aqhome/hexfile/hexfilerecord.h index ba3f8ae..6a7ec4e 100644 --- a/aqhome/hexfile/hexfilerecord.h +++ b/aqhome/hexfile/hexfilerecord.h @@ -55,7 +55,7 @@ AQHOME_API void AQH_HexfileRecord_SetData(AQH_HEXFILERECORD *hr, const uint8_t * * @return next non-contiguous or non-data record (NULL if none) * @param hr record to start with (i.e. whose successor are checked for continuity) */ -AQHOME_API AQH_HEXFILERECORD *AQH_HexfileRecord_List_FindNonAdjacentDataRecord(AQH_HEXFILERECORD *hr); +AQHOME_API const AQH_HEXFILERECORD *AQH_HexfileRecord_List_FindNonAdjacentDataRecord(const AQH_HEXFILERECORD *hr);