Skip to contentSkip to conversation

mtd: maps: add INT0800 firmware-flash map driver

PATCH Superseded Stephen Bancroft 2 participants 3 messages Sep 17 Memory technology devices (MTD)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: maps: add INT0800 firmware-flash map driver

Add a read-only mapping driver that binds the ACPI INT0800 "Intel 82802 firmware hub" device and exposes the system firmware flash as an MTD ROM device.

On x86 machines the boot flash is decoded into the physical address space below 4 GB, so a plain ioremap() of the declared resource window is sufficient for reads - no SPI or LPC controller access is needed. The window may be larger than the real flash; undecoded holes read as 0xff.

This gives userspace a clean, safe way to read firmware flash contents without flashrom or relaxed /dev/mem access - for firmware analysis, and for extracting option ROMs stored inside EFI firmware volumes (e.g. the NVIDIA VBIOS on EFI-booted Apple machines, which can then be fed to nouveau via nouveau.config=NvBios=). There is deliberately no write or erase support.

Tested on a MacBookPro4,1 (ICH8M): /dev/mtd0 reads are byte-identical to a flashrom dump of the 2 MiB SST25VF016B, except for live NVRAM variable-store regions.

---
 drivers/mtd/maps/Kconfig   | 17 +++++++
 drivers/mtd/maps/Makefile  |  1 +
 drivers/mtd/maps/int0800.c | 96 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 drivers/mtd/maps/int0800.c
drivers/mtd/maps/Kconfig +17 -0
index 1bb3dba..649fd14 100644
@@ -161,6 +161,23 @@ config MTD_AMD76XROM
 
 	  BE VERY CAREFUL.
 
+config MTD_INT0800
+	tristate "Read-only BIOS/firmware flash via ACPI INT0800"
+	depends on X86 && ACPI
+	select MTD_ROM
+	help
+	  Support for reading the system firmware (BIOS/EFI) flash chip
+	  through the memory window described by the ACPI INT0800
+	  "82802 firmware hub" device, present on most x86 machines.
+
+	  The flash is exposed read-only via the ROM chip driver, e.g.
+	  for firmware analysis or extracting option ROMs (such as
+	  video BIOS images embedded in EFI firmware volumes). There is
+	  no write or erase support.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called int0800.
+
 config MTD_ICHXROM
 	tristate "BIOS flash chip on Intel Controller Hub 2/3/4/5"
 	depends on X86 && MTD_JEDECPROBE
drivers/mtd/maps/Makefile +1 -0
index 01745ec..2f1a737 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_MTD_L440GX)	+= l440gx.o
 obj-$(CONFIG_MTD_AMD76XROM)	+= amd76xrom.o
 obj-$(CONFIG_MTD_ESB2ROM)	+= esb2rom.o
 obj-$(CONFIG_MTD_ICHXROM)	+= ichxrom.o
+obj-$(CONFIG_MTD_INT0800)	+= int0800.o
 obj-$(CONFIG_MTD_CK804XROM)	+= ck804xrom.o
 obj-$(CONFIG_MTD_TSUNAMI)	+= tsunami_flash.o
 obj-$(CONFIG_MTD_PXA2XX)	+= pxa2xx-flash.o
drivers/mtd/maps/int0800.c new file +96 -0

96 lines not on this page · raw message

Signature · 6 lines
2.43.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] mtd: memory and mapping leak on mtd_device_register() failure - [Medium] mtd: shared state…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] mtd: memory and mapping leak on mtd_device_register() failure
- [Medium] mtd: shared state corruption via global variables in probe
- [Low] mtd: format string mismatch for resource_size_t in dev_info
--

commit a217a15f9e29300a155e6f6c8138325d4f178f7b
Author: Stephen Bancroft <[email protected]>

mtd: maps: add INT0800 firmware-flash map driver

This commit adds a read-only MTD mapping driver for the ACPI INT0800 firmware hub device on x86. It exposes the system firmware flash as an MTD ROM device to allow userspace to read the firmware flash contents safely.

Quoted 5 lines
drivers/mtd/maps/int0800.c new file +0 -0
new file mode 100644
index 0000000000000..2438d970b9fa4

[ ... ]

