Nicolas Pitre nico at cam.org The code unconditionally writes into the oob area all...
[openocd.git] / src / flash / flash.c
index 6d47334b9302158f78c3689e112716149662871d..1572e5cd53b8239620e5d0882c4dc4042ed4b0c3 100644 (file)
@@ -78,6 +78,7 @@ extern flash_driver_t tms470_flash;
 extern flash_driver_t ecosflash_flash;
 extern flash_driver_t lpc288x_flash;
 extern flash_driver_t ocl_flash;
+extern flash_driver_t pic32mx_flash;
 
 flash_driver_t *flash_drivers[] = {
        &lpc2000_flash,
@@ -94,6 +95,7 @@ flash_driver_t *flash_drivers[] = {
        &ecosflash_flash,
        &lpc288x_flash,
        &ocl_flash,
+       &pic32mx_flash,
        NULL,
 };
 
@@ -144,7 +146,7 @@ int flash_register_commands(struct command_context_s *cmd_ctx)
 {
        flash_cmd = register_command(cmd_ctx, NULL, "flash", NULL, COMMAND_ANY, NULL);
 
-       register_command(cmd_ctx, flash_cmd, "bank", handle_flash_bank_command, COMMAND_CONFIG, "flash_bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]");
+       register_command(cmd_ctx, flash_cmd, "bank", handle_flash_bank_command, COMMAND_CONFIG, "flash bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]");
        return ERROR_OK;
 }
 
@@ -157,11 +159,6 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                return JIM_ERR;
        }
 
-       if (!flash_banks)
-       {
-               return JIM_ERR;
-       }
-
        Jim_Obj *list=Jim_NewListObj(interp, NULL, 0);
        for (p = flash_banks; p; p = p->next)
        {
@@ -188,10 +185,10 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 
 int flash_init_drivers(struct command_context_s *cmd_ctx)
 {
+       register_jim(cmd_ctx, "ocd_flash_banks", jim_flash_banks, "return information about the flash banks");
+
        if (flash_banks)
        {
-               register_jim(cmd_ctx, "ocd_flash_banks", jim_flash_banks, "return information about the flash banks");
-
                register_command(cmd_ctx, flash_cmd, "info", handle_flash_info_command, COMMAND_EXEC,
                                                 "print info about flash bank <num>");
                register_command(cmd_ctx, flash_cmd, "probe", handle_flash_probe_command, COMMAND_EXEC,
@@ -321,14 +318,17 @@ int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char
                        /* put flash bank in linked list */
                        if (flash_banks)
                        {
+                               int     bank_num = 0;
                                /* find last flash bank */
-                               for (p = flash_banks; p && p->next; p = p->next);
+                               for (p = flash_banks; p && p->next; p = p->next) bank_num++;
                                if (p)
                                        p->next = c;
+                               c->bank_number = bank_num + 1;
                        }
                        else
                        {
                                flash_banks = c;
+                               c->bank_number = 0;
                        }
 
                        found = 1;
@@ -471,7 +471,6 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
                                                j, p->sectors[j].offset, p->sectors[j].size, p->sectors[j].size>>10,
                                                erase_state);
                }
-
        }
 
        return ERROR_OK;
@@ -663,7 +662,6 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
                command_print(cmd_ctx, "auto erase enabled");
        }
 
-
        if (argc < 1)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -748,7 +746,6 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
        if(count == 0)
                return ERROR_OK;
 
-
        switch(cmd[4])
        {
        case 'w':
@@ -809,7 +806,6 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
                return retval;
        }
 
-
        if(err == ERROR_OK)
        {
                float speed;
@@ -954,7 +950,7 @@ int flash_erase_address_range(target_t *target, u32 addr, u32 length)
        }
 
        /* check whether it fits */
-       if (addr + length > c->base + c->size)
+       if (addr + length - 1 > c->base + c->size - 1)
                return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
 
        addr -= c->base;
@@ -1034,7 +1030,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                section_first = section;
                section_last = section;
                padding[section] = 0;
-               while ((run_address + run_size < c->base + c->size)
+               while ((run_address + run_size - 1 < c->base + c->size - 1)
                                && (section_last + 1 < image->num_sections))
                {
                        if (image->sections[section_last + 1].base_address < (run_address + run_size))
@@ -1056,8 +1052,12 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                }
 
                /* fit the run into bank constraints */
-               if (run_address + run_size > c->base + c->size)
+               if (run_address + run_size - 1 > c->base + c->size - 1)
+               {
+                       LOG_WARNING("writing %d bytes only - as image section is %d bytes and bank is only %d bytes", \
+                                       c->base + c->size - run_address, run_size, c->size);
                        run_size = c->base + c->size - run_address;
+               }
 
                /* allocate buffer */
                buffer = malloc(run_size);
@@ -1178,7 +1178,7 @@ int default_flash_blank_check(struct flash_bank_s *bank)
        int i;
        int retval;
        int fast_check = 0;
-       int blank;
+       u32 blank;
 
        if (bank->target->state != TARGET_HALTED)
        {

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)