aboutsummaryrefslogtreecommitdiff
path: root/projects
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2016-12-20 19:05:11 -0500
committerPaul Selkirk <paul@psgd.org>2016-12-20 19:05:11 -0500
commitbebc5595be1679bfcecc70a2be975c461c75524a (patch)
tree1283f70ecc6b6b23f33fa684150d4f14e5eaba63 /projects
parent0a8d3a24018c00b688691678f566e3a5178791ce (diff)
Fix bootloader upload callback routine to write the correct number of bytes to flash. While we're at it, propagate error returns.
Diffstat (limited to 'projects')
-rw-r--r--projects/hsm/mgmt-bootloader.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/projects/hsm/mgmt-bootloader.c b/projects/hsm/mgmt-bootloader.c
index a4783cc..738686e 100644
--- a/projects/hsm/mgmt-bootloader.c
+++ b/projects/hsm/mgmt-bootloader.c
@@ -52,7 +52,8 @@ static uint32_t dfu_offset;
static int _flash_write_callback(uint8_t *buf, size_t len)
{
- stm_flash_write32(dfu_offset, (uint32_t *)buf, sizeof(buf)/4);
+ if (stm_flash_write32(dfu_offset, (uint32_t *)buf, (uint32_t)len/4) != 1)
+ return 0;
dfu_offset += DFU_UPLOAD_CHUNK_SIZE;
return 1;
}
@@ -67,10 +68,12 @@ static int cmd_bootloader_upload(struct cli_def *cli, const char *command, char
uint8_t buf[DFU_UPLOAD_CHUNK_SIZE];
dfu_offset = DFU_BOOTLOADER_ADDR;
- cli_receive_data(cli, buf, sizeof(buf), _flash_write_callback);
-
- cli_print(cli, "DFU offset now: %li (%li chunks)", dfu_offset, dfu_offset / DFU_UPLOAD_CHUNK_SIZE);
- return CLI_OK;
+ int ret = cli_receive_data(cli, buf, sizeof(buf), _flash_write_callback);
+ if (ret == CLI_OK) {
+ cli_print(cli, "\nRebooting\n");
+ HAL_NVIC_SystemReset();
+ }
+ return ret;
}
void configure_cli_bootloader(struct cli_def *cli)