From patchwork Mon Mar 1 10:58:23 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: 1445523 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.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=CJ/r1AG3; 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=G1AWt1T7; 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 4Dpy2L2wsMz9sSC for ; Mon, 1 Mar 2021 21:59:38 +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=KmwwjgyuqMQjuAUFES7BZhC2/k9g4UvPTyOeVrrRPik=; b=CJ/r1AG3girMZ8SecJeYwEpMKZ Pht+QLDRst3f2Z5iLpjM/8S9bBRC/g0y1DIj1+/rmNa8VBiSA5MbOHufMRc4naI+NirkvOWnfDVXJ D5nqJt/7v343b4GrXNvvTIerMIGnFCQdsgnAlAcTU3GBWg1E5PPQGRppzPSZGD778jvXLYybAQxrF UfIqTBPdY7lZ4KBIGgbL14E/vjjhgfITi/zsruLeBs1ho6A40rFjfO0EKmXOdsW/X24QzH+cvWa1J TDW5l11NwIBPT4mZBDBluM9Wuh2Pxz2tKWi0AAwqjl5Z0P9M2us8hXVCfiJdWu8tSUKuBH5S+0yXF Rz+/N81w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lGgGB-0004vZ-Af; Mon, 01 Mar 2021 10:58:43 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lGgG8-0004uB-Er for linux-mtd@lists.infradead.org; Mon, 01 Mar 2021 10:58:41 +0000 Received: by mail-lj1-x22c.google.com with SMTP id y12so5941335ljj.12 for ; Mon, 01 Mar 2021 02:58:35 -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=/p80LPfpMJj3Lr3ldVEyli9uqUKvSBAMYnYbx9TAgGM=; b=G1AWt1T7GEq9joSCRveCxO5OmQzq8/AZY1IkdwlZ062fValjqg4CDsxIQd/A5IIC0O /wYVFo9lDuJX2iEGz1p7+k+nocYDsbVQkca1RIBQp3Cth5z/n43JGvv88kZAELb+8r/2 THCPqKr/whO7eUbZvCgsErswhIC2knEVlTCstFV5MIo9CTbC75iiB+rO4+eFKM/dH/jU 59t/HqDpe0kekqUGmYNnX0oQj6qP9MzUEessW3Fe3HRbONCra30R2osYY5Vsvdm47tc+ v9wk1FyEISIgxrK6lohcFeXxaTkdlA9y/Od2xSwJws6bm8yI7SzhkpDtxLt4rjE3fhsA 5Ygw== 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=/p80LPfpMJj3Lr3ldVEyli9uqUKvSBAMYnYbx9TAgGM=; b=CgpFBVCChJunmlxm3a8/yDrYAIuo45Vo5bbHfZc2pXqqEXsIg/1CwtxBCujLrVnTLT ItYPK3ul63qjqMq1l3L29WFiqwMOxs5kAe/urlCSBBdG0ER1PT8cOJc/XxMU0mP5p+2q B5DmR0pcgzJhaQ6b399v16oeVknuhpnbHaMNmu0mbZ4YqzHgPV2r1gHU2n80PVSXKDEq GPQ83QV7kqhhOHng2xfDegB4pA89mJYKEB9FBw0BPOha2BEY2CXM1cNSC+oQSNNGZi0K VQBdH4C97NZo7XjdTS8HViQ7jcnSIfbRZU6PXyWOcIZi1Xl9EqWHnaSjFOvHdQyGaDqV FX9Q== X-Gm-Message-State: AOAM5323R5U+UFCHI+fgTsHWVe9etOLbqdRDer0Brch2fngudHJcKHfq 1+F6SBXHPUcT2u4hGthUo2c= X-Google-Smtp-Source: ABdhPJymiNAtVvYoTfUn1kiceoDHw8j01iZko6xJg5G3CZ4Zl+xuTyDQ8RZHQ5Ku+x5Ud1IBlK4BXg== X-Received: by 2002:a2e:7d02:: with SMTP id y2mr9143267ljc.153.1614596314844; Mon, 01 Mar 2021 02:58:34 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id b11sm2264311lfd.306.2021.03.01.02.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 02:58:34 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Subject: [PATCH V4] mtd: parsers: ofpart: support BCM4908 fixed partitions Date: Mon, 1 Mar 2021 11:58:23 +0100 Message-Id: <20210301105823.31032-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-20210301_055840_516524_06FE71E2 X-CRM114-Status: GOOD ( 30.21 ) 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:22c listed in] [list.dnswl.org] 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.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zajec5[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Florian Fainelli , Boris Brezillon , linux-mtd@lists.infradead.org, Manivannan Sadhasivam , =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= , Vivek Unune Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Rafał Miłecki Some devices use fixed partitioning with some partitions requiring some extra logic. E.g. BCM4908 may have multiple firmware partitions but detecting currently used one requires checking bootloader parameters. To support such cases without duplicating a lot of code (without copying most of the ofpart.c code) support for post-parsing callback was added. BCM4908 support in ofpart can be enabled using config option and results in compiling & executing a specific callback. It simply reads offset of currently used firmware partition from the DT. Bootloader specifies it using the "brcm_blparms" property. Signed-off-by: Rafał Miłecki --- V4: Rework Makefile changes, use ofpart_core.c to avoid compilation and module loading problems. Kernel doesn't like building object files using source file of the same name + additional source files. This patch has been compile-tested using 4 config variants: CONFIG_MTD_OF_PARTS=m # CONFIG_MTD_OF_PARTS_BCM4908 is not set CONFIG_MTD_OF_PARTS=m CONFIG_MTD_OF_PARTS_BCM4908=y CONFIG_MTD_OF_PARTS=y # CONFIG_MTD_OF_PARTS_BCM4908 is not set CONFIG_MTD_OF_PARTS=y CONFIG_MTD_OF_PARTS_BCM4908=y Additionally both: "fixed-partitions" and "brcm,bcm4908-partitions" were runtime-tested using 2 config variants: CONFIG_MTD_OF_PARTS=y # CONFIG_MTD_OF_PARTS_BCM4908 is not set CONFIG_MTD_OF_PARTS=y CONFIG_MTD_OF_PARTS_BCM4908=y --- drivers/mtd/parsers/Kconfig | 9 +++ drivers/mtd/parsers/Makefile | 2 + drivers/mtd/parsers/ofpart_bcm4908.c | 64 +++++++++++++++++++ drivers/mtd/parsers/ofpart_bcm4908.h | 15 +++++ .../mtd/parsers/{ofpart.c => ofpart_core.c} | 28 +++++++- 5 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 drivers/mtd/parsers/ofpart_bcm4908.c create mode 100644 drivers/mtd/parsers/ofpart_bcm4908.h rename drivers/mtd/parsers/{ofpart.c => ofpart_core.c} (88%) diff --git a/drivers/mtd/parsers/Kconfig b/drivers/mtd/parsers/Kconfig index d90c30229052..05b6a24cedd8 100644 --- a/drivers/mtd/parsers/Kconfig +++ b/drivers/mtd/parsers/Kconfig @@ -67,6 +67,15 @@ config MTD_OF_PARTS flash memory node, as described in Documentation/devicetree/bindings/mtd/partition.txt. +config MTD_OF_PARTS_BCM4908 + bool "BCM4908 partitioning support" + depends on MTD_OF_PARTS && (ARCH_BCM4908 || COMPILE_TEST) + default ARCH_BCM4908 + help + This provides partitions parser for BCM4908 family devices + that can have multiple "firmware" partitions. It takes care of + finding currently used one and backup ones. + config MTD_PARSER_IMAGETAG tristate "Parser for BCM963XX Image Tag format partitions" depends on BCM63XX || BMIPS_GENERIC || COMPILE_TEST diff --git a/drivers/mtd/parsers/Makefile b/drivers/mtd/parsers/Makefile index 50eb0b0a2210..2dfe9fb602de 100644 --- a/drivers/mtd/parsers/Makefile +++ b/drivers/mtd/parsers/Makefile @@ -4,6 +4,8 @@ obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o +ofpart-y += ofpart_core.o +ofpart-$(CONFIG_MTD_OF_PARTS_BCM4908) += ofpart_bcm4908.o obj-$(CONFIG_MTD_PARSER_IMAGETAG) += parser_imagetag.o obj-$(CONFIG_MTD_AFS_PARTS) += afs.o obj-$(CONFIG_MTD_PARSER_TRX) += parser_trx.o diff --git a/drivers/mtd/parsers/ofpart_bcm4908.c b/drivers/mtd/parsers/ofpart_bcm4908.c new file mode 100644 index 000000000000..0eddef4c198e --- /dev/null +++ b/drivers/mtd/parsers/ofpart_bcm4908.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021 Rafał Miłecki + */ + +#include +#include +#include +#include +#include +#include + +#include "ofpart_bcm4908.h" + +#define BLPARAMS_FW_OFFSET "NAND_RFS_OFS" + +static long long bcm4908_partitions_fw_offset(void) +{ + struct device_node *root; + struct property *prop; + const char *s; + + root = of_find_node_by_path("/"); + if (!root) + return -ENOENT; + + of_property_for_each_string(root, "brcm_blparms", prop, s) { + size_t len = strlen(BLPARAMS_FW_OFFSET); + unsigned long offset; + int err; + + if (strncmp(s, BLPARAMS_FW_OFFSET, len) || s[len] != '=') + continue; + + err = kstrtoul(s + len + 1, 0, &offset); + if (err) { + pr_err("failed to parse %s\n", s + len + 1); + return err; + } + + return offset << 10; + } + + return -ENOENT; +} + +int bcm4908_partitions_post_parse(struct mtd_info *mtd, struct mtd_partition *parts, int nr_parts) +{ + long long fw_offset; + int i; + + fw_offset = bcm4908_partitions_fw_offset(); + + for (i = 0; i < nr_parts; i++) { + if (of_device_is_compatible(parts[i].of_node, "brcm,bcm4908-firmware")) { + if (fw_offset < 0 || parts[i].offset == fw_offset) + parts[i].name = "firmware"; + else + parts[i].name = "backup"; + } + } + + return 0; +} diff --git a/drivers/mtd/parsers/ofpart_bcm4908.h b/drivers/mtd/parsers/ofpart_bcm4908.h new file mode 100644 index 000000000000..80f8c086641f --- /dev/null +++ b/drivers/mtd/parsers/ofpart_bcm4908.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __BCM4908_PARTITIONS_H +#define __BCM4908_PARTITIONS_H + +#ifdef CONFIG_MTD_OF_PARTS_BCM4908 +int bcm4908_partitions_post_parse(struct mtd_info *mtd, struct mtd_partition *parts, int nr_parts); +#else +static inline int bcm4908_partitions_post_parse(struct mtd_info *mtd, struct mtd_partition *parts, + int nr_parts) +{ + return -EOPNOTSUPP; +} +#endif + +#endif diff --git a/drivers/mtd/parsers/ofpart.c b/drivers/mtd/parsers/ofpart_core.c similarity index 88% rename from drivers/mtd/parsers/ofpart.c rename to drivers/mtd/parsers/ofpart_core.c index daf507c123e6..258c06a42283 100644 --- a/drivers/mtd/parsers/ofpart.c +++ b/drivers/mtd/parsers/ofpart_core.c @@ -16,6 +16,18 @@ #include #include +#include "ofpart_bcm4908.h" + +struct fixed_partitions_quirks { + int (*post_parse)(struct mtd_info *mtd, struct mtd_partition *parts, int nr_parts); +}; + +struct fixed_partitions_quirks bcm4908_partitions_quirks = { + .post_parse = bcm4908_partitions_post_parse, +}; + +static const struct of_device_id parse_ofpart_match_table[]; + static bool node_has_compatible(struct device_node *pp) { return of_get_property(pp, "compatible", NULL); @@ -25,6 +37,8 @@ static int parse_fixed_partitions(struct mtd_info *master, const struct mtd_partition **pparts, struct mtd_part_parser_data *data) { + const struct fixed_partitions_quirks *quirks; + const struct of_device_id *of_id; struct mtd_partition *parts; struct device_node *mtd_node; struct device_node *ofpart_node; @@ -33,7 +47,6 @@ static int parse_fixed_partitions(struct mtd_info *master, int nr_parts, i, ret = 0; bool dedicated = true; - /* Pull of_node from the master device node */ mtd_node = mtd_get_of_node(master); if (!mtd_node) @@ -50,11 +63,16 @@ static int parse_fixed_partitions(struct mtd_info *master, master->name, mtd_node); ofpart_node = mtd_node; dedicated = false; - } else if (!of_device_is_compatible(ofpart_node, "fixed-partitions")) { + } + + of_id = of_match_node(parse_ofpart_match_table, ofpart_node); + if (dedicated && !of_id) { /* The 'partitions' subnode might be used by another parser */ return 0; } + quirks = of_id ? of_id->data : NULL; + /* First count the subnodes */ nr_parts = 0; for_each_child_of_node(ofpart_node, pp) { @@ -126,6 +144,9 @@ static int parse_fixed_partitions(struct mtd_info *master, if (!nr_parts) goto ofpart_none; + if (quirks && quirks->post_parse) + quirks->post_parse(master, parts, nr_parts); + *pparts = parts; return nr_parts; @@ -140,7 +161,10 @@ static int parse_fixed_partitions(struct mtd_info *master, } static const struct of_device_id parse_ofpart_match_table[] = { + /* Generic */ { .compatible = "fixed-partitions" }, + /* Customized */ + { .compatible = "brcm,bcm4908-partitions", .data = &bcm4908_partitions_quirks, }, {}, }; MODULE_DEVICE_TABLE(of, parse_ofpart_match_table);