[elbe-devel] [PATCH 3/4] elbepack: check-build: add interpreter-firmware feature

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Mar 6 10:53:59 CET 2024


Image checks can define which firmware features they require and
"elbe check-build img" will find and use a matching firmware binary.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/commands/check-build.py | 32 +++++++++++++++++++++++++++++++-
 elbepack/schema/dbsfed.xsd       | 23 +++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/elbepack/commands/check-build.py b/elbepack/commands/check-build.py
index 67492564cb1b..0112fc995a52 100644
--- a/elbepack/commands/check-build.py
+++ b/elbepack/commands/check-build.py
@@ -11,6 +11,7 @@ import sys
 import tempfile
 import traceback
 
+from elbepack import qemu_firmware
 from elbepack.directories import elbe_exe
 from elbepack.filesystem import TmpdirFilesystem
 from elbepack.log import elbe_logging
@@ -414,11 +415,40 @@ class CheckImage(CheckBase):
 
         return fail_cnt
 
+    def _firmware_opts(self, tag):
+        searcher = qemu_firmware.FirmwareSearcher()
+        request = qemu_firmware.SearchRequest(
+                architecture=tag.attrib['architecture'],
+                machine=tag.attrib['machine'],
+                interface_types=(
+                    qemu_firmware.FeatureMatcher.from_string(tag.attrib['interface_types'])),
+                features=qemu_firmware.FeatureMatcher.from_string(tag.attrib['features']),
+        )
+
+        fw = searcher.search(request)
+        if fw is None:
+            raise RuntimeError('No acceptable firmware found')
+
+        mapping = fw.mapping
+        if not isinstance(mapping, qemu_firmware.FirmwareMappingFlash):
+            raise ValueError('Non-flash firmware is not supported')
+
+        return ' '.join([
+            '-drive', (
+                'if=none,id=pflash0,readonly=on,'
+                f'file={mapping.executable.filename},'
+                f'format={mapping.executable.format}'
+            ),
+            '-machine', 'pflash0=pflash0',
+        ])
+
     def do_img(self, tag):
 
         img_name = tag.text('./img')
         qemu = tag.text('./interpreter')
 
+        fw_opts = self._firmware_opts(tag.et.find('./interpreter-firmware'))
+
         with self.open_img(img_name) as img:
 
             # ELBE_IMG always points to the opened image
@@ -434,7 +464,7 @@ class CheckImage(CheckBase):
                 element = tag.et.find(os.path.join('./action', candidate))
 
                 if element is not None:
-                    return action(element, img_name, qemu, opts)
+                    return action(element, img_name, qemu, opts + ' ' + fw_opts)
 
         # No valid action!
         return 1
diff --git a/elbepack/schema/dbsfed.xsd b/elbepack/schema/dbsfed.xsd
index 9b695bbf3a5c..f20103f46c4d 100644
--- a/elbepack/schema/dbsfed.xsd
+++ b/elbepack/schema/dbsfed.xsd
@@ -560,6 +560,22 @@ SPDX-FileCopyrightText: Linutronix GmbH
     <attributeGroup ref="xml:specialAttrs"/>
   </complexType>
 
+  <complexType name="interpreter-firmware">
+    <annotation>
+      <documentation>
+	Describes aspects of a firmware binary needed to run an image.
+
+        A matching firmware image will be looked for in QEMU's database of
+        installed firmware binaries.
+      </documentation>
+    </annotation>
+    <attribute name="architecture" type="string" use="required" />
+    <attribute name="machine" type="string" use="required" />
+    <attribute name="interface_types" type="string" use="required" />
+    <attribute name="features" type="string" use="required" />
+    <attributeGroup ref="xml:specialAttrs"/>
+  </complexType>
+
   <complexType name="check-img">
     <all>
       <element name="img" type="rfs:string" minOccurs="1" maxOccurs="1">
@@ -591,6 +607,13 @@ SPDX-FileCopyrightText: Linutronix GmbH
           </documentation>
         </annotation>
       </element>
+      <element name="interpreter-firmware" type="rfs:interpreter-firmware" minOccurs="0" maxOccurs="1">
+        <annotation>
+          <documentation>
+            Firmware to start the interpreter with.
+          </documentation>
+        </annotation>
+      </element>
       <element name="action" type="rfs:check-img-action">
         <annotation>
           <documentation>

-- 
2.44.0



More information about the elbe-devel mailing list