Quoted 9 lines
drivers/mtd/maps/int0800.c new file +9 -0
+static struct map_info int0800_map = {
+	.name		= "int0800",
+	.bankwidth	= 1,
+};
+
+static struct mtd_info *int0800_mtd;
+
+static int int0800_probe(struct platform_device *pdev)
+{

[ ... ]

drivers/mtd/maps/int0800.c line 52

Quoted 1 line
drivers/mtd/maps/int0800.c new file +1 -0
+	int0800_map.virt = ioremap(int0800_map.phys, int0800_map.size);

[Severity: Medium]
Since int0800_map and int0800_mtd are global variables, what happens if multiple INT0800 devices are enumerated?

It looks like this unconditionally overwrites the global state during int0800_probe(). Later, int0800_remove() will free these globally stored pointers, which could destroy the state for all active instances or cause a double-free.

[ ... ]

drivers/mtd/maps/int0800.c line 66

Quoted 3 lines
drivers/mtd/maps/int0800.c new file +3 -0
+	dev_info(&pdev->dev, "mapped firmware window 0x%lx-0x%lx\n",
+		 int0800_map.phys,
+		 int0800_map.phys + int0800_map.size - 1);

[Severity: Low]
Does this format string cause issues on 32-bit architectures where resource_size_t is a 64-bit integer?

Using %lx for resource_size_t can consume only half the value and misalign subsequent arguments on the stack. Should this use %pa or an explicit cast to u64 with %llx instead?

drivers/mtd/maps/int0800.c line 69

Quoted 3 lines
drivers/mtd/maps/int0800.c new file +3 -0
+
+	return mtd_device_register(int0800_mtd, NULL, 0);
+}

[Severity: Medium]
If mtd_device_register() fails here, do we leak the memory mapping and the MTD instance?

Normally, we would expect to see map_destroy() and iounmap() on this failure path, similar to what is done in int0800_remove(), but here the error is returned directly.

Signature · 5 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#2 lore raw

Thanks for the review — all three addressed in v2: per-device state via devm_kzalloc, map_destroy on the register-failure path, and %pa for the window print. Also added the missing Signed-off-by.

Quoted 70 lines · On Thu, 17 Sept 2026 at 11:14, <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] mtd: memory and mapping leak on mtd_device_register() failure
- [Medium] mtd: shared state corruption via global variables in probe
- [Low] mtd: format string mismatch for resource_size_t in dev_info
--

commit a217a15f9e29300a155e6f6c8138325d4f178f7b
Author: Stephen Bancroft <[email protected]>

mtd: maps: add INT0800 firmware-flash map driver

This commit adds a read-only MTD mapping driver for the ACPI INT0800 firmware hub device on x86. It exposes the system firmware flash as an MTD ROM device to allow userspace to read the firmware flash contents safely.

Quoted 5 lines
drivers/mtd/maps/int0800.c new file +0 -0
new file mode 100644
index 0000000000000..2438d970b9fa4

[ ... ]

Quoted 9 lines
drivers/mtd/maps/int0800.c new file +9 -0
+static struct map_info int0800_map = {
+     .name           = "int0800",
+     .bankwidth      = 1,
+};
+
+static struct mtd_info *int0800_mtd;
+
+static int int0800_probe(struct platform_device *pdev)
+{

[ ... ]

Quoted 1 line

+ int0800_map.virt = ioremap(int0800_map.phys, int0800_map.size);

[Severity: Medium]
Since int0800_map and int0800_mtd are global variables, what happens if multiple INT0800 devices are enumerated?

It looks like this unconditionally overwrites the global state during int0800_probe(). Later, int0800_remove() will free these globally stored pointers, which could destroy the state for all active instances or cause a double-free.

[ ... ]

drivers/mtd/maps/int0800.c line 66

Quoted 3 lines
drivers/mtd/maps/int0800.c new file +3 -0
+     dev_info(&pdev->dev, "mapped firmware window 0x%lx-0x%lx\n",
+              int0800_map.phys,
+              int0800_map.phys + int0800_map.size - 1);

[Severity: Low]
Does this format string cause issues on 32-bit architectures where resource_size_t is a 64-bit integer?

Using %lx for resource_size_t can consume only half the value and misalign subsequent arguments on the stack. Should this use %pa or an explicit cast to u64 with %llx instead?

drivers/mtd/maps/int0800.c line 69

Quoted 3 lines
drivers/mtd/maps/int0800.c new file +3 -0
+
+     return mtd_device_register(int0800_mtd, NULL, 0);
+}

[Severity: Medium]
If mtd_device_register() fails here, do we leak the memory mapping and the MTD instance?

Normally, we would expect to see map_destroy() and iounmap() on this failure path, similar to what is done in int0800_remove(), but here the error is returned directly.

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1