From patchwork Fri Mar 22 10:57:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 781837 Delivered-To: patch@linaro.org Received: by 2002:adf:cf01:0:b0:33e:7753:30bd with SMTP id o1csp1273544wrj; Fri, 22 Mar 2024 03:58:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWHfEy2akL+1SCp91uxokx8MMCVw+7r4ZEVguUxfnfMIJtf45CDXLKvU3rw8sNJyQC8lnqxp/IMs111KqD5A5Rw X-Google-Smtp-Source: AGHT+IFafPm2MTBOZKSafV6Pp2nLIS0MXqlWro/mlo77sQjyPMm4U2mYjOZOpRxeinVE65zh9HUA X-Received: by 2002:a2e:9cd9:0:b0:2d4:51f4:dbee with SMTP id g25-20020a2e9cd9000000b002d451f4dbeemr1413929ljj.53.1711105138773; Fri, 22 Mar 2024 03:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711105138; cv=none; d=google.com; s=arc-20160816; b=GT4iCxMLq1G4p7bq4kUyPE5tkB8Qx9SrON7PaAfBF0i4VF42scNenTTOAe7dpIMsQT UYNZHdaTIq4Lc1ynYjCAsTHA7Rz1wZ4fEVfTQuB27fKesAEI12hDZc2kcF/xlaB85qGo Rp6VHlNaPUnat0T4jOuAsAQwz9hFDm0JGMLfSRIwUz39wPMy+VeGazO9faK5M94iCp1P 31RFtHTHLFnBaAckUmjemGgSsagdUbZAqPBh0j5UVt+G0CoXJm7bds8Og4YKO209sknQ UeM80opJkHbRpRptKeHyDZuTBQycspYhW6wrywlxBPetisifAKFkkaN9mfc0RYhIT8eV D2Zw== 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=0cZT83lcSQ7Rl2y9cHIFnZMXmauvWAEhQUtPGQIaU/w=; fh=0OBOeNvG1YwOz62VjCAPxJsyowuZOMIwtNTktJXXBMY=; b=GSxT3px3f20lWPJcYKWcXokszKZ9jV5uBZ2UedmUJBZbXnNmCfrerr117KHnAvWTQw 5mXzYN9P+xhZ09EhsS9LkSZ/BPFpxp3q3zP2CToZqkXza54tUqAMktxDpSLtngaTLYPO CbKfrkGpTYEnHUeQj0fgboKpgwHq+XewkYrpNM+ihKDvtlIFIvpOVd0mMbbIQQEHfrDI VcZFvTZMryQUNNcLL1zhtCJSWUNWh0AzBmKec0ZBJVNnn8UnGm2pU916IQfUZl9e+C5S JNTwiM3jxYQZLM/+RL1RydN+vTpY1DHMUkZLi1z+miFKKIPezWS6rcf6+2uGAD/gJzUs kDiQ==; dara=google.com 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 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 v11-20020a05600c15cb00b00414692b33b7si986950wmf.179.2024.03.22.03.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 03:58:58 -0700 (PDT) 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 3084487F6A; Fri, 22 Mar 2024 11:58:25 +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 53ADD86BDB; Fri, 22 Mar 2024 11:58:24 +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 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 26CE988113 for ; Fri, 22 Mar 2024 11:58:22 +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 BA5641007; Fri, 22 Mar 2024 03:58:55 -0700 (PDT) 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 9F8873F64C; Fri, 22 Mar 2024 03:58:18 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Yann GAUTIER , Etienne Carriere , Patrick DELAUNAY - foss , Michal Simek , Masahisa Kojima , Michal Simek , Sughosh Ganu Subject: [PATCH v3 04/20] drivers: fwu: mtd: allocate buffer for image info dynamically Date: Fri, 22 Mar 2024 16:27:17 +0530 Message-Id: <20240322105733.203888-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240322105733.203888-1-sughosh.ganu@linaro.org> References: <20240322105733.203888-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 The FWU metadata access driver for MTD partitioned devices currently uses a statically allocated array for storing the updatable image information. This array depends on the number of banks and images per bank. With migration of the FWU metadata to version 2, these parameters are now obtained at runtime from the metadata. Make changes to the FWU metadata access driver for MTD devices to allocate memory for the image information dynamically in the driver's probe function, after having obtained the number of banks and images per bank by reading the metadata. Move the image information as part of the driver's private structure, instead of using a global variable. Signed-off-by: Sughosh Ganu --- Changes since V2: None drivers/fwu-mdata/raw_mtd.c | 68 +++++++++++++++++++++++-------------- include/fwu.h | 9 +++++ 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/drivers/fwu-mdata/raw_mtd.c b/drivers/fwu-mdata/raw_mtd.c index 9f3f1dc213..78a709f766 100644 --- a/drivers/fwu-mdata/raw_mtd.c +++ b/drivers/fwu-mdata/raw_mtd.c @@ -12,22 +12,11 @@ #include #include -/* Internal helper structure to move data around */ -struct fwu_mdata_mtd_priv { - struct mtd_info *mtd; - char pri_label[50]; - char sec_label[50]; - u32 pri_offset; - u32 sec_offset; -}; - enum fwu_mtd_op { FWU_MTD_READ, FWU_MTD_WRITE, }; -extern struct fwu_mtd_image_info fwu_mtd_images[]; - static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size) { return !do_div(size, mtd->erasesize); @@ -134,7 +123,7 @@ static int flash_partition_offset(struct udevice *dev, const char *part_name, fd return (int)size; } -static int fwu_mdata_mtd_of_to_plat(struct udevice *dev) +static int get_fwu_mdata_dev(struct udevice *dev) { struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(dev); const fdt32_t *phandle_p = NULL; @@ -144,8 +133,6 @@ static int fwu_mdata_mtd_of_to_plat(struct udevice *dev) fdt_addr_t offset; int ret, size; u32 phandle; - ofnode bank; - int off_img; /* Find the FWU mdata storage device */ phandle_p = ofnode_get_property(dev_ofnode(dev), @@ -199,8 +186,28 @@ static int fwu_mdata_mtd_of_to_plat(struct udevice *dev) return ret; mtd_priv->sec_offset = offset; - off_img = 0; + return 0; +} + +static int fwu_mtd_image_info_populate(struct udevice *dev, u8 nbanks, + u16 nimages) +{ + struct fwu_mtd_image_info *mtd_images; + struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(dev); + struct udevice *mtd_dev = mtd_priv->mtd->dev; + fdt_addr_t offset; + ofnode bank; + int off_img; + u32 total_images; + total_images = nbanks * nimages; + mtd_priv->fwu_mtd_images = malloc(sizeof(struct fwu_mtd_image_info) * + total_images); + if (!mtd_priv->fwu_mtd_images) + return -ENOMEM; + + off_img = 0; + mtd_images = mtd_priv->fwu_mtd_images; ofnode_for_each_subnode(bank, dev_ofnode(dev)) { int bank_num, bank_offset, bank_size; const char *bank_name; @@ -219,8 +226,7 @@ static int fwu_mdata_mtd_of_to_plat(struct udevice *dev) int image_num, image_offset, image_size; const char *uuid; - if (off_img == CONFIG_FWU_NUM_BANKS * - CONFIG_FWU_NUM_IMAGES_PER_BANK) { + if (off_img == total_images) { log_err("DT provides more images than configured!\n"); break; } @@ -230,11 +236,11 @@ static int fwu_mdata_mtd_of_to_plat(struct udevice *dev) ofnode_read_u32(image, "offset", &image_offset); ofnode_read_u32(image, "size", &image_size); - fwu_mtd_images[off_img].start = bank_offset + image_offset; - fwu_mtd_images[off_img].size = image_size; - fwu_mtd_images[off_img].bank_num = bank_num; - fwu_mtd_images[off_img].image_num = image_num; - strcpy(fwu_mtd_images[off_img].uuidbuf, uuid); + mtd_images[off_img].start = bank_offset + image_offset; + mtd_images[off_img].size = image_size; + mtd_images[off_img].bank_num = bank_num; + mtd_images[off_img].image_num = image_num; + strcpy(mtd_images[off_img].uuidbuf, uuid); log_debug("\tImage%d: %s @0x%x\n\n", image_num, uuid, bank_offset + image_offset); off_img++; @@ -246,8 +252,21 @@ static int fwu_mdata_mtd_of_to_plat(struct udevice *dev) static int fwu_mdata_mtd_probe(struct udevice *dev) { - /* Ensure the metadata can be read. */ - return fwu_get_mdata(NULL); + u8 nbanks; + u16 nimages; + int ret; + + ret = get_fwu_mdata_dev(dev); + if (ret) + return ret; + + nbanks = CONFIG_FWU_NUM_BANKS; + nimages = CONFIG_FWU_NUM_IMAGES_PER_BANK; + ret = fwu_mtd_image_info_populate(dev, nbanks, nimages); + if (ret) + return ret; + + return 0; } static struct fwu_mdata_ops fwu_mtd_ops = { @@ -266,6 +285,5 @@ U_BOOT_DRIVER(fwu_mdata_mtd) = { .of_match = fwu_mdata_ids, .ops = &fwu_mtd_ops, .probe = fwu_mdata_mtd_probe, - .of_to_plat = fwu_mdata_mtd_of_to_plat, .priv_auto = sizeof(struct fwu_mdata_mtd_priv), }; diff --git a/include/fwu.h b/include/fwu.h index 1815bd0064..6c4d218e13 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -26,6 +26,15 @@ struct fwu_mtd_image_info { char uuidbuf[UUID_STR_LEN + 1]; }; +struct fwu_mdata_mtd_priv { + struct mtd_info *mtd; + char pri_label[50]; + char sec_label[50]; + u32 pri_offset; + u32 sec_offset; + struct fwu_mtd_image_info *fwu_mtd_images; +}; + struct fwu_mdata_ops { /** * read_mdata() - Populate the asked FWU metadata copy