From patchwork Wed Mar 12 08:54:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 872822 Delivered-To: patch@linaro.org Received: by 2002:a5d:64e7:0:b0:38f:210b:807b with SMTP id g7csp159366wri; Wed, 12 Mar 2025 01:55:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVawsXNV4379g6gvwiFRdueoWTcQ0QiktC0DMnqJdCjebqSOcaUotXH5LHHhEPdH4u3O3h6kg==@linaro.org X-Google-Smtp-Source: AGHT+IEf/8ZmhT/9wdvTpR7F0Ag+gwjTV6bMKeTcn+eMqzu+FZIHUF//yJmvj4kjLvH01Dd8/CAS X-Received: by 2002:a05:690c:650a:b0:6f9:50aa:b7e2 with SMTP id 00721157ae682-6febf3220f4mr308563317b3.21.1741769740788; Wed, 12 Mar 2025 01:55:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1741769740; cv=none; d=google.com; s=arc-20240605; b=Zx8/VAJcGl7uAT2aXMHDpDxlr0UTZCjxpRYZQgxC+2lV4l+md4FdcoLSKeuk9IRQZE NX3hAZi3Iq3U0SaxKLNbq5JtEsbyMa0TEERlNE/eqlmvFKxPTpcBNSoLaK0143vQrHlo PB44rdt5/WXQ/lqvM4oQOfe/cLjQbISVytOGt4w6bIs7QMQqygyIRPHX4kpfMGM8VPNd 0DvO/ZEnRHfDgvIt4IZJQ7fbsSYaqOWA2bSW+KAxObx6EziOoO6UXzKstS/KhuK9MSoV FQ5UdpenEhyIzTxvlSRA+yA45XhokEJMaFcv2dvxrlOTB2INIl/k/ukfTeaBCrmMsUsL 3Pzw== 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=8PBg36dVe+e8fWxE7HDO5GBcY79WBJztGCf2MhBvWUg=; fh=Evn5eBx2ytD/hj+tB8Xv1T61prWYrP0E59LRKWAPORI=; b=eZ9li+a7BuPe2/oQzA94+s9/9ArFg27D3THtIYd54jsTkAhd02jlYyNIUWuzjA0jdy Uc3M7AV/T/3jMk+JJlyiBSGX1/X0E9D40u+PYfI44tELONduJYPuCxSWK47TUC3Nwwky I5R2VFxzI2XlHFk8/QmknBJoLTS6r/dIt942QAHEvvGSJRNcpbRgiKuRbN1U9HenS7pD 7CGvdutzV7L5FrY/L/jA6acHYsZtL6d4DBXjPDFObIhuifBKqpZdASOfQ6gKnB0T8LVM KtQCDskEAYLI/v8LunhgQMZpAQlDh2qKPZoSBICOVuiDA93Gr/IEJBmreRNKIkyDRWT3 LLTw==; 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 00721157ae682-6fec637af96si80661577b3.384.2025.03.12.01.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 01:55:40 -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 ECE0081A0C; Wed, 12 Mar 2025 09:55:06 +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 40E51805D7; Wed, 12 Mar 2025 09:55:05 +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 00635805D7 for ; Wed, 12 Mar 2025 09:55:02 +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 39623152B; Wed, 12 Mar 2025 01:55:13 -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 D6D703F5A1; Wed, 12 Mar 2025 01:54:59 -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 v8 5/8] efi_loader: preserve installer images in pmem Date: Wed, 12 Mar 2025 14:24:21 +0530 Message-Id: <20250312085424.1201148-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250312085424.1201148-1-sughosh.ganu@linaro.org> References: <20250312085424.1201148-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 One of the problems OS installers face, when running in EFI, is that the mounted ISO after calling ExitBootServices goes away. For some distros this is a problem since they rely on finding some core packages before continuing the installation. Distros have works around this -- e.g Fedora has a special kernel command line parameter called inst.stage2 [0]. ACPI has NFIT and NVDIMM support to provide ramdisks to the OS, but we don't have anything in place for DTs. Linux and device trees have support for persistent memory devices. 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 2MB aligned. PowerPC is an exception here and requires 16MB alignment, but since we don't have EFI support for it, limit the alignment to 2MB. Ensure that the ISO image is 2MB aligned and remove the region occupied by the image from the EFI memory map. Signed-off-by: Ilias Apalodimas Signed-off-by: Sughosh Ganu --- Changes since V7: None lib/efi_loader/efi_bootmgr.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index c6124c590d9..081eff057f4 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; @@ -362,13 +364,16 @@ 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); + ret = efi_remove_memory_map(addr, size, EFI_CONVENTIONAL_MEMORY); if (ret != EFI_SUCCESS) { - log_err("Memory reservation failed\n"); + log_err("Failed to reserve memory\n"); goto err; } @@ -490,6 +495,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 area must be page + * aligned or 2MB aligned. PowerPC is an exception here and requires + * 16MB alignment, but since we don't have EFI support for it, limit + * the alignment to 2MB. + */ + image_size = ALIGN(image_size, SZ_2M); /* * If the file extension is ".iso" or ".img", mount it and try to load