1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

Constify flashchips array

This moves 99.5% of the .data section to .rodata (which ends up in .text).

Corresponding to flashrom svn r1293.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
Carl-Daniel Hailfinger 2011-05-04 00:39:50 +00:00
parent 54ce73a1f5
commit 4c82318e4a
7 changed files with 53 additions and 40 deletions

View File

@ -100,7 +100,11 @@ int cli_classic(int argc, char *argv[])
{ {
unsigned long size; unsigned long size;
/* Probe for up to three flash chips. */ /* Probe for up to three flash chips. */
struct flashchip *flash, *flashes[3]; const struct flashchip *flash;
struct flashchip flashes[3];
struct flashchip *fill_flash;
int startchip = 0;
int chipcount = 0;
const char *name; const char *name;
int namelen; int namelen;
int opt; int opt;
@ -359,49 +363,47 @@ int cli_classic(int argc, char *argv[])
exit(1); exit(1);
} }
/* FIXME: Delay calibration should happen in programmer code. */
for (i = 0; i < ARRAY_SIZE(flashes); i++) { for (i = 0; i < ARRAY_SIZE(flashes); i++) {
flashes[i] = startchip = probe_flash(startchip, &flashes[i], 0);
probe_flash(i ? flashes[i - 1] + 1 : flashchips, 0); if (startchip == -1)
if (!flashes[i]) break;
for (i++; i < ARRAY_SIZE(flashes); i++) chipcount++;
flashes[i] = NULL;
} }
if (flashes[1]) { if (chipcount > 1) {
printf("Multiple flash chips were detected:"); printf("Multiple flash chips were detected:");
for (i = 0; i < ARRAY_SIZE(flashes) && flashes[i]; i++) for (i = 0; i < chipcount; i++)
printf(" %s", flashes[i]->name); printf(" %s", flashes[i].name);
printf("\nPlease specify which chip to use with the -c <chipname> option.\n"); printf("\nPlease specify which chip to use with the -c <chipname> option.\n");
programmer_shutdown(); programmer_shutdown();
exit(1); exit(1);
} else if (!flashes[0]) { } else if (!chipcount) {
printf("No EEPROM/flash device found.\n"); printf("No EEPROM/flash device found.\n");
if (!force || !chip_to_probe) { if (!force || !chip_to_probe) {
printf("Note: flashrom can never write if the flash chip isn't found automatically.\n"); printf("Note: flashrom can never write if the flash chip isn't found automatically.\n");
} }
if (force && read_it && chip_to_probe) { if (force && read_it && chip_to_probe) {
printf("Force read (-f -r -c) requested, pretending the chip is there:\n"); printf("Force read (-f -r -c) requested, pretending the chip is there:\n");
flashes[0] = probe_flash(flashchips, 1); startchip = probe_flash(0, &flashes[0], 1);
if (!flashes[0]) { if (startchip == -1) {
printf("Probing for flash chip '%s' failed.\n", chip_to_probe); printf("Probing for flash chip '%s' failed.\n", chip_to_probe);
programmer_shutdown(); programmer_shutdown();
exit(1); exit(1);
} }
printf("Please note that forced reads most likely contain garbage.\n"); printf("Please note that forced reads most likely contain garbage.\n");
return read_flash_to_file(flashes[0], filename); return read_flash_to_file(&flashes[0], filename);
} }
// FIXME: flash writes stay enabled! // FIXME: flash writes stay enabled!
programmer_shutdown(); programmer_shutdown();
exit(1); exit(1);
} }
flash = flashes[0]; fill_flash = &flashes[0];
check_chip_supported(flash); check_chip_supported(fill_flash);
size = flash->total_size * 1024; size = fill_flash->total_size * 1024;
if (check_max_decode((buses_supported & flash->bustype), size) && if (check_max_decode((buses_supported & fill_flash->bustype), size) &&
(!force)) { (!force)) {
fprintf(stderr, "Chip is too big for this programmer " fprintf(stderr, "Chip is too big for this programmer "
"(-V gives details). Use --force to override.\n"); "(-V gives details). Use --force to override.\n");
@ -432,5 +434,5 @@ int cli_classic(int argc, char *argv[])
* Give the chip time to settle. * Give the chip time to settle.
*/ */
programmer_delay(100000); programmer_delay(100000);
return doit(flash, force, filename, read_it, write_it, erase_it, verify_it); return doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it);
} }

