[flashrom] [commit] r1021 - trunk

repository service svn at flashrom.org
Mon May 31 00:24:41 CEST 2010


Author: hailfinger
Date: Mon May 31 00:24:40 2010
New Revision: 1021
URL: http://flashrom.org/trac/coreboot/changeset/1021

Log:
Remove unneeded #include statements completely.

unistd.h was only used to get a definition of NULL in all files. Add our
own NULL #define and remove unistd.h from flash.h
stdio.h has no place in flash.h, it should be included only in files
which really need it.
Add #include statements in individual .c files where needed.

Replace a few printf with msg_* to eliminate the need for stdio.h.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
Acked-by: Uwe Hermann <uwe at hermann-uwe.de>

Modified:
   trunk/82802ab.c
   trunk/board_enable.c
   trunk/cbtable.c
   trunk/chipset_enable.c
   trunk/cli_classic.c
   trunk/dediprog.c
   trunk/drkaiser.c
   trunk/flash.h
   trunk/flashrom.c
   trunk/hwaccess.c
   trunk/layout.c
   trunk/nic3com.c
   trunk/nicrealtek.c
   trunk/physmap.c
   trunk/print.c
   trunk/programmer.c
   trunk/satasii.c
   trunk/sb600spi.c
   trunk/sharplhf00l04.c
   trunk/spi.c
   trunk/sst49lfxxxc.c
   trunk/sst_fwhub.c
   trunk/stm50flw0x0x.c
   trunk/udelay.c
   trunk/wbsio_spi.c

Modified: trunk/82802ab.c
==============================================================================
--- trunk/82802ab.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/82802ab.c	Mon May 31 00:24:40 2010	(r1021)
@@ -26,8 +26,6 @@
  *  - Order number: 290658-004
  */
 
-#include <string.h>
-#include <stdlib.h>
 #include "flash.h"
 #include "chipdrivers.h"
 

Modified: trunk/board_enable.c
==============================================================================
--- trunk/board_enable.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/board_enable.c	Mon May 31 00:24:40 2010	(r1021)
@@ -25,7 +25,6 @@
  */
 
 #include <string.h>
-#include <fcntl.h>
 #include "flash.h"
 
 #if defined(__i386__) || defined(__x86_64__)
@@ -107,8 +106,8 @@
 	OUTB(0x55, port);	/* enter conf mode */
 	id = sio_read(port, 0x20);
 	if (id != 0x44) {
-		fprintf(stderr, "\nERROR: %s: FDC37B787: Wrong ID 0x%02X.\n",
-		        name, id);
+		msg_perr("\nERROR: %s: FDC37B787: Wrong ID 0x%02X.\n",
+			 name, id);
 		OUTB(0xAA, port); /* leave conf mode */
 		return -1;
 	}
@@ -118,8 +117,8 @@
 	val = sio_read(port, 0xC8);	/* GP50 */
 	if ((val & 0x1B) != 0x10)	/* output, no invert, GPIO */
 	{
-		fprintf(stderr, "\nERROR: %s: GPIO50 mode 0x%02X unexpected.\n",
-		        name, val);
+		msg_perr("\nERROR: %s: GPIO50 mode 0x%02X unexpected.\n",
+			 name, val);
 		OUTB(0xAA, port);
 		return -1;
 	}

Modified: trunk/cbtable.c
==============================================================================
--- trunk/cbtable.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/cbtable.c	Mon May 31 00:24:40 2010	(r1021)
@@ -22,6 +22,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <unistd.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <string.h>

Modified: trunk/chipset_enable.c
==============================================================================
--- trunk/chipset_enable.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/chipset_enable.c	Mon May 31 00:24:40 2010	(r1021)
@@ -27,6 +27,7 @@
 
 #define _LARGEFILE64_SOURCE
 
+#include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>

Modified: trunk/cli_classic.c
==============================================================================
--- trunk/cli_classic.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/cli_classic.c	Mon May 31 00:24:40 2010	(r1021)
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <stdio.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>

