summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrevor Woerner <trevor.woerner@amd.com>2025-03-20 14:50:45 -0600
committerMark Hatle <mark.hatle@amd.com>2025-03-30 14:16:15 -0600
commit17d0c589cb8fe91688fa141c4f804e90ce24fcef (patch)
tree704b0ae7f5e506c4c0da2bcf4684a4090bf82823
parentaac160dbfa1e4efd6e8239bfbc1d7fe97364d87c (diff)
downloadmeta-xilinx-17d0c589cb8fe91688fa141c4f804e90ce24fcef.tar.gz
wic: add --sector-size cmdline arg to create
Add a command-line argument, --sector-size <N>, to wic's "create" subcommand and allow it to propagate throughout the wic code so it can be used when generating a wic image. Signed-off-by: Trevor Woerner <trevor.woerner@amd.com> Added scripts/lib/scriptpath.py change. Updated the wic version to make it clear it's from this layer. Signed-off-by: Mark Hatle <mark.hatle@amd.com>
-rw-r--r--meta-xilinx-core/scripts/lib/scriptpath.py2
-rw-r--r--meta-xilinx-core/scripts/lib/wic/ksparser.py5
-rw-r--r--meta-xilinx-core/scripts/lib/wic/partition.py18
-rw-r--r--meta-xilinx-core/scripts/lib/wic/plugins/imager/direct.py16
-rwxr-xr-xmeta-xilinx-core/scripts/wic4
5 files changed, 29 insertions, 16 deletions
diff --git a/meta-xilinx-core/scripts/lib/scriptpath.py b/meta-xilinx-core/scripts/lib/scriptpath.py
index f32326db..7df06018 100644
--- a/meta-xilinx-core/scripts/lib/scriptpath.py
+++ b/meta-xilinx-core/scripts/lib/scriptpath.py
@@ -12,7 +12,7 @@ import os.path
12 12
13def add_oe_lib_path(): 13def add_oe_lib_path():
14 basepath = os.path.abspath(os.path.dirname(__file__) + '/../..') 14 basepath = os.path.abspath(os.path.dirname(__file__) + '/../..')
15 newpath = basepath + '/meta/lib' 15 newpath = basepath + '/lib'
16 sys.path.insert(0, newpath) 16 sys.path.insert(0, newpath)
17 17
18def add_bitbake_lib_path(): 18def add_bitbake_lib_path():
diff --git a/meta-xilinx-core/scripts/lib/wic/ksparser.py b/meta-xilinx-core/scripts/lib/wic/ksparser.py
index 7ef3dc83..98a98fa5 100644
--- a/meta-xilinx-core/scripts/lib/wic/ksparser.py
+++ b/meta-xilinx-core/scripts/lib/wic/ksparser.py
@@ -135,12 +135,13 @@ class KickStart():
135 DEFAULT_EXTRA_SPACE = 10*1024 135 DEFAULT_EXTRA_SPACE = 10*1024
136 DEFAULT_OVERHEAD_FACTOR = 1.3 136 DEFAULT_OVERHEAD_FACTOR = 1.3
137 137
138 def __init__(self, confpath): 138 def __init__(self, confpath, cmdline_args):
139 139
140 self.partitions = [] 140 self.partitions = []
141 self.bootloader = None 141 self.bootloader = None
142 self.lineno = 0 142 self.lineno = 0
143 self.partnum = 0 143 self.partnum = 0
144 self.cmdline_args = cmdline_args
144 145
145 parser = KickStartParser() 146 parser = KickStartParser()
146 subparsers = parser.add_subparsers() 147 subparsers = parser.add_subparsers()
@@ -281,7 +282,7 @@ class KickStart():
281 parsed.extra_space = self.DEFAULT_EXTRA_SPACE 282 parsed.extra_space = self.DEFAULT_EXTRA_SPACE
282 283
283 self.partnum += 1 284 self.partnum += 1
284 self.partitions.append(Partition(parsed, self.partnum)) 285 self.partitions.append(Partition(parsed, self.partnum, self.cmdline_args))
285 elif line.startswith('include'): 286 elif line.startswith('include'):
286 self._parse(parser, parsed.path) 287 self._parse(parser, parsed.path)
287 elif line.startswith('bootloader'): 288 elif line.startswith('bootloader'):
diff --git a/meta-xilinx-core/scripts/lib/wic/partition.py b/meta-xilinx-core/scripts/lib/wic/partition.py
index bf2c34d5..4dc5adfa 100644
--- a/meta-xilinx-core/scripts/lib/wic/partition.py
+++ b/meta-xilinx-core/scripts/lib/wic/partition.py
@@ -22,7 +22,7 @@ logger = logging.getLogger('wic')
22 22
23class Partition(): 23class Partition():
24 24
25 def __init__(self, args, lineno): 25 def __init__(self, args, lineno, cmdline_args):
26 self.args = args 26 self.args = args
27 self.active = args.active 27 self.active = args.active
28 self.align = args.align 28 self.align = args.align
@@ -61,6 +61,7 @@ class Partition():
61 self.update_fstab_in_rootfs = False 61 self.update_fstab_in_rootfs = False
62 self.hidden = args.hidden 62 self.hidden = args.hidden
63 self.mbr = args.mbr 63 self.mbr = args.mbr
64 self.sector_size = cmdline_args.sector_size
64 65
65 self.lineno = lineno 66 self.lineno = lineno
66 self.source_file = "" 67 self.source_file = ""
@@ -283,6 +284,8 @@ class Partition():
283 os.ftruncate(sparse.fileno(), rootfs_size * 1024) 284 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
284 285
285 extraopts = self.mkfs_extraopts or "-F -i 8192" 286 extraopts = self.mkfs_extraopts or "-F -i 8192"
287 if self.sector_size != 512:
288 extraopts += " -b %d" % self.sector_size
286 289
287 # use hash_seed to generate reproducible ext4 images 290 # use hash_seed to generate reproducible ext4 images
288 (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, pseudo) 291 (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, pseudo)
@@ -293,6 +296,7 @@ class Partition():
293 296
294 mkfs_cmd = "mkfs.%s %s %s %s -U %s -d %s" % \ 297 mkfs_cmd = "mkfs.%s %s %s %s -U %s -d %s" % \
295 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir) 298 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
299 logger.info("mkfs_cmd(rootfs): %s" % mkfs_cmd)
296 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) 300 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
297 301
298 if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update: 302 if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update:
@@ -390,11 +394,13 @@ class Partition():
390 394
391 size_str = "" 395 size_str = ""
392 396
393 extraopts = self.mkfs_extraopts or '-S 512' 397 extraopts = self.mkfs_extraopts
398 extraopts += " -S %d" % self.sector_size
394 399
395 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \ 400 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
396 (label_str, self.fsuuid, size_str, extraopts, rootfs, 401 (label_str, self.fsuuid, size_str, extraopts, rootfs,
397 rootfs_size) 402 rootfs_size)
403 logger.info("dosfs_cmd(rootfs): %s" % dosfs_cmd)
398 exec_native_cmd(dosfs_cmd, native_sysroot) 404 exec_native_cmd(dosfs_cmd, native_sysroot)
399 405
400 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir) 406 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
@@ -442,6 +448,8 @@ class Partition():
442 os.ftruncate(sparse.fileno(), size * 1024) 448 os.ftruncate(sparse.fileno(), size * 1024)
443 449
444 extraopts = self.mkfs_extraopts or "-i 8192" 450 extraopts = self.mkfs_extraopts or "-i 8192"
451 if self.sector_size != 512:
452 extraopts += " -b %s" % self.sector_size
445 453
446 # use hash_seed to generate reproducible ext4 images 454 # use hash_seed to generate reproducible ext4 images
447 (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, None) 455 (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, None)
@@ -452,6 +460,7 @@ class Partition():
452 460
453 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \ 461 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \
454 (self.fstype, extraopts, label_str, self.fsuuid, rootfs) 462 (self.fstype, extraopts, label_str, self.fsuuid, rootfs)
463 logger.info("mkfs_cmd(empty): %s" % mkfs_cmd)
455 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) 464 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
456 465
457 self.check_for_Y2038_problem(rootfs, native_sysroot) 466 self.check_for_Y2038_problem(rootfs, native_sysroot)
@@ -487,12 +496,13 @@ class Partition():
487 496
488 size_str = "" 497 size_str = ""
489 498
490 extraopts = self.mkfs_extraopts or '-S 512' 499 extraopts = self.mkfs_extraopts
500 extraopts += " -S %d" % self.sector_size
491 501
492 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \ 502 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
493 (label_str, self.fsuuid, extraopts, size_str, rootfs, 503 (label_str, self.fsuuid, extraopts, size_str, rootfs,
494 blocks) 504 blocks)
495 505 logger.info("dosfs_cmd(empty): %s" % dosfs_cmd)
496 exec_native_cmd(dosfs_cmd, native_sysroot) 506 exec_native_cmd(dosfs_cmd, native_sysroot)
497 507
498 chmod_cmd = "chmod 644 %s" % rootfs 508 chmod_cmd = "chmod 644 %s" % rootfs
diff --git a/meta-xilinx-core/scripts/lib/wic/plugins/imager/direct.py b/meta-xilinx-core/scripts/lib/wic/plugins/imager/direct.py
index a1d15265..75aa0644 100644
--- a/meta-xilinx-core/scripts/lib/wic/plugins/imager/direct.py
+++ b/meta-xilinx-core/scripts/lib/wic/plugins/imager/direct.py
@@ -43,7 +43,7 @@ class DirectPlugin(ImagerPlugin):
43 def __init__(self, wks_file, rootfs_dir, bootimg_dir, kernel_dir, 43 def __init__(self, wks_file, rootfs_dir, bootimg_dir, kernel_dir,
44 native_sysroot, oe_builddir, options): 44 native_sysroot, oe_builddir, options):
45 try: 45 try:
46 self.ks = KickStart(wks_file) 46 self.ks = KickStart(wks_file, options)
47 except KickStartError as err: 47 except KickStartError as err:
48 raise WicError(str(err)) 48 raise WicError(str(err))
49 49
@@ -60,6 +60,9 @@ class DirectPlugin(ImagerPlugin):
60 self.bmap = options.bmap 60 self.bmap = options.bmap
61 self.no_fstab_update = options.no_fstab_update 61 self.no_fstab_update = options.no_fstab_update
62 self.updated_fstab_path = None 62 self.updated_fstab_path = None
63 self.sector_size = options.sector_size
64 if self.sector_size != 512:
65 os.environ['PARTED_SECTOR_SIZE'] = "%d" % self.sector_size
63 66
64 self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0], 67 self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0],
65 strftime("%Y%m%d%H%M")) 68 strftime("%Y%m%d%H%M"))
@@ -77,8 +80,8 @@ class DirectPlugin(ImagerPlugin):
77 80
78 image_path = self._full_path(self.workdir, self.parts[0].disk, "direct") 81 image_path = self._full_path(self.workdir, self.parts[0].disk, "direct")
79 self._image = PartitionedImage(image_path, self.ptable_format, 82 self._image = PartitionedImage(image_path, self.ptable_format,
80 self.parts, self.native_sysroot, 83 self.parts, self.sector_size,
81 options.extra_space) 84 self.native_sysroot, options.extra_space)
82 85
83 def setup_workdir(self, workdir): 86 def setup_workdir(self, workdir):
84 if workdir: 87 if workdir:
@@ -292,15 +295,12 @@ MBR_OVERHEAD = 1
292# Overhead of the GPT partitioning scheme 295# Overhead of the GPT partitioning scheme
293GPT_OVERHEAD = 34 296GPT_OVERHEAD = 34
294 297
295# Size of a sector in bytes
296SECTOR_SIZE = 512
297
298class PartitionedImage(): 298class PartitionedImage():
299 """ 299 """
300 Partitioned image in a file. 300 Partitioned image in a file.
301 """ 301 """
302 302
303 def __init__(self, path, ptable_format, partitions, native_sysroot=None, extra_space=0): 303 def __init__(self, path, ptable_format, partitions, sector_size, native_sysroot=None, extra_space=0):
304 self.path = path # Path to the image file 304 self.path = path # Path to the image file
305 self.numpart = 0 # Number of allocated partitions 305 self.numpart = 0 # Number of allocated partitions
306 self.realpart = 0 # Number of partitions in the partition table 306 self.realpart = 0 # Number of partitions in the partition table
@@ -321,7 +321,7 @@ class PartitionedImage():
321 self.partitions = partitions 321 self.partitions = partitions
322 self.partimages = [] 322 self.partimages = []
323 # Size of a sector used in calculations 323 # Size of a sector used in calculations
324 self.sector_size = SECTOR_SIZE 324 self.sector_size = sector_size
325 self.native_sysroot = native_sysroot 325 self.native_sysroot = native_sysroot
326 num_real_partitions = len([p for p in self.partitions if not p.no_table]) 326 num_real_partitions = len([p for p in self.partitions if not p.no_table])
327 self.extra_space = extra_space 327 self.extra_space = extra_space
diff --git a/meta-xilinx-core/scripts/wic b/meta-xilinx-core/scripts/wic
index 06e0b48d..c0ba6d71 100755
--- a/meta-xilinx-core/scripts/wic
+++ b/meta-xilinx-core/scripts/wic
@@ -14,7 +14,7 @@
14# AUTHORS 14# AUTHORS
15# Tom Zanussi <tom.zanussi (at] linux.intel.com> 15# Tom Zanussi <tom.zanussi (at] linux.intel.com>
16# 16#
17__version__ = "0.2.0" 17__version__ = "0.2.0 (meta-xilinx-core)"
18 18
19# Python Standard Library modules 19# Python Standard Library modules
20import os 20import os
@@ -351,6 +351,8 @@ def wic_init_parser_create(subparser):
351 default="direct", help="the wic imager plugin") 351 default="direct", help="the wic imager plugin")
352 subparser.add_argument("--extra-space", type=int, dest="extra_space", 352 subparser.add_argument("--extra-space", type=int, dest="extra_space",
353 default=0, help="additional free disk space to add to the image") 353 default=0, help="additional free disk space to add to the image")
354 subparser.add_argument("--sector-size", type=int, dest="sector_size",
355 default=512, help="sector size to use")
354 return 356 return
355 357
356 358