u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Sughosh Ganu <sughosh.ganu@linaro.org>
Cc: u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Takahiro Akashi <takahiro.akashi@linaro.org>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Patrice Chotard <patrice.chotard@foss.st.com>,
	Simon Glass <sjg@chromium.org>, Bin Meng <bmeng.cn@gmail.com>,
	Tom Rini <trini@konsulko.com>,
	Etienne Carriere <etienne.carriere@linaro.org>,
	Michal Simek <monstr@monstr.eu>,
	Jassi Brar <jaswinder.singh@linaro.org>
Subject: Re: [PATCH v9 06/15] FWU: Add helper functions for accessing FWU metadata
Date: Wed, 7 Sep 2022 08:59:00 +0300	[thread overview]
Message-ID: <YxgzJC0XvixT9VcP@hera> (raw)
In-Reply-To: <20220826095716.1676150-7-sughosh.ganu@linaro.org>

On Fri, Aug 26, 2022 at 03:27:07PM +0530, Sughosh Ganu wrote:
> Add weak functions for getting the update index value and dfu
> alternate number needed for FWU Multi Bank update
> functionality.
> 
> The current implementation for getting the update index value is for
> platforms with 2 banks. If a platform supports more than 2 banks, it
> can implement it's own function. The function to get the dfu alternate
> number has been added for platforms with GPT partitioned storage
> devices. Platforms with other storage partition scheme need to
> implement their own function.
> 
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> Changes since V8:
> * Add comments for API functions
> * Update the logic to get the update index as suggested by Jassi
> 
>  include/fwu.h             |  29 ++++++++++
>  lib/fwu_updates/fwu.c     |  27 +++++++++
>  lib/fwu_updates/fwu_gpt.c | 115 ++++++++++++++++++++++++++++++++++++++
>  3 files changed, 171 insertions(+)
>  create mode 100644 lib/fwu_updates/fwu_gpt.c
> 
> diff --git a/include/fwu.h b/include/fwu.h
> index ecabf11210..7ebd3a7115 100644
> --- a/include/fwu.h
> +++ b/include/fwu.h
> @@ -211,4 +211,33 @@ 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);
>  
> +/**
> + * fwu_plat_get_alt_num() - Get the DFU Alt Num for the image from the platform
> + * @dev: FWU device
> + * @image_guid: Image GUID for which DFU alt number needs to be retrieved
> + * @alt_num: Pointer to the alt_num
> + *
> + * Get the DFU alt number from the platform for the image specified by the
> + * image GUID.
> + *
> + * Return: 0 if OK, -ve on error
> + *
> + */
> +int fwu_plat_get_alt_num(struct udevice *dev, efi_guid_t *image_guid,
> +			 int *alt_num);
> +
> +/**
> + * fwu_plat_get_update_index() - Get the value of the update bank
> + * @update_idx: Bank number to which images are to be updated
> + *
> + * Get the value of the bank(partition) to which the update needs to be
> + * made.
> + *
> + * Note: This is a weak function and platforms can override this with
> + * their own implementation for selection of the update bank.
> + *
> + * Return: 0 if OK, -ve on error
> + *
> + */
> +int fwu_plat_get_update_index(uint *update_idx);
>  #endif /* _FWU_H_ */
> diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c
> index a871d77b4c..94b15859a5 100644
> --- a/lib/fwu_updates/fwu.c
> +++ b/lib/fwu_updates/fwu.c
> @@ -355,3 +355,30 @@ int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank)
>  	return fwu_clrset_image_accept(img_type_id, bank,
>  				       IMAGE_ACCEPT_CLEAR);
>  }
> +
> +/**
> + * fwu_plat_get_update_index() - Get the value of the update bank
> + * @update_idx: Bank number to which images are to be updated
> + *
> + * Get the value of the bank(partition) to which the update needs to be
> + * made.
> + *
> + * Note: This is a weak function and platforms can override this with
> + * their own implementation for selection of the update bank.
> + *
> + * Return: 0 if OK, -ve on error
> + *
> + */
> +__weak int fwu_plat_get_update_index(uint *update_idx)
> +{
> +	int ret;
> +	u32 active_idx;
> +
> +	ret = fwu_get_active_index(&active_idx);
> +	if (ret < 0)
> +		return -1;
> +
> +	*update_idx = (active_idx + 1) % CONFIG_FWU_NUM_BANKS;
> +
> +	return ret;
> +}
> diff --git a/lib/fwu_updates/fwu_gpt.c b/lib/fwu_updates/fwu_gpt.c
> new file mode 100644
> index 0000000000..a3134b80c9
> --- /dev/null
> +++ b/lib/fwu_updates/fwu_gpt.c
> @@ -0,0 +1,115 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2022, Linaro Limited
> + */
> +
> +#include <blk.h>
> +#include <dfu.h>
> +#include <efi.h>
> +#include <efi_loader.h>
> +#include <fwu.h>
> +#include <log.h>
> +#include <part.h>
> +
> +#include <linux/errno.h>
> +
> +static int get_gpt_dfu_identifier(struct blk_desc *desc, efi_guid_t *image_guid)
> +{
> +	int i;
> +	struct disk_partition info;
> +	efi_guid_t unique_part_guid;
> +
> +	for (i = 1; i < MAX_SEARCH_PARTITIONS; i++) {
> +		if (part_get_info(desc, i, &info))
> +			continue;
> +		uuid_str_to_bin(info.uuid, unique_part_guid.b,
> +				UUID_STR_FORMAT_GUID);
> +
> +		if (!guidcmp(&unique_part_guid, image_guid))
> +			return i;
> +	}
> +
> +	log_err("No partition found with image_guid %pUs\n", image_guid);
> +	return -ENOENT;
> +}
> +
> +static int fwu_gpt_get_alt_num(struct blk_desc *desc, efi_guid_t *image_guid,
> +			       int *alt_num, unsigned char dfu_dev)
> +{
> +	int ret = -1;
> +	int i, part, dev_num;
> +	int nalt;
> +	struct dfu_entity *dfu;
> +
> +	dev_num = desc->devnum;
> +	part = get_gpt_dfu_identifier(desc, image_guid);
> +	if (part < 0)
> +		return -ENOENT;
> +
> +	dfu_init_env_entities(NULL, NULL);
> +
> +	nalt = 0;
> +	list_for_each_entry(dfu, &dfu_list, list) {
> +		nalt++;
> +	}

Nit, you don't need {}

> +
> +	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;
> +
> +		/*
> +		 * Currently, Multi Bank update
> +		 * feature is being supported
> +		 * only on GPT partitioned
> +		 * MMC/SD devices.
> +		 */
> +		if (dfu->dev_type != dfu_dev)
> +			continue;
> +
> +		if (dfu->layout == DFU_RAW_ADDR &&
> +		    dfu->data.mmc.dev_num == dev_num &&
> +		    dfu->data.mmc.part == part) {
> +			*alt_num = dfu->alt;
> +			ret = 0;

Can we make this function return the partition number and < 0 on failure?
If it's too big of a change, I don't mind keeping it as is

Regards
/Ilias
> +			break;
> +		}
> +	}
> +
> +	dfu_free_entities();
> +
> +	return ret;
> +}
> +
> +/**
> + * fwu_plat_get_alt_num() - Get the DFU alt number
> + * @dev: FWU metadata device
> + * @image_guid: GUID value of the image for which the alt num is to
> + *              be obtained
> + * @alt_num: The DFU alt number for the image that is to be updated
> + *
> + * Get the DFU alt number for the image that is to be updated. The
> + * image is identified with the image_guid parameter that is passed
> + * to the function.
> + *
> + * Note: This is a weak function and platforms can override this with
> + * their own implementation for obtaining the alt number value.
> + *
> + * Return: 0 if OK, -ve on error
> + *
> + */
> +__weak int fwu_plat_get_alt_num(struct udevice *dev, efi_guid_t *image_guid,
> +				int *alt_num)
> +{
> +	struct fwu_mdata_gpt_blk_priv *priv = dev_get_priv(dev);
> +
> +	return fwu_gpt_get_alt_num(dev_get_uclass_plat(priv->blk_dev),
> +				   image_guid, alt_num, DFU_DEV_MMC);
> +}
> -- 
> 2.34.1
> 

  parent reply	other threads:[~2022-09-07  5:59 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26  9:57 [PATCH v9 00/15] FWU: Add FWU Multi Bank Update feature support Sughosh Ganu
2022-08-26  9:57 ` [PATCH v9 01/15] dt/bindings: Add bindings for GPT based FWU Metadata storage device Sughosh Ganu
2022-09-04  7:09   ` Ilias Apalodimas
2022-09-06  7:35   ` Etienne Carriere
2022-08-26  9:57 ` [PATCH v9 02/15] FWU: Add FWU metadata structure and driver for accessing metadata Sughosh Ganu
2022-09-06  7:36   ` Etienne Carriere
2022-09-07  6:45   ` Ilias Apalodimas
2022-09-07 11:02     ` Sughosh Ganu
2022-08-26  9:57 ` [PATCH v9 03/15] FWU: Add FWU metadata access driver for GPT partitioned block devices Sughosh Ganu
2022-09-06  7:01   ` Etienne Carriere
2022-09-06  7:12     ` Sughosh Ganu
2022-08-26  9:57 ` [PATCH v9 04/15] stm32mp1: dk2: Add a node for the FWU metadata device Sughosh Ganu
2022-09-06  7:37   ` Etienne Carriere
2022-08-26  9:57 ` [PATCH v9 05/15] stm32mp1: dk2: Add image information for capsule updates Sughosh Ganu
2022-09-04  7:11   ` Ilias Apalodimas
2022-09-05 19:18   ` Etienne Carriere
2022-09-06  7:08     ` Sughosh Ganu
2022-08-26  9:57 ` [PATCH v9 06/15] FWU: Add helper functions for accessing FWU metadata Sughosh Ganu
2022-09-06  7:39   ` Etienne Carriere
2022-09-07  5:59   ` Ilias Apalodimas [this message]
2022-09-07 11:05     ` Sughosh Ganu
2022-08-26  9:57 ` [PATCH v9 07/15] FWU: STM32MP1: Add support to read boot index from backup register Sughosh Ganu
2022-09-06  7:27   ` Etienne Carriere
2022-09-06  7:37     ` Sughosh Ganu
2022-09-06  7:44       ` Sughosh Ganu
2022-08-26  9:57 ` [PATCH v9 08/15] event: Add an event for main_loop Sughosh Ganu
2022-08-27  0:20   ` Simon Glass
2022-08-26  9:57 ` [PATCH v9 09/15] FWU: Add boot time checks as highlighted by the FWU specification Sughosh Ganu
2022-09-06  6:58   ` Etienne Carriere
2022-09-06  7:01   ` Etienne Carriere
2022-09-06  7:11     ` Sughosh Ganu
2022-08-26  9:57 ` [PATCH v9 10/15] FWU: Add support for the FWU Multi Bank Update feature Sughosh Ganu
2022-09-07 13:34   ` Ilias Apalodimas
2022-09-08  2:15   ` Takahiro Akashi
2022-09-08  6:34     ` Sughosh Ganu
2022-08-26  9:57 ` [PATCH v9 11/15] FWU: cmd: Add a command to read FWU metadata Sughosh Ganu
2022-09-06  7:59   ` Etienne Carriere
2022-08-26  9:57 ` [PATCH v9 12/15] test: dm: Add test cases for FWU Metadata uclass Sughosh Ganu
2022-09-04  7:10   ` Ilias Apalodimas
2022-08-26  9:57 ` [PATCH v9 13/15] mkeficapsule: Add support for generating empty capsules Sughosh Ganu
2022-09-22 13:26   ` Ilias Apalodimas
2022-08-26  9:57 ` [PATCH v9 14/15] mkeficapsule: Add support for setting OEM flags in capsule header Sughosh Ganu
2022-08-26  9:57 ` [PATCH v9 15/15] FWU: doc: Add documentation for the FWU feature Sughosh Ganu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YxgzJC0XvixT9VcP@hera \
    --to=ilias.apalodimas@linaro.org \
    --cc=bmeng.cn@gmail.com \
    --cc=etienne.carriere@linaro.org \
    --cc=jaswinder.singh@linaro.org \
    --cc=monstr@monstr.eu \
    --cc=patrice.chotard@foss.st.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=sjg@chromium.org \
    --cc=sughosh.ganu@linaro.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).