Add config for BOOT_MAX_IMG_SECTORS

This still defaults to 128 for compatibility, but allows users to
specify less elements to save space, or more elements for devices that
have massive flash size and/or too small sectors.

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index 82e17c5..e2762bd 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -337,14 +337,22 @@
     size_t size_0, size_1;
     size_t i;
 
-    /* Ensure both image slots have identical sector layouts. */
-    if (num_sectors_0 != num_sectors_1) {
+    if (num_sectors_0 > BOOT_MAX_IMG_SECTORS || num_sectors_1 > BOOT_MAX_IMG_SECTORS) {
+        BOOT_LOG_WRN("Cannot upgrade: more sectors than allowed");
         return 0;
     }
+
+    /* Ensure both image slots have identical sector layouts. */
+    if (num_sectors_0 != num_sectors_1) {
+        BOOT_LOG_WRN("Cannot upgrade: number of sectors differ between slots");
+        return 0;
+    }
+
     for (i = 0; i < num_sectors_0; i++) {
         size_0 = boot_img_sector_size(&boot_data, 0, i);
         size_1 = boot_img_sector_size(&boot_data, 1, i);
         if (size_0 != size_1) {
+            BOOT_LOG_WRN("Cannot upgrade: an incompatible sector was found");
             return 0;
         }
     }
@@ -1336,6 +1344,8 @@
     /* Determine the sector layout of the image slots and scratch area. */
     rc = boot_read_sectors();
     if (rc != 0) {
+        BOOT_LOG_WRN("Failed reading sectors; BOOT_MAX_IMG_SECTORS=%d - too small?",
+                BOOT_MAX_IMG_SECTORS);
         goto out;
     }