libs/libc/hex2bin: enhance 64-bit compatibility

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an 2023-08-11 16:22:36 +08:00 committed by Xiang Xiao
parent 52c0e6b576
commit 60c4d61c02
4 changed files with 20 additions and 20 deletions

View File

@ -100,8 +100,8 @@ extern "C"
struct lib_instream_s;
struct lib_sostream_s;
int hex2bin(FAR struct lib_instream_s *instream,
FAR struct lib_sostream_s *outstream, uint32_t baseaddr,
uint32_t endpaddr, enum hex2bin_swap_e swap);
FAR struct lib_sostream_s *outstream, unsigned long baseaddr,
unsigned long endpaddr, enum hex2bin_swap_e swap);
/****************************************************************************
* Name: hex2mem
@ -127,7 +127,7 @@ int hex2bin(FAR struct lib_instream_s *instream,
*
****************************************************************************/
int hex2mem(int fd, uint32_t baseaddr, uint32_t endpaddr,
int hex2mem(int fd, unsigned long baseaddr, unsigned long endpaddr,
enum hex2bin_swap_e swap);
/****************************************************************************
@ -154,8 +154,8 @@ int hex2mem(int fd, uint32_t baseaddr, uint32_t endpaddr,
*
****************************************************************************/
int fhex2mem(FAR FILE *instream, uint32_t baseaddr, uint32_t endpaddr,
enum hex2bin_swap_e swap);
int fhex2mem(FAR FILE *instream, unsigned long baseaddr,
unsigned long endpaddr, enum hex2bin_swap_e swap);
#undef EXTERN
#ifdef __cplusplus

View File

@ -60,8 +60,8 @@
*
****************************************************************************/
int fhex2mem(FAR FILE *instream, uint32_t baseaddr, uint32_t endpaddr,
enum hex2bin_swap_e swap)
int fhex2mem(FAR FILE *instream, unsigned long baseaddr,
unsigned long endpaddr, enum hex2bin_swap_e swap)
{
struct lib_stdinstream_s stdinstream;
struct lib_memsostream_s memoutstream;
@ -81,7 +81,7 @@ int fhex2mem(FAR FILE *instream, uint32_t baseaddr, uint32_t endpaddr,
/* And do the deed */
return hex2bin(&stdinstream.public, &memoutstream.public,
(uint32_t)baseaddr, (uint32_t)endpaddr,
(unsigned long)baseaddr, (unsigned long)endpaddr,
(enum hex2bin_swap_e)swap);
}

View File

@ -378,18 +378,18 @@ static inline void writedata(FAR struct lib_sostream_s *outstream,
****************************************************************************/
int hex2bin(FAR struct lib_instream_s *instream,
FAR struct lib_sostream_s *outstream, uint32_t baseaddr,
uint32_t endpaddr, enum hex2bin_swap_e swap)
FAR struct lib_sostream_s *outstream, unsigned long baseaddr,
unsigned long endpaddr, enum hex2bin_swap_e swap)
{
FAR uint8_t *alloc;
FAR uint8_t *line;
FAR uint8_t *bin;
int nbytes;
int bytecount;
uint32_t address;
uint32_t endaddr;
uint32_t expected;
uint32_t extension;
unsigned long address;
unsigned long endaddr;
unsigned long expected;
unsigned long extension;
uint16_t address16;
uint8_t checksum;
unsigned int lineno;
@ -546,7 +546,7 @@ int hex2bin(FAR struct lib_instream_s *instream,
/* Get and verify the full 32-bit address */
address = extension + (uint32_t)address16;
address = extension + (unsigned long)address16;
endaddr = address + bytecount;
if (address < baseaddr || (endpaddr != 0 && endaddr >= endpaddr))
@ -621,7 +621,7 @@ int hex2bin(FAR struct lib_instream_s *instream,
goto errout_with_einval;
}
extension = (uint32_t)bin[DATA_BINNDX] << 12;
extension = (unsigned long)bin[DATA_BINNDX] << 12;
break;
case RECORD_START_SEGADDR: /* Start segment address record */
@ -654,8 +654,8 @@ int hex2bin(FAR struct lib_instream_s *instream,
goto errout_with_einval;
}
extension = (uint32_t)bin[DATA_BINNDX] << 24 |
(uint32_t)bin[DATA_BINNDX + 1] << 16;
extension = (unsigned long)bin[DATA_BINNDX] << 24 |
(unsigned long)bin[DATA_BINNDX + 1] << 16;
break;
case RECORD_START_LINADDR: /* Start linear address record */

View File

@ -60,7 +60,7 @@
*
****************************************************************************/
int hex2mem(int fd, uint32_t baseaddr, uint32_t endpaddr,
int hex2mem(int fd, unsigned long baseaddr, unsigned long endpaddr,
enum hex2bin_swap_e swap)
{
struct lib_rawinstream_s rawinstream;
@ -81,7 +81,7 @@ int hex2mem(int fd, uint32_t baseaddr, uint32_t endpaddr,
/* And do the deed */
return hex2bin(&rawinstream.public, &memoutstream.public,
(uint32_t)baseaddr, (uint32_t)endpaddr,
(unsigned long)baseaddr, (unsigned long)endpaddr,
(enum hex2bin_swap_e)swap);
}