bootutil tests - Don't assume min-write-sz==1.
diff --git a/boot/bootutil/test/src/boot_test.h b/boot/bootutil/test/src/boot_test.h
index b10bec6..072dfbb 100644
--- a/boot/bootutil/test/src/boot_test.h
+++ b/boot/bootutil/test/src/boot_test.h
@@ -59,6 +59,7 @@
#define BOOT_TEST_AREA_IDX_SCRATCH 6
uint8_t boot_test_util_byte_at(int img_msb, uint32_t image_offset);
+uint8_t boot_test_util_flash_align(void);
void boot_test_util_init_flash(void);
void boot_test_util_copy_area(int from_area_idx, int to_area_idx);
void boot_test_util_swap_areas(int area_idx1, int area_idx2);
diff --git a/boot/bootutil/test/src/boot_test_utils.c b/boot/bootutil/test/src/boot_test_utils.c
index d882101..dc6fbb0 100644
--- a/boot/bootutil/test/src/boot_test_utils.c
+++ b/boot/bootutil/test/src/boot_test_utils.c
@@ -56,6 +56,17 @@
return u8p[image_offset % 4];
}
+uint8_t
+boot_test_util_flash_align(void)
+{
+ const struct flash_area *fap;
+ int rc;
+
+ rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ return flash_area_align(fap);
+}
void
boot_test_util_init_flash(void)
@@ -113,6 +124,7 @@
const struct flash_area *desc;
int64_t diff;
uint32_t trailer_start;
+ uint8_t elem_sz;
if (dst_idx != BOOT_TEST_AREA_IDX_SCRATCH - 1) {
return size;
@@ -120,7 +132,8 @@
/* Don't include trailer in copy to second slot. */
desc = boot_test_area_descs + dst_idx;
- trailer_start = desc->fa_size - boot_trailer_sz(1);
+ elem_sz = boot_test_util_flash_align();
+ trailer_start = desc->fa_size - boot_trailer_sz(elem_sz);
diff = off + size - trailer_start;
if (diff > 0) {
if (diff > size) {
@@ -255,10 +268,10 @@
tlv._pad = 0;
tlv.it_len = sizeof(hash);
- rc = hal_flash_write(flash_id, addr + off, &tlv, sizeof(tlv));
- TEST_ASSERT(rc == 0);
- off += sizeof(tlv);
- rc = hal_flash_write(flash_id, addr + off, hash, sizeof(hash));
+ memcpy(tmpdata, &tlv, sizeof tlv);
+ memcpy(tmpdata + sizeof tlv, hash, sizeof hash);
+ rc = hal_flash_write(flash_id, addr + off, tmpdata,
+ sizeof tlv + sizeof hash);
TEST_ASSERT(rc == 0);
}