From patchwork Mon Mar 17 08:33:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 874151 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1869922wrq; Mon, 17 Mar 2025 01:35:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVX6WDoq6dMI8S0bS25IMv8f3cd567CZDUTNLOiNaACcuASoeGnkuEfS5+vkLwxMFvBXuT+hg==@linaro.org X-Google-Smtp-Source: AGHT+IHzxYlD2JXPeJe4l/dDx2uAPNmfrDBeeh22oKc1Qz8Dcb8BCOXY+lnW0PQrByPCQkKWAPrC X-Received: by 2002:a17:907:9694:b0:abf:7406:a5c3 with SMTP id a640c23a62f3a-ac3303dc7camr1414333666b.51.1742200516299; Mon, 17 Mar 2025 01:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742200516; cv=none; d=google.com; s=arc-20240605; b=FaFsimQHtgIm4v/GNWJrC3HQ229b9WVmFQKCYEn1b3yoW0zSlNBzvq11/uvtXPvGb0 f1mcU59mfMIuNyVh9oQz+j2hQ5/x79TvXQIfOW8w2NQaNF8CypcweVnDl39mjMcSyENF Snxkd/3oSGkGAWXFMAh81Uch0VmJz+9vjvjdnFFvmvNcie/lI9Gza04fZbdAfcPU5HMg kXS4e+Vr7nTOf62ku9BDb1vYCQCL29Sa2nWCaGPk+x7asVAiAkl/2ZB27dw4QtJixM6Y 9qX8+Jkinr2WIp/9nXC5OvBv3w5GSRb5kw2DbtpHIPcbYyNOzjgMIrFrByIgxAB4Mz9G /ogA== 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=GhkUqpzym1+JTcfqWpKYq1xQBhgV4qAd4X2TOcuwvS4=; fh=Evn5eBx2ytD/hj+tB8Xv1T61prWYrP0E59LRKWAPORI=; b=Sjm1K0MKczWoyL57OOOzcDW3GUnm5hTTat01ju+ydPYbTFal979qfj92moBprGOK06 6r/bt0eYxI1xtx0kZ7V2bw7D0NU9Y4N8OvGHXPA2mARnrywEAIL5fuzc6+ED3qCCf7tz 0IXLPx9apH+ju0uoAL01fm1bJ6EQZ0qpM/sulJPqg2D43PS7z+TmL+kazYpKut5ew/Ee lIfzNi1EjmnVr4yxI5BCl+JGj04Swu5ufHXhD62m/spIKpSK/uCuPqUCWhRwKW3fX5WB 9ler0RE2UeuAkHpZLnU5whH5wm4yTpMEmZyrYdkGWXzBLg1JWX2uFV/gRu3qw9uHGsS8 ZVCw==; 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 4fb4d7f45d1cf-5e816935ba3si7164275a12.38.2025.03.17.01.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 01:35:16 -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 96CC88141E; Mon, 17 Mar 2025 09:34:46 +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 EB1F081A0E; Mon, 17 Mar 2025 09:34:44 +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 9DD54817EC for ; Mon, 17 Mar 2025 09:34:42 +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 C64C113D5; Mon, 17 Mar 2025 01:34:50 -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 0882D3F673; Mon, 17 Mar 2025 01:34:38 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Tom Rini , Heinrich Schuchardt , Anton Antonov , Tobias Waldekranz , Sughosh Ganu Subject: [PATCH v9 5/8] efi_loader: remove memory occupied by a ramdisk from EFI memory map Date: Mon, 17 Mar 2025 14:03:59 +0530 Message-Id: <20250317083402.412310-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317083402.412310-1-sughosh.ganu@linaro.org> References: <20250317083402.412310-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 From: Ilias Apalodimas ACPI has NFIT and NVDIMM support to provide ramdisks to the OS. Linux and device trees have support for persistent memory(pmem) devices. The firmware can then add a pmem node for the region of memory occupied by the ramdisk when passing the device-tree to the OS. It's worth noting that for linux to instantiate the /dev/pmemX device, the memory described in the pmem node has to be omitted from the EFI memory map we hand over to the OS if ZONE_DEVICES and SPARSEMEM is enabled. With those enabled the pmem driver ends up calling devm_memremap_pages() instead of devm_memremap(). The latter works whether the memory is omitted or marked as reserved, but mapping pages only works if the memory is omitted. On top of that, depending on how the kernel is configured, that memory area must be page aligned or 2MiB aligned. PowerPC is an exception here and requires 16MiB alignment, but since we don't have EFI support for it, limit the alignment to 2MiB. Ensure that the ISO image is 2MiB aligned and remove the region occupied by the image from the EFI memory map. Signed-off-by: Ilias Apalodimas Signed-off-by: Sughosh Ganu --- * Re-word the commit message to indicate that the ramdisk region is being removed from the EFI memory map * Fix the comment in prepare_loaded_image() on similar lines as above * s/pmem memory area/pmem memory areas/ * s/MB/MiB/g lib/efi_loader/efi_bootmgr.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index c6124c590d9..f9534ef85ed 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include static const struct efi_boot_services *bs; static const struct efi_runtime_services *rs; @@ -348,6 +350,7 @@ static efi_status_t prepare_loaded_image(u16 *label, ulong addr, ulong size, struct efi_device_path **dp, struct udevice **blk) { + u64 pages; efi_status_t ret; struct udevice *ramdisk_blk; @@ -362,13 +365,18 @@ static efi_status_t prepare_loaded_image(u16 *label, ulong addr, ulong size, } /* - * TODO: expose the ramdisk to OS. - * Need to pass the ramdisk information by the architecture-specific - * methods such as 'pmem' device-tree node. + * Linux supports 'pmem' which allows OS installers to find, reclaim + * the mounted images and continue the installation since the contents + * of the pmem region are treated as local media. + * + * The memory regions used for it needs to be carved out of the EFI + * memory map. */ - ret = efi_add_memory_map(addr, size, EFI_RESERVED_MEMORY_TYPE); + pages = efi_size_in_pages(size + (addr & EFI_PAGE_MASK)); + ret = efi_update_memory_map(addr, pages, EFI_CONVENTIONAL_MEMORY, + false, true); if (ret != EFI_SUCCESS) { - log_err("Memory reservation failed\n"); + log_err("Failed to reserve memory\n"); goto err; } @@ -490,6 +498,13 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, ret = EFI_INVALID_PARAMETER; goto err; } + /* + * Depending on the kernel configuration, pmem memory areas must be + * page aligned or 2MiB aligned. PowerPC is an exception here and + * requires 16MiB alignment, but since we don't have EFI support for + * it, limit the alignment to 2MiB. + */ + image_size = ALIGN(image_size, SZ_2M); /* * If the file extension is ".iso" or ".img", mount it and try to load