From 66ef4e5ff32b1d19281c9d6723b1acfe566f9763 Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Sun, 13 Dec 2009 22:28:00 +0000 Subject: 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 Acked-by: Sean Nelson --- Makefile | 30 +++++++++++++++++++++++------- cbtable.c | 14 ++++++++++++++ chipset_enable.c | 21 --------------------- flash.h | 49 ++++++++++++++++++++++++++++++++++++++----------- flashrom.c | 54 +++++++++++++++++++++++++++++++++++++++++++----------- internal.c | 4 ++++ layout.c | 4 ++++ print.c | 6 ++++++ spi.c | 6 ++++++ 9 files changed, 138 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index ae06d7c..77731ed 100644 --- a/Makefile +++ b/Makefile @@ -43,13 +43,11 @@ endif 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 @@ RELEASENAME ?= $(VERSION) 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 @@ CONFIG_BUSPIRATESPI ?= yes # 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 @@ endif 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 @@ endif 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 @@ OBJS += serial.o 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 #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 #include #include +#if NEED_PCI == 1 #include +#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 @@ enum programmer { #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 @@ struct flashchip { 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_ok[]; 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 @@ struct pcidev_status { }; 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_write(uint16_t port, uint8_t reg, uint8_t data); 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 @@ int freebsd_wrmsr(int addr, msr_t msr); #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 @@ uint8_t internal_chip_readb(const chipaddr addr); 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 @@ extern int io_fd; #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 @@ uint32_t dummy_chip_readl(const chipaddr addr); 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_send_command(unsigned int writecnt, unsigned int readcnt, cons 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 find_romentry(char *name); 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 @@ extern int partvendor_from_cbtable; /* 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 @@ const struct programmer_entry programmer_table[] = { .chip_writen = fallback_chip_writen, .delay = internal_delay, }, +#endif #if DUMMY_SUPPORT == 1 { @@ -149,6 +178,7 @@ const struct programmer_entry programmer_table[] = { }, #endif +#if INTERNAL_SUPPORT == 1 { .name = "it87spi", .init = it87spi_init, @@ -165,6 +195,7 @@ const struct programmer_entry programmer_table[] = { .chip_writen = fallback_chip_writen, .delay = internal_delay, }, +#endif #if FT2232_SPI_SUPPORT == 1 { @@ -308,6 +339,8 @@ int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len) return 0; } +unsigned long flashbase = 0; + int min(int a, int b) { return (a < b) ? a : b; @@ -866,7 +899,9 @@ void usage(const char *name) " -E | --erase: erase flash device\n" " -V | --verbose: more verbose output\n" " -c | --chip : 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 : read ROM layout from file\n" " -i | --image : only flash image name from flash layout\n" @@ -962,7 +997,7 @@ int main(int argc, char *argv[]) char *filename = NULL; - char *tempstr = NULL, *tempstr2 = NULL; + char *tempstr = NULL; print_version(); @@ -1046,18 +1081,12 @@ int main(int argc, char *argv[]) } 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 @@ int main(int argc, char *argv[]) "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 @@ int main(int argc, char *argv[]) } 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 @@ struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device, return NULL; } +#endif void get_io_perms(void) { @@ -122,6 +124,7 @@ void release_io_perms(void) #endif } +#if INTERNAL_SUPPORT == 1 int internal_init(void) { int ret = 0; @@ -163,6 +166,7 @@ int internal_shutdown(void) 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 #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 @@ typedef struct { 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 @@ int show_id(uint8_t *bios, int size, int force) 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 @@ void print_supported_chips(void) } } +#if INTERNAL_SUPPORT == 1 void print_supported_chipsets(void) { int i, j, chipsetcount = 0; @@ -221,12 +222,15 @@ void print_supported_boards(void) 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 @@ void print_supported(void) } +#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 @@ const struct board_info laptops_bad[] = { {}, }; +#endif diff --git a/spi.c b/spi.c index 14beed7..a2b26c5 100644 --- a/spi.c +++ b/spi.c @@ -40,6 +40,7 @@ const struct spi_programmer spi_programmer[] = { .write_256 = NULL, }, +#if INTERNAL_SUPPORT == 1 { /* SPI_CONTROLLER_ICH7 */ .command = ich_spi_send_command, .multicommand = ich_spi_send_multicommand, @@ -81,6 +82,7 @@ const struct spi_programmer spi_programmer[] = { .read = wbsio_spi_read, .write_256 = wbsio_spi_write_1, }, +#endif #if FT2232_SPI_SUPPORT == 1 { /* SPI_CONTROLLER_FT2232 */ @@ -308,11 +310,13 @@ int probe_spi_rdid4(struct flashchip *flash) { /* 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 spi_aai_write(struct flashchip *flash, uint8_t *buf) 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; } -- cgit v1.1