[Cryptech-Commits] [sw/stm32] 02/04: Fix bootloader upload callback routine to write the correct number of bytes to flash. While we're at it, propagate error returns.

git at cryptech.is git at cryptech.is
Wed Dec 21 00:11:05 UTC 2016


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch master
in repository sw/stm32.

commit bebc5595be1679bfcecc70a2be975c461c75524a
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Tue Dec 20 19:05:11 2016 -0500

    Fix bootloader upload callback routine to write the correct number of bytes to flash. While we're at it, propagate error returns.
---
 projects/hsm/mgmt-bootloader.c | 13 ++++++++-----
 1 file 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)



More information about the Commits mailing list