flash_map: Increase minimum supported write align via flash_area_align

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index c4f5a06..e2c70bc 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -167,7 +167,7 @@
 boot_status_off(const struct flash_area *fap)
 {
     uint32_t off_from_end;
-    uint8_t elem_sz;
+    uint32_t elem_sz;
 
     elem_sz = flash_area_align(fap);
 
diff --git a/boot/bootutil/src/bootutil_public.c b/boot/bootutil/src/bootutil_public.c
index f9b086f..6ce09d0 100644
--- a/boot/bootutil/src/bootutil_public.c
+++ b/boot/bootutil/src/bootutil_public.c
@@ -370,8 +370,8 @@
         const uint8_t *inbuf, uint8_t inlen)
 {
     uint8_t buf[BOOT_MAX_ALIGN];
-    uint8_t align;
     uint8_t erased_val;
+    uint32_t align;
     int rc;
 
     align = flash_area_align(fap);
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index 10bd5c6..6f6343c 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -426,7 +426,7 @@
     int area_id;
     int rc = 0;
     uint8_t buf[BOOT_MAX_ALIGN];
-    uint8_t align;
+    uint32_t align;
     uint8_t erased_val;
 
     /* NOTE: The first sector copied (that is the last sector on slot) contains
diff --git a/boot/cypress/cy_flash_pal/cy_flash_map.c b/boot/cypress/cy_flash_pal/cy_flash_map.c
index 2e56031..0878568 100644
--- a/boot/cypress/cy_flash_pal/cy_flash_map.c
+++ b/boot/cypress/cy_flash_pal/cy_flash_map.c
@@ -355,7 +355,7 @@
 }
 
 /*< Returns this `flash_area`s alignment */
-size_t flash_area_align(const struct flash_area *fa)
+uint32_t flash_area_align(const struct flash_area *fa)
 {
     int ret = -1;
     if (fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH)
diff --git a/boot/cypress/cy_flash_pal/include/flash_map_backend/flash_map_backend.h b/boot/cypress/cy_flash_pal/include/flash_map_backend/flash_map_backend.h
index 1c4dc7a..6fd506d 100644
--- a/boot/cypress/cy_flash_pal/include/flash_map_backend/flash_map_backend.h
+++ b/boot/cypress/cy_flash_pal/include/flash_map_backend/flash_map_backend.h
@@ -167,7 +167,7 @@
 /*< Erases `len` bytes of flash memory at `off` */
 int flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len);
 /*< Returns this `flash_area`s alignment */
-size_t flash_area_align(const struct flash_area *);
+uint32_t flash_area_align(const struct flash_area *);
 /*< Initializes an array of flash_area elements for the slot's sectors */
 int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret);
 /*< Returns the `fa_id` for slot, where slot is 0 (primary) or 1 (secondary) */
diff --git a/boot/espressif/include/flash_map_backend/flash_map_backend.h b/boot/espressif/include/flash_map_backend/flash_map_backend.h
index fcbdc9f..b56bcbc 100644
--- a/boot/espressif/include/flash_map_backend/flash_map_backend.h
+++ b/boot/espressif/include/flash_map_backend/flash_map_backend.h
@@ -69,7 +69,7 @@
                      uint32_t off, uint32_t len);
 
 //! Returns this `flash_area`s alignment
-size_t flash_area_align(const struct flash_area *area);
+uint32_t flash_area_align(const struct flash_area *area);
 //! Returns the value read from an erased flash area byte
 uint8_t flash_area_erased_val(const struct flash_area *area);
 
diff --git a/boot/espressif/port/esp_mcuboot.c b/boot/espressif/port/esp_mcuboot.c
index 556e422..4dd03b9 100644
--- a/boot/espressif/port/esp_mcuboot.c
+++ b/boot/espressif/port/esp_mcuboot.c
@@ -239,7 +239,7 @@
     return 0;
 }
 
-size_t flash_area_align(const struct flash_area *area)
+uint32_t flash_area_align(const struct flash_area *area)
 {
     return 4;
 }
