Author: uwe Date: 2009-06-17 14:07:12 +0200 (Wed, 17 Jun 2009) New Revision: 601
Added: trunk/print.c Modified: trunk/Makefile trunk/board_enable.c trunk/chipset_enable.c trunk/flash.h trunk/flashrom.c Log: Move all printing code to print.c.
Drop no longer needed MAX macro, we have a max() function.
Signed-off-by: Uwe Hermann uwe@hermann-uwe.de Acked-by: Uwe Hermann uwe@hermann-uwe.de
Modified: trunk/Makefile =================================================================== --- trunk/Makefile 2009-06-17 10:13:42 UTC (rev 600) +++ trunk/Makefile 2009-06-17 12:07:12 UTC (rev 601) @@ -49,7 +49,7 @@ 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)
Modified: trunk/board_enable.c =================================================================== --- trunk/board_enable.c 2009-06-17 10:13:42 UTC (rev 600) +++ trunk/board_enable.c 2009-06-17 12:07:12 UTC (rev 601) @@ -827,62 +827,6 @@ {}, };
-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.
Modified: trunk/chipset_enable.c =================================================================== --- trunk/chipset_enable.c 2009-06-17 10:13:42 UTC (rev 600) +++ trunk/chipset_enable.c 2009-06-17 12:07:12 UTC (rev 601) @@ -948,9 +948,6 @@ 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 @@ {}, };
-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;
Modified: trunk/flash.h =================================================================== --- trunk/flash.h 2009-06-17 10:13:42 UTC (rev 600) +++ trunk/flash.h 2009-06-17 12:07:12 UTC (rev 601) @@ -272,6 +272,12 @@ }; 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 @@ 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,7 +380,11 @@ 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); int read_romlayout(char *name);
Modified: trunk/flashrom.c =================================================================== --- trunk/flashrom.c 2009-06-17 10:13:42 UTC (rev 600) +++ trunk/flashrom.c 2009-06-17 12:07:12 UTC (rev 601) @@ -236,37 +236,6 @@ 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 @@ 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"
Added: trunk/print.c =================================================================== --- trunk/print.c (rev 0) +++ trunk/print.c 2009-06-17 12:07:12 UTC (rev 601) @@ -0,0 +1,224 @@ +/* + * This file is part of the flashrom project. + * + * Copyright (C) 2009 Uwe Hermann uwe@hermann-uwe.de + * 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 <string.h> +#include <stdlib.h> +#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); +}