diff options
Diffstat (limited to 'scripts/lib/wic')
-rw-r--r-- | scripts/lib/wic/engine.py | 6 | ||||
-rw-r--r-- | scripts/lib/wic/help.py | 4 | ||||
-rw-r--r-- | scripts/lib/wic/misc.py | 17 | ||||
-rw-r--r-- | scripts/lib/wic/partition.py | 40 | ||||
-rw-r--r-- | scripts/lib/wic/pluginbase.py | 8 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/imager/direct.py | 2 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-efi.py | 7 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-pcbios.py | 6 |
8 files changed, 76 insertions, 14 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py index 9ff4394757..7dbde85696 100644 --- a/scripts/lib/wic/engine.py +++ b/scripts/lib/wic/engine.py | |||
@@ -19,10 +19,10 @@ import os | |||
19 | import tempfile | 19 | import tempfile |
20 | import json | 20 | import json |
21 | import subprocess | 21 | import subprocess |
22 | import shutil | ||
22 | import re | 23 | import re |
23 | 24 | ||
24 | from collections import namedtuple, OrderedDict | 25 | from collections import namedtuple, OrderedDict |
25 | from distutils.spawn import find_executable | ||
26 | 26 | ||
27 | from wic import WicError | 27 | from wic import WicError |
28 | from wic.filemap import sparse_copy | 28 | from wic.filemap import sparse_copy |
@@ -245,7 +245,7 @@ class Disk: | |||
245 | for path in pathlist.split(':'): | 245 | for path in pathlist.split(':'): |
246 | self.paths = "%s%s:%s" % (native_sysroot, path, self.paths) | 246 | self.paths = "%s%s:%s" % (native_sysroot, path, self.paths) |
247 | 247 | ||
248 | self.parted = find_executable("parted", self.paths) | 248 | self.parted = shutil.which("parted", path=self.paths) |
249 | if not self.parted: | 249 | if not self.parted: |
250 | raise WicError("Can't find executable parted") | 250 | raise WicError("Can't find executable parted") |
251 | 251 | ||
@@ -283,7 +283,7 @@ class Disk: | |||
283 | "resize2fs", "mkswap", "mkdosfs", "debugfs"): | 283 | "resize2fs", "mkswap", "mkdosfs", "debugfs"): |
284 | aname = "_%s" % name | 284 | aname = "_%s" % name |
285 | if aname not in self.__dict__: | 285 | if aname not in self.__dict__: |
286 | setattr(self, aname, find_executable(name, self.paths)) | 286 | setattr(self, aname, shutil.which(name, path=self.paths)) |
287 | if aname not in self.__dict__ or self.__dict__[aname] is None: | 287 | if aname not in self.__dict__ or self.__dict__[aname] is None: |
288 | raise WicError("Can't find executable '{}'".format(name)) | 288 | raise WicError("Can't find executable '{}'".format(name)) |
289 | return self.__dict__[aname] | 289 | return self.__dict__[aname] |
diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py index 62a2a90e79..fcace95ff4 100644 --- a/scripts/lib/wic/help.py +++ b/scripts/lib/wic/help.py | |||
@@ -840,8 +840,8 @@ DESCRIPTION | |||
840 | meanings. The commands are based on the Fedora kickstart | 840 | meanings. The commands are based on the Fedora kickstart |
841 | documentation but with modifications to reflect wic capabilities. | 841 | documentation but with modifications to reflect wic capabilities. |
842 | 842 | ||
843 | http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition | 843 | https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#part-or-partition |
844 | http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader | 844 | https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#bootloader |
845 | 845 | ||
846 | Commands | 846 | Commands |
847 | 847 | ||
diff --git a/scripts/lib/wic/misc.py b/scripts/lib/wic/misc.py index e4b5a0d519..3e11822996 100644 --- a/scripts/lib/wic/misc.py +++ b/scripts/lib/wic/misc.py | |||
@@ -16,9 +16,9 @@ import logging | |||
16 | import os | 16 | import os |
17 | import re | 17 | import re |
18 | import subprocess | 18 | import subprocess |
19 | import shutil | ||
19 | 20 | ||
20 | from collections import defaultdict | 21 | from collections import defaultdict |
21 | from distutils import spawn | ||
22 | 22 | ||
23 | from wic import WicError | 23 | from wic import WicError |
24 | 24 | ||
@@ -26,6 +26,7 @@ logger = logging.getLogger('wic') | |||
26 | 26 | ||
27 | # executable -> recipe pairs for exec_native_cmd | 27 | # executable -> recipe pairs for exec_native_cmd |
28 | NATIVE_RECIPES = {"bmaptool": "bmap-tools", | 28 | NATIVE_RECIPES = {"bmaptool": "bmap-tools", |
29 | "dumpe2fs": "e2fsprogs", | ||
29 | "grub-mkimage": "grub-efi", | 30 | "grub-mkimage": "grub-efi", |
30 | "isohybrid": "syslinux", | 31 | "isohybrid": "syslinux", |
31 | "mcopy": "mtools", | 32 | "mcopy": "mtools", |
@@ -45,7 +46,8 @@ NATIVE_RECIPES = {"bmaptool": "bmap-tools", | |||
45 | "parted": "parted", | 46 | "parted": "parted", |
46 | "sfdisk": "util-linux", | 47 | "sfdisk": "util-linux", |
47 | "sgdisk": "gptfdisk", | 48 | "sgdisk": "gptfdisk", |
48 | "syslinux": "syslinux" | 49 | "syslinux": "syslinux", |
50 | "tar": "tar" | ||
49 | } | 51 | } |
50 | 52 | ||
51 | def runtool(cmdln_or_args): | 53 | def runtool(cmdln_or_args): |
@@ -112,6 +114,15 @@ def exec_cmd(cmd_and_args, as_shell=False): | |||
112 | """ | 114 | """ |
113 | return _exec_cmd(cmd_and_args, as_shell)[1] | 115 | return _exec_cmd(cmd_and_args, as_shell)[1] |
114 | 116 | ||
117 | def find_executable(cmd, paths): | ||
118 | recipe = cmd | ||
119 | if recipe in NATIVE_RECIPES: | ||
120 | recipe = NATIVE_RECIPES[recipe] | ||
121 | provided = get_bitbake_var("ASSUME_PROVIDED") | ||
122 | if provided and "%s-native" % recipe in provided: | ||
123 | return True | ||
124 | |||
125 | return shutil.which(cmd, path=paths) | ||
115 | 126 | ||
116 | def exec_native_cmd(cmd_and_args, native_sysroot, pseudo=""): | 127 | def exec_native_cmd(cmd_and_args, native_sysroot, pseudo=""): |
117 | """ | 128 | """ |
@@ -140,7 +151,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, pseudo=""): | |||
140 | logger.debug("exec_native_cmd: %s", native_cmd_and_args) | 151 | logger.debug("exec_native_cmd: %s", native_cmd_and_args) |
141 | 152 | ||
142 | # If the command isn't in the native sysroot say we failed. | 153 | # If the command isn't in the native sysroot say we failed. |
143 | if spawn.find_executable(args[0], native_paths): | 154 | if find_executable(args[0], native_paths): |
144 | ret, out = _exec_cmd(native_cmd_and_args, True) | 155 | ret, out = _exec_cmd(native_cmd_and_args, True) |
145 | else: | 156 | else: |
146 | ret = 127 | 157 | ret = 127 |
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py index e574f40c47..792bb3dcd3 100644 --- a/scripts/lib/wic/partition.py +++ b/scripts/lib/wic/partition.py | |||
@@ -104,7 +104,7 @@ class Partition(): | |||
104 | extra_blocks = self.extra_space | 104 | extra_blocks = self.extra_space |
105 | 105 | ||
106 | rootfs_size = actual_rootfs_size + extra_blocks | 106 | rootfs_size = actual_rootfs_size + extra_blocks |
107 | rootfs_size *= self.overhead_factor | 107 | rootfs_size = int(rootfs_size * self.overhead_factor) |
108 | 108 | ||
109 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", | 109 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", |
110 | extra_blocks, self.mountpoint, rootfs_size) | 110 | extra_blocks, self.mountpoint, rootfs_size) |
@@ -298,6 +298,8 @@ class Partition(): | |||
298 | mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) | 298 | mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) |
299 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) | 299 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) |
300 | 300 | ||
301 | self.check_for_Y2038_problem(rootfs, native_sysroot) | ||
302 | |||
301 | def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, | 303 | def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, |
302 | native_sysroot, pseudo): | 304 | native_sysroot, pseudo): |
303 | """ | 305 | """ |
@@ -388,6 +390,8 @@ class Partition(): | |||
388 | (self.fstype, extraopts, label_str, self.fsuuid, rootfs) | 390 | (self.fstype, extraopts, label_str, self.fsuuid, rootfs) |
389 | exec_native_cmd(mkfs_cmd, native_sysroot) | 391 | exec_native_cmd(mkfs_cmd, native_sysroot) |
390 | 392 | ||
393 | self.check_for_Y2038_problem(rootfs, native_sysroot) | ||
394 | |||
391 | def prepare_empty_partition_btrfs(self, rootfs, oe_builddir, | 395 | def prepare_empty_partition_btrfs(self, rootfs, oe_builddir, |
392 | native_sysroot): | 396 | native_sysroot): |
393 | """ | 397 | """ |
@@ -449,3 +453,37 @@ class Partition(): | |||
449 | 453 | ||
450 | mkswap_cmd = "mkswap %s -U %s %s" % (label_str, self.fsuuid, path) | 454 | mkswap_cmd = "mkswap %s -U %s %s" % (label_str, self.fsuuid, path) |
451 | exec_native_cmd(mkswap_cmd, native_sysroot) | 455 | exec_native_cmd(mkswap_cmd, native_sysroot) |
456 | |||
457 | def check_for_Y2038_problem(self, rootfs, native_sysroot): | ||
458 | """ | ||
459 | Check if the filesystem is affected by the Y2038 problem | ||
460 | (Y2038 problem = 32 bit time_t overflow in January 2038) | ||
461 | """ | ||
462 | def get_err_str(part): | ||
463 | err = "The {} filesystem {} has no Y2038 support." | ||
464 | if part.mountpoint: | ||
465 | args = [part.fstype, "mounted at %s" % part.mountpoint] | ||
466 | elif part.label: | ||
467 | args = [part.fstype, "labeled '%s'" % part.label] | ||
468 | elif part.part_name: | ||
469 | args = [part.fstype, "in partition '%s'" % part.part_name] | ||
470 | else: | ||
471 | args = [part.fstype, "in partition %s" % part.num] | ||
472 | return err.format(*args) | ||
473 | |||
474 | # ext2 and ext3 are always affected by the Y2038 problem | ||
475 | if self.fstype in ["ext2", "ext3"]: | ||
476 | logger.warn(get_err_str(self)) | ||
477 | return | ||
478 | |||
479 | ret, out = exec_native_cmd("dumpe2fs %s" % rootfs, native_sysroot) | ||
480 | |||
481 | # if ext4 is affected by the Y2038 problem depends on the inode size | ||
482 | for line in out.splitlines(): | ||
483 | if line.startswith("Inode size:"): | ||
484 | size = int(line.split(":")[1].strip()) | ||
485 | if size < 256: | ||
486 | logger.warn("%s Inodes (of size %d) are too small." % | ||
487 | (get_err_str(self), size)) | ||
488 | break | ||
489 | |||
diff --git a/scripts/lib/wic/pluginbase.py b/scripts/lib/wic/pluginbase.py index d9b4e57747..b64568339b 100644 --- a/scripts/lib/wic/pluginbase.py +++ b/scripts/lib/wic/pluginbase.py | |||
@@ -9,9 +9,11 @@ __all__ = ['ImagerPlugin', 'SourcePlugin'] | |||
9 | 9 | ||
10 | import os | 10 | import os |
11 | import logging | 11 | import logging |
12 | import types | ||
12 | 13 | ||
13 | from collections import defaultdict | 14 | from collections import defaultdict |
14 | from importlib.machinery import SourceFileLoader | 15 | import importlib |
16 | import importlib.util | ||
15 | 17 | ||
16 | from wic import WicError | 18 | from wic import WicError |
17 | from wic.misc import get_bitbake_var | 19 | from wic.misc import get_bitbake_var |
@@ -54,7 +56,9 @@ class PluginMgr: | |||
54 | mname = fname[:-3] | 56 | mname = fname[:-3] |
55 | mpath = os.path.join(ppath, fname) | 57 | mpath = os.path.join(ppath, fname) |
56 | logger.debug("loading plugin module %s", mpath) | 58 | logger.debug("loading plugin module %s", mpath) |
57 | SourceFileLoader(mname, mpath).load_module() | 59 | spec = importlib.util.spec_from_file_location(mname, mpath) |
60 | module = importlib.util.module_from_spec(spec) | ||
61 | spec.loader.exec_module(module) | ||
58 | 62 | ||
59 | return PLUGINS.get(ptype) | 63 | return PLUGINS.get(ptype) |
60 | 64 | ||
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index 7e1c1c03ab..42704d1e10 100644 --- a/scripts/lib/wic/plugins/imager/direct.py +++ b/scripts/lib/wic/plugins/imager/direct.py | |||
@@ -115,7 +115,7 @@ class DirectPlugin(ImagerPlugin): | |||
115 | updated = False | 115 | updated = False |
116 | for part in self.parts: | 116 | for part in self.parts: |
117 | if not part.realnum or not part.mountpoint \ | 117 | if not part.realnum or not part.mountpoint \ |
118 | or part.mountpoint == "/": | 118 | or part.mountpoint == "/" or not (part.mountpoint.startswith('/') or part.mountpoint == "swap"): |
119 | continue | 119 | continue |
120 | 120 | ||
121 | if part.use_uuid: | 121 | if part.use_uuid: |
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py index 2cfdc10ecd..05e8471116 100644 --- a/scripts/lib/wic/plugins/source/bootimg-efi.py +++ b/scripts/lib/wic/plugins/source/bootimg-efi.py | |||
@@ -277,6 +277,13 @@ class BootimgEFIPlugin(SourcePlugin): | |||
277 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", | 277 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", |
278 | extra_blocks, part.mountpoint, blocks) | 278 | extra_blocks, part.mountpoint, blocks) |
279 | 279 | ||
280 | # required for compatibility with certain devices expecting file system | ||
281 | # block count to be equal to partition block count | ||
282 | if blocks < part.fixed_size: | ||
283 | blocks = part.fixed_size | ||
284 | logger.debug("Overriding %s to %d total blocks for compatibility", | ||
285 | part.mountpoint, blocks) | ||
286 | |||
280 | # dosfs image, created by mkdosfs | 287 | # dosfs image, created by mkdosfs |
281 | bootimg = "%s/boot.img" % cr_workdir | 288 | bootimg = "%s/boot.img" % cr_workdir |
282 | 289 | ||
diff --git a/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/scripts/lib/wic/plugins/source/bootimg-pcbios.py index f2639e7004..32e47f1831 100644 --- a/scripts/lib/wic/plugins/source/bootimg-pcbios.py +++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py | |||
@@ -186,8 +186,10 @@ class BootimgPcbiosPlugin(SourcePlugin): | |||
186 | # dosfs image, created by mkdosfs | 186 | # dosfs image, created by mkdosfs |
187 | bootimg = "%s/boot%s.img" % (cr_workdir, part.lineno) | 187 | bootimg = "%s/boot%s.img" % (cr_workdir, part.lineno) |
188 | 188 | ||
189 | dosfs_cmd = "mkdosfs -n boot -i %s -S 512 -C %s %d" % \ | 189 | label = part.label if part.label else "boot" |
190 | (part.fsuuid, bootimg, blocks) | 190 | |
191 | dosfs_cmd = "mkdosfs -n %s -i %s -S 512 -C %s %d" % \ | ||
192 | (label, part.fsuuid, bootimg, blocks) | ||
191 | exec_native_cmd(dosfs_cmd, native_sysroot) | 193 | exec_native_cmd(dosfs_cmd, native_sysroot) |
192 | 194 | ||
193 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | 195 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) |