From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4BEAFC54EE9 for ; Wed, 7 Sep 2022 11:06:14 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 191E284A5F; Wed, 7 Sep 2022 13:06:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="gwDabFGw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B2A90848DC; Wed, 7 Sep 2022 13:06:08 +0200 (CEST) Received: from mail-vk1-xa36.google.com (mail-vk1-xa36.google.com [IPv6:2607:f8b0:4864:20::a36]) (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 83BFC848DC for ; Wed, 7 Sep 2022 13:06:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sughosh.ganu@linaro.org Received: by mail-vk1-xa36.google.com with SMTP id s19so2255941vkf.0 for ; Wed, 07 Sep 2022 04:06:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=0gdamxLQ4nnNHSEQ5d1CCKOKDDB3gpON2c91+Ru+plM=; b=gwDabFGw+bgGbkyHsBsRLHicqfKGnPKNaGF+B0unesAShF5Fup8CLZ8qc/5MNd9XS2 xP3nA6ubqHopDLjnPgpxc8JpBkeMD8KiN4vEkTAxnAZv2v8zL/kTmSg8pnHlYpTp0bs6 46y+6OH+goZl9eqreZ6rLfWJAjT2EAJfJZWb5t0eUvTq8vkGH/KGJn3bSrd9G8dDF5ea IZreObpGKebiDcpbgi+Iwv7YMj702aaiNtDL+OnJETLuijFu37MUIcANsjzh64i1vRKd WAAw4KRl5J/qj0ZaLWd8ZYmnOYpL7gEXD0TWwHeZ+E/AV46LBQovFb401B/JEqFv8uZZ G6ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=0gdamxLQ4nnNHSEQ5d1CCKOKDDB3gpON2c91+Ru+plM=; b=oGFogxoy6ahk/bLI89Xh/zz1D7oUS610C2R890E02vbU4SeDPJVgfRoMVLJBMG83xC jVRKCXj1USPXrRoZgYam6S3XQnbHnfhvp0efRkxQ1RsJ7J8tFd/Z5gEpCSEBk3YFhZhO AYNYWprhXRTr6f0z0EdPaRfsLntB85iH5v5KfcnUt9f7PH22iMZgNNXhRTiA3UZvJHiq W7CyO7sSWOOd7hH0aujssRrs4quux7ZIe/zk4KfZDWsaKMG2VmOccFN/fsfKDLgA9/hX eRuFPHvzhYvIYEuDrF8CJUuZuwawcB8GulWNUwDRaiBi0d0EXk9Cr4rro6mmPkXDbv8j LU/g== X-Gm-Message-State: ACgBeo1fceUrYt8TbZjS+O4RFfaZk7yg9GCEjLWKzqRSHf6C6cMrEll8 snIglPcw1dEuAQKCYtIMiEqXp0rK2pdMX41AG8/MyA== X-Google-Smtp-Source: AA6agR78ICklC7FgJMDe/e0vFSrRbTK6GmOxhhQLToSWu2eB4+uzeH9IgOTvPulRXiYHEckaLYto5XkHes+pUCuXeLU= X-Received: by 2002:a05:6122:2207:b0:376:bb9e:dc86 with SMTP id bb7-20020a056122220700b00376bb9edc86mr790275vkb.1.1662548764057; Wed, 07 Sep 2022 04:06:04 -0700 (PDT) MIME-Version: 1.0 References: <20220826095716.1676150-1-sughosh.ganu@linaro.org> <20220826095716.1676150-7-sughosh.ganu@linaro.org> In-Reply-To: From: Sughosh Ganu Date: Wed, 7 Sep 2022 16:35:53 +0530 Message-ID: Subject: Re: [PATCH v9 06/15] FWU: Add helper functions for accessing FWU metadata To: Ilias Apalodimas Cc: u-boot@lists.denx.de, Heinrich Schuchardt , Takahiro Akashi , Patrick Delaunay , Patrice Chotard , Simon Glass , Bin Meng , Tom Rini , Etienne Carriere , Michal Simek , Jassi Brar Content-Type: text/plain; charset="UTF-8" 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 hi Ilias, On Wed, 7 Sept 2022 at 11:29, Ilias Apalodimas wrote: > > 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 > > Reviewed-by: Patrick Delaunay > > --- > > 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 > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include > > + > > +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 {} Will remove > > > + > > + 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 If you don't have a strong opinion on this, I would prefer to keep it as is, since this is consistent with the behaviour of the other functions where the value is being obtained through a pointer and the function is returning the status. -sughosh > > 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 > >