diff --git a/boot/mbed/include/flash_map_backend/flash_map_backend.h b/boot/mbed/include/flash_map_backend/flash_map_backend.h
index f2bad16..34bac73 100644
--- a/boot/mbed/include/flash_map_backend/flash_map_backend.h
+++ b/boot/mbed/include/flash_map_backend/flash_map_backend.h
@@ -143,7 +143,7 @@
 /*
  * Alignment restriction for flash writes.
  */
-uint8_t flash_area_align(const struct flash_area * fap);
+uint32_t flash_area_align(const struct flash_area * fap);
 
 /*
  * What is value is read from erased flash bytes.
diff --git a/boot/mbed/src/flash_map_backend.cpp b/boot/mbed/src/flash_map_backend.cpp
index 28afec8..8f5137d 100644
--- a/boot/mbed/src/flash_map_backend.cpp
+++ b/boot/mbed/src/flash_map_backend.cpp
@@ -191,7 +191,7 @@
     return bd->erase(off, len);
 }
 
-uint8_t flash_area_align(const struct flash_area* fap) {
+uint32_t flash_area_align(const struct flash_area* fap) {
     mbed::BlockDevice* bd = flash_map_bd[fap->fa_id];
     return bd->get_program_size();
 }
diff --git a/boot/nuttx/include/flash_map_backend/flash_map_backend.h b/boot/nuttx/include/flash_map_backend/flash_map_backend.h
index 91ea90f..50dbc57 100644
--- a/boot/nuttx/include/flash_map_backend/flash_map_backend.h
+++ b/boot/nuttx/include/flash_map_backend/flash_map_backend.h
@@ -306,7 +306,7 @@
  *
  ****************************************************************************/
 
-uint8_t flash_area_align(const struct flash_area *fa);
+uint32_t flash_area_align(const struct flash_area *fa);
 
 /****************************************************************************
  * Name: flash_area_erased_val
diff --git a/boot/nuttx/src/flash_map_backend/flash_map_backend.c b/boot/nuttx/src/flash_map_backend/flash_map_backend.c
index b357ce8..fcf6bab 100644
--- a/boot/nuttx/src/flash_map_backend/flash_map_backend.c
+++ b/boot/nuttx/src/flash_map_backend/flash_map_backend.c
@@ -595,13 +595,13 @@
  *
  ****************************************************************************/
 
-uint8_t flash_area_align(const struct flash_area *fa)
+uint32_t flash_area_align(const struct flash_area *fa)
 {
   /* MTD access alignment is handled by the character and block device
    * drivers.
    */
 
-  const uint8_t minimum_write_length = 1;
+  const uint32_t minimum_write_length = 1;
 
   BOOT_LOG_INF("ID:%" PRIu8 " align:%" PRIu8,
                fa->fa_id, minimum_write_length);
diff --git a/docs/PORTING.md b/docs/PORTING.md
index d69a965..4804096 100644
--- a/docs/PORTING.md
+++ b/docs/PORTING.md
@@ -141,31 +141,31 @@
 
 ```c
 /*< Opens the area for use. id is one of the `fa_id`s */
-int     flash_area_open(uint8_t id, const struct flash_area **);
-void    flash_area_close(const struct flash_area *);
+int      flash_area_open(uint8_t id, const struct flash_area **);
+void     flash_area_close(const struct flash_area *);
 /*< Reads `len` bytes of flash memory at `off` to the buffer at `dst` */
-int     flash_area_read(const struct flash_area *, uint32_t off, void *dst,
-                     uint32_t len);
+int      flash_area_read(const struct flash_area *, uint32_t off, void *dst,
+                         uint32_t len);
 /*< Writes `len` bytes of flash memory at `off` from the buffer at `src` */
-int     flash_area_write(const struct flash_area *, uint32_t off,
-                     const void *src, uint32_t len);
+int      flash_area_write(const struct flash_area *, uint32_t off,
+                          const void *src, uint32_t len);
 /*< Erases `len` bytes of flash memory at `off` */
-int     flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len);
+int      flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len);
 /*< Returns this `flash_area`s alignment */
-uint8_t flash_area_align(const struct flash_area *);
+uint32_t flash_area_align(const struct flash_area *);
 /*< What is value is read from erased flash bytes. */
-uint8_t flash_area_erased_val(const struct flash_area *);
+uint8_t  flash_area_erased_val(const struct flash_area *);
 /*< Given flash area ID, return info about sectors within the area. */
-int     flash_area_get_sectors(int fa_id, uint32_t *count,
-                     struct flash_sector *sectors);
+int      flash_area_get_sectors(int fa_id, uint32_t *count,
+                                struct flash_sector *sectors);
 /*< Returns the `fa_id` for slot, where slot is 0 (primary) or 1 (secondary).
     `image_index` (0 or 1) is the index of the image. Image index is
     relevant only when multi-image support support is enabled */
-int     flash_area_id_from_multi_image_slot(int image_index, int slot);
+int      flash_area_id_from_multi_image_slot(int image_index, int slot);
 /*< Returns the slot (0 for primary or 1 for secondary), for the supplied
     `image_index` and `area_id`. `area_id` is unique and is represented by
     `fa_id` in the `flash_area` struct. */
-int     flash_area_id_to_multi_image_slot(int image_index, int area_id);
+int      flash_area_id_to_multi_image_slot(int image_index, int area_id);
 ```
 
 ---
diff --git a/sim/mcuboot-sys/csupport/run.c b/sim/mcuboot-sys/csupport/run.c
index a51ced9..6c61228 100644
--- a/sim/mcuboot-sys/csupport/run.c
+++ b/sim/mcuboot-sys/csupport/run.c
@@ -43,7 +43,7 @@
         uint32_t size);
 extern int sim_flash_write(uint8_t flash_id, uint32_t offset, const uint8_t *src,
         uint32_t size);
