From patchwork Tue Dec 3 16:36:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 846966 Delivered-To: patch@linaro.org Received: by 2002:a5d:44cd:0:b0:385:e875:8a9e with SMTP id z13csp595729wrr; Tue, 3 Dec 2024 08:36:44 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVhVRvpJVRxaRzm4qMuKWnNw14l6IwRaSz8D66lWCh7YwNwUm66PcT8FCiziASJtcEP612XOQ==@linaro.org X-Google-Smtp-Source: AGHT+IFr/0kJ+Kc4p0VNekq8wajJsgo1Ozrxvy91MWr2pUTLO6Kgtd2aLzmBfzhETwwnI5KWV4Zz X-Received: by 2002:a05:6402:27c6:b0:5d0:f6ed:4cb0 with SMTP id 4fb4d7f45d1cf-5d10cb4f110mr2782173a12.1.1733243803815; Tue, 03 Dec 2024 08:36:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733243803; cv=none; d=google.com; s=arc-20240605; b=H7a9jNMuNRZ/O62gtEoFAdHe6GBTikZGSRvK2pnVoZHELojgigqEzfee4jUe84kmlv 7Omj2Yn8GgR4EOBKOGHR9RJPy8/LwalD+EsIVKzdeU6h0bNY+pF1iBfEQvcbS/6pUzYh lkqjZkfvzhgsmo2Erqy1+StVN1B8Ums82CT4D7y2asGCejSCnGZihMpk2a4uA8Bxh9E5 TmTy5pI8zlv0jhFK7stzUKxiDYhEDouUBqrVDip1kciaADNaonWL/Fjz9T+0/G5sRV+f 7fxAwxo3mlBxxy9GnjlpAlqPCL/g0uBC3crgSnTZLSCWASqXAYGmeEO5M2wbagXyVtFf Nbzg== 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=R8h4+2Y4eSwEWKvG99XvMP+TcMX7RjLPwHwlojRAodg=; fh=rPmMTArAbwoOFNVFb2co+289VhVVNzBHoPR9c3uaLKo=; b=a7i/jL2I39655E2rw2rcX8JOah1VcY3/75BjH26GxPN6cWdiE0l9T84IocN/SBkXwS ayvwQlvulE/oTyzRX5bU6acWGE2pN7FZ3QKeWIo6Lwp5BmF7qEHOHszil3kA8QoPgVuL kYts5IBpw3Ehswz88BMFk9j4T2iMFsWb752QByNdKbG4TCr7o2pT5I4JGUxqxzX3H+Ur 1YftLyaJenD0FamfI4wqr1BLFnqymKXnXiPtYvH/uOXWq4EMP8rVUZk5D4eaip6EOpe2 lSC6SeaUrIVkhdCvuLFXTl4pG2A5rftP1DZ3kuP54+P/+7jPi2nPFfvNuA2SwIxK40pH bOSQ==; 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 4fb4d7f45d1cf-5d0c6818029si6483523a12.186.2024.12.03.08.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 08:36:43 -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 73A6B89588; Tue, 3 Dec 2024 17:36:29 +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 0B966893A9; Tue, 3 Dec 2024 17:36:28 +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 B729389538 for ; Tue, 3 Dec 2024 17:36:25 +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 2B183FEC; Tue, 3 Dec 2024 08:36:53 -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 D35AD3F71E; Tue, 3 Dec 2024 08:36:22 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Anton Antonov , Tom Rini , Sughosh Ganu Subject: [PATCH v2 3/4] efi_loader: preserve installer images in pmem Date: Tue, 3 Dec 2024 22:06:04 +0530 Message-Id: <20241203163605.1482152-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241203163605.1482152-1-sughosh.ganu@linaro.org> References: <20241203163605.1482152-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 Reviewed-by: Heinrich Schuchardt --- Changes since V1: 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 8c51a6ef2ed..b906e53e26e 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