Refs #343. Added option to specify a memory address offset to BltFirmwareLoadFromFile.

git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@275 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
Frank Voorburg 2017-06-13 16:00:29 +00:00
parent be5f70b264
commit 97cadfc1da
7 changed files with 27 additions and 16 deletions

View File

@ -170,8 +170,8 @@ int main(int argc, char const * const argv[])
printf("Loading firmware data from file..."); (void)fflush(stdout); printf("Loading firmware data from file..."); (void)fflush(stdout);
/* Initialize the firmware data module using the S-record parser. */ /* Initialize the firmware data module using the S-record parser. */
BltFirmwareInit(BLT_FIRMWARE_PARSER_SRECORD); BltFirmwareInit(BLT_FIRMWARE_PARSER_SRECORD);
/* Load firmware data from the firmware file. */ /* Load firmware data from the firmware file without memory address offset. */
if (BltFirmwareLoadFromFile(appFirmwareFile) != BLT_RESULT_OK) if (BltFirmwareLoadFromFile(appFirmwareFile, 0) != BLT_RESULT_OK)
{ {
/* Set error code. */ /* Set error code. */
result = RESULT_ERROR_FIRMWARE_LOAD; result = RESULT_ERROR_FIRMWARE_LOAD;

View File

@ -93,10 +93,12 @@ void FirmwareTerminate(void)
** \brief Uses the linked parser to load the firmware data from the specified file ** \brief Uses the linked parser to load the firmware data from the specified file
** into the linked list of segments. ** into the linked list of segments.
** \param firmwareFile Filename of the firmware file to load. ** \param firmwareFile Filename of the firmware file to load.
** \param addressOffset Optional memory address offset to add when loading the
** firmware data from the file.
** \return True if successful, false otherwise. ** \return True if successful, false otherwise.
** **
****************************************************************************************/ ****************************************************************************************/
bool FirmwareLoadFromFile(char const * firmwareFile) bool FirmwareLoadFromFile(char const * firmwareFile, uint32_t addressOffset)
{ {
bool result = false; bool result = false;
@ -113,7 +115,7 @@ bool FirmwareLoadFromFile(char const * firmwareFile)
if (parserPtr->LoadFromFile != NULL) if (parserPtr->LoadFromFile != NULL)
{ {
/* Request the parser to perform the load operation. */ /* Request the parser to perform the load operation. */
result = parserPtr->LoadFromFile(firmwareFile); result = parserPtr->LoadFromFile(firmwareFile, addressOffset);
} }
} }
} }

View File

@ -68,7 +68,7 @@ typedef struct t_firmware_parser
/** \brief Extract the firmware segments from the firmware file and add them as nodes /** \brief Extract the firmware segments from the firmware file and add them as nodes
* to the linked list. * to the linked list.
*/ */
bool (* LoadFromFile) (char const * firmwareFile); bool (* LoadFromFile) (char const * firmwareFile, uint32_t addressOffset);
/** \brief Write all the firmware segments from the linked list to the specified /** \brief Write all the firmware segments from the linked list to the specified
* firmware file. * firmware file.
*/ */
@ -81,7 +81,7 @@ typedef struct t_firmware_parser
****************************************************************************************/ ****************************************************************************************/
void FirmwareInit(tFirmwareParser const * parser); void FirmwareInit(tFirmwareParser const * parser);
void FirmwareTerminate(void); void FirmwareTerminate(void);
bool FirmwareLoadFromFile(char const * firmwareFile); bool FirmwareLoadFromFile(char const * firmwareFile, uint32_t addressOffset);
bool FirmwareSaveToFile(char const * firmwareFile); bool FirmwareSaveToFile(char const * firmwareFile);
uint32_t FirmwareGetSegmentCount(void); uint32_t FirmwareGetSegmentCount(void);
tFirmwareSegment * FirmwareGetSegment(uint32_t segmentIdx); tFirmwareSegment * FirmwareGetSegment(uint32_t segmentIdx);

View File

