Make flash-size limiting of atapromise a general --force feature

To allow accessing at least part of flash chips behind this size-limited
controller,  the `atapromise' driver used a local function that adjusted
a chip description.  As flashprog would have bailed out earlier already,
this was only ever usable with the `--force' flag.

The same adjustment can be used with other programmers. Making it a glo-
bal feature also gets rid of a driver peculiarity and removes the depen-
dency on `flashctx` in the `atapromise' driver.

The logic enforces a complete chip erase if any erase is necessary. So,
while this should make part of the chip fully read/writable, content of
the inaccessible area will be lost on write.

Change-Id: I6bce8ff7781f683b001f76154621f22bd03687bc
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/431
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/cli_classic.c b/cli_classic.c
index 2593f62..4ed820f 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -170,14 +170,23 @@
 }
 
 /* Returns true if the flash chip cannot be completely accessed due to size/address limits of the programmer. */
-static bool max_decode_exceeded(const struct flashctx *const flash)
+static bool max_decode_exceeded(const struct flashctx *const flash, const bool force)
 {
 	if (flashprog_flash_getsize(flash) <= flash->mst.common->max_rom_decode)
 		return false;
 
 	msg_pdbg("Chip size %u kB is bigger than supported size %zu kB of\n"
-		 "chipset/board/programmer for memory-mapped interface, probe/read/erase/write\n"
-		 "may fail.\n", flash->chip->total_size, flash->mst.common->max_rom_decode / KiB);
+		 "chipset/board/programmer for memory-mapped interface.\n",
+		 flash->chip->total_size, flash->mst.common->max_rom_decode / KiB);
+
+	if (!force) {
+		msg_cerr("This flash chip is too big for this programmer (--verbose/-V gives details).\n"
+			 "Use --force/-f to override at your own risk. Any write may erase the whole\n"
+			 "chip and leave the unwritten area in erased state! You have been warned.\n");
+	} else {
+		msg_cwarn("This flash chip is too big for this programmer. Any write may erase the whole\n"
+			  "chip and leave the unwritten area in erased state!\n");
+	}
 	return true;
 }
 
@@ -529,11 +538,11 @@
 
 	print_chip_support_status(fill_flash->chip);
 
-	if (max_decode_exceeded(fill_flash) && !force) {
-		msg_cerr("This flash chip is too big for this programmer (--verbose/-V gives details).\n"
-			 "Use --force/-f to override at your own risk.\n");
-		ret = 1;
-		goto out_shutdown;
+	if (max_decode_exceeded(fill_flash, force)) {
+		if (!force || flashprog_limit_chip(fill_flash)) {
+			ret = 1;
+			goto out_shutdown;
+		}
 	}
 
 	if (!(read_it | write_it | verify_it | erase_it | flash_name | flash_size)) {