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 575D9ECAAD2 for ; Thu, 1 Sep 2022 07:01:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A4EE5848E3; Thu, 1 Sep 2022 09:01:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="gpXs+RIw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 712C3849C9; Thu, 1 Sep 2022 09:01:18 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7B27D848A6 for ; Thu, 1 Sep 2022 09:01:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1662015672; bh=R/Bu9YzldU4xk0esmL1Fj4/ak9IP7GMj1en9Jief3JQ=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=gpXs+RIwVOJ60cyav/59xxKGSrPigMq1zlYXBqISVjbrD4uMu78DF8VOnJtnOHRZN 9oeLiAL3XWG60qMyFQdkGmpjBlW+WxbAcvcjx2ILzX7oZfo26BwsshcmL5z2jz55Rn ZaEZF3tc+tK+/WE36nTrGE1MsJtqHV4vPXf+2eBo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([84.118.157.2]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MUosN-1ouHt03tuD-00QnPh; Thu, 01 Sep 2022 09:01:12 +0200 Message-ID: Date: Thu, 1 Sep 2022 09:01:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH 3/5] FWU: mtd: Add helper functions for accessing FWU metadata Content-Language: en-US To: jassisinghbrar@gmail.com, Sughosh Ganu Cc: 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 , u-boot@lists.denx.de References: <20220722174240.63935-1-jassisinghbrar@gmail.com> <20220722174319.64006-1-jassisinghbrar@gmail.com> <20220722174319.64006-4-jassisinghbrar@gmail.com> From: Heinrich Schuchardt In-Reply-To: <20220722174319.64006-4-jassisinghbrar@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:BdDiZ1cnecigDKnDH9GWaazCl5oBUYrjLnteIHWOEC9+Stxl+rW ztl16EkBbmEN8RznMzxNp/iaQgC/RS/Erzr+rG5DLsInx5IDC1m87csWf4BbyNRDlOnreHA 6448g7KonxGpGwfsw3hdAdsb5y2VaYEqb6JEO5/KVIKXNOgztVBbgRy+uVpFabdjfgnHRGT AomXeE+8mWgfWeZrLUv5w== X-UI-Out-Filterresults: notjunk:1;V03:K0:EYPpuAvCxHQ=:bwJeIRuoYyrd/57besUvlh LxtxhFCMcecJ+ClOqaWdFeU+AMKMilN7k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YV tXQfOxigvhyHMMYyAN7EOa4PoMvGYAYeGxU2NqXG5wSNwVYo5qhyHl85ToahgvAt+DkXAoiY+ V94m8uU5NMWasnTPoAIiFU9gGN 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 On 7/22/22 19:43, jassisinghbrar@gmail.com wrote: > 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) +=3D fwu.o > obj-$(CONFIG_FWU_MDATA_GPT_BLK) +=3D fwu_gpt.o > +obj-$(CONFIG_FWU_MDATA_MTD) +=3D 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 > + Please, document functions. You missed adding the function to an include in the series. The include changes should be in the same patch as the library functions. > +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 =3D -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 =3D get_mtd_device_nm(mtd_dev); > + > + /* Find partition node under given MTD device. */ > + parts_node =3D 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 =3D 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; > + } Isn't finding an mtd partition by UUID something that should be a function in the mtd uclass because it may find usages outside FWU? > + > + offset =3D ofnode_get_addr_size_index_notrans(node, 0, &size); > + if (offset =3D=3D FDT_ADDR_T_NONE || !size) > + return -ENOENT; > + > + dfu_init_env_entities(NULL, NULL); > + > + nalt =3D 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 =3D 0; i < nalt; i++) { > + dfu =3D dfu_get_entity(i); > + > + if (!dfu) > + continue; > + > + if (dfu->dev_type !=3D DFU_DEV_MTD) > + continue; > + > + if (dfu->layout =3D=3D DFU_RAW_ADDR && > + dfu->data.mtd.start =3D=3D offset && > + dfu->data.mtd.size =3D=3D size) { > + *alt_num =3D dfu->alt; > + ret =3D 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 =3D buf, *end =3D buf + len; > + > + /* Find partition node under given MTD device. */ > + parts_node =3D ofnode_by_compatible(mtd_get_ofnode(mtd), > + "fixed-partitions"); > + if (!ofnode_valid(parts_node)) > + return -ENOENT; > + > + /* Check the media UUID if exist. */ > + suuid =3D 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 +=3D snprintf(p, end - p, "mtd %s", mtd->name); > + if (end < p) err_log() needed? > + return -E2BIG; > + > + /* > + * List up the image banks in the FWU mdata and search the correspondi= ng %s/up // > + * partition based on partition's uuid. > + */ > + for (i =3D 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 =3D &img->img_bank_info[i]; > + uuid_bin_to_str(bank->image_uuid.b, uuidbuf, > + UUID_STR_FORMAT_STD); > + node =3D 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 =3D ofnode_get_addr_size_index_notrans(node, 0, &size); > + if (offset =3D=3D FDT_ADDR_T_NONE || !size) > + break; > + > + p +=3D snprintf(p, end - p, "%sbank%d raw %lx %lx", > + i =3D=3D 0 ? "=3D" : ";", i, (unsigned long)offset, > + (unsigned long)size); > + if (end < p) > + return -E2BIG; > + } > + > + return i !=3D CONFIG_FWU_NUM_BANKS ? -ENOENT : 0; This is easier to read: if (i !=3D CONFIG_FWU_NUM_BANKS) return -ENOENT; return 0; Best regards Heinrich > +} > + > +int fwu_gen_alt_info_from_mtd(char *buf, size_t len, struct mtd_info *m= td) > +{ > + struct fwu_mdata *mdata =3D NULL; > + int i, l, ret; > + > + ret =3D fwu_get_mdata(&mdata); > + if (ret < 0) { > + log_debug("Failed to get the FWU mdata.\n"); > + return ret; > + } > + > + for (i =3D 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) { > + ret =3D gen_image_alt_info(buf, len, i * CONFIG_FWU_NUM_BANKS, > + &mdata->img_entry[i], mtd); > + if (ret) > + break; > + l =3D strlen(buf); > + /* Replace the last ';' with '&' if there is another image. */ > + if (i !=3D CONFIG_FWU_NUM_IMAGES_PER_BANK - 1 && l) > + buf[l - 1] =3D '&'; > + len -=3D l; > + buf +=3D l; > + } > + > + free(mdata); > + > + return ret; > +}