flash: add padded_value cmd 35/1635/2
authorSpencer Oliver <spen@spen-soft.co.uk>
Thu, 19 Sep 2013 11:07:06 +0000 (12:07 +0100)
committerSpencer Oliver <spen@spen-soft.co.uk>
Mon, 7 Oct 2013 19:28:19 +0000 (19:28 +0000)
This adds support for setting the default value used when padding image
sections. Previously 0xff was used but some targets have an erased value
of 0x00.

Change-Id: If3df6fea3abf95b09daa3ff7be362acf991070ce
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/1635
Tested-by: jenkins
doc/openocd.texi
src/flash/nor/core.c
src/flash/nor/core.h
src/flash/nor/tcl.c
src/flash/nor/virtual.c

index 003ec4ff6284cd924702b72979621a7291c17936..a2bcaf8507801886cc26dff1ed3688a5ba42a16a 100644 (file)
@@ -4862,6 +4862,12 @@ specifies "to the end of the flash bank".
 The @var{num} parameter is a value shown by @command{flash banks}.
 @end deffn
 
+@deffn Command {flash padded_value} num value
+Sets the default value used for padding any image sections, This should
+normally match the flash bank erased value. If not specified by this
+comamnd or the flash driver then it defaults to 0xff.
+@end deffn
+
 @anchor{program}
 @deffn Command {program} filename [verify] [reset] [offset]
 This is a helper script that simplifies using OpenOCD as a standalone
index 21ea05d33782feb96d7934d42fdb4c5bda723532..e61b30326a8003936a98589211a21bfe74d453f2 100644 (file)
@@ -710,7 +710,7 @@ int flash_write_unlock(struct target *target, struct image *image,
 
                        /* see if we need to pad the section */
                        while (padding[section]--)
-                               (buffer + buffer_size)[size_read++] = 0xff;
+                               (buffer + buffer_size)[size_read++] = c->default_padded_value;
 
                        buffer_size += size_read;
                        section_offset += size_read;
index 07b095f9ba57055c9425f72d117a4a35b97b527f..726dd957ececc37802d2f072d793aee3654d63fe 100644 (file)
@@ -87,6 +87,10 @@ struct flash_bank {
        int chip_width; /**< Width of the chip in bytes (1,2,4 bytes) */
        int bus_width; /**< Maximum bus width, in bytes (1,2,4 bytes) */
 
+       /** Default padded value used, normally this matches the  flash
+        * erased value. Defaults to 0xFF. */
+       uint8_t default_padded_value;
+
        /**
         * The number of sectors on this chip.  This value will
         * be set intially to 0, and the flash driver must set this to
index 788d050b967b938ddb9863ee15d8e7c2a8feb335..5bc0958be7fd11c02aa8494d65cc0b297c136f7f 100644 (file)
@@ -605,6 +605,24 @@ void flash_set_dirty(void)
        }
 }
 
+COMMAND_HANDLER(handle_flash_padded_value_command)
+{
+       if (CMD_ARGC != 2)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       struct flash_bank *p;
+       int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &p);
+       if (ERROR_OK != retval)
+               return retval;
+
+       COMMAND_PARSE_NUMBER(u8, CMD_ARGV[1], p->default_padded_value);
+
+       command_print(CMD_CTX, "Default padded value set to 0x%" PRIx8 " for flash bank %u", \
+                       p->default_padded_value, p->bank_number);
+
+       return retval;
+}
+
 static const struct command_registration flash_exec_command_handlers[] = {
        {
                .name = "probe",
@@ -700,6 +718,13 @@ static const struct command_registration flash_exec_command_handlers[] = {
                .help = "Turn protection on or off for a range of sectors "
                        "in a given flash bank.",
        },
+       {
+               .name = "padded_value",
+               .handler = handle_flash_padded_value_command,
+               .mode = COMMAND_EXEC,
+               .usage = "bank_id value",
+               .help = "Set default flash padded value",
+       },
        COMMAND_REGISTRATION_DONE
 };
 
@@ -712,7 +737,6 @@ static int flash_init_drivers(struct command_context *cmd_ctx)
        return register_commands(cmd_ctx, parent, flash_exec_command_handlers);
 }
 
-
 COMMAND_HANDLER(handle_flash_bank_command)
 {
        if (CMD_ARGC < 7) {
@@ -765,6 +789,7 @@ COMMAND_HANDLER(handle_flash_bank_command)
        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], c->size);
        COMMAND_PARSE_NUMBER(int, CMD_ARGV[3], c->chip_width);
        COMMAND_PARSE_NUMBER(int, CMD_ARGV[4], c->bus_width);
+       c->default_padded_value = 0xff;
        c->num_sectors = 0;
        c->sectors = NULL;
        c->next = NULL;
index 45738ed42f88ff94323b9ba0e06f3e448e074d07..fab521dd6cff296df8f4b7aa982109dacd1957be 100644 (file)
@@ -46,6 +46,7 @@ static void virtual_update_bank_info(struct flash_bank *bank)
        bank->size = master_bank->size;
        bank->chip_width = master_bank->chip_width;
        bank->bus_width = master_bank->bus_width;
+       bank->default_padded_value = master_bank->default_padded_value;
        bank->num_sectors = master_bank->num_sectors;
        bank->sectors = master_bank->sectors;
 }

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)