While at it, fix some coding style issues.
Change-Id: Id521394d89e0bf787a6f812701c2cc0fe7e4e63f
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5919
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
{
int retval = ERROR_OK;
- int section;
+ unsigned int section;
uint32_t section_offset;
struct flash_bank *c;
int *padding;
* whereas an image can have sections out of order. */
struct imagesection **sections = malloc(sizeof(struct imagesection *) *
image->num_sections);
- int i;
- for (i = 0; i < image->num_sections; i++)
+
+ for (unsigned int i = 0; i < image->num_sections; i++)
sections[i] = &image->sections[i];
qsort(sections, image->num_sections, sizeof(struct imagesection *),
while (section < image->num_sections) {
uint32_t buffer_idx;
uint8_t *buffer;
- int section_last;
+ unsigned int section_last;
target_addr_t run_address = sections[section]->base_address + section_offset;
uint32_t run_size = sections[section]->size - section_offset;
int pad_bytes = 0;
/* The image will always start at offset 0 */
struct image image;
- image.base_address_set = 1;
+ image.base_address_set = true;
image.base_address = 0;
- image.start_address_set = 0;
+ image.start_address_set = false;
const char *filename = CMD_ARGV[1];
const char *type = (CMD_ARGC >= 3) ? CMD_ARGV[2] : NULL;
duration_start(&bench);
if (CMD_ARGC >= 2) {
- image.base_address_set = 1;
+ image.base_address_set = true;
COMMAND_PARSE_NUMBER(llong, CMD_ARGV[1], image.base_address);
} else {
- image.base_address_set = 0;
+ image.base_address_set = false;
image.base_address = 0x0;
}
- image.start_address_set = 0;
+ image.start_address_set = false;
retval = image_open(&image, CMD_ARGV[0], (CMD_ARGC == 3) ? CMD_ARGV[2] : NULL);
if (retval != ERROR_OK)
static int ulink_load_firmware(struct ulink *device, const char *filename)
{
struct image ulink_firmware_image;
- int ret, i;
+ int ret;
ret = ulink_cpu_reset(device, CPU_RESET);
if (ret != ERROR_OK) {
}
ulink_firmware_image.base_address = 0;
- ulink_firmware_image.base_address_set = 0;
+ ulink_firmware_image.base_address_set = false;
ret = image_open(&ulink_firmware_image, filename, "ihex");
if (ret != ERROR_OK) {
}
/* Download all sections in the image to ULINK */
- for (i = 0; i < ulink_firmware_image.num_sections; i++) {
+ for (unsigned int i = 0; i < ulink_firmware_image.num_sections; i++) {
ret = ulink_write_firmware_section(device, &ulink_firmware_image, i);
if (ret != ERROR_OK)
return ret;
}
ublast2_firmware_image.base_address = 0;
- ublast2_firmware_image.base_address_set = 0;
+ ublast2_firmware_image.base_address_set = false;
int ret = image_open(&ublast2_firmware_image, low->firmware_path, "ihex");
if (ret != ERROR_OK) {
100);
/* Download all sections in the image to ULINK */
- for (int i = 0; i < ublast2_firmware_image.num_sections; i++) {
+ for (unsigned int i = 0; i < ublast2_firmware_image.num_sections; i++) {
ret = ublast2_write_firmware_section(libusb_dev,
&ublast2_firmware_image, i);
if (ret != ERROR_OK) {
static int etm_read_instruction(struct etm_context *ctx, struct arm_instruction *instruction)
{
- int i;
int section = -1;
size_t size_read;
uint32_t opcode;
return ERROR_TRACE_IMAGE_UNAVAILABLE;
/* search for the section the current instruction belongs to */
- for (i = 0; i < ctx->image->num_sections; i++) {
+ for (unsigned int i = 0; i < ctx->image->num_sections; i++) {
if ((ctx->image->sections[i].base_address <= ctx->current_pc) &&
(ctx->image->sections[i].base_address + ctx->image->sections[i].size >
ctx->current_pc)) {
}
etm_ctx->image = malloc(sizeof(struct image));
- etm_ctx->image->base_address_set = 0;
- etm_ctx->image->start_address_set = 0;
+ etm_ctx->image->base_address_set = false;
+ etm_ctx->image->start_address_set = false;
/* a base address isn't always necessary, default to 0x0 (i.e. don't relocate) */
if (CMD_ARGC >= 2) {
- etm_ctx->image->base_address_set = 1;
+ etm_ctx->image->base_address_set = true;
COMMAND_PARSE_NUMBER(llong, CMD_ARGV[1], etm_ctx->image->base_address);
} else
- etm_ctx->image->base_address_set = 0;
+ etm_ctx->image->base_address_set = false;
if (image_open(etm_ctx->image, CMD_ARGV[0],
(CMD_ARGC >= 3) ? CMD_ARGV[2] : NULL) != ERROR_OK) {
uint32_t full_address;
uint32_t cooked_bytes;
bool end_rec = false;
- int i;
/* we can't determine the number of sections that we'll have to create ahead of time,
* so we locally hold them until parsing is finished */
/* copy section information */
image->sections = malloc(sizeof(struct imagesection) * image->num_sections);
- for (i = 0; i < image->num_sections; i++) {
+ for (unsigned int i = 0; i < image->num_sections; i++) {
image->sections[i].private = section[i].private;
image->sections[i].base_address = section[i].base_address;
image->sections[i].size = section[i].size;
cal_checksum += (uint8_t)start_address;
bytes_read += 8;
- image->start_address_set = 1;
+ image->start_address_set = true;
image->start_address = be_to_h_u32((uint8_t *)&start_address);
} else {
LOG_ERROR("unhandled IHEX record type: %i", (int)record_type);
}
}
- image->start_address_set = 1;
+ image->start_address_set = true;
image->start_address = field32(elf, elf->header->e_entry);
return ERROR_OK;
uint32_t full_address;
uint32_t cooked_bytes;
bool end_rec = false;
- int i;
/* we can't determine the number of sections that we'll have to create ahead of time,
* so we locally hold them until parsing is finished */
/* copy section information */
image->sections = malloc(sizeof(struct imagesection) * image->num_sections);
- for (i = 0; i < image->num_sections; i++) {
+ for (unsigned int i = 0; i < image->num_sections; i++) {
image->sections[i].private = section[i].private;
image->sections[i].base_address = section[i].base_address;
image->sections[i].size = section[i].size;
}
} else if (image->type == IMAGE_BUILDER) {
image->num_sections = 0;
- image->base_address_set = 0;
+ image->base_address_set = false;
image->sections = NULL;
image->type_private = NULL;
}
if (image->base_address_set) {
/* relocate */
- int section;
- for (section = 0; section < image->num_sections; section++)
+ for (unsigned int section = 0; section < image->num_sections; section++)
image->sections[section].base_address += image->base_address;
/* we're done relocating. The two statements below are mainly
* for documentation purposes: stop anyone from empirically
* thinking they should use these values henceforth. */
image->base_address = 0;
- image->base_address_set = 0;
+ image->base_address_set = false;
}
return retval;
free(image_mot->buffer);
image_mot->buffer = NULL;
} else if (image->type == IMAGE_BUILDER) {
- int i;
-
- for (i = 0; i < image->num_sections; i++) {
+ for (unsigned int i = 0; i < image->num_sections; i++) {
free(image->sections[i].private);
image->sections[i].private = NULL;
}
struct image {
enum image_type type; /* image type (plain, ihex, ...) */
void *type_private; /* type private data */
- int num_sections; /* number of sections contained in the image */
+ unsigned int num_sections; /* number of sections contained in the image */
struct imagesection *sections; /* array of sections */
- int base_address_set; /* whether the image has a base address set (for relocation purposes) */
+ bool base_address_set; /* whether the image has a base address set (for relocation purposes) */
long long base_address; /* base address, if one is set */
- int start_address_set; /* whether the image has a start address (entry point) associated */
+ bool start_address_set; /* whether the image has a start address (entry point) associated */
uint32_t start_address; /* start address, if one is set */
};
target_addr_t addr;
COMMAND_PARSE_ADDRESS(CMD_ARGV[1], addr);
image->base_address = addr;
- image->base_address_set = 1;
+ image->base_address_set = true;
} else
- image->base_address_set = 0;
+ image->base_address_set = false;
- image->start_address_set = 0;
+ image->start_address_set = false;
if (CMD_ARGC >= 4)
COMMAND_PARSE_ADDRESS(CMD_ARGV[3], *min_address);
uint32_t image_size;
target_addr_t min_address = 0;
target_addr_t max_address = -1;
- int i;
struct image image;
int retval = CALL_COMMAND_HANDLER(parse_load_image_command_CMD_ARGV,
image_size = 0x0;
retval = ERROR_OK;
- for (i = 0; i < image.num_sections; i++) {
+ for (unsigned int i = 0; i < image.num_sections; i++) {
buffer = malloc(image.sections[i].size);
if (buffer == NULL) {
command_print(CMD,
uint8_t *buffer;
size_t buf_cnt;
uint32_t image_size;
- int i;
int retval;
uint32_t checksum = 0;
uint32_t mem_checksum = 0;
target_addr_t addr;
COMMAND_PARSE_ADDRESS(CMD_ARGV[1], addr);
image.base_address = addr;
- image.base_address_set = 1;
+ image.base_address_set = true;
} else {
- image.base_address_set = 0;
+ image.base_address_set = false;
image.base_address = 0x0;
}
- image.start_address_set = 0;
+ image.start_address_set = false;
retval = image_open(&image, CMD_ARGV[0], (CMD_ARGC == 3) ? CMD_ARGV[2] : NULL);
if (retval != ERROR_OK)
image_size = 0x0;
int diffs = 0;
retval = ERROR_OK;
- for (i = 0; i < image.num_sections; i++) {
+ for (unsigned int i = 0; i < image.num_sections; i++) {
buffer = malloc(image.sections[i].size);
if (buffer == NULL) {
command_print(CMD,
- "error allocating buffer for section (%d bytes)",
- (int)(image.sections[i].size));
+ "error allocating buffer for section (%" PRIu32 " bytes)",
+ image.sections[i].size);
break;
}
retval = image_read_section(&image, i, 0x0, image.sections[i].size, buffer, &buf_cnt);
uint32_t image_size;
target_addr_t min_address = 0;
target_addr_t max_address = -1;
- int i;
struct image image;
return ERROR_FAIL;
}
memset(fastload, 0, sizeof(struct FastLoad)*image.num_sections);
- for (i = 0; i < image.num_sections; i++) {
+ for (unsigned int i = 0; i < image.num_sections; i++) {
buffer = malloc(image.sections[i].size);
if (buffer == NULL) {
command_print(CMD, "error allocating buffer for section (%d bytes)",
struct arm_instruction *instruction)
{
struct xscale_common *const xscale = target_to_xscale(target);
- int i;
int section = -1;
size_t size_read;
uint32_t opcode;
return ERROR_TRACE_IMAGE_UNAVAILABLE;
/* search for the section the current instruction belongs to */
- for (i = 0; i < xscale->trace.image->num_sections; i++) {
+ for (unsigned int i = 0; i < xscale->trace.image->num_sections; i++) {
if ((xscale->trace.image->sections[i].base_address <= pc) &&
(xscale->trace.image->sections[i].base_address +
xscale->trace.image->sections[i].size > pc)) {
}
xscale->trace.image = malloc(sizeof(struct image));
- xscale->trace.image->base_address_set = 0;
- xscale->trace.image->start_address_set = 0;
+ xscale->trace.image->base_address_set = false;
+ xscale->trace.image->start_address_set = false;
/* a base address isn't always necessary, default to 0x0 (i.e. don't relocate) */
if (CMD_ARGC >= 2) {
- xscale->trace.image->base_address_set = 1;
+ xscale->trace.image->base_address_set = true;
COMMAND_PARSE_NUMBER(llong, CMD_ARGV[1], xscale->trace.image->base_address);
} else
- xscale->trace.image->base_address_set = 0;
+ xscale->trace.image->base_address_set = false;
if (image_open(xscale->trace.image, CMD_ARGV[0],
(CMD_ARGC >= 3) ? CMD_ARGV[2] : NULL) != ERROR_OK) {