From patchwork Fri Oct 25 11:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 838337 Delivered-To: patch@linaro.org Received: by 2002:adf:e287:0:b0:37d:45d0:187 with SMTP id v7csp210811wri; Fri, 25 Oct 2024 04:15:39 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXfCPslo5JyXGPOzMl8Bax9mPIF3wBq1jFy9B7QNFaDGLcMkfCQDNLgD6YM8HKg/3shx9Z3hw==@linaro.org X-Google-Smtp-Source: AGHT+IERMDmoAxPunIjExLTRfQdJB2eJl3ZcoexbKs2FbgMl9u8aMTQ3wRVI9e5eBhvYnemm9XH6 X-Received: by 2002:a2e:be9f:0:b0:2fb:955e:5c17 with SMTP id 38308e7fff4ca-2fc9d5e5bc2mr53915701fa.40.1729854939052; Fri, 25 Oct 2024 04:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729854939; cv=none; d=google.com; s=arc-20240605; b=PHFA7YPtnmFBT2Q1k2jFC3qlb5rDgJQjfktRY6sapBkr/54QfhYihl2vXGH4tryy8i idvs/wtLNeKkq7FM3P1TEnnZB07FcXr22kRCyghiRZVDJTGjpjo319CbSGx0yncGY8Md Fd/HgcXtJHUX5My6V9tL5us36t/FAZgMStdjBU8+0whBj77hB5t7IOS2LraKBrLaOazr yTGvQ2f27tpnJEoVviRrXHO8oePsQmAcNUEblP176Gn5vi4pgDmG9DG8+XxU8/AEA3Yv TrNg1DllSSA7ESdTDAo8ukN1IIBi9VjpeyBx0kyp/bHPBfG/Ys0RIgG1y1K7X5jpdKJI r0Tg== 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=Rt4MAL6XI+osu7NM0mLBmrxUTxCqC8LCJDvlHmCsfLU=; fh=u6ljpCS4uZ/kj1Y8Zoinr3YBaBeaYO7JTxZPQgvPhM8=; b=EpXmykvmMI5JFIOOOdsfE9vZWBhozT/8l2S5MGmBze5O5yYj2TJnyplrh5hyZrFC2Y 24PQ/PuETeuvkJynvVdtUlFFvreMLqRCwUm1kBnrjomGYOFRsHz3fFBglSRdTvfgUwiV R2dFlz/lnbVtv+QZyGjJ3nhVOzgr6Hz4Giv4OY/sMIXx7S6Gu8b0oz5rbPs8br1M2k/Y bejSdThRNCebANm+sWNHyXl2wkuxndoshR/AJqUD3L0HeREl2k7bbzeReqy/JSo4tYrL kwhCTD6Ee0LDqTrCvzuwjxJjuMqsSkrs5O9iVHKLOFTWDMDtyK95LUHurfVf4fVtWYGT lV6w==; 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 38308e7fff4ca-2fcb4636e41si2806971fa.551.2024.10.25.04.15.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 04:15:39 -0700 (PDT) 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 C439189016; Fri, 25 Oct 2024 13:15:04 +0200 (CEST) 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 350B889001; Fri, 25 Oct 2024 13:14:59 +0200 (CEST) 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_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_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 0FFF888F47 for ; Fri, 25 Oct 2024 13:14:55 +0200 (CEST) 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 349D5497; Fri, 25 Oct 2024 04:15:24 -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 9A4BD3F73B; Fri, 25 Oct 2024 04:14:52 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Tom Rini , Sughosh Ganu Subject: [PATCH 3/4] efi_loader: preserve installer images in pmem Date: Fri, 25 Oct 2024 16:44:10 +0530 Message-Id: <20241025111411.165904-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241025111411.165904-1-sughosh.ganu@linaro.org> References: <20241025111411.165904-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 --- 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 a3aa2b8d1b..16f75555f6 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; @@ -358,13 +360,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; } @@ -486,6 +491,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