-extern uint16_t sim_flash_align(uint8_t flash_id);
+extern uint32_t sim_flash_align(uint8_t flash_id);
 extern uint8_t sim_flash_erased_val(uint8_t flash_id);
 
 struct sim_context {
@@ -222,7 +222,7 @@
 #endif
 }
 
-uint16_t flash_area_align(const struct flash_area *area)
+uint32_t flash_area_align(const struct flash_area *area)
 {
     return sim_flash_align(area->fa_device_id);
 }
diff --git a/sim/mcuboot-sys/csupport/storage/flash_map.h b/sim/mcuboot-sys/csupport/storage/flash_map.h
index 2a6fd56..f8388f5 100644
--- a/sim/mcuboot-sys/csupport/storage/flash_map.h
+++ b/sim/mcuboot-sys/csupport/storage/flash_map.h
@@ -123,7 +123,7 @@
 /*
  * Alignment restriction for flash writes.
  */
-uint16_t flash_area_align(const struct flash_area *);
+uint32_t flash_area_align(const struct flash_area *);
 
 /*
  * What is value is read from erased flash bytes.
diff --git a/sim/mcuboot-sys/src/api.rs b/sim/mcuboot-sys/src/api.rs
index fb55595..624b3e9 100644
--- a/sim/mcuboot-sys/src/api.rs
+++ b/sim/mcuboot-sys/src/api.rs
@@ -20,7 +20,7 @@
 pub type FlashMap = HashMap<u8, FlashPtr>;
 
 pub struct FlashParamsStruct {
-    align: u16,
+    align: u32,
     erased_val: u8,
 }
 
@@ -146,7 +146,7 @@
 pub fn set_flash(dev_id: u8, dev: &mut dyn Flash) {
     THREAD_CTX.with(|ctx| {
         ctx.borrow_mut().flash_params.insert(dev_id, FlashParamsStruct {
-            align: dev.align() as u16,
+            align: dev.align() as u32,
             erased_val: dev.erased_val(),
         });
         unsafe {
@@ -272,7 +272,7 @@
 }
 
 #[no_mangle]
-pub extern fn sim_flash_align(id: u8) -> u16 {
+pub extern fn sim_flash_align(id: u8) -> u32 {
     THREAD_CTX.with(|ctx| {
         ctx.borrow().flash_params.get(&id).unwrap().align
     })