/* convert ELF header field to host endianness */
#define field16(elf,field)\
((elf->endianness==ELFDATA2LSB)? \
/* convert ELF header field to host endianness */
#define field16(elf,field)\
((elf->endianness==ELFDATA2LSB)? \
#define field32(elf,field)\
((elf->endianness==ELFDATA2LSB)? \
#define field32(elf,field)\
((elf->endianness==ELFDATA2LSB)? \
/* read the first 4 bytes of image */
if ((retval = fileio_open(&fileio, url, FILEIO_READ, FILEIO_BINARY)) != ERROR_OK)
/* read the first 4 bytes of image */
if ((retval = fileio_open(&fileio, url, FILEIO_READ, FILEIO_BINARY)) != ERROR_OK)
- else if ((buffer[0]==':') /* record start byte */
- &&(isxdigit(buffer[1]))
- &&(isxdigit(buffer[2]))
- &&(isxdigit(buffer[3]))
- &&(isxdigit(buffer[4]))
- &&(isxdigit(buffer[5]))
- &&(isxdigit(buffer[6]))
- &&(buffer[7]=='0') /* record type : 00 -> 05 */
- &&(buffer[8]>='0')&&(buffer[8]<'6'))
+ else if ((buffer[0]==':') /* record start byte */
+ &&(isxdigit(buffer[1]))
+ &&(isxdigit(buffer[2]))
+ &&(isxdigit(buffer[3]))
+ &&(isxdigit(buffer[4]))
+ &&(isxdigit(buffer[5]))
+ &&(isxdigit(buffer[6]))
+ &&(buffer[7]=='0') /* record type : 00 -> 05 */
+ &&(buffer[8]>='0')&&(buffer[8]<'6'))
u32 bytes_read = 0;
if (sscanf(&lpszLine[bytes_read], ":%2x%4x%2x", &count, &address, &record_type) != 3)
u32 bytes_read = 0;
if (sscanf(&lpszLine[bytes_read], ":%2x%4x%2x", &count, &address, &record_type) != 3)
- cal_checksum += (u8)count;
- cal_checksum += (u8)(address >> 8);
- cal_checksum += (u8)address;
- cal_checksum += (u8)record_type;
+ cal_checksum += (uint8_t)count;
+ cal_checksum += (uint8_t)(address >> 8);
+ cal_checksum += (uint8_t)address;
+ cal_checksum += (uint8_t)record_type;
- sscanf(&lpszLine[bytes_read], "%2x", (u32*)&ihex->buffer[cooked_bytes]);
- cal_checksum += (u8)ihex->buffer[cooked_bytes];
+ unsigned value;
+ sscanf(&lpszLine[bytes_read], "%2x", &value);
+ ihex->buffer[cooked_bytes] = (uint8_t)value;
+ cal_checksum += (uint8_t)ihex->buffer[cooked_bytes];
- cal_checksum += (u8)(start_address >> 24);
- cal_checksum += (u8)(start_address >> 16);
- cal_checksum += (u8)(start_address >> 8);
- cal_checksum += (u8)start_address;
+ cal_checksum += (uint8_t)(start_address >> 24);
+ cal_checksum += (uint8_t)(start_address >> 16);
+ cal_checksum += (uint8_t)(start_address >> 8);
+ cal_checksum += (uint8_t)start_address;
- if ((retval = fileio_read(&elf->fileio, sizeof(Elf32_Ehdr), (u8*)elf->header, &read_bytes)) != ERROR_OK)
+ if ((retval = fileio_read(&elf->fileio, sizeof(Elf32_Ehdr), (uint8_t*)elf->header, &read_bytes)) != ERROR_OK)
{
LOG_ERROR("cannot read ELF file header, read failed");
return ERROR_FILEIO_OPERATION_FAILED;
{
LOG_ERROR("cannot read ELF file header, read failed");
return ERROR_FILEIO_OPERATION_FAILED;
elf->endianness = elf->header->e_ident[EI_DATA];
if ((elf->endianness!=ELFDATA2LSB)
&&(elf->endianness!=ELFDATA2MSB))
elf->endianness = elf->header->e_ident[EI_DATA];
if ((elf->endianness!=ELFDATA2LSB)
&&(elf->endianness!=ELFDATA2MSB))
- if ((retval = fileio_read(&elf->fileio, elf->segment_count*sizeof(Elf32_Phdr), (u8*)elf->segments, &read_bytes)) != ERROR_OK)
+ if ((retval = fileio_read(&elf->fileio, elf->segment_count*sizeof(Elf32_Phdr), (uint8_t*)elf->segments, &read_bytes)) != ERROR_OK)
-int image_elf_read_section(image_t *image, int section, u32 offset, u32 size, u8 *buffer, u32 *size_read)
+static int image_elf_read_section(image_t *image, int section, u32 offset, u32 size, uint8_t *buffer, u32 *size_read)
{
image_elf_t *elf = image->type_private;
Elf32_Phdr *segment = (Elf32_Phdr *)image->sections[section].private;
{
image_elf_t *elf = image->type_private;
Elf32_Phdr *segment = (Elf32_Phdr *)image->sections[section].private;
case 1:
/* S1 - 16 bit address data record */
sscanf(&lpszLine[bytes_read], "%4x", &address);
case 1:
/* S1 - 16 bit address data record */
sscanf(&lpszLine[bytes_read], "%4x", &address);
case 2:
/* S2 - 24 bit address data record */
sscanf(&lpszLine[bytes_read], "%6x", &address);
case 2:
/* S2 - 24 bit address data record */
sscanf(&lpszLine[bytes_read], "%6x", &address);
- cal_checksum += (u8)(address >> 16);
- cal_checksum += (u8)(address >> 8);
- cal_checksum += (u8)address;
+ cal_checksum += (uint8_t)(address >> 16);
+ cal_checksum += (uint8_t)(address >> 8);
+ cal_checksum += (uint8_t)address;
case 3:
/* S3 - 32 bit address data record */
sscanf(&lpszLine[bytes_read], "%8x", &address);
case 3:
/* S3 - 32 bit address data record */
sscanf(&lpszLine[bytes_read], "%8x", &address);
- cal_checksum += (u8)(address >> 24);
- cal_checksum += (u8)(address >> 16);
- cal_checksum += (u8)(address >> 8);
- cal_checksum += (u8)address;
+ cal_checksum += (uint8_t)(address >> 24);
+ cal_checksum += (uint8_t)(address >> 16);
+ cal_checksum += (uint8_t)(address >> 8);
+ cal_checksum += (uint8_t)address;
- sscanf(&lpszLine[bytes_read], "%2x", (u32*)&mot->buffer[cooked_bytes]);
- cal_checksum += (u8)mot->buffer[cooked_bytes];
+ unsigned value;
+ sscanf(&lpszLine[bytes_read], "%2x", &value);
+ mot->buffer[cooked_bytes] = (uint8_t)value;
+ cal_checksum += (uint8_t)mot->buffer[cooked_bytes];
/* account for checksum, will always be 0xFF */
sscanf(&lpszLine[bytes_read], "%2x", &checksum);
/* account for checksum, will always be 0xFF */
sscanf(&lpszLine[bytes_read], "%2x", &checksum);
-int image_read_section(image_t *image, int section, u32 offset, u32 size, u8 *buffer, u32 *size_read)
+int image_read_section(image_t *image, int section, u32 offset, u32 size, uint8_t *buffer, u32 *size_read)
-int image_add_section(image_t *image, u32 base, u32 size, int flags, u8 *data)
+int image_add_section(image_t *image, u32 base, u32 size, int flags, uint8_t *data)
if (((section->base_address + section->size) == base) && (section->flags == flags))
{
section->private = realloc(section->private, section->size + size);
if (((section->base_address + section->size) == base) && (section->flags == flags))
{
section->private = realloc(section->private, section->size + size);
- section->private = malloc(sizeof(u8) * size);
- memcpy((u8*)section->private, data, size);
+ section->private = malloc(sizeof(uint8_t) * size);
+ memcpy((uint8_t*)section->private, data, size);