Rebased: Add return value check for flash_func_start() calls
@@ -106,9 +106,6 @@ static error_t target_flash_init()
return ERROR_ALGO_DL;
}
- if (0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->init, g_board_info.target_cfg->flash_start, 0, 0, 0)) {
- return ERROR_INIT;
- }
state = STATE_OPEN;
return ERROR_SUCCESS;
} else {
@@ -120,7 +117,10 @@ static error_t target_flash_init()
static error_t target_flash_uninit(void)
{
if (g_board_info.target_cfg) {
- flash_func_start(FLASH_FUNC_NOP);
+ error_t status = flash_func_start(FLASH_FUNC_NOP);
+ if (status != ERROR_SUCCESS) {
+ return status;
+ }
if (config_get_auto_rst()) {
// Resume the target if configured to do so
target_set_state(RESET_RUN);
@@ -142,8 +142,9 @@ static error_t target_flash_uninit(void)
static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size)
{
- if (g_board_info.target_cfg) {
+ if (g_board_info.target_cfg) {
+ error_t status = ERROR_SUCCESS;
const program_target_t *const flash = g_board_info.target_cfg->flash_algo;
// check if security bits were set
@@ -153,7 +154,12 @@ static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint
}
}
- flash_func_start(FLASH_FUNC_PROGRAM);
+ status = flash_func_start(FLASH_FUNC_PROGRAM);
+
+ if (status != ERROR_SUCCESS) {
+ return status;
+ }
+
while (size > 0) {
uint32_t write_size = MIN(size, flash->program_buffer_size);
@@ -216,7 +222,9 @@ static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint
static error_t target_flash_erase_sector(uint32_t addr)
{
+
if (g_board_info.target_cfg) {
+ error_t status = ERROR_SUCCESS;
const program_target_t *const flash = g_board_info.target_cfg->flash_algo;
// Check to make sure the address is on a sector boundary
@@ -224,8 +232,12 @@ static error_t target_flash_erase_sector(uint32_t addr)
return ERROR_ERASE_SECTOR;
}
+ status = flash_func_start(FLASH_FUNC_ERASE);
+
+ if (status != ERROR_SUCCESS) {
+ return status;
+ }
- flash_func_start(FLASH_FUNC_ERASE);
if (0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->erase_sector, addr, 0, 0, 0)) {
return ERROR_ERASE_SECTOR;
}
@@ -242,7 +254,10 @@ static error_t target_flash_erase_chip(void)
error_t status = ERROR_SUCCESS;
const program_target_t *const flash = g_board_info.target_cfg->flash_algo;
- flash_func_start(FLASH_FUNC_PROGRAM);
+ status = flash_func_start(FLASH_FUNC_PROGRAM);
+ if (status != ERROR_SUCCESS) {
+ return status;
+ }
if (0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->erase_chip, 0, 0, 0, 0)) {
return ERROR_ERASE_ALL;
}
