From 050fb3b55cde4348f4ed12ab98f451c4c56a695b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= Date: Fri, 27 Oct 2017 20:12:15 +0200 Subject: tools/firmware-utils: mktplinkfw* fix rootfs offset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With '-a' specified on the command line, the current code: - computes an aligned _kernel length_ instead of an aligned _rootfs offset_. - does not update the rootfs offset after computing the new kernel length, and instead retains the layout default. When the kernel length exceeds the available space left with this fixed offset, the resulting image header contains invalid data, with the recorded rootfs offset overlapping the kernel area. This patch ensures that rootfs offset is correctly computed and reflected in the final image. Furthermore, the build_fw() function special cases the rootfs_align option because of the above invalid logic. This is also fixed and the computed (or command-line provided, or layout-provided) rootfs_ofs value is used in all cases. There seems to be no valid reason to extend the kernel length beyond the actual length of the kernel itself (OFW images don't do it) so this part of the existing behavior is dropped. Example image before the patch: Kernel data offset : 0x00000200 / 512 bytes Kernel data length : 0x00158438 / 1410104 bytes Kernel load address : 0x00000080 Kernel entry point : 0x00000080 Rootfs data offset : 0x00140000 / 1310720 bytes Rootfs data length : 0x001e4f7e / 1986430 bytes Example image after the patch: Kernel data offset : 0x00000200 / 512 bytes Kernel data length : 0x001583fe / 1410046 bytes Kernel load address : 0x00000080 Kernel entry point : 0x00000080 Rootfs data offset : 0x00158600 / 1410560 bytes Rootfs data length : 0x001e4e22 / 1986082 bytes Tested-by: Mathias Kresin Tested-by: Stefan Lippers-Hollmann Tested-by: Daniel Engberg Tested-by: Henryk Heisig Signed-off-by: Thibaut VARĂˆNE --- tools/firmware-utils/src/mktplinkfw-lib.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'tools/firmware-utils/src/mktplinkfw-lib.c') diff --git a/tools/firmware-utils/src/mktplinkfw-lib.c b/tools/firmware-utils/src/mktplinkfw-lib.c index 18da13d..b2b6de2 100644 --- a/tools/firmware-utils/src/mktplinkfw-lib.c +++ b/tools/firmware-utils/src/mktplinkfw-lib.c @@ -236,19 +236,13 @@ int build_fw(size_t header_size) goto out_free_buf; if (!combined) { - if (rootfs_align) - p = buf + writelen; - else - p = buf + rootfs_ofs; + p = buf + rootfs_ofs; ret = read_to_buf(&rootfs_info, p); if (ret) goto out_free_buf; - if (rootfs_align) - writelen += rootfs_info.file_size; - else - writelen = rootfs_ofs + rootfs_info.file_size; + writelen = rootfs_ofs + rootfs_info.file_size; if (add_jffs2_eof) writelen = pad_jffs2(buf, writelen, layout->fw_max_len); -- cgit v1.1