drivers/: Make 'fallback_{un}map' the default unless defined
Drop the explicit need to specify the default 'fallback_{un}map'
callback function pointer from the 'programmer_entry' struct.
This is a reasonable default for every other driver in the tree
with only a select few exceptions [atavia, serprog, dummyflasher
and internal].
Thus this simplifies driver development and paves way
to remove the 'programmer' global handle.
flashrom-stable: Updated `dirtyjtag_spi` which was added earlier.
Change-Id: I5ea7bd68f7ae2cd4af9902ef07255ab6ce0bfdb3
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/67404
Original-Reviewed-by: Felix Singer <felixsinger@posteo.net>
Original-Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72360
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
diff --git a/atahpt.c b/atahpt.c
index d92d470..42741a7 100644
--- a/atahpt.c
+++ b/atahpt.c
@@ -96,6 +96,4 @@
.type = PCI,
.devs.dev = ata_hpt,
.init = atahpt_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/atapromise.c b/atapromise.c
index 86f8e2e..083239d 100644
--- a/atapromise.c
+++ b/atapromise.c
@@ -170,5 +170,4 @@
.devs.dev = ata_promise,
.init = atapromise_init,
.map_flash_region = atapromise_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/atavia.c b/atavia.c
index df2e428..e96c808 100644
--- a/atavia.c
+++ b/atavia.c
@@ -192,5 +192,4 @@
.devs.dev = ata_via,
.init = atavia_init,
.map_flash_region = atavia_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/buspirate_spi.c b/buspirate_spi.c
index a23fdb7..5dee4ed 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -719,6 +719,4 @@
/* FIXME */
.devs.note = "Dangerous Prototypes Bus Pirate\n",
.init = buspirate_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/ch341a_spi.c b/ch341a_spi.c
index ca131f0..a3ea93d 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -532,7 +532,5 @@
.type = USB,
.devs.dev = devs_ch341a_spi,
.init = ch341a_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
.delay = ch341a_spi_delay,
};
diff --git a/dediprog.c b/dediprog.c
index ad5bad2..a5d35d1 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1322,6 +1322,4 @@
.type = USB,
.devs.dev = devs_dediprog,
.init = dediprog_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/developerbox_spi.c b/developerbox_spi.c
index 26af1e8..e186240 100644
--- a/developerbox_spi.c
+++ b/developerbox_spi.c
@@ -170,6 +170,4 @@
.type = USB,
.devs.dev = devs_developerbox_spi,
.init = developerbox_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/digilent_spi.c b/digilent_spi.c
index cc99b46..cd73c65 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -462,6 +462,4 @@
.type = USB,
.devs.dev = devs_digilent_spi,
.init = digilent_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/dirtyjtag_spi.c b/dirtyjtag_spi.c
index f02df49..35add46 100644
--- a/dirtyjtag_spi.c
+++ b/dirtyjtag_spi.c
@@ -317,6 +317,4 @@
.type = USB,
.devs.dev = devs_dirtyjtag_spi,
.init = dirtyjtag_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/drkaiser.c b/drkaiser.c
index e704ea0..40cd157 100644
--- a/drkaiser.c
+++ b/drkaiser.c
@@ -95,6 +95,4 @@
.type = PCI,
.devs.dev = drkaiser_pcidev,
.init = drkaiser_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/flashrom.c b/flashrom.c
index c434cff..40472ec 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -209,7 +209,11 @@
void *programmer_map_flash_region(const char *descr, uintptr_t phys_addr, size_t len)
{
- void *ret = programmer->map_flash_region(descr, phys_addr, len);
+ void *ret;
+ if (programmer->map_flash_region)
+ ret = programmer->map_flash_region(descr, phys_addr, len);
+ else
+ ret = fallback_map(descr, phys_addr, len);
msg_gspew("%s: mapping %s from 0x%0*" PRIxPTR " to 0x%0*" PRIxPTR "\n",
__func__, descr, PRIxPTR_WIDTH, phys_addr, PRIxPTR_WIDTH, (uintptr_t) ret);
return ret;
@@ -217,7 +221,10 @@
void programmer_unmap_flash_region(void *virt_addr, size_t len)
{
- programmer->unmap_flash_region(virt_addr, len);
+ if (programmer->unmap_flash_region)
+ programmer->unmap_flash_region(virt_addr, len);
+ else
+ fallback_unmap(virt_addr, len);
msg_gspew("%s: unmapped 0x%0*" PRIxPTR "\n", __func__, PRIxPTR_WIDTH, (uintptr_t)virt_addr);
}
@@ -1420,14 +1427,6 @@
msg_gerr("Programmer %s does not have a valid init function!\n", p->name);
ret = 1;
}
- if (p->map_flash_region == NULL) {
- msg_gerr("Programmer %s does not have a valid map_flash_region function!\n", p->name);
- ret = 1;
- }
- if (p->unmap_flash_region == NULL) {
- msg_gerr("Programmer %s does not have a valid unmap_flash_region function!\n", p->name);
- ret = 1;
- }
}
/* It would be favorable if we could check for the correct layout (especially termination) of various
diff --git a/ft2232_spi.c b/ft2232_spi.c
index e232fe5..378566e 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -711,6 +711,4 @@
.type = USB,
.devs.dev = devs_ft2232spi,
.init = ft2232_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/gfxnvidia.c b/gfxnvidia.c
index 1a75688..7eb633d 100644
--- a/gfxnvidia.c
+++ b/gfxnvidia.c
@@ -122,6 +122,4 @@
.type = PCI,
.devs.dev = gfx_nvidia,
.init = gfxnvidia_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/it8212.c b/it8212.c
index 842c172..5657bca 100644
--- a/it8212.c
+++ b/it8212.c
@@ -83,6 +83,4 @@
.type = PCI,
.devs.dev = devs_it8212,
.init = it8212_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/jlink_spi.c b/jlink_spi.c
index 196ca0f..3559882 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -538,6 +538,4 @@
.type = OTHER,
.init = jlink_spi_init,
.devs.note = "SEGGER J-Link and compatible devices\n",
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/linux_mtd.c b/linux_mtd.c
index ce93f86..f7cd82b 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -437,6 +437,4 @@
.type = OTHER,
.devs.note = "Device files /dev/mtd*\n",
.init = linux_mtd_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/linux_spi.c b/linux_spi.c
index 8598dc1..c4ba915 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -260,6 +260,4 @@
.type = OTHER,
.devs.note = "Device files /dev/spidev*.*\n",
.init = linux_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/mstarddc_spi.c b/mstarddc_spi.c
index ef44470..d303e21 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -231,6 +231,4 @@
.type = OTHER,
.devs.note = "MSTAR DDC devices addressable via /dev/i2c-* on Linux.\n",
.init = mstarddc_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/ni845x_spi.c b/ni845x_spi.c
index 487bef5..415b276 100644
--- a/ni845x_spi.c
+++ b/ni845x_spi.c
@@ -640,6 +640,4 @@
.type = OTHER, // choose other because NI-845x uses own USB implementation
.devs.note = "National Instruments USB-845x\n",
.init = ni845x_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/nic3com.c b/nic3com.c
index 32c5961..a8b612e 100644
--- a/nic3com.c
+++ b/nic3com.c
@@ -141,6 +141,4 @@
.type = PCI,
.devs.dev = nics_3com,
.init = nic3com_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/nicintel.c b/nicintel.c
index 8692a73..f564dc2 100644
--- a/nicintel.c
+++ b/nicintel.c
@@ -114,6 +114,4 @@
.type = PCI,
.devs.dev = nics_intel,
.init = nicintel_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c
index 00d1d6b..0128d08 100644
--- a/nicintel_eeprom.c
+++ b/nicintel_eeprom.c
@@ -518,6 +518,4 @@
.type = PCI,
.devs.dev = nics_intel_ee,
.init = nicintel_ee_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/nicintel_spi.c b/nicintel_spi.c
index 774ffeb..b89dc09 100644
--- a/nicintel_spi.c
+++ b/nicintel_spi.c
@@ -305,6 +305,4 @@
.type = PCI,
.devs.dev = nics_intel_spi,
.init = nicintel_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/nicnatsemi.c b/nicnatsemi.c
index 3819d22..8b0b68f 100644
--- a/nicnatsemi.c
+++ b/nicnatsemi.c
@@ -108,6 +108,4 @@
.type = PCI,
.devs.dev = nics_natsemi,
.init = nicnatsemi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/nicrealtek.c b/nicrealtek.c
index 170b757..d635705 100644
--- a/nicrealtek.c
+++ b/nicrealtek.c
@@ -130,6 +130,4 @@
.type = PCI,
.devs.dev = nics_realtek,
.init = nicrealtek_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/ogp_spi.c b/ogp_spi.c
index 99d29b6..18e6514 100644
--- a/ogp_spi.c
+++ b/ogp_spi.c
@@ -144,6 +144,4 @@
.type = PCI,
.devs.dev = ogp_spi,
.init = ogp_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 3a49207..240723c 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -510,6 +510,4 @@
.type = USB,
.devs.dev = devs_pickit2_spi,
.init = pickit2_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/pony_spi.c b/pony_spi.c
index 6b68fdc..fba7fb7 100644
--- a/pony_spi.c
+++ b/pony_spi.c
@@ -236,6 +236,4 @@
/* FIXME */
.devs.note = "Programmers compatible with SI-Prog, serbang or AJAWe\n",
.init = pony_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/rayer_spi.c b/rayer_spi.c
index 316efc2..12ff019 100644
--- a/rayer_spi.c
+++ b/rayer_spi.c
@@ -285,6 +285,4 @@
/* FIXME */
.devs.note = "RayeR parallel port programmer\n",
.init = rayer_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/satamv.c b/satamv.c
index 6c55eb9..735495c 100644
--- a/satamv.c
+++ b/satamv.c
@@ -192,6 +192,4 @@
.type = PCI,
.devs.dev = satas_mv,
.init = satamv_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/satasii.c b/satasii.c
index 6e741de..21ea879 100644
--- a/satasii.c
+++ b/satasii.c
@@ -137,6 +137,4 @@
.type = PCI,
.devs.dev = satas_sii,
.init = satasii_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/serprog.c b/serprog.c
index 0c33257..8b2af8a 100644
--- a/serprog.c
+++ b/serprog.c
@@ -982,6 +982,5 @@
.devs.note = "All programmer devices speaking the serprog protocol\n",
.init = serprog_init,
.map_flash_region = serprog_map,
- .unmap_flash_region = fallback_unmap,
.delay = serprog_delay,
};
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index 2f622b7..f5d31e2 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -519,6 +519,4 @@
.type = USB,
.devs.dev = devs_stlinkv3_spi,
.init = stlinkv3_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index 9c21903..8f05088 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -217,6 +217,4 @@
.type = USB,
.devs.dev = devs_usbblasterspi,
.init = usbblaster_spi_init,
- .map_flash_region = fallback_map,
- .unmap_flash_region = fallback_unmap,
};