To be able to get rid of lots of #ifdefs and centralize programmer-specific data more... - introduce two new fields to struct programmer_entry, namely enum type (OTHER, USB, PCI) and union devices (pcidev_status, usbdev_status or char *note). - use those fields to generate device listings in print.c and print_wiki.c.
Bonus: add printing of USB devices to print_wiki.c and count supported PCI and USB devices
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at --- flashrom.c | 43 ++++++++++++++++++ ft2232_spi.c | 13 ------ pcidev.c | 1 - print.c | 135 +++++++++++++++++---------------------------------------- print_wiki.c | 136 +++++++++++++++++++++++++++++++++++++++------------------- programmer.h | 12 +++++ 6 files changed, 187 insertions(+), 153 deletions(-)
diff --git a/flashrom.c b/flashrom.c index cad043b..bf1e157 100644 --- a/flashrom.c +++ b/flashrom.c @@ -62,6 +62,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_INTERNAL == 1 { .name = "internal", + .type = OTHER, + .devices.note = NULL, .init = internal_init, .map_flash_region = physmap, .unmap_flash_region = physunmap, @@ -72,6 +74,9 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_DUMMY == 1 { .name = "dummy", + .type = OTHER, + /* FIXME */ + .devices.note = "Dummy device, does nothing and logs all accesses\n", .init = dummy_init, .map_flash_region = dummy_map, .unmap_flash_region = dummy_unmap, @@ -82,6 +87,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_NIC3COM == 1 { .name = "nic3com", + .type = PCI, + .devices.pci = nics_3com, .init = nic3com_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -93,6 +100,8 @@ const struct programmer_entry programmer_table[] = { { /* This programmer works for Realtek RTL8139 and SMC 1211. */ .name = "nicrealtek", + .type = PCI, + .devices.pci = nics_realtek, //.name = "nicsmc1211", .init = nicrealtek_init, .map_flash_region = fallback_map, @@ -104,6 +113,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_NICNATSEMI == 1 { .name = "nicnatsemi", + .type = PCI, + .devices.pci = nics_natsemi, .init = nicnatsemi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -114,6 +125,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_GFXNVIDIA == 1 { .name = "gfxnvidia", + .type = PCI, + .devices.pci = gfx_nvidia, .init = gfxnvidia_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -124,6 +137,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_DRKAISER == 1 { .name = "drkaiser", + .type = PCI, + .devices.pci = drkaiser_pcidev, .init = drkaiser_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -134,6 +149,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_SATASII == 1 { .name = "satasii", + .type = PCI, + .devices.pci = satas_sii, .init = satasii_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -144,6 +161,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_ATAHPT == 1 { .name = "atahpt", + .type = PCI, + .devices.pci = ata_hpt, .init = atahpt_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -154,6 +173,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_FT2232_SPI == 1 { .name = "ft2232_spi", + .type = USB, + .devices.usb = devs_ft2232spi, .init = ft2232_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -164,6 +185,9 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_SERPROG == 1 { .name = "serprog", + .type = OTHER, + /* FIXME */ + .devices.note = "All programmer devices speaking the serprog protocol\n", .init = serprog_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -174,6 +198,9 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_BUSPIRATE_SPI == 1 { .name = "buspirate_spi", + .type = OTHER, + /* FIXME */ + .devices.note = "Dangerous Prototypes Bus Pirate\n", .init = buspirate_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -184,6 +211,9 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_DEDIPROG == 1 { .name = "dediprog", + .type = OTHER, + /* FIXME */ + .devices.note = "Dediprog SF100\n", .init = dediprog_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -194,6 +224,9 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_RAYER_SPI == 1 { .name = "rayer_spi", + .type = OTHER, + /* FIXME */ + .devices.note = "RayeR parallel port programmer\n", .init = rayer_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -204,6 +237,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_NICINTEL == 1 { .name = "nicintel", + .type = PCI, + .devices.pci = nics_intel, .init = nicintel_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -214,6 +249,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_NICINTEL_SPI == 1 { .name = "nicintel_spi", + .type = PCI, + .devices.pci = nics_intel_spi, .init = nicintel_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -224,6 +261,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_OGP_SPI == 1 { .name = "ogp_spi", + .type = PCI, + .devices.pci = ogp_spi, .init = ogp_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -234,6 +273,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_SATAMV == 1 { .name = "satamv", + .type = PCI, + .devices.pci = satas_mv, .init = satamv_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -244,6 +285,8 @@ const struct programmer_entry programmer_table[] = { #if CONFIG_LINUX_SPI == 1 { .name = "linux_spi", + .type = OTHER, + .devices.note = "Device files /dev/spidev*.*\n", .init = linux_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, diff --git a/ft2232_spi.c b/ft2232_spi.c index 122866f..ec4934e 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -435,17 +435,4 @@ static int ft2232_spi_send_command(struct flashctx *flash, return failed ? -1 : 0; }
-void print_supported_usbdevs(const struct usbdev_status *devs) -{ - int i; - - msg_pinfo("USB devices:\n"); - for (i = 0; devs[i].vendor_name != NULL; i++) { - msg_pinfo("%s %s [%04x:%04x]%s\n", devs[i].vendor_name, - devs[i].device_name, devs[i].vendor_id, - devs[i].device_id, - (devs[i].status == NT) ? " (untested)" : ""); - } -} - #endif diff --git a/pcidev.c b/pcidev.c index e8b4dc1..6e5d0f1 100644 --- a/pcidev.c +++ b/pcidev.c @@ -244,7 +244,6 @@ void print_supported_pcidevs(const struct pcidev_status *devs) { int i;
- msg_pinfo("PCI devices:\n"); for (i = 0; devs[i].vendor_name != NULL; i++) { msg_pinfo("%s %s [%04x:%04x]%s\n", devs[i].vendor_name, devs[i].device_name, devs[i].vendor_id, diff --git a/print.c b/print.c index 544a846..8bab8e3 100644 --- a/print.c +++ b/print.c @@ -422,8 +422,24 @@ static void print_supported_boards_helper(const struct board_info *boards, } #endif
+#if CONFIG_FT2232_SPI == 1 +void print_supported_usbdevs(const struct usbdev_status *devs) +{ + int i; + + msg_pinfo("USB devices:\n"); + for (i = 0; devs[i].vendor_name != NULL; i++) { + msg_pinfo("%s %s [%04x:%04x]%s\n", devs[i].vendor_name, + devs[i].device_name, devs[i].vendor_id, + devs[i].device_id, + (devs[i].status == NT) ? " (untested)" : ""); + } +} +#endif + void print_supported(void) { + unsigned int i; print_supported_chips();
msg_ginfo("\nSupported programmers:\n"); @@ -437,101 +453,30 @@ void print_supported(void) msg_ginfo("\n"); print_supported_boards_helper(laptops_known, "laptops"); #endif -#if CONFIG_DUMMY == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_DUMMY].name); - /* FIXME */ - msg_ginfo("Dummy device, does nothing and logs all accesses\n"); -#endif -#if CONFIG_NIC3COM == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_NIC3COM].name); - print_supported_pcidevs(nics_3com); -#endif -#if CONFIG_NICREALTEK == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_NICREALTEK].name); - print_supported_pcidevs(nics_realtek); -#endif -#if CONFIG_NICNATSEMI == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_NICNATSEMI].name); - print_supported_pcidevs(nics_natsemi); -#endif -#if CONFIG_GFXNVIDIA == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_GFXNVIDIA].name); - print_supported_pcidevs(gfx_nvidia); -#endif -#if CONFIG_DRKAISER == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_DRKAISER].name); - print_supported_pcidevs(drkaiser_pcidev); -#endif -#if CONFIG_SATASII == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_SATASII].name); - print_supported_pcidevs(satas_sii); -#endif -#if CONFIG_ATAHPT == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_ATAHPT].name); - print_supported_pcidevs(ata_hpt); -#endif -#if CONFIG_FT2232_SPI == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_FT2232_SPI].name); - print_supported_usbdevs(devs_ft2232spi); -#endif -#if CONFIG_SERPROG == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_SERPROG].name); - /* FIXME */ - msg_ginfo("All programmer devices speaking the serprog protocol\n"); -#endif -#if CONFIG_BUSPIRATE_SPI == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_BUSPIRATE_SPI].name); - /* FIXME */ - msg_ginfo("Dangerous Prototypes Bus Pirate\n"); -#endif -#if CONFIG_DEDIPROG == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_DEDIPROG].name); - /* FIXME */ - msg_ginfo("Dediprog SF100\n"); -#endif -#if CONFIG_RAYER_SPI == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_RAYER_SPI].name); - /* FIXME */ - msg_ginfo("RayeR parallel port programmer\n"); -#endif -#if CONFIG_NICINTEL == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_NICINTEL].name); - print_supported_pcidevs(nics_intel); -#endif -#if CONFIG_NICINTEL_SPI == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_NICINTEL_SPI].name); - print_supported_pcidevs(nics_intel_spi); -#endif -#if CONFIG_OGP_SPI == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_OGP_SPI].name); - print_supported_pcidevs(ogp_spi); -#endif -#if CONFIG_SATAMV == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_SATAMV].name); - print_supported_pcidevs(satas_mv); -#endif -#if CONFIG_LINUX_SPI == 1 - msg_ginfo("\nSupported devices for the %s programmer:\n", - programmer_table[PROGRAMMER_LINUX_SPI].name); - msg_ginfo("Device files /dev/spidev*.*\n"); -#endif + for (i = 0; i < PROGRAMMER_INVALID; i++) { + const struct programmer_entry prog = programmer_table[i]; + switch (prog.type) { + case USB: + msg_ginfo("\nSupported USB devices for the %s programmer:\n", + prog.name); + print_supported_usbdevs(prog.devices.usb); + break; + case PCI: + msg_ginfo("\nSupported PCI devices for the %s programmer:\n", + prog.name); + print_supported_pcidevs(prog.devices.pci); + break; + case OTHER: + if (prog.devices.note == NULL) + break; + msg_ginfo("\nSupported devices for the %s programmer:\n", + prog.name); + msg_ginfo("%s", prog.devices.note); + break; + default: + break; + } + } }
#if CONFIG_INTERNAL == 1 diff --git a/print_wiki.c b/print_wiki.c index 9a9cd83..756f8d4 100644 --- a/print_wiki.c +++ b/print_wiki.c @@ -72,12 +72,9 @@ static const char chip_th[] = "{\ | Probe\n| Read\n| Erase\n| Write\n\ | align="center" | Min \n| align="center" | Max\n\n";
-static const char programmer_section[] = "\ -\n== Supported programmers ==\n\nThis is a list \ -of supported PCI devices flashrom can use as programmer:\n\n{| border="0" \ -valign="top"\n| valign="top"|\n\n{| border="0" style="font-size: \ +static const char programmer_th[] = "{| border="0" style="font-size: \ smaller" valign="top"\n|- bgcolor="#6699dd"\n! align="left" | Vendor\n\ -! align="left" | Device\n! align="center" | PCI IDs\n\ +! align="left" | Device\n! align="center" | IDs\n\ ! align="center" | Status\n\n";
#if CONFIG_INTERNAL == 1 @@ -126,7 +123,7 @@ static void print_supported_chipsets_wiki(int cols) printf("\n|}\n\n|}\n"); }
-static void wiki_helper(const char *devicetype, int cols, +static void print_supported_boards_wiki_helper(const char *devicetype, int cols, const struct board_info boards[]) { int i, j, k = 0, boardcount_good = 0, boardcount_bad = 0, color = 1; @@ -200,10 +197,10 @@ static void wiki_helper(const char *devicetype, int cols, static void print_supported_boards_wiki(void) { printf("%s", board_intro); - wiki_helper("boards", 2, boards_known); + print_supported_boards_wiki_helper("boards", 2, boards_known);
printf("%s", laptop_intro); - wiki_helper("laptops", 1, laptops_known); + print_supported_boards_wiki_helper("laptops", 1, laptops_known); } #endif
@@ -277,7 +274,16 @@ static void print_supported_chips_wiki(int cols)
/* Not needed for CONFIG_INTERNAL, but for all other PCI-based programmers. */ #if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_NICINTEL+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI+CONFIG_SATAMV >= 1 -static void print_supported_pcidevs_wiki(const struct pcidev_status *devs) +static int count_supported_pcidevs_wiki(const struct pcidev_status *devs) +{ + unsigned int count = 0; + unsigned int i = 0; + for (i = 0; devs[i].vendor_name != NULL; i++) + count++; + return count; +} + +static void print_supported_pcidevs_wiki_helper(const struct pcidev_status *devs) { int i = 0; static int c = 0; @@ -295,6 +301,82 @@ static void print_supported_pcidevs_wiki(const struct pcidev_status *devs) } #endif
+static int count_supported_usbdevs_wiki(const struct usbdev_status *devs) +{ + unsigned int count = 0; + unsigned int i = 0; + for (i = 0; devs[i].vendor_name != NULL; i++) + count++; + return count; +} + +static void print_supported_usbdevs_wiki_helper(const struct usbdev_status *devs) +{ + int i = 0; + static int c = 0; + + /* Alternate colors if the vendor changes. */ + c = !c; + + for (i = 0; devs[i].vendor_name != NULL; i++) { + printf("|- bgcolor="#%s"\n| %s || %s || " + "%04x:%04x || {{%s}}\n", (c) ? "eeeeee" : "dddddd", + devs[i].vendor_name, devs[i].device_name, + devs[i].vendor_id, devs[i].device_id, + (devs[i].status == NT) ? "?3" : "OK"); + } +} + +static void print_supported_devs_wiki() +{ + unsigned int pci_count = 0; + unsigned int usb_count = 0; + unsigned int i; + + for (i = 0; i < PROGRAMMER_INVALID; i++) { + const struct programmer_entry prog = programmer_table[i]; + switch (prog.type) { + case USB: + usb_count += count_supported_usbdevs_wiki(prog.devices.usb); + break; + case PCI: + pci_count += count_supported_pcidevs_wiki(prog.devices.pci); + break; + case OTHER: + default: + break; + } + } + + printf("\n== PCI Devices ==\n\n" + "Total amount of supported PCI devices flashrom can use as a programmer: '''%d'''\n\n" + "{| border="0" valign="top"\n| valign="top"|\n\n", + pci_count); + printf("%s", programmer_th); + + for (i = 0; i < PROGRAMMER_INVALID; i++) { + const struct programmer_entry prog = programmer_table[i]; + if (prog.type == PCI) { + print_supported_pcidevs_wiki_helper(prog.devices.pci); + } + } + printf("\n|}\n"); + + printf("\n== USB Devices ==\n\n" + "Total amount of supported USB devices flashrom can use as a programmer: '''%d'''\n\n" + "{| border="0" valign="top"\n| valign="top"|\n\n", + usb_count); + printf("%s", programmer_th); + + for (i = 0; i < PROGRAMMER_INVALID; i++) { + const struct programmer_entry prog = programmer_table[i]; + if (prog.type == USB) { + print_supported_usbdevs_wiki_helper(prog.devices.usb); + } + } + printf("\n|}\n"); +} + void print_supported_wiki(void) { time_t t = time(NULL); @@ -305,40 +387,6 @@ void print_supported_wiki(void) print_supported_chipsets_wiki(3); print_supported_boards_wiki(); #endif - printf("%s", programmer_section); -#if CONFIG_NIC3COM == 1 - print_supported_pcidevs_wiki(nics_3com); -#endif -#if CONFIG_NICREALTEK == 1 - print_supported_pcidevs_wiki(nics_realtek); -#endif -#if CONFIG_NICNATSEMI == 1 - print_supported_pcidevs_wiki(nics_natsemi); -#endif -#if CONFIG_GFXNVIDIA == 1 - print_supported_pcidevs_wiki(gfx_nvidia); -#endif -#if CONFIG_DRKAISER == 1 - print_supported_pcidevs_wiki(drkaiser_pcidev); -#endif -#if CONFIG_SATASII == 1 - print_supported_pcidevs_wiki(satas_sii); -#endif -#if CONFIG_ATAHPT == 1 - print_supported_pcidevs_wiki(ata_hpt); -#endif -#if CONFIG_NICINTEL == 1 - print_supported_pcidevs_wiki(nics_intel); -#endif -#if CONFIG_NICINTEL_SPI == 1 - print_supported_pcidevs_wiki(nics_intel_spi); -#endif -#if CONFIG_OGP_SPI == 1 - print_supported_pcidevs_wiki(ogp_spi); -#endif -#if CONFIG_SATAMV == 1 - print_supported_pcidevs_wiki(satas_mv); -#endif - printf("\n|}\n"); + print_supported_devs_wiki(); }
diff --git a/programmer.h b/programmer.h index 479d963..9f90fe5 100644 --- a/programmer.h +++ b/programmer.h @@ -87,9 +87,21 @@ enum programmer { PROGRAMMER_INVALID /* This must always be the last entry. */ };
+enum programmer_type { + PCI, + USB, + OTHER, +}; + struct programmer_entry { const char *vendor; const char *name; + enum programmer_type type; + union { + const struct pcidev_status *const pci; + const struct usbdev_status *const usb; + const char * const note; + } devices;
int (*init) (void);