summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/partition.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/partition.py')
-rw-r--r--scripts/lib/wic/partition.py76
1 files changed, 67 insertions, 9 deletions
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index a25834048e..b34691d313 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
@@ -58,6 +59,8 @@ class Partition():
58 self.updated_fstab_path = None 59 self.updated_fstab_path = None
59 self.has_fstab = False 60 self.has_fstab = False
60 self.update_fstab_in_rootfs = False 61 self.update_fstab_in_rootfs = False
62 self.hidden = args.hidden
63 self.mbr = args.mbr
61 64
62 self.lineno = lineno 65 self.lineno = lineno
63 self.source_file = "" 66 self.source_file = ""
@@ -132,6 +135,8 @@ class Partition():
132 self.update_fstab_in_rootfs = True 135 self.update_fstab_in_rootfs = True
133 136
134 if not self.source: 137 if not self.source:
138 if self.fstype == "none" or self.no_table:
139 return
135 if not self.size and not self.fixed_size: 140 if not self.size and not self.fixed_size:
136 raise WicError("The %s partition has a size of zero. Please " 141 raise WicError("The %s partition has a size of zero. Please "
137 "specify a non-zero --size/--fixed-size for that " 142 "specify a non-zero --size/--fixed-size for that "
@@ -159,6 +164,9 @@ class Partition():
159 164
160 plugins = PluginMgr.get_plugins('source') 165 plugins = PluginMgr.get_plugins('source')
161 166
167 # Don't support '-' in plugin names
168 self.source = self.source.replace("-", "_")
169
162 if self.source not in plugins: 170 if self.source not in plugins:
163 raise WicError("The '%s' --source specified for %s doesn't exist.\n\t" 171 raise WicError("The '%s' --source specified for %s doesn't exist.\n\t"
164 "See 'wic list source-plugins' for a list of available" 172 "See 'wic list source-plugins' for a list of available"
@@ -171,9 +179,9 @@ class Partition():
171 # Split sourceparams string of the form key1=val1[,key2=val2,...] 179 # Split sourceparams string of the form key1=val1[,key2=val2,...]
172 # into a dict. Also accepts valueless keys i.e. without = 180 # into a dict. Also accepts valueless keys i.e. without =
173 splitted = self.sourceparams.split(',') 181 splitted = self.sourceparams.split(',')
174 srcparams_dict = dict(par.split('=', 1) for par in splitted if par) 182 srcparams_dict = dict((par.split('=', 1) + [None])[:2] for par in splitted if par)
175 183
176 plugin = PluginMgr.get_plugins('source')[self.source] 184 plugin = plugins[self.source]
177 plugin.do_configure_partition(self, srcparams_dict, creator, 185 plugin.do_configure_partition(self, srcparams_dict, creator,
178 cr_workdir, oe_builddir, bootimg_dir, 186 cr_workdir, oe_builddir, bootimg_dir,
179 kernel_dir, native_sysroot) 187 kernel_dir, native_sysroot)
@@ -217,19 +225,19 @@ class Partition():
217 if (pseudo_dir): 225 if (pseudo_dir):
218 # Canonicalize the ignore paths. This corresponds to 226 # Canonicalize the ignore paths. This corresponds to
219 # calling oe.path.canonicalize(), which is used in bitbake.conf. 227 # calling oe.path.canonicalize(), which is used in bitbake.conf.
220 ignore_paths = [rootfs] + (get_bitbake_var("PSEUDO_IGNORE_PATHS") or "").split(",") 228 include_paths = [rootfs_dir] + (get_bitbake_var("PSEUDO_INCLUDE_PATHS") or "").split(",")
221 canonical_paths = [] 229 canonical_paths = []
222 for path in ignore_paths: 230 for path in include_paths:
223 if "$" not in path: 231 if "$" not in path:
224 trailing_slash = path.endswith("/") and "/" or "" 232 trailing_slash = path.endswith("/") and "/" or ""
225 canonical_paths.append(os.path.realpath(path) + trailing_slash) 233 canonical_paths.append(os.path.realpath(path) + trailing_slash)
226 ignore_paths = ",".join(canonical_paths) 234 include_paths = ",".join(canonical_paths)
227 235
228 pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix 236 pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix
229 pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % pseudo_dir 237 pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % pseudo_dir
230 pseudo += "export PSEUDO_PASSWD=%s;" % rootfs_dir 238 pseudo += "export PSEUDO_PASSWD=%s;" % rootfs_dir
231 pseudo += "export PSEUDO_NOSYMLINKEXP=1;" 239 pseudo += "export PSEUDO_NOSYMLINKEXP=1;"
232 pseudo += "export PSEUDO_IGNORE_PATHS=%s;" % ignore_paths 240 pseudo += "export PSEUDO_INCLUDE_PATHS=%s;" % include_paths
233 pseudo += "%s " % get_bitbake_var("FAKEROOTCMD") 241 pseudo += "%s " % get_bitbake_var("FAKEROOTCMD")
234 else: 242 else:
235 pseudo = None 243 pseudo = None
@@ -239,7 +247,7 @@ class Partition():
239 # from bitbake variable 247 # from bitbake variable
240 rsize_bb = get_bitbake_var('ROOTFS_SIZE') 248 rsize_bb = get_bitbake_var('ROOTFS_SIZE')
241 rdir = get_bitbake_var('IMAGE_ROOTFS') 249 rdir = get_bitbake_var('IMAGE_ROOTFS')
242 if rsize_bb and rdir == rootfs_dir: 250 if rsize_bb and (rdir == rootfs_dir or (rootfs_dir.split('/')[-2] == "tmp-wic" and rootfs_dir.split('/')[-1][:6] == "rootfs")):
243 # Bitbake variable ROOTFS_SIZE is calculated in 251 # Bitbake variable ROOTFS_SIZE is calculated in
244 # Image._get_rootfs_size method from meta/lib/oe/image.py 252 # Image._get_rootfs_size method from meta/lib/oe/image.py
245 # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT, 253 # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT,
@@ -279,6 +287,9 @@ class Partition():
279 287
280 extraopts = self.mkfs_extraopts or "-F -i 8192" 288 extraopts = self.mkfs_extraopts or "-F -i 8192"
281 289
290 # use hash_seed to generate reproducible ext4 images
291 (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, pseudo)
292
282 label_str = "" 293 label_str = ""
283 if self.label: 294 if self.label:
284 label_str = "-L %s" % self.label 295 label_str = "-L %s" % self.label
@@ -299,8 +310,49 @@ class Partition():
299 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) 310 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs)
300 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) 311 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
301 312
313 if os.getenv('SOURCE_DATE_EPOCH'):
314 sde_time = hex(int(os.getenv('SOURCE_DATE_EPOCH')))
315 debugfs_script_path = os.path.join(cr_workdir, "debugfs_script")
316 files = []
317 for root, dirs, others in os.walk(rootfs_dir):
318 base = root.replace(rootfs_dir, "").rstrip(os.sep)
319 files += [ "/" if base == "" else base ]
320 files += [ base + "/" + n for n in dirs + others ]
321 with open(debugfs_script_path, "w") as f:
322 f.write("set_current_time %s\n" % (sde_time))
323 if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update:
324 f.write("set_inode_field /etc/fstab mtime %s\n" % (sde_time))
325 f.write("set_inode_field /etc/fstab mtime_extra 0\n")
326 for file in set(files):
327 for time in ["atime", "ctime", "crtime"]:
328 f.write("set_inode_field \"%s\" %s %s\n" % (file, time, sde_time))
329 f.write("set_inode_field \"%s\" %s_extra 0\n" % (file, time))
330 for time in ["wtime", "mkfs_time", "lastcheck"]:
331 f.write("set_super_value %s %s\n" % (time, sde_time))
332 for time in ["mtime", "first_error_time", "last_error_time"]:
333 f.write("set_super_value %s 0\n" % (time))
334 debugfs_cmd = "debugfs -w -f %s %s" % (debugfs_script_path, rootfs)
335 exec_native_cmd(debugfs_cmd, native_sysroot)
336
302 self.check_for_Y2038_problem(rootfs, native_sysroot) 337 self.check_for_Y2038_problem(rootfs, native_sysroot)
303 338
339 def get_hash_seed_ext4(self, extraopts, pseudo):
340 if os.getenv('SOURCE_DATE_EPOCH'):
341 sde_time = int(os.getenv('SOURCE_DATE_EPOCH'))
342 if pseudo:
343 pseudo = "export E2FSPROGS_FAKE_TIME=%s;%s " % (sde_time, pseudo)
344 else:
345 pseudo = "export E2FSPROGS_FAKE_TIME=%s; " % sde_time
346
347 # Set hash_seed to generate deterministic directory indexes
348 namespace = uuid.UUID("e7429877-e7b3-4a68-a5c9-2f2fdf33d460")
349 if self.fsuuid:
350 namespace = uuid.UUID(self.fsuuid)
351 hash_seed = str(uuid.uuid5(namespace, str(sde_time)))
352 extraopts += " -E hash_seed=%s" % hash_seed
353
354 return (extraopts, pseudo)
355
304 def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, 356 def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir,
305 native_sysroot, pseudo): 357 native_sysroot, pseudo):
306 """ 358 """
@@ -352,7 +404,7 @@ class Partition():
352 exec_native_cmd(mcopy_cmd, native_sysroot) 404 exec_native_cmd(mcopy_cmd, native_sysroot)
353 405
354 if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update: 406 if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update:
355 mcopy_cmd = "mcopy -i %s %s ::/etc/fstab" % (rootfs, self.updated_fstab_path) 407 mcopy_cmd = "mcopy -m -i %s %s ::/etc/fstab" % (rootfs, self.updated_fstab_path)
356 exec_native_cmd(mcopy_cmd, native_sysroot) 408 exec_native_cmd(mcopy_cmd, native_sysroot)
357 409
358 chmod_cmd = "chmod 644 %s" % rootfs 410 chmod_cmd = "chmod 644 %s" % rootfs
@@ -380,6 +432,9 @@ class Partition():
380 (extraopts, self.fsuuid, rootfs, rootfs_dir) 432 (extraopts, self.fsuuid, rootfs, rootfs_dir)
381 exec_native_cmd(erofs_cmd, native_sysroot, pseudo=pseudo) 433 exec_native_cmd(erofs_cmd, native_sysroot, pseudo=pseudo)
382 434
435 def prepare_empty_partition_none(self, rootfs, oe_builddir, native_sysroot):
436 pass
437
383 def prepare_empty_partition_ext(self, rootfs, oe_builddir, 438 def prepare_empty_partition_ext(self, rootfs, oe_builddir,
384 native_sysroot): 439 native_sysroot):
385 """ 440 """
@@ -391,13 +446,16 @@ class Partition():
391 446
392 extraopts = self.mkfs_extraopts or "-i 8192" 447 extraopts = self.mkfs_extraopts or "-i 8192"
393 448
449 # use hash_seed to generate reproducible ext4 images
450 (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, None)
451
394 label_str = "" 452 label_str = ""
395 if self.label: 453 if self.label:
396 label_str = "-L %s" % self.label 454 label_str = "-L %s" % self.label
397 455
398 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \ 456 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \
399 (self.fstype, extraopts, label_str, self.fsuuid, rootfs) 457 (self.fstype, extraopts, label_str, self.fsuuid, rootfs)
400 exec_native_cmd(mkfs_cmd, native_sysroot) 458 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
401 459
402 self.check_for_Y2038_problem(rootfs, native_sysroot) 460 self.check_for_Y2038_problem(rootfs, native_sysroot)
403 461