Modified: trunk/dediprog.c
==============================================================================
--- trunk/dediprog.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/dediprog.c	Mon May 31 00:24:40 2010	(r1021)
@@ -18,9 +18,6 @@
  */
 
 #include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <sys/types.h>
 #include <usb.h>
 #include "flash.h"
 #include "chipdrivers.h"

Modified: trunk/drkaiser.c
==============================================================================
--- trunk/drkaiser.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/drkaiser.c	Mon May 31 00:24:40 2010	(r1021)
@@ -19,8 +19,6 @@
  */
 
 #include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
 #include "flash.h"
 
 #define PCI_VENDOR_ID_DRKAISER		0x1803

Modified: trunk/flash.h
==============================================================================
--- trunk/flash.h	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/flash.h	Mon May 31 00:24:40 2010	(r1021)
@@ -24,9 +24,7 @@
 #ifndef __FLASH_H__
 #define __FLASH_H__ 1
 
-#include <unistd.h>
 #include <stdint.h>
-#include <stdio.h>
 #include "hwaccess.h"
 #ifdef _WIN32
 #include <windows.h>
@@ -34,6 +32,10 @@
 #undef max
 #endif
 
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
 typedef unsigned long chipaddr;
 
 enum programmer {
@@ -556,7 +558,6 @@
 extern int verbose;
 extern const char *flashrom_version;
 extern char *chip_to_probe;
-#define printf_debug(x...) { if (verbose) printf(x); }
 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);

Modified: trunk/flashrom.c
==============================================================================
--- trunk/flashrom.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/flashrom.c	Mon May 31 00:24:40 2010	(r1021)
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <stdio.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>

Modified: trunk/hwaccess.c
==============================================================================
--- trunk/hwaccess.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/hwaccess.c	Mon May 31 00:24:40 2010	(r1021)
@@ -21,6 +21,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <errno.h>

Modified: trunk/layout.c
==============================================================================
--- trunk/layout.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/layout.c	Mon May 31 00:24:40 2010	(r1021)
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
@@ -73,7 +74,7 @@
 	mb_vendor_offset = *(walk - 2);
 	if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || (*walk) > size ||
 	    mb_part_offset > size || mb_vendor_offset > size) {
-		printf("Flash image seems to be a legacy BIOS. Disabling checks.\n");
+		msg_pinfo("Flash image seems to be a legacy BIOS. Disabling checks.\n");
 		return 0;
 	}
 
