[openwrt/openwrt] kernel: add support for mtdsplit-fit offset

LEDE Commits lede-commits at lists.infradead.org
Sun Sep 11 17:48:34 PDT 2022


dangole pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/49763d907b0d87769c3e5885f1c11b5b62ccfa2b

commit 49763d907b0d87769c3e5885f1c11b5b62ccfa2b
Author: Yoonji Park <koreapyj at dcmys.kr>
AuthorDate: Sun Jun 5 18:04:18 2022 +0000

    kernel: add support for mtdsplit-fit offset
    
    Support devices that has vendor custom header before FIT image.
    
    Some devices has vendor custom header before FIT image. In this case mtd-
    split can not find FIT image and it results in rootfs mount failure.
    Please refer iptime,a6004mx device for further examples.
    
    Signed-off-by: Yoonji Park <koreapyj at dcmys.kr>
---
 .../linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_fit.c   | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_fit.c b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_fit.c
index d8fb74ea38..3b71597d23 100644
--- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_fit.c
+++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_fit.c
@@ -199,6 +199,7 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
 	struct fdt_header hdr;
 	size_t hdr_len, retlen;
 	size_t offset;
+	u32 offset_start = 0;
 	size_t fit_offset, fit_size;
 	size_t rootfs_offset, rootfs_size;
 	size_t data_size, img_total, max_size = 0;
@@ -211,11 +212,13 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
 	if (cmdline_match && !strstr(saved_command_line, cmdline_match))
 		return -ENODEV;
 
+	of_property_read_u32(np, "openwrt,fit-offset", &offset_start);
+
 	hdr_len = sizeof(struct fdt_header);
 
 	/* Parse the MTD device & search for the FIT image location */
 	for(offset = 0; offset + hdr_len <= mtd->size; offset += mtd->erasesize) {
-		ret = mtd_read(mtd, offset, hdr_len, &retlen, (void*) &hdr);
+		ret = mtd_read(mtd, offset + offset_start, hdr_len, &retlen, (void*) &hdr);
 		if (ret) {
 			pr_err("read error in \"%s\" at offset 0x%llx\n",
 			       mtd->name, (unsigned long long) offset);
@@ -259,7 +262,7 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
 		enum mtdsplit_part_type type;
 
 		/* Search for the rootfs partition after the FIT image */
-		ret = mtd_find_rootfs_from(mtd, fit_offset + fit_size, mtd->size,
+		ret = mtd_find_rootfs_from(mtd, fit_offset + fit_size + offset_start, mtd->size,
 					   &rootfs_offset, &type);
 		if (ret) {
 			pr_info("no rootfs found after FIT image in \"%s\"\n",
@@ -275,7 +278,7 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
 
 		parts[0].name = KERNEL_PART_NAME;
 		parts[0].offset = fit_offset;
-		parts[0].size = mtd_rounddown_to_eb(fit_size, mtd) + mtd->erasesize;
+		parts[0].size = mtd_rounddown_to_eb(fit_size + offset_start, mtd) + mtd->erasesize;
 
 		if (type == MTDSPLIT_PART_TYPE_UBI)
 			parts[1].name = UBI_PART_NAME;
@@ -290,7 +293,7 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
 	} else {
 		/* Search for rootfs_data after FIT external data */
 		fit = kzalloc(fit_size, GFP_KERNEL);
-		ret = mtd_read(mtd, offset, fit_size, &retlen, fit);
+		ret = mtd_read(mtd, offset, fit_size + offset_start, &retlen, fit);
 		if (ret) {
 			pr_err("read error in \"%s\" at offset 0x%llx\n",
 			       mtd->name, (unsigned long long) offset);




More information about the lede-commits mailing list