OpenOCD
image.c File Reference
Include dependency graph for image.c:

Go to the source code of this file.

Macros

#define field16(elf, field)
 
#define field32(elf, field)
 
#define field64(elf, field)
 

Functions

static int autodetect_image_type (struct image *image, const char *url)
 
static int identify_image_type (struct image *image, const char *type_string, const char *url)
 
int image_add_section (struct image *image, target_addr_t base, uint32_t size, uint64_t flags, uint8_t const *data)
 
int image_calculate_checksum (const uint8_t *buffer, uint32_t nbytes, uint32_t *checksum)
 
void image_close (struct image *image)
 
static int image_elf32_read_headers (struct image *image)
 
static int image_elf32_read_section (struct image *image, int section, target_addr_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
 
static int image_elf64_read_headers (struct image *image)
 
static int image_elf64_read_section (struct image *image, int section, target_addr_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
 
static int image_elf_read_headers (struct image *image)
 
static int image_elf_read_section (struct image *image, int section, target_addr_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
 
static int image_ihex_buffer_complete (struct image *image)
 Allocate memory dynamically instead of on the stack. More...
 
static int image_ihex_buffer_complete_inner (struct image *image, char *lpsz_line, struct imagesection *section)
 
static int image_mot_buffer_complete (struct image *image)
 Allocate memory dynamically instead of on the stack. More...
 
static int image_mot_buffer_complete_inner (struct image *image, char *lpsz_line, struct imagesection *section)
 
int image_open (struct image *image, const char *url, const char *type_string)
 
int image_read_section (struct image *image, int section, target_addr_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
 

Macro Definition Documentation

◆ field16

#define field16 (   elf,
  field 
)
Value:
((elf->endianness == ELFDATA2LSB) ? \
le_to_h_u16((uint8_t *)&field) : be_to_h_u16((uint8_t *)&field))
#define ELFDATA2LSB
Definition: replacements.h:263
static uint16_t le_to_h_u16(const uint8_t *buf)
Definition: types.h:122
static uint16_t be_to_h_u16(const uint8_t *buf)
Definition: types.h:149

Definition at line 30 of file image.c.

◆ field32

#define field32 (   elf,
  field 
)
Value:
((elf->endianness == ELFDATA2LSB) ? \
le_to_h_u32((uint8_t *)&field) : be_to_h_u32((uint8_t *)&field))
static uint32_t be_to_h_u32(const uint8_t *buf)
Definition: types.h:139
static uint32_t le_to_h_u32(const uint8_t *buf)
Definition: types.h:112

Definition at line 34 of file image.c.

◆ field64

#define field64 (   elf,
  field 
)
Value:
((elf->endianness == ELFDATA2LSB) ? \
le_to_h_u64((uint8_t *)&field) : be_to_h_u64((uint8_t *)&field))
static uint64_t le_to_h_u64(const uint8_t *buf)
Definition: types.h:100
static uint64_t be_to_h_u64(const uint8_t *buf)
Definition: types.h:127

Definition at line 38 of file image.c.

Function Documentation

◆ autodetect_image_type()

static int autodetect_image_type ( struct image image,
const char *  url 
)
static

◆ identify_image_type()

static int identify_image_type ( struct image image,
const char *  type_string,
const char *  url 
)
static

◆ image_add_section()

int image_add_section ( struct image image,
target_addr_t  base,
uint32_t  size,
uint64_t  flags,
uint8_t const *  data 
)

◆ image_calculate_checksum()

int image_calculate_checksum ( const uint8_t *  buffer,
uint32_t  nbytes,
uint32_t *  checksum 
)

◆ image_close()

◆ image_elf32_read_headers()

static int image_elf32_read_headers ( struct image image)
static

some ELF linkers produce binaries with all the program header p_paddr fields zero (there can be however one loadable segment that has valid physical address 0x0). If we have such a binary with more than one PT_LOAD header, then use p_vaddr instead of p_paddr (ARM ELF standard demands p_paddr = 0 anyway, and BFD library uses this approach to workaround zero-initialized p_paddrs when obtaining lma - look at elf.c of BDF)

Definition at line 357 of file image.c.

References imagesection::base_address, Elf32_Ehdr::e_entry, Elf32_Ehdr::e_phnum, Elf32_Ehdr::e_phoff, ERROR_FILEIO_OPERATION_FAILED, ERROR_IMAGE_FORMAT_ERROR, ERROR_OK, field16, field32, image_elf::fileio, fileio_read(), fileio_seek(), imagesection::flags, image_elf::header32, LOG_ERROR, image::num_sections, Elf32_Phdr::p_filesz, Elf32_Phdr::p_flags, Elf32_Phdr::p_memsz, Elf32_Phdr::p_paddr, Elf32_Phdr::p_type, Elf32_Phdr::p_vaddr, imagesection::private, PT_LOAD, image::sections, image_elf::segment_count, image_elf::segments32, imagesection::size, image::start_address, image::start_address_set, and image::type_private.

Referenced by image_elf_read_headers().

◆ image_elf32_read_section()

static int image_elf32_read_section ( struct image image,
int  section,
target_addr_t  offset,
uint32_t  size,
uint8_t *  buffer,
size_t *  size_read 
)
static

◆ image_elf64_read_headers()

static int image_elf64_read_headers ( struct image image)
static

some ELF linkers produce binaries with all the program header p_paddr fields zero (there can be however one loadable segment that has valid physical address 0x0). If we have such a binary with more than one PT_LOAD header, then use p_vaddr instead of p_paddr (ARM ELF standard demands p_paddr = 0 anyway, and BFD library uses this approach to workaround zero-initialized p_paddrs when obtaining lma - look at elf.c of BDF)

Definition at line 482 of file image.c.

References imagesection::base_address, Elf64_Ehdr::e_entry, Elf64_Ehdr::e_phnum, Elf64_Ehdr::e_phoff, ERROR_FILEIO_OPERATION_FAILED, ERROR_IMAGE_FORMAT_ERROR, ERROR_OK, field16, field32, field64, image_elf::fileio, fileio_read(), fileio_seek(), imagesection::flags, image_elf::header64, LOG_ERROR, image::num_sections, Elf64_Phdr::p_filesz, Elf64_Phdr::p_flags, Elf64_Phdr::p_memsz, Elf64_Phdr::p_paddr, Elf64_Phdr::p_type, Elf64_Phdr::p_vaddr, imagesection::private, PT_LOAD, image::sections, image_elf::segment_count, image_elf::segments64, imagesection::size, image::start_address, image::start_address_set, and image::type_private.

Referenced by image_elf_read_headers().

◆ image_elf64_read_section()

static int image_elf64_read_section ( struct image image,
int  section,
target_addr_t  offset,
uint32_t  size,
uint8_t *  buffer,
size_t *  size_read 
)
static

◆ image_elf_read_headers()

◆ image_elf_read_section()

static int image_elf_read_section ( struct image image,
int  section,
target_addr_t  offset,
uint32_t  size,
uint8_t *  buffer,
size_t *  size_read 
)
static

◆ image_ihex_buffer_complete()

static int image_ihex_buffer_complete ( struct image image)
static

Allocate memory dynamically instead of on the stack.

This is important w/embedded hosts.

Definition at line 334 of file image.c.

References ERROR_FAIL, image_ihex_buffer_complete_inner(), IMAGE_MAX_SECTIONS, and LOG_ERROR.

Referenced by image_open().

◆ image_ihex_buffer_complete_inner()

◆ image_mot_buffer_complete()

static int image_mot_buffer_complete ( struct image image)
static

Allocate memory dynamically instead of on the stack.

This is important w/embedded hosts.

Definition at line 934 of file image.c.

References ERROR_FAIL, IMAGE_MAX_SECTIONS, image_mot_buffer_complete_inner(), and LOG_ERROR.

Referenced by image_open().

◆ image_mot_buffer_complete_inner()

◆ image_open()

◆ image_read_section()