From faa19b5280ba9f5bd0ffede853a300157a116954 Mon Sep 17 00:00:00 2001 From: Maxime Coquelin Date: Mon, 14 Mar 2016 15:09:22 +0100 Subject: [PATCH] stlink-common: Ensure flash type is properly declared in device params Signed-off-by: Maxime Coquelin --- src/stlink-common.c | 11 +++++++---- src/stlink-common.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/stlink-common.c b/src/stlink-common.c index 76413b4..a1ccdfd 100644 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@ -591,6 +591,12 @@ int stlink_load_device_params(stlink_t *sl) { return -1; } + if (params->flash_type == FLASH_TYPE_UNKNOWN) { + WLOG("Invalid flash type, please check device declaration\n"); + return -1; + } + + // These are fixed... sl->flash_base = STM32_FLASH_BASE; sl->sram_base = STM32_SRAM_BASE; @@ -2063,7 +2069,7 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons reg rr; int i = 0; - size_t count; + size_t count = 0; DLOG("Running flash loader, write address:%#x, size: %zd\n", target, size); // FIXME This can never return -1 @@ -2085,9 +2091,6 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons count = size / sizeof(uint64_t); if (size % sizeof(uint64_t)) ++count; - } else { - fprintf(stderr, "unknown coreid 0x%x, don't know what flash loader to use\n", sl->core_id); - return -1; } /* setup core */ diff --git a/src/stlink-common.h b/src/stlink-common.h index e7be10f..448d01a 100644 --- a/src/stlink-common.h +++ b/src/stlink-common.h @@ -167,6 +167,7 @@ extern "C" { #define C_BUF_LEN 32 enum flash_type { + FLASH_TYPE_UNKNOWN = 0, FLASH_TYPE_F0, FLASH_TYPE_L0, FLASH_TYPE_F4, -- 2.47.2