Internal (onboard) programming was the only feature which could not be disabled
Make various pieces of code conditional on support for internal
programming. Code shared between PCI device programmers and onboard
programming is now conditional as well.
It is now possible to build only with dummy support:
make CONFIG_INTERNAL=no CONFIG_NIC3COM=no CONFIG_SATASII=no
CONFIG_DRKAISER=no CONFIG_SERPROG=no CONFIG_FT2232SPI=no
This allows building for a specific use case only, and it also
facilitates porting to a new architecture because it is possible to
focus on highlevel code only.
Note: Either internal or dummy programmer needs to be compiled in due to
the current behaviour of always picking a default programmer if -p is
not specified. Picking an arbitrary external programmer as default
wouldn't make sense.
Build and runtime tested in all 1024 possible build combinations. The
only failures are by design as mentioned above.
Corresponding to flashrom svn r797.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Sean Nelson <audiohacked@gmail.com>
diff --git a/Makefile b/Makefile
index ae06d7c..77731ed 100644
--- a/Makefile
+++ b/Makefile
@@ -43,13 +43,11 @@
LIBS += -lpci
-OBJS = chipset_enable.o board_enable.o udelay.o jedec.o stm50flw0x0x.o \
- sst28sf040.o am29f040b.o mx29f002.o m29f400bt.o pm29f002.o \
- w49f002u.o 82802ab.o pm49fl00x.o sst49lf040.o en29f002a.o \
- sst49lfxxxc.o sst_fwhub.o layout.o cbtable.o flashchips.o physmap.o \
- flashrom.o w39v080fa.o sharplhf00l04.o w29ee011.o spi.o it87spi.o \
- ichspi.o w39v040c.o sb600spi.o wbsio_spi.o m29f002.o internal.o \
- pcidev.o print.o
+OBJS = jedec.o stm50flw0x0x.o w39v080fa.o sharplhf00l04.o w29ee011.o \
+ sst28sf040.o am29f040b.o mx29f002.o m29f400bt.o pm29f002.o w39v040c.o \
+ w49f002u.o 82802ab.o pm49fl00x.o sst49lf040.o en29f002a.o m29f002.o \
+ sst49lfxxxc.o sst_fwhub.o flashchips.o layout.o spi.o \
+ flashrom.o print.o physmap.o internal.o udelay.o
all: pciutils features dep $(PROGRAM)
@@ -65,6 +63,9 @@
SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"'
+# Always enable internal/onboard support for now.
+CONFIG_INTERNAL ?= yes
+
# Always enable serprog for now. Needs to be disabled on Windows.
CONFIG_SERPROG ?= yes
@@ -95,6 +96,12 @@
# Disable wiki printing by default. It is only useful if you have wiki access.
CONFIG_PRINT_WIKI ?= no
+ifeq ($(CONFIG_INTERNAL), yes)
+FEATURE_CFLAGS += -D'INTERNAL_SUPPORT=1'
+OBJS += chipset_enable.o board_enable.o cbtable.o it87spi.o ichspi.o sb600spi.o wbsio_spi.o
+NEED_PCI := yes
+endif
+
ifeq ($(CONFIG_SERPROG), yes)
FEATURE_CFLAGS += -D'SERPROG_SUPPORT=1'
OBJS += serprog.o
@@ -111,16 +118,19 @@
ifeq ($(CONFIG_NIC3COM), yes)
FEATURE_CFLAGS += -D'NIC3COM_SUPPORT=1'
OBJS += nic3com.o
+NEED_PCI := yes
endif
ifeq ($(CONFIG_GFXNVIDIA), yes)
FEATURE_CFLAGS += -D'GFXNVIDIA_SUPPORT=1'
OBJS += gfxnvidia.o
+NEED_PCI := yes
endif
ifeq ($(CONFIG_SATASII), yes)
FEATURE_CFLAGS += -D'SATASII_SUPPORT=1'
OBJS += satasii.o
+NEED_PCI := yes
endif
FTDILIBS := $(shell pkg-config --libs libftdi 2>/dev/null || printf "%s" "-lftdi -lusb")
@@ -139,6 +149,7 @@
ifeq ($(CONFIG_DRKAISER), yes)
FEATURE_CFLAGS += -D'DRKAISER_SUPPORT=1'
OBJS += drkaiser.o
+NEED_PCI := yes
endif
ifeq ($(CONFIG_BUSPIRATESPI), yes)
@@ -155,6 +166,11 @@
endif
endif
+ifeq ($(NEED_PCI), yes)
+FEATURE_CFLAGS += -D'NEED_PCI=1'
+OBJS += pcidev.o
+endif
+
ifeq ($(CONFIG_PRINT_WIKI), yes)
FEATURE_CFLAGS += -D'PRINT_WIKI_SUPPORT=1'
OBJS += print_wiki.o
diff --git a/cbtable.c b/cbtable.c
index 9d7e758..2bc1bfa 100644
--- a/cbtable.c
+++ b/cbtable.c
@@ -30,6 +30,20 @@
char *lb_part = NULL, *lb_vendor = NULL;
int partvendor_from_cbtable = 0;
+void lb_vendor_dev_from_string(char *boardstring)
+{
+ char *tempstr2 = NULL;
+ strtok(boardstring, ":");
+ tempstr2 = strtok(NULL, ":");
+ if (tempstr2) {
+ lb_vendor = boardstring;
+ lb_part = tempstr2;
+ } else {
+ lb_vendor = NULL;
+ lb_part = boardstring;
+ }
+}
+
static unsigned long compute_checksum(void *addr, unsigned long length)
{
uint8_t *ptr;
diff --git a/chipset_enable.c b/chipset_enable.c
index 3bdd7d0..333d79d 100644
--- a/chipset_enable.c
+++ b/chipset_enable.c
@@ -32,27 +32,6 @@
#include <fcntl.h>
#include "flash.h"
-unsigned long flashbase = 0;
-
-/**
- * flashrom defaults to Parallel/LPC/FWH flash devices. If a known host
- * controller is found, the init routine sets the buses_supported bitfield to
- * contain the supported buses for that controller.
- */
-
-enum chipbustype buses_supported = CHIP_BUSTYPE_NONSPI;
-
-/**
- * Programmers supporting multiple buses can have differing size limits on
- * each bus. Store the limits for each bus in a common struct.
- */
-struct decode_sizes max_rom_decode = {
- .parallel = 0xffffffff,
- .lpc = 0xffffffff,
- .fwh = 0xffffffff,
- .spi = 0xffffffff
-};
-
extern int ichspi_lock;
static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name)
diff --git a/flash.h b/flash.h
index 4178d47..a1bcdf0 100644
--- a/flash.h
+++ b/flash.h
@@ -30,7 +30,9 @@
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
+#if NEED_PCI == 1
#include <pci/pci.h>
+#endif
/* for iopl and outb under Solaris */
#if defined (__sun) && (defined(__i386) || defined(__amd64))
@@ -81,7 +83,9 @@
typedef unsigned long chipaddr;
enum programmer {
+#if INTERNAL_SUPPORT == 1
PROGRAMMER_INTERNAL,
+#endif
#if DUMMY_SUPPORT == 1
PROGRAMMER_DUMMY,
#endif
@@ -97,7 +101,9 @@
#if SATASII_SUPPORT == 1
PROGRAMMER_SATASII,
#endif
+#if INTERNAL_SUPPORT == 1
PROGRAMMER_IT87SPI,
+#endif
#if FT2232_SPI_SUPPORT == 1
PROGRAMMER_FT2232SPI,
#endif
@@ -269,6 +275,7 @@
extern struct flashchip flashchips[];
+#if INTERNAL_SUPPORT == 1
struct penable {
uint16_t vendor_id;
uint16_t device_id;
@@ -316,11 +323,13 @@
extern const struct board_info boards_bad[];
extern const struct board_info laptops_ok[];
extern const struct board_info laptops_bad[];
+#endif
/* udelay.c */
void myusec_delay(int usecs);
void myusec_calibrate_delay(void);
+#if NEED_PCI == 1
/* pcidev.c */
#define PCI_OK 0
#define PCI_NT 1 /* Not tested */
@@ -338,11 +347,14 @@
};
uint32_t pcidev_validate(struct pci_dev *dev, uint32_t bar, struct pcidev_status *devs);
uint32_t pcidev_init(uint16_t vendor_id, uint32_t bar, struct pcidev_status *devs, char *pcidev_bdf);
+#endif
/* print.c */
char *flashbuses_to_text(enum chipbustype bustype);
void print_supported(void);
+#if (NIC3COM_SUPPORT == 1) || (GFXNVIDIA_SUPPORT == 1) || (DRKAISER_SUPPORT == 1) || (SATASII_SUPPORT == 1)
void print_supported_pcidevs(struct pcidev_status *devs);
+#endif
void print_supported_wiki(void);
/* board_enable.c */
@@ -353,19 +365,8 @@
void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
int board_flash_enable(const char *vendor, const char *part);
-struct decode_sizes {
- uint32_t parallel;
- uint32_t lpc;
- uint32_t fwh;
- uint32_t spi;
-};
-
/* chipset_enable.c */
-extern enum chipbustype buses_supported;
int chipset_flash_enable(void);
-extern struct decode_sizes max_rom_decode;
-
-extern unsigned long flashbase;
/* physmap.c */
void *physmap(const char *descr, unsigned long phys_addr, size_t len);
@@ -389,13 +390,16 @@
#endif
/* internal.c */
+#if NEED_PCI == 1
struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t class);
struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
uint16_t card_vendor, uint16_t card_device);
+#endif
void get_io_perms(void);
void release_io_perms(void);
+#if INTERNAL_SUPPORT == 1
int internal_init(void);
int internal_shutdown(void);
void internal_chip_writeb(uint8_t val, chipaddr addr);
@@ -405,6 +409,7 @@
uint16_t internal_chip_readw(const chipaddr addr);
uint32_t internal_chip_readl(const chipaddr addr);
void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
+#endif
void mmio_writeb(uint8_t val, void *addr);
void mmio_writew(uint16_t val, void *addr);
void mmio_writel(uint32_t val, void *addr);
@@ -428,6 +433,7 @@
#endif
/* dummyflasher.c */
+#if DUMMY_SUPPORT == 1
int dummy_init(void);
int dummy_shutdown(void);
void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
@@ -442,34 +448,43 @@
void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr);
+#endif
/* nic3com.c */
+#if NIC3COM_SUPPORT == 1
int nic3com_init(void);
int nic3com_shutdown(void);
void nic3com_chip_writeb(uint8_t val, chipaddr addr);
uint8_t nic3com_chip_readb(const chipaddr addr);
extern struct pcidev_status nics_3com[];
+#endif
/* gfxnvidia.c */
+#if GFXNVIDIA_SUPPORT == 1
int gfxnvidia_init(void);
int gfxnvidia_shutdown(void);
void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr);
uint8_t gfxnvidia_chip_readb(const chipaddr addr);
extern struct pcidev_status gfx_nvidia[];
+#endif
/* drkaiser.c */
+#if DRKAISER_SUPPORT == 1
int drkaiser_init(void);
int drkaiser_shutdown(void);
void drkaiser_chip_writeb(uint8_t val, chipaddr addr);
uint8_t drkaiser_chip_readb(const chipaddr addr);
extern struct pcidev_status drkaiser_pcidev[];
+#endif
/* satasii.c */
+#if SATASII_SUPPORT == 1
int satasii_init(void);
int satasii_shutdown(void);
void satasii_chip_writeb(uint8_t val, chipaddr addr);
uint8_t satasii_chip_readb(const chipaddr addr);
extern struct pcidev_status satas_sii[];
+#endif
/* ft2232_spi.c */
#define FTDI_FT2232H 0x6010
@@ -498,7 +513,16 @@
int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
/* flashrom.c */
+extern enum chipbustype buses_supported;
+struct decode_sizes {
+ uint32_t parallel;
+ uint32_t lpc;
+ uint32_t fwh;
+ uint32_t spi;
+};
+extern struct decode_sizes max_rom_decode;
extern char *programmer_param;
+extern unsigned long flashbase;
extern int verbose;
extern const char *flashrom_version;
#define printf_debug(x...) { if (verbose) printf(x); }
@@ -522,6 +546,7 @@
int handle_romentries(uint8_t *buffer, struct flashchip *flash);
/* cbtable.c */
+void lb_vendor_dev_from_string(char *boardstring);
int coreboot_init(void);
extern char *lb_part, *lb_vendor;
extern int partvendor_from_cbtable;
@@ -529,12 +554,14 @@
/* spi.c */
enum spi_controller {
SPI_CONTROLLER_NONE,
+#if INTERNAL_SUPPORT == 1
SPI_CONTROLLER_ICH7,
SPI_CONTROLLER_ICH9,
SPI_CONTROLLER_IT87XX,
SPI_CONTROLLER_SB600,
SPI_CONTROLLER_VIA,
SPI_CONTROLLER_WBSIO,
+#endif
#if FT2232_SPI_SUPPORT == 1
SPI_CONTROLLER_FT2232,
#endif
diff --git a/flashrom.c b/flashrom.c
index 64a6835..a0dedb5 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -33,10 +33,38 @@
const char *flashrom_version = FLASHROM_VERSION;
char *chip_to_probe = NULL;
int verbose = 0;
+
+#if INTERNAL_SUPPORT == 1
enum programmer programmer = PROGRAMMER_INTERNAL;
+#elif DUMMY_SUPPORT == 1
+enum programmer programmer = PROGRAMMER_DUMMY;
+#else
+/* Activating the #error explodes on make dep. */
+//#error Neither internal nor dummy selected
+#endif
+
char *programmer_param = NULL;
+/**
+ * flashrom defaults to Parallel/LPC/FWH flash devices. If a known host
+ * controller is found, the init routine sets the buses_supported bitfield to
+ * contain the supported buses for that controller.
+ */
+enum chipbustype buses_supported = CHIP_BUSTYPE_NONSPI;
+
+/**
+ * Programmers supporting multiple buses can have differing size limits on
+ * each bus. Store the limits for each bus in a common struct.
+ */
+struct decode_sizes max_rom_decode = {
+ .parallel = 0xffffffff,
+ .lpc = 0xffffffff,
+ .fwh = 0xffffffff,
+ .spi = 0xffffffff
+};
+
const struct programmer_entry programmer_table[] = {
+#if INTERNAL_SUPPORT == 1
{
.name = "internal",
.init = internal_init,
@@ -53,6 +81,7 @@
.chip_writen = fallback_chip_writen,
.delay = internal_delay,
},
+#endif
#if DUMMY_SUPPORT == 1
{
@@ -149,6 +178,7 @@
},
#endif
+#if INTERNAL_SUPPORT == 1
{
.name = "it87spi",
.init = it87spi_init,
@@ -165,6 +195,7 @@
.chip_writen = fallback_chip_writen,
.delay = internal_delay,
},
+#endif
#if FT2232_SPI_SUPPORT == 1
{
@@ -308,6 +339,8 @@
return 0;
}
+unsigned long flashbase = 0;
+
int min(int a, int b)
{
return (a < b) ? a : b;
@@ -866,7 +899,9 @@
" -E | --erase: erase flash device\n"
" -V | --verbose: more verbose output\n"
" -c | --chip <chipname>: probe only for specified flash chip\n"
+#if INTERNAL_SUPPORT == 1
" -m | --mainboard <[vendor:]part>: override mainboard settings\n"
+#endif
" -f | --force: force write without checking image\n"
" -l | --layout <file.layout>: read ROM layout from file\n"
" -i | --image <name>: only flash image name from flash layout\n"
@@ -962,7 +997,7 @@
char *filename = NULL;
- char *tempstr = NULL, *tempstr2 = NULL;
+ char *tempstr = NULL;
print_version();
@@ -1046,18 +1081,12 @@
}
erase_it = 1;
break;
+#if INTERNAL_SUPPORT == 1
case 'm':
tempstr = strdup(optarg);
- strtok(tempstr, ":");
- tempstr2 = strtok(NULL, ":");
- if (tempstr2) {
- lb_vendor = tempstr;
- lb_part = tempstr2;
- } else {
- lb_vendor = NULL;
- lb_part = tempstr;
- }
+ lb_vendor_dev_from_string(tempstr);
break;
+#endif
case 'f':
force = 1;
break;
@@ -1224,7 +1253,8 @@
"this flash part. Please include the flashrom\noutput "
"with the additional -V option for all operations you "
"tested (-V, -rV,\n-wV, -EV), and mention which "
- "mainboard you tested. Thanks for your help!\n===\n");
+ "mainboard or programmer you tested. Thanks for your "
+ "help!\n===\n");
}
size = flash->total_size * 1024;
@@ -1318,7 +1348,9 @@
}
numbytes = fread(buf, 1, size, image);
+#if INTERNAL_SUPPORT == 1
show_id(buf, size, force);
+#endif
fclose(image);
if (numbytes != size) {
fprintf(stderr, "Error: Failed to read file. Got %ld bytes, wanted %ld!\n", numbytes, size);
diff --git a/internal.c b/internal.c
index fc662c5..cfb83d7 100644
--- a/internal.c
+++ b/internal.c
@@ -31,6 +31,7 @@
int io_fd;
#endif
+#if NEED_PCI == 1
struct pci_dev *pci_dev_find_filter(struct pci_filter filter)
{
struct pci_dev *temp;
@@ -99,6 +100,7 @@
return NULL;
}
+#endif
void get_io_perms(void)
{
@@ -122,6 +124,7 @@
#endif
}
+#if INTERNAL_SUPPORT == 1
int internal_init(void)
{
int ret = 0;
@@ -163,6 +166,7 @@
return 0;
}
+#endif
void internal_chip_writeb(uint8_t val, chipaddr addr)
{
diff --git a/layout.c b/layout.c
index c432ebe..26b7c6a 100644
--- a/layout.c
+++ b/layout.c
@@ -23,8 +23,10 @@
#include <ctype.h>
#include "flash.h"
+#if INTERNAL_SUPPORT == 1
char *mainboard_vendor = NULL;
char *mainboard_part = NULL;
+#endif
int romimages = 0;
#define MAX_ROMLAYOUT 16
@@ -38,6 +40,7 @@
romlayout_t rom_entries[MAX_ROMLAYOUT];
+#if INTERNAL_SUPPORT == 1 /* FIXME: Move the whole block to cbtable.c? */
static char *def_name = "DEFAULT";
int show_id(uint8_t *bios, int size, int force)
@@ -126,6 +129,7 @@
return 0;
}
+#endif
int read_romlayout(char *name)
{
diff --git a/print.c b/print.c
index a2a6c63..3f2f397 100644
--- a/print.c
+++ b/print.c
@@ -144,6 +144,7 @@
}
}
+#if INTERNAL_SUPPORT == 1
void print_supported_chipsets(void)
{
int i, j, chipsetcount = 0;
@@ -221,12 +222,15 @@
print_supported_boards_helper(laptops_bad,
"Laptops which have been verified to NOT work yet");
}
+#endif
void print_supported(void)
{
print_supported_chips();
+#if INTERNAL_SUPPORT == 1
print_supported_chipsets();
print_supported_boards();
+#endif
printf("\nSupported PCI devices flashrom can use "
"as programmer:\n\n");
#if NIC3COM_SUPPORT == 1
@@ -244,6 +248,7 @@
}
+#if INTERNAL_SUPPORT == 1
/* Please keep this list alphabetically ordered by vendor/board. */
const struct board_info boards_ok[] = {
/* Verified working boards that don't need write-enables. */
@@ -394,4 +399,5 @@
{},
};
+#endif
diff --git a/spi.c b/spi.c
index 14beed7..a2b26c5 100644
--- a/spi.c
+++ b/spi.c
@@ -40,6 +40,7 @@
.write_256 = NULL,
},
+#if INTERNAL_SUPPORT == 1
{ /* SPI_CONTROLLER_ICH7 */
.command = ich_spi_send_command,
.multicommand = ich_spi_send_multicommand,
@@ -81,6 +82,7 @@
.read = wbsio_spi_read,
.write_256 = wbsio_spi_write_1,
},
+#endif
#if FT2232_SPI_SUPPORT == 1
{ /* SPI_CONTROLLER_FT2232 */
@@ -308,11 +310,13 @@
{
/* only some SPI chipsets support 4 bytes commands */
switch (spi_controller) {
+#if INTERNAL_SUPPORT == 1
case SPI_CONTROLLER_ICH7:
case SPI_CONTROLLER_ICH9:
case SPI_CONTROLLER_VIA:
case SPI_CONTROLLER_SB600:
case SPI_CONTROLLER_WBSIO:
+#endif
#if FT2232_SPI_SUPPORT == 1
case SPI_CONTROLLER_FT2232:
#endif
@@ -1042,10 +1046,12 @@
int result;
switch (spi_controller) {
+#if INTERNAL_SUPPORT == 1
case SPI_CONTROLLER_WBSIO:
fprintf(stderr, "%s: impossible with Winbond SPI masters,"
" degrading to byte program\n", __func__);
return spi_chip_write_1(flash, buf);
+#endif
default:
break;
}