>From 30477d7de1d8e2bdee5aa8e51bedcf2f37eae244 Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Tue, 16 Aug 2011 23:23:33 +0300
Subject: [carFl mem 12/21] Move globals to new struct

Move verbose, chip_to_probe variables to our dedicated struct.

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>
---
 cli_classic.c |   16 ++++++++--------
 cli_output.c  |    6 +++---
 flash.h       |    5 ++---
 flashrom.c    |    6 +++---
 w29ee011.c    |    2 +-
 5 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/cli_classic.c b/cli_classic.c
index 2f3aa8e..9a247e6 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -199,10 +199,10 @@ int cli_classic(int argc, char *argv[])
 			dont_verify_it = 1;
 			break;
 		case 'c':
-			chip_to_probe = strdup(optarg);
+			g->chip_to_probe = strdup(optarg);
 			break;
 		case 'V':
-			verbose++;
+			g->verbose++;
 			break;
 		case 'E':
 			if (++operation_specified > 1) {
@@ -346,13 +346,13 @@ int cli_classic(int argc, char *argv[])
 	}
 #endif
 
-	if (chip_to_probe) {
+	if (g->chip_to_probe) {
 		for (flash = flashchips; flash && flash->name; flash++)
-			if (!strcmp(flash->name, chip_to_probe))
+			if (!strcmp(flash->name, g->chip_to_probe))
 				break;
 		if (!flash || !flash->name) {
 			fprintf(stderr, "Error: Unknown chip '%s' specified.\n",
-				chip_to_probe);
+				g->chip_to_probe);
 			printf("Run flashrom -L to view the hardware supported "
 			       "in this flashrom version.\n");
 			exit(1);
@@ -389,17 +389,17 @@ int cli_classic(int argc, char *argv[])
 		goto out_shutdown;
 	} else if (!chipcount) {
 		printf("No EEPROM/flash device found.\n");
-		if (!force || !chip_to_probe) {
+		if (!force || !g->chip_to_probe) {
 			printf("Note: flashrom can never write if the flash "
 			       "chip isn't found automatically.\n");
 		}
-		if (force && read_it && chip_to_probe) {
+		if (force && read_it && g->chip_to_probe) {
 			printf("Force read (-f -r -c) requested, pretending "
 			       "the chip is there:\n");
 			startchip = probe_flash(0, &flashes[0], 1);
 			if (startchip == -1) {
 				printf("Probing for flash chip '%s' failed.\n",
-				       chip_to_probe);
+				       g->chip_to_probe);
 				ret = 1;
 				goto out_shutdown;
 			}
diff --git a/cli_output.c b/cli_output.c
index 65bd33d..3c86aad 100644
--- a/cli_output.c
+++ b/cli_output.c
@@ -40,13 +40,13 @@ int print(int type, const char *fmt, ...)
 		output_type = stderr;
 		break;
 	case MSG_BARF:
-		if (verbose < 3)
+		if (g->verbose < 3)
 			return 0;
 	case MSG_DEBUG2:
-		if (verbose < 2)
+		if (g->verbose < 2)
 			return 0;
 	case MSG_DEBUG:
-		if (verbose < 1)
+		if (g->verbose < 1)
 			return 0;
 	case MSG_INFO:
 	default:
diff --git a/flash.h b/flash.h
index a2521a5..e3119f7 100644
--- a/flash.h
+++ b/flash.h
@@ -206,9 +206,7 @@ enum write_granularity {
 	write_gran_256bytes,
 };
 extern enum chipbustype buses_supported;
-extern int verbose;
 extern const char flashrom_version[];
-extern char *chip_to_probe;
 void map_flash_registers(struct flashchip *flash);
 int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
 int erase_flash(struct flashchip *flash);
@@ -280,7 +278,8 @@ int spi_send_multicommand(struct spi_command *cmds);
 uint32_t spi_get_valid_read_addr(void);
 
 struct globals {
-
+	int verbose;
+	char *chip_to_probe;
 };
 globals *get_globals(void);
 
diff --git a/flashrom.c b/flashrom.c
index 5504d01..6b832d4 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -39,8 +39,6 @@
 #include "programmer.h"
 
 const char flashrom_version[] = "carFl";
-char *chip_to_probe = NULL;
-int verbose = 0;
 
 static globals g;
 
@@ -93,6 +91,8 @@ static void sync_all_globals(void)
 
 static void init_globals(void)
 {
+	g.verbose = 0;
+	g.chip_to_probe = NULL;
 	sync_all_globals();
 }
 
@@ -1182,7 +1182,7 @@ int probe_flash(int startchip, struct flashchip *fill_flash, int force)
 	char *tmp;
 
 	for (flash = flashchips + startchip; flash && flash->name; flash++) {
-		if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0)
+		if (g.chip_to_probe && strcmp(flash->name, g.chip_to_probe) != 0)
 			continue;
 		buses_common = buses_supported & flash->bustype;
 		if (!buses_common) {
diff --git a/w29ee011.c b/w29ee011.c
index e5a0707..42c69f1 100644
--- a/w29ee011.c
+++ b/w29ee011.c
@@ -37,7 +37,7 @@ int probe_w29ee011(struct flashchip *flash)
 	chipaddr bios = flash->virtual_memory;
 	uint8_t id1, id2;
 
-	if (!chip_to_probe || strcmp(chip_to_probe, flash->name)) {
+	if (!g->chip_to_probe || strcmp(g->chip_to_probe, flash->name)) {
 		msg_cdbg("Old Winbond W29* probe method disabled because "
 			 "the probing sequence puts the AMIC A49LF040A in "
 			 "a funky state. Use 'flashrom -c %s' if you "
-- 
1.7.6