View File

@ -173,7 +173,7 @@ struct flashchip {
#define TIMING_IGNORED -1 #define TIMING_IGNORED -1
#define TIMING_ZERO -2 #define TIMING_ZERO -2
extern struct flashchip flashchips[]; extern const struct flashchip flashchips[];
/* print.c */ /* print.c */
char *flashbuses_to_text(enum chipbustype bustype); char *flashbuses_to_text(enum chipbustype bustype);
@ -193,7 +193,7 @@ extern char *chip_to_probe;
void map_flash_registers(struct flashchip *flash); void map_flash_registers(struct flashchip *flash);
int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len); int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
int erase_flash(struct flashchip *flash); int erase_flash(struct flashchip *flash);
struct flashchip *probe_flash(struct flashchip *first_flash, int force); int probe_flash(int startchip, struct flashchip *fill_flash, int force);
int read_flash_to_file(struct flashchip *flash, char *filename); int read_flash_to_file(struct flashchip *flash, char *filename);
int min(int a, int b); int min(int a, int b);
int max(int a, int b); int max(int a, int b);

View File

@ -32,7 +32,7 @@
* Please keep the list sorted by vendor name and chip name, so that * Please keep the list sorted by vendor name and chip name, so that
* the output of 'flashrom -L' is alphabetically sorted. * the output of 'flashrom -L' is alphabetically sorted.
*/ */
struct flashchip flashchips[] = { const struct flashchip flashchips[] = {
/* /*
* .vendor = Vendor name * .vendor = Vendor name

View File

@ -1109,16 +1109,16 @@ int check_max_decode(enum chipbustype buses, uint32_t size)
return 1; return 1;
} }
struct flashchip *probe_flash(struct flashchip *first_flash, int force) int probe_flash(int startchip, struct flashchip *fill_flash, int force)
{ {
struct flashchip *flash; const struct flashchip *flash;
unsigned long base = 0; unsigned long base = 0;
char location[64]; char location[64];
uint32_t size; uint32_t size;
enum chipbustype buses_common; enum chipbustype buses_common;
char *tmp; char *tmp;
for (flash = first_flash; flash && flash->name; flash++) { for (flash = flashchips + startchip; flash && flash->name; flash++) {
if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0)
continue; continue;
msg_gdbg("Probing for %s %s, %d KB: ", msg_gdbg("Probing for %s %s, %d KB: ",
@ -1145,25 +1145,35 @@ struct flashchip *probe_flash(struct flashchip *first_flash, int force)
size = flash->total_size * 1024; size = flash->total_size * 1024;
check_max_decode(buses_common, size); check_max_decode(buses_common, size);
/* Start filling in the dynamic data. */
*fill_flash = *flash;
base = flashbase ? flashbase : (0xffffffff - size + 1); base = flashbase ? flashbase : (0xffffffff - size + 1);
flash->virtual_memory = (chipaddr)programmer_map_flash_region("flash chip", base, size); fill_flash->virtual_memory = (chipaddr)programmer_map_flash_region("flash chip", base, size);
if (force) if (force)
break; break;
if (flash->probe(flash) != 1) if (fill_flash->probe(fill_flash) != 1)
goto notfound; goto notfound;
if (first_flash == flashchips /* If this is the first chip found, accept it.
|| flash->model_id != GENERIC_DEVICE_ID) * If this is not the first chip found, accept it only if it is
* a non-generic match.
* We could either make chipcount global or provide it as
* parameter, or we assume that startchip==0 means this call to
* probe_flash() is the first one and thus no chip has been
* found before.
*/
if (startchip == 0 || fill_flash->model_id != GENERIC_DEVICE_ID)
break; break;
notfound: notfound:
programmer_unmap_flash_region((void *)flash->virtual_memory, size); programmer_unmap_flash_region((void *)fill_flash->virtual_memory, size);
} }
if (!flash || !flash->name) if (!flash || !flash->name)
return NULL; return -1;
#if CONFIG_INTERNAL == 1 #if CONFIG_INTERNAL == 1
if (programmer_table[programmer].map_flash_region == physmap) if (programmer_table[programmer].map_flash_region == physmap)
@ -1181,10 +1191,11 @@ notfound:
* may be stored in registers, so avoid lock info printing. * may be stored in registers, so avoid lock info printing.
*/ */
if (!force) if (!force)
if (flash->printlock) if (fill_flash->printlock)
flash->printlock(flash); fill_flash->printlock(fill_flash);
return flash; /* Return position of matching chip. */
return flash - flashchips;
} }
int verify_flash(struct flashchip *flash, uint8_t *buf) int verify_flash(struct flashchip *flash, uint8_t *buf)
@ -1293,7 +1304,7 @@ out_free:
* walk_eraseregions(). * walk_eraseregions().
* Even if an error is found, the function will keep going and check the rest. * Even if an error is found, the function will keep going and check the rest.
*/ */
static int selfcheck_eraseblocks(struct flashchip *flash) static int selfcheck_eraseblocks(const struct flashchip *flash)
{ {
int i, j, k; int i, j, k;
int ret = 0; int ret = 0;
@ -1670,7 +1681,7 @@ void print_banner(void)
int selfcheck(void) int selfcheck(void)
{ {
int ret = 0; int ret = 0;
struct flashchip *flash; const struct flashchip *flash;
/* Safety check. Instead of aborting after the first error, check /* Safety check. Instead of aborting after the first error, check
* if more errors exist. * if more errors exist.
@ -1689,7 +1700,7 @@ int selfcheck(void)
return ret; return ret;
} }
void check_chip_supported(struct flashchip *flash) void check_chip_supported(const struct flashchip *flash)
{ {
if (TEST_OK_MASK != (flash->tested & TEST_OK_MASK)) { if (TEST_OK_MASK != (flash->tested & TEST_OK_MASK)) {
msg_cinfo("===\n"); msg_cinfo("===\n");

View File

@ -78,7 +78,7 @@ static void print_supported_chips(void)
{ {
int okcol = 0, pos = 0, i, chipcount = 0; int okcol = 0, pos = 0, i, chipcount = 0;
int maxchiplen = 0, maxvendorlen = 0; int maxchiplen = 0, maxvendorlen = 0;
struct flashchip *f; const struct flashchip *f;
for (f = flashchips; f->name != NULL; f++) { for (f = flashchips; f->name != NULL; f++) {
/* Ignore "unknown XXXX SPI chip" entries. */ /* Ignore "unknown XXXX SPI chip" entries. */

View File

@ -201,7 +201,7 @@ static void print_supported_boards_wiki(void)
static void print_supported_chips_wiki(int cols) static void print_supported_chips_wiki(int cols)
{ {
int i = 0, c = 1, chipcount = 0; int i = 0, c = 1, chipcount = 0;
struct flashchip *f, *old = NULL; const struct flashchip *f, *old = NULL;
uint32_t t; uint32_t t;
for (f = flashchips; f->name != NULL; f++) for (f = flashchips; f->name != NULL; f++)

View File

@ -515,7 +515,7 @@ struct decode_sizes {
extern struct decode_sizes max_rom_decode; extern struct decode_sizes max_rom_decode;
extern int programmer_may_write; extern int programmer_may_write;
extern unsigned long flashbase; extern unsigned long flashbase;
void check_chip_supported(struct flashchip *flash); void check_chip_supported(const struct flashchip *flash);
int check_max_decode(enum chipbustype buses, uint32_t size); int check_max_decode(enum chipbustype buses, uint32_t size);
char *extract_programmer_param(char *param_name); char *extract_programmer_param(char *param_name);