@@ -81,25 +82,25 @@
 	mb_vendor = (char *)(bios + size - mb_vendor_offset);
 	if (!isprint((unsigned char)*mb_part) ||
 	    !isprint((unsigned char)*mb_vendor)) {
-		printf("Flash image seems to have garbage in the ID location."
+		msg_pinfo("Flash image seems to have garbage in the ID location."
 		       " Disabling checks.\n");
 		return 0;
 	}
 
-	printf_debug("coreboot last image size "
+	msg_pdbg("coreboot last image size "
 		     "(not ROM size) is %d bytes.\n", *walk);
 
 	mainboard_part = strdup(mb_part);
 	mainboard_vendor = strdup(mb_vendor);
-	printf_debug("Manufacturer: %s\n", mainboard_vendor);
-	printf_debug("Mainboard ID: %s\n", mainboard_part);
+	msg_pdbg("Manufacturer: %s\n", mainboard_vendor);
+	msg_pdbg("Mainboard ID: %s\n", mainboard_part);
 
 	/*
 	 * If lb_vendor is not set, the coreboot table was
 	 * not found. Nor was -m VENDOR:PART specified.
 	 */
 	if (!lb_vendor || !lb_part) {
-		printf("Note: If the following flash access fails, "
+		msg_pinfo("Note: If the following flash access fails, "
 		       "try -m <vendor>:<mainboard>.\n");
 		return 0;
 	}
@@ -109,13 +110,13 @@
 	 */
 	if (!strcasecmp(mainboard_vendor, lb_vendor) &&
 	    !strcasecmp(mainboard_part, lb_part)) {
-		printf_debug("This firmware image matches this mainboard.\n");
+		msg_pdbg("This firmware image matches this mainboard.\n");
 	} else {
 		if (force_boardmismatch) {
-			printf("WARNING: This firmware image does not "
+			msg_pinfo("WARNING: This firmware image does not "
 			       "seem to fit to this machine - forcing it.\n");
 		} else {
-			printf("ERROR: Your firmware image (%s:%s) does not "
+			msg_pinfo("ERROR: Your firmware image (%s:%s) does not "
 			       "appear to\n       be correct for the detected "
 			       "mainboard (%s:%s)\n\nOverride with -p internal:"
 			       "boardmismatch=force if you are absolutely sure "
@@ -141,7 +142,7 @@
 	romlayout = fopen(name, "r");
 
 	if (!romlayout) {
-		fprintf(stderr, "ERROR: Could not open ROM layout (%s).\n",
+		msg_gerr("ERROR: Could not open ROM layout (%s).\n",
 			name);
 		return -1;
 	}
@@ -159,7 +160,7 @@
 		tstr1 = strtok(tempstr, ":");
 		tstr2 = strtok(NULL, ":");
 		if (!tstr1 || !tstr2) {
-			fprintf(stderr, "Error parsing layout file.\n");
+			msg_gerr("Error parsing layout file.\n");
 			fclose(romlayout);
 			return 1;
 		}
@@ -170,7 +171,7 @@
 	}
 
 	for (i = 0; i < romimages; i++) {
-		printf_debug("romlayout %08x - %08x named %s\n",
+		msg_gdbg("romlayout %08x - %08x named %s\n",
 			     rom_entries[i].start,
 			     rom_entries[i].end, rom_entries[i].name);
 	}
@@ -187,16 +188,16 @@
 	if (!romimages)
 		return -1;
 
-	printf("Looking for \"%s\"... ", name);
+	msg_ginfo("Looking for \"%s\"... ", name);
 
 	for (i = 0; i < romimages; i++) {
 		if (!strcmp(rom_entries[i].name, name)) {
 			rom_entries[i].included = 1;
-			printf("found.\n");
+			msg_ginfo("found.\n");
 			return i;
 		}
 	}
-	printf("not found.\n");	// Not found. Error.
+	msg_ginfo("not found.\n");	// Not found. Error.
 
 	return -1;
 }

Modified: trunk/nic3com.c
==============================================================================
--- trunk/nic3com.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/nic3com.c	Mon May 31 00:24:40 2010	(r1021)
@@ -21,8 +21,6 @@
 #if defined(__i386__) || defined(__x86_64__)
 
 #include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
 #include "flash.h"
 
 #define BIOS_ROM_ADDR		0x04

Modified: trunk/nicrealtek.c
==============================================================================
--- trunk/nicrealtek.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/nicrealtek.c	Mon May 31 00:24:40 2010	(r1021)
@@ -21,8 +21,6 @@
 #if defined(__i386__) || defined(__x86_64__)
 
 #include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
 #include "flash.h"
 
 #define PCI_VENDOR_ID_REALTEK	0x10ec

Modified: trunk/physmap.c
==============================================================================
--- trunk/physmap.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/physmap.c	Mon May 31 00:24:40 2010	(r1021)
@@ -20,6 +20,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <unistd.h>
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -310,8 +312,8 @@
 int setup_cpu_msr(int cpu)
 {
 	char msrfilename[64];
-	memset(msrfilename, 0, 64);
-	sprintf(msrfilename, "/dev/cpu/%d/msr", cpu);
+	memset(msrfilename, 0, sizeof(msrfilename));
+	snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu/%d/msr", cpu);
 
 	if (fd_msr != -1) {
 		msg_pinfo("MSR was already initialized\n");
@@ -393,8 +395,8 @@
 int setup_cpu_msr(int cpu)
 {
 	char msrfilename[64];
-	memset(msrfilename, 0, 64);
-	sprintf(msrfilename, "/dev/cpu%d", cpu);
+	memset(msrfilename, 0, sizeof(msrfilename));
+	snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu%d", cpu);
 
 	if (fd_msr != -1) {
 		msg_pinfo("MSR was already initialized\n");

Modified: trunk/print.c
==============================================================================
--- trunk/print.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/print.c	Mon May 31 00:24:40 2010	(r1021)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include "flash.h"

Modified: trunk/programmer.c
==============================================================================
--- trunk/programmer.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/programmer.c	Mon May 31 00:24:40 2010	(r1021)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdlib.h>
 #include "flash.h"
 
 /* No-op shutdown() for programmers which don't need special handling */

Modified: trunk/satasii.c
==============================================================================
--- trunk/satasii.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/satasii.c	Mon May 31 00:24:40 2010	(r1021)
@@ -21,7 +21,6 @@
 /* Datasheets can be found on http://www.siliconimage.com. Great thanks! */
 
 #include <stdlib.h>
-#include <string.h>
 #include "flash.h"
 
 #define PCI_VENDOR_ID_SII	0x1095

Modified: trunk/sb600spi.c
==============================================================================
--- trunk/sb600spi.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/sb600spi.c	Mon May 31 00:24:40 2010	(r1021)
@@ -23,7 +23,6 @@
 
 #if defined(__i386__) || defined(__x86_64__)
 
-#include <string.h>
 #include "flash.h"
 #include "chipdrivers.h"
 #include "spi.h"

Modified: trunk/sharplhf00l04.c
==============================================================================
--- trunk/sharplhf00l04.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/sharplhf00l04.c	Mon May 31 00:24:40 2010	(r1021)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdlib.h>
 #include "flash.h"
 #include "chipdrivers.h"
 

Modified: trunk/spi.c
==============================================================================
--- trunk/spi.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/spi.c	Mon May 31 00:24:40 2010	(r1021)
@@ -22,7 +22,6 @@
  * Contains the generic SPI framework
  */
 
-#include <string.h>
 #include "flash.h"
 #include "flashchips.h"
 #include "chipdrivers.h"

Modified: trunk/sst49lfxxxc.c
==============================================================================
--- trunk/sst49lfxxxc.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/sst49lfxxxc.c	Mon May 31 00:24:40 2010	(r1021)
@@ -20,7 +20,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdlib.h>
 #include "flash.h"
 #include "chipdrivers.h"
 

Modified: trunk/sst_fwhub.c
==============================================================================
--- trunk/sst_fwhub.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/sst_fwhub.c	Mon May 31 00:24:40 2010	(r1021)
@@ -22,8 +22,6 @@
 
 /* Adapted from the Intel FW hub stuff for 82802ax parts. */
 
-#include <stdlib.h>
-#include <string.h>
 #include "flash.h"
 #include "chipdrivers.h"
 

Modified: trunk/stm50flw0x0x.c
==============================================================================
--- trunk/stm50flw0x0x.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/stm50flw0x0x.c	Mon May 31 00:24:40 2010	(r1021)
@@ -27,8 +27,6 @@
  * ST M50FLW080B (not yet tested)
  */
 
-#include <string.h>
-#include <stdlib.h>
 #include "flash.h"
 #include "flashchips.h"
 #include "chipdrivers.h"

Modified: trunk/udelay.c
==============================================================================
--- trunk/udelay.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/udelay.c	Mon May 31 00:24:40 2010	(r1021)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <unistd.h>
 #include <sys/time.h>
 #include <stdlib.h>
 #include <limits.h>
@@ -63,7 +64,7 @@
 	unsigned long timeusec;
 	int i, tries = 0;
 
-	printf("Calibrating delay loop... ");
+	msg_pinfo("Calibrating delay loop... ");
 
 recalibrate:
 	count = 1000;
@@ -113,7 +114,7 @@
 	timeusec = measure_delay(10000);
 	msg_pdbg("10000 myus = %ld us, ", timeusec);
 
-	printf("OK.\n");
+	msg_pinfo("OK.\n");
 }
 
 void internal_delay(int usecs)

Modified: trunk/wbsio_spi.c
==============================================================================
--- trunk/wbsio_spi.c	Sun May 30 19:50:16 2010	(r1020)
+++ trunk/wbsio_spi.c	Mon May 31 00:24:40 2010	(r1021)
@@ -20,7 +20,6 @@
 
 #if defined(__i386__) || defined(__x86_64__)
 
-#include <string.h>
 #include "flash.h"
 #include "chipdrivers.h"
 #include "spi.h"




More information about the flashrom mailing list