Update how trailer is handled during a swap

Before this change, trailer was handled as part of the binary image,
which during a swap was just copied around together with the image.
This had issues if some fault happened while the trailer copy was
underway.

This patch changes how trailer is handled by making by non-copying.
The trailer is now updated step-by-step based on the current status.
Magic, copy_done and image_ok are also handled by writing them
individually, not by copying.

The trailer on scratch area was reduced to include at most swap state for
one sector, since it is only used temporarily while erasing the last
sector of the slot that stores the final trailer.

Many other small fixes were applied.
diff --git a/boot/bootutil/src/bootutil_priv.h b/boot/bootutil/src/bootutil_priv.h
index 3bdd1cc..6de8d4e 100644
--- a/boot/bootutil/src/bootutil_priv.h
+++ b/boot/bootutil/src/bootutil_priv.h
@@ -86,10 +86,12 @@
 #define BOOT_STATUS_SOURCE_SCRATCH 1
 #define BOOT_STATUS_SOURCE_SLOT0   2
 
+extern const uint32_t BOOT_MAGIC_SZ;
+
 int bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, int slen,
     uint8_t key_id);
 
-uint32_t boot_trailer_sz(uint8_t min_write_sz);
+uint32_t boot_slots_trailer_sz(uint8_t min_write_sz);
 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);
@@ -101,8 +103,6 @@
 int boot_write_copy_done(const struct flash_area *fap);
 int boot_write_image_ok(const struct flash_area *fap);
 
-uint32_t boot_status_sz(uint8_t min_write_sz);
-
 #ifdef __cplusplus
 }
 #endif