From patchwork Mon Feb 12 07:46:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 772029 Delivered-To: patch@linaro.org Received: by 2002:adf:9dca:0:b0:33b:4db1:f5b3 with SMTP id q10csp2000533wre; Sun, 11 Feb 2024 23:48:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHaKEGb48sPFI4NPbe8vZ2UZc0nuAUi4bPDU0T/zCtlQKohUieBOwB8dQWnSeeH4vHN9eWK X-Received: by 2002:a17:906:fc13:b0:a38:40eb:9fe6 with SMTP id ov19-20020a170906fc1300b00a3840eb9fe6mr6522420ejb.33.1707724133413; Sun, 11 Feb 2024 23:48:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707724133; cv=none; d=google.com; s=arc-20160816; b=eF0MXGuImpW7ImHqun2TvEWmtJxKBW+MA5QkuqgcUpIcwR3ai4iXq7wYamnhKHqo4E I2jAYapPCHk61qnZF+eU4QldkQim+Gsb0gXOiM+VwkI5UZIXT9Z9u1BgKRBhL+Mr157d dBIBpT65N1XoTj9Ru2tFRA2vD87YLpQEKzovCFYgfpaF0gRLBdrSnb0bws4BBNRZi84L 6bNGBPQbWDjr2KzONAHg/9UxwxqTkABSBEydMx/nJtSiUftMJ/T44t3nbvG9Jqxd5bLh SIWKhXBbUgT/cV0Umhe2cfhVqmdy9H3udVeDze+/tuJHc2EPWASMzOAoClOCemUFFZBp SSAw== 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=7HTu3BUq+G8HibyudYouyXk5uKM5QjiJk5ujjuKrjII=; fh=mi7J6cZjilAFpBBsdiJVJiY+MrfsjxkQEbeIfSPmPbw=; b=FQ3YBLz7PbH4CGXFsann3UwAeYx1MDXAfK7f+b5L8b6EYxhX6Eqt2ENeIQsaz8rMrm 5liXYkxwOlnvrKRzKy69PDSU23d7HLWv4bMZm5iA1HFZ4FMJ8sCR03S3TxxgZPSxnxWy w4EzqH7Xop+YD0wB4Tsenmn7wB7p0ODPoe53Br/Kv3l61YHIOK6Xeb4F2XxBRZ66vq0j kNK0Yosxedl2R+NNy0pUQdRpJjL1Ni0828UHwZagGUPCj0p3uDHGEKsDsJ1+fvuS7HO2 xWcVwb/pTYEyj1BUUvp7kO+F3J3TNcrwV5tOwJaQj9gRi+YcnHPTrlGnQTDNylTWCEUx FBXA==; 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; AJvYcCWsEQsOBvOIkTmT/BDhwzomfbBsd6jPPJ15wNVH0zZzGllEjAVGVlClcDamo5aasp2XoGJbR7dSnBs2kGf+x8HEVYV27f2XjJMH6k2SsDuBbDh6+hcUw5QeXyH5jzZomKc+FU6nHnFog6u8Soep2EYeh8YZD1kAJYPJr9TYUV4J3LRL0e9H4bBNw0DDAt1AfsF7fe/ljpgDlyPy5KXXQGScGYZrSGMFDCoxFsH7NYnOq6HWleOFtZdHSWHM/IId2ZFBJoZ6DQNg4AUBxll7ccq5kC6Uud4kPBXRNIiUT70YPW/znD/UV+cN0JtQ0W2HQ3eqzAzMZXibH1xT4/u3rjLPj8V5csEhTDOtS48EqGiv9+JzwbFVEEIV/IqKdGKepjccmGmEWUNq4aQfKvfu3JDJlQ9P6gfjgU6VnFt/p7yYg9LN8gvfmFFkvVj72GCc7sP+0WH5JRjBraGNMuUHYPTEPLSwvYXBiTjts3DYW9rkD9uqEfjOpCveGV7w7MT13YmijO+T48RHkR0OCXLWK6HhGnHAw5dsMvWp/mFeLJIgmnU56k+3ahkgmz1bMbXweX1SaKIihv3+L/V5IPLCkKV8f+OZwSvN/3aPApm7fe6+XOFIxRQQV7vM+Pa3wo22g3yG5e1lXFaQYvKaD6RVyWBqOOOQ6zUI0cQcamrvoSHwiVGcYHUJQsFW7HObHirMlgFPBKDRaRVQ6fony6nDydC6G1ZEX2+14c8lWifUuaU/SvGyRi0TqV5LgiBcnKfqlOAYMbcZATgjJcu4BXj0gGG27WN46+7XWk6/lhQAjD5x3aANw/5YbXCv3oAovqBGFcOcWvm3SD5Wo/1EM1nCq9+xc/5FukcNUnmBl3t2KTaxhcI= 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 qw18-20020a170906fcb200b00a3c9abc9b56si770018ejb.892.2024.02.11.23.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 23:48:53 -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 75A0987EE4; Mon, 12 Feb 2024 08:48:04 +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 186FF87EE6; Mon, 12 Feb 2024 08:48:03 +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 C424387EE2 for ; Mon, 12 Feb 2024 08:48:00 +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 D1C79DA7; Sun, 11 Feb 2024 23:48:41 -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 115103F762; Sun, 11 Feb 2024 23:47:56 -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 07/21] drivers: fwu: mtd: allocate buffer for image info dynamically Date: Mon, 12 Feb 2024 13:16:58 +0530 Message-Id: <20240212074712.3657076-8-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 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 V1: None drivers/fwu-mdata/raw_mtd.c | 71 ++++++++++++++++++++++++------------- include/fwu.h | 9 +++++ 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/drivers/fwu-mdata/raw_mtd.c b/drivers/fwu-mdata/raw_mtd.c index 9f3f1dc213..da36094644 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,24 @@ 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; + + /* Read the metadata to get number of banks and images */ + ret = fwu_get_banks_images(&nbanks, &nimages); + if (ret) + return ret; + + 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 +288,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 ce8c98921a..109ceb2610 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -27,6 +27,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