Added 'unlock' option to flash write_image

__archive__
Øyvind Harboe 2009-10-20 12:03:36 +02:00
parent e4dba30b63
commit ad75639611
2 changed files with 63 additions and 17 deletions

View File

@ -3537,7 +3537,7 @@ The @var{num} parameter is a value shown by @command{flash banks}.
@end deffn @end deffn
@anchor{flash write_image} @anchor{flash write_image}
@deffn Command {flash write_image} [erase] filename [offset] [type] @deffn Command {flash write_image} [erase] [unlock] filename [offset] [type]
Write the image @file{filename} to the current target's flash bank(s). Write the image @file{filename} to the current target's flash bank(s).
A relocation @var{offset} may be specified, in which case it is added A relocation @var{offset} may be specified, in which case it is added
to the base address for each section in the image. to the base address for each section in the image.
@ -3546,8 +3546,9 @@ explicitly as @option{bin} (binary), @option{ihex} (Intel hex),
@option{elf} (ELF file), @option{s19} (Motorola s19). @option{elf} (ELF file), @option{s19} (Motorola s19).
@option{mem}, or @option{builder}. @option{mem}, or @option{builder}.
The relevant flash sectors will be erased prior to programming The relevant flash sectors will be erased prior to programming
if the @option{erase} parameter is given. if the @option{erase} parameter is given. If @option{unlock} is
The flash bank to use is inferred from the @var{address} of provided, then the flash banks are unlocked before erase and
program. The flash bank to use is inferred from the @var{address} of
each image segment. each image segment.
@end deffn @end deffn

View File

@ -43,6 +43,7 @@ static int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, ch
static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
static int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); static int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
static int flash_write_unlock(target_t *target, image_t *image, uint32_t *written, int erase, bool unlock);
/* flash drivers /* flash drivers
*/ */
@ -199,7 +200,7 @@ int flash_init_drivers(struct command_context_s *cmd_ctx)
register_command(cmd_ctx, flash_cmd, "write_bank", handle_flash_write_bank_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "write_bank", handle_flash_write_bank_command, COMMAND_EXEC,
"write binary data to <bank> <file> <offset>"); "write binary data to <bank> <file> <offset>");
register_command(cmd_ctx, flash_cmd, "write_image", handle_flash_write_image_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "write_image", handle_flash_write_image_command, COMMAND_EXEC,
"write_image [erase] <file> [offset] [type]"); "write_image [erase] [unlock] <file> [offset] [type]");
register_command(cmd_ctx, flash_cmd, "protect", handle_flash_protect_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "protect", handle_flash_protect_command, COMMAND_EXEC,
"set protection of sectors at <bank> <first> <last> <on | off>"); "set protection of sectors at <bank> <first> <last> <on | off>");
} }
@ -697,13 +698,26 @@ static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, c
/* flash auto-erase is disabled by default*/ /* flash auto-erase is disabled by default*/
int auto_erase = 0; int auto_erase = 0;
bool auto_unlock = false;
if (strcmp(args[0], "erase") == 0) for (;;)
{ {
auto_erase = 1; if (strcmp(args[0], "erase") == 0)
args++; {
argc--; auto_erase = 1;
command_print(cmd_ctx, "auto erase enabled"); args++;
argc--;
command_print(cmd_ctx, "auto erase enabled");
} else if (strcmp(args[0], "unlock") == 0)
{
auto_unlock = true;
args++;
argc--;
command_print(cmd_ctx, "auto unlock enabled");
} else
{
break;
}
} }
if (argc < 1) if (argc < 1)
@ -738,7 +752,7 @@ static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, c
return retval; return retval;
} }
retval = flash_write(target, &image, &written, auto_erase); retval = flash_write_unlock(target, &image, &written, auto_erase, auto_unlock);
if (retval != ERROR_OK) if (retval != ERROR_OK)
{ {
image_close(&image); image_close(&image);
@ -994,7 +1008,8 @@ flash_bank_t *get_flash_bank_by_addr(target_t *target, uint32_t addr)
} }
/* erase given flash region, selects proper bank according to target and address */ /* erase given flash region, selects proper bank according to target and address */
int flash_erase_address_range(target_t *target, uint32_t addr, uint32_t length) static int flash_iterate_address_range(target_t *target, uint32_t addr, uint32_t length,
int (*callback)(struct flash_bank_s *bank, int first, int last))
{ {
flash_bank_t *c; flash_bank_t *c;
int first = -1; int first = -1;
@ -1016,7 +1031,7 @@ int flash_erase_address_range(target_t *target, uint32_t addr, uint32_t length)
if (addr != c->base) if (addr != c->base)
return ERROR_FLASH_DST_BREAKS_ALIGNMENT; return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
return flash_driver_erase(c, 0, c->num_sectors - 1); return callback(c, 0, c->num_sectors - 1);
} }
/* check whether it fits */ /* check whether it fits */
@ -1039,11 +1054,29 @@ int flash_erase_address_range(target_t *target, uint32_t addr, uint32_t length)
if (first == -1 || last == -1) if (first == -1 || last == -1)
return ERROR_OK; return ERROR_OK;
return flash_driver_erase(c, first, last); return callback(c, first, last);
} }
int flash_erase_address_range(target_t *target, uint32_t addr, uint32_t length)
{
return flash_iterate_address_range(target, addr, length, &flash_driver_erase);
}
static int flash_driver_unprotect(struct flash_bank_s *bank, int first, int last)
{
return flash_driver_protect(bank, 0, first, last);
}
static int flash_unlock_address_range(target_t *target, uint32_t addr, uint32_t length)
{
return flash_iterate_address_range(target, addr, length, &flash_driver_unprotect);
}
/* write (optional verify) an image to flash memory of the given target */ /* write (optional verify) an image to flash memory of the given target */
int flash_write(target_t *target, image_t *image, uint32_t *written, int erase) static int flash_write_unlock(target_t *target, image_t *image, uint32_t *written, int erase, bool unlock)
{ {
int retval = ERROR_OK; int retval = ERROR_OK;
@ -1166,10 +1199,17 @@ int flash_write(target_t *target, image_t *image, uint32_t *written, int erase)
retval = ERROR_OK; retval = ERROR_OK;
if (erase) if (unlock)
{ {
/* calculate and erase sectors */ retval = flash_unlock_address_range(target, run_address, run_size);
retval = flash_erase_address_range(target, run_address, run_size); }
if (retval == ERROR_OK)
{
if (erase)
{
/* calculate and erase sectors */
retval = flash_erase_address_range(target, run_address, run_size);
}
} }
if (retval == ERROR_OK) if (retval == ERROR_OK)
@ -1195,6 +1235,11 @@ int flash_write(target_t *target, image_t *image, uint32_t *written, int erase)
return retval; return retval;
} }
int flash_write(target_t *target, image_t *image, uint32_t *written, int erase)
{
return flash_write_unlock(target, image, written, erase, false);
}
int default_flash_mem_blank_check(struct flash_bank_s *bank) int default_flash_mem_blank_check(struct flash_bank_s *bank)
{ {
target_t *target = bank->target; target_t *target = bank->target;