summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Greber <sgreber@lilafast.org>2025-10-27 22:42:56 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-10-30 11:06:28 +0000
commite8f38f022e8e30275f76c3692453f1a0b1b90f9b (patch)
treef43ed72768238e908284651bd6e5c57815bd123a
parent050942f1cf40c40d286cc765b7a1ccebdd060e38 (diff)
downloadpoky-e8f38f022e8e30275f76c3692453f1a0b1b90f9b.tar.gz
wic: add wic tests and support setting GPT diskid
Also extend implementation to allow defining the diskid for GPT partitions. Add unit tests for wic.py to cover new setting. (From OE-Core rev: 0d5da9477703212d3cfb63828c5c38afdb162e43) Signed-off-by: Steffen Greber <sgreber@lilafast.org> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/selftest/cases/wic.py36
-rw-r--r--scripts/lib/wic/ksparser.py21
-rw-r--r--scripts/lib/wic/plugins/imager/direct.py14
3 files changed, 64 insertions, 7 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index bb4ac23ebf..d7a9b14658 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -1905,6 +1905,42 @@ INITRAMFS_IMAGE = "core-image-initramfs-boot"
1905 self.assertIn("Source parameter 'fill' only works with the '--fixed-size' option, exiting.", result.output) 1905 self.assertIn("Source parameter 'fill' only works with the '--fixed-size' option, exiting.", result.output)
1906 self.assertNotEqual(0, result.status) 1906 self.assertNotEqual(0, result.status)
1907 1907
1908 def test_diskid_on_msdos_partition(self):
1909 """Test diksid on msdos partions"""
1910 img = 'core-image-minimal'
1911 diskid = "0xdeadbbef"
1912 with NamedTemporaryFile("w", suffix=".wks") as wks:
1913 wks.writelines(['bootloader --ptable msdos --diskid %s\n' % diskid,
1914 'part /boot --size=100M --active --fstype=ext4 --label boot\n'
1915 'part / --source rootfs --fstype=ext4 --label root\n'])
1916 wks.flush()
1917 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1918 runCmd(cmd)
1919 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1920 out = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
1921 self.assertEqual(1, len(out))
1922 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1923 result = runCmd("%s/usr/sbin/sfdisk -l %s | grep 'Disk identifier:'" % (sysroot, out[0]))
1924 self.assertEqual("Disk identifier: %s" % diskid.lower(), result.output)
1925
1926 def test_diskid_on_gpt_partition(self):
1927 """Test diksid on gpt partions"""
1928 img = 'core-image-minimal'
1929 diskid = "deadbeef-cafe-babe-f00d-cec2ea4eface"
1930 with NamedTemporaryFile("w", suffix=".wks") as wks:
1931 wks.writelines(['bootloader --ptable gpt --diskid %s\n' % diskid,
1932 'part /boot --size=100M --active --fstype=ext4 --label boot\n'
1933 'part / --source rootfs --fstype=ext4 --label root\n'])
1934 wks.flush()
1935 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1936 runCmd(cmd)
1937 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1938 out = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
1939 self.assertEqual(1, len(out))
1940 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1941 result = runCmd("%s/usr/sbin/sfdisk -l %s | grep 'Disk identifier:'" % (sysroot, out[0]))
1942 self.assertEqual("Disk identifier: %s" % diskid.upper(), result.output)
1943
1908class ModifyTests(WicTestCase): 1944class ModifyTests(WicTestCase):
1909 def test_wic_ls(self): 1945 def test_wic_ls(self):
1910 """Test listing image content using 'wic ls'""" 1946 """Test listing image content using 'wic ls'"""
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index 48b5b09ddd..4ccd70dc55 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -16,6 +16,7 @@ import os
16import shlex 16import shlex
17import logging 17import logging
18import re 18import re
19import uuid
19 20
20from argparse import ArgumentParser, ArgumentError, ArgumentTypeError 21from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
21 22
@@ -196,7 +197,7 @@ class KickStart():
196 bootloader.add_argument('--configfile') 197 bootloader.add_argument('--configfile')
197 bootloader.add_argument('--ptable', choices=('msdos', 'gpt', 'gpt-hybrid'), 198 bootloader.add_argument('--ptable', choices=('msdos', 'gpt', 'gpt-hybrid'),
198 default='msdos') 199 default='msdos')
199 bootloader.add_argument('--diskid', type=lambda x: int(x, 0)) 200 bootloader.add_argument('--diskid')
200 bootloader.add_argument('--timeout', type=int) 201 bootloader.add_argument('--timeout', type=int)
201 bootloader.add_argument('--source') 202 bootloader.add_argument('--source')
202 203
@@ -297,6 +298,24 @@ class KickStart():
297 if append_var: 298 if append_var:
298 self.bootloader.append = ' '.join(filter(None, \ 299 self.bootloader.append = ' '.join(filter(None, \
299 (self.bootloader.append, append_var))) 300 (self.bootloader.append, append_var)))
301 if parsed.diskid:
302 if parsed.ptable == "msdos":
303 try:
304 self.bootloader.diskid = int(parsed.diskid, 0)
305 except ValueError:
306 err = "with --ptbale msdos only 32bit integers " \
307 "are allowed for --diskid. %s could not " \
308 "be parsed" % self.ptable
309 raise KickStartError(err)
310 else:
311 try:
312 self.bootloader.diskid = uuid.UUID(parsed.diskid)
313 except ValueError:
314 err = "with --ptable %s only valid uuids are " \
315 "allowed for --diskid. %s could not be " \
316 "parsed" % (parsed.ptable, parsed.diskid)
317 raise KickStartError(err)
318
300 else: 319 else:
301 err = "%s:%d: more than one bootloader specified" \ 320 err = "%s:%d: more than one bootloader specified" \
302 % (confpath, lineno) 321 % (confpath, lineno)
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index f40f033a3d..ad922cfbf1 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -315,7 +315,14 @@ class PartitionedImage():
315 # all partitions (in bytes) 315 # all partitions (in bytes)
316 self.ptable_format = ptable_format # Partition table format 316 self.ptable_format = ptable_format # Partition table format
317 # Disk system identifier 317 # Disk system identifier
318 if disk_id: 318 if disk_id and ptable_format in ('gpt', 'gpt-hybrid'):
319 self.disk_guid = disk_id
320 elif os.getenv('SOURCE_DATE_EPOCH'):
321 self.disk_guid = uuid.UUID(int=int(os.getenv('SOURCE_DATE_EPOCH')))
322 else:
323 self.disk_guid = uuid.uuid4()
324
325 if disk_id and ptable_format == 'msdos':
319 self.identifier = disk_id 326 self.identifier = disk_id
320 elif os.getenv('SOURCE_DATE_EPOCH'): 327 elif os.getenv('SOURCE_DATE_EPOCH'):
321 self.identifier = random.Random(int(os.getenv('SOURCE_DATE_EPOCH'))).randint(1, 0xffffffff) 328 self.identifier = random.Random(int(os.getenv('SOURCE_DATE_EPOCH'))).randint(1, 0xffffffff)
@@ -545,11 +552,6 @@ class PartitionedImage():
545 552
546 def _write_disk_guid(self): 553 def _write_disk_guid(self):
547 if self.ptable_format in ('gpt', 'gpt-hybrid'): 554 if self.ptable_format in ('gpt', 'gpt-hybrid'):
548 if os.getenv('SOURCE_DATE_EPOCH'):
549 self.disk_guid = uuid.UUID(int=int(os.getenv('SOURCE_DATE_EPOCH')))
550 else:
551 self.disk_guid = uuid.uuid4()
552
553 logger.debug("Set disk guid %s", self.disk_guid) 555 logger.debug("Set disk guid %s", self.disk_guid)
554 sfdisk_cmd = "sfdisk --sector-size %s --disk-id %s %s" % \ 556 sfdisk_cmd = "sfdisk --sector-size %s --disk-id %s %s" % \
555 (self.sector_size, self.path, self.disk_guid) 557 (self.sector_size, self.path, self.disk_guid)