[elbe-devel] [PATCH 4/9] hdimg: implement partition filles with binary data from file

Torben Hohn torben.hohn at linutronix.de
Mon Dec 14 17:41:08 CET 2020


Allow generating a raw partition, that contains a bootloader or
the kernel.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/hdimg.py | 27 ++++++++++++++++++++++++---
 schema/dbsfed.xsd |  9 +++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index 965fff856..ccd1ef86f 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -13,7 +13,7 @@ import os
 import parted
 import _ped
 
-from elbepack.fstab import fstabentry, mountpoint_dict
+from elbepack.fstab import fstabentry, mountpoint_dict, hdpart
 from elbepack.filesystem import Filesystem, size_to_int
 from elbepack.shellhelper import do, CommandError, chroot, get_command_out
 
@@ -370,6 +370,23 @@ def create_label(disk, part, ppart, fslabel, target, grub):
 
     return ppart
 
+def create_binary(disk, part, ppart, target):
+
+    entry = hdpart()
+    entry.set_geometry(ppart, disk)
+
+    loopdev = entry.losetup()
+
+    # copy from buildenv if path starts with /
+    if part.text("binary")[0] == '/':
+        tmp = target + "/" + "chroot" + part.text("binary")
+    # copy from project directory
+    else:
+        tmp = target + "/" + part.text("binary")
+
+    do(f'dd if="{tmp}" of="{loopdev}"')
+
+    do(f'losetup -d "{loopdev}"')
 
 def create_logical_partitions(disk,
                               extended,
@@ -395,7 +412,9 @@ def create_logical_partitions(disk,
             fslabel,
             size_in_sectors,
             current_sector)
-        if logical.has("label") and logical.text("label") in fslabel:
+        if logical.has('binary'):
+            create_binary(disk, logical, lpart, target)
+        elif logical.has("label") and logical.text("label") in fslabel:
             create_label(disk, logical, lpart, fslabel, target, grub)
 
         current_sector += lpart.getLength()
@@ -443,7 +462,9 @@ def do_image_hd(hd, fslabel, target, grub_version, grub_fw_type=None):
                 fslabel,
                 size_in_sectors,
                 current_sector)
-            if part.text("label") in fslabel:
+            if part.has("binary"):
+                create_binary(disk, part, ppart, target)
+            elif part.text("label") in fslabel:
                 create_label(disk, part, ppart, fslabel, target, grub)
         elif part.tag == "extended":
             ppart = create_partition(
diff --git a/schema/dbsfed.xsd b/schema/dbsfed.xsd
index 88d26a75c..d6ca98bb4 100644
--- a/schema/dbsfed.xsd
+++ b/schema/dbsfed.xsd
@@ -1770,6 +1770,15 @@
           </documentation>
         </annotation>
       </element>
+      <element name="binary" type="rfs:string" minOccurs="0">
+        <annotation>
+          <documentation>
+            path and filename of a binary image which will be used as a source
+	    for this volume; this can be used for example to store a bootloader
+	    in a partition.
+          </documentation>
+        </annotation>
+      </element>
       <element name="bootable" type="rfs:string" minOccurs="0">
         <annotation>
           <documentation>
-- 
2.20.1



More information about the elbe-devel mailing list