Commit c2e30cf2 authored by Andrzej Puzdrowski's avatar Andrzej Puzdrowski Committed by Fabio Utzig
Browse files

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: default avatarAndrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
parent 205c8c69
Loading
Loading
Loading
Loading
+26 −1
Changes for boot/boot_serial/src/boot_serial.c: 26 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -55,6 +55,10 @@
#include "boot_serial/boot_serial.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_OUT_MAX	80

@@ -354,7 +358,7 @@ bs_upload(char *buf, int len)
    }
    if (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);
        if (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);
    if (rc == 0) {
        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 {
    out_invalid_data:
        rc = MGMT_ERR_EINVAL;
+4
Changes for boot/zephyr/CMakeLists.txt: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -134,6 +134,10 @@ zephyr_include_directories(${BOOT_DIR}/bootutil/include)
  zephyr_include_directories(${BOOT_DIR}/boot_serial/include)
  zephyr_include_directories(include)
  zephyr_link_libraries_ifdef(CONFIG_TINYCBOR TINYCBOR)

  if (CONFIG_BOOT_ERASE_PROGRESSIVELY)
    zephyr_include_directories(${BOOT_DIR}/bootutil/src)
  endif()
endif()

if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "")