Rework internal bus handling and laptop bail-out

We used to bail out on any unknown laptop. However, modern systems with
SPI flashes don't suffer from the original problem. Even if a flash chip
is shared with the EC, the latter has to expect the host to send regular
JEDEC SPI commands any time.

So instead of bailing out, we limit the set of buses to probe. If we
suspect to be running on a laptop, we only allow probing of SPI and
opaque programmers. The user can still use the existing force options
to probe all buses.

This will obsolete some board-enables that could be moved to `print.c`
in follow-up commits.

Change-Id: I1dbda8cf0c10d7786106f14f0d18c3dcce35f0a3
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/28716
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Thomas Heijligen <src@posteo.de>
diff --git a/internal.c b/internal.c
index 1d6cff6..2bb437c 100644
--- a/internal.c
+++ b/internal.c
@@ -257,6 +257,8 @@
 #endif
 
 #if IS_X86
+	is_laptop = 2; /* Assume that we don't know by default. */
+
 	dmi_init();
 
 	/* In case Super I/O probing would cause pretty explosions. */
@@ -275,36 +277,13 @@
 	/* Check laptop whitelist. */
 	board_handle_before_laptop();
 
-	/* Warn if a non-whitelisted laptop is detected. */
-	if (is_laptop && !laptop_ok) {
-		msg_perr("========================================================================\n");
-		if (is_laptop == 1) {
-			msg_perr("WARNING! You seem to be running flashrom on an unsupported laptop.\n");
-		} else {
-			msg_perr("WARNING! You may be running flashrom on an unsupported laptop. We could\n"
-				 "not detect this for sure because your vendor has not setup the SMBIOS\n"
-				 "tables correctly. You can enforce execution by adding\n"
-				 "'-p internal:laptop=this_is_not_a_laptop' to the command line, but\n"
-				 "please read the following warning if you are not sure.\n\n");
-		}
-		msg_perr("Laptops, notebooks and netbooks are difficult to support and we\n"
-			 "recommend to use the vendor flashing utility. The embedded controller\n"
-			 "(EC) in these machines often interacts badly with flashing.\n"
-			 "See the manpage and https://flashrom.org/Laptops for details.\n\n"
-			 "If flash is shared with the EC, erase is guaranteed to brick your laptop\n"
-			 "and write may brick your laptop.\n"
-			 "Read and probe may irritate your EC and cause fan failure, backlight\n"
-			 "failure and sudden poweroff.\n"
-			 "You have been warned.\n"
-			 "========================================================================\n");
-
-		if (force_laptop || (not_a_laptop && (is_laptop == 2))) {
-			msg_perr("Proceeding anyway because user forced us to.\n");
-		} else {
-			msg_perr("Aborting.\n");
-			return 1;
-		}
-	}
+	/*
+	 * Disable all internal buses by default if we are not sure
+	 * this isn't a laptop. Board-enables may override this,
+	 * non-legacy buses (SPI and opaque atm) are probed anyway.
+	 */
+	if (is_laptop && !(laptop_ok || force_laptop || (not_a_laptop && is_laptop == 2)))
+		internal_buses_supported = BUS_NONE;
 
 	/* try to enable it. Failure IS an option, since not all motherboards
 	 * really need this to be done, etc., etc.
@@ -327,7 +306,36 @@
 	}
 #endif
 
-	register_par_master(&par_master_internal, internal_buses_supported);
+	if (internal_buses_supported & BUS_NONSPI)
+		register_par_master(&par_master_internal, internal_buses_supported);
+
+	/* Report if a non-whitelisted laptop is detected that likely uses a legacy bus. */
+	if (is_laptop && !laptop_ok) {
+		msg_pinfo("========================================================================\n");
+		if (is_laptop == 1) {
+			msg_pinfo("You seem to be running flashrom on an unknown laptop. Some\n"
+				  "internal buses have been disabled for safety reasons.\n\n");
+		} else {
+			msg_pinfo("You may be running flashrom on an unknown laptop. We could not\n"
+				  "detect this for sure because your vendor has not set up the SMBIOS\n"
+				  "tables correctly. Some internal buses have been disabled for\n"
+				  "safety reasons. You can enforce using all buses by adding\n"
+				  "  -p internal:laptop=this_is_not_a_laptop\n"
+				  "to the command line, but please read the following warning if you\n"
+				  "are not sure.\n\n");
+		}
+		msg_perr("Laptops, notebooks and netbooks are difficult to support and we\n"
+			 "recommend to use the vendor flashing utility. The embedded controller\n"
+			 "(EC) in these machines often interacts badly with flashing.\n"
+			 "See the manpage and https://flashrom.org/Laptops for details.\n\n"
+			 "If flash is shared with the EC, erase is guaranteed to brick your laptop\n"
+			 "and write may brick your laptop.\n"
+			 "Read and probe may irritate your EC and cause fan failure, backlight\n"
+			 "failure and sudden poweroff.\n"
+			 "You have been warned.\n"
+			 "========================================================================\n");
+	}
+
 	return 0;
 }