Remove current_image global and macro updates
Currently to determine which image is being operated on, there is a global
variable called current_image which is used by most macros and APIs to
correctly access the flash areas required by the bootloader. This moves
this variable to the already existing state struct and refactors all
macros and APIs to receive the current image by parameters. To maintain
compatibility some of the macros were not updated and use image 0 when
called.
The definitions of FLASH_AREA_IMAGE_PRIMARY and FLASH_AREA_IMAGE_SECONDARY
for Mynewt compatibility were moved out of bootutil sources to a Mynewt
specific include file.
Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c
index 1ea009b..bdf3749 100644
--- a/boot/boot_serial/src/boot_serial.c
+++ b/boot/boot_serial/src/boot_serial.c
@@ -178,7 +178,7 @@
flash_area_read(fap, 0, &hdr, sizeof(hdr));
if (hdr.ih_magic != IMAGE_MAGIC ||
- bootutil_img_validate(&hdr, fap, tmpbuf, sizeof(tmpbuf),
+ bootutil_img_validate(0, &hdr, fap, tmpbuf, sizeof(tmpbuf),
NULL, 0, NULL)) {
flash_area_close(fap);
continue;
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c b/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c
index e2c7dbd..7aa9590 100644
--- a/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c
+++ b/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c
@@ -61,7 +61,7 @@
/*
* Validate contents inside the primary slot
*/
- rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY, &fap);
+ rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(0), &fap);
assert(rc == 0);
rc = flash_area_read(fap, 0, enc_img, sizeof(img));