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.py99
1 files changed, 84 insertions, 15 deletions
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index 76d144d12d..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
@@ -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)
@@ -158,6 +164,9 @@ class Partition():
158 164
159 plugins = PluginMgr.get_plugins('source') 165 plugins = PluginMgr.get_plugins('source')
160 166
167 # Don't support '-' in plugin names
168 self.source = self.source.replace("-", "_")
169
161 if self.source not in plugins: 170 if self.source not in plugins:
162 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"
163 "See 'wic list source-plugins' for a list of available" 172 "See 'wic list source-plugins' for a list of available"
@@ -170,9 +179,9 @@ class Partition():
170 # Split sourceparams string of the form key1=val1[,key2=val2,...] 179 # Split sourceparams string of the form key1=val1[,key2=val2,...]
171 # into a dict. Also accepts valueless keys i.e. without = 180 # into a dict. Also accepts valueless keys i.e. without =
172 splitted = self.sourceparams.split(',') 181 splitted = self.sourceparams.split(',')
173 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)
174 183
175 plugin = PluginMgr.get_plugins('source')[self.source] 184 plugin = plugins[self.source]
176 plugin.do_configure_partition(self, srcparams_dict, creator, 185 plugin.do_configure_partition(self, srcparams_dict, creator,
177 cr_workdir, oe_builddir, bootimg_dir, 186 cr_workdir, oe_builddir, bootimg_dir,
178 kernel_dir, native_sysroot) 187 kernel_dir, native_sysroot)
@@ -216,19 +225,19 @@ class Partition():
216 if (pseudo_dir): 225 if (pseudo_dir):
217 # Canonicalize the ignore paths. This corresponds to 226 # Canonicalize the ignore paths. This corresponds to
218 # calling oe.path.canonicalize(), which is used in bitbake.conf. 227 # calling oe.path.canonicalize(), which is used in bitbake.conf.
219 ignore_paths = [rootfs] + (get_bitbake_var("PSEUDO_IGNORE_PATHS") or "").split(",") 228 include_paths = [rootfs_dir] + (get_bitbake_var("PSEUDO_INCLUDE_PATHS") or "").split(",")
220 canonical_paths = [] 229 canonical_paths = []
221 for path in ignore_paths: 230 for path in include_paths:
222 if "$" not in path: 231 if "$" not in path:
223 trailing_slash = path.endswith("/") and "/" or "" 232 trailing_slash = path.endswith("/") and "/" or ""
224 canonical_paths.append(os.path.realpath(path) + trailing_slash) 233 canonical_paths.append(os.path.realpath(path) + trailing_slash)
225 ignore_paths = ",".join(canonical_paths) 234 include_paths = ",".join(canonical_paths)
226 235
227 pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix 236 pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix
228 pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % pseudo_dir 237 pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % pseudo_dir
229 pseudo += "export PSEUDO_PASSWD=%s;" % rootfs_dir 238 pseudo += "export PSEUDO_PASSWD=%s;" % rootfs_dir
230 pseudo += "export PSEUDO_NOSYMLINKEXP=1;" 239 pseudo += "export PSEUDO_NOSYMLINKEXP=1;"
231 pseudo += "export PSEUDO_IGNORE_PATHS=%s;" % ignore_paths 240 pseudo += "export PSEUDO_INCLUDE_PATHS=%s;" % include_paths
232 pseudo += "%s " % get_bitbake_var("FAKEROOTCMD") 241 pseudo += "%s " % get_bitbake_var("FAKEROOTCMD")
233 else: 242 else:
234 pseudo = None 243 pseudo = None
@@ -238,7 +247,7 @@ class Partition():
238 # from bitbake variable 247 # from bitbake variable
239 rsize_bb = get_bitbake_var('ROOTFS_SIZE') 248 rsize_bb = get_bitbake_var('ROOTFS_SIZE')
240 rdir = get_bitbake_var('IMAGE_ROOTFS') 249 rdir = get_bitbake_var('IMAGE_ROOTFS')
241 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")):
242 # Bitbake variable ROOTFS_SIZE is calculated in 251 # Bitbake variable ROOTFS_SIZE is calculated in
243 # Image._get_rootfs_size method from meta/lib/oe/image.py 252 # Image._get_rootfs_size method from meta/lib/oe/image.py
244 # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT, 253 # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT,
@@ -278,6 +287,9 @@ class Partition():
278 287
279 extraopts = self.mkfs_extraopts or "-F -i 8192" 288 extraopts = self.mkfs_extraopts or "-F -i 8192"
280 289
290 # use hash_seed to generate reproducible ext4 images
291 (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, pseudo)
292
281 label_str = "" 293 label_str = ""
282 if self.label: 294 if self.label:
283 label_str = "-L %s" % self.label 295 label_str = "-L %s" % self.label
@@ -286,7 +298,7 @@ class Partition():
286 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir) 298 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
287 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) 299 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
288 300
289 if self.updated_fstab_path and self.has_fstab: 301 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") 302 debugfs_script_path = os.path.join(cr_workdir, "debugfs_script")
291 with open(debugfs_script_path, "w") as f: 303 with open(debugfs_script_path, "w") as f:
292 f.write("cd etc\n") 304 f.write("cd etc\n")
@@ -298,8 +310,49 @@ class Partition():
298 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) 310 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs)
299 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) 311 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
300 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
301 self.check_for_Y2038_problem(rootfs, native_sysroot) 337 self.check_for_Y2038_problem(rootfs, native_sysroot)
302 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
303 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,
304 native_sysroot, pseudo): 357 native_sysroot, pseudo):
305 """ 358 """
@@ -350,8 +403,8 @@ class Partition():
350 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir) 403 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
351 exec_native_cmd(mcopy_cmd, native_sysroot) 404 exec_native_cmd(mcopy_cmd, native_sysroot)
352 405
353 if self.updated_fstab_path and self.has_fstab: 406 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) 407 mcopy_cmd = "mcopy -m -i %s %s ::/etc/fstab" % (rootfs, self.updated_fstab_path)
355 exec_native_cmd(mcopy_cmd, native_sysroot) 408 exec_native_cmd(mcopy_cmd, native_sysroot)
356 409
357 chmod_cmd = "chmod 644 %s" % rootfs 410 chmod_cmd = "chmod 644 %s" % rootfs
@@ -369,6 +422,19 @@ class Partition():
369 (rootfs_dir, rootfs, extraopts) 422 (rootfs_dir, rootfs, extraopts)
370 exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo) 423 exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo)
371 424
425 def prepare_rootfs_erofs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir,
426 native_sysroot, pseudo):
427 """
428 Prepare content for a erofs rootfs partition.
429 """
430 extraopts = self.mkfs_extraopts or ''
431 erofs_cmd = "mkfs.erofs %s -U %s %s %s" % \
432 (extraopts, self.fsuuid, rootfs, rootfs_dir)
433 exec_native_cmd(erofs_cmd, native_sysroot, pseudo=pseudo)
434
435 def prepare_empty_partition_none(self, rootfs, oe_builddir, native_sysroot):
436 pass
437
372 def prepare_empty_partition_ext(self, rootfs, oe_builddir, 438 def prepare_empty_partition_ext(self, rootfs, oe_builddir,
373 native_sysroot): 439 native_sysroot):
374 """ 440 """
@@ -380,13 +446,16 @@ class Partition():
380 446
381 extraopts = self.mkfs_extraopts or "-i 8192" 447 extraopts = self.mkfs_extraopts or "-i 8192"
382 448
449 # use hash_seed to generate reproducible ext4 images
450 (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, None)
451
383 label_str = "" 452 label_str = ""
384 if self.label: 453 if self.label:
385 label_str = "-L %s" % self.label 454 label_str = "-L %s" % self.label
386 455
387 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \ 456 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \
388 (self.fstype, extraopts, label_str, self.fsuuid, rootfs) 457 (self.fstype, extraopts, label_str, self.fsuuid, rootfs)
389 exec_native_cmd(mkfs_cmd, native_sysroot) 458 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
390 459
391 self.check_for_Y2038_problem(rootfs, native_sysroot) 460 self.check_for_Y2038_problem(rootfs, native_sysroot)
392 461