helpers: Handle "default layout" in flashprog_limit_chip()

This force-mode access to a partially accessible chip didn't fully
work anymore because of the "default layout" that is usually used.
Fix that by adapting the layout entry as well.

Change-Id: I5f965adaba1bfa10a4f37d7b5889d18e740ba861
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/556
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/helpers.c b/helpers.c
index 48b8b99..7e12c3e 100644
--- a/helpers.c
+++ b/helpers.c
@@ -20,6 +20,7 @@
 #include <string.h>
 
 #include "flash.h"
+#include "layout.h"
 #include "programmer.h"
 
 /* Check if raw data is all 0 or all 1. */
@@ -74,6 +75,13 @@
 	if (chip_size <= limit)
 		return 0;
 
+	const struct flashprog_layout *const layout = get_default_layout(flash);
+	if (layout) {
+		struct romentry *const entry = (struct romentry *)layout_next(layout, NULL);
+		if (entry)
+			entry->end = limit - 1;
+	}
+
 	/* Undefine all block_erasers that don't operate on the whole chip,
 	   and adjust the eraseblock size of those which do. */
 	for (i = 0; i < NUM_ERASEFUNCTIONS; ++i) {