From patchwork Mon Feb 7 18:19:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 540568 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp344475imr; Mon, 7 Feb 2022 10:21:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/D3bJ+uKxKeU2LO8P8fps3ZThxJyqyM7uV1t7L9aMz2JbRk/NSA+xa+ifXXeTKplmNLyO X-Received: by 2002:aa7:d809:: with SMTP id v9mr783327edq.2.1644258098574; Mon, 07 Feb 2022 10:21:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644258098; cv=none; d=google.com; s=arc-20160816; b=nuE4Kmjyl9Ee+W6gQI+uDi65nvmgjptkizgS6vz+rksxj/b1nully26VzZdvv+oeI3 +ab+lcLoAon7mgO6aebKHEqJkm//HxLpVdtpYTs+K955h3bGcscSkuJtTLuu8/c0zNxn cdnW2uGx04RVYD+YveZJaFLBDaLrjPsUihZ4BWm2RrEV7VFccZPORjDvNv5e/j8Cf7AC WUNkOdPvR34TvhKSpYXWZSHh1izZlypB8foP3r75K+TUjycOuf/RODgVlvaocD19e829 U6ozoiQzOIo2jBNoFkWqlFVIsIbGEeHBxpTmvppxl2nkx/QPumx5O1dXvGIsmhzxhU7j Tdow== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=GIzSFaDYS/sfGikf2U9mio7aZjY+v5E+lRFxoj9XA+g=; b=UM5xB7DspUDrlXXGsb9fl1WeWAY1HrJD9X/pk7dDfYKtzd+KPCRO23gA8NKjyGpLoZ 2BkhC8HFMFuUKYsgxNtf76ThbUtHpRmHlZs2lj9s6DNe7KwW++1KtXd2x+E+sSMh3rJZ W9gSMLjE3EEive7W8mt7YbsHgkD0OjCZ6AeZYUWBGk25s9Q2gjl19ALNbzZXXjYPH/4U jLI+GlKXF5e9r9JtGwRRyuoMemXB+BLgy2uKYZeVZ2oOtv5GEJ1AQ4ELzwBMSQ9pEj1C 2ZOZe7o4GGhdsjNZics8LHbAEF07MoJLaWk+sffmOLPqi2BQebaOi/ZaS2rZGE2pOvpB IC5Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 y4si7868670ejk.541.2022.02.07.10.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 10:21:38 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 038A083BAD; Mon, 7 Feb 2022 19:21:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 647E9837E2; Mon, 7 Feb 2022 19:21:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 1C9A883B99 for ; Mon, 7 Feb 2022 19:21:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 941A811B3; Mon, 7 Feb 2022 10:21:14 -0800 (PST) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 92CCC3F718; Mon, 7 Feb 2022 10:21:10 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu Subject: [PATCH v4 03/11] FWU: stm32mp1: Add helper functions for accessing FWU metadata Date: Mon, 7 Feb 2022 23:49:53 +0530 Message-Id: <20220207182001.31270-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220207182001.31270-1-sughosh.ganu@linaro.org> References: <20220207182001.31270-1-sughosh.ganu@linaro.org> 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.5 at phobos.denx.de X-Virus-Status: Clean Add helper functions needed for accessing the FWU metadata which contains information on the updatable images. These functions have been added for the STM32MP157C-DK2 board which has the updatable images on the uSD card, formatted as GPT partitions. Signed-off-by: Sughosh Ganu --- Changes since V3: * Remove function for getting the storage device containing the metadata as the information is now obtained from the device tree. board/st/stm32mp1/stm32mp1.c | 78 ++++++++++++++++++++++++++++++++++++ include/fwu.h | 3 ++ 2 files changed, 81 insertions(+) diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 84592677e4..5e8cb29067 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -7,10 +7,13 @@ #include #include +#include #include #include #include +#include #include +#include #include #include #include @@ -23,9 +26,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -938,3 +943,76 @@ static void board_copro_image_process(ulong fw_image, size_t fw_size) } U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process); + +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE) +#include +#include + +static int gpt_plat_get_alt_num(int dev_num, void *identifier) +{ + int i; + int ret = -1; + u32 part; + int alt_num = dfu_get_alt_number(); + struct dfu_entity *dfu; + + part = *(u32 *)identifier; + dfu_init_env_entities(NULL, NULL); + + for (i = 0; i < alt_num; i++) { + dfu = dfu_get_entity(i); + + if (!dfu) + continue; + + /* + * Currently, Multi Bank update + * feature is being supported + * only on GPT partitioned + * MMC/SD devices. + */ + if (dfu->dev_type != DFU_DEV_MMC) + continue; + + if (dfu->layout == DFU_RAW_ADDR && + dfu->data.mmc.dev_num == dev_num && + dfu->data.mmc.part == part) { + ret = dfu->alt; + break; + } + } + + dfu_free_entities(); + + return ret; +} + +int fwu_plat_get_alt_num(struct udevice *dev, void *identifier) +{ + struct blk_desc *desc; + + desc = dev_get_uclass_plat(dev); + if (!desc) { + log_err("Block device not found\n"); + return -ENODEV; + } + + return gpt_plat_get_alt_num(desc->devnum, identifier); +} + +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 -1; + + *update_idx = active_idx ^= 0x1; + + return ret; +} + +#endif /* CONFIG_FWU_MULTI_BANK_UPDATE */ diff --git a/include/fwu.h b/include/fwu.h index 2c7db2dff9..b746e616b2 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -50,4 +50,7 @@ int fwu_revert_boot_index(void); int fwu_accept_image(efi_guid_t *img_type_id, u32 bank); int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank); +int fwu_plat_get_update_index(u32 *update_idx); +int fwu_plat_get_alt_num(struct udevice *dev, void *identifier); + #endif /* _FWU_H_ */