aboutsummaryrefslogtreecommitdiff
path: root/src/lpc43xx.c
diff options
context:
space:
mode:
authorAllen Ibara2014-01-10 10:48:59 -0800
committerAllen Ibara2014-01-10 13:24:25 -0800
commit813622b1b6146371a3a9ff50bc62727ecd1f6b26 (patch)
tree6c83d5e98c57c3f93db5ae07f6b8a7b9686506ec /src/lpc43xx.c
parent29c7846612f90acb7ced1f6a1d49d9062609ec2b (diff)
LPC43XX: Add mkboot target command; dont make banks bootable by default.
This used to be done transparently in the write step, however that breaks the 'verify' command. This is also more flexible for cases where you want to write a flash bank without ever intending it to be bootable.
Diffstat (limited to 'src/lpc43xx.c')
-rw-r--r--src/lpc43xx.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/src/lpc43xx.c b/src/lpc43xx.c
index 1a437e3..49f8068 100644
--- a/src/lpc43xx.c
+++ b/src/lpc43xx.c
@@ -114,6 +114,7 @@ struct flash_program {
};
static bool lpc43xx_cmd_erase(target *t);
+static bool lpc43xx_cmd_mkboot(target *target, int argc, const char *argv[]);
static int lpc43xx_flash_init(struct target_s *target);
static void lpc43xx_iap_call(struct target_s *target, struct flash_param *param, unsigned param_len);
static int lpc43xx_flash_prepare(struct target_s *target, uint32_t addr, int len);
@@ -122,6 +123,7 @@ static int lpc43xx_flash_write(struct target_s *target, uint32_t dest, const uin
const struct command_s lpc43xx_cmd_list[] = {
{"erase_mass", (cmd_handler)lpc43xx_cmd_erase, "Erase entire flash memory"},
+ {"mkboot", lpc43xx_cmd_mkboot, "Make flash bank bootable"},
{NULL, NULL, NULL}
};
@@ -467,21 +469,56 @@ static int lpc43xx_flash_write(struct target_s *target, uint32_t dest, const uin
if (flash_pgm.p.result[0] != IAP_STATUS_CMD_SUCCESS) {
return -1;
}
+ }
+
+ return 0;
+}
- /* special command to compute/write magic vector for signature */
- if (chunk == first_chunk)
+/*
+ * Call Boot ROM code to make a flash bank bootable by computing and writing the
+ * correct signature into the exception table near the start of the bank.
+ *
+ * This is done indepently of writing to give the user a chance to verify flash
+ * before changing it.
+ */
+static bool lpc43xx_cmd_mkboot(target *target, int argc, const char *argv[])
+{
+ /* Usage: mkboot 0 or mkboot 1 */
+ if (argc == 2)
+ {
+ const long int bank = strtol(argv[1], NULL, 0);
+
+ if (bank == 0 || bank == 1)
{
+ lpc43xx_flash_init(target);
+ struct flash_program flash_pgm;
+
+ /* special command to compute/write magic vector for signature */
flash_pgm.p.command = IAP_CMD_SET_ACTIVE_BANK;
- flash_pgm.p.params.make_active.flash_bank = flash_bank(dest);
+ flash_pgm.p.params.make_active.flash_bank = bank;
flash_pgm.p.params.make_active.cpu_clk_khz = CPU_CLK_KHZ;
flash_pgm.p.result[0] = IAP_STATUS_CMD_SUCCESS;
lpc43xx_iap_call(target, &flash_pgm.p, sizeof(flash_pgm));
- if (flash_pgm.p.result[0] != IAP_STATUS_CMD_SUCCESS) {
- return -1;
+ if (flash_pgm.p.result[0] == IAP_STATUS_CMD_SUCCESS) {
+ gdb_outf("Set bootable OK.\n");
+ return true;
+ }
+ else
+ {
+ gdb_outf("Set bootable failed.\n");
}
}
-
+ else
+ {
+ gdb_outf("Unexpected bank number, should be 0 or 1.\n");
+ }
+ }
+ else
+ {
+ gdb_outf("Expected bank argument 0 or 1.\n");
}
- return 0;
+
+ return false;
}
+