From patchwork Mon Feb 12 07:47:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 772033 Delivered-To: patch@linaro.org Received: by 2002:adf:9dca:0:b0:33b:4db1:f5b3 with SMTP id q10csp2000665wre; Sun, 11 Feb 2024 23:49:31 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWNDhPqQyLvGjk2Lu8SZNndX8XpG7ulldgYypPd7TThv6mF5DSgUK8AvkEgsjwVW7X6Ij7YkjQCTxheRSvNqMHR X-Google-Smtp-Source: AGHT+IHUNadYsloKbbo4LLn84KgQwQjF+cLBvGl5V7ZwyaXxwYuciTj92G/b/gHvUTx0kL/zMCzV X-Received: by 2002:aa7:c909:0:b0:561:bcbc:7c96 with SMTP id b9-20020aa7c909000000b00561bcbc7c96mr1073213edt.31.1707724171052; Sun, 11 Feb 2024 23:49:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707724171; cv=none; d=google.com; s=arc-20160816; b=D7iY0jP4FdMsiFi2RT6iWUoNSnSl2PAPz4K9gb+Z2zLjk/cgXicCtRDBF1BRc/76bC Ajk1eL3RG/2r+zICSTvWLuarciYo2JAKmzhSFKZS93/5VAS18ZKoDwBHVvhio5KQAzor jWn6+YV98GAh8slZbupyDay30xfsTxDs6BLzDL/ZxS+b6jQZU9npYOoOjWe0VfPVRZFY 11VHdItQPOEJozUJZahAaRxykRMPzU2d1MQYiCSHf1J2FXdds+OK/N/xJQLpLPtQLIT2 zlvVh7xQX6jLtHx+3JtK7c0k/BFrs8+dbhF/DNiqmxDKQCIZwME2USGSoRMkGc9eyS6C 7ZkQ== 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=diPQDN5UK8bhh35j/lvr2pLsl0ZFDbZM/AnS6aKR2gU=; fh=8tEjx/KtaLOcnAbiIAsn0D0GchDv2Ez4lJrbnoRR0eA=; b=utco2nlnY8r6DS3UVmUbPqS3/bXTTyDxDRgCNAR83i2FkffHryzXJ3s3rVnzgsDqHV q6AHqtEhLANV56pNUZB/fYYfrU5adMPXaDRWyHHOSGMj4o580qJiMGgWGjQd/oUrHYf2 l4EnaAA9L0VvZ6tyvXytkDCCuigsdpt5slSMJMo3jPqs/9bCLBubLtmmU2TaLgHjDTaa ylRWxTI7Z0fAbYBos3235dFvXuvI6Qp6cOZcodHkjvWsU2MYUbIUSQ9/z2VR8ZjFYVyz i/cZJv+REwfm5ZMxf2IL7TO8UFxIZHsFPNJvR58sSw9hHxYFX1sqsqyfGMERYZJwZk0A txnA==; darn=linaro.org 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 X-Forwarded-Encrypted: i=1; AJvYcCUR7aeaw3SIpSwOpln2SkrBW4lrN9jFUmVIRyu5jqdI1OLE0Uj4sJJxbPcehWFFvjfrqT0W4EclMx+6U49ct4U3eyBuk1Lmv1Ad832O2w9NjaFs6GaZbjn87+iCeV0zvjhhNMkeca7Low+gcjCBuupYSG0sUm3BE1GKOaochz0oHgFfjvMCaFYuPXPe3Pc6HvrYbe1XQmplWEA+AEg5Z/st3z0h0GOPJLXW1IH/FHEz6HS4Fn7YbnJ83jfC6kf23qiwQIqDaLeR2cVnPUzxGamq+aLtiVKbA/PukRacILosFvKehvCnh+uosp+Nwtokk5+5gwJ3+n9LWWyCgv1R/E4wO3n2NBx3bfh4WnuBXtg1bgi+0busgWyQ4pghF/tgZIqHTfcCTIgujM6YkpPeLS9XDVTK3MIh2tIxVgkryfOfi/0F90nO9zhyoXSWq9FlAwIPHasFXojz7nKGzAfbbPanxHNh6cSFCp07o1iW3KF3UL+IcfhbAtBU86XOkkxmSNSeEAlCRgNxTP5TEpYg+YkbNgyh5wbGak5ik7FZVxdUTWB5Skwo0XBELnv5kZKxWODMduqDMoy31Yyv+QLkNq8QGt26F1IFM/COJ9JOaBGvqERmDD4SBgSYIsVa27arIzkffC+ib4Ga7h93jij9WosMZN/iKAC4TcaA0Zg2EnTQAv+cjAeX9Q3Pd9tqE3xTUyhlxvXCa4cCDHqV0tID34CDWgF5U1L634RSAd2dV96JMM2CSDQyvbgpdyTonVVSiLVxuEN9uf9Ltp9/HEWvBNpCXRHI2TH1TzFUyrpvU0sHwV6H7OgNK5E9CfmH43mvBCTQ3aBF91RIVlm2qvIcMWe3VTkKPmj7peKpK3W5UeUuav0= 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 i10-20020aa7dd0a000000b0055fed500e30si2481191edv.677.2024.02.11.23.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 23:49:31 -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 6EA9487EF2; Mon, 12 Feb 2024 08:48:19 +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 0059487808; Mon, 12 Feb 2024 08:48:17 +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 C4C9587EC9 for ; Mon, 12 Feb 2024 08:48: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 D0579DA7; Sun, 11 Feb 2024 23:48:56 -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 0F7AB3F762; Sun, 11 Feb 2024 23:48:11 -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 11/21] fwu: mtd: modify the DFU API's to align with metadata version 2 Date: Mon, 12 Feb 2024 13:17:02 +0530 Message-Id: <20240212074712.3657076-12-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 Make changes to the functions used for generating the DFU's alt variable so that they are aligned with changes to the metadata version 2. These changes include getting the number of banks and images per bank at runtime from the metadata, as well as accessing the updatable image information from the FWU MTD driver's private structure. Signed-off-by: Sughosh Ganu --- Changes since V1: * Use the helper functions from the previous patch to access the image information in the metadata. lib/fwu_updates/fwu_mtd.c | 81 +++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/lib/fwu_updates/fwu_mtd.c b/lib/fwu_updates/fwu_mtd.c index 69cd3d7001..50ff0d692d 100644 --- a/lib/fwu_updates/fwu_mtd.c +++ b/lib/fwu_updates/fwu_mtd.c @@ -15,16 +15,51 @@ #include -struct fwu_mtd_image_info -fwu_mtd_images[CONFIG_FWU_NUM_BANKS * CONFIG_FWU_NUM_IMAGES_PER_BANK]; +static struct fwu_mdata *mdata; + +static int read_mdata(void) +{ + int ret = 0; + u32 mdata_size; + + ret = fwu_get_mdata_size(&mdata_size); + if (ret) + return ret; + + mdata = malloc(mdata_size); + if (!mdata) + return -ENOMEM; + + ret = fwu_get_mdata(mdata); + if (ret < 0) { + log_err("Failed to get the FWU mdata\n"); + free(mdata); + mdata = NULL; + } + + return ret; +} static struct fwu_mtd_image_info *mtd_img_by_uuid(const char *uuidbuf) { - int num_images = ARRAY_SIZE(fwu_mtd_images); + u8 nbanks; + u16 nimages; + int num_images, ret; + struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(fwu_get_dev()); + struct fwu_mtd_image_info *image_info = mtd_priv->fwu_mtd_images; + + if (!image_info) + return NULL; + + ret = fwu_get_banks_images(&nbanks, &nimages); + if (ret) + return NULL; + + num_images = nbanks * nimages; for (int i = 0; i < num_images; i++) - if (!strcmp(uuidbuf, fwu_mtd_images[i].uuidbuf)) - return &fwu_mtd_images[i]; + if (!strcmp(uuidbuf, image_info[i].uuidbuf)) + return &image_info[i]; return NULL; } @@ -107,8 +142,9 @@ __weak int fwu_plat_get_alt_num(struct udevice *dev, efi_guid_t *image_id, return fwu_mtd_get_alt_num(image_id, alt_num, "nor1"); } -static int gen_image_alt_info(char *buf, size_t len, int sidx, - struct fwu_image_entry *img, struct mtd_info *mtd) +static int gen_image_alt_info(char *buf, size_t len, int idx, + struct fwu_image_entry *img, + struct mtd_info *mtd, uint8_t num_banks) { char *p = buf, *end = buf + len; int i; @@ -123,15 +159,15 @@ static int gen_image_alt_info(char *buf, size_t len, int sidx, * List the image banks in the FWU mdata and search the corresponding * partition based on partition's uuid. */ - for (i = 0; i < CONFIG_FWU_NUM_BANKS; i++) { + for (i = 0; i < num_banks; i++) { struct fwu_mtd_image_info *mtd_img_info; struct fwu_image_bank_info *bank; char uuidbuf[UUID_STR_LEN + 1]; u32 offset, size; /* Query a partition by image UUID */ - bank = &img->img_bank_info[i]; - uuid_bin_to_str(bank->image_uuid.b, uuidbuf, UUID_STR_FORMAT_STD); + bank = fwu_img_bank_info_offset(mdata, idx, i); + uuid_bin_to_str(bank->image_guid.b, uuidbuf, UUID_STR_FORMAT_STD); mtd_img_info = mtd_img_by_uuid(uuidbuf); if (!mtd_img_info) { @@ -150,7 +186,7 @@ static int gen_image_alt_info(char *buf, size_t len, int sidx, } } - if (i == CONFIG_FWU_NUM_BANKS) + if (i == num_banks) return 0; return -ENOENT; @@ -158,24 +194,29 @@ static int gen_image_alt_info(char *buf, size_t len, int sidx, int fwu_gen_alt_info_from_mtd(char *buf, size_t len, struct mtd_info *mtd) { - struct fwu_mdata mdata; + u8 num_banks; + u16 num_images; int i, l, ret; + struct fwu_image_entry *img_entry; - ret = fwu_get_mdata(&mdata); - if (ret < 0) { - log_err("Failed to get the FWU mdata.\n"); - return ret; + if (!mdata) { + ret = read_mdata(); + if (ret) + return ret; } - for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) { - ret = gen_image_alt_info(buf, len, i * CONFIG_FWU_NUM_BANKS, - &mdata.img_entry[i], mtd); + num_banks = fwu_get_fw_desc(mdata)->num_banks; + num_images = fwu_get_fw_desc(mdata)->num_images; + for (i = 0; i < num_images; i++) { + img_entry = fwu_img_entry_offset(mdata, i); + ret = gen_image_alt_info(buf, len, i, + img_entry, mtd, num_banks); if (ret) break; l = strlen(buf); /* Replace the last ';' with '&' if there is another image. */ - if (i != CONFIG_FWU_NUM_IMAGES_PER_BANK - 1 && l) { + if (i != num_images - 1 && l) { buf[l] = '&'; buf++; }