bootutil: Add active slot number and max app size to shared data
This allows the currently executing slot number to be checked by
the external function, which can be used by XIP images to know
which slot is currently being executed from to allow for correct
uploading/positioning of firmware files, and also provides the
maximum size of an upgrade that can be loaded so that applications
can reject images that are too large.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
diff --git a/boot/bootutil/src/swap_move.c b/boot/bootutil/src/swap_move.c
index d7b5108..61246b9 100644
--- a/boot/bootutil/src/swap_move.c
+++ b/boot/bootutil/src/swap_move.c
@@ -542,4 +542,26 @@
flash_area_close(fap_sec);
}
+int app_max_size(struct boot_loader_state *state)
+{
+ uint32_t sz = 0;
+ uint32_t sector_sz;
+ uint32_t trailer_sz;
+ uint32_t first_trailer_idx;
+
+ sector_sz = boot_img_sector_size(state, BOOT_PRIMARY_SLOT, 0);
+ trailer_sz = boot_trailer_sz(BOOT_WRITE_SZ(state));
+ first_trailer_idx = boot_img_num_sectors(state, BOOT_PRIMARY_SLOT) - 1;
+
+ while (1) {
+ sz += sector_sz;
+ if (sz >= trailer_sz) {
+ break;
+ }
+ first_trailer_idx--;
+ }
+
+ return (first_trailer_idx * sector_sz);
+}
+
#endif