[coreboot-gerrit] Change in coreboot[master]: Extract the VGA BIOS from an UEFI dump

Thomas Weißschuh (Code Review) gerrit at coreboot.org
Sat Dec 30 14:44:06 CET 2017


Thomas Weißschuh has uploaded this change for review. ( https://review.coreboot.org/23045


Change subject: Extract the VGA BIOS from an UEFI dump
......................................................................

Extract the VGA BIOS from an UEFI dump

Depends on the 3rd party Python library uefi-firmware-parser.
(https://github.com/theopolis/uefi-firmware-parser)

Change-Id: Ic95b7520c65062e2106f7bd7d39bb652d4cecd7a
Signed-off-by: Thomas Weißschuh <thomas at t-8ch.de>
---
M src/arch/x86/Makefile.inc
M src/device/Kconfig
A util/vgabios_extract/vgabios_extract.py
3 files changed, 90 insertions(+), 3 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/45/23045/1

diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc
index cc227b3..3f2f1e4 100644
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -38,9 +38,24 @@
 	$(NVRAMTOOL) -y $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout -H $@
 endif # CONFIG_HAVE_OPTION_TABLE
 
+vgabios-rom=$(obj)/vgabios.rom
+
+ifeq ($(CONFIG_VGA_BIOS_EXTRACT),y)
+
+$(vgabios-rom): $(call strip_quotes,$(CONFIG_VGA_BIOS_EXTRACT_FILE))
+	@printf "    VGA_BIOS_EXTRACT $(CONFIG_VGA_BIOS_EXTRACT_FILE) $(vgabios-rom)\n"
+	util/vgabios_extract/vgabios_extract.py $(CONFIG_VGA_BIOS_EXTRACT_FILE) $(vgabios-rom)
+
+else
+
+$(vgabios-rom): $(call strip_quotes,$(CONFIG_VGA_BIOS_FILE))
+	$(CP) $(vgabios-rom) $(CONFIG_VGA_BIOS_FILE)
+
+endif
+
 stripped_vgabios_id = $(call strip_quotes,$(CONFIG_VGA_BIOS_ID))
 cbfs-files-$(CONFIG_VGA_BIOS) += pci$(stripped_vgabios_id).rom
-pci$(stripped_vgabios_id).rom-file := $(call strip_quotes,$(CONFIG_VGA_BIOS_FILE))
+pci$(stripped_vgabios_id).rom-file := $(vgabios-rom)
 pci$(stripped_vgabios_id).rom-type := optionrom
 
 cbfs-files-$(CONFIG_INTEL_MBI) += mbi.bin
diff --git a/src/device/Kconfig b/src/device/Kconfig
index 28298d5..a6b1168 100644
--- a/src/device/Kconfig
+++ b/src/device/Kconfig
@@ -566,11 +566,23 @@
 	  like to add to your ROM.
 
 	  You will be able to specify the location and file name of the
-	  image later.
+	  false
+
+config VGA_BIOS_EXTRACT
+	bool "Extract VGA BIOS from BIOS image"
+	depends on VGA_BIOS
+	default n
+
+config VGA_BIOS_EXTRACT_FILE
+	string "VGA BIOS extract path and filename"
+	depends on VGA_BIOS_EXTRACT
+	default "3rdpart/blobs/mainboard/$(MAINBOARDDIR)/bios.bin"
+	help
+	  The path and filename of the file to extract the VGA BIOS from.
 
 config VGA_BIOS_FILE
 	string "VGA BIOS path and filename"
-	depends on VGA_BIOS
+	depends on VGA_BIOS && !VGA_BIOS_EXTRACT
 	default "vgabios.bin"
 	help
 	  The path and filename of the file to use as VGA BIOS.
diff --git a/util/vgabios_extract/vgabios_extract.py b/util/vgabios_extract/vgabios_extract.py
new file mode 100755
index 0000000..1c32b93
--- /dev/null
+++ b/util/vgabios_extract/vgabios_extract.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python2
+
+from __future__ import print_function
+
+import uefi_firmware
+
+
+def extract_vga_bios(blob):
+    volumes = uefi_firmware.search_firmware_volumes(blob)
+
+    objects = []
+
+    for v in volumes:
+        x = uefi_firmware.AutoParser(blob[v - 40:])
+
+        if x.type() == 'unknown':
+            continue
+
+        objects.extend(x.parse().objects)
+
+    while len(objects):
+        o = objects.pop()
+
+        if not o:
+            continue
+
+        subobjects = filter(lambda x: x is not None, o.objects)
+
+        if subobjects:
+            objects.extend(subobjects)
+            continue
+
+        if b'VGA Compatible BIOS' in o.content:
+            return o
+
+
+if __name__ == '__main__':
+    import argparse
+    import sys
+
+    print(sys.argv)
+
+    parser = argparse.ArgumentParser()
+    parser.add_argument('input', type=str)
+    parser.add_argument('output', type=str)
+
+    args = parser.parse_args()
+
+    with open(args.input, 'rb') as f:
+        blob = f.read()
+
+    o = extract_vga_bios(blob)
+
+    if o is not None:
+        print('Found VGA Bios in {}'.format(o.guid_label), file=sys.stderr)
+        with open(args.output, 'wb') as f:
+            f.write(o.content)
+    else:
+        print('Did not find anything')
+        sys.exit(1)

-- 
To view, visit https://review.coreboot.org/23045
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic95b7520c65062e2106f7bd7d39bb652d4cecd7a
Gerrit-Change-Number: 23045
Gerrit-PatchSet: 1
Gerrit-Owner: Thomas Weißschuh <thomas at t-8ch.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20171230/cfee79eb/attachment.html>


More information about the coreboot-gerrit mailing list