@ -357,10 +357,14 @@ LIBOPENBLT_EXPORT void BltFirmwareTerminate(void)
** \brief Loads firmware data from the specified file using the firmware file parser ** \brief Loads firmware data from the specified file using the firmware file parser
** that was specified during the initialization of this module. ** that was specified during the initialization of this module.
** \param firmwareFile Filename of the firmware file to load. ** \param firmwareFile Filename of the firmware file to load.
** \param addressOffset Optional memory address offset to add when loading the
** firmware data from the file. This is typically only useful when loading
** firmware data from a binary formatted firmware file.
** \return BLT_RESULT_OK if successful, BLT_RESULT_ERROR_xxx otherwise. ** \return BLT_RESULT_OK if successful, BLT_RESULT_ERROR_xxx otherwise.
** **
****************************************************************************************/ ****************************************************************************************/
LIBOPENBLT_EXPORT uint32_t BltFirmwareLoadFromFile(char const * firmwareFile) LIBOPENBLT_EXPORT uint32_t BltFirmwareLoadFromFile(char const * firmwareFile,
uint32_t addressOffset)
{ {
uint32_t result = BLT_RESULT_ERROR_GENERIC; uint32_t result = BLT_RESULT_ERROR_GENERIC;
@ -371,7 +375,7 @@ LIBOPENBLT_EXPORT uint32_t BltFirmwareLoadFromFile(char const * firmwareFile)
if (firmwareFile != NULL) /*lint !e774 */ if (firmwareFile != NULL) /*lint !e774 */
{ {
/* Pass the request on to the firmware data module. */ /* Pass the request on to the firmware data module. */
if (FirmwareLoadFromFile(firmwareFile)) if (FirmwareLoadFromFile(firmwareFile, addressOffset))
{ {
result = BLT_RESULT_OK; result = BLT_RESULT_OK;
} }

View File

@ -191,7 +191,8 @@ LIBOPENBLT_EXPORT uint32_t BltSessionReadData(uint32_t address, uint32_t len,
****************************************************************************************/ ****************************************************************************************/
LIBOPENBLT_EXPORT void BltFirmwareInit(uint32_t parserType); LIBOPENBLT_EXPORT void BltFirmwareInit(uint32_t parserType);
LIBOPENBLT_EXPORT void BltFirmwareTerminate(void); LIBOPENBLT_EXPORT void BltFirmwareTerminate(void);
LIBOPENBLT_EXPORT uint32_t BltFirmwareLoadFromFile(char const * firmwareFile); LIBOPENBLT_EXPORT uint32_t BltFirmwareLoadFromFile(char const * firmwareFile,
uint32_t addressOffset);
LIBOPENBLT_EXPORT uint32_t BltFirmwareSaveToFile(char const * firmwareFile); LIBOPENBLT_EXPORT uint32_t BltFirmwareSaveToFile(char const * firmwareFile);
LIBOPENBLT_EXPORT uint32_t BltFirmwareGetSegmentCount(void); LIBOPENBLT_EXPORT uint32_t BltFirmwareGetSegmentCount(void);
LIBOPENBLT_EXPORT uint8_t * BltFirmwareGetSegment(uint32_t idx, uint32_t * address, LIBOPENBLT_EXPORT uint8_t * BltFirmwareGetSegment(uint32_t idx, uint32_t * address,

View File

@ -134,9 +134,9 @@ const
procedure BltFirmwareInit(parserType: LongWord); cdecl; external LIBOPENBLT_LIBNAME; procedure BltFirmwareInit(parserType: LongWord); cdecl; external LIBOPENBLT_LIBNAME;
procedure BltFirmwareTerminate; cdecl; external LIBOPENBLT_LIBNAME; procedure BltFirmwareTerminate; cdecl; external LIBOPENBLT_LIBNAME;
function BltFirmwareLoadFromFile(firmwareFile: PAnsiChar): LongWord; function BltFirmwareLoadFromFile(firmwareFile: PAnsiChar; addressOffsets: LongWord):
cdecl; external LIBOPENBLT_LIBNAME; LongWord; cdecl; external LIBOPENBLT_LIBNAME;
function BltFirmwareSaveToFile(firmwareFile: PAnsiChar): LongWord; function BltFirmwareSaveToFile(firmwareFile: PAnsiChar): LongWord;
cdecl; external LIBOPENBLT_LIBNAME; cdecl; external LIBOPENBLT_LIBNAME;
function BltFirmwareGetSegmentCount: LongWord; cdecl; external LIBOPENBLT_LIBNAME; function BltFirmwareGetSegmentCount: LongWord; cdecl; external LIBOPENBLT_LIBNAME;
function BltFirmwareGetSegment(idx: LongWord; function BltFirmwareGetSegment(idx: LongWord;

View File

@ -61,7 +61,7 @@ typedef enum t_srec_parser_line_type
/**************************************************************************************** /****************************************************************************************
* Function prototypes * Function prototypes
****************************************************************************************/ ****************************************************************************************/
static bool SRecParserLoadFromFile (char const * firmwareFile); static bool SRecParserLoadFromFile (char const * firmwareFile, uint32_t addressOffset);
static bool SRecParserSaveToFile (char const * firmwareFile); static bool SRecParserSaveToFile (char const * firmwareFile);
static bool SRecParserExtractLineData(char const * line, uint32_t * address, static bool SRecParserExtractLineData(char const * line, uint32_t * address,
uint32_t * len, uint8_t * data); uint32_t * len, uint8_t * data);
@ -101,10 +101,12 @@ tFirmwareParser const * SRecParserGetParser(void)
** data to the firmware data that is currently managed by the firmware data ** data to the firmware data that is currently managed by the firmware data
** module. ** module.
** \param firmwareFile Filename of the firmware file to load. ** \param firmwareFile Filename of the firmware file to load.
** \param addressOffset Optional memory address offset to add when loading the
** firmware data from the file.
** \return True if successful, false otherwise. ** \return True if successful, false otherwise.
** **
****************************************************************************************/ ****************************************************************************************/
static bool SRecParserLoadFromFile (char const * firmwareFile) static bool SRecParserLoadFromFile (char const * firmwareFile, uint32_t addressOffset)
{ {
bool result = false; bool result = false;
FILE *fp; FILE *fp;
@ -151,8 +153,10 @@ static bool SRecParserLoadFromFile (char const * firmwareFile)
/* Only add data if there is actually something to add. */ /* Only add data if there is actually something to add. */
if (len > 0) if (len > 0)
{ {
/* Add the extracted data to the firmware data module. */ /* Add the extracted data to the firmware data module and add the memory
if (!FirmwareAddData(address, len, data)) * address that was specified by the caller.
*/
if (!FirmwareAddData(address + addressOffset, len, data))
{ {
/* Error detected. Flag it and abort. */ /* Error detected. Flag it and abort. */
result = false; result = false;