From patchwork Wed Jan 20 15:49:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 1429299 X-Patchwork-Delegate: zajec5@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=iAs4hID1; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=XmyCHcnZ; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DLVPP6RfLz9sSs for ; Thu, 21 Jan 2021 02:51:21 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=vnvf5T2u1NV+wEPyVMk1PqXhcHEVYR1VFPKWA5btFfE=; b=iAs4hID1zjJ0qr4qGTFaS7q8LE Tt9ALJkfkgxi0yUdpbfpeh23Ij7UoBRw+a/1bYr07UEdNzR1KEmUQTeqT1cg88MjS1Qj2+vSPIvWX xrU3S2EiJLOTqlw8K1J/FzcXPoRTunEB/xgJBUMmh3uRiNLcG6FJrjRco7aOVTKhSDMW6NinnDuXY 91nG4HgFYTmn9WjJLyLs5ULJnBZYGhp+ymd6BqEATqZCqIyjNQmzITSfYMiWS6l1pWGD+IvZRHcB3 y9pmLKQ2docCM7xBDWcetVHyTd/yIM5Gjny34Epzc0fbYpk+WfopGcRkLbza2l0Wy81U6E8PomJAr sqlnTeQw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Fju-0001O7-Dl; Wed, 20 Jan 2021 15:49:46 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Fjs-0001NC-0W for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 15:49:44 +0000 Received: by mail-ed1-x529.google.com with SMTP id g1so25652977edu.4 for ; Wed, 20 Jan 2021 07:49:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zH93uvtwDz/atLTVViYUTBbuUDbsqvPMZhJeQwBKF88=; b=XmyCHcnZu/vKG7ZoDKwWqBYwqPytakVUI0QBlvbxRgFGviFxiicta7PmZrENB/xpzy oxyED72eHA+0JSfIcX19oKThgQsiODahBsF1fWriARdpdOWHMBR9ytKfVz8kyoZ/jIOu GYpjD6pdY/cDOXX1jzUxuPAkfsbOnpt5QQ+BFai8lXbOaKknnuVisN80X5YjqABS3kdO foPy08pKPUH61w4Ogn/Qr+kw9ZYsu7an8FpaVXO6HiUBbWCwugFn1xhEkGiXdOuJ86DO 9u5s3alcuM3jrLFN6p1DufZijnb7GA6V5z+YSovmkoJ+Gae6Ms3BzoGwx2TlBUkNCWmQ 1/Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zH93uvtwDz/atLTVViYUTBbuUDbsqvPMZhJeQwBKF88=; b=Bgyjxg0sRPZbAix4HJDCHJPat4yPDlyK+AirEJIC0TOGYIvtjVvPUpuK6CJ8uUMEsD SUo/uCzY65lMfxPVxNyjP6rVl/DyTKcHdoPstQBiLhRUTtuYaPAMoIZsXrc6jtCwPCKu 6X99OwScCjGsptyzy9Uksw1Okgz8PmmHGVMCTcarNPwD5ZCDXXRCs6Y0X1eD0LV4wA8l txYwclrjvRdLGoRkhaJ1lf/DZRLuqkTYhra8htcoM4nPA5IXjTnyfXQ379B76a/ZMD2a uL87U6oQM6Zjigq7kFUILbkS8a/x70Tivbmbr/jr6S9Ksio+rypRkXreF863w7rpJvFi 5Caw== X-Gm-Message-State: AOAM531jrgON4R0PieJ0oNC9NXXNyIq4iHNUnn3LXjl5IypZq4bV8pN6 k5y0DcrG7iF7jsaH7GJfeyXGtq8cYzY= X-Google-Smtp-Source: ABdhPJyKwoXt2sFkoLRXcZ2IZtf4aOfFeb3wzlUHWdlbirUTKf/KrrvN1+ed96TjzG0BHGaNgOyLWw== X-Received: by 2002:aa7:d919:: with SMTP id a25mr7911048edr.243.1611157782578; Wed, 20 Jan 2021 07:49:42 -0800 (PST) Received: from localhost.localdomain (public-gprs350448.centertel.pl. [37.47.0.49]) by smtp.gmail.com with ESMTPSA id x16sm1082620ejc.22.2021.01.20.07.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 07:49:41 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH] kernel: add parser finding rootfs after CFE bootfs Date: Wed, 20 Jan 2021 16:49:26 +0100 Message-Id: <20210120154926.24030-1-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210120_104944_066837_FA6A8E5C X-CRM114-Status: GOOD ( 22.32 ) X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:529 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zajec5[at]gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zajec5[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki It's required for BCM4908. It cannot use "bcm-wfi-fw" parser because that one requires *two* JFFS2 partitions which is untested / unsupported on the BCM4908 architecture. With a single JFFS2 partition "bcm-wfi-fw" parser will: 1. Fail to find "vmlinux.lz" as it doesn't follow "1-openwrt" file 2. Create partitions that don't precisely match bootfs layout The new parser is described in details in the MTD_SPLIT_CFE_BOOTFS symbol help message. Signed-off-by: Rafał Miłecki --- .../files/drivers/mtd/mtdsplit/Kconfig | 12 +++ .../files/drivers/mtd/mtdsplit/Makefile | 1 + .../mtd/mtdsplit/mtdsplit_cfe_bootfs.c | 86 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_cfe_bootfs.c diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig b/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig index 3b7e23af33..4832b8d9e4 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig @@ -25,6 +25,18 @@ config MTD_SPLIT_BCM_WFI_FW depends on MTD_SPLIT_SUPPORT select MTD_SPLIT +config MTD_SPLIT_CFE_BOOTFS + bool "Parser finding rootfs appended to the CFE bootfs" + depends on MTD_SPLIT_SUPPORT && ARCH_BCM4908 + select MTD_SPLIT + help + cferom on BCM4908 (and bcm63xx) uses JFFS2 bootfs partition + for storing kernel, cferam and some device specific files. + There isn't any straight way of storing rootfs so it gets + appended to the JFFS2 bootfs partition. Kernel needs to find + it and run init from it. This parser is responsible for + finding appended rootfs. + config MTD_SPLIT_SEAMA_FW bool "Seama firmware parser" depends on MTD_SPLIT_SUPPORT diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile b/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile index 8671628e7c..9217d8f64f 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile @@ -1,5 +1,6 @@ obj-$(CONFIG_MTD_SPLIT) += mtdsplit.o obj-$(CONFIG_MTD_SPLIT_BCM_WFI_FW) += mtdsplit_bcm_wfi.o +obj-$(CONFIG_MTD_SPLIT_CFE_BOOTFS) += mtdsplit_cfe_bootfs.o obj-$(CONFIG_MTD_SPLIT_SEAMA_FW) += mtdsplit_seama.o obj-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o obj-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_cfe_bootfs.c b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_cfe_bootfs.c new file mode 100644 index 0000000000..5c8a5e1b9b --- /dev/null +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_cfe_bootfs.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2021 Rafał Miłecki + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mtdsplit.h" + +#define je16_to_cpu(x) ((x).v16) +#define je32_to_cpu(x) ((x).v32) + +#define NR_PARTS 1 + +static int mtdsplit_cfe_bootfs_parse(struct mtd_info *mtd, + const struct mtd_partition **pparts, + struct mtd_part_parser_data *data) +{ + struct jffs2_raw_dirent node; + enum mtdsplit_part_type type; + struct mtd_partition *parts; + size_t rootfs_offset; + size_t retlen; + size_t offset; + int err; + + /* Don't parse backup partitions */ + if (strcmp(mtd->name, "firmware")) + return -EINVAL; + + /* Find the end of JFFS2 bootfs partition */ + offset = 0; + do { + err = mtd_read(mtd, offset, sizeof(node), &retlen, (void *)&node); + if (err || retlen != sizeof(node)) + break; + + if (je16_to_cpu(node.magic) != JFFS2_MAGIC_BITMASK) + break; + + offset += je32_to_cpu(node.totlen); + offset = (offset + 0x3) & ~0x3; + } while (offset < mtd->size); + + /* Find rootfs partition that follows the bootfs */ + err = mtd_find_rootfs_from(mtd, mtd->erasesize, mtd->size, &rootfs_offset, &type); + if (err) + return err; + + parts = kzalloc(NR_PARTS * sizeof(*parts), GFP_KERNEL); + if (!parts) + return -ENOMEM; + + if (type == MTDSPLIT_PART_TYPE_UBI) + parts[0].name = UBI_PART_NAME; + else + parts[0].name = ROOTFS_PART_NAME; + parts[0].offset = rootfs_offset; + parts[0].size = mtd->size - rootfs_offset; + + *pparts = parts; + + return NR_PARTS; +} + +static const struct of_device_id mtdsplit_cfe_bootfs_of_match_table[] = { + { .compatible = "brcm,bcm4908-firmware" }, + {}, +}; +MODULE_DEVICE_TABLE(of, mtdsplit_cfe_bootfs_of_match_table); + +static struct mtd_part_parser mtdsplit_cfe_bootfs_parser = { + .owner = THIS_MODULE, + .name = "cfe-bootfs", + .of_match_table = mtdsplit_cfe_bootfs_of_match_table, + .parse_fn = mtdsplit_cfe_bootfs_parse, +}; + +module_mtd_part_parser(mtdsplit_cfe_bootfs_parser);