From patchwork Mon Mar 10 11:57:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 872195 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp942005wri; Mon, 10 Mar 2025 04:58:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWUmAdhGQVCgbR/onypdJXd43l+tfXVblppcXqnDWqd2PoDldDlAcAZrDz84o/wEYbgH8Y9AQ==@linaro.org X-Google-Smtp-Source: AGHT+IHWCe6RDpUL/VU5SO1YH1rKe8uD1jKqMovsTNW7dO3HBtm+BvU4Y4Bmfiz3i0CJfePUSejY X-Received: by 2002:a05:690c:6813:b0:6fe:aa66:5d75 with SMTP id 00721157ae682-6febf2c4544mr191223567b3.10.1741607899100; Mon, 10 Mar 2025 04:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1741607899; cv=none; d=google.com; s=arc-20240605; b=WrquuukLTQZHg067VdgmZDvw1qtS9xeU8wFBz6euH79kGcGI5pUU+hVplOexUvedid ihfAaDHdWDnLCUkigfP+c2wLsCAhylr9rhSM5GsbHiGXrnJpPSIuUVYS926DIZb15RGn IrgxLcG6bSJ4dD1N+NdnJzT7KcAwgcCxUSlTtWeVri5Xb484+H9L9TH0G1QPwWu06tYj mQqKXYh+chg6LfvKJRzhbJT2G3UFJJ6071g1/iquqJ4rHm0ywepficS7STBQteP1jSXV THg7C+utcoWvJdY9kymWdiJXXnjASm4riMPcArL9ASaDmCk7bhxxO9nRf4mdMTErXpy6 9Wzg== 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=z2Vg55UGUfpWVZPi5ggShoWXJcoNSY4EEZW4EyWRJeo=; fh=WIErNPtEyr4LSk0kn+FyUcnvc47vQRNxykSeJQzwMAA=; b=IaEIa1tiFvywauUNqwCFCXJdmGI0+Y0HYYvn+Yh7ZiHz9i0YYZXzYP2mArwFdMOJnX vaZ6lGBBFItdh6X5HeSQLuEqOMmJMtl09giG/YkiggN+vynFM9u34XY+B0Tejd23JDgZ 27a73dzchBFk8Mo8FSfUx3s5f80zSkg7RNTrjp0q9DLGv8ciirV9GTW6sG83cmEt5OW+ b9fCno8ov1RlwcFbjlk57zKwPHz0LMo3i6XIodtWVE0il+165vT827kyQHy+GpOd66Fc /B6usAqUKI5SqkqItRJnPiCUhwCbpVVe0Ct+Ef5E3JKWdv3SnhzlfbmOYnOo2HsWjSMZ vQ7Q==; 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-6fed9c1b21bsi38718537b3.374.2025.03.10.04.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 04:58:19 -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 DD9AE81417; Mon, 10 Mar 2025 12:58:12 +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 3555B8141E; Mon, 10 Mar 2025 12:58:12 +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_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 30B7281417 for ; Mon, 10 Mar 2025 12:58:10 +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 27D541516; Mon, 10 Mar 2025 04:58:21 -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 CA16C3F5A1; Mon, 10 Mar 2025 04:58:06 -0700 (PDT) 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 v7 1/8] efi_loader: remove unused code from copy_fdt() Date: Mon, 10 Mar 2025 17:27:43 +0530 Message-Id: <20250310115750.1019051-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310115750.1019051-1-sughosh.ganu@linaro.org> References: <20250310115750.1019051-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 There is logic in the copy_fdt() function which is iterating over the platform's DRAM banks and setting the fdt_ram_start variable. However, this variable is not used subsequently in the function. Remove this superfluous code. Signed-off-by: Sughosh Ganu --- Changes since V6: New patch lib/efi_loader/efi_helper.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 04b2efc4a3b..15ad042bc61 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -454,23 +454,11 @@ efi_status_t efi_env_set_load_options(efi_handle_t handle, */ static efi_status_t copy_fdt(void **fdtp) { - unsigned long fdt_ram_start = -1L, fdt_pages; + unsigned long fdt_pages; efi_status_t ret = 0; void *fdt, *new_fdt; u64 new_fdt_addr; uint fdt_size; - int i; - - for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { - u64 ram_start = gd->bd->bi_dram[i].start; - u64 ram_size = gd->bd->bi_dram[i].size; - - if (!ram_size) - continue; - - if (ram_start < fdt_ram_start) - fdt_ram_start = ram_start; - } /* * Give us at least 12 KiB of breathing room in case the device tree From patchwork Mon Mar 10 11:57:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 872196 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp942042wri; Mon, 10 Mar 2025 04:58:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXrw6gH4bLZgji5m2iOCQZXWuM9VYWw5Pr08xcxlcv27EotXdHpcpJEl7JfJu24g5YWqzLVvw==@linaro.org X-Google-Smtp-Source: AGHT+IG0GlqIFxtcUxK4tKvdjia9/GyQ83m33wvbFQ/Vc74Az4y0O+eQZRPSb2kEHq4SbIWQ4NSf X-Received: by 2002:a05:6902:218b:b0:e5b:18ff:8cf4 with SMTP id 3f1490d57ef6-e635c0f7f8fmr17684317276.5.1741607906992; Mon, 10 Mar 2025 04:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1741607906; cv=none; d=google.com; s=arc-20240605; b=QxUogFcvVocPqgkZVThX1BBtF/hqIj2R8HshYH15oNAxAUu6vs0h5V+rLVuL0L5Rug jBcuxW0F5AI7EbltkRYRw2/qRHEBgPZ6UX/sB+zeyuKL5VwZVLZTLc0kVZVW9v4+ZDWS r7/Kbn6S3GCwaOYd48ck+uTfcV4NdGX9R3WbczHY92EZnklIdpPd4xp3iL7cAWJmkZ0T HJmJz7APYKXWy7NMIFoRh2rDm6mdoqlJWoxjXiDHb2bR//f2Mc/KPIgUpySCGDQW0Gb9 UYSxA3Q26xGn5co97loXiQbaNNi+xoIdcBRl9MdLsvK8Vp3GshFm0d2D+fZRhDje3gme dsCQ== 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=42EsITw+E5qh1V7tOlARE4cCmLe0KJ8MhZjwZsGC1xQ=; fh=WIErNPtEyr4LSk0kn+FyUcnvc47vQRNxykSeJQzwMAA=; b=ADAVeaTNZVQg9mpdyQEYNIIyNnewh4txf9L0fRf5kqHuIMC0W1bFv8qCaXarqlLBkS CpEDftOo8IGOQml4DwfAbJG/3AaH1jS/xCYrNY7lHgzYL/jwNiwnhpFMzBHEhUq+Yv7c hjVy9B08f2VqqpO34yAgvPdKf4ou4jostGXlE4PCCFdzYEx5Iqcjk4xgFgPPtxFLC8a+ b4oZxywc+7SvRruj8wChvttwWSE9asA+qmHmqbfMBEXQfyvYosIokOATgdxlNYN6AbL1 prdIxXhHiza4FyhHgifbF90FnqzWXGtH1VFpzvN3GC1/5p4fe3cyuLT6KbOA4sQR8/lZ wEBA==; 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 3f1490d57ef6-e634b90d817si7671463276.605.2025.03.10.04.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 04:58:26 -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 3273581668; Mon, 10 Mar 2025 12:58:17 +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 028CE811DF; Mon, 10 Mar 2025 12:58:16 +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_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 B8CE28142D for ; Mon, 10 Mar 2025 12:58:13 +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 86CB01516; Mon, 10 Mar 2025 04:58: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 350543F5A1; Mon, 10 Mar 2025 04:58:09 -0700 (PDT) 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 v7 2/8] efi_loader: install device-tree on configuration table on every invocation Date: Mon, 10 Mar 2025 17:27:44 +0530 Message-Id: <20250310115750.1019051-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310115750.1019051-1-sughosh.ganu@linaro.org> References: <20250310115750.1019051-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_install_fdt() function is called before booting an EFI binary, either directly, or through a bootmanager. This function installs a copy of the device-tree(DT) on the EFI configuration table, which is passed on to the OS. The current logic in this function does not install a DT if the table already has a DT installed on it. However, this existing copy of the DT might not be up-to-date, or it could be a wrong DT for the image that is being booted. Always install a DT afresh to the configuration table before booting the EFI binary. Installing a new DT also involves some additional checks that are needed to clean up memory associated with the existing DT copy. Check for an existing copy, and free up that memory. Signed-off-by: Sughosh Ganu --- Changes since V6: New patch lib/efi_loader/efi_helper.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 15ad042bc61..fe25eabeaac 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -454,11 +454,27 @@ efi_status_t efi_env_set_load_options(efi_handle_t handle, */ static efi_status_t copy_fdt(void **fdtp) { - unsigned long fdt_pages; efi_status_t ret = 0; void *fdt, *new_fdt; - u64 new_fdt_addr; - uint fdt_size; + static u64 new_fdt_addr; + static ulong fdt_pages; + ulong fdt_size; + + if ((new_fdt_addr && !fdt_pages) || (fdt_pages && !new_fdt_addr)) { + log_err("%s: Fdt address/size not in the right state\n", + __func__); + return EFI_INVALID_PARAMETER; + } + + if (new_fdt_addr) { + log_debug("%s: Found allocated memory at %#llx, with %#lx pages\n", + __func__, new_fdt_addr, fdt_pages); + ret = efi_free_pages(new_fdt_addr, fdt_pages); + if (ret != EFI_SUCCESS) { + log_err("Unable to free up existing FDT memory region\n"); + return ret; + } + } /* * Give us at least 12 KiB of breathing room in case the device tree @@ -472,16 +488,20 @@ static efi_status_t copy_fdt(void **fdtp) EFI_ACPI_RECLAIM_MEMORY, fdt_pages, &new_fdt_addr); if (ret != EFI_SUCCESS) { + new_fdt_addr = fdt_pages = 0; log_err("Failed to reserve space for FDT\n"); - goto done; + return ret; } + log_debug("%s: Allocated memory at %#llx, with %#lx pages\n", + __func__, new_fdt_addr, fdt_pages); + new_fdt = (void *)(uintptr_t)new_fdt_addr; memcpy(new_fdt, fdt, fdt_totalsize(fdt)); fdt_set_totalsize(new_fdt, fdt_size); - *fdtp = (void *)(uintptr_t)new_fdt_addr; -done: - return ret; + *fdtp = new_fdt; + + return EFI_SUCCESS; } /** @@ -534,9 +554,6 @@ efi_status_t efi_install_fdt(void *fdt) const char *fdt_opt; uintptr_t fdt_addr; - /* Look for device tree that is already installed */ - if (efi_get_configuration_table(&efi_guid_fdt)) - return EFI_SUCCESS; /* Check if there is a hardware device tree */ fdt_opt = env_get("fdt_addr"); /* Use our own device tree as fallback */ From patchwork Mon Mar 10 11:57:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 872197 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp942086wri; Mon, 10 Mar 2025 04:58:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXboCNsKlx5EV7/o5mCARt8eaQPFza0AJJWIuGFrNuzuUfPCKnGdIB9IxjDOu9lKBzMfISgLg==@linaro.org X-Google-Smtp-Source: AGHT+IGP6yVhR8WpzayiBKAShmQj2qru++s16e0y/JJvS4bxPsc8HMp0MliHu2I8pS4PUUZpygQ6 X-Received: by 2002:a05:6902:1081:b0:e5a:e6eb:d444 with SMTP id 3f1490d57ef6-e635c1017e6mr18754117276.2.1741607915429; Mon, 10 Mar 2025 04:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1741607915; cv=none; d=google.com; s=arc-20240605; b=b/DGpl/gAWSIqfPw6aeRa7VFQ/6RFHmttrQxYo/oJDctOmxywsV9dAUefEJj34WTUP n1wLt4+ccqsOBnL61sA+Vxaq26cvwLGo6F8Mw8QYjoxsyM8c9KVavfTX40EGFfr+iFCo p+vf2vvhoYRyLkk66f/kw0eEHU6Ck5PkCFpEO605d79Z11ICqpW02thtXxcmf7JLcJqf rCM92PQvMcRSx2ps+EWvYk32GYVyLjZIas6SKg4FiVKh8AM2wCB255ZTDQpzy+EYdkcP qwRw+/NBGsPVsfi0u74C42t1/Uqj76DLdwvzMFlH4TWWuOjFiWWWbxCgfKwauY6Yl2ts Nhng== 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=83F8zLrC4Ime7p3GOWGt33qI69Kpl/LfW3x8LuFCP3o=; fh=ncKX6Psppa2mA/qi0jSiZhkst8cqIKIl8luKo8HO7JM=; b=RuSQEuOVvNlqgUzNNPXyh2hFFPh+qmVJabe19bk5ZvdQJbwm6GpsNGXgf1UO+ACfE2 Mw6wvmQxol5ViybKzNGzmeuwWl5z2YsyNTuP+Y/k5jEVlyshcUkbJjAC4k0IdDbYAhzc qUIHPzZXqDxzL58ZiuGKjYmpl+I50Znfr0t4LS+ZLTyUrZhM01tkkj3gqE2MHR0pEq2t tb+o0ndH3cKEs8qB/UWvB8OSUITxrgQ+MwU48bwy20lkazGIJxBwtIZ7hMSbG3cBcll+ cIqSmnCZCZo/lLLALM/Jzbvq3PG3lAmmm9cpq7p+LXRWNphPhZd8zjgnblebx2MevsKN zKhQ==; 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 3f1490d57ef6-e6365c47b3csi5699340276.599.2025.03.10.04.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 04:58:35 -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 78DF0814A4; Mon, 10 Mar 2025 12:58:21 +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 24405811DF; Mon, 10 Mar 2025 12:58:20 +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_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 43B5C8175D for ; Mon, 10 Mar 2025 12:58:17 +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 316681516; Mon, 10 Mar 2025 04:58:28 -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 93FD83F5A1; Mon, 10 Mar 2025 04:58:13 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Tom Rini , Heinrich Schuchardt , Anton Antonov , Tobias Waldekranz , Bin Meng , Masahisa Kojima , Sughosh Ganu Subject: [PATCH v7 3/8] fdt: add support for adding pmem nodes Date: Mon, 10 Mar 2025 17:27:45 +0530 Message-Id: <20250310115750.1019051-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310115750.1019051-1-sughosh.ganu@linaro.org> References: <20250310115750.1019051-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: Masahisa Kojima 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. So add a function that can inject a pmem node in a DT, so we can use it when launhing OS installers with EFI. [0] https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/installation_guide/chap-anaconda-boot-options#sect-boot-options-installer Signed-off-by: Masahisa Kojima Signed-off-by: Sughosh Ganu --- Changes since V6: None boot/fdt_support.c | 41 ++++++++++++++++++++++++++++++++++++++++- include/fdt_support.h | 14 ++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/boot/fdt_support.c b/boot/fdt_support.c index 49efeec3681..e20b9759138 100644 --- a/boot/fdt_support.c +++ b/boot/fdt_support.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -464,7 +465,6 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat, do_fixup_by_compat(fdt, compat, prop, &tmp, 4, create); } -#ifdef CONFIG_ARCH_FIXUP_FDT_MEMORY /* * fdt_pack_reg - pack address and size array into the "reg"-suitable stream */ @@ -493,6 +493,7 @@ static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size, return p - (char *)buf; } +#ifdef CONFIG_ARCH_FIXUP_FDT_MEMORY #if CONFIG_NR_DRAM_BANKS > 4 #define MEMORY_BANKS_MAX CONFIG_NR_DRAM_BANKS #else @@ -2222,3 +2223,41 @@ int fdt_valid(struct fdt_header **blobp) } return 1; } + +int fdt_fixup_pmem_region(void *blob, ulong addr, u32 size) +{ + u64 pmem_start[2] = { 0 }; + u64 pmem_size[2] = { 0 }; + char pmem_node[32] = {0}; + int nodeoffset, len; + int err; + u8 tmp[4 * 16]; /* Up to 64-bit address + 64-bit size */ + + if (!IS_ALIGNED(addr, SZ_2M) || !IS_ALIGNED(addr + size, SZ_2M)) { + printf("Start and end address must be 2MiB aligned\n"); + return -1; + } + + snprintf(pmem_node, sizeof(pmem_node), "pmem@%lx", addr); + nodeoffset = fdt_find_or_add_subnode(blob, 0, pmem_node); + if (nodeoffset < 0) + return nodeoffset; + + err = fdt_setprop_string(blob, nodeoffset, "compatible", "pmem-region"); + if (err) + return err; + err = fdt_setprop_empty(blob, nodeoffset, "volatile"); + if (err) + return err; + pmem_start[0] = addr; + pmem_size[0] = size; + len = fdt_pack_reg(blob, tmp, pmem_start, pmem_size, 1); + err = fdt_setprop(blob, nodeoffset, "reg", tmp, len); + if (err < 0) { + printf("WARNING: could not set pmem %s %s.\n", "reg", + fdt_strerror(err)); + return err; + } + + return 0; +} diff --git a/include/fdt_support.h b/include/fdt_support.h index f0ad2e6b365..b72cd2920de 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -507,4 +507,18 @@ void fdt_fixup_pstore(void *blob); */ int fdt_kaslrseed(void *blob, bool overwrite); +/** + * fdt_fixup_pmem_region() - add a pmem node on the device tree + * + * This functions adds/updates a pmem node to the device tree. + * Usually used with EFI installers to preserve installer + * images + * + * @blob: device tree provided by caller + * @addr: start address of the pmem node + * @size: size of the memory of the pmem node + * Return: 0 on success or < 0 on failure + */ +int fdt_fixup_pmem_region(void *blob, ulong addr, u32 size); + #endif /* ifndef __FDT_SUPPORT_H */ From patchwork Mon Mar 10 11:57:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 872198 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp942157wri; Mon, 10 Mar 2025 04:58:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUZoXZdZLHT3Uy+SIj/0qpDqRdsGJ+21LcfAbCbvRT14cLj0HxqHcp5OxKwuxhVKYpSDL+h8A==@linaro.org X-Google-Smtp-Source: AGHT+IGfLOmzGVciYf9Tx24ZSgHuAPyKtFmKb8mlP300qItBkmTlSmmkzneGhCaKzJRnNoAdTFE0 X-Received: by 2002:a05:6902:2702:b0:e5a:e897:2846 with SMTP id 3f1490d57ef6-e635c13dc87mr15596628276.16.1741607927184; Mon, 10 Mar 2025 04:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1741607927; cv=none; d=google.com; s=arc-20240605; b=E9cgxvZTjHW7tOFAfC4q85hFNcjOKJFNUKQyQFq/Puhz7xhQ1bfxkMRKh7YTwY4owM ryjyNWyQ3RoAVPQv/7+BChUnz+4qJEOnHzokOaiCvL2ldkMmemmkN+PblW6h3+Lod+mL T9WDtTElYBzh56vTWWRv7Vle0a0yJF7RoUfQ1XQ8ESA357dIS1CNNDHcsh0BJd/v1QxR QXbUjhqNXEJeNVpdPvEQuIJcT1WoRuBHRD4gwrKqnMFv3CS+ASwKgO55edltxsLUKouK PUAF6wBuTHKPZBTTD9CjtJze1n9Z1pteTwWvoGjFLfvf45rdkRkfrlj6n3CrK2NG5Ust ++eQ== 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=KpqQPnLluWN5j8HfayyYu83iYA08htaTtFnKb7NQxd8=; fh=z2jt2+4Oxfk+w1FdonL0uXC75CEnFQeSOhmLSw9OoY0=; b=LL0OLZV8hjfLWcP3nRzyo/his4KLDquWUY5DX3iaERzN0nBVf/+EGlxQTQOeQhqO3s MCz5KCcJ6mhLgpXfBLfKnChhG6nfxg0WFwpya+8FkBzJdpntzZW4BhP8WTLR8rRqNif+ S9rHtxWHJmZFpJC8afk0U0TWg3hi6pWOHosWtKdn5X2Nsi99V2wPovqoPwmQEWk6a/Hx hd4ZzJyyNjnrleU9h3xhXEeBBFhHFKoNNzLqcHdU8czTsjE69IL0CN5cXpiYHmrh+rdi joVasKpRmOR1Ml+zOggIAUmAJdwHVV9/FCPL4AwcjW/hkFTeFjyGKHC7O0UP/lovgGwQ tarw==; 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 3f1490d57ef6-e636cab1dccsi5019993276.346.2025.03.10.04.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 04:58:47 -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 C131B817A5; Mon, 10 Mar 2025 12:58:23 +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 2C4C3817A5; Mon, 10 Mar 2025 12:58:23 +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_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 D86E9811DF for ; Mon, 10 Mar 2025 12:58:20 +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 D01FF1516; Mon, 10 Mar 2025 04:58:31 -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 3EAAD3F5A1; Mon, 10 Mar 2025 04:58:16 -0700 (PDT) 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 , Heinrich Schuchardt Subject: [PATCH v7 4/8] efi_loader: add a function to remove memory from the EFI map Date: Mon, 10 Mar 2025 17:27:46 +0530 Message-Id: <20250310115750.1019051-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310115750.1019051-1-sughosh.ganu@linaro.org> References: <20250310115750.1019051-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 With upcoming changes supporting pmem nodes, we need to remove the pmem area from the EFI memory map. Add a function to do that. Signed-off-by: Ilias Apalodimas Signed-off-by: Sughosh Ganu Reviewed-by: Heinrich Schuchardt --- Changes since V6: None include/efi_loader.h | 18 ++++++++++++ lib/efi_loader/efi_memory.c | 56 ++++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 1d75d97ebbc..0ac00911598 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -852,6 +852,24 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, /* Adds a range into the EFI memory map */ efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type); +/** + * efi_update_memory_map() - update the memory map by adding/removing pages + * + * @start: start address, must be a multiple of + * EFI_PAGE_SIZE + * @pages: number of pages to add + * @memory_type: type of memory added + * @overlap_conventional: region may only overlap free(conventional) + * memory + * @remove: remove memory map + * Return: status code + */ +efi_status_t efi_update_memory_map(u64 start, u64 pages, int memory_type, + bool overlap_conventional, bool remove); + +/* Remove memory from the EFI memory map */ +efi_status_t efi_remove_memory_map(u64 start, u64 size, int memory_type); + /* Called by board init to initialize the EFI drivers */ efi_status_t efi_driver_init(void); /* Called when a block device is added */ diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 6d00b186250..3fec40b6de5 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -258,7 +258,7 @@ static s64 efi_mem_carve_out(struct efi_mem_list *map, } /** - * efi_add_memory_map_pg() - add pages to the memory map + * efi_update_memory_map() - update the memory map by adding/removing pages * * @start: start address, must be a multiple of * EFI_PAGE_SIZE @@ -266,12 +266,11 @@ static s64 efi_mem_carve_out(struct efi_mem_list *map, * @memory_type: type of memory added * @overlap_conventional: region may only overlap free(conventional) * memory + * @remove: remove memory map * Return: status code */ -static -efi_status_t efi_add_memory_map_pg(u64 start, u64 pages, - int memory_type, - bool overlap_conventional) +efi_status_t efi_update_memory_map(u64 start, u64 pages, int memory_type, + bool overlap_conventional, bool remove) { struct efi_mem_list *lmem; struct efi_mem_list *newlist; @@ -279,9 +278,9 @@ efi_status_t efi_add_memory_map_pg(u64 start, u64 pages, uint64_t carved_pages = 0; struct efi_event *evt; - EFI_PRINT("%s: 0x%llx 0x%llx %d %s\n", __func__, + EFI_PRINT("%s: 0x%llx 0x%llx %d %s %s\n", __func__, start, pages, memory_type, overlap_conventional ? - "yes" : "no"); + "yes" : "no", remove ? "remove" : "add"); if (memory_type >= EFI_MAX_MEMORY_TYPE) return EFI_INVALID_PARAMETER; @@ -364,7 +363,10 @@ efi_status_t efi_add_memory_map_pg(u64 start, u64 pages, } /* Add our new map */ - list_add_tail(&newlist->link, &efi_mem); + if (!remove) + list_add_tail(&newlist->link, &efi_mem); + else + free(newlist); /* And make sure memory is listed in descending order */ efi_mem_sort(); @@ -401,7 +403,29 @@ efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type) pages = efi_size_in_pages(size + (start & EFI_PAGE_MASK)); start &= ~EFI_PAGE_MASK; - return efi_add_memory_map_pg(start, pages, memory_type, false); + return efi_update_memory_map(start, pages, memory_type, false, false); +} + +/** + * efi_remove_memory_map() - remove memory area to the memory map + * + * @start: start address of the memory area + * @size: length in bytes of the memory area + * @memory_type: type of memory removed + * + * Return: status code + * + * This function automatically aligns the start and size of the memory area + * to EFI_PAGE_SIZE. + */ +efi_status_t efi_remove_memory_map(u64 start, u64 size, int memory_type) +{ + u64 pages; + + pages = efi_size_in_pages(size + (start & EFI_PAGE_MASK)); + start &= ~EFI_PAGE_MASK; + + return efi_update_memory_map(start, pages, memory_type, false, true); } /** @@ -502,7 +526,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, efi_addr = (u64)(uintptr_t)map_sysmem(addr, 0); /* Reserve that map in our memory maps */ - ret = efi_add_memory_map_pg(efi_addr, pages, memory_type, true); + ret = efi_update_memory_map(efi_addr, pages, memory_type, true, false); if (ret != EFI_SUCCESS) { /* Map would overlap, bail out */ lmb_free_flags(addr, (u64)pages << EFI_PAGE_SHIFT, flags); @@ -823,8 +847,8 @@ static void add_u_boot_and_runtime(void) uboot_stack_size) & ~EFI_PAGE_MASK; uboot_pages = ((uintptr_t)map_sysmem(gd->ram_top - 1, 0) - uboot_start + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; - efi_add_memory_map_pg(uboot_start, uboot_pages, EFI_BOOT_SERVICES_CODE, - false); + efi_update_memory_map(uboot_start, uboot_pages, EFI_BOOT_SERVICES_CODE, + false, false); #if defined(__aarch64__) /* * Runtime Services must be 64KiB aligned according to the @@ -842,8 +866,8 @@ static void add_u_boot_and_runtime(void) runtime_end = (uintptr_t)__efi_runtime_stop; runtime_end = (runtime_end + runtime_mask) & ~runtime_mask; runtime_pages = (runtime_end - runtime_start) >> EFI_PAGE_SHIFT; - efi_add_memory_map_pg(runtime_start, runtime_pages, - EFI_RUNTIME_SERVICES_CODE, false); + efi_update_memory_map(runtime_start, runtime_pages, + EFI_RUNTIME_SERVICES_CODE, false, false); } int efi_memory_init(void) @@ -878,11 +902,11 @@ int efi_map_update_notify(phys_addr_t addr, phys_size_t size, pages = efi_size_in_pages(size + (efi_addr & EFI_PAGE_MASK)); efi_addr &= ~EFI_PAGE_MASK; - status = efi_add_memory_map_pg(efi_addr, pages, + status = efi_update_memory_map(efi_addr, pages, op == LMB_MAP_OP_RESERVE ? EFI_BOOT_SERVICES_DATA : EFI_CONVENTIONAL_MEMORY, - false); + false, false); if (status != EFI_SUCCESS) { log_err("LMB Map notify failure %lu\n", status & ~EFI_ERROR_MASK); From patchwork Mon Mar 10 11:57:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 872199 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp942203wri; Mon, 10 Mar 2025 04:58:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUtuaQAoMG9CsAWzoa2LXs3TkuvAkyhpOFNAXTfsICabHmalTno00DBBKjrLHgtCN+xdegYhA==@linaro.org X-Google-Smtp-Source: AGHT+IFthM/qdLrUUvzt8fW0BQYkUQZXdpnnUelV4T+qkF9F1uXaoWB1rfm3s/RutCd/DEmzZU4t X-Received: by 2002:a05:6902:1896:b0:e5e:758:10e1 with SMTP id 3f1490d57ef6-e635c179ce9mr18733867276.23.1741607933253; Mon, 10 Mar 2025 04:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1741607933; cv=none; d=google.com; s=arc-20240605; b=Gn6+NuIK878QPquNKY58ENYAoDWBHQQfWWjCM/OfhLNzY9Cny8uy1SUTzoK1XCOFcS F2WY9KJCWp0Wz1GitWzwzHkJqtb6h5+0oYDV+CIXiYgssnWp5xGV5Q0S/5ZIGaOVrTdh BKX55ko262eWCMfI4+HsMwUYoFNqLlfEfv/95V33jHt6Xe0Dtgt2yChktFW1VLvmNDwK wvmmTZLG8OPu3krgLzC39zmXNDHMS8xrnzdu2SsZCjzIJMotE5GErj597EgNj7qTp7tN 6GKDUqU9Nfp8iB1sH3Uw54mg2Rh1zMffpjjMB1kKT3ksg2fc11ZjI9n6r5wqfa2Y3kGD U7Pw== 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=Q4zt25fSj04RV45EgKzuA7uh4IldG38NgoyyMo6Vw+w=; fh=WIErNPtEyr4LSk0kn+FyUcnvc47vQRNxykSeJQzwMAA=; b=TiDQ7ciDRUHf25g36LVNmoWuNT6KZgXrxP2+S7XWpC2GZWRdI3CBWk8C/aJ7Z9tYkK kMtNMW+F8rkSBqG8cS1ZSgHw29rieTvSwrS9Z/KkoJ3Z/QuevwTJwj1x3huPh2IoXFQY D4eN4/daV2uSgLIRg8wI8l7DiG/wg/JTLICDvqMMtfIamR1n6K3WSCdFOXlPh1dw4dTF Z8v789iUTxusyDe8KYOZmhIH825rcFddelXkxiZx6wz5DZkSbj+C/pfP4JmAw6Lkv/JQ K4Sc+1wVYUjTUnWoPOFz2OI6jlkKLw3l/dUGDmWezJzUiEBJNvopJUMnodmImdHL0WCi 4CBg==; 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 3f1490d57ef6-e634b70cb61si8118744276.87.2025.03.10.04.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 04:58:53 -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 12FCF8164E; Mon, 10 Mar 2025 12:58:28 +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 983CC811DF; Mon, 10 Mar 2025 12:58:26 +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_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 4DA428186D for ; Mon, 10 Mar 2025 12:58:24 +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 3B232153B; Mon, 10 Mar 2025 04:58:35 -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 DD8633F5A1; Mon, 10 Mar 2025 04:58:20 -0700 (PDT) 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 v7 5/8] efi_loader: preserve installer images in pmem Date: Mon, 10 Mar 2025 17:27:47 +0530 Message-Id: <20250310115750.1019051-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310115750.1019051-1-sughosh.ganu@linaro.org> References: <20250310115750.1019051-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 V6: 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 From patchwork Mon Mar 10 11:57:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 872200 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp942271wri; Mon, 10 Mar 2025 04:59:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUi76X9VaMQXuodF+GdL5yMa1TiV5/P50J7GxHjUVHXSVsifiHgakwiVZ/JD2eGBrhlMdYEEA==@linaro.org X-Google-Smtp-Source: AGHT+IEP5896VWTN73GB4/EfZaV+6XfvmI/R268TBa5wkReERg8fzL8z6eWxhEHI2gxuRA7Iv/42 X-Received: by 2002:a05:6902:1107:b0:e57:442a:befd with SMTP id 3f1490d57ef6-e635c1c4226mr14827700276.32.1741607942423; Mon, 10 Mar 2025 04:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1741607942; cv=none; d=google.com; s=arc-20240605; b=NftPJyGgoyqSVSo5aeWLPorqvuphne6nh+li7XKyz/sDDAOuXh18uhKHls6pESwI// UKriV2DUahacKgu4Bug2Pvxd2WM7/C4ZNXbrGyUaFKkGy+i1pjLdETH9CBfZYwcgR+GC VBAkDBhZ/pbxTCPA3TDA92MP7tNFx1j0Bg0cl0+aNQMCIR7pGZVnoF6Nz0mGUMmh3mFA gwCqW524ClsZZ2H/MTLwkX9XTVaR0JH47fZwgrsKCoaQN8x/c3vtXuL60dU4hTQYSwNW L5ARadvGLC0z2dT2v47wp9tfCdh28N4d5/BzsLRIpgW/tlccEKvlHYnYphqQ4a31ckVN zCtQ== 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=aMOXHutqC5FiVDDLEx4P1jy7obI67eqZtFOrZBwmuBs=; fh=WIErNPtEyr4LSk0kn+FyUcnvc47vQRNxykSeJQzwMAA=; b=d+qWndFZSn2dZ3ZTyrPJrzHVyM0UEmgARkeWZ6AB/wVvRc2H+z+1qwLXeJcXMYk+iY ZBMAimC4ZCfj/Un5762OFnyyVJnAL3T/rKisRjktD8Sb2elXz84r9Zec5Pye5YQLdPm/ RuGM40NsAXJIFfbl5BV9kRzlujTGEI0ehiFasEwiLqXYnt4YigYIjzUJkXUWriLmpXz8 q45j/TZV1pIStk6Vr1tNZ16YbnAxPx9pZnJj6t4qEnqVNNE2jWJkGAAXDeZ0kUIOmwjD magh0o29IDR4RuFrxw4qWd0a2L0BzPJcrdk0e/MLy9jqWN/KWN4PeXoKOYlk+pWwC/5z 1pOw==; 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 3f1490d57ef6-e634b909ff8si9362133276.576.2025.03.10.04.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 04:59:02 -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 55A2E81870; Mon, 10 Mar 2025 12:58:31 +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 AC3B78169D; Mon, 10 Mar 2025 12:58:29 +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_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 A2AB0811DF for ; Mon, 10 Mar 2025 12:58:27 +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 9A5251516; Mon, 10 Mar 2025 04:58:38 -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 4874E3F5A1; Mon, 10 Mar 2025 04:58:24 -0700 (PDT) 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 v7 6/8] blkmap: store type of blkmap slice in corresponding structure Date: Mon, 10 Mar 2025 17:27:48 +0530 Message-Id: <20250310115750.1019051-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310115750.1019051-1-sughosh.ganu@linaro.org> References: <20250310115750.1019051-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 Add information about the type of blkmap slice as an attribute in the corresponding slice structure. Put information in the blkmap slice structure to identify if it is associated with a memory or linear mapped device. Which can then be used to take specific action based on the type of the blkmap slice. Signed-off-by: Sughosh Ganu Reviewed-by: Tobias Waldekranz Reviewed-by: Ilias Apalodimas --- Changes since V6: None drivers/block/blkmap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 34eed1380dc..453510cca62 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -16,6 +16,10 @@ struct blkmap; +/* Attributes of blkmap slice */ +#define BLKMAP_SLICE_LINEAR BIT(0) +#define BLKMAP_SLICE_MEM BIT(1) + /** * struct blkmap_slice - Region mapped to a blkmap * @@ -25,12 +29,14 @@ struct blkmap; * @node: List node used to associate this slice with a blkmap * @blknr: Start block number of the mapping * @blkcnt: Number of blocks covered by this mapping + * @attr: Attributes of blkmap slice */ struct blkmap_slice { struct list_head node; lbaint_t blknr; lbaint_t blkcnt; + uint attr; /** * @read: - Read from slice @@ -169,6 +175,7 @@ int blkmap_map_linear(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, .slice = { .blknr = blknr, .blkcnt = blkcnt, + .attr = BLKMAP_SLICE_LINEAR, .read = blkmap_linear_read, .write = blkmap_linear_write, @@ -248,6 +255,7 @@ int __blkmap_map_mem(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, .slice = { .blknr = blknr, .blkcnt = blkcnt, + .attr = BLKMAP_SLICE_MEM, .read = blkmap_mem_read, .write = blkmap_mem_write, From patchwork Mon Mar 10 11:57:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 872201 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp942324wri; Mon, 10 Mar 2025 04:59:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXDqEHudxFHRlRv+vtMxStPWMqmr6SGhkaSO2s4M6fc4/UmCUr3ojriL4SLTNj2LMt1yVuhxQ==@linaro.org X-Google-Smtp-Source: AGHT+IFuI6SPih96m1ViX1m6hIP37MhLanE4DSWq8L8cdALl7jh5GJrfmsLlb+SBVK5PW9Dd/C3M X-Received: by 2002:a05:690c:6112:b0:6fb:1c5a:80f8 with SMTP id 00721157ae682-6febf2b5f5fmr187068257b3.15.1741607952774; Mon, 10 Mar 2025 04:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1741607952; cv=none; d=google.com; s=arc-20240605; b=BPuFrO3Q+Mt2u2SeWWItyDYUktEcb5J85QVN2+TNiZGPsa+RrJ+BXEN6dz3ve4C0e5 ToAwPLy/ozI7+2zLJPv2Xf6lcZTctOZE8e3okh48r7XudLRTaGWkAVE9LmYm1j5fQt5G f4+4bIe/QX7K5xz8Cdpop3/ji8pBo0lm7Ct7mFIaIZ1SnejFEgueFcK4X77FR8biswpp MeenxwQUeq5NEJZpwhE/5Lsf7/plQWlBwAHZjNyUpNkky2888ryc+PBUm37tYM4XGhUR aEk3rlDha9MY8bsI65scTp45geZHfs+DHl3LNYUymMtFzrgub2Q0pTBsb0X/ncaEMblJ xIAA== 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=Bzov7iz4gLvezWtOkp/Hj7lYlsUGVtLmyrI94e2cgGI=; fh=WIErNPtEyr4LSk0kn+FyUcnvc47vQRNxykSeJQzwMAA=; b=P4u92bMdTwZ0gKObQzOl1gIM4D93RryBNxR0GA9MHpH1a26enOy8FytsUzOenuvGuo 6/m6CYnZZdLeN7n+t5XGesJeha48uL+Ry/wOTa7Vyud0fuy87SAKkwnFSKf+ljbKWsER 9f8E1f943LhNgtXTe4HHRZk5+nMTtYyfpm8ltNpcpGZKdzwSy5YqfR+vSl2liTKXQxT+ tFIR/4smRIDTn4VD9tvfhyVVZ79cNdKhHJQo+NBoo1KPo3e5jiTkvrRMIK21iw6XOxlJ /HnLUns6ZFFKKLfva3jogKdUoW5mW0jZaKorn0urEBg8WeSCizegRbHb7tHzw3lWQwTM 1hew==; 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-6feddba6d0csi35272167b3.120.2025.03.10.04.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 04:59:12 -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 9E79D816AB; Mon, 10 Mar 2025 12:58:34 +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 627A38129F; Mon, 10 Mar 2025 12:58:34 +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_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 2FB43817D8 for ; Mon, 10 Mar 2025 12:58:31 +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 0585E1516; Mon, 10 Mar 2025 04:58:42 -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 A7CE93F5A1; Mon, 10 Mar 2025 04:58:27 -0700 (PDT) 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 v7 7/8] blkmap: add an attribute to preserve the mem mapping Date: Mon, 10 Mar 2025 17:27:49 +0530 Message-Id: <20250310115750.1019051-8-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310115750.1019051-1-sughosh.ganu@linaro.org> References: <20250310115750.1019051-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 Some blkmap memory mapped devices might have to be be relevant even after U-Boot passes control to the next image as part of the platform boot. An example of such a mapping would be an OS installer ISO image, information for which has to be provided to the OS kernel. Use the 'preserve' attribute for such mappings. The code for adding a pmem node to the device-tree then checks if this attribute is set, and adds a node only for mappings which have this attribute. Signed-off-by: Sughosh Ganu Reviewed-by: Tobias Waldekranz Reviewed-by: Ilias Apalodimas --- Changes since V6: None cmd/blkmap.c | 9 +++++++-- drivers/block/blkmap.c | 12 ++++++++---- drivers/block/blkmap_helper.c | 2 +- include/blkmap.h | 4 +++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/cmd/blkmap.c b/cmd/blkmap.c index 164f80f1387..86a123b1cd3 100644 --- a/cmd/blkmap.c +++ b/cmd/blkmap.c @@ -62,13 +62,18 @@ static int do_blkmap_map_mem(struct map_ctx *ctx, int argc, char *const argv[]) { phys_addr_t addr; int err; + bool preserve = false; if (argc < 2) return CMD_RET_USAGE; addr = hextoul(argv[1], NULL); - err = blkmap_map_pmem(ctx->dev, ctx->blknr, ctx->blkcnt, addr); + if (argc == 3 && !strcmp(argv[2], "preserve")) + preserve = true; + + err = blkmap_map_pmem(ctx->dev, ctx->blknr, ctx->blkcnt, addr, + preserve); if (err) { printf("Unable to map %#llx at block 0x" LBAF ": %d\n", (unsigned long long)addr, ctx->blknr, err); @@ -221,7 +226,7 @@ U_BOOT_CMD_WITH_SUBCMDS( "blkmap create