[flashrom] [PATCH 1/2] Various fixes for building as a payload.

Tadas Slotkus devtadas at gmail.com
Sun Jun 12 06:02:22 CEST 2011


Signed-off-by: Tadas Slotkus <devtadas at gmail.com>
---
 Makefile      |    7 ++++++-
 cli_classic.c |    6 +++++-
 flash.h       |    6 +++++-
 flashrom.c    |    6 ++++++
 layout.c      |    6 ++++--
 nicintel.c    |    2 ++
 sst49lfxxxc.c |    3 +--
 7 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 6e6e2de..fbfbd2f 100644
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,9 @@ ifeq ($(WARNERROR), yes)
 CFLAGS += -Werror
 endif
 
+# Uncomment this if you want to build for libpayload
+# OS_ARCH = libpayload
+
 # FIXME We have to differentiate between host and target arch.
 OS_ARCH	?= $(shell uname)
 ifneq ($(OS_ARCH), SunOS)
@@ -85,7 +88,7 @@ endif
 endif
 
 ifeq ($(OS_ARCH), libpayload)
-CC:=CC=i386-elf-gcc lpgcc
+CC:=../libpayload/install/libpayload/bin/lpgcc
 AR:=i386-elf-ar
 RANLIB:=i386-elf-ranlib
 CPPFLAGS += -DSTANDALONE
@@ -361,7 +364,9 @@ ifeq ($(OS_ARCH), DOS)
 # FIXME There needs to be a better way to do this
 LIBS += ../libpci/lib/libpci.a
 else
+ifneq ($(OS_ARCH), libpayload)
 LIBS += -lpci
+endif
 ifeq ($(OS_ARCH), OpenBSD)
 # For (i386|amd64)_iopl(2).
 LIBS += -l$(shell uname -m)
diff --git a/cli_classic.c b/cli_classic.c
index d1b4686..f102433 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -22,8 +22,10 @@
  */
 
 #include <stdio.h>
+#ifndef __LIBPAYLOAD__
 #include <fcntl.h>
 #include <sys/stat.h>
+#endif
 #include <string.h>
 #include <stdlib.h>
 #include <getopt.h>
@@ -150,12 +152,14 @@ int cli_classic(int argc, char *argv[])
 	if (selfcheck())
 		exit(1);
 
+#ifndef __LIBPAYLOAD__
 	setbuf(stdout, NULL);
+#endif
 	/* FIXME: Delay all operation_specified checks until after command
 	 * line parsing to allow --help overriding everything else.
 	 */
 	while ((opt = getopt_long(argc, argv, optstring,
-				  long_options, &option_index)) != EOF) {
+				  long_options, &option_index)) != -1) {
 		switch (opt) {
 		case 'r':
 			if (++operation_specified > 1) {
diff --git a/flash.h b/flash.h
index 3247700..2d7457e 100644
--- a/flash.h
+++ b/flash.h
@@ -32,7 +32,11 @@
 #undef min
 #undef max
 #endif
-
+#ifdef __LIBPAYLOAD__
+#undef __linux__
+#define fprintf(stream, ...) printf(__VA_ARGS__)
+#define vfprintf(output_type, fmt, ap) vprintf(fmt, ap)
+#endif
 #define ERROR_PTR ((void*)-1)
 
 /* Error codes */
diff --git a/flashrom.c b/flashrom.c
index e9e6a77..b145037 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -26,6 +26,8 @@
 #ifndef __LIBPAYLOAD__
 #include <fcntl.h>
 #include <sys/stat.h>
+#else
+#include <libpayload.h>
 #endif
 #include <string.h>
 #include <stdlib.h>
@@ -1234,6 +1236,7 @@ int verify_flash(struct flashchip *flash, uint8_t *buf)
 
 int read_buf_from_file(unsigned char *buf, unsigned long size, char *filename)
 {
+#ifndef __LIBPAYLOAD__
 	unsigned long numbytes;
 	FILE *image;
 	struct stat image_stat;
@@ -1262,11 +1265,13 @@ int read_buf_from_file(unsigned char *buf, unsigned long size, char *filename)
 			 "wanted %ld!\n", numbytes, size);
 		return 1;
 	}
+#endif
 	return 0;
 }
 
 int write_buf_to_file(unsigned char *buf, unsigned long size, char *filename)
 {
+#ifndef __LIBPAYLOAD__
 	unsigned long numbytes;
 	FILE *image;
 
@@ -1286,6 +1291,7 @@ int write_buf_to_file(unsigned char *buf, unsigned long size, char *filename)
 			 filename);
 		return 1;
 	}
+#endif
 	return 0;
 }
 
diff --git a/layout.c b/layout.c
index d719a05..c5a0245 100644
--- a/layout.c
+++ b/layout.c
@@ -136,9 +136,9 @@ int show_id(uint8_t *bios, int size, int force)
 }
 #endif
 
-#ifndef __LIBPAYLOAD__
 int read_romlayout(char *name)
 {
+#ifndef __LIBPAYLOAD__
 	FILE *romlayout;
 	char tempstr[256];
 	int i;
@@ -191,8 +191,10 @@ int read_romlayout(char *name)
 	fclose(romlayout);
 
 	return 0;
-}
+#else
+	return -1;
 #endif
+}
 
 int find_romentry(char *name)
 {
diff --git a/nicintel.c b/nicintel.c
index 3d53ec8..b88597a 100644
--- a/nicintel.c
+++ b/nicintel.c
@@ -23,6 +23,8 @@
 #include "flash.h"
 #include "programmer.h"
 
+#define PCI_VENDOR_ID_INTEL 0x8086
+
 uint8_t *nicintel_bar;
 uint8_t *nicintel_control_bar;
 
diff --git a/sst49lfxxxc.c b/sst49lfxxxc.c
index 046b9f3..5299c6e 100644
--- a/sst49lfxxxc.c
+++ b/sst49lfxxxc.c
@@ -61,13 +61,12 @@ int unlock_49lfxxxc(struct flashchip *flash)
 
 int erase_sector_49lfxxxc(struct flashchip *flash, unsigned int address, unsigned int sector_size)
 {
-	uint8_t status;
 	chipaddr bios = flash->virtual_memory;
 
 	chip_writeb(0x30, bios);
 	chip_writeb(0xD0, bios + address);
 
-	status = wait_82802ab(flash);
+	wait_82802ab(flash);
 
 	if (check_erased_range(flash, address, sector_size)) {
 		msg_cerr("ERASE FAILED!\n");
-- 
1.7.0.4






More information about the flashrom mailing list