Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#endif

#include "bootutil/boot_hooks.h"
#include "bootutil/mcuboot_status.h"

BOOT_LOG_MODULE_DECLARE(mcuboot);

Expand Down Expand Up @@ -1438,6 +1439,7 @@ bs_upload(char *buf, int len)

if (rc == 0) {
curr_off += img_chunk_len + rem_bytes;
mcuboot_progress(MCUBOOT_PROGRESS_UPLOAD, curr_off, img_size);
if (curr_off == img_size) {
#if defined(MCUBOOT_ERASE_PROGRESSIVELY) && defined(BOOT_IMAGE_HAS_STATUS_FIELDS)
/* Assure that sector for image trailer was erased. If the image
Expand Down
16 changes: 16 additions & 0 deletions boot/bootutil/include/bootutil/mcuboot_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef H_MCUBOOT_STATUS_
#define H_MCUBOOT_STATUS_

#include <stdint.h>

#include "mcuboot_config/mcuboot_config.h"

/* Enumeration representing the states that MCUboot can be in */
Expand All @@ -29,4 +31,18 @@ extern void mcuboot_status_change(mcuboot_status_type_t status);
#define mcuboot_status_change(_status) do {} while (0)
#endif

/* Operations that report progress, and the unit each one counts in */
typedef enum
{
MCUBOOT_PROGRESS_SWAP = 0, /* flash sectors swapped */
MCUBOOT_PROGRESS_UPLOAD, /* bytes received by serial recovery */
} mcuboot_progress_type_t;

#if defined(MCUBOOT_PROGRESS_HOOKS)
extern void mcuboot_progress(mcuboot_progress_type_t type, uint32_t done, uint32_t total);
#else
#define mcuboot_progress(_type, _done, _total) \
do { (void)(_type); (void)(_done); (void)(_total); } while (0)
#endif

#endif /* H_MCUBOOT_STATUS_ */
3 changes: 3 additions & 0 deletions boot/bootutil/src/swap_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "bootutil_priv.h"
#include "swap_priv.h"
#include "bootutil/bootutil_log.h"
#include "bootutil/mcuboot_status.h"

#include "mcuboot_config/mcuboot_config.h"

Expand Down Expand Up @@ -591,6 +592,7 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
return rc;
}
}
mcuboot_progress(MCUBOOT_PROGRESS_SWAP, last_idx - idx + 1, 2 * last_idx);
idx--;
}
bs->idx = BOOT_STATUS_IDX_0;
Expand All @@ -606,6 +608,7 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
return rc;
}
}
mcuboot_progress(MCUBOOT_PROGRESS_SWAP, last_idx + idx, 2 * last_idx);
idx++;
}

Expand Down
3 changes: 3 additions & 0 deletions boot/bootutil/src/swap_offset.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "bootutil_priv.h"
#include "swap_priv.h"
#include "bootutil/bootutil_log.h"
#include "bootutil/mcuboot_status.h"

#include "mcuboot_config/mcuboot_config.h"

Expand Down Expand Up @@ -735,6 +736,7 @@ int swap_run(struct boot_loader_state *state, struct boot_status *bs,
}
}

mcuboot_progress(MCUBOOT_PROGRESS_SWAP, idx + 1, last_idx + 1);
idx++;
}

Expand Down Expand Up @@ -762,6 +764,7 @@ int swap_run(struct boot_loader_state *state, struct boot_status *bs,
}
}

mcuboot_progress(MCUBOOT_PROGRESS_SWAP, idx + 1, last_idx + 1);
idx++;
}
}
Expand Down
4 changes: 4 additions & 0 deletions boot/bootutil/src/swap_scratch.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "bootutil_priv.h"
#include "swap_priv.h"
#include "bootutil/bootutil_log.h"
#include "bootutil/mcuboot_status.h"

#include "mcuboot_config/mcuboot_config.h"

Expand Down Expand Up @@ -974,11 +975,13 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
int first_sector_idx;
int last_sector_idx;
uint32_t swap_idx;
uint32_t num_sectors;
int rc;

BOOT_LOG_INF("Starting swap using scratch algorithm.");

last_sector_idx = find_last_sector_idx(state, copy_size);
num_sectors = last_sector_idx + 1;

swap_idx = 0;
while (last_sector_idx >= 0) {
Expand All @@ -990,6 +993,7 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
}
}

mcuboot_progress(MCUBOOT_PROGRESS_SWAP, num_sectors - first_sector_idx, num_sectors);
last_sector_idx = first_sector_idx - 1;
swap_idx++;
}
Expand Down
11 changes: 11 additions & 0 deletions boot/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,17 @@ config MCUBOOT_ACTION_HOOKS
'mcuboot_status_type_t' is listed in
boot/bootutil/include/bootutil/mcuboot_status.h

config MCUBOOT_PROGRESS_HOOKS
bool "Hooks for reporting swap and serial upload progress"
help
This will call a handler as a swap or a serial recovery upload
advances, which allows for user feedback during these long
operations, for instance blinking an LED, using the callback:
'void mcuboot_progress(mcuboot_progress_type_t type, uint32_t done,
uint32_t total)' where 'mcuboot_progress_type_t' is listed in
boot/bootutil/include/bootutil/mcuboot_status.h. A swap reports
flash sectors, an upload reports bytes.

config FIND_NEXT_SLOT_HOOKS
bool "Hooks for finding the next active slot"
help
Expand Down
4 changes: 4 additions & 0 deletions boot/zephyr/include/mcuboot_config/mcuboot_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@
#define MCUBOOT_ACTION_HOOKS
#endif

#ifdef CONFIG_MCUBOOT_PROGRESS_HOOKS
#define MCUBOOT_PROGRESS_HOOKS
#endif

#if defined(MCUBOOT_DATA_SHARING) && defined(ZEPHYR_VER_INCLUDE)
#include <zephyr/app_version.h>

Expand Down
4 changes: 4 additions & 0 deletions docs/release-notes.d/progress-hooks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Added `MCUBOOT_PROGRESS_HOOKS` (`CONFIG_MCUBOOT_PROGRESS_HOOKS` on
Zephyr). When set, MCUboot calls `mcuboot_progress()` as a swap
(scratch, move or offset) or a serial recovery upload advances, so a
board can show progress during these long operations.
6 changes: 6 additions & 0 deletions samples/mcuboot_config/mcuboot_config.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,10 @@
*/
/* #define MCUBOOT_ACTION_HOOKS */

/*
* MCUboot can also report how far a swap or a serial recovery upload has got, by
* calling mcuboot_progress(), see boot/bootutil/include/bootutil/mcuboot_status.h.
*/
/* #define MCUBOOT_PROGRESS_HOOKS */

#endif /* __MCUBOOT_CONFIG_H__ */
Loading