Add support for swapping only fw sectors in use
Before this patch, the swapping would process all sectors in a slot
not matter what the size of the binary firmware was. This changes the
swap process to swap only sectors that are in use by firmware.
Also, if the last slot sector, which stores the trailer, is actually not
in use by the binary firmware, now trailer is never written to scratch.
`use_scratch` temp variable was added to boot_status struct to control
this (this var is never written to disk).
Random other small refactorings were applied.
diff --git a/boot/bootutil/src/bootutil_priv.h b/boot/bootutil/src/bootutil_priv.h
index 6de8d4e..45ce625 100644
--- a/boot/bootutil/src/bootutil_priv.h
+++ b/boot/bootutil/src/bootutil_priv.h
@@ -45,8 +45,9 @@
* Maintain state of copy progress.
*/
struct boot_status {
- uint32_t idx; /* Which area we're operating on */
- uint8_t state; /* Which part of the swapping process are we at */
+ uint32_t idx; /* Which area we're operating on */
+ uint8_t state; /* Which part of the swapping process are we at */
+ uint8_t use_scratch; /* Are status bytes ever written to scratch? */
};
#define BOOT_MAGIC_GOOD 1
@@ -86,6 +87,9 @@
#define BOOT_STATUS_SOURCE_SCRATCH 1
#define BOOT_STATUS_SOURCE_SLOT0 2
+#define BOOT_FLAG_IMAGE_OK 0
+#define BOOT_FLAG_COPY_DONE 1
+
extern const uint32_t BOOT_MAGIC_SZ;
int bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, int slen,
@@ -95,8 +99,8 @@
uint32_t boot_status_off(const struct flash_area *fap);
int boot_read_swap_state(const struct flash_area *fap,
struct boot_swap_state *state);
-int boot_read_swap_state_img(int slot, struct boot_swap_state *state);
-int boot_read_swap_state_scratch(struct boot_swap_state *state);
+int boot_read_swap_state_by_id(int flash_area_id,
+ struct boot_swap_state *state);
int boot_write_magic(const struct flash_area *fap);
int boot_write_status(struct boot_status *bs);
int boot_schedule_test_swap(void);