Add manufacturer_id and model_id as probe function parameters instead of accessing them directly.
This serves three goals: - Allow multiple sets of IDs per flash chip (needed for pretty much every SPI chip). - Prepare for returning the ID instead of returning a match/mismatch decision. - Prepare for the elimination of a sizable amount of probe functions which are simple duplicates after the changes above.
I used Coccinelle to create this patch. Please note that this needs further changes in spi.c and stm50flw0x0x.c which can built on this patch.
Comments and design reviews highly appreciated.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-probe_params_manuf_model/flash.h =================================================================== --- flashrom-probe_params_manuf_model/flash.h (Revision 551) +++ flashrom-probe_params_manuf_model/flash.h (Arbeitskopie) @@ -139,7 +139,7 @@ */ uint32_t tested;
- int (*probe) (struct flashchip *flash); + int (*probe) (struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int (*erase) (struct flashchip *flash); int (*write) (struct flashchip *flash, uint8_t *buf); int (*read) (struct flashchip *flash, uint8_t *buf); @@ -692,10 +692,10 @@ extern char *lb_part, *lb_vendor;
/* spi.c */ -int probe_spi_rdid(struct flashchip *flash); -int probe_spi_rdid4(struct flashchip *flash); -int probe_spi_rems(struct flashchip *flash); -int probe_spi_res(struct flashchip *flash); +int probe_spi_rdid(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); +int probe_spi_rdid4(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); +int probe_spi_rems(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); +int probe_spi_res(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); int spi_write_enable(void); @@ -717,17 +717,17 @@ uint32_t spi_get_valid_read_addr(void);
/* 82802ab.c */ -int probe_82802ab(struct flashchip *flash); +int probe_82802ab(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_82802ab(struct flashchip *flash); int write_82802ab(struct flashchip *flash, uint8_t *buf);
/* am29f040b.c */ -int probe_29f040b(struct flashchip *flash); +int probe_29f040b(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_29f040b(struct flashchip *flash); int write_29f040b(struct flashchip *flash, uint8_t *buf);
/* en29f002a.c */ -int probe_en29f002a(struct flashchip *flash); +int probe_en29f002a(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_en29f002a(struct flashchip *flash); int write_en29f002a(struct flashchip *flash, uint8_t *buf);
@@ -765,7 +765,7 @@ void protect_jedec(chipaddr bios); int write_byte_program_jedec(chipaddr bios, uint8_t *src, chipaddr dst); -int probe_jedec(struct flashchip *flash); +int probe_jedec(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_chip_jedec(struct flashchip *flash); int write_jedec(struct flashchip *flash, uint8_t *buf); int erase_sector_jedec(chipaddr bios, unsigned int page); @@ -779,7 +779,7 @@ int write_m29f002b(struct flashchip *flash, uint8_t *buf);
/* m29f400bt.c */ -int probe_m29f400bt(struct flashchip *flash); +int probe_m29f400bt(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_m29f400bt(struct flashchip *flash); int block_erase_m29f400bt(chipaddr bios, chipaddr dst); @@ -792,17 +792,17 @@ chipaddr dst, int page_size);
/* mx29f002.c */ -int probe_29f002(struct flashchip *flash); +int probe_29f002(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_29f002(struct flashchip *flash); int write_29f002(struct flashchip *flash, uint8_t *buf);
/* pm49fl00x.c */ -int probe_49fl00x(struct flashchip *flash); +int probe_49fl00x(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_49fl00x(struct flashchip *flash); int write_49fl00x(struct flashchip *flash, uint8_t *buf);
/* sharplhf00l04.c */ -int probe_lhf00l04(struct flashchip *flash); +int probe_lhf00l04(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_lhf00l04(struct flashchip *flash); int write_lhf00l04(struct flashchip *flash, uint8_t *buf); void toggle_ready_lhf00l04(chipaddr dst); @@ -810,7 +810,7 @@ void protect_lhf00l04(chipaddr bios);
/* sst28sf040.c */ -int probe_28sf040(struct flashchip *flash); +int probe_28sf040(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_28sf040(struct flashchip *flash); int write_28sf040(struct flashchip *flash, uint8_t *buf);
@@ -823,27 +823,27 @@ int write_49lf040(struct flashchip *flash, uint8_t *buf);
/* sst49lfxxxc.c */ -int probe_49lfxxxc(struct flashchip *flash); +int probe_49lfxxxc(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_49lfxxxc(struct flashchip *flash); int write_49lfxxxc(struct flashchip *flash, uint8_t *buf);
/* sst_fwhub.c */ -int probe_sst_fwhub(struct flashchip *flash); +int probe_sst_fwhub(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_sst_fwhub(struct flashchip *flash); int write_sst_fwhub(struct flashchip *flash, uint8_t *buf);
/* w39v040c.c */ -int probe_w39v040c(struct flashchip *flash); +int probe_w39v040c(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_w39v040c(struct flashchip *flash); int write_w39v040c(struct flashchip *flash, uint8_t *buf);
/* w39V080fa.c */ -int probe_winbond_fwhub(struct flashchip *flash); +int probe_winbond_fwhub(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_winbond_fwhub(struct flashchip *flash); int write_winbond_fwhub(struct flashchip *flash, uint8_t *buf);
/* w29ee011.c */ -int probe_w29ee011(struct flashchip *flash); +int probe_w29ee011(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id);
/* w49f002u.c */ int write_49f002(struct flashchip *flash, uint8_t *buf); @@ -855,7 +855,7 @@ int wbsio_spi_write_1(struct flashchip *flash, uint8_t *buf);
/* stm50flw0x0x.c */ -int probe_stm50flw0x0x(struct flashchip *flash); +int probe_stm50flw0x0x(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id); int erase_stm50flw0x0x(struct flashchip *flash); int write_stm50flw0x0x(struct flashchip *flash, uint8_t *buf);
Index: flashrom-probe_params_manuf_model/pm49fl00x.c =================================================================== --- flashrom-probe_params_manuf_model/pm49fl00x.c (Revision 551) +++ flashrom-probe_params_manuf_model/pm49fl00x.c (Arbeitskopie) @@ -38,9 +38,9 @@ } }
-int probe_49fl00x(struct flashchip *flash) +int probe_49fl00x(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { - int ret = probe_jedec(flash); + int ret = probe_jedec(flash, manufacture_id, model_id);
if (ret == 1) map_flash_registers(flash); Index: flashrom-probe_params_manuf_model/en29f002a.c =================================================================== --- flashrom-probe_params_manuf_model/en29f002a.c (Revision 551) +++ flashrom-probe_params_manuf_model/en29f002a.c (Arbeitskopie) @@ -28,7 +28,7 @@
#include "flash.h"
-int probe_en29f512(struct flashchip *flash) +int probe_en29f512(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -49,7 +49,7 @@
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
- if (id1 == flash->manufacture_id && id2 == flash->model_id) + if (id1 == manufacture_id && id2 == model_id) return 1;
return 0; @@ -61,7 +61,7 @@ */
/* This does not seem to function properly for EN29F002NT. */ -int probe_en29f002a(struct flashchip *flash) +int probe_en29f002a(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -82,7 +82,7 @@
printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
- if (id1 == flash->manufacture_id && id2 == flash->model_id) + if (id1 == manufacture_id && id2 == model_id) return 1;
return 0; Index: flashrom-probe_params_manuf_model/jedec.c =================================================================== --- flashrom-probe_params_manuf_model/jedec.c (Revision 551) +++ flashrom-probe_params_manuf_model/jedec.c (Arbeitskopie) @@ -85,7 +85,7 @@ usleep(200); }
-int probe_jedec(struct flashchip *flash) +int probe_jedec(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -153,7 +153,7 @@ printf_debug(", id2 is normal flash content");
printf_debug("\n"); - if (largeid1 == flash->manufacture_id && largeid2 == flash->model_id) + if (largeid1 == manufacture_id && largeid2 == model_id) return 1;
return 0; Index: flashrom-probe_params_manuf_model/w29ee011.c =================================================================== --- flashrom-probe_params_manuf_model/w29ee011.c (Revision 551) +++ flashrom-probe_params_manuf_model/w29ee011.c (Arbeitskopie) @@ -21,7 +21,7 @@ #include <string.h> #include "flash.h"
-int probe_w29ee011(struct flashchip *flash) +int probe_w29ee011(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -64,7 +64,7 @@
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
- if (id1 == flash->manufacture_id && id2 == flash->model_id) + if (id1 == manufacture_id && id2 == model_id) return 1;
return 0; Index: flashrom-probe_params_manuf_model/sst49lfxxxc.c =================================================================== --- flashrom-probe_params_manuf_model/sst49lfxxxc.c (Revision 551) +++ flashrom-probe_params_manuf_model/sst49lfxxxc.c (Arbeitskopie) @@ -115,7 +115,7 @@ return 0; }
-int probe_49lfxxxc(struct flashchip *flash) +int probe_49lfxxxc(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory;
@@ -131,7 +131,7 @@
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
- if (!(id1 == flash->manufacture_id && id2 == flash->model_id)) + if (!(id1 == manufacture_id && id2 == model_id)) return 0;
map_flash_registers(flash); Index: flashrom-probe_params_manuf_model/sharplhf00l04.c =================================================================== --- flashrom-probe_params_manuf_model/sharplhf00l04.c (Revision 551) +++ flashrom-probe_params_manuf_model/sharplhf00l04.c (Arbeitskopie) @@ -33,7 +33,7 @@ printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); }
-int probe_lhf00l04(struct flashchip *flash) +int probe_lhf00l04(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -62,7 +62,7 @@
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
- if (id1 != flash->manufacture_id || id2 != flash->model_id) + if (id1 != manufacture_id || id2 != model_id) return 0;
map_flash_registers(flash); Index: flashrom-probe_params_manuf_model/spi.c =================================================================== --- flashrom-probe_params_manuf_model/spi.c (Revision 551) +++ flashrom-probe_params_manuf_model/spi.c (Arbeitskopie) @@ -193,13 +193,13 @@ return 0; }
-int probe_spi_rdid(struct flashchip *flash) +int probe_spi_rdid(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { return probe_spi_rdid_generic(flash, 3); }
/* support 4 bytes flash ID */ -int probe_spi_rdid4(struct flashchip *flash) +int probe_spi_rdid4(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { /* only some SPI chipsets support 4 bytes commands */ switch (flashbus) { @@ -217,7 +217,7 @@ return 0; }
-int probe_spi_rems(struct flashchip *flash) +int probe_spi_rems(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { unsigned char readarr[JEDEC_REMS_INSIZE]; uint32_t id1, id2; @@ -230,7 +230,7 @@
printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
- if (id1 == flash->manufacture_id && id2 == flash->model_id) { + if (id1 == manufacture_id && id2 == model_id) { /* Print the status register to tell the * user about possible write protection. */ @@ -240,14 +240,14 @@ }
/* Test if this is a pure vendor match. */ - if (id1 == flash->manufacture_id && - GENERIC_DEVICE_ID == flash->model_id) + if (id1 == manufacture_id && + GENERIC_DEVICE_ID == model_id) return 1;
return 0; }
-int probe_spi_res(struct flashchip *flash) +int probe_spi_res(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { unsigned char readarr[3]; uint32_t id2; @@ -264,7 +264,7 @@
id2 = readarr[0]; printf_debug("%s: id 0x%x\n", __FUNCTION__, id2); - if (id2 != flash->model_id) + if (id2 != model_id) return 0;
/* Print the status register to tell the Index: flashrom-probe_params_manuf_model/w39v040c.c =================================================================== --- flashrom-probe_params_manuf_model/w39v040c.c (Revision 551) +++ flashrom-probe_params_manuf_model/w39v040c.c (Arbeitskopie) @@ -20,7 +20,7 @@
#include "flash.h"
-int probe_w39v040c(struct flashchip *flash) +int probe_w39v040c(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2, lock; @@ -47,7 +47,7 @@ if (!oddparity(id1)) printf_debug(", id1 parity violation"); printf_debug("\n"); - if (flash->manufacture_id == id1 && flash->model_id == id2) { + if (manufacture_id == id1 && model_id == id2) { printf("%s: Boot block #TBL is %slocked, rest of chip #WP is %slocked.\n", __func__, lock & 0x4 ? "" : "un", lock & 0x8 ? "" : "un"); return 1; Index: flashrom-probe_params_manuf_model/sst28sf040.c =================================================================== --- flashrom-probe_params_manuf_model/sst28sf040.c (Revision 551) +++ flashrom-probe_params_manuf_model/sst28sf040.c (Arbeitskopie) @@ -88,7 +88,7 @@ return 0; }
-int probe_28sf040(struct flashchip *flash) +int probe_28sf040(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -106,7 +106,7 @@ myusec_delay(10);
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2); - if (id1 == flash->manufacture_id && id2 == flash->model_id) + if (id1 == manufacture_id && id2 == model_id) return 1;
return 0; Index: flashrom-probe_params_manuf_model/stm50flw0x0x.c =================================================================== --- flashrom-probe_params_manuf_model/stm50flw0x0x.c (Revision 551) +++ flashrom-probe_params_manuf_model/stm50flw0x0x.c (Arbeitskopie) @@ -38,7 +38,7 @@ usleep(200); }
-int probe_stm50flw0x0x(struct flashchip *flash) +int probe_stm50flw0x0x(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -81,7 +81,7 @@ printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, largeid1, largeid2);
- if (largeid1 != flash->manufacture_id || largeid2 != flash->model_id) + if (largeid1 != manufacture_id || largeid2 != model_id) return 0;
map_flash_registers(flash); Index: flashrom-probe_params_manuf_model/am29f040b.c =================================================================== --- flashrom-probe_params_manuf_model/am29f040b.c (Revision 551) +++ flashrom-probe_params_manuf_model/am29f040b.c (Arbeitskopie) @@ -61,7 +61,7 @@ return 0; }
-int probe_29f040b(struct flashchip *flash) +int probe_29f040b(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -78,7 +78,7 @@ myusec_delay(10);
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2); - if (id1 == flash->manufacture_id && id2 == flash->model_id) + if (id1 == manufacture_id && id2 == model_id) return 1;
return 0; Index: flashrom-probe_params_manuf_model/sst_fwhub.c =================================================================== --- flashrom-probe_params_manuf_model/sst_fwhub.c (Revision 551) +++ flashrom-probe_params_manuf_model/sst_fwhub.c (Arbeitskopie) @@ -79,11 +79,11 @@ }
/* probe_jedec works fine for probing */ -int probe_sst_fwhub(struct flashchip *flash) +int probe_sst_fwhub(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { int i;
- if (probe_jedec(flash) == 0) + if (probe_jedec(flash, manufacture_id, model_id) == 0) return 0;
map_flash_registers(flash); Index: flashrom-probe_params_manuf_model/w39v080fa.c =================================================================== --- flashrom-probe_params_manuf_model/w39v080fa.c (Revision 551) +++ flashrom-probe_params_manuf_model/w39v080fa.c (Arbeitskopie) @@ -20,7 +20,7 @@
#include "flash.h"
-int probe_winbond_fwhub(struct flashchip *flash) +int probe_winbond_fwhub(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -43,7 +43,7 @@
printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
- if (id1 != flash->manufacture_id || id2 != flash->model_id) + if (id1 != manufacture_id || id2 != model_id) return 0;
map_flash_registers(flash); Index: flashrom-probe_params_manuf_model/flashrom.c =================================================================== --- flashrom-probe_params_manuf_model/flashrom.c (Revision 551) +++ flashrom-probe_params_manuf_model/flashrom.c (Arbeitskopie) @@ -184,7 +184,7 @@ if (force) break;
- if (flash->probe(flash) != 1) + if (flash->probe(flash, flash->manufacture_id, flash->model_id) != 1) goto notfound;
if (first_flash == flashchips Index: flashrom-probe_params_manuf_model/82802ab.c =================================================================== --- flashrom-probe_params_manuf_model/82802ab.c (Revision 551) +++ flashrom-probe_params_manuf_model/82802ab.c (Arbeitskopie) @@ -41,7 +41,7 @@ printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); }
-int probe_82802ab(struct flashchip *flash) +int probe_82802ab(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -69,7 +69,7 @@
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
- if (id1 != flash->manufacture_id || id2 != flash->model_id) + if (id1 != manufacture_id || id2 != model_id) return 0;
map_flash_registers(flash); Index: flashrom-probe_params_manuf_model/mx29f002.c =================================================================== --- flashrom-probe_params_manuf_model/mx29f002.c (Revision 551) +++ flashrom-probe_params_manuf_model/mx29f002.c (Arbeitskopie) @@ -20,7 +20,7 @@
#include "flash.h"
-int probe_29f002(struct flashchip *flash) +int probe_29f002(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -37,7 +37,7 @@ myusec_delay(10);
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2); - if (id1 == flash->manufacture_id && id2 == flash->model_id) + if (id1 == manufacture_id && id2 == model_id) return 1;
return 0; Index: flashrom-probe_params_manuf_model/m29f400bt.c =================================================================== --- flashrom-probe_params_manuf_model/m29f400bt.c (Revision 551) +++ flashrom-probe_params_manuf_model/m29f400bt.c (Arbeitskopie) @@ -52,7 +52,7 @@ } }
-int probe_m29f400bt(struct flashchip *flash) +int probe_m29f400bt(struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; @@ -77,7 +77,7 @@
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
- if (id1 == flash->manufacture_id && id2 == flash->model_id) + if (id1 == manufacture_id && id2 == model_id) return 1;
return 0;