serial recovery: always erase image status

It is possible that while flash was erased progressively
the flash image status page was not erased.
This patch check this case and performs additional eras
if it was required.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
Andrzej Puzdrowski 2018-07-20 16:19:09 +02:00 committed by Fabio Utzig
parent 205c8c6980
commit c2e30cf2c3
2 changed files with 36 additions and 7 deletions

View File

@ -55,6 +55,10 @@
#include "boot_serial/boot_serial.h" #include "boot_serial/boot_serial.h"
#include "boot_serial_priv.h" #include "boot_serial_priv.h"
#ifdef CONFIG_BOOT_ERASE_PROGRESSIVELY
#include "bootutil_priv.h"
#endif
#define BOOT_SERIAL_INPUT_MAX 512 #define BOOT_SERIAL_INPUT_MAX 512
#define BOOT_SERIAL_OUT_MAX 80 #define BOOT_SERIAL_OUT_MAX 80
@ -354,7 +358,7 @@ bs_upload(char *buf, int len)
} }
if (off_last != sector.fs_off) { if (off_last != sector.fs_off) {
off_last = sector.fs_off; off_last = sector.fs_off;
BOOT_LOG_INF("Moving to sector 0x%x", sector.fs_off); BOOT_LOG_INF("Erasing sector at offset 0x%x", sector.fs_off);
rc = flash_area_erase(fap, sector.fs_off, sector.fs_size); rc = flash_area_erase(fap, sector.fs_off, sector.fs_size);
if (rc) { if (rc) {
BOOT_LOG_ERR("Error %d while erasing sector", rc); BOOT_LOG_ERR("Error %d while erasing sector", rc);
@ -367,6 +371,27 @@ bs_upload(char *buf, int len)
rc = flash_area_write(fap, curr_off, img_data, img_blen); rc = flash_area_write(fap, curr_off, img_data, img_blen);
if (rc == 0) { if (rc == 0) {
curr_off += img_blen; curr_off += img_blen;
#ifdef CONFIG_BOOT_ERASE_PROGRESSIVELY
if (curr_off == img_size) {
/* get the last sector offset */
rc = flash_area_sector_from_off(boot_status_off(fap), &sector);
if (rc) {
BOOT_LOG_ERR("Unable to determine flash sector of"
"the image trailer");
goto out;
}
/* Assure that sector for image trailer was erased. */
/* Check whether it was erased during previous upload. */
if (off_last < sector.fs_off) {
BOOT_LOG_INF("Erasing sector at offset 0x%x", sector.fs_off);
rc = flash_area_erase(fap, sector.fs_off, sector.fs_size);
if (rc) {
BOOT_LOG_ERR("Error %d while erasing sector", rc);
goto out;
}
}
}
#endif
} else { } else {
out_invalid_data: out_invalid_data:
rc = MGMT_ERR_EINVAL; rc = MGMT_ERR_EINVAL;

View File

@ -127,13 +127,17 @@ elseif(CONFIG_BOOT_SIGNATURE_TYPE_RSA)
endif() endif()
if (CONFIG_MCUBOOT_SERIAL) if (CONFIG_MCUBOOT_SERIAL)
zephyr_sources(${BOOT_DIR}/zephyr/serial_adapter.c) zephyr_sources(${BOOT_DIR}/zephyr/serial_adapter.c)
zephyr_sources(${BOOT_DIR}/boot_serial/src/boot_serial.c) zephyr_sources(${BOOT_DIR}/boot_serial/src/boot_serial.c)
zephyr_include_directories(${BOOT_DIR}/bootutil/include) zephyr_include_directories(${BOOT_DIR}/bootutil/include)
zephyr_include_directories(${BOOT_DIR}/boot_serial/include) zephyr_include_directories(${BOOT_DIR}/boot_serial/include)
zephyr_include_directories(include) zephyr_include_directories(include)
zephyr_link_libraries_ifdef(CONFIG_TINYCBOR TINYCBOR) zephyr_link_libraries_ifdef(CONFIG_TINYCBOR TINYCBOR)
if (CONFIG_BOOT_ERASE_PROGRESSIVELY)
zephyr_include_directories(${BOOT_DIR}/bootutil/src)
endif()
endif() endif()
if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "") if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "")