From patchwork Mon Feb 12 07:46:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 772026 Delivered-To: patch@linaro.org Received: by 2002:adf:9dca:0:b0:33b:4db1:f5b3 with SMTP id q10csp2000402wre; Sun, 11 Feb 2024 23:48:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1QHOJQOtojyFiU1NP2zDeYXC8hxoYgIHXClWianGZnWrhD5wvloTuTc+7RWvrjmaXD8P7 X-Received: by 2002:a17:906:aacc:b0:a3c:bad6:7685 with SMTP id kt12-20020a170906aacc00b00a3cbad67685mr638227ejb.46.1707724102023; Sun, 11 Feb 2024 23:48:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707724102; cv=none; d=google.com; s=arc-20160816; b=RfS4KLxt7du4xOXeZKs61xfT9DZunRM0Oek6hp94JullBuuLr4zzVnvvLgQCHM+9Qd inq/vWpYz5mgcngJee1GubRR/4Q5fvcj85PmhH9Cd7s5HasfgdybHlGUepS/kzHC4eJp 0emYjallRuTMjfq5ZFaFRuGLS9mQ/0guVKiLNWyFMfMzNmJijKAZSZsdEQ22qBD6+TfA u/m5CY8/hdpW8xzuBIEYhKDXBwyLRYK5rvW8ykVZiXW3VQeoFXdLf2I6i9d9rMtxJJj7 SOUeu1skcPk7GPYiOrFNxAS9ZaRFPpPEy8tc9Cw9zEt2+8e5z3M0wohY9IoFrs2qe1wl AHZg== 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; bh=mE9xITILK9rBql73I6O28FWnkhFNfNP8v+TXOTy789w=; fh=/6NQxHDn1PUPHDnUUo7f2dw9hTxjrHBua5wYRDWdiIg=; b=q5tEBoU33zNl/O7BqoAtmqTremU7ffFVi9zMjkXhKD/b9hJl0w/5O/KjClfSs7JtOu Z958Ih8s8QMxWRZPadBzJa0qQFLb2bZQrUaWmVUbhW2uAxmNQz3hL4vbDLzXXY1Q1LzZ RnfzFmLO/4bkGeRRt6UCCChZoNS+b9n3cBPvqJeotxPX0WZz6kbP3Jpx13MjtwxQXvQJ sk5+Uk5QSlQkkQLsaEhI/YrIPtSGoVDmp4WSu8Q3TNKLGgob+oNdXS34buupUMEFalpZ z++0VaXLiILxpmvV9QIQZgZS5GUCxNpS31gVTGROoD9pGyIj/ku7Zv2SRYrZqb1xDxkb fuHA==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=1; AJvYcCUIm3EhbnQAZA1Vx1Iv8NR7YhQ4MVfh9y0PaMGWvTU5XeK5mVsmDaeseLnZFcQQPQsNh6k9+856zNJbVCkJq35vbjez14arNJyPXsTgtVYUNtlLuyAifp4t+7D0UPu/bWeREfSOsgvmBOaJOPsbuBnY3kNXtWu82eG/kvp228guigNmyu+R3tLt1191IrN6Vic119bBzwUlxHGLY7x39FDgWUX4MjcAbyIukW6hiWbhyW3dDQH+rfG8J2HrWuqdDeagzFBAXgxQty435ommlwDyCJPFmlQHrzYr4OpBDpUsTpy9sN2TRewenvH1M4CxvDMcFU+3ze4cUGuxhQQWeDQQdnA8Tvw9dgZkQrW9PV1agaNNCuk1abIOnKUDfNV8dF7W5rGPBctKNx/iUyy/MNyjF2rgF3KxzJ2sIELH0ja7PtP3v98gJECwmhLZ3q1HWnqvMNDIfgtYW9G2tQol1AFoWPL3Titk1dc8T8q1/ApJ3J/46UM2r6SO2A6g/snqshQ1EWtUV/4POZXTXqDdvJXDs7S6EN95PAHsnUX0mZ7U6jjupjTsC3qg6KAM1wrBHyRN35jLb6PzHhVPpBWQ8JkVCTenjJBXrhNBh/x+SUpOHhPtSFuVL7wfKMFH+vJBxh5mnrQ/aII4pLGR84SLkluVbMcJb0EHCChdpziPU6Vx/QE4TgQjTUXjs2nWlGr+nYf6hY9PPtrEV6k8WrtboNhMSelD/UE47PK30po2wtXUKtpY6lAmO5tITIQJYRoEQnbHCX94B6dIz4V6irn7qIapkHaXhf9eENJfNWmAdqNJxlPkUeNc8zs9AfLwRGsfdvFG2JmR9naM1AuwrfTrQN222uZy6h+UrQTAZgmsREgz2wk= Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a13-20020a1709066d4d00b00a3612401eb0si3622164ejt.484.2024.02.11.23.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 23:48:22 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 B656887ECC; Mon, 12 Feb 2024 08:47:52 +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 EDB1987ED1; Mon, 12 Feb 2024 08:47:51 +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 4D96787C80 for ; Mon, 12 Feb 2024 08:47:49 +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 58CCEDA7; Sun, 11 Feb 2024 23:48:30 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8C9643F7BD; Sun, 11 Feb 2024 23:47:45 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Patrice Chotard , Patrick Delaunay , Yann Gautier , Etienne Carriere , Michal Simek , Jassi Brar , Sughosh Ganu Subject: [PATCH v2 04/21] fwu: add helper functions for getting image description offsets Date: Mon, 12 Feb 2024 13:16:55 +0530 Message-Id: <20240212074712.3657076-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240212074712.3657076-1-sughosh.ganu@linaro.org> References: <20240212074712.3657076-1-sughosh.ganu@linaro.org> 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.8 at phobos.denx.de X-Virus-Status: Clean With migration of the FWU metadata structure to version 2, the size of the structure is not determined at build time, but at run time. This means, that the offsets for the structures describing firmware images which are part of the FWU metadata(struct fwu_fw_store_desc, struct fwu_image_entry and struct fwu_image_bank_info) need to be computed at runtime. Add helper functions to get addresses of these structures. Signed-off-by: Sughosh Ganu --- Changes since V1: * New patch needed based on comments from Ilias on the earlier version. include/fwu.h | 45 +++++++++++++++++++++++++++++++++ lib/fwu_updates/fwu.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/include/fwu.h b/include/fwu.h index 1815bd0064..7de462548c 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -81,6 +82,50 @@ struct fwu_mdata_ops { EFI_GUID(0x0c996046, 0xbcc0, 0x4d04, 0x85, 0xec, \ 0xe1, 0xfc, 0xed, 0xf1, 0xc6, 0xf8) + +/** + * fwu_get_fw_desc() - Return pointer to firmware descriptor store struct + * @mdata: Pointer to the FWU metadata + * + * Returns pointer to the firmware store descriptor of the FWU metadata + * containing information on updatable images. + * + * Return: Pointer to the struct fwu_fw_store_desc + */ +static inline struct fwu_fw_store_desc *fwu_get_fw_desc(struct fwu_mdata *mdata) +{ + return (struct fwu_fw_store_desc *)((u8 *)mdata + sizeof(*mdata)); +} + +/** + * fwu_img_entry_offset() - Get pointer to struct fwu_image_entry + * @mdata: Pointer to the FWU metadata + * @idx: Image index for which pointer is to be returned + * + * Fetches pointer to am array element of type struct fwu_image_entry. + * This returns back a pointer to a structure which is providing + * information on a updatable image. + * + * Return: Pointer to an array element of type struct fwu_image_entry + * + */ +struct fwu_image_entry *fwu_img_entry_offset(struct fwu_mdata *mdata, u16 idx); + +/** + * fwu_img_bank_info_offset() - Get pointer to struct fwu_image_bank_info + * @mdata: Pointer to the FWU metadata + * @idx: Image index for which information is needed + * @bank: Bank for which pointer is to be returned + * + * Fetches pointer to an array element of type struct fwu_image_bank_info + * for a given image. This returns back a pointer to a structure which + * is providing information for a given bank for a particular image. + * + * Return: Pointer to an array element of type fwu_image_bank_info + * + */ +struct fwu_image_bank_info *fwu_img_bank_info_offset(struct fwu_mdata *mdata, + u16 idx, u8 bank); /** * fwu_read_mdata() - Wrapper around fwu_mdata_ops.read_mdata() */ diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 86518108c2..5f1182a764 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -141,6 +141,64 @@ static int fwu_get_image_type_id(u8 image_index, efi_guid_t *image_type_id) return -ENOENT; } +/** + * fwu_img_entry_offset() - Get pointer to struct fwu_image_entry + * @mdata: Pointer to the FWU metadata + * @idx: Image index for which pointer is to be returned + * + * Fetches pointer to am array element of type struct fwu_image_entry. + * This returns back a pointer to a structure which is providing + * information on a updatable image. + * + * Return: Pointer to an array element of type struct fwu_image_entry + * + */ +struct fwu_image_entry *fwu_img_entry_offset(struct fwu_mdata *mdata, u16 idx) +{ + u8 num_banks; + size_t offset; + + num_banks = fwu_get_fw_desc(mdata)->num_banks; + + offset = sizeof(struct fwu_mdata) + + sizeof(struct fwu_fw_store_desc) + + (sizeof(struct fwu_image_entry) + + sizeof(struct fwu_image_bank_info) * num_banks) * idx; + + return (struct fwu_image_entry *)((char *)mdata + offset); +} + +/** + * fwu_img_bank_info_offset() - Get pointer to struct fwu_image_bank_info + * @mdata: Pointer to the FWU metadata + * @idx: Image index for which information is needed + * @bank: Bank for which pointer is to be returned + * + * Fetches pointer to an array element of type struct fwu_image_bank_info + * for a given image. This returns back a pointer to a structure which + * is providing information for a given bank for a particular image. + * + * Return: Pointer to an array element of type fwu_image_bank_info + * + */ +struct fwu_image_bank_info *fwu_img_bank_info_offset(struct fwu_mdata *mdata, + u16 idx, u8 bank) +{ + u8 num_banks; + size_t offset; + + num_banks = fwu_get_fw_desc(mdata)->num_banks; + + offset = sizeof(struct fwu_mdata) + + sizeof(struct fwu_fw_store_desc) + + (sizeof(struct fwu_image_entry) + + sizeof(struct fwu_image_bank_info) * num_banks) * idx + + sizeof(struct fwu_image_entry) + + sizeof(struct fwu_image_bank_info) * bank; + + return (struct fwu_image_bank_info *)((char *)mdata + offset); +} + /** * fwu_sync_mdata() - Update given meta-data partition(s) with the copy provided * @mdata: FWU metadata structure