From patchwork Fri Jul 22 17:43:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 592478 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp710586mab; Fri, 22 Jul 2022 10:43:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s7Q1fmhkjEgivBJX1IjEz6PGkPeY1zC7JwgcZHBIpZwSRncy8200ui8HmVplvJ8de/fYQM X-Received: by 2002:a92:ca46:0:b0:2dd:52b:bfd1 with SMTP id q6-20020a92ca46000000b002dd052bbfd1mr426906ilo.315.1658511838953; Fri, 22 Jul 2022 10:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658511838; cv=none; d=google.com; s=arc-20160816; b=P6ame0YMo0GIs4qlrg0XTs+Hbudxq9EMVJtnm45X0b8nnXdxp07FJIjwt7sXJYWD7L aZGvdy1npp5t5CKm0CEmc2jgiiewaEjqxYYhVhSTMXhtTmrdVXRQpG6bjc73e4Hv0z2u sg5lQk4nalistZZCLKzaH2bOTtT/rbhrg7qTWMuxynlGk3xeCs8s4aQXMfS1/GgQLJnk zl64/nn4IZnYyc1R1FckviauqMJDA2kgiAdaq52o+POAm50xXPyyUfLUwlyoGqUjQRAC Mg09Jp/kDNJgB3Cns/vIJjRpCM5Rxhsb941oxLhosvC6raV51I5zoRbYU3kZuADShxuR cljw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nXenbi8S+JkNhheD7P0GbIzhuSKu5hm4C4u20NfFT/Q=; b=k5vrK+EJx7fTdETRM64FViAbEvOqkybz0xtw5YMj4CWlWRryNq7NbHNXePt2uevMr+ nguByd6yG8DSezHJz4h9NRjPneqgOwZbDc9OxPYG4JfEIZh+EhQIj9tbwVeYOcUpIuDq J/6pWTlfVom2xy/22nc0ljla/KeEPld2xVJ0SVe8X0zD/c59xiJPD8G6/nFXpx/bQ0Z/ x/gT+L1gbw8HaPtr/utpFI4hLZrJ74qfTRPNoai+67IbphwvA80/lnJCOas8QnNL8x1Y jjJVm6bN+akzoEMTKj1uP4tSTAGrwJ2DRmbLkGG1mM8PWQX48tLJEp9yzdpT4aP0KRrt chmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZVhhd+NZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id u10-20020a056e021a4a00b002dd2065c122si1196976ilv.103.2022.07.22.10.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:43:58 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZVhhd+NZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EF39583FAE; Fri, 22 Jul 2022 19:43:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZVhhd+NZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9BB5F83FA7; Fri, 22 Jul 2022 19:43:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C180483FA1 for ; Fri, 22 Jul 2022 19:43:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-io1-xd2b.google.com with SMTP id p81so4171665iod.2 for ; Fri, 22 Jul 2022 10:43:51 -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=nXenbi8S+JkNhheD7P0GbIzhuSKu5hm4C4u20NfFT/Q=; b=ZVhhd+NZ2wOKxVAUaJ5Rl+ZZjfuGzEKJAYpf23FjmwK1dtL/fF7nIono2lMi2lhmTX Jb7rXR4QQ1g/RNwPCVMdQ2UiobD5ckQY8pFWRy7L8hBUXrH79RWxsgs6yOkGe5etjrZb 8tpEc6ueGehZPvkyqpWQdYNI//s+H5mJDESUCBZUoj5T9uVmcptkxK68cPhqmOfNt0Vn c08JJma0ExiMmxm+vO+MgwE18Q4EO4UAR0DeemmySV5CGooEnEQBMSSpBQsCv2la/yvS zzwzuh8HTb8xRy10a4VOkWFtcfL2eOhnxK1qQa7R8XyOP7iPAHsmbWuDhH/XJixxwtlJ O7Sg== 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=nXenbi8S+JkNhheD7P0GbIzhuSKu5hm4C4u20NfFT/Q=; b=dC0dGdBLtLGEpMsfOGpqXsiGRhuaFFvg0AXilJGCo+AhmZcNHOIqv+NxqajBLMpEfg b7MPJJtOHJPJBqgNOCavQiPX0kjiI8wU4Km04R8BvsiP71++2R63mID92MuUDmazR09A s8p1/XeB5AmhyIQ9mIC3Ifz2ehtPulMxivc66kcRExcGtIBNI1ihOknr5bqFxKBNAbp1 sODZMOFVrnqZld0jUPo/TvSldxmPcpj6GsCqvwsdxtdVjCU+8mvFRym1YotitJEVLN0/ erX3FV7ZFHOxvJoj7qj6kT2OfwZl3Iq5ijspaBFR4H1mj5WjWcZ+c4tloA2PMOunh3fV +zxg== X-Gm-Message-State: AJIora/b4Zqu5rso3LEd7Vg6HOaB7Qb1Pj/y7DONzEgOc+ECvDZb2RFu wwlL7ost6c2l7WlpIlL82z0lE9ZWcrM= X-Received: by 2002:a02:84e2:0:b0:33f:7ec1:b430 with SMTP id f89-20020a0284e2000000b0033f7ec1b430mr544187jai.63.1658511830038; Fri, 22 Jul 2022 10:43:50 -0700 (PDT) Received: from localhost.localdomain (wnpgmb0311w-ds01-179-115.dynamic.bellmts.net. [206.45.179.115]) by smtp.gmail.com with ESMTPSA id s26-20020a02c51a000000b00339eedc7840sm2242348jam.94.2022.07.22.10.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:43:49 -0700 (PDT) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de Cc: xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, takahiro.akashi@linaro.org, patrick.delaunay@foss.st.com, patrice.chotard@foss.st.com, sjg@chromium.org, bmeng.cn@gmail.com, trini@konsulko.com, etienne.carriere@linaro.org, monstr@monstr.eu, Sughosh Ganu , Masami Hiramatsu , Jassi Brar Subject: [PATCH 1/5] dt/bindings: Add bindings for FWU Metadata mtd storage Date: Fri, 22 Jul 2022 12:43:15 -0500 Message-Id: <20220722174319.64006-2-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220722174319.64006-1-jassisinghbrar@gmail.com> References: <20220722174240.63935-1-jassisinghbrar@gmail.com> <20220722174319.64006-1-jassisinghbrar@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Sughosh Ganu Add bindings needed for accessing the FWU metadata regions. These include the compatible string which point to the access method, the actual device which stores the FWU metadata and the offsets for both metadata regions. The current patch adds basic bindings needed for accessing the metadata structure on non-GPT mtd regions. Signed-off-by: Masami Hiramatsu Signed-off-by: Jassi Brar --- .../firmware/fwu-mdata-mtd.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml diff --git a/doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml b/doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml new file mode 100644 index 0000000000..4f5404f999 --- /dev/null +++ b/doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/u-boot,fwu-mdata-sf.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: FWU metadata on MTD device without GPT + +maintainers: + - Masami Hiramatsu + +properties: + compatible: + items: + - const: u-boot,fwu-mdata-mtd + + fwu-mdata-store: + maxItems: 1 + description: Phandle of the MTD device which contains the FWU medatata. + + mdata-offsets: + minItems: 2 + description: Offsets of the primary and secondary FWU metadata in the NOR flash. + +required: + - compatible + - fwu-mdata-store + - mdata-offsets + +additionalProperties: false + +examples: + - | + fwu-mdata { + compatible = "u-boot,fwu-mdata-mtd"; + fwu-mdata-store = <&spi-flash>; + mdata-offsets = <0x500000 0x530000>; + }; From patchwork Fri Jul 22 17:43:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 592479 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp710778mab; Fri, 22 Jul 2022 10:44:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1srjNs/edRqw6z5knDseeVycsEHVdugDawEgENPTilFIRThqk7NHmy6dT1AQ9h/bFusHfg9 X-Received: by 2002:a02:6d1f:0:b0:33f:8d28:4d6d with SMTP id m31-20020a026d1f000000b0033f8d284d6dmr549172jac.16.1658511857908; Fri, 22 Jul 2022 10:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658511857; cv=none; d=google.com; s=arc-20160816; b=UHVJ+S5puc+AJHE2EOIhjCwM4a1Sh1o01nsIG3JxgacjBMpe7hAbaRE6nZ8P+rGA9g Zu8AI0T/1SFNaUSleQAApSelM4fPSOCrs1FpZ1+ybhysFQHcuTyVYgqr2Rt0lhkm/F+i JLiQ5hRM+kM8uUn1C9a7yPnVH6CLOKGqv33d5er7ZhPIbtFlFSFxENDHIUD837oGAB6J jTiAe65UE6DFarZ6olIrrDcZG188q5QLn3Zu1WAikGBkoOjPQ7RGtS249MyrYx0Kh8es ksyr5PmLwCsKr492xucR0epW4j6kulShMxUGyGP0edB9RNGiLMRnk2I1c2gw8WWhyvgz HGVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=q6/wBxomtzb4iUaBLzhy3l36VqjsOzDIycNrjWp/Gu8=; b=0ZsjR1e1jivwikv/1o0LBO7/x11PH7NHwVbS7XgwNDZf0DmIHpMKIGs67Gjqkld9UU JhO/5l1ZdGJA0IfTWTQAYXMioTkTNP7l0KYcfS2yuNG6VZTNSonJtRRkfc2+O3fYd+nF F/p7KzFeiMPnwaXLaPqCJeZa3Bqreyzhg5LWcwSDuz004xaQQyB0qc/HGtE14Gx2c7H5 GYjpJr/2rogUqs9/BfL+BcfexCLnLdZ/uofxWdXpuxpmx6yBj4wXeDxSrdvRHBSvYyed Xbeonepb8HDYeycqcj+SNj2pi870RWC3brKXte7djRrKq3sxdfutqAU4OU12xow9nxOc bvhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="SlJ/ZoBZ"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id m14-20020a026d0e000000b0033c74ff7630si4607704jac.97.2022.07.22.10.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:44:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="SlJ/ZoBZ"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D109B840B3; Fri, 22 Jul 2022 19:44:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SlJ/ZoBZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9669383FB5; Fri, 22 Jul 2022 19:43:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EB4A883AC3 for ; Fri, 22 Jul 2022 19:43:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-io1-xd35.google.com with SMTP id n7so4155079ioo.7 for ; Fri, 22 Jul 2022 10:43:55 -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=q6/wBxomtzb4iUaBLzhy3l36VqjsOzDIycNrjWp/Gu8=; b=SlJ/ZoBZpIfPS9y0KjloCIJWhpDvfeIlWiS+dxeAhM380Vzm3TkHAIxejYu5yikUGr ebHzntD6UmeGJ3ZmSEiBntGB6XZLoEaP65wtYYX71zEJo6JLX4jjppUorLt01UQ1Kcwm n1/nWRlXQ2sWFPxmCAKQZHIQoAKzQx9+upLQNuc5bPAYPdxtBkQG0zM5J7rZ+JfdUIvj y7PE9Uu56licw4soW6nhfSyrzPO35Stng2lYoEyVaRFAQhbOXSFMotiggYuwbkwfitOH Sj9qkB1DiMA6KXiJTYkBG58Q+Zc8KB4MUI2GhTHY2UsnHPVsbtb9QGH8Nwffe4sQhDyT kBSQ== 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=q6/wBxomtzb4iUaBLzhy3l36VqjsOzDIycNrjWp/Gu8=; b=rf585QoDnC8Q5PQO9lgUfkE0ZwNh4ZZmMG1ffldU7O2SBsp0gEofo6iXVGrP5YasS3 KzvQbWIMrP44g7gG3+BqjoM3o9pZ89Awzly5RzNidCYubG/BVJbeHWzkN0aM2DtK+6MH V6/AnzQZAyg88IPzK+6U9lKu6X2MCEYRvYxizF6LBmL2oEgiN8iR7+OJKJ/77rg9OVd7 LKeroDU0YUslYCGE6DWw9BCZt2ckK6jTTDA2pttMXpmE2AKa8ML8fm/igI+R+VkDLUBK 30CXYVeVpQc5uzIH2ZpeBvvuNsSWg7kCzJqyh+7tN79XPAcg7ny8WGx9OU9czf/p2Mdf 6YSg== X-Gm-Message-State: AJIora9dQpHM0dVt5JA0RIQ89QuhRWINSvVRBFyoca3OnCWnfRyeKTHQ JvSR+wMUyeudHWYi1InVpPNaEBDOgaI= X-Received: by 2002:a05:6602:2c8f:b0:67c:31dc:ef6 with SMTP id i15-20020a0566022c8f00b0067c31dc0ef6mr317823iow.63.1658511834127; Fri, 22 Jul 2022 10:43:54 -0700 (PDT) Received: from localhost.localdomain (wnpgmb0311w-ds01-179-115.dynamic.bellmts.net. [206.45.179.115]) by smtp.gmail.com with ESMTPSA id s26-20020a02c51a000000b00339eedc7840sm2242348jam.94.2022.07.22.10.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:43:53 -0700 (PDT) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de Cc: xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, takahiro.akashi@linaro.org, patrick.delaunay@foss.st.com, patrice.chotard@foss.st.com, sjg@chromium.org, bmeng.cn@gmail.com, trini@konsulko.com, etienne.carriere@linaro.org, monstr@monstr.eu, Sughosh Ganu , Jassi Brar Subject: [PATCH 2/5] FWU: Add FWU metadata access driver for MTD storage regions Date: Fri, 22 Jul 2022 12:43:16 -0500 Message-Id: <20220722174319.64006-3-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220722174319.64006-1-jassisinghbrar@gmail.com> References: <20220722174240.63935-1-jassisinghbrar@gmail.com> <20220722174319.64006-1-jassisinghbrar@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Sughosh Ganu In the FWU Multi Bank Update feature, the information about the updatable images is stored as part of the metadata, on a separate region. Add a driver for reading from and writing to the metadata when the updatable images and the metadata are stored on a raw MTD region. Signed-off-by: Sughosh Ganu Signed-off-by: Jassi Brar --- drivers/fwu-mdata/Kconfig | 8 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++++++++++++++++++++++++++++++ 3 files changed, 317 insertions(+) create mode 100644 drivers/fwu-mdata/fwu_mdata_mtd.c diff --git a/drivers/fwu-mdata/Kconfig b/drivers/fwu-mdata/Kconfig index d5edef19d6..a8fa9ad783 100644 --- a/drivers/fwu-mdata/Kconfig +++ b/drivers/fwu-mdata/Kconfig @@ -14,3 +14,11 @@ config FWU_MDATA_GPT_BLK help Enable support for accessing FWU Metadata on GPT partitioned block devices. + +config FWU_MDATA_MTD + bool "FWU Metadata access for non-GPT MTD devices" + depends on DM_FWU_MDATA && MTD + help + Enable support for accessing FWU Metadata on non-partitioned + (or non-GPT partitioned, e.g. partition nodes in devicetree) + MTD devices. diff --git a/drivers/fwu-mdata/Makefile b/drivers/fwu-mdata/Makefile index 313049f67a..58f8023f16 100644 --- a/drivers/fwu-mdata/Makefile +++ b/drivers/fwu-mdata/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o +obj-$(CONFIG_FWU_MDATA_MTD) += fwu_mdata_mtd.o diff --git a/drivers/fwu-mdata/fwu_mdata_mtd.c b/drivers/fwu-mdata/fwu_mdata_mtd.c new file mode 100644 index 0000000000..d543a419fd --- /dev/null +++ b/drivers/fwu-mdata/fwu_mdata_mtd.c @@ -0,0 +1,308 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +struct fwu_mdata_mtd_priv { + struct mtd_info *mtd; + u32 pri_offset; + u32 sec_offset; +}; + +enum fwu_mtd_op { + FWU_MTD_READ, + FWU_MTD_WRITE, +}; + +static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size) +{ + return !do_div(size, mtd->erasesize); +} + +static int mtd_io_data(struct mtd_info *mtd, u32 offs, u32 size, void *data, + enum fwu_mtd_op op) +{ + struct mtd_oob_ops io_op ={}; + u64 lock_offs, lock_len; + size_t len; + void *buf; + int ret; + + if (!mtd_is_aligned_with_block_size(mtd, offs)) + return -EINVAL; + lock_offs = offs; + lock_len = round_up(size, mtd->erasesize); + + ret = mtd_unlock(mtd, lock_offs, lock_len); + if (ret && ret != -EOPNOTSUPP) + return ret; + + if (op == FWU_MTD_WRITE) { + struct erase_info erase_op = {}; + + /* This will expand erase size to align with the block size */ + erase_op.mtd = mtd; + erase_op.addr = lock_offs; + erase_op.len = lock_len; + erase_op.scrub = 0; + + ret = mtd_erase(mtd, &erase_op); + if (ret) + goto lock_out; + } + + /* Also, expand the write size to align with the write size */ + len = round_up(size, mtd->writesize); + + buf = memalign(ARCH_DMA_MINALIGN, len); + if (!buf) { + ret = -ENOMEM; + goto lock_out; + } + io_op.mode = MTD_OPS_AUTO_OOB; + io_op.len = len; + io_op.ooblen = 0; + io_op.datbuf = buf; + io_op.oobbuf = NULL; + + if (op == FWU_MTD_WRITE) { + memcpy(buf, data, size); + ret = mtd_write_oob(mtd, offs, &io_op); + } else { + ret = mtd_read_oob(mtd, offs, &io_op); + if (!ret) + memcpy(data, buf, size); + } + free(buf); + +lock_out: + mtd_lock(mtd, lock_offs, lock_len); + + return ret; +} + +static int fwu_mtd_load_mdata(struct mtd_info *mtd, struct fwu_mdata **mdata, + u32 offs, bool primary) +{ + size_t size = sizeof(struct fwu_mdata); + int ret; + + *mdata = malloc(size); + if (!*mdata) + return -ENOMEM; + + ret = mtd_io_data(mtd, offs, size, (void *)*mdata, FWU_MTD_READ); + if (ret >= 0) { + ret = fwu_verify_mdata(*mdata, primary); + if (ret < 0) { + free(*mdata); + *mdata = NULL; + } + } + + return ret; +} + +static int fwu_mtd_load_primary_mdata(struct fwu_mdata_mtd_priv *mtd_priv, + struct fwu_mdata **mdata) +{ + return fwu_mtd_load_mdata(mtd_priv->mtd, mdata, mtd_priv->pri_offset, true); +} + +static int fwu_mtd_load_secondary_mdata(struct fwu_mdata_mtd_priv *mtd_priv, + struct fwu_mdata **mdata) +{ + return fwu_mtd_load_mdata(mtd_priv->mtd, mdata, mtd_priv->sec_offset, false); +} + +static int fwu_mtd_save_primary_mdata(struct fwu_mdata_mtd_priv *mtd_priv, + struct fwu_mdata *mdata) +{ + return mtd_io_data(mtd_priv->mtd, mtd_priv->pri_offset, + sizeof(struct fwu_mdata), mdata, FWU_MTD_WRITE); +} + +static int fwu_mtd_save_secondary_mdata(struct fwu_mdata_mtd_priv *mtd_priv, + struct fwu_mdata *mdata) +{ + return mtd_io_data(mtd_priv->mtd, mtd_priv->sec_offset, + sizeof(struct fwu_mdata), mdata, FWU_MTD_WRITE); +} + +static int fwu_mtd_get_valid_mdata(struct fwu_mdata_mtd_priv *mtd_priv, + struct fwu_mdata **mdata) +{ + if (fwu_mtd_load_primary_mdata(mtd_priv, mdata) == 0) + return 0; + + log_err("Failed to load/verify primary mdata. Try secondary.\n"); + + if (fwu_mtd_load_secondary_mdata(mtd_priv, mdata) == 0) + return 0; + + log_err("Failed to load/verify secondary mdata.\n"); + + return -1; +} + +static int fwu_mtd_update_mdata(struct udevice *dev, struct fwu_mdata *mdata) +{ + struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(dev); + int ret; + + /* Update mdata crc32 field */ + mdata->crc32 = crc32(0, (void *)&mdata->version, + sizeof(*mdata) - sizeof(u32)); + + /* First write the primary mdata */ + ret = fwu_mtd_save_primary_mdata(mtd_priv, mdata); + if (ret < 0) { + log_err("Failed to update the primary mdata.\n"); + return ret; + } + + /* And now the replica */ + ret = fwu_mtd_save_secondary_mdata(mtd_priv, mdata); + if (ret < 0) { + log_err("Failed to update the secondary mdata.\n"); + return ret; + } + + return 0; +} + +static int fwu_mtd_mdata_check(struct udevice *dev) +{ + struct fwu_mdata *primary = NULL, *secondary = NULL; + struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(dev); + int ret; + + ret = fwu_mtd_load_primary_mdata(mtd_priv, &primary); + if (ret < 0) + log_err("Failed to read the primary mdata: %d\n", ret); + + ret = fwu_mtd_load_secondary_mdata(mtd_priv, &secondary); + if (ret < 0) + log_err("Failed to read the secondary mdata: %d\n", ret); + + if (primary && secondary) { + if (memcmp(primary, secondary, sizeof(struct fwu_mdata))) { + log_err("The primary and the secondary mdata are different\n"); + ret = -1; + } + } else if (primary) { + ret = fwu_mtd_save_secondary_mdata(mtd_priv, primary); + if (ret < 0) + log_err("Restoring secondary mdata partition failed\n"); + } else if (secondary) { + ret = fwu_mtd_save_primary_mdata(mtd_priv, secondary); + if (ret < 0) + log_err("Restoring primary mdata partition failed\n"); + } + + free(primary); + free(secondary); + return ret; +} + +static int fwu_mtd_get_mdata(struct udevice *dev, struct fwu_mdata **mdata) +{ + struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(dev); + + return fwu_mtd_get_valid_mdata(mtd_priv, mdata); +} + +/** + * fwu_mdata_mtd_of_to_plat() - Translate from DT to fwu mdata device + */ +static int fwu_mdata_mtd_of_to_plat(struct udevice *dev) +{ + struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(dev); + const fdt32_t *phandle_p = NULL; + struct udevice *mtd_dev; + struct mtd_info *mtd; + int ret, size; + u32 phandle; + + /* Find the FWU mdata storage device */ + phandle_p = ofnode_get_property(dev_ofnode(dev), + "fwu-mdata-store", &size); + if (!phandle_p) { + log_err("fwu-mdata-store property not found\n"); + return -ENOENT; + } + + phandle = fdt32_to_cpu(*phandle_p); + + ret = device_get_global_by_ofnode( + ofnode_get_by_phandle(phandle), + &mtd_dev); + if (ret) + return ret; + + mtd_probe_devices(); + + mtd_for_each_device(mtd) { + if (mtd->dev == mtd_dev) { + mtd_priv->mtd = mtd; + log_debug("Found the FWU mdata mtd device %s\n", mtd->name); + break; + } + } + if (!mtd_priv->mtd) { + log_err("Failed to find mtd device by fwu-mdata-store\n"); + return -ENOENT; + } + + /* Get the offset of primary and seconday mdata */ + ret = ofnode_read_u32_index(dev_ofnode(dev), "mdata-offsets", 0, + &mtd_priv->pri_offset); + if (ret) + return ret; + ret = ofnode_read_u32_index(dev_ofnode(dev), "mdata-offsets", 1, + &mtd_priv->sec_offset); + if (ret) + return ret; + + return 0; +} + +static int fwu_mdata_mtd_probe(struct udevice *dev) +{ + /* Ensure the metadata can be read. */ + return fwu_mtd_mdata_check(dev); +} + +static struct fwu_mdata_ops fwu_mtd_ops = { + .mdata_check = fwu_mtd_mdata_check, + .get_mdata = fwu_mtd_get_mdata, + .update_mdata = fwu_mtd_update_mdata, +}; + +static const struct udevice_id fwu_mdata_ids[] = { + { .compatible = "u-boot,fwu-mdata-mtd" }, + { } +}; + +U_BOOT_DRIVER(fwu_mdata_mtd) = { + .name = "fwu-mdata-mtd", + .id = UCLASS_FWU_MDATA, + .of_match = fwu_mdata_ids, + .ops = &fwu_mtd_ops, + .probe = fwu_mdata_mtd_probe, + .of_to_plat = fwu_mdata_mtd_of_to_plat, + .priv_auto = sizeof(struct fwu_mdata_mtd_priv), +}; From patchwork Fri Jul 22 17:43:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 592480 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp710956mab; Fri, 22 Jul 2022 10:44:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vfUXv4x5i+WDEPEaDqq4EtetHFVQsQd6YNYkzSyonerLc3WuJuIdu1hLP2AGgeWApVAtwb X-Received: by 2002:a05:6638:ecd:b0:33f:32d5:469c with SMTP id q13-20020a0566380ecd00b0033f32d5469cmr492940jas.222.1658511870236; Fri, 22 Jul 2022 10:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658511870; cv=none; d=google.com; s=arc-20160816; b=bo4uviNOg9tB1hIDlc6EbiyyJ0K6Mb/LYhJXCb4Lun1hpnbX1n/8PwGpdiEeeXI84d +exFLCULdVEwtk/nHAXZRDyzL0veBjRVbasYtm/S66kaYq6APYZY7u0kUc86bJE6fmnj N24zjAvQlFuIPsEc0R84I9O010N+uopxw4cvCaiGIxGoLJiDF+xD8pMEyjr+D059Dz/D 3PayAQE92TbegeyzgLOMMiNxxVhvZgZCfW+DJ2kZ/RO4+QsZgfDl6EjIWE/n3aDukZx8 Nty0zZOdbVwPWhVU6DSeHlnhhv4dIWOPGOOU2WVA+V0koahG9501UjymftqrmOpvXr4L /3ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f9jYYazshQqA12WmGyKaOAtWiR4EbzujmcP7AuvT46I=; b=wRQrCGv5jHkn8sv7UTVWDyEmYvAOBSebfuHJC9WWt7OEoA1R7gAt1P8ctBJlwD7QxL bvs7zmz3J9QDLLUV+nas9ubkTCwgTtM+7YlpAxayjyxmcTNEz3bYaPpwhRR9wGdEkoxu dDpXiw064wGabbAkPD2ENawOb7AimvBAmrBVA3WecLFYJGxnexXU34PhZ1kTsr+6ofH7 Eg0V7nFw1/H+wffcqmN6Kl18bDo8FHhHJQouTByCNsFYpvxN0NkJJFGDRGlT/rLFLrfN tytK9CMoSRqK074xioXhQj2n82Uhky3CCfXGOsblCd/ky1ukZyPpMLZgUNA1wFhViZd/ H+cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DK7FvD0A; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id t21-20020a026415000000b0033f351f2854si3892177jac.75.2022.07.22.10.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:44:30 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DK7FvD0A; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2C0E5840CB; Fri, 22 Jul 2022 19:44:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DK7FvD0A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6A1AC8410A; Fri, 22 Jul 2022 19:44:18 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 203E283FCA for ; Fri, 22 Jul 2022 19:44:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-io1-xd32.google.com with SMTP id y197so3322312iof.12 for ; Fri, 22 Jul 2022 10:44:10 -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=f9jYYazshQqA12WmGyKaOAtWiR4EbzujmcP7AuvT46I=; b=DK7FvD0AYbkSuC3B6U23asdEOgDyorQIgN6obAlD9US/qX/IQCK34imKawx0J4zCsv HCF+PEFDx0b/LsvBylhnLgUP5FDwRPBzs0eXysqncBL/rXYxVtKI4jn+Jx1wFK81irKE iq6GXGq5m0ac/YOK+3wdAZXHgRF9Mi0PHxBRTBnaBhJzR+VK9K6Mq5u8otwygyqPFTJX h9qFTVUzLy/LnM6BVcSA5jQcJO3pP/jfb0yLA/p+9lrhSdYlTGLuK/uErWPg1d+764Jm Q/Kk86imVZGgAXPw1IvXqwU3QshYRdiOegj4amneU0iEPmotmB8OROps9a6dvOEhJcGk 12Rg== 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=f9jYYazshQqA12WmGyKaOAtWiR4EbzujmcP7AuvT46I=; b=yxOsEjlBN5oTXUvG+mjIJ15D07LMX0wneL/PfE8yG5ZKMg4Lw76IND9l8gLugehQv8 xvpzuMpqYP5wK99c/xVHQPjCoCyiWvvzHACXgeB9MNtEopUrgxMo82tFI3RCY8DYtB3k +pgJyAHRkTdSxCLSLs89qzRlx3RjHvV80kvq3J/Vjj6uD24lM3W9oHMDS5xf+E3Un6dQ GGTi2P5n1Vc4d1XocgGD0yA99OZVHKWKuaidbIlJfQjZo9OlhFC+cUpdTFvYTq+P+kv9 wbD0l8/rpDjS9N+/Armf/qggxnF/VqkGrP0WpCLG5q0kKLtDcMfDEjb/CKuJT+2v91tp qDwg== X-Gm-Message-State: AJIora9MPBhFw2R81dW8tVjtgdl8QfLscDwsEsrHWttcVfOGyti0+scF Jp4zFUCx7vdrj9apyuUSjhRf9lIZgC4= X-Received: by 2002:a05:6638:38aa:b0:341:95dd:db30 with SMTP id b42-20020a05663838aa00b0034195dddb30mr542976jav.145.1658511848294; Fri, 22 Jul 2022 10:44:08 -0700 (PDT) Received: from localhost.localdomain (wnpgmb0311w-ds01-179-115.dynamic.bellmts.net. [206.45.179.115]) by smtp.gmail.com with ESMTPSA id s26-20020a02c51a000000b00339eedc7840sm2242348jam.94.2022.07.22.10.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:44:07 -0700 (PDT) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de Cc: xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, takahiro.akashi@linaro.org, patrick.delaunay@foss.st.com, patrice.chotard@foss.st.com, sjg@chromium.org, bmeng.cn@gmail.com, trini@konsulko.com, etienne.carriere@linaro.org, monstr@monstr.eu, Sughosh Ganu , Jassi Brar Subject: [PATCH 3/5] FWU: mtd: Add helper functions for accessing FWU metadata Date: Fri, 22 Jul 2022 12:43:17 -0500 Message-Id: <20220722174319.64006-4-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220722174319.64006-1-jassisinghbrar@gmail.com> References: <20220722174240.63935-1-jassisinghbrar@gmail.com> <20220722174319.64006-1-jassisinghbrar@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Sughosh Ganu Add helper functions needed for accessing the FWU metadata which contains information on the updatable images. Signed-off-by: Sughosh Ganu Signed-off-by: Jassi Brar --- lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 lib/fwu_updates/fwu_mtd.c diff --git a/lib/fwu_updates/Makefile b/lib/fwu_updates/Makefile index 1993088e5b..c9e3c06b48 100644 --- a/lib/fwu_updates/Makefile +++ b/lib/fwu_updates/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_gpt.o +obj-$(CONFIG_FWU_MDATA_MTD) += fwu_mtd.o diff --git a/lib/fwu_updates/fwu_mtd.c b/lib/fwu_updates/fwu_mtd.c new file mode 100644 index 0000000000..f13cb149a2 --- /dev/null +++ b/lib/fwu_updates/fwu_mtd.c @@ -0,0 +1,173 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +int mtd_plat_get_alt_num(efi_guid_t *image_id, int *alt_num, + const char *mtd_dev, bool guid) +{ + int i, nalt; + int ret = -1; + struct mtd_info *mtd; + struct dfu_entity *dfu; + ofnode node, parts_node; + fdt_addr_t offset, size; + char uuidbuf[UUID_STR_LEN + 1]; + + mtd_probe_devices(); + mtd = get_mtd_device_nm(mtd_dev); + + /* Find partition node under given MTD device. */ + parts_node = ofnode_by_compatible(mtd_get_ofnode(mtd), + "fixed-partitions"); + + uuid_bin_to_str(image_id->b, uuidbuf, + guid ? UUID_STR_FORMAT_GUID : UUID_STR_FORMAT_STD); + node = ofnode_by_prop_value(parts_node, "uuid", uuidbuf, + sizeof(uuidbuf)); + if (!ofnode_valid(node)) { + log_warning("Warning: Failed to find partition by image UUID\n"); + return -ENOENT; + } + + offset = ofnode_get_addr_size_index_notrans(node, 0, &size); + if (offset == FDT_ADDR_T_NONE || !size) + return -ENOENT; + + dfu_init_env_entities(NULL, NULL); + + nalt = 0; + list_for_each_entry(dfu, &dfu_list, list) { + nalt++; + } + + if (!nalt) { + log_warning("No entities in dfu_alt_info\n"); + dfu_free_entities(); + return -ENOENT; + } + + for (i = 0; i < nalt; i++) { + dfu = dfu_get_entity(i); + + if (!dfu) + continue; + + if (dfu->dev_type != DFU_DEV_MTD) + continue; + + if (dfu->layout == DFU_RAW_ADDR && + dfu->data.mtd.start == offset && + dfu->data.mtd.size == size) { + *alt_num = dfu->alt; + ret = 0; + break; + } + } + + dfu_free_entities(); + + return ret; +} + +int gen_image_alt_info(char *buf, size_t len, int sidx, + struct fwu_image_entry *img, struct mtd_info *mtd) +{ + int i; + const char *suuid; + ofnode node, parts_node; + char uuidbuf[UUID_STR_LEN + 1]; + char *p = buf, *end = buf + len; + + /* Find partition node under given MTD device. */ + parts_node = ofnode_by_compatible(mtd_get_ofnode(mtd), + "fixed-partitions"); + if (!ofnode_valid(parts_node)) + return -ENOENT; + + /* Check the media UUID if exist. */ + suuid = ofnode_read_string(parts_node, "uuid"); + if (suuid) { + log_debug("Get location uuid %s\n", suuid); + uuid_bin_to_str(img->location_uuid.b, uuidbuf, + UUID_STR_FORMAT_STD); + if (strcasecmp(suuid, uuidbuf)) + log_warning("Warning: Location UUID does not match!\n"); + } + + p += snprintf(p, end - p, "mtd %s", mtd->name); + if (end < p) + return -E2BIG; + + /* + * List up the image banks in the FWU mdata and search the corresponding + * partition based on partition's uuid. + */ + for (i = 0; i < CONFIG_FWU_NUM_BANKS; i++) { + struct fwu_image_bank_info *bank; + fdt_addr_t offset, size; + + /* Query a partition by image UUID */ + bank = &img->img_bank_info[i]; + uuid_bin_to_str(bank->image_uuid.b, uuidbuf, + UUID_STR_FORMAT_STD); + node = ofnode_by_prop_value(parts_node, "uuid", uuidbuf, + sizeof(uuidbuf)); + if (!ofnode_valid(node)) { + log_warning("Warning: Failed to find partition by image UUID\n"); + break; + } + + offset = ofnode_get_addr_size_index_notrans(node, 0, &size); + if (offset == FDT_ADDR_T_NONE || !size) + break; + + p += snprintf(p, end - p, "%sbank%d raw %lx %lx", + i == 0 ? "=" : ";", i, (unsigned long)offset, + (unsigned long)size); + if (end < p) + return -E2BIG; + } + + return i != CONFIG_FWU_NUM_BANKS ? -ENOENT : 0; +} + +int fwu_gen_alt_info_from_mtd(char *buf, size_t len, struct mtd_info *mtd) +{ + struct fwu_mdata *mdata = NULL; + int i, l, ret; + + ret = fwu_get_mdata(&mdata); + if (ret < 0) { + log_debug("Failed to get the FWU mdata.\n"); + return ret; + } + + for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) { + ret = gen_image_alt_info(buf, len, i * CONFIG_FWU_NUM_BANKS, + &mdata->img_entry[i], mtd); + if (ret) + break; + l = strlen(buf); + /* Replace the last ';' with '&' if there is another image. */ + if (i != CONFIG_FWU_NUM_IMAGES_PER_BANK - 1 && l) + buf[l - 1] = '&'; + len -= l; + buf += l; + } + + free(mdata); + + return ret; +} From patchwork Fri Jul 22 17:43:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 592481 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp711079mab; Fri, 22 Jul 2022 10:44:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vA61djIn3QN4gRsQgcauvMMt3hyX0PCLEuGeh38/VZhTQBYF6Uiu7S09opESEWjXosCcdH X-Received: by 2002:a05:6638:dd1:b0:341:55c2:38b6 with SMTP id m17-20020a0566380dd100b0034155c238b6mr537523jaj.245.1658511881033; Fri, 22 Jul 2022 10:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658511881; cv=none; d=google.com; s=arc-20160816; b=D6T81QLSG16D+XZOQHC6ff31H/aJWcGe4ime3mkjUEu4qrnW+wskgXDEXxg0789PLJ inykeRHEhjTcDepWcLP9ujUBrGEoCFXahxNfEILRlaOEqYNFN+vhyXJ1ZcwOEvo0sAU1 1qLi3PmHYPPkgh0px5RwKZJUXyO0ev1uyVDmW4buCjguvbPQlBwz0XLCgryNDUWtBioX wD3SsqPMVd/Su5PwQicMH9WyBbv8KlT1epgx4QpLz2SxijYddqhDPWq92b+65XR7L1ag Q8llFRf9Y3BoC7IgHAIHmiogubH2iWHm0GeZ/aq2PTZXoIbDtJJsK+XUwewERM/+hsiz bujw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lmQqVx6EVDCL+Zesf7VuDeCxJ6UTU7RyQNgyN2hXD1Q=; b=xy8/fHlkcOL8u1hrP1R/sABGjz0yUCWYyMnAQpR8N/gBGaqBIQoPZ+5wvyPYPCNR5W ferDCJ/3N6Zgnv2cYQJKxEVoioQWvIB5Fvwgi0z0QncHFoJ2OxbatmD8/iWJ/UugDuxO UgigAKE1KAAEku4G7X+Cg3sOgN9Bu0gMptHROm8m86A8uDg8vmmghVxqp6la2K8gKn1j 5diVsgwdULBrrzF3sLtrrnz5+JJhe6apry/L7Hjm0Hv524TfEruiz8n42PTFYjYEjezT Ht0hfG5sMG2VqelZ6P3ZkwgPRi7Nnl0TmLNTYH4XWFxp4yt7j9ayYZOUZB0a7TJpkIlO mvcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Oe8dlrN+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id m26-20020a026a5a000000b003403cc95d86si4015983jaf.67.2022.07.22.10.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:44:41 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Oe8dlrN+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4FBBC83FC2; Fri, 22 Jul 2022 19:44:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Oe8dlrN+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A375884039; Fri, 22 Jul 2022 19:44:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2D89C840FE for ; Fri, 22 Jul 2022 19:44:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-io1-xd35.google.com with SMTP id n7so4155754ioo.7 for ; Fri, 22 Jul 2022 10:44:15 -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=lmQqVx6EVDCL+Zesf7VuDeCxJ6UTU7RyQNgyN2hXD1Q=; b=Oe8dlrN+fuLmGjjWDEHhXaDswxu+zAMFAiwY0TBLIuXVcyBt6F5KcEXBXLXo5IXWYe oNB1wm7Z+1Le6GpttJvY0vg3ywbWTdU5f7ZEgGu2qF2Ej2WGfNiIGVI3GcMjiLpI7jfQ ScA9pgKb6LbUv72ncs1qK5dXaoxvqAf2X5V7i9gQGDkVksePu7lgp8YiGlA5VCod3ddv CDd+7opYIX3AprEWFHQEnrixJsjHlt+eRO4izm0kPK3S0NT5Ma8myqe0xQdXt6A0n3Fg gjPo6TdiznkoIocCzux3sosZgou5kb6Q9Zewh/gYs2uZavivUL5bFk9Ii4UYmbDiMMiy BmIw== 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=lmQqVx6EVDCL+Zesf7VuDeCxJ6UTU7RyQNgyN2hXD1Q=; b=MTgG5F65bKrGVBodaYdYhUmbUCYTpLxg9RWQ+BX3tyKzVir5ckh0HvZ2GemjcaH8id TcKP1AFHLtB3AISCOYJct41PFLMX48Y4D1vVVbvgKcFYvghQ+aXD2ydQ7IJKaLA71RV0 TRfsrof6utnE+2YkC3pfJLh/1RBfRDOS5ARqz4Xx8PL0BZ4E8zSHDqJboKtxA9EY9gl8 POJG3v2r7pryKh5dnMMcjd9kwqDYsvAqCGjQMGPnOgKjSFlKxLVlyxeICkHJWwsc2epQ 1glDDqcDqHsZ1XY28pbS2H2T6kLAV2G0APyc9ikm0yBL5m6xzA1YEXyXz4uQ6TRgup4t q7Rg== X-Gm-Message-State: AJIora/LqN5Dy51T1EPQI/flhNj1zXycU2Xr9nEt4qZXT9At8pAXotzh uZR75F125lnT2Q/Iv21ywAlKvfoJMtA= X-Received: by 2002:a02:1607:0:b0:33f:3af8:61e3 with SMTP id a7-20020a021607000000b0033f3af861e3mr521095jaa.307.1658511854364; Fri, 22 Jul 2022 10:44:14 -0700 (PDT) Received: from localhost.localdomain (wnpgmb0311w-ds01-179-115.dynamic.bellmts.net. [206.45.179.115]) by smtp.gmail.com with ESMTPSA id s26-20020a02c51a000000b00339eedc7840sm2242348jam.94.2022.07.22.10.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:44:13 -0700 (PDT) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de Cc: xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, takahiro.akashi@linaro.org, patrick.delaunay@foss.st.com, patrice.chotard@foss.st.com, sjg@chromium.org, bmeng.cn@gmail.com, trini@konsulko.com, etienne.carriere@linaro.org, monstr@monstr.eu, Jassi Brar , Masami Hiramatsu Subject: [PATCH 4/5] dt: fwu: developerbox: enable fwu banks and mdata regions Date: Fri, 22 Jul 2022 12:43:18 -0500 Message-Id: <20220722174319.64006-5-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220722174319.64006-1-jassisinghbrar@gmail.com> References: <20220722174240.63935-1-jassisinghbrar@gmail.com> <20220722174319.64006-1-jassisinghbrar@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Jassi Brar specify Bank-0/1 and fwu metadata mtd regions. Signed-off-by: Masami Hiramatsu Signed-off-by: Jassi Brar --- .../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi index 7a56116d6f..62eee0aaf0 100644 --- a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi +++ b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi @@ -23,7 +23,7 @@ active_clk_edges; chipselect_num = <1>; - spi-flash@0 { + spi_flash: spi-flash@0 { #address-cells = <1>; #size-cells = <1>; compatible = "jedec,spi-nor"; @@ -36,6 +36,7 @@ compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; + uuid = "17e86d77-41f9-4fd7-87ec-a55df9842de5"; partition@0 { label = "BootStrap-BL1"; @@ -79,6 +80,19 @@ label = "Ex-OPTEE"; reg = <0x500000 0x200000>; }; + + /* FWU Multi bank update partitions */ + partition@600000 { + label = "FIP-Bank0"; + reg = <0x600000 0x400000>; + uuid = "5a66a702-99fd-4fef-a392-c26e261a2828"; + }; + + partition@a00000 { + label = "FIP-Bank1"; + reg = <0xa00000 0x400000>; + uuid = "a8f868a1-6e5c-4757-878d-ce63375ef2c0"; + }; }; }; }; @@ -104,6 +118,12 @@ optee { status = "okay"; }; + + fwu-mdata { + compatible = "u-boot,fwu-mdata-mtd"; + fwu-mdata-store = <&spi_flash>; + mdata-offsets = <0x500000 0x530000>; + }; }; }; From patchwork Fri Jul 22 17:43:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 592482 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp711207mab; Fri, 22 Jul 2022 10:44:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1voE7zGXgLz9XG9h2+Ob0reaRw9P7Ph41oESckUFMPe13IDA4m0DPysxV5sil6/PrBtwL4Q X-Received: by 2002:a05:6e02:10d2:b0:2dd:182d:d59e with SMTP id s18-20020a056e0210d200b002dd182dd59emr460457ilj.111.1658511892622; Fri, 22 Jul 2022 10:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658511892; cv=none; d=google.com; s=arc-20160816; b=csjgJ7LsMxtqFZ3FxUctsa4IxBLJoBy50LFKOkYCnj5OcNXzPlWuUwr02kTPn1UO0V w/wC6aCT+dd7UknoaD9XI+XELXpTCBIqU3eGVwSBJSzvM96z2zd5USHe/hNqy7fK58Cf Shx4Wy2SzvCx+XvxV4pfWT0t6B9BM4FpY2LIBS3OCk6L9ylMe1FiN7XkNeryqs6eSGMy uUxfvdCWFOL9ud0lU2qDi45ucZIWnjWq96cZ053dvaW9KRnMpX+lq4vGUIH7IVv4p6oD U6jHunactBxGNnd+xIH5/Yde2stn+myPJZQ8q4MDGXcDwaXwYCOD3EoPj3bf5/rXiKqr yOLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xWHxLNcSsM/NkdjxiHEjmtei20eMXaWS1Jeu4Sbfms8=; b=HZ2JmtE1GAnbyI5HWGt77Eu0366fPN1chQLv32tDCLQl70a9odl3FWtZHiAgq9qnqu 3MkRVuCscbw0V8bo8L5oSEqAhnVrYcwGexl+C2Qb3CQkyW6tyK5X75u/jNgZFSgGfMBT lagdYBIJP2LCT78aGdlT2t6C2Sq7QATLTXkV92ipj6m19Re32MdcatS1S96NBL8+xQAn RKmPRFn6oqEBvMupBUgsDnNC7yE2f4rx+VuNO9NCnfBTSh5I5ahmBkyHSme9H9CIZO2W 6EH/pVKvuzVKCeGxinkRCB+Sisuv9z4MzTmbccf58bwtpbdofz62eJ4gStVXZI0gPPd7 raLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FDOQYq6E; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id k7-20020a5e9307000000b00678ec535ce4si3377217iom.13.2022.07.22.10.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:44:52 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FDOQYq6E; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6E95C840A6; Fri, 22 Jul 2022 19:44:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FDOQYq6E"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 04EF983AC3; Fri, 22 Jul 2022 19:44:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E585B84084 for ; Fri, 22 Jul 2022 19:44:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-il1-x136.google.com with SMTP id y13so2554071ilv.5 for ; Fri, 22 Jul 2022 10:44:21 -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=xWHxLNcSsM/NkdjxiHEjmtei20eMXaWS1Jeu4Sbfms8=; b=FDOQYq6E0h/HiEguZ1KnEDe6sYQ6D9Ic1HkAbyvccOGXIbd6iZTBYWcPitanQ2eLM1 SnJg2I6INDp3uq3h4SHQZuQYBnY38W1JjXC3V3jotD+66V9I/eOFCoFAIXOyf5SkakW4 QwxuW5aPHsKyfNmCnoFt8Ai6hawH3GeSxtrxfXY3rsQi5QZwvcI6HkYeurBhPq/nyL0m xUKxN8+M95jBVx7Tth6Jb72dgi7LrC1bztU3cEY0FjUwcdYM2NzK4ofw9AuMj6v7EHFI PCGn9lJc8/1dNMZhB4esaxCPlQrskUEcolwhCWrQB/lH8E3azomPZ903UTJCLFgNGPU7 nHxg== 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=xWHxLNcSsM/NkdjxiHEjmtei20eMXaWS1Jeu4Sbfms8=; b=TsTVVr9WVMqnVdGbnGokgsp3T7BXQon5MPrpSgrkSB5eFFU/JJawky8Yq5wC4pNk5A EPjejnD4fGN0VEqXIt0itLR41cgE4Z84Yd3sCNIPnVc24L64zlVt3WzcOZXdhcDX1FhF lPhAs81veecKNXh1Da7ydkOlzT+6bkctfNVFaCB/apaKVhO/5anIzgc/l1D8+BQ+dakt njRme96DEPnvBsr1fDX5asrJu9TBMb8YvLO84d3VF7h8gZg3oMJrzofaJhHcd4Xkoq4G /1CczZ7tfdT0bsVh50ccD9UPGBDH4+UPxfV4+kzs5sqoxQo+abFUumxXxmfoIWEadm61 BPMA== X-Gm-Message-State: AJIora8dB8BmgeKro97Tx4gvYcC6d7AzOUnZjUQ6KHIeT2OI1YjBfPdf VanKjMrm7bmuhvTHZtgGHBGuO5AcZes= X-Received: by 2002:a05:6e02:1c89:b0:2dc:7f32:793b with SMTP id w9-20020a056e021c8900b002dc7f32793bmr453617ill.189.1658511860016; Fri, 22 Jul 2022 10:44:20 -0700 (PDT) Received: from localhost.localdomain (wnpgmb0311w-ds01-179-115.dynamic.bellmts.net. [206.45.179.115]) by smtp.gmail.com with ESMTPSA id s26-20020a02c51a000000b00339eedc7840sm2242348jam.94.2022.07.22.10.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 10:44:19 -0700 (PDT) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de Cc: xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, takahiro.akashi@linaro.org, patrick.delaunay@foss.st.com, patrice.chotard@foss.st.com, sjg@chromium.org, bmeng.cn@gmail.com, trini@konsulko.com, etienne.carriere@linaro.org, monstr@monstr.eu, Jassi Brar , Masami Hiramatsu Subject: [PATCH 5/5] fwu: DeveloperBox: add support for FWU Date: Fri, 22 Jul 2022 12:43:19 -0500 Message-Id: <20220722174319.64006-6-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220722174319.64006-1-jassisinghbrar@gmail.com> References: <20220722174240.63935-1-jassisinghbrar@gmail.com> <20220722174319.64006-1-jassisinghbrar@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Jassi Brar Add code to support FWU_MULTI_BANK_UPDATE. The platform does not have gpt-partition storage for Banks and MetaData, rather it used SPI-NOR backed mtd regions for the purpose. Signed-off-by: Masami Hiramatsu Signed-off-by: Jassi Brar --- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 13 +++ board/socionext/developerbox/fwu_plat.c | 95 ++++++++++++++++++++ configs/synquacer_developerbox_defconfig | 13 ++- doc/board/socionext/developerbox.rst | 96 +++++++++++++++++++++ include/configs/synquacer.h | 10 +++ 6 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 board/socionext/developerbox/fwu_plat.c diff --git a/board/socionext/developerbox/Makefile b/board/socionext/developerbox/Makefile index 4a46de995a..9b80ee38e7 100644 --- a/board/socionext/developerbox/Makefile +++ b/board/socionext/developerbox/Makefile @@ -7,3 +7,4 @@ # obj-y := developerbox.o +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_plat.o diff --git a/board/socionext/developerbox/developerbox.c b/board/socionext/developerbox/developerbox.c index f5a5fe0121..ad2260e3d7 100644 --- a/board/socionext/developerbox/developerbox.c +++ b/board/socionext/developerbox/developerbox.c @@ -20,6 +20,13 @@ #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) struct efi_fw_image fw_images[] = { +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE) + { + .image_type_id = DEVELOPERBOX_FIP_IMAGE_GUID, + .fw_name = u"DEVELOPERBOX-FIP", + .image_index = 1, + }, +#else { .image_type_id = DEVELOPERBOX_UBOOT_IMAGE_GUID, .fw_name = u"DEVELOPERBOX-UBOOT", @@ -35,12 +42,18 @@ struct efi_fw_image fw_images[] = { .fw_name = u"DEVELOPERBOX-OPTEE", .image_index = 3, }, +#endif }; struct efi_capsule_update_info update_info = { +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE) + .dfu_string = "mtd nor1=bank0 raw 600000 400000;" + "bank1 raw a00000 400000;", +#else .dfu_string = "mtd nor1=u-boot.bin raw 200000 100000;" "fip.bin raw 180000 78000;" "optee.bin raw 500000 100000", +#endif .images = fw_images, }; diff --git a/board/socionext/developerbox/fwu_plat.c b/board/socionext/developerbox/fwu_plat.c new file mode 100644 index 0000000000..9fb5cb28b3 --- /dev/null +++ b/board/socionext/developerbox/fwu_plat.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define DFU_ALT_BUF_LEN 256 +#define DFU_ALT_NUM_MAX (CONFIG_FWU_NUM_IMAGES_PER_BANK * CONFIG_FWU_NUM_BANKS) + +/* Generate dfu_alt_info from partitions */ +void set_dfu_alt_info(char *interface, char *devstr) +{ + int ret; + struct mtd_info *mtd; + static char *buf = NULL; + + if (!buf) { + buf = malloc_cache_aligned(DFU_ALT_BUF_LEN); + memset(buf, 0, DFU_ALT_BUF_LEN); + + mtd_probe_devices(); + + mtd = get_mtd_device_nm("nor1"); + if (IS_ERR_OR_NULL(mtd)) + return; + + ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd); + if (ret < 0) { + log_err("Error: Failed to generate dfu_alt_info. (%d)\n", ret); + return; + } + log_debug("Make dfu_alt_info: '%s'\n", buf); + } + env_set("dfu_alt_info", buf); +} + +int fwu_plat_get_alt_num(struct udevice __always_unused *dev, + efi_guid_t *image_id, int *alt_num) +{ + return mtd_plat_get_alt_num(image_id, alt_num, "nor1", 0); +} + +int fwu_plat_get_update_index(u32 *update_idx) +{ + int ret; + u32 active_idx; + + ret = fwu_get_active_index(&active_idx); + + if (ret < 0) + return ret; + + *update_idx = 1 - active_idx; + + return ret; +} + +void fwu_plat_get_bootidx(void *boot_idx) +{ + int ret; + u32 active_idx; + u32 *bootidx = boot_idx; + + ret = fwu_get_active_index(&active_idx); + + if (ret < 0) + *bootidx = -1; + + *bootidx = active_idx; +} + +int board_late_init(void) +{ + /* Make mmc available for EFI, otherwise efi subsystem + * complains "No EFI system partition" during bootup. + */ + run_command("mmc dev 0", 0); + + return 0; +} diff --git a/configs/synquacer_developerbox_defconfig b/configs/synquacer_developerbox_defconfig index add6041e27..ded31ada6e 100644 --- a/configs/synquacer_developerbox_defconfig +++ b/configs/synquacer_developerbox_defconfig @@ -1,10 +1,11 @@ CONFIG_ARM=y CONFIG_ARCH_SYNQUACER=y -CONFIG_SYS_TEXT_BASE=0x08200000 +CONFIG_POSITION_INDEPENDENT=y +CONFIG_SYS_TEXT_BASE=0 CONFIG_SYS_MALLOC_LEN=0x1000000 CONFIG_SYS_MALLOC_F_LEN=0x400 CONFIG_ENV_SIZE=0x30000 -CONFIG_ENV_OFFSET=0x300000 +CONFIG_ENV_OFFSET=0x580000 CONFIG_ENV_SECT_SIZE=0x10000 CONFIG_DM_GPIO=y CONFIG_DEFAULT_DEVICE_TREE="synquacer-sc2a11-developerbox" @@ -93,3 +94,11 @@ CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y CONFIG_EFI_CAPSULE_ON_DISK=y CONFIG_EFI_IGNORE_OSINDICATIONS=y CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y +CONFIG_EFI_SECURE_BOOT=y +CONFIG_BOARD_LATE_INIT=y +CONFIG_FWU_MULTI_BANK_UPDATE=y +CONFIG_DM_FWU_MDATA=y +CONFIG_FWU_MDATA_MTD=y +CONFIG_FWU_NUM_BANKS=2 +CONFIG_FWU_NUM_IMAGES_PER_BANK=1 +CONFIG_CMD_FWU_METADATA=y diff --git a/doc/board/socionext/developerbox.rst b/doc/board/socionext/developerbox.rst index 2d943c23be..f52820c2b0 100644 --- a/doc/board/socionext/developerbox.rst +++ b/doc/board/socionext/developerbox.rst @@ -85,3 +85,99 @@ Once the flasher tool is running we are ready flash the UEFI image:: After transferring the SPI_NOR_UBOOT.fd, turn off the DSW2-7 and reset the board. + +Enable FWU Multi Bank Update +============================ + +DeveloperBox supports the FWU Multi Bank Update. You *MUST* update both *SCP firmware* and *TF-A* for this feature. This will change the layout and the boot process but you can switch back to the normal one by changing the DSW 1-4 off. + +Configure U-Boot +---------------- + +To enable the FWU Multi Bank Update on the DeveloperBox, you need to add following configurations to configs/synquacer_developerbox_defconfig :: + + CONFIG_FWU_MULTI_BANK_UPDATE=y + CONFIG_DM_FWU_MDATA=y + CONFIG_FWU_MDATA_MTD=y + CONFIG_FWU_NUM_BANKS=2 + CONFIG_FWU_NUM_IMAGES_PER_BANK=1 + CONFIG_CMD_FWU_METADATA=y + +And build it:: + + cd u-boot/ + export ARCH=arm64 + export CROSS_COMPILE=aarch64-linux-gnu- + make synqucer_developerbox_defconfig + make -j `noproc` + cd ../ + +By default, the CONFIG_FWU_NUM_BANKS and COFNIG_FWU_NUM_IMAGES_PER_BANKS are set to 2 and 1 respectively. This uses FIP (Firmware Image Package) type image which contains TF-A, U-Boot and OP-TEE (the OP-TEE is optional.) +You can use fiptool to compose the FIP image from those firmware images. + +Rebuild SCP firmware +-------------------- + +Rebuild SCP firmware which supports FWU Multi Bank Update as below:: + + cd SCP-firmware/ + OUT=./build/product/synquacer + ROMFW_FILE=$OUT/scp_romfw/$SCP_BUILD_MODE/bin/scp_romfw.bin + RAMFW_FILE=$OUT/scp_ramfw/$SCP_BUILD_MODE/bin/scp_ramfw.bin + ROMRAMFW_FILE=scp_romramfw_release.bin + + make CC=$ARM_EMB_GCC PRODUCT=synquacer MODE=release + tr "\000" "\377" < /dev/zero | dd of=${ROMRAMFW_FILE} bs=1 count=196608 + dd if=${ROMFW_FILE} of=${ROMRAMFW_FILE} bs=1 conv=notrunc seek=0 + dd if=${RAMFW_FILE} of=${ROMRAMFW_FILE} bs=1 seek=65536 + cd ../ + +And you can get the `scp_romramfw_release.bin` file + +Rebuild TF-A and FIP +-------------------- + +Rebuild TF-A which supports FWU Multi Bank Update as below:: + + cd arm-trusted-firmware/ + make CROSS_COMPILE=aarch64-linux-gnu- -j`nproc` PLAT=synquacer \ + SPD=opteed SQ_RESET_TO_BL2=1 GENERATE_COT=1 MBEDTLS_DIR=../mbedtls \ + BL33=../u-boot/u-boot.bin all fip fiptool + +And make a FIP image.:: + + cp build/synquacer/release/fip.bin SPI_NOR_NEWFIP.fd + tools/fiptool/fiptool update --tb-fw build/synquacer/release/bl2.bin SPI_NOR_NEWFIP.fd + + +UUIDs for the FWU Multi Bank Update +----------------------------------- + +FWU multi-bank update requires some UUIDs. The DeveloperBox platform uses following UUIDs. + + - Location UUID for the FIP image: 17e86d77-41f9-4fd7-87ec-a55df9842de5 + - Image type UUID for the FIP image: 10c36d7d-ca52-b843-b7b9-f9d6c501d108 + - Image UUID for Bank0 : 5a66a702-99fd-4fef-a392-c26e261a2828 + - Image UUID for Bank1 : a8f868a1-6e5c-4757-878d-ce63375ef2c0 + +These UUIDs are used for making a FWU metadata image. + +Install via flash writer +------------------------ + +As explained in above section, the new FIP image and the FWU metadata image can be installed via NOR flash writer. Note that the installation offsets for the FWU multi bank update supported firmware. + +Once the flasher tool is running we are ready flash the images.:: +Write the FIP image to the 0x600000 offset.:: + + flash rawwrite 600000 180000 + >> Send SPI_NOR_NEWFIP.fd via XMODEM (Control-A S in minicom) << + +And write the new SCP firmware.:: + + flash write cm3 + >> Send scp_romramfw_release.bin via XMODEM (Control-A S in minicom) << + +At last, turn on the DSW 3-4 on the board, and reboot. +Note that if DSW 3-4 is turned off, the DeveloperBox will boot from +the original EDK2 firmware (or non-FWU U-Boot if you already installed.) diff --git a/include/configs/synquacer.h b/include/configs/synquacer.h index 5686a5b910..7995be852d 100644 --- a/include/configs/synquacer.h +++ b/include/configs/synquacer.h @@ -46,19 +46,29 @@ /* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIO support */ +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEFAULT_DFU_ALT_INFO +#else #define DEFAULT_DFU_ALT_INFO "dfu_alt_info=" \ "mtd nor1=u-boot.bin raw 200000 100000;" \ "fip.bin raw 180000 78000;" \ "optee.bin raw 500000 100000\0" +#endif /* GUIDs for capsule updatable firmware images */ #define DEVELOPERBOX_UBOOT_IMAGE_GUID \ EFI_GUID(0x53a92e83, 0x4ef4, 0x473a, 0x8b, 0x0d, \ 0xb5, 0xd8, 0xc7, 0xb2, 0xd6, 0x00) +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEVELOPERBOX_FIP_IMAGE_GUID \ + EFI_GUID(0x7d6dc310, 0x52ca, 0x43b8, 0xb7, 0xb9, \ + 0xf9, 0xd6, 0xc5, 0x01, 0xd1, 0x08) +#else #define DEVELOPERBOX_FIP_IMAGE_GUID \ EFI_GUID(0x880866e9, 0x84ba, 0x4793, 0xa9, 0x08, \ 0x33, 0xe0, 0xb9, 0x16, 0xf3, 0x98) +#endif #define DEVELOPERBOX_OPTEE_IMAGE_GUID \ EFI_GUID(0xc1b629f1, 0xce0e, 0x4894, 0x82, 0xbf, \