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/zephyr/include/sysflash/sysflash.h b/boot/zephyr/include/sysflash/sysflash.h
index d4617bb..c422efd 100644
--- a/boot/zephyr/include/sysflash/sysflash.h
+++ b/boot/zephyr/include/sysflash/sysflash.h
@@ -6,26 +6,33 @@
 #include <generated_dts_board.h>
 #include <mcuboot_config/mcuboot_config.h>
 
-extern uint8_t current_image;
-
 #if (MCUBOOT_IMAGE_NUMBER == 1)
-#define FLASH_AREA_IMAGE_PRIMARY    DT_FLASH_AREA_IMAGE_0_ID
-#define FLASH_AREA_IMAGE_SECONDARY  DT_FLASH_AREA_IMAGE_1_ID
+/*
+ * NOTE: the definition below returns the same values for true/false on
+ * purpose, to avoid having to mark x as non-used by all callers when
+ * running in single image mode.
+ */
+#define FLASH_AREA_IMAGE_PRIMARY(x)    (((x) == 0) ?                \
+                                         DT_FLASH_AREA_IMAGE_0_ID : \
+                                         DT_FLASH_AREA_IMAGE_0_ID)
+#define FLASH_AREA_IMAGE_SECONDARY(x)  (((x) == 0) ?                \
+                                         DT_FLASH_AREA_IMAGE_1_ID : \
+                                         DT_FLASH_AREA_IMAGE_1_ID)
 #elif (MCUBOOT_IMAGE_NUMBER == 2)
 /* MCUBoot currently supports only up to 2 updateable firmware images.
  * If the number of the current image is greater than MCUBOOT_IMAGE_NUMBER - 1
  * then a dummy value will be assigned to the flash area macros.
  */
-#define FLASH_AREA_IMAGE_PRIMARY    ((current_image == 0) ?         \
+#define FLASH_AREA_IMAGE_PRIMARY(x)    (((x) == 0) ?                \
                                          DT_FLASH_AREA_IMAGE_0_ID : \
-                                     (current_image == 1) ?         \
+                                        ((x) == 1) ?                \
                                          DT_FLASH_AREA_IMAGE_2_ID : \
-                                         255 )
-#define FLASH_AREA_IMAGE_SECONDARY  ((current_image == 0) ?         \
+                                         255)
+#define FLASH_AREA_IMAGE_SECONDARY(x)  (((x) == 0) ?                \
                                          DT_FLASH_AREA_IMAGE_1_ID : \
-                                     (current_image == 1) ?         \
+                                        ((x) == 1) ?                \
                                          DT_FLASH_AREA_IMAGE_3_ID : \
-                                         255 )
+                                         255)
 #else
 #error "Image slot and flash area mapping is not defined"
 #endif