internal.c: Seperate out get_params() from internal_init()

Move all programmer parameter wrangling into its own
function.

Tested: `flashrom -p internal` on dooly DUT.

Change-Id: I66bb370eb0466c5c838621762a6ba825c44567d4
Original-Tested-by: Nikolai Artemiev <nartemiev@google.com>
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/61578
Original-Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72294
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/internal.c b/internal.c
index 9d2069d..fa45798 100644
--- a/internal.c
+++ b/internal.c
@@ -152,22 +152,21 @@
 
 enum chipbustype internal_buses_supported = BUS_NONE;
 
-static int internal_init(void)
+static int get_params(int *boardenable, int *boardmismatch,
+		int *force_laptop, int *not_a_laptop,
+		char **board_vendor, char **board_model)
 {
-	int ret = 0;
-	int force_laptop = 0;
-	int not_a_laptop = 0;
-	char *board_vendor = NULL;
-	char *board_model = NULL;
-#if defined(__i386__) || defined(__x86_64__)
-	const char *cb_vendor = NULL;
-	const char *cb_model = NULL;
-#endif
 	char *arg;
 
+	/* default values. */
+	*force_laptop = 0;
+	*not_a_laptop = 0;
+	*board_vendor = NULL;
+	*board_model = NULL;
+
 	arg = extract_programmer_param("boardenable");
 	if (arg && !strcmp(arg,"force")) {
-		force_boardenable = 1;
+		*boardenable = 1;
 	} else if (arg && !strlen(arg)) {
 		msg_perr("Missing argument for boardenable.\n");
 		free(arg);
@@ -181,7 +180,7 @@
 
 	arg = extract_programmer_param("boardmismatch");
 	if (arg && !strcmp(arg,"force")) {
-		force_boardmismatch = 1;
+		*boardmismatch = 1;
 	} else if (arg && !strlen(arg)) {
 		msg_perr("Missing argument for boardmismatch.\n");
 		free(arg);
@@ -195,9 +194,9 @@
 
 	arg = extract_programmer_param("laptop");
 	if (arg && !strcmp(arg, "force_I_want_a_brick"))
-		force_laptop = 1;
+		*force_laptop = 1;
 	else if (arg && !strcmp(arg, "this_is_not_a_laptop"))
-		not_a_laptop = 1;
+		*not_a_laptop = 1;
 	else if (arg && !strlen(arg)) {
 		msg_perr("Missing argument for laptop.\n");
 		free(arg);
@@ -211,7 +210,7 @@
 
 	arg = extract_programmer_param("mainboard");
 	if (arg && strlen(arg)) {
-		if (board_parse_parameter(arg, &board_vendor, &board_model)) {
+		if (board_parse_parameter(arg, board_vendor, board_model)) {
 			free(arg);
 			return 1;
 		}
@@ -222,6 +221,26 @@
 	}
 	free(arg);
 
+	return 0;
+}
+
+static int internal_init(void)
+{
+	int ret = 0;
+	int force_laptop;
+	int not_a_laptop;
+	char *board_vendor;
+	char *board_model;
+#if defined(__i386__) || defined(__x86_64__)
+	const char *cb_vendor = NULL;
+	const char *cb_model = NULL;
+#endif
+
+	ret = get_params(&force_boardenable, &force_boardmismatch,
+			 &force_laptop, &not_a_laptop,
+			 &board_vendor, &board_model);
+	if (ret)
+		return ret;
 
 	/* Unconditionally reset global state from previous operation. */
 	laptop_ok = false;