Uwe Hermann | ba290d1 | 2009-06-17 12:07:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de> |
| 5 | * Copyright (C) 2009 Carl-Daniel Hailfinger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include <string.h> |
| 23 | #include <stdlib.h> |
| 24 | #include "flash.h" |
| 25 | #include "flashchips.h" |
| 26 | |
| 27 | /* |
| 28 | * Return a string corresponding to the bustype parameter. |
| 29 | * Memory is obtained with malloc() and can be freed with free(). |
| 30 | */ |
| 31 | char *flashbuses_to_text(enum chipbustype bustype) |
| 32 | { |
| 33 | char *ret = calloc(1, 1); |
| 34 | if (bustype == CHIP_BUSTYPE_UNKNOWN) { |
| 35 | ret = strcat_realloc(ret, "Unknown,"); |
| 36 | /* |
| 37 | * FIXME: Once all chipsets and flash chips have been updated, NONSPI |
| 38 | * will cease to exist and should be eliminated here as well. |
| 39 | */ |
| 40 | } else if (bustype == CHIP_BUSTYPE_NONSPI) { |
| 41 | ret = strcat_realloc(ret, "Non-SPI,"); |
| 42 | } else { |
| 43 | if (bustype & CHIP_BUSTYPE_PARALLEL) |
| 44 | ret = strcat_realloc(ret, "Parallel,"); |
| 45 | if (bustype & CHIP_BUSTYPE_LPC) |
| 46 | ret = strcat_realloc(ret, "LPC,"); |
| 47 | if (bustype & CHIP_BUSTYPE_FWH) |
| 48 | ret = strcat_realloc(ret, "FWH,"); |
| 49 | if (bustype & CHIP_BUSTYPE_SPI) |
| 50 | ret = strcat_realloc(ret, "SPI,"); |
| 51 | if (bustype == CHIP_BUSTYPE_NONE) |
| 52 | ret = strcat_realloc(ret, "None,"); |
| 53 | } |
| 54 | /* Kill last comma. */ |
| 55 | ret[strlen(ret) - 1] = '\0'; |
| 56 | ret = realloc(ret, strlen(ret) + 1); |
| 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | #define POS_PRINT(x) do { pos += strlen(x); printf(x); } while (0) |
| 61 | |
| 62 | static int digits(int n) |
| 63 | { |
| 64 | int i; |
| 65 | |
| 66 | if (!n) |
| 67 | return 1; |
| 68 | |
| 69 | for (i = 0; n; ++i) |
| 70 | n /= 10; |
| 71 | |
| 72 | return i; |
| 73 | } |
| 74 | |
| 75 | void print_supported_chips(void) |
| 76 | { |
| 77 | int okcol = 0, pos = 0, i, chipcount = 0; |
| 78 | struct flashchip *f; |
| 79 | |
| 80 | for (f = flashchips; f->name != NULL; f++) { |
| 81 | if (GENERIC_DEVICE_ID == f->model_id) |
| 82 | continue; |
| 83 | okcol = max(okcol, strlen(f->vendor) + 1 + strlen(f->name)); |
| 84 | } |
| 85 | okcol = (okcol + 7) & ~7; |
| 86 | |
| 87 | for (f = flashchips; f->name != NULL; f++) |
| 88 | chipcount++; |
| 89 | |
| 90 | printf("\nSupported flash chips (total: %d):\n\n", chipcount); |
| 91 | POS_PRINT("Vendor: Device:"); |
| 92 | while (pos < okcol) { |
| 93 | printf("\t"); |
| 94 | pos += 8 - (pos % 8); |
| 95 | } |
| 96 | |
| 97 | printf("Tested OK:\tKnown BAD: Size/KB: Type:\n\n"); |
| 98 | printf("(P = PROBE, R = READ, E = ERASE, W = WRITE)\n\n"); |
| 99 | |
| 100 | for (f = flashchips; f->name != NULL; f++) { |
| 101 | /* Don't print "unknown XXXX SPI chip" entries. */ |
| 102 | if (!strncmp(f->name, "unknown", 7)) |
| 103 | continue; |
| 104 | |
| 105 | printf("%s", f->vendor); |
| 106 | for (i = 0; i < 10 - strlen(f->vendor); i++) |
| 107 | printf(" "); |
| 108 | printf("%s", f->name); |
| 109 | |
| 110 | pos = 10 + strlen(f->name); |
| 111 | while (pos < okcol) { |
| 112 | printf("\t"); |
| 113 | pos += 8 - (pos % 8); |
| 114 | } |
| 115 | if ((f->tested & TEST_OK_MASK)) { |
| 116 | if ((f->tested & TEST_OK_PROBE)) |
| 117 | POS_PRINT("P "); |
| 118 | if ((f->tested & TEST_OK_READ)) |
| 119 | POS_PRINT("R "); |
| 120 | if ((f->tested & TEST_OK_ERASE)) |
| 121 | POS_PRINT("E "); |
| 122 | if ((f->tested & TEST_OK_WRITE)) |
| 123 | POS_PRINT("W "); |
| 124 | } |
| 125 | while (pos < okcol + 9) { |
| 126 | printf("\t"); |
| 127 | pos += 8 - (pos % 8); |
| 128 | } |
| 129 | if ((f->tested & TEST_BAD_MASK)) { |
| 130 | if ((f->tested & TEST_BAD_PROBE)) |
| 131 | printf("P "); |
| 132 | if ((f->tested & TEST_BAD_READ)) |
| 133 | printf("R "); |
| 134 | if ((f->tested & TEST_BAD_ERASE)) |
| 135 | printf("E "); |
| 136 | if ((f->tested & TEST_BAD_WRITE)) |
| 137 | printf("W "); |
| 138 | } |
| 139 | |
| 140 | printf("\t %d", f->total_size); |
| 141 | for (i = 0; i < 10 - digits(f->total_size); i++) |
| 142 | printf(" "); |
| 143 | printf("%s\n", flashbuses_to_text(f->bustype)); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void print_supported_chipsets(void) |
| 148 | { |
| 149 | int i, j, chipsetcount = 0; |
| 150 | const struct penable *c = chipset_enables; |
| 151 | |
| 152 | for (i = 0; c[i].vendor_name != NULL; i++) |
| 153 | chipsetcount++; |
| 154 | |
| 155 | printf("\nSupported chipsets (total: %d):\n\nVendor: " |
| 156 | "Chipset: PCI IDs:\n\n", chipsetcount); |
| 157 | |
| 158 | for (i = 0; c[i].vendor_name != NULL; i++) { |
| 159 | printf("%s", c[i].vendor_name); |
| 160 | for (j = 0; j < 25 - strlen(c[i].vendor_name); j++) |
| 161 | printf(" "); |
| 162 | printf("%s", c[i].device_name); |
| 163 | for (j = 0; j < 25 - strlen(c[i].device_name); j++) |
| 164 | printf(" "); |
| 165 | printf("%04x:%04x%s\n", c[i].vendor_id, c[i].device_id, |
| 166 | (c[i].status == OK) ? "" : " (untested)"); |
| 167 | } |
| 168 | } |
| 169 | |
Uwe Hermann | e1aa75e | 2009-06-18 14:04:44 +0000 | [diff] [blame^] | 170 | void print_supported_boards_helper(const struct board_info *b, const char *msg) |
Uwe Hermann | ba290d1 | 2009-06-17 12:07:12 +0000 | [diff] [blame] | 171 | { |
| 172 | int i, j, boardcount = 0; |
| 173 | |
| 174 | for (i = 0; b[i].vendor != NULL; i++) |
| 175 | boardcount++; |
| 176 | |
Uwe Hermann | e1aa75e | 2009-06-18 14:04:44 +0000 | [diff] [blame^] | 177 | printf("\n%s (total: %d):\n\n", msg, boardcount); |
| 178 | |
Uwe Hermann | ba290d1 | 2009-06-17 12:07:12 +0000 | [diff] [blame] | 179 | for (i = 0; b[i].vendor != NULL; i++) { |
| 180 | printf("%s", b[i].vendor); |
| 181 | for (j = 0; j < 25 - strlen(b[i].vendor); j++) |
| 182 | printf(" "); |
| 183 | printf("%s", b[i].name); |
| 184 | for (j = 0; j < 23 - strlen(b[i].name); j++) |
| 185 | printf(" "); |
| 186 | printf("\n"); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void print_supported_boards(void) |
| 191 | { |
| 192 | int i, j, boardcount = 0; |
| 193 | struct board_pciid_enable *b = board_pciid_enables; |
| 194 | |
| 195 | for (i = 0; b[i].vendor_name != NULL; i++) |
| 196 | boardcount++; |
| 197 | |
| 198 | printf("\nSupported boards which need write-enable code (total: %d):" |
| 199 | "\n\nVendor: Board: " |
| 200 | "Required option:\n\n", boardcount); |
| 201 | |
| 202 | for (i = 0; b[i].vendor_name != NULL; i++) { |
| 203 | printf("%s", b[i].vendor_name); |
| 204 | for (j = 0; j < 25 - strlen(b[i].vendor_name); j++) |
| 205 | printf(" "); |
| 206 | printf("%s", b[i].board_name); |
| 207 | for (j = 0; j < 25 - strlen(b[i].board_name); j++) |
| 208 | printf(" "); |
| 209 | if (b[i].lb_vendor != NULL) |
| 210 | printf("-m %s:%s\n", b[i].lb_vendor, b[i].lb_part); |
| 211 | else |
| 212 | printf("(none, board is autodetected)\n"); |
| 213 | } |
| 214 | |
Uwe Hermann | e1aa75e | 2009-06-18 14:04:44 +0000 | [diff] [blame^] | 215 | print_supported_boards_helper(boards_ok, |
| 216 | "Supported boards which don't need write-enable code"); |
| 217 | print_supported_boards_helper(boards_bad, |
| 218 | "Boards which have been verified to NOT work yet"); |
| 219 | print_supported_boards_helper(laptops_ok, |
| 220 | "Laptops which have been verified to work"); |
| 221 | print_supported_boards_helper(laptops_bad, |
| 222 | "Laptops which have been verified to NOT work yet"); |
Uwe Hermann | ba290d1 | 2009-06-17 12:07:12 +0000 | [diff] [blame] | 223 | } |