diff options
author | Sergei Zhmylev <s.zhmylev@yadro.com> | 2022-11-07 17:24:53 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-11-24 15:30:01 +0000 |
commit | 8a4021d2370155dce3bf193eafea4c1ee1054765 (patch) | |
tree | 436ccefb42c1f196026e09e8fcdf020f19b38b07 /scripts | |
parent | 9a3bc4c51af3c738703dbf5b571fa511f6aafcbd (diff) | |
download | poky-8a4021d2370155dce3bf193eafea4c1ee1054765.tar.gz |
wic: make ext2/3/4 images reproducible
Ext2/3/4 FS contains not only mtime, but also ctime, atime and crtime.
Currently, all the files are being added into the rootfs image using
mkfs -d functionality which affects all the timestamps excluding mtime.
This patch ensures these timestamps inside the FS image equal to
the SOURCE_DATE_EPOCH if it is set.
(From OE-Core rev: da2c64b3158c58eb0a484d3acbdf0419df2d34e8)
Signed-off-by: Sergei Zhmylev <s.zhmylev@yadro.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
(cherry picked from commit 75d2dd0ea7790db2e8ee921784ca373abff2df65)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/wic/partition.py | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py index 7c288d2958..5563f4448a 100644 --- a/scripts/lib/wic/partition.py +++ b/scripts/lib/wic/partition.py | |||
@@ -293,17 +293,36 @@ class Partition(): | |||
293 | f.write("cd etc\n") | 293 | f.write("cd etc\n") |
294 | f.write("rm fstab\n") | 294 | f.write("rm fstab\n") |
295 | f.write("write %s fstab\n" % (self.updated_fstab_path)) | 295 | f.write("write %s fstab\n" % (self.updated_fstab_path)) |
296 | if os.getenv('SOURCE_DATE_EPOCH'): | ||
297 | fstab_time = int(os.getenv('SOURCE_DATE_EPOCH')) | ||
298 | for time in ["atime", "mtime", "ctime"]: | ||
299 | f.write("set_inode_field fstab %s %s\n" % (time, hex(fstab_time))) | ||
300 | f.write("set_inode_field fstab %s_extra 0\n" % (time)) | ||
301 | debugfs_cmd = "debugfs -w -f %s %s" % (debugfs_script_path, rootfs) | 296 | debugfs_cmd = "debugfs -w -f %s %s" % (debugfs_script_path, rootfs) |
302 | exec_native_cmd(debugfs_cmd, native_sysroot) | 297 | exec_native_cmd(debugfs_cmd, native_sysroot) |
303 | 298 | ||
304 | mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) | 299 | mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) |
305 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) | 300 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) |
306 | 301 | ||
302 | if os.getenv('SOURCE_DATE_EPOCH'): | ||
303 | sde_time = hex(int(os.getenv('SOURCE_DATE_EPOCH'))) | ||
304 | debugfs_script_path = os.path.join(cr_workdir, "debugfs_script") | ||
305 | files = [] | ||
306 | for root, dirs, others in os.walk(rootfs_dir): | ||
307 | base = root.replace(rootfs_dir, "").rstrip(os.sep) | ||
308 | files += [ "/" if base == "" else base ] | ||
309 | files += [ base + "/" + n for n in dirs + others ] | ||
310 | with open(debugfs_script_path, "w") as f: | ||
311 | f.write("set_current_time %s\n" % (sde_time)) | ||
312 | if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update: | ||
313 | f.write("set_inode_field /etc/fstab mtime %s\n" % (sde_time)) | ||
314 | f.write("set_inode_field /etc/fstab mtime_extra 0\n") | ||
315 | for file in set(files): | ||
316 | for time in ["atime", "ctime", "crtime"]: | ||
317 | f.write("set_inode_field \"%s\" %s %s\n" % (file, time, sde_time)) | ||
318 | f.write("set_inode_field \"%s\" %s_extra 0\n" % (file, time)) | ||
319 | for time in ["wtime", "mkfs_time", "lastcheck"]: | ||
320 | f.write("set_super_value %s %s\n" % (time, sde_time)) | ||
321 | for time in ["mtime", "first_error_time", "last_error_time"]: | ||
322 | f.write("set_super_value %s 0\n" % (time)) | ||
323 | debugfs_cmd = "debugfs -w -f %s %s" % (debugfs_script_path, rootfs) | ||
324 | exec_native_cmd(debugfs_cmd, native_sysroot) | ||
325 | |||
307 | self.check_for_Y2038_problem(rootfs, native_sysroot) | 326 | self.check_for_Y2038_problem(rootfs, native_sysroot) |
308 | 327 | ||
309 | def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, | 328 | def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, |