diff options
Diffstat (limited to 'scripts/lib/wic/partition.py')
-rw-r--r-- | scripts/lib/wic/partition.py | 73 |
1 files changed, 65 insertions, 8 deletions
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py index 76d144d12d..795707ec5d 100644 --- a/scripts/lib/wic/partition.py +++ b/scripts/lib/wic/partition.py | |||
@@ -33,6 +33,7 @@ class Partition(): | |||
33 | self.include_path = args.include_path | 33 | self.include_path = args.include_path |
34 | self.change_directory = args.change_directory | 34 | self.change_directory = args.change_directory |
35 | self.fsopts = args.fsopts | 35 | self.fsopts = args.fsopts |
36 | self.fspassno = args.fspassno | ||
36 | self.fstype = args.fstype | 37 | self.fstype = args.fstype |
37 | self.label = args.label | 38 | self.label = args.label |
38 | self.use_label = args.use_label | 39 | self.use_label = args.use_label |
@@ -54,9 +55,12 @@ class Partition(): | |||
54 | self.uuid = args.uuid | 55 | self.uuid = args.uuid |
55 | self.fsuuid = args.fsuuid | 56 | self.fsuuid = args.fsuuid |
56 | self.type = args.type | 57 | self.type = args.type |
58 | self.no_fstab_update = args.no_fstab_update | ||
57 | self.updated_fstab_path = None | 59 | self.updated_fstab_path = None |
58 | self.has_fstab = False | 60 | self.has_fstab = False |
59 | self.update_fstab_in_rootfs = False | 61 | self.update_fstab_in_rootfs = False |
62 | self.hidden = args.hidden | ||
63 | self.mbr = args.mbr | ||
60 | 64 | ||
61 | self.lineno = lineno | 65 | self.lineno = lineno |
62 | self.source_file = "" | 66 | self.source_file = "" |
@@ -104,7 +108,7 @@ class Partition(): | |||
104 | extra_blocks = self.extra_space | 108 | extra_blocks = self.extra_space |
105 | 109 | ||
106 | rootfs_size = actual_rootfs_size + extra_blocks | 110 | rootfs_size = actual_rootfs_size + extra_blocks |
107 | rootfs_size *= self.overhead_factor | 111 | rootfs_size = int(rootfs_size * self.overhead_factor) |
108 | 112 | ||
109 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", | 113 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", |
110 | extra_blocks, self.mountpoint, rootfs_size) | 114 | extra_blocks, self.mountpoint, rootfs_size) |
@@ -131,6 +135,8 @@ class Partition(): | |||
131 | self.update_fstab_in_rootfs = True | 135 | self.update_fstab_in_rootfs = True |
132 | 136 | ||
133 | if not self.source: | 137 | if not self.source: |
138 | if self.fstype == "none" or self.no_table: | ||
139 | return | ||
134 | if not self.size and not self.fixed_size: | 140 | if not self.size and not self.fixed_size: |
135 | raise WicError("The %s partition has a size of zero. Please " | 141 | raise WicError("The %s partition has a size of zero. Please " |
136 | "specify a non-zero --size/--fixed-size for that " | 142 | "specify a non-zero --size/--fixed-size for that " |
@@ -141,9 +147,9 @@ class Partition(): | |||
141 | native_sysroot) | 147 | native_sysroot) |
142 | self.source_file = "%s/fs.%s" % (cr_workdir, self.fstype) | 148 | self.source_file = "%s/fs.%s" % (cr_workdir, self.fstype) |
143 | else: | 149 | else: |
144 | if self.fstype == 'squashfs': | 150 | if self.fstype in ('squashfs', 'erofs'): |
145 | raise WicError("It's not possible to create empty squashfs " | 151 | raise WicError("It's not possible to create empty %s " |
146 | "partition '%s'" % (self.mountpoint)) | 152 | "partition '%s'" % (self.fstype, self.mountpoint)) |
147 | 153 | ||
148 | rootfs = "%s/fs_%s.%s.%s" % (cr_workdir, self.label, | 154 | rootfs = "%s/fs_%s.%s.%s" % (cr_workdir, self.label, |
149 | self.lineno, self.fstype) | 155 | self.lineno, self.fstype) |
@@ -170,7 +176,7 @@ class Partition(): | |||
170 | # Split sourceparams string of the form key1=val1[,key2=val2,...] | 176 | # Split sourceparams string of the form key1=val1[,key2=val2,...] |
171 | # into a dict. Also accepts valueless keys i.e. without = | 177 | # into a dict. Also accepts valueless keys i.e. without = |
172 | splitted = self.sourceparams.split(',') | 178 | splitted = self.sourceparams.split(',') |
173 | srcparams_dict = dict(par.split('=', 1) for par in splitted if par) | 179 | srcparams_dict = dict((par.split('=', 1) + [None])[:2] for par in splitted if par) |
174 | 180 | ||
175 | plugin = PluginMgr.get_plugins('source')[self.source] | 181 | plugin = PluginMgr.get_plugins('source')[self.source] |
176 | plugin.do_configure_partition(self, srcparams_dict, creator, | 182 | plugin.do_configure_partition(self, srcparams_dict, creator, |
@@ -278,6 +284,20 @@ class Partition(): | |||
278 | 284 | ||
279 | extraopts = self.mkfs_extraopts or "-F -i 8192" | 285 | extraopts = self.mkfs_extraopts or "-F -i 8192" |
280 | 286 | ||
287 | if os.getenv('SOURCE_DATE_EPOCH'): | ||
288 | sde_time = int(os.getenv('SOURCE_DATE_EPOCH')) | ||
289 | if pseudo: | ||
290 | pseudo = "export E2FSPROGS_FAKE_TIME=%s;%s " % (sde_time, pseudo) | ||
291 | else: | ||
292 | pseudo = "export E2FSPROGS_FAKE_TIME=%s; " % sde_time | ||
293 | |||
294 | # Set hash_seed to generate deterministic directory indexes | ||
295 | namespace = uuid.UUID("e7429877-e7b3-4a68-a5c9-2f2fdf33d460") | ||
296 | if self.fsuuid: | ||
297 | namespace = uuid.UUID(self.fsuuid) | ||
298 | hash_seed = str(uuid.uuid5(namespace, str(sde_time))) | ||
299 | extraopts += " -E hash_seed=%s" % hash_seed | ||
300 | |||
281 | label_str = "" | 301 | label_str = "" |
282 | if self.label: | 302 | if self.label: |
283 | label_str = "-L %s" % self.label | 303 | label_str = "-L %s" % self.label |
@@ -286,7 +306,7 @@ class Partition(): | |||
286 | (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir) | 306 | (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir) |
287 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) | 307 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) |
288 | 308 | ||
289 | if self.updated_fstab_path and self.has_fstab: | 309 | if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update: |
290 | debugfs_script_path = os.path.join(cr_workdir, "debugfs_script") | 310 | debugfs_script_path = os.path.join(cr_workdir, "debugfs_script") |
291 | with open(debugfs_script_path, "w") as f: | 311 | with open(debugfs_script_path, "w") as f: |
292 | f.write("cd etc\n") | 312 | f.write("cd etc\n") |
@@ -298,6 +318,30 @@ class Partition(): | |||
298 | mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) | 318 | mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) |
299 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) | 319 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) |
300 | 320 | ||
321 | if os.getenv('SOURCE_DATE_EPOCH'): | ||
322 | sde_time = hex(int(os.getenv('SOURCE_DATE_EPOCH'))) | ||
323 | debugfs_script_path = os.path.join(cr_workdir, "debugfs_script") | ||
324 | files = [] | ||
325 | for root, dirs, others in os.walk(rootfs_dir): | ||
326 | base = root.replace(rootfs_dir, "").rstrip(os.sep) | ||
327 | files += [ "/" if base == "" else base ] | ||
328 | files += [ base + "/" + n for n in dirs + others ] | ||
329 | with open(debugfs_script_path, "w") as f: | ||
330 | f.write("set_current_time %s\n" % (sde_time)) | ||
331 | if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update: | ||
332 | f.write("set_inode_field /etc/fstab mtime %s\n" % (sde_time)) | ||
333 | f.write("set_inode_field /etc/fstab mtime_extra 0\n") | ||
334 | for file in set(files): | ||
335 | for time in ["atime", "ctime", "crtime"]: | ||
336 | f.write("set_inode_field \"%s\" %s %s\n" % (file, time, sde_time)) | ||
337 | f.write("set_inode_field \"%s\" %s_extra 0\n" % (file, time)) | ||
338 | for time in ["wtime", "mkfs_time", "lastcheck"]: | ||
339 | f.write("set_super_value %s %s\n" % (time, sde_time)) | ||
340 | for time in ["mtime", "first_error_time", "last_error_time"]: | ||
341 | f.write("set_super_value %s 0\n" % (time)) | ||
342 | debugfs_cmd = "debugfs -w -f %s %s" % (debugfs_script_path, rootfs) | ||
343 | exec_native_cmd(debugfs_cmd, native_sysroot) | ||
344 | |||
301 | self.check_for_Y2038_problem(rootfs, native_sysroot) | 345 | self.check_for_Y2038_problem(rootfs, native_sysroot) |
302 | 346 | ||
303 | def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, | 347 | def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, |
@@ -350,8 +394,8 @@ class Partition(): | |||
350 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir) | 394 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir) |
351 | exec_native_cmd(mcopy_cmd, native_sysroot) | 395 | exec_native_cmd(mcopy_cmd, native_sysroot) |
352 | 396 | ||
353 | if self.updated_fstab_path and self.has_fstab: | 397 | if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update: |
354 | mcopy_cmd = "mcopy -i %s %s ::/etc/fstab" % (rootfs, self.updated_fstab_path) | 398 | mcopy_cmd = "mcopy -m -i %s %s ::/etc/fstab" % (rootfs, self.updated_fstab_path) |
355 | exec_native_cmd(mcopy_cmd, native_sysroot) | 399 | exec_native_cmd(mcopy_cmd, native_sysroot) |
356 | 400 | ||
357 | chmod_cmd = "chmod 644 %s" % rootfs | 401 | chmod_cmd = "chmod 644 %s" % rootfs |
@@ -369,6 +413,19 @@ class Partition(): | |||
369 | (rootfs_dir, rootfs, extraopts) | 413 | (rootfs_dir, rootfs, extraopts) |
370 | exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo) | 414 | exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo) |
371 | 415 | ||
416 | def prepare_rootfs_erofs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, | ||
417 | native_sysroot, pseudo): | ||
418 | """ | ||
419 | Prepare content for a erofs rootfs partition. | ||
420 | """ | ||
421 | extraopts = self.mkfs_extraopts or '' | ||
422 | erofs_cmd = "mkfs.erofs %s -U %s %s %s" % \ | ||
423 | (extraopts, self.fsuuid, rootfs, rootfs_dir) | ||
424 | exec_native_cmd(erofs_cmd, native_sysroot, pseudo=pseudo) | ||
425 | |||
426 | def prepare_empty_partition_none(self, rootfs, oe_builddir, native_sysroot): | ||
427 | pass | ||
428 | |||
372 | def prepare_empty_partition_ext(self, rootfs, oe_builddir, | 429 | def prepare_empty_partition_ext(self, rootfs, oe_builddir, |
373 | native_sysroot): | 430 | native_sysroot): |
374 | """ | 431 | """ |