From patchwork Fri Feb 28 08:45:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 869282 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp678823wrz; Fri, 28 Feb 2025 00:46:55 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV1xb1Ojn/DBaWvjKMJRlnTVnfBVCmjUJwpcGoT4GXhKATg/1DpG8X20+LAqRLZOlZVi5ELYA==@linaro.org X-Google-Smtp-Source: AGHT+IH6g5NLqluBjJfBQWMl8YlH1hKb67Xl5Zd0w2eB29FwO1IgD9XwVsE1yJyQnxmkJIdyOS8q X-Received: by 2002:a05:6000:4027:b0:38f:28dc:ec23 with SMTP id ffacd0b85a97d-390ec7cc23cmr1581854f8f.19.1740732415449; Fri, 28 Feb 2025 00:46:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740732415; cv=none; d=google.com; s=arc-20240605; b=EenV9Rf3rmrflsafAZsVdXiX7dzWqt8NjUsqPtDS1Ts0TqmhjGN05uXW0yCco1EPaF IqUsgj4AlcgRnsM/4iMfkPGp5G9JABNvcu5GySu5DdcikC5uc+LBY6uju9zpBQd4gA24 PmCUgh+T8RMarDFDgq9QK8cbfr08o8UuDvQwuwS/a81zP7pdrvtcgzAE/Bl2D8iOVWLT B7vq9wWIEQCgwG5lPLHxmRNGLno9xiNgpibyUkQ/ecvI+b2gGYftqRyqrUuyZvSdQkGe Wm9PEeMrmL3s8XfwGs7yeFzqcaWE4EvA7rP5hW5jx8ZqCbzDC6gcx87KZSCt2fpU4Jf+ NfPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=5N6u1fFPEgbDWdh3jInN/hbhC+XPizXsbHXnDnZVdGc=; fh=WIErNPtEyr4LSk0kn+FyUcnvc47vQRNxykSeJQzwMAA=; b=a948hPqBc1+0ZtZppzfc+1mXyYc0ouEI4W4+yWGvj6zPECtYo24VkpjnNhRGDSDFZW tCe4B+JNGeSWLdN0p2XCajCm6BL5GisS01NbSPJ6WMzBPIIMMXI13kiM0urz5fTeRDTW 7cInldZbyVcPSBPbmEFqmHfNdVYi40kAIk3o1HpQeKXEM0pruMetXvcVOuC6ZS826IAE XrNJLTQtiEabngXghA5jH0CjAfYnXyTVMtYeJW2t+eQ7r4Rh3olHV8RbuICHhk1lk9iA RNBknzqYJGcQOE0KJqP2eMJa6M7k7KDogp0xPqzT6ssqP9LTEfq5QEGGVctbaSL2t0DL rkbw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id 5b1f17b1804b1-43b736cb5d5si23923515e9.35.2025.02.28.00.46.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 00:46:55 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 624C4811DF; Fri, 28 Feb 2025 09:46: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 2E50A80FAA; Fri, 28 Feb 2025 09:46:18 +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, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,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 EF95D81120 for ; Fri, 28 Feb 2025 09:46: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 AD41F113E; Fri, 28 Feb 2025 00:46:30 -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 826053F673; Fri, 28 Feb 2025 00:46:12 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Tom Rini , Heinrich Schuchardt , Anton Antonov , Tobias Waldekranz , Bin Meng , Sughosh Ganu Subject: [PATCH v6 6/6] blkmap: pass information on ISO image to the OS Date: Fri, 28 Feb 2025 14:15:29 +0530 Message-Id: <20250228084529.127823-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250228084529.127823-1-sughosh.ganu@linaro.org> References: <20250228084529.127823-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 EFI HTTP boot puts the ISO installer image at some location in memory. Information about this image has to be passed on to the OS kernel, which is done by adding a persistent memory(pmem) node to the devicetree(DT) that is passed to the OS. The OS kernel then gets information about the presence of this ISO image and proceeds with the installation. In U-Boot, this ISO image gets mounted as a memory mapped blkmap device slice, with the 'preserve' attribute. Add a helper function which iterates through all such slices, and invokes a callback. The callback adds the pmem node to the DT and removes the corresponding memory region from the EFI memory map. Invoke this helper function as part of the DT fixup which happens before booting the OS. Signed-off-by: Sughosh Ganu Reviewed-by: Tobias Waldekranz --- Changes since V5: * Move the failure message to the callback function instead of printing it in blkmap_get_preserved_pmem_slice() * Move the check for the callback function before entering the loop in blkmap_get_preserved_pmem_slice() * Return the error code returned by the callback function in blkmap_get_preserved_pmem_slice() boot/image-fdt.c | 7 ++++++ drivers/block/blkmap.c | 45 +++++++++++++++++++++++++++++++++++++ include/blkmap.h | 17 ++++++++++++++ include/efi.h | 13 +++++++++++ lib/efi_loader/efi_helper.c | 40 +++++++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+) diff --git a/boot/image-fdt.c b/boot/image-fdt.c index 9d1598b1a93..8f718ad29f6 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -649,6 +650,12 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb) if (!ft_verify_fdt(blob)) goto err; + if (CONFIG_IS_ENABLED(BLKMAP) && CONFIG_IS_ENABLED(EFI_LOADER)) { + fdt_ret = fdt_efi_pmem_setup(blob); + if (fdt_ret) + goto err; + } + /* after here we are using a livetree */ if (!of_live_active() && CONFIG_IS_ENABLED(EVENT)) { struct event_ft_fixup fixup; diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index eefed615998..1a633c71d43 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -498,6 +498,51 @@ err: return err; } +static bool blkmap_mem_preserve_slice(struct blkmap_slice *bms) +{ + return (bms->attr & (BLKMAP_SLICE_MEM | BLKMAP_SLICE_PRESERVE)) == + (BLKMAP_SLICE_MEM | BLKMAP_SLICE_PRESERVE); +} + +int blkmap_get_preserved_pmem_slice(int (*cb)(void *ctx, ulong addr, + u32 size), void *ctx) +{ + int ret; + u32 size; + ulong addr; + struct udevice *dev; + struct uclass *uc; + struct blkmap *bm; + struct blkmap_mem *bmm; + struct blkmap_slice *bms; + struct blk_desc *bd; + + if (!cb) { + log_debug("%s: No callback passed to the function\n", __func__); + return 0; + } + + uclass_id_foreach_dev(UCLASS_BLKMAP, dev, uc) { + bm = dev_get_plat(dev); + bd = dev_get_uclass_plat(bm->blk); + + list_for_each_entry(bms, &bm->slices, node) { + if (!blkmap_mem_preserve_slice(bms)) + continue; + + bmm = container_of(bms, struct blkmap_mem, slice); + addr = (ulong)(uintptr_t)bmm->addr; + size = (u32)bms->blkcnt << bd->log2blksz; + ret = cb(ctx, addr, size); + if (ret) + return ret; + } + } + + return 0; + +} + int blkmap_destroy(struct udevice *dev) { int err; diff --git a/include/blkmap.h b/include/blkmap.h index 754d8671b01..30ce80c0ad1 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -7,6 +7,7 @@ #ifndef _BLKMAP_H #define _BLKMAP_H +#include #include /** @@ -104,4 +105,20 @@ int blkmap_destroy(struct udevice *dev); int blkmap_create_ramdisk(const char *label, ulong image_addr, ulong image_size, struct udevice **devp); +/** + * blkmap_get_preserved_pmem_slice() - Look for memory mapped preserved slice + * @cb: Callback function to call for the blkmap slice + * @ctx: Argument to be passed to the callback function + * + * The function is used to iterate through all the blkmap slices, looking + * specifically for memory mapped blkmap mapping which has been + * created with the preserve attribute. The function looks for such slices + * with the relevant attributes and then calls the callback function which + * then does additional configuration as needed. + * + * Return: 0 on success, negative error on failure + */ +int blkmap_get_preserved_pmem_slice(int (*cb)(void *ctx, ulong addr, + u32 size), void *ctx); + #endif /* _BLKMAP_H */ diff --git a/include/efi.h b/include/efi.h index d005cb6181e..f9bbb175c3a 100644 --- a/include/efi.h +++ b/include/efi.h @@ -705,4 +705,17 @@ static inline bool efi_use_host_arch(void) */ int efi_get_pxe_arch(void); +/** + * fdt_efi_pmem_setup() - Pmem setup in DT and EFI memory map + * @fdt: Devicetree to add the pmem nodes to + * + * Iterate through all the blkmap devices, look for BLKMAP_MEM devices, + * and add pmem nodes corresponding to the blkmap slice to the + * devicetree along with removing the corresponding region from the + * EFI memory map. + * + * Returns: 0 on success, negative error on failure + */ +int fdt_efi_pmem_setup(void *fdt); + #endif /* _LINUX_EFI_H */ diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 04b2efc4a3b..ebe819ea58d 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -5,6 +5,7 @@ #define LOG_CATEGORY LOGC_EFI +#include #include #include #include @@ -680,3 +681,42 @@ out: return ret; } + +/** + * pmem_node_efi_memmap_setup() - Add pmem node and tweak EFI memmap + * @fdt: The devicetree to which pmem node is added + * @addr: start address of the pmem node + * @size: size of the memory of the pmem node + * + * The function adds the pmem node to the device-tree along with removing + * the corresponding region from the EFI memory map. Used primarily to + * pass the information of a RAM based ISO image to the OS. + * + * Return: 0 on success, -ve value on error + */ +static int pmem_node_efi_memmap_setup(void *fdt, ulong addr, u32 size) +{ + int ret; + efi_status_t status; + + ret = fdt_fixup_pmem_region(fdt, addr, size); + if (ret) { + log_err("Failed to setup pmem node for addr %#lx, size %#x, err %d\n", + addr, size, ret); + return ret; + } + + status = efi_remove_memory_map(addr, size, + EFI_CONVENTIONAL_MEMORY); + if (status != EFI_SUCCESS) + return -1; + + return 0; +} + +int fdt_efi_pmem_setup(void *fdt) +{ + + return blkmap_get_preserved_pmem_slice(pmem_node_efi_memmap_setup, + fdt); +}