target/image: Use proper data types 19/5919/3
authorMarc Schink <dev@zapb.de>
Tue, 3 Nov 2020 15:11:48 +0000 (16:11 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 7 Nov 2020 20:52:00 +0000 (20:52 +0000)
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>
src/flash/nor/core.c
src/flash/nor/lpc2900.c
src/flash/nor/tcl.c
src/jtag/drivers/ulink.c
src/jtag/drivers/usb_blaster/ublast2_access_libusb.c
src/target/etm.c
src/target/image.c
src/target/image.h
src/target/target.c
src/target/xscale.c

index d56301351bdaa5f0c67fd763689cecbfffb7d86d..6182a5f8207f73cd3e64754a761e846cc3a1579a 100644 (file)
@@ -702,7 +702,7 @@ int flash_write_unlock(struct target *target, struct image *image,
 {
        int retval = ERROR_OK;
 
-       int section;
+       unsigned int section;
        uint32_t section_offset;
        struct flash_bank *c;
        int *padding;
@@ -727,8 +727,8 @@ int flash_write_unlock(struct target *target, struct image *image,
         * 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 *),
@@ -738,7 +738,7 @@ int flash_write_unlock(struct target *target, struct image *image,
        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;
index c8e885aba15644af07799d27a6dbcebc000a7bbc..6596cde9414924875d598ab2c54a63aa7b08dc34 100644 (file)
@@ -635,9 +635,9 @@ COMMAND_HANDLER(lpc2900_handle_write_custom_command)
 
        /* 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;
index 386d73e395381bb8a837ff4e9bece5fbcc1ff255..87c8cede7a9f54ead1d81011934ab5cd0d705668 100644 (file)
@@ -441,14 +441,14 @@ COMMAND_HANDLER(handle_flash_write_image_command)
        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)
index 4bc6051718ff03be20ae711fd2424340b373841f..fd08c1661161185f830d3761e7c3d95a80f58578 100644 (file)
@@ -393,7 +393,7 @@ static int ulink_load_firmware_and_renumerate(struct ulink **device,
 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) {
@@ -402,7 +402,7 @@ static int ulink_load_firmware(struct ulink *device, const char *filename)
        }
 
        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) {
@@ -411,7 +411,7 @@ static int ulink_load_firmware(struct ulink *device, const char *filename)
        }
 
        /* 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;
index f8ff66e2fb300a898c5c71999a44beb95db50f66..6f15fa70a280115bdba86857924522859a257795 100644 (file)
@@ -134,7 +134,7 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev,
        }
 
        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) {
@@ -162,7 +162,7 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev,
                                     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) {
index 5d079ffa8285360f78ab990491db6de9f9cce1cc..93dbd29488fb5b38169ba35a5e26dd1f128723b0 100644 (file)
@@ -650,7 +650,6 @@ static struct etm_capture_driver *etm_capture_drivers[] = {
 
 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;
@@ -660,7 +659,7 @@ static int etm_read_instruction(struct etm_context *ctx, struct arm_instruction
                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)) {
@@ -1683,15 +1682,15 @@ COMMAND_HANDLER(handle_etm_image_command)
        }
 
        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) {
index 8160e5f92978bd963f16a089c5532dd1fdab2d9f..0b7debaeff2a2816e493be086980b202033c7161 100644 (file)
@@ -124,7 +124,6 @@ static int image_ihex_buffer_complete_inner(struct image *image,
        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 */
@@ -207,7 +206,7 @@ static int image_ihex_buffer_complete_inner(struct image *image,
 
                                /* 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;
@@ -294,7 +293,7 @@ static int image_ihex_buffer_complete_inner(struct image *image,
                                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);
@@ -471,7 +470,7 @@ static int image_elf_read_headers(struct image *image)
                }
        }
 
-       image->start_address_set = 1;
+       image->start_address_set = true;
        image->start_address = field32(elf, elf->header->e_entry);
 
        return ERROR_OK;
@@ -529,7 +528,6 @@ static int image_mot_buffer_complete_inner(struct image *image,
        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 */
@@ -658,7 +656,7 @@ static int image_mot_buffer_complete_inner(struct image *image,
 
                                /* 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;
@@ -821,21 +819,20 @@ int image_open(struct image *image, const char *url, const char *type_string)
                }
        } 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;
@@ -1009,9 +1006,7 @@ void image_close(struct image *image)
                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;
                }
index 9907a5f3fbca180b080d46eae257632b5d4f07a2..765d29022f0ea493e360d405e97da1957301cccb 100644 (file)
@@ -55,11 +55,11 @@ struct imagesection {
 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 */
 };
 
index da0c943bfbad9d5fc276a8d9113405e29aa87b22..39575b01c41cbb225dfdd3cdce28bde3f9a52c9b 100644 (file)
@@ -3404,11 +3404,11 @@ static COMMAND_HELPER(parse_load_image_command_CMD_ARGV, struct image *image,
                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);
@@ -3431,7 +3431,6 @@ COMMAND_HANDLER(handle_load_image_command)
        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,
@@ -3449,7 +3448,7 @@ COMMAND_HANDLER(handle_load_image_command)
 
        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,
@@ -3582,7 +3581,6 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver
        uint8_t *buffer;
        size_t buf_cnt;
        uint32_t image_size;
-       int i;
        int retval;
        uint32_t checksum = 0;
        uint32_t mem_checksum = 0;
@@ -3606,13 +3604,13 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver
                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)
@@ -3621,12 +3619,12 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver
        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);
@@ -5871,7 +5869,6 @@ COMMAND_HANDLER(handle_fast_load_image_command)
        uint32_t image_size;
        target_addr_t min_address = 0;
        target_addr_t max_address = -1;
-       int i;
 
        struct image image;
 
@@ -5897,7 +5894,7 @@ COMMAND_HANDLER(handle_fast_load_image_command)
                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)",
index 6d1d426d52f2425911d735638a1c633383bcadae..aaaed0ebb2d0cfc0b7fd8987bbf26c617df66c8d 100644 (file)
@@ -2582,7 +2582,6 @@ static int xscale_read_instruction(struct target *target, uint32_t pc,
        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;
@@ -2592,7 +2591,7 @@ static int xscale_read_instruction(struct target *target, uint32_t pc,
                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)) {
@@ -3428,15 +3427,15 @@ COMMAND_HANDLER(xscale_handle_trace_image_command)
        }
 
        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) {

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)