From nobody Sun May 10 13:21:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19A82C433F5 for ; Tue, 3 May 2022 15:47:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238853AbiECPuo (ORCPT ); Tue, 3 May 2022 11:50:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237302AbiECPul (ORCPT ); Tue, 3 May 2022 11:50:41 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D055E33E8F; Tue, 3 May 2022 08:47:07 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id ay11-20020a05600c1e0b00b0038eb92fa965so1617581wmb.4; Tue, 03 May 2022 08:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=80Ajy3E8zr74DMwLvdHtBgD6k+JzeYDH65oyG0hvOck=; b=CfQAahfU+n8KZFyEVz4yGEntqne5VtENCybgdvVVfOHkdxKI1dSynIe76HkAAmBYhR VaZQYgBJwIVintv/q/oDTUnM/FO7x7Zg5NoiYM8fPyVIs525a8tuVNgif5KDWlK5Die2 EurbCewLNat2XW7KsWN5MXYrwTewDT8Ea9B9J1ANnsNa6ExkCaNnsN8hr/1N0txrBG1C LKHJqwFlBq42CnCKnyZZAA1B7N6q4d0Fo9g2TGDwLQTTwBcP9IppKzgz+Hbp2xHfY+pL 0W99f+knV/mYB//28Mx7Iio6J7PWEJOpM1Wcvs6fU+cmEAgLWeWF+JZn6sKELlQ0UeE/ FAag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=80Ajy3E8zr74DMwLvdHtBgD6k+JzeYDH65oyG0hvOck=; b=68kmf4mdaon1v6YoKMNetJxoHWrfjhSWbOXXB8WESVWPldSsrCs7KW7legsIX0mXc7 clzzTbPBDozLT2x9gKZFDLgTznvOaGw5iGi42qGIpzjsLuQKX9OdLIS2uRy8p4qbQyTn Syn7PumC1emkvpHuw6QYjUFrz+8KgIgs5lAzLTVjO1LNsh7NvTZnzaEOmsuSu0NDAZfr 5tl7cG2VAcrPKn2pMCauz2i1l0UTXPoZnjby9DFw4HCsatFek09vQ4T/akI/zjeLYnPJ 7MoZCA1OHqTI25+SDmCz7wrBIpVPAlJjPz2/O4pT1Ha/nQfgINo+XbWQCW6TPDyPRwlA IqWw== X-Gm-Message-State: AOAM530slq3XxsYnHp2ujnPi6Edlr9NoPkMOxdmjS0xSZ5h1mvjVACyN t8dA4p7OGzyiNYkMkp+nkok= X-Google-Smtp-Source: ABdhPJwCH+6lVfB4Sqddsc3NgswMMhmULDQDl8FrAVs2ZeTHKe+xjOs06ldTX1Zh0UsH8qVC6O0qnQ== X-Received: by 2002:a05:600c:1da9:b0:394:235f:f5de with SMTP id p41-20020a05600c1da900b00394235ff5demr3863342wms.120.1651592826369; Tue, 03 May 2022 08:47:06 -0700 (PDT) Received: from vmu1804.lan ([2a06:a004:d009:c8fa:102c:912a:a6e3:41ea]) by smtp.googlemail.com with ESMTPSA id c23-20020a7bc017000000b003942a244ecesm1861958wmb.19.2022.05.03.08.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 08:47:06 -0700 (PDT) From: Mikhail Zhilkin To: Rob Herring , Krzysztof Kozlowski Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Karim , M , Mikhail Zhilkin Subject: [PATCH v3 1/3] dt-bindings: Add Sercomm (Suzhou) Corporation vendor prefix Date: Tue, 3 May 2022 15:47:00 +0000 Message-Id: <20220503154700.2339796-1-csharper2005@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220503154254.2339744-1-csharper2005@gmail.com> References: <20220503154254.2339744-1-csharper2005@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Update Documentation/devicetree/bindings/vendor-prefixes.yaml to include "sercomm" as a vendor prefix for "Sercomm (Suzhou) Corporation". Company website: Link: https://www.sercomm.com/ Signed-off-by: Mikhail Zhilkin --- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Docum= entation/devicetree/bindings/vendor-prefixes.yaml index 01430973ecec..65ff22364fb3 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -1082,6 +1082,8 @@ patternProperties: description: Sensirion AG "^sensortek,.*": description: Sensortek Technology Corporation + "^sercomm,.*": + description: Sercomm (Suzhou) Corporation "^sff,.*": description: Small Form Factor Committee "^sgd,.*": --=20 2.25.1 From nobody Sun May 10 13:21:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42ECEC433EF for ; Tue, 3 May 2022 15:52:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238923AbiECPzj (ORCPT ); Tue, 3 May 2022 11:55:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238925AbiECPxu (ORCPT ); Tue, 3 May 2022 11:53:50 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 170DA6317; Tue, 3 May 2022 08:50:17 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id e2so23956207wrh.7; Tue, 03 May 2022 08:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kp0I+fDrNRZ+kcOulyBqIwYKgrX5Pypr91NpoQc/0zE=; b=ZFBOAaAsyVFB3azHklpMGisviv1wFqvgeuS+yXrkzNpI26aW8Rx4DIz/LT7mfLZjPt bdSXl4i53f+OSdYghJLapyYcckMhm1aIWxAOhQJWj9MXjGBcX1mpRpKOV1Vn8qMxL+uT rbpSVr+q9XpCTyISVuUqjbeBbgQyt4Mb7cVIlawXk/UCnggkV8Hm2nphDs5FQJAzITBY oVOiFW48hIk39EbzTqNOrPIxn6DY1w8fyciLm7M60NL5RxX91a2ZBhLOcd/UO2Ps2NYy AG5Z1NBvTY2N+gZkwta6wGhtU8KQYzrSLNGfezKuY0g5WSEwdseZf75KgGLAxa/faj0V O4Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kp0I+fDrNRZ+kcOulyBqIwYKgrX5Pypr91NpoQc/0zE=; b=8Q9Z5I5gd7jHBo1oJbt5X1k48MziwjLBRU+hrXKBqAdSWCV8YcewlSTmH7onHf26mn OvaG2LTjCo0PwSRU+2hdvXOwt7JMs0d/U3JmRRlfbk/8fjxTi6qUhmzDF7LJbcf1nUZq M1I2t4o0V5XTsGVDsHaACQYwRB4VYQVqqovGXv+yNdLI1yVr2SNJEsuIgxqWzefnOyc0 vW0v1AFlVIRp1ZPKQYitItn+TgDYETyVl39z4OLCSfQ46frzZ6+uDON+OhxfxSqwEA+U CifXTf53NFrCz7PyZsUVhFZAwnqut7nnUzANPO8A/jbuuDy92kQ4oCrwHwprbkyZMqB+ 1WBw== X-Gm-Message-State: AOAM530v7mGyVtHQAPUeBiJpGpLpHGU6VKSLelvNC1ZYo6DssSpExl3Z LoprFRJBLzJZ39V1P/uFs3Y= X-Google-Smtp-Source: ABdhPJwW896RxEFOdbJcnn2DEmhLXrdedi9FVjmGiZViAFZp1PCH+C2fCuq498nQlWo9yP0OdCiwUA== X-Received: by 2002:a5d:690c:0:b0:20a:d9d1:f5ce with SMTP id t12-20020a5d690c000000b0020ad9d1f5cemr13436892wru.295.1651593015655; Tue, 03 May 2022 08:50:15 -0700 (PDT) Received: from vmu1804.lan ([2a06:a004:d009:c8fa:102c:912a:a6e3:41ea]) by smtp.googlemail.com with ESMTPSA id p26-20020adfa21a000000b0020c5253d8ecsm9523482wra.56.2022.05.03.08.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 08:50:15 -0700 (PDT) From: Mikhail Zhilkin To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski Cc: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Karim , M , Mikhail Zhilkin Subject: [PATCH v3 2/3] dt-bindings: mtd: partitions: Extend fixed-partitions binding Date: Tue, 3 May 2022 15:50:07 +0000 Message-Id: <20220503155007.2339847-1-csharper2005@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220503154254.2339744-1-csharper2005@gmail.com> References: <20220503154254.2339744-1-csharper2005@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extend fixed-partitions binding for support of Sercomm partition parser (add "sercomm,sc-partitions" compatible). Signed-off-by: Mikhail Zhilkin Reviewed-by: Krzysztof Kozlowski --- .../mtd/partitions/fixed-partitions.yaml | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/mtd/partitions/fixed-partiti= ons.yaml b/Documentation/devicetree/bindings/mtd/partitions/fixed-partition= s.yaml index ea4cace6a955..ad3ccd250802 100644 --- a/Documentation/devicetree/bindings/mtd/partitions/fixed-partitions.yaml +++ b/Documentation/devicetree/bindings/mtd/partitions/fixed-partitions.yaml @@ -19,7 +19,11 @@ maintainers: =20 properties: compatible: - const: fixed-partitions + oneOf: + - const: fixed-partitions + - items: + - const: sercomm,sc-partitions + - const: fixed-partitions =20 "#address-cells": true =20 @@ -27,7 +31,24 @@ properties: =20 patternProperties: "@[0-9a-f]+$": - $ref: "partition.yaml#" + allOf: + - $ref: "partition.yaml#" + - if: + properties: + compatible: + contains: + const: sercomm,sc-partitions + then: + properties: + sercomm,scpart-id: + description: Partition id in Sercomm partition map. Mtd + parser uses this id to find a record in the partition map + containing offset and size of the current partition. The + values from partition map overrides partition offset and + size defined in reg property of the dts. Frequently these + values are the same, but may differ if device has bad + eraseblocks on a flash. + $ref: /schemas/types.yaml#/definitions/uint32 =20 required: - "#address-cells" @@ -52,6 +73,7 @@ examples: reg =3D <0x0100000 0x200000>; }; }; + - | partitions { compatible =3D "fixed-partitions"; @@ -64,6 +86,7 @@ examples: reg =3D <0x00000000 0x1 0x00000000>; }; }; + - | partitions { compatible =3D "fixed-partitions"; @@ -82,6 +105,7 @@ examples: reg =3D <0x2 0x00000000 0x1 0x00000000>; }; }; + - | partitions { compatible =3D "fixed-partitions"; @@ -119,3 +143,30 @@ examples: }; }; }; + + - | + partitions { + compatible =3D "sercomm,sc-partitions", "fixed-partitions"; + #address-cells =3D <1>; + #size-cells =3D <1>; + + partition@0 { + label =3D "u-boot"; + reg =3D <0x0 0x100000>; + sercomm,scpart-id =3D <0>; + read-only; + }; + + partition@100000 { + label =3D "dynamic partition map"; + reg =3D <0x100000 0x100000>; + sercomm,scpart-id =3D <1>; + }; + + partition@200000 { + label =3D "Factory"; + reg =3D <0x200000 0x100000>; + sercomm,scpart-id =3D <2>; + read-only; + }; + }; --=20 2.25.1 From nobody Sun May 10 13:21:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 163E6C433F5 for ; Tue, 3 May 2022 15:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238697AbiECPzX (ORCPT ); Tue, 3 May 2022 11:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238114AbiECPzU (ORCPT ); Tue, 3 May 2022 11:55:20 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F4E931DF3 for ; Tue, 3 May 2022 08:51:47 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id j15so24006722wrb.2 for ; Tue, 03 May 2022 08:51:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3XVNWTw//x2P33682v6NyS3MKzAVxlenoKtyup9T5mU=; b=p2dTj+s6tGOxAoKO+MFD+GzBNaogbuyHxrxkpY07zY697prCUCqky699LgqJ06/1lm wbkSRWIGPurtaYNjrH7fNLFd1iehUhpUL+dlSLLzCWYQwCSToUjbDtvVWWME2R4qPJMw WDs/rif5E67LjXwCzr/JnS5SHYzpH2wJAiEtv6ZvX1yGETTMYQJ39qIsD3JuqMZmSwuv +/fYl/EwsSyjIK/3w2a2d0wBsv2GGbkhKeeK/UpZj2vOGaiG2QbbRYD4jsDt9gFLKlBH qyMERdd66eTw2xIAuuIvYSY/QVsp2xaYxUl5WNH0+/BKLMQc7bHOBeCATaad3J3/Lnt+ +uUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3XVNWTw//x2P33682v6NyS3MKzAVxlenoKtyup9T5mU=; b=o39hQLgdhm+mUZ5q1q0KU7eJrXQ55p1Hrv9xyvvDv1AazjRUhn6DQyRtqJvAA75VYS K5f47A8jyExYNX6PZGl8/M3tuvuY+iLc4akj2oJvtewBEb24dnSKiw4aBUV0ZN7rPfwT Jj/R+f479GbodoiIAgTmyZDtm5oeS7zzuRQGkx0LujOT4ZRgEtf1Y246xpmywvUPBN8x ooGtLBbdq6J+8CZh2H6NIGm1fKyss7EE9rNP+LR6lUPmm6QxgZPeIXt1rqsTv3zSpaog j0u0wWdL6AiX+d73U6Un/qgM0tYVohrRPv/2PfKFUP1osUCmWjzgfJk7hjbBAXm6Sz5d iC6A== X-Gm-Message-State: AOAM533TNED/FJklfjUltj9nSpcoMcNB1DEKw6J6OoyVblFmL0AAge6R kPY1++z0btouut4lB2USVVXzi51uZRtXv1AMclo= X-Google-Smtp-Source: ABdhPJzf5uVzicYMnLTOJWrC/r+9FRMRD1XT6VAvs3qBP/hlXXXqZ7PjLfCoesHxEvB53kiD/OOdZA== X-Received: by 2002:adf:cc83:0:b0:20a:ca0c:ca1 with SMTP id p3-20020adfcc83000000b0020aca0c0ca1mr13084027wrj.553.1651593105974; Tue, 03 May 2022 08:51:45 -0700 (PDT) Received: from vmu1804.lan ([2a06:a004:d009:c8fa:102c:912a:a6e3:41ea]) by smtp.googlemail.com with ESMTPSA id bi26-20020a05600c3d9a00b003942a244f37sm1828549wmb.16.2022.05.03.08.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 08:51:45 -0700 (PDT) From: Mikhail Zhilkin To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Mikhail Zhilkin , Hauke Mehrtens , NOGUCHI Hiroshi , INAGAKI Hiroshi , linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Karim , M Subject: [PATCH v3 3/3] mtd: parsers: add support for Sercomm partitions Date: Tue, 3 May 2022 15:51:40 +0000 Message-Id: <20220503155140.2339899-1-csharper2005@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220503154254.2339744-1-csharper2005@gmail.com> References: <20220503154254.2339744-1-csharper2005@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This adds an MTD partition parser for the Sercomm partition table that is used in some Beeline, Netgear and Sercomm routers. The Sercomm partition map table contains real partition offsets, which may differ from device to device depending on the number and location of bad blocks on NAND. This is essentially the same code as proposed by NOGUCHI Hiroshi: Link: https://github.com/openwrt/openwrt/pull/1318#issuecomment-420607394 Signed-off-by: NOGUCHI Hiroshi Signed-off-by: Mikhail Zhilkin --- drivers/mtd/parsers/Kconfig | 9 ++ drivers/mtd/parsers/Makefile | 1 + drivers/mtd/parsers/scpart.c | 240 +++++++++++++++++++++++++++++++++++ 3 files changed, 250 insertions(+) create mode 100644 drivers/mtd/parsers/scpart.c diff --git a/drivers/mtd/parsers/Kconfig b/drivers/mtd/parsers/Kconfig index 23763d16e4f9..851f4670d89b 100644 --- a/drivers/mtd/parsers/Kconfig +++ b/drivers/mtd/parsers/Kconfig @@ -186,3 +186,12 @@ config MTD_QCOMSMEM_PARTS help This provides support for parsing partitions from Shared Memory (SMEM) for NAND and SPI flash on Qualcomm platforms. + +config MTD_SERCOMM_PARTS + tristate "Sercomm partition table parser" + depends on MTD + help + This provides partitions table parser for devices with Sercomm + partition map. This partition table contains real partition + offsets, which may differ from device to device depending on the + number and location of bad blocks on NAND. diff --git a/drivers/mtd/parsers/Makefile b/drivers/mtd/parsers/Makefile index 2e98aa048278..2fcf0ab9e7da 100644 --- a/drivers/mtd/parsers/Makefile +++ b/drivers/mtd/parsers/Makefile @@ -10,6 +10,7 @@ ofpart-$(CONFIG_MTD_OF_PARTS_LINKSYS_NS)+=3D ofpart_links= ys_ns.o obj-$(CONFIG_MTD_PARSER_IMAGETAG) +=3D parser_imagetag.o obj-$(CONFIG_MTD_AFS_PARTS) +=3D afs.o obj-$(CONFIG_MTD_PARSER_TRX) +=3D parser_trx.o +obj-$(CONFIG_MTD_SERCOMM_PARTS) +=3D scpart.o obj-$(CONFIG_MTD_SHARPSL_PARTS) +=3D sharpslpart.o obj-$(CONFIG_MTD_REDBOOT_PARTS) +=3D redboot.o obj-$(CONFIG_MTD_QCOMSMEM_PARTS) +=3D qcomsmempart.o diff --git a/drivers/mtd/parsers/scpart.c b/drivers/mtd/parsers/scpart.c new file mode 100644 index 000000000000..d7bb736c9f2a --- /dev/null +++ b/drivers/mtd/parsers/scpart.c @@ -0,0 +1,240 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * drivers/mtd/scpart.c: Sercomm Partition Parser + * + * Copyright (C) 2018 NOGUCHI Hiroshi + * Copyright (C) 2022 Mikhail Zhilkin + */ + +#include +#include +#include +#include +#include + +#define MOD_NAME "scpart" + +#ifdef pr_fmt +#undef pr_fmt +#endif + +#define pr_fmt(fmt) MOD_NAME ": " fmt + +static const char sc_part_magic[] =3D { + 'S', 'C', 'F', 'L', 'M', 'A', 'P', 'O', 'K', '\0', +}; +#define PART_MAGIC_LEN sizeof(sc_part_magic) + +/* assumes that all fields are set by CPU native endian */ +struct sc_part_desc { + uint32_t part_id; + uint32_t part_offs; + uint32_t part_bytes; +}; +#define ID_ALREADY_FOUND 0xFFFFFFFFUL + +#define MAP_OFFS_IN_BLK 0x800 + +#define MAP_MIRROR_NUM 2 + +static int scpart_desc_is_valid(struct sc_part_desc *pdesc) +{ + return ((pdesc->part_id !=3D 0xFFFFFFFFUL) && + (pdesc->part_offs !=3D 0xFFFFFFFFUL) && + (pdesc->part_bytes !=3D 0xFFFFFFFFUL)); +} + +static int scpart_scan_partmap(struct mtd_info *master, loff_t partmap_off= s, + struct sc_part_desc **ppdesc) +{ + uint8_t *buf; + loff_t offs; + size_t retlen; + struct sc_part_desc *pdesc =3D NULL; + struct sc_part_desc *tmpdesc; + int cnt =3D 0; + int res2; + int res =3D 0; + + buf =3D kzalloc(master->erasesize, GFP_KERNEL); + if (!buf) { + res =3D -ENOMEM; + goto out; + } + + res2 =3D mtd_read(master, partmap_offs, master->erasesize, &retlen, buf); + if (res2 || retlen !=3D master->erasesize) { + res =3D -EIO; + goto free; + } + + offs =3D MAP_OFFS_IN_BLK; + while (offs < (master->erasesize - sizeof(*tmpdesc))) { + tmpdesc =3D (struct sc_part_desc *)&(buf[offs]); + if (!scpart_desc_is_valid(tmpdesc)) + break; + cnt++; + offs +=3D sizeof(*tmpdesc); + } + + if (cnt > 0) { + int bytes =3D cnt * sizeof(*pdesc); + + pdesc =3D kcalloc(cnt, sizeof(*pdesc), GFP_KERNEL); + if (!pdesc) { + res =3D -ENOMEM; + goto free; + } + memcpy(pdesc, &(buf[MAP_OFFS_IN_BLK]), bytes); + + *ppdesc =3D pdesc; + res =3D cnt; + } + +free: + kfree(buf); + +out: + return res; +} + +static int scpart_find_partmap(struct mtd_info *master, + struct sc_part_desc **ppdesc) +{ + loff_t offs; + uint8_t rdbuf[PART_MAGIC_LEN]; + size_t retlen; + int magic_found =3D 0; + int res2; + int res =3D 0; + + offs =3D 0; + while ((magic_found < MAP_MIRROR_NUM) && + (offs < master->size) && !mtd_block_isbad(master, offs)) { + res2 =3D mtd_read(master, offs, PART_MAGIC_LEN, &retlen, rdbuf); + if (res2 || (retlen !=3D PART_MAGIC_LEN)) { + res =3D -EIO; + goto out; + } + if (!memcmp(rdbuf, sc_part_magic, PART_MAGIC_LEN)) { + pr_debug("Signature found at 0x%llx\n", offs); + magic_found++; + res =3D scpart_scan_partmap(master, offs, ppdesc); + if (res > 0) + goto out; + } + offs +=3D master->erasesize; + } + +out: + if (res > 0) + pr_info("Valid 'SC PART MAP' (%d partitions) found at 0x%llx\n", res, of= fs); + else + pr_info("No valid 'SC PART MAP' was found\n"); + + return res; +} + +static int scpart_parse(struct mtd_info *master, + const struct mtd_partition **pparts, + struct mtd_part_parser_data *data) +{ + struct sc_part_desc *scpart_map =3D NULL; + struct mtd_partition *parts =3D NULL; + struct device_node *mtd_node; + struct device_node *ofpart_node; + struct device_node *pp; + const char *partname; + int nr_scparts; + int nr_parts =3D 0; + int n; + int res =3D 0; + + mtd_node =3D mtd_get_of_node(master); + if (!mtd_node) + goto out; + + ofpart_node =3D of_get_child_by_name(mtd_node, "partitions"); + if (!ofpart_node) + goto out; + + nr_scparts =3D scpart_find_partmap(master, &scpart_map); + if (nr_scparts <=3D 0) { + res =3D nr_scparts; + goto free; + } + + parts =3D kcalloc(of_get_child_count(ofpart_node), sizeof(*parts), + GFP_KERNEL); + if (!parts) { + res =3D -ENOMEM; + goto out; + } + + for_each_child_of_node(ofpart_node, pp) { + u32 scpart_id; + + if (of_property_read_u32(pp, "sercomm,scpart-id", &scpart_id)) + continue; + + for (n =3D 0 ; n < nr_scparts ; n++) + if ((scpart_map[n].part_id !=3D ID_ALREADY_FOUND) && + (scpart_id =3D=3D scpart_map[n].part_id)) + break; + if (n >=3D nr_scparts) + /* not match */ + continue; + + /* add the partition found in OF into MTD partition array */ + parts[nr_parts].offset =3D scpart_map[n].part_offs; + parts[nr_parts].size =3D scpart_map[n].part_bytes; + parts[nr_parts].of_node =3D pp; + + if (!of_property_read_string(pp, "label", &partname)) + parts[nr_parts].name =3D partname; + if (of_property_read_bool(pp, "read-only")) + parts[nr_parts].mask_flags |=3D MTD_WRITEABLE; + if (of_property_read_bool(pp, "lock")) + parts[nr_parts].mask_flags |=3D MTD_POWERUP_LOCK; + + /* mark as 'done' */ + scpart_map[n].part_id =3D ID_ALREADY_FOUND; + + nr_parts++; + } + + if (nr_parts > 0) { + *pparts =3D parts; + res =3D nr_parts; + } else + pr_info("No partition in OF matches partition ID with 'SC PART MAP'.\n"); + + of_node_put(pp); + +free: + kfree(scpart_map); + if (res <=3D 0) + kfree(parts); + +out: + return res; +} + +static const struct of_device_id scpart_parser_of_match_table[] =3D { + { .compatible =3D "sercomm,sc-partitions" }, + {}, +}; +MODULE_DEVICE_TABLE(of, scpart_parser_of_match_table); + +static struct mtd_part_parser scpart_parser =3D { + .parse_fn =3D scpart_parse, + .name =3D "scpart", + .of_match_table =3D scpart_parser_of_match_table, +}; +module_mtd_part_parser(scpart_parser); + +/* mtd parsers will request the module by parser name */ +MODULE_ALIAS("scpart"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("NOGUCHI Hiroshi "); +MODULE_DESCRIPTION("Sercomm partition parser"); --=20 2.25.1