From ba290d1ce346bac710e43e9a27cc072b1019d9d2 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Wed, 17 Jun 2009 12:07:12 +0000 Subject: [PATCH] Move all printing code to print.c Drop no longer needed MAX macro, we have a max() function. Corresponding to flashrom svn r601. Signed-off-by: Uwe Hermann Acked-by: Uwe Hermann --- Makefile | 2 +- board_enable.c | 56 ------------ chipset_enable.c | 26 ------ flash.h | 12 ++- flashrom.c | 121 ------------------------- print.c | 224 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 235 insertions(+), 206 deletions(-) create mode 100644 print.c diff --git a/Makefile b/Makefile index 39b5577ee..eba4d04bf 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ OBJS = chipset_enable.o board_enable.o udelay.o jedec.o stm50flw0x0x.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 \ - dummyflasher.o pcidev.o nic3com.o satasii.o ft2232_spi.o + dummyflasher.o pcidev.o nic3com.o satasii.o ft2232_spi.o print.o all: pciutils .features dep $(PROGRAM) diff --git a/board_enable.c b/board_enable.c index 377524e8b..39ad2b789 100644 --- a/board_enable.c +++ b/board_enable.c @@ -827,62 +827,6 @@ const struct board_info boards_bad[] = { {}, }; -void print_supported_boards_helper(const struct board_info *b) -{ - int i, j, boardcount = 0; - - for (i = 0; b[i].vendor != NULL; i++) - boardcount++; - - for (i = 0; b[i].vendor != NULL; i++) { - printf("%s", b[i].vendor); - for (j = 0; j < 25 - strlen(b[i].vendor); j++) - printf(" "); - printf("%s", b[i].name); - for (j = 0; j < 23 - strlen(b[i].name); j++) - printf(" "); - printf("\n"); - } -} - -void print_supported_boards(void) -{ - int i, j, boardcount = 0; - struct board_pciid_enable *b = board_pciid_enables; - - for (i = 0; b[i].vendor_name != NULL; i++) - boardcount++; - - printf("\nSupported boards which need write-enable code (total: %d):" - "\n\nVendor: Board: " - "Required option:\n\n", boardcount); - - for (i = 0; b[i].vendor_name != NULL; i++) { - printf("%s", b[i].vendor_name); - for (j = 0; j < 25 - strlen(b[i].vendor_name); j++) - printf(" "); - printf("%s", b[i].board_name); - for (j = 0; j < 25 - strlen(b[i].board_name); j++) - printf(" "); - if (b[i].lb_vendor != NULL) - printf("-m %s:%s\n", b[i].lb_vendor, b[i].lb_part); - else - printf("(none, board is autodetected)\n"); - } - - for (i = 0, boardcount = 0; boards_ok[i].vendor != NULL; i++) - boardcount++; - printf("\nSupported boards which don't need write-enable code " - "(total: %d):\n\n", boardcount); - print_supported_boards_helper(boards_ok); - - for (i = 0, boardcount = 0; boards_bad[i].vendor != NULL; i++) - boardcount++; - printf("\nBoards which have been verified to NOT work yet " - "(total: %d):\n\n", boardcount); - print_supported_boards_helper(boards_bad); -} - /** * Match boards on coreboot table gathered vendor and part name. * Require main PCI IDs to match too as extra safety. diff --git a/chipset_enable.c b/chipset_enable.c index 72ac367ab..d5fd1c777 100644 --- a/chipset_enable.c +++ b/chipset_enable.c @@ -948,9 +948,6 @@ static int get_flashbase_sc520(struct pci_dev *dev, const char *name) return 0; } -#define OK 0 -#define NT 1 /* Not tested */ - /* Please keep this list alphabetically sorted by vendor/device. */ const struct penable chipset_enables[] = { {0x10B9, 0x1533, OK, "ALi", "M1533", enable_flash_ali_m1533}, @@ -1035,29 +1032,6 @@ const struct penable chipset_enables[] = { {}, }; -void print_supported_chipsets(void) -{ - int i, j, chipsetcount = 0; - const struct penable *c = chipset_enables; - - for (i = 0; c[i].vendor_name != NULL; i++) - chipsetcount++; - - printf("\nSupported chipsets (total: %d):\n\nVendor: " - "Chipset: PCI IDs:\n\n", chipsetcount); - - for (i = 0; c[i].vendor_name != NULL; i++) { - printf("%s", c[i].vendor_name); - for (j = 0; j < 25 - strlen(c[i].vendor_name); j++) - printf(" "); - printf("%s", c[i].device_name); - for (j = 0; j < 25 - strlen(c[i].device_name); j++) - printf(" "); - printf("%04x:%04x%s\n", c[i].vendor_id, c[i].device_id, - (c[i].status == OK) ? "" : " (untested)"); - } -} - int chipset_flash_enable(void) { struct pci_dev *dev = 0; diff --git a/flash.h b/flash.h index b1ee6d392..88dcda247 100644 --- a/flash.h +++ b/flash.h @@ -272,6 +272,12 @@ struct pcidev_status { }; uint32_t pcidev_validate(struct pci_dev *dev, struct pcidev_status *devs); uint32_t pcidev_init(uint16_t vendor_id, struct pcidev_status *devs); + +/* print.c */ +char *flashbuses_to_text(enum chipbustype bustype); +void print_supported_chips(void); +void print_supported_chipsets(void); +void print_supported_boards(void); void print_supported_pcidevs(struct pcidev_status *devs); /* board_enable.c */ @@ -281,12 +287,10 @@ uint8_t sio_read(uint16_t port, uint8_t reg); 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); -void print_supported_boards(void); /* chipset_enable.c */ extern enum chipbustype buses_supported; int chipset_flash_enable(void); -void print_supported_chipsets(void); extern unsigned long flashbase; @@ -376,6 +380,10 @@ int max(int a, int b); int check_erased_range(struct flashchip *flash, int start, int len); int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message); extern char *pcidev_bdf; +char *strcat_realloc(char *dest, const char *src); + +#define OK 0 +#define NT 1 /* Not tested */ /* layout.c */ int show_id(uint8_t *bios, int size, int force); diff --git a/flashrom.c b/flashrom.c index 04e025f19..e1944c92c 100644 --- a/flashrom.c +++ b/flashrom.c @@ -236,37 +236,6 @@ char *strcat_realloc(char *dest, const char *src) return dest; } -/* Return a string corresponding to the bustype parameter. - * Memory is obtained with malloc() and can be freed with free(). - */ -char *flashbuses_to_text(enum chipbustype bustype) -{ - char *ret = calloc(1, 1); - if (bustype == CHIP_BUSTYPE_UNKNOWN) { - ret = strcat_realloc(ret, "Unknown,"); - /* FIXME: Once all chipsets and flash chips have been updated, NONSPI - * will cease to exist and should be eliminated here as well. - */ - } else if (bustype == CHIP_BUSTYPE_NONSPI) { - ret = strcat_realloc(ret, "Non-SPI,"); - } else { - if (bustype & CHIP_BUSTYPE_PARALLEL) - ret = strcat_realloc(ret, "Parallel,"); - if (bustype & CHIP_BUSTYPE_LPC) - ret = strcat_realloc(ret, "LPC,"); - if (bustype & CHIP_BUSTYPE_FWH) - ret = strcat_realloc(ret, "FWH,"); - if (bustype & CHIP_BUSTYPE_SPI) - ret = strcat_realloc(ret, "SPI,"); - if (bustype == CHIP_BUSTYPE_NONE) - ret = strcat_realloc(ret, "None,"); - } - /* Kill last comma. */ - ret[strlen(ret) - 1] = '\0'; - ret = realloc(ret, strlen(ret) + 1); - return ret; -} - /* start is an offset to the base address of the flash chip */ int check_erased_range(struct flashchip *flash, int start, int len) { @@ -511,96 +480,6 @@ int erase_flash(struct flashchip *flash) return 0; } -#ifndef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif -#define POS_PRINT(x) do { pos += strlen(x); printf(x); } while (0) - -static int digits(int n) -{ - int i; - - if (!n) - return 1; - - for (i = 0; n; ++i) - n /= 10; - - return i; -} - -void print_supported_chips(void) -{ - int okcol = 0, pos = 0, i, chipcount = 0; - struct flashchip *f; - - for (f = flashchips; f->name != NULL; f++) { - if (GENERIC_DEVICE_ID == f->model_id) - continue; - okcol = MAX(okcol, strlen(f->vendor) + 1 + strlen(f->name)); - } - okcol = (okcol + 7) & ~7; - - for (f = flashchips; f->name != NULL; f++) - chipcount++; - - printf("\nSupported flash chips (total: %d):\n\n", chipcount); - POS_PRINT("Vendor: Device:"); - while (pos < okcol) { - printf("\t"); - pos += 8 - (pos % 8); - } - - printf("Tested OK:\tKnown BAD: Size/KB: Type:\n\n"); - printf("(P = PROBE, R = READ, E = ERASE, W = WRITE)\n\n"); - - for (f = flashchips; f->name != NULL; f++) { - /* Don't print "unknown XXXX SPI chip" entries. */ - if (!strncmp(f->name, "unknown", 7)) - continue; - - printf("%s", f->vendor); - for (i = 0; i < 10 - strlen(f->vendor); i++) - printf(" "); - printf("%s", f->name); - - pos = 10 + strlen(f->name); - while (pos < okcol) { - printf("\t"); - pos += 8 - (pos % 8); - } - if ((f->tested & TEST_OK_MASK)) { - if ((f->tested & TEST_OK_PROBE)) - POS_PRINT("P "); - if ((f->tested & TEST_OK_READ)) - POS_PRINT("R "); - if ((f->tested & TEST_OK_ERASE)) - POS_PRINT("E "); - if ((f->tested & TEST_OK_WRITE)) - POS_PRINT("W "); - } - while (pos < okcol + 9) { - printf("\t"); - pos += 8 - (pos % 8); - } - if ((f->tested & TEST_BAD_MASK)) { - if ((f->tested & TEST_BAD_PROBE)) - printf("P "); - if ((f->tested & TEST_BAD_READ)) - printf("R "); - if ((f->tested & TEST_BAD_ERASE)) - printf("E "); - if ((f->tested & TEST_BAD_WRITE)) - printf("W "); - } - - printf("\t %d", f->total_size); - for (i = 0; i < 10 - digits(f->total_size); i++) - printf(" "); - printf("%s\n", flashbuses_to_text(f->bustype)); - } -} - void usage(const char *name) { printf("usage: %s [-VfLhR] [-E|-r file|-w file|-v file] [-c chipname] [-s addr]\n" diff --git a/print.c b/print.c new file mode 100644 index 000000000..89a7602ec --- /dev/null +++ b/print.c @@ -0,0 +1,224 @@ +/* + * This file is part of the flashrom project. + * + * Copyright (C) 2009 Uwe Hermann + * Copyright (C) 2009 Carl-Daniel Hailfinger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include "flash.h" +#include "flashchips.h" + +/* + * Return a string corresponding to the bustype parameter. + * Memory is obtained with malloc() and can be freed with free(). + */ +char *flashbuses_to_text(enum chipbustype bustype) +{ + char *ret = calloc(1, 1); + if (bustype == CHIP_BUSTYPE_UNKNOWN) { + ret = strcat_realloc(ret, "Unknown,"); + /* + * FIXME: Once all chipsets and flash chips have been updated, NONSPI + * will cease to exist and should be eliminated here as well. + */ + } else if (bustype == CHIP_BUSTYPE_NONSPI) { + ret = strcat_realloc(ret, "Non-SPI,"); + } else { + if (bustype & CHIP_BUSTYPE_PARALLEL) + ret = strcat_realloc(ret, "Parallel,"); + if (bustype & CHIP_BUSTYPE_LPC) + ret = strcat_realloc(ret, "LPC,"); + if (bustype & CHIP_BUSTYPE_FWH) + ret = strcat_realloc(ret, "FWH,"); + if (bustype & CHIP_BUSTYPE_SPI) + ret = strcat_realloc(ret, "SPI,"); + if (bustype == CHIP_BUSTYPE_NONE) + ret = strcat_realloc(ret, "None,"); + } + /* Kill last comma. */ + ret[strlen(ret) - 1] = '\0'; + ret = realloc(ret, strlen(ret) + 1); + return ret; +} + +#define POS_PRINT(x) do { pos += strlen(x); printf(x); } while (0) + +static int digits(int n) +{ + int i; + + if (!n) + return 1; + + for (i = 0; n; ++i) + n /= 10; + + return i; +} + +void print_supported_chips(void) +{ + int okcol = 0, pos = 0, i, chipcount = 0; + struct flashchip *f; + + for (f = flashchips; f->name != NULL; f++) { + if (GENERIC_DEVICE_ID == f->model_id) + continue; + okcol = max(okcol, strlen(f->vendor) + 1 + strlen(f->name)); + } + okcol = (okcol + 7) & ~7; + + for (f = flashchips; f->name != NULL; f++) + chipcount++; + + printf("\nSupported flash chips (total: %d):\n\n", chipcount); + POS_PRINT("Vendor: Device:"); + while (pos < okcol) { + printf("\t"); + pos += 8 - (pos % 8); + } + + printf("Tested OK:\tKnown BAD: Size/KB: Type:\n\n"); + printf("(P = PROBE, R = READ, E = ERASE, W = WRITE)\n\n"); + + for (f = flashchips; f->name != NULL; f++) { + /* Don't print "unknown XXXX SPI chip" entries. */ + if (!strncmp(f->name, "unknown", 7)) + continue; + + printf("%s", f->vendor); + for (i = 0; i < 10 - strlen(f->vendor); i++) + printf(" "); + printf("%s", f->name); + + pos = 10 + strlen(f->name); + while (pos < okcol) { + printf("\t"); + pos += 8 - (pos % 8); + } + if ((f->tested & TEST_OK_MASK)) { + if ((f->tested & TEST_OK_PROBE)) + POS_PRINT("P "); + if ((f->tested & TEST_OK_READ)) + POS_PRINT("R "); + if ((f->tested & TEST_OK_ERASE)) + POS_PRINT("E "); + if ((f->tested & TEST_OK_WRITE)) + POS_PRINT("W "); + } + while (pos < okcol + 9) { + printf("\t"); + pos += 8 - (pos % 8); + } + if ((f->tested & TEST_BAD_MASK)) { + if ((f->tested & TEST_BAD_PROBE)) + printf("P "); + if ((f->tested & TEST_BAD_READ)) + printf("R "); + if ((f->tested & TEST_BAD_ERASE)) + printf("E "); + if ((f->tested & TEST_BAD_WRITE)) + printf("W "); + } + + printf("\t %d", f->total_size); + for (i = 0; i < 10 - digits(f->total_size); i++) + printf(" "); + printf("%s\n", flashbuses_to_text(f->bustype)); + } +} + +void print_supported_chipsets(void) +{ + int i, j, chipsetcount = 0; + const struct penable *c = chipset_enables; + + for (i = 0; c[i].vendor_name != NULL; i++) + chipsetcount++; + + printf("\nSupported chipsets (total: %d):\n\nVendor: " + "Chipset: PCI IDs:\n\n", chipsetcount); + + for (i = 0; c[i].vendor_name != NULL; i++) { + printf("%s", c[i].vendor_name); + for (j = 0; j < 25 - strlen(c[i].vendor_name); j++) + printf(" "); + printf("%s", c[i].device_name); + for (j = 0; j < 25 - strlen(c[i].device_name); j++) + printf(" "); + printf("%04x:%04x%s\n", c[i].vendor_id, c[i].device_id, + (c[i].status == OK) ? "" : " (untested)"); + } +} + +void print_supported_boards_helper(const struct board_info *b) +{ + int i, j, boardcount = 0; + + for (i = 0; b[i].vendor != NULL; i++) + boardcount++; + + for (i = 0; b[i].vendor != NULL; i++) { + printf("%s", b[i].vendor); + for (j = 0; j < 25 - strlen(b[i].vendor); j++) + printf(" "); + printf("%s", b[i].name); + for (j = 0; j < 23 - strlen(b[i].name); j++) + printf(" "); + printf("\n"); + } +} + +void print_supported_boards(void) +{ + int i, j, boardcount = 0; + struct board_pciid_enable *b = board_pciid_enables; + + for (i = 0; b[i].vendor_name != NULL; i++) + boardcount++; + + printf("\nSupported boards which need write-enable code (total: %d):" + "\n\nVendor: Board: " + "Required option:\n\n", boardcount); + + for (i = 0; b[i].vendor_name != NULL; i++) { + printf("%s", b[i].vendor_name); + for (j = 0; j < 25 - strlen(b[i].vendor_name); j++) + printf(" "); + printf("%s", b[i].board_name); + for (j = 0; j < 25 - strlen(b[i].board_name); j++) + printf(" "); + if (b[i].lb_vendor != NULL) + printf("-m %s:%s\n", b[i].lb_vendor, b[i].lb_part); + else + printf("(none, board is autodetected)\n"); + } + + for (i = 0, boardcount = 0; boards_ok[i].vendor != NULL; i++) + boardcount++; + printf("\nSupported boards which don't need write-enable code " + "(total: %d):\n\n", boardcount); + print_supported_boards_helper(boards_ok); + + for (i = 0, boardcount = 0; boards_bad[i].vendor != NULL; i++) + boardcount++; + printf("\nBoards which have been verified to NOT work yet " + "(total: %d):\n\n", boardcount); + print_supported_boards_helper(boards_bad); +}