From patchwork Mon Mar 17 08:33:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 874147 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1869765wrq; Mon, 17 Mar 2025 01:34:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUUKeIeWJgu3KfzDM73QpX7MrUDJ8CVPFaoWvJvp/h2uvrVl7iK48L2XNmQiVPZwF7R1IOsoA==@linaro.org X-Google-Smtp-Source: AGHT+IEdhEWCHYModVcRxcw1gHXlw4sFcf1iGEI+EYRNqeroB5jA95ItHUtYnlIURqtTrIBeOhln X-Received: by 2002:a17:907:2dac:b0:ac2:7a3b:31ef with SMTP id a640c23a62f3a-ac33037158bmr1439960566b.41.1742200482988; Mon, 17 Mar 2025 01:34:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742200482; cv=none; d=google.com; s=arc-20240605; b=NzBxB2M3Pxmb7g9VQx9RkTT7eFaOfWkffA6kvqA1WczaWlzV904uIqgKeSCZbHHDYE 6N4smvYNYRn6Hhngqx8laxQEk6eFEgEmbFFYcmu9GwCQNC7Ak8hIfIY3NOphq5FQ05iP dG/Uf5XShjOX2gyxq3Vtxp5dTjfvVka1pJINt4kUm4g8hyzb2Yq/w69K886DmeiJEbHA dXSwVj52xjZza9Qcs0CdY/WjyGA4Nb4ibuPU3FXvmTStbIMGDOKRDojxZMhkyqlgiiWJ X4j3YTLI96DQzwFQdFp85ENabsQTgDLerWHCO4gmP4jSHAs/NcynZmu9pAm3UxgIbfKw Bo1g== 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=qiwHl2Ke/4d5Wbftn2oIiAyMIVWt2nO/8EP2SdCkBR8=; fh=Evn5eBx2ytD/hj+tB8Xv1T61prWYrP0E59LRKWAPORI=; b=WG4Cf2sbjb3r6l7+tnuba2VyO4b4cRsLepIjTyOCaOrWUVD1Hhi3Uj9yJDtNy2n6kC 3DYWp1OHB3KrFOe55b1DQPj0pZlZTeC7xkIPhLKu4/IGrzLREwPJcYch23herAK8/fG7 /YMweUqZfe+Qi3rsbuG/bX+7amuHXmHsZDwwtltQweRjYBOdZoqLlic00kP02YsA4mGu TNKN+JPZXrymJsDNmKWQBYIWc8rbrsWlGZ8bRC2eUolSnWatiDDi3rFDti1wL78WJQjF TeKe/8qJMknjPvgI6TGo5A91KZ367Ss9LXwoTIVeYWTr5aqPt8Fs/R1FZ1fQOBcqt3CQ BkkA==; 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 a640c23a62f3a-ac33ddeac98si428366066b.777.2025.03.17.01.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 01:34:42 -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 7443E81101; Mon, 17 Mar 2025 09:34:33 +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 002E781101; Mon, 17 Mar 2025 09:34:31 +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 ECB5D80107 for ; Mon, 17 Mar 2025 09:34:29 +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 5D38813D5; Mon, 17 Mar 2025 01:34: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 E6ECB3F673; Mon, 17 Mar 2025 01:34:26 -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 1/8] efi_loader: remove unused code from copy_fdt() Date: Mon, 17 Mar 2025 14:03:55 +0530 Message-Id: <20250317083402.412310-2-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 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 Reviewed-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- Changes since V8: None 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 17 08:33:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 874148 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1869786wrq; Mon, 17 Mar 2025 01:34:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVYjV5Y0Giz6KQkIMk17WHkOL67to2r5TPpV5UY7366rZWdkRgX+TCfbWJR0LarGjcSoen3Kg==@linaro.org X-Google-Smtp-Source: AGHT+IH/++/ZowzXegqSC47yCHVHLohjfUcDkrP8IwnnowEL55OuODptL+llZMEMy2vcuTeLe11Q X-Received: by 2002:a50:99d1:0:b0:5e6:de5:312f with SMTP id 4fb4d7f45d1cf-5e8a0c14582mr8466638a12.23.1742200490288; Mon, 17 Mar 2025 01:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742200490; cv=none; d=google.com; s=arc-20240605; b=izUtg0zbfzXKWkPGxtMzYGUMnrMI+93yJ8vWree1FZC+mLamN21b9hMjklsepZqm4o iIbx/5Ts3mXD8IfEKCg5Lb/iVSdHOTgexsvpKkWvU2Hr+mmpCXVpFT0FZgGGu/jO1+FV nZlrP5CbEEcefKi/1pZmNTohcUtpfTP59vjFyBm6zn50F6LcAVa45PO0bN4NUoB9gCEz xXVVjrPbLIEpw5ySFKfIHa6ri0yCDg3ym025crJbyXnddteMAOg2jP2GpqVjc3f9Oind WnZ3OexDRwWw9QoZny90cgAGlDuJThYW4J89ZSwvxL1VA2LRo5r4Fnc6Dc9oAIJgf4tY zk4w== 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=9+FMpwQbUGKCYyUsJ/3CUsECYu9IJjLLDQ1Rq+mptZw=; fh=Evn5eBx2ytD/hj+tB8Xv1T61prWYrP0E59LRKWAPORI=; b=e1ON0sL2j3BR+XEei8U6yFNDv07B5ovJuRnSpC9wa6eefCMWz/o0mTqRJZT8z3PDTw UXeI8hhSKsDdjjvqp8+I8aPLIKAbTbadMs40hmPH97y4RfI3QFal755HoQC3FvmMhy74 2sk+v3zA/PSWWEc3fQ9wIwFa96I7/JtB7JKXElG9E5sn3ULVj7FSrdnxJDd9FkjZ+K1V ZJ/dDBoqtNV/OcZblT5ieigHw/XYpLAU97XWgmj9LOcIlhCz+my5MIBN/1iu6wur/BfY TqAQgBj1gG6MNyNoTP6AQ9gtAU/t4J1xQYLubkj5xDLCh7ScAHoXjogO2+J6nIkJiXs8 LKrg==; 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-5e816935748si6982835a12.21.2025.03.17.01.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 01:34:50 -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 BA03D8192A; Mon, 17 Mar 2025 09:34:36 +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 86E9881877; Mon, 17 Mar 2025 09:34:35 +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 4936F80107 for ; Mon, 17 Mar 2025 09:34:33 +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 A16B5169E; Mon, 17 Mar 2025 01:34:41 -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 DD0003F673; Mon, 17 Mar 2025 01:34:29 -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 2/8] efi_loader: install device-tree on configuration table on every invocation Date: Mon, 17 Mar 2025 14:03:56 +0530 Message-Id: <20250317083402.412310-3-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 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 a device-tree is already installed as an EFI configuration table. 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 V8: * Re-word the commit message to indicate DT being installed as EFI configuration table * Remove the existing EFI config table in copy_fdt() * Move assignment of new_fdt_addr and fdt_pages variables to the block freeing up the existing config table memory lib/efi_loader/efi_helper.c | 39 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 15ad042bc61..f6fbcdffe82 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -454,11 +454,30 @@ 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 efi_uintn_t fdt_pages; + ulong fdt_size; + + /* + * Remove the configuration table that might already be + * installed, ignoring EFI_NOT_FOUND if no device-tree + * is installed + */ + efi_install_configuration_table(&efi_guid_fdt, NULL); + + if (new_fdt_addr) { + log_debug("%s: Found allocated memory at %#llx, with %#zx 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"); + + new_fdt_addr = 0; + fdt_pages = 0; + } /* * Give us at least 12 KiB of breathing room in case the device tree @@ -473,15 +492,18 @@ static efi_status_t copy_fdt(void **fdtp) &new_fdt_addr); if (ret != EFI_SUCCESS) { log_err("Failed to reserve space for FDT\n"); - goto done; + return ret; } + log_debug("%s: Allocated memory at %#llx, with %#zx 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 +556,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 17 08:33:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 874149 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1869818wrq; Mon, 17 Mar 2025 01:34:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXOwVGu+QPpoZ1R95SBM0lmlXiGJVMU/I0h/PmDR7VfQjC/WI5ktvVLzMAtu2jppCJ63f2BiQ==@linaro.org X-Google-Smtp-Source: AGHT+IEiXYG2aWks0IsqB/DPb5gmnt1iWu+n0Rr5LHmEwxhH0LLbYjooIvNS6CLPaqJAREmmHKuM X-Received: by 2002:a17:907:2cc5:b0:abf:6ede:dce1 with SMTP id a640c23a62f3a-ac3301fdf30mr1216045166b.24.1742200498486; Mon, 17 Mar 2025 01:34:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742200498; cv=none; d=google.com; s=arc-20240605; b=UxWKF6UbmLRkL1PJalNZvGziVt1XX7ozuu0Uh4z37UqT3oqM2d8eVajkijxXQn1lo+ aHmdonFgeZsUpTQW63Whi17hiXtHVm3twUNB97epfHuUdFPLXGdqRpM0EzLLLZE/j1TJ mlozX+8B0riSDkpJ1nstvYjLJE9hzhcexW7XJN+LlOM8tByu9K5b2mLS5d75s2NzMq8R 4C07svZp59CS4LiS/Waa1h/9sXzuaFX+h4vUqpT1CFsb3gUf6RcpoO1yOldmgN4cuI6X g7BWueiQPuDsnzWDXTnhkxvfKFXnDXQKm+shTJmf+3pEJ4QrnTiiRgKSpb5DCWbeTVTt irkg== 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=UI/60Rzto3eUXTwWNoCoRUKzOT5tl3/CKYJi0rRrGiE=; fh=ky/3EXJ4V9VcIMC2RiXGMLRKI2lBbfUuCc6cZ3L4Gic=; b=MVkB1Mg4sA46uVE/h18cAtuzHDp8lh8mbytWeAOMmATkCMY/uIY8G1KQo/5IABwa/0 790n/O5SbpLMMpffKW3Vsp8aWA02anKWwMrOi9Aivyh4XPcJnzcIt4csTwsQj3OB9PuM 8pjQ0uC4vJzhlmFGyPPpKEndOmOKGEKOUU4crq8VkqPEG/sSrsCs9+rFUQLbeg2GFn/c HhOnwWGaeBkIo3hyGrekbnyYx/sMxMLqE7BtK5gejSygoAYoS1dHYmsxi8Gfj/W+/F+G UZe8q8ZxxV1Vt2JuLaCXvmrB1PcZ2GGhtLNzWQYeRejnX9BRzVjxXKRwRC5FCmfk71ZX iy/A==; 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 a640c23a62f3a-ac3146ab8cdsi727241566b.29.2025.03.17.01.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 01:34:58 -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 0B8D0810F4; Mon, 17 Mar 2025 09:34:40 +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 D6EB58141E; Mon, 17 Mar 2025 09:34:38 +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 3F9188058A for ; Mon, 17 Mar 2025 09:34:36 +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 850FC13D5; Mon, 17 Mar 2025 01:34:44 -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 D3BD53F673; Mon, 17 Mar 2025 01:34:32 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Tom Rini , Heinrich Schuchardt , Anton Antonov , Tobias Waldekranz , Masahisa Kojima , Sughosh Ganu Subject: [PATCH v9 3/8] fdt: add support for adding pmem nodes Date: Mon, 17 Mar 2025 14:03:57 +0530 Message-Id: <20250317083402.412310-4-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: Masahisa Kojima One of the problems an OS may face, when running in EFI, is that a mounted ISO, after calling ExitBootServices goes away, if that ISO is resident in RAM memory as a ramdisk. 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 pass information on the ramdisk the OS. Signed-off-by: Masahisa Kojima Signed-off-by: Sughosh Ganu Reviewed-by: Ilias Apalodimas --- Changes since V8: * Re-word the commit message to indicate that the ramdisk information is being passed to the OS through pmem node * Change the type of addr and size parameters to the fdt_fixup_pmem_region() as u64 * Rename the first parameter of fdt_fixup_pmem_region() as fdt instead of blob * Modify the format specifier of snprintf() call in fdt_fixup_pmem_region() accordingly * Remove pmem_start and pmem_size array variables in fdt_fixup_pmem_region() * s/pmem_node/node_name/g * Do not initialise node_name variable boot/fdt_support.c | 39 ++++++++++++++++++++++++++++++++++++++- include/fdt_support.h | 14 ++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/boot/fdt_support.c b/boot/fdt_support.c index 49efeec3681..92f2f534ee0 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,39 @@ int fdt_valid(struct fdt_header **blobp) } return 1; } + +int fdt_fixup_pmem_region(void *fdt, u64 pmem_start, u64 pmem_size) +{ + char node_name[32]; + int nodeoffset, len; + int err; + u8 tmp[4 * 16]; /* Up to 64-bit address + 64-bit size */ + + if (!IS_ALIGNED(pmem_start, SZ_2M) || + !IS_ALIGNED(pmem_start + pmem_size, SZ_2M)) { + printf("Start and end address must be 2MiB aligned\n"); + return -1; + } + + snprintf(node_name, sizeof(node_name), "pmem@%llx", pmem_start); + nodeoffset = fdt_find_or_add_subnode(fdt, 0, node_name); + if (nodeoffset < 0) + return nodeoffset; + + err = fdt_setprop_string(fdt, nodeoffset, "compatible", "pmem-region"); + if (err) + return err; + err = fdt_setprop_empty(fdt, nodeoffset, "volatile"); + if (err) + return err; + + len = fdt_pack_reg(fdt, tmp, &pmem_start, &pmem_size, 1); + err = fdt_setprop(fdt, 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..049190cf3d7 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -471,6 +471,20 @@ int fdt_valid(struct fdt_header **blobp); */ int fdt_get_cells_len(const void *blob, char *nr_cells_name); +/** + * 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 + * + * @fdt: 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 *fdt, u64 pmem_start, u64 pmem_size); + #endif /* !USE_HOSTCC */ #ifdef USE_HOSTCC From patchwork Mon Mar 17 08:33:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 874150 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1869862wrq; Mon, 17 Mar 2025 01:35:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXMJcI2CPgNbiQHb11xc0WEmp6F4h57o6styvUtXXdQyTbZ//dU+5iZOf2dm4sd9QOZ/fpoTw==@linaro.org X-Google-Smtp-Source: AGHT+IFsm8wfXzUVOKIGPPB/a4f5g6y5XFlmXVpkmsV8M8tNQPEPrKJPF+NKzvENKnPkgZkp0BgU X-Received: by 2002:a17:907:7241:b0:ac3:26ff:11a0 with SMTP id a640c23a62f3a-ac3304430damr1256579966b.38.1742200507379; Mon, 17 Mar 2025 01:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742200507; cv=none; d=google.com; s=arc-20240605; b=SvrG7M2A7dDvrjbSLjnXLfmOEW1Z2nz6hSRUdknDCGvxkPdsu/YYQQCFfrv/DhPieu bJMv7hp/Aa3ov308n5FzuUINQDLLwoylDB1OBoxGFqOFmpjsP0U7SNBtLaJz12XXnwEU EQc1aO8TDLB8JrKGBOJya1jqef/SCLSfVNpf7YPdCyD7AOP2btGXcy6PFN3l6T8f0IHF zCgvNpAyrZY6Wd0jjQW7o9JIPOkchWy5D3LajsA8smrjxRChRc32rTVoEavb7urApdjm HCZtKAZZSejSNmviaSrEx4XlHNRhwKydLyfLiM7d4ZptEBmx6rWblGxsXRTEV3QcG2PV kyRw== 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=vMGBUkA8DkU1g4IZpVXr+Pzp/ZEaklnrLcV8WjEuQzY=; fh=Evn5eBx2ytD/hj+tB8Xv1T61prWYrP0E59LRKWAPORI=; b=hWZpQqfa4GHRZSG8SJt5vHRqD/zqjB9vkoyXkpmrUTWAWkzZtR2J+tb3Tz08qdoLbx JZeHB+6m/UXA24ewDFNokabVHoQJlCtNdQcvm9tahlnyG+btwuC5nsLzvYHN8ChmcB9k Ghgm3mCxa2dNsWxgKAqKlUIwYUaTnvMqvhCG7fy8AHwvALIADazXddP99Pj58gppDiJL Fbn9KcRH38mzHZNDuvE5z64tP+B+cHM0t6vnN2x6W1qm0zBnrWcVl/dMOBwlYud6zFK4 8XqpqjslvapewvaZZqGzNu1s9QfZKQUzpaktAG4dCm4lBzKdyZTr1PEfPPK0jqw2Zm9A qaog==; 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-5e816b78b2csi7111485a12.516.2025.03.17.01.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 01:35:07 -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 51BE180F70; 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=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 64B8D81428; Mon, 17 Mar 2025 09:34:41 +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 1E4FE80107 for ; Mon, 17 Mar 2025 09:34:39 +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 84F3913D5; Mon, 17 Mar 2025 01:34:47 -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 128283F673; Mon, 17 Mar 2025 01:34:35 -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 4/8] efi_loader: allow for removal of memory from the EFI map Date: Mon, 17 Mar 2025 14:03:58 +0530 Message-Id: <20250317083402.412310-5-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 With upcoming changes supporting pmem nodes, we need to remove the pmem area from the EFI memory map. Rename efi_add_memory_map_pg() to efi_update_memory_map(), and allow removing memory from the EFI memory map. Signed-off-by: Ilias Apalodimas Signed-off-by: Sughosh Ganu --- Changes since V8: * Re-word the commit message to indicate using efi_update_memory_map() for removal of memory from the EFI memory map * Use efi_update_memory_map() for removing memory from the EFI memory map instead of adding a new function efi_remove_memory_map() include/efi_loader.h | 15 +++++++++++++++ lib/efi_loader/efi_memory.c | 34 ++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index e9c10819ba2..5f769786786 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -878,6 +878,21 @@ 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); + /* 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..487b5e302cc 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,7 @@ 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); } /** @@ -502,7 +504,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 +825,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 +844,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 +880,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 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 From patchwork Mon Mar 17 08:34:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 874152 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1869957wrq; Mon, 17 Mar 2025 01:35:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU2f5Ka4ojfAxm2MA375/z/OISOXBWzX/BrlmLXKz+W/XxoAFHhNmEi0A6oV2p8pr/Cmso2Zg==@linaro.org X-Google-Smtp-Source: AGHT+IFbKC0/DOUyv+kp7+lpjT0Djfu4WTJYYIOLmnrSNmI05kAv2fG0A59Z/J0mS6/FBqHscc8x X-Received: by 2002:a17:907:970f:b0:ac3:45b8:968c with SMTP id a640c23a62f3a-ac345b8aef5mr811560966b.1.1742200525789; Mon, 17 Mar 2025 01:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742200525; cv=none; d=google.com; s=arc-20240605; b=jIrrLC0/6xL+MreiirjNcJTk/U1qwxzfoWRVT/H5royt8Ai4hmt7dufyPY9/tD5+6C r1Hu2DZJiovvJbfvk6aryYlwxS1hh/66UMSlqY67j0EMfA1Y6294eJRCbtD03u2ISNhl qc22cSZymmm1PFtspSiho1VLASrYoEi8Z6AlVFkFAQR5anMZLBu0MgMqdnry6qzfECkm VYFEklNQZKdhhraJ6kBmM2tpKt8QeLZvihUwa6BjPbgkznsl6wVSMzY/sgUBEUJcw71r 4//yo7Q/3jlWyplwEL5xE6dd8FI0BhEiMQeJnUaF8SZlQXwiZGOuwS+W8xDl+mwpnIqt A0WA== 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=FQvCj/z4bqU1zjDlBaQwx07eBbdrUouo9dQW4ZUNVp4=; fh=Evn5eBx2ytD/hj+tB8Xv1T61prWYrP0E59LRKWAPORI=; b=Q4IPECSIKJ8DsFNnAR08e/+fDVEpqcqgvGt3FabhsoyPvfq1pF6H9AHhjvycN+hOTR 6EpSHeAQ/InjDWF/66qhmHHkj7kzByp61nyl2ty2IXIJocXVx6r0QFVjcvq6bO9UfJn8 MlmbkWaJV0n7c+7KgpYDUr8HjK+8gDSd5sws4dcr8EEEyvluaKPBSNz/yxCbdRhkgA2F Qsn6j1AO+lVwqnHMXS2o6MrGOcIMScQ83jum9aqoflg0oFyt5q9Fm0Z/5Qn2HBaG/ggM QX84PgQXyx84+Y+pqj+5gpfztwgaqVgxavqjoluJQUKrFq80qOP3zlYN4UFLcH0CM8is mtAg==; 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 a640c23a62f3a-ac314a46c37si708178366b.268.2025.03.17.01.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 01:35:25 -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 DC3BB817EC; Mon, 17 Mar 2025 09:34:48 +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 DBFFB8058A; Mon, 17 Mar 2025 09:34:47 +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 32AFB811B2 for ; Mon, 17 Mar 2025 09:34:45 +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 610ED169E; Mon, 17 Mar 2025 01:34:53 -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 F28E53F7B4; Mon, 17 Mar 2025 01:34:41 -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 6/8] blkmap: store type of blkmap slice in corresponding structure Date: Mon, 17 Mar 2025 14:04:00 +0530 Message-Id: <20250317083402.412310-7-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 Add information about the type of blkmap slices 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 V8: * s/blkmap slice/blkmap slices/ in the commit message * Add comments to the macros added in the patch drivers/block/blkmap.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 34eed1380dc..08f68570224 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -16,6 +16,22 @@ struct blkmap; +/** + * define BLKMAP_SLICE_LINEAR - Linear mapping to another block device + * + * This blkmap slice type is used for mapping to other existing block + * devices. + */ +#define BLKMAP_SLICE_LINEAR BIT(0) + +/** + * define BLKMAP_SLICE_MEM - Linear mapping to memory based block device + * + * This blkmap slice type is used for mapping to memory based block + * devices, like ramdisks. + */ +#define BLKMAP_SLICE_MEM BIT(1) + /** * struct blkmap_slice - Region mapped to a blkmap * @@ -25,12 +41,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 +187,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 +267,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 17 08:34:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 874153 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1869994wrq; Mon, 17 Mar 2025 01:35:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVIjBJBzA08UCXUt4WcjUcDi1N0LEYsjys9XkmvSxbbNIZ0Ywxuw4/Hvw6bD8toA8tU4B1dKA==@linaro.org X-Google-Smtp-Source: AGHT+IFT1AIs4UIKBn8qpCmWtbQa6ZywNSMX8lAF7d99g0qfE+9w5evFRhSUyWDYccoI1hGU07Os X-Received: by 2002:a17:906:c147:b0:ac1:791c:1532 with SMTP id a640c23a62f3a-ac330450945mr1290934266b.51.1742200534433; Mon, 17 Mar 2025 01:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742200534; cv=none; d=google.com; s=arc-20240605; b=Td6QvJ/98u3vuTd8oBcyQ9u2X/F9t8gTsbLKP9PFka7w8VRNP5fcQKhiJvvyYh5mWi u5MyzpfdqersANjMSiDmpMhJ4tk7tFyOgUIMKUG0p9Y3He3eCsFkfKoSYuNqFZVSueUu ch8yOpPqi7AvOCBDUHbXpmToFS7qtqEei7wbIPBqWPLvPch17EN85mYzCTlYF5xxRE5+ k4fVYnB7sv6mNLmpV/eUCvdWmPRUqK37lR0u0QM3DNB/+IbZMRr1k6TuOqfQcaANrLy+ cviFgICJK506nWBgkhOZRvdhv4iofiWLZ479yhzICPYYAKji8GX2qfTV0tbOJ/ZlDJh9 XpDQ== 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=luUkqL9+JF0SqDT9+6Jhnm1+6M2GEK8KBkSpVOhiGN0=; fh=Evn5eBx2ytD/hj+tB8Xv1T61prWYrP0E59LRKWAPORI=; b=jcxyj9MvkDnmOpYLcRQdpj+/XWcUvX9a/cS4UcaY0uXGqIxTcGCsy/efHr37q9lXrU 8xdZSNCjqcvNsnddX1/iBjIg5BC1R6hpqSdjeH6ThX/XvX+CFa++bs0lMgNjanqarC9a kXe4P96UINH2hNQnx59e3YerXDeAl7LhmTCbLolpkqWFFDwxnCfj2wuu6lMoS7RASD1b wQP6J4LXDoa3tyyDgv7rm61ScnrIBe2lcLW5c6csShwgM2SWIUxFHxBbjBAqzhmYhh+6 X54XmiNlV0GoSQCebsi7/9epVti0NwJLSOhjuQFYI4WxbSCHzRK4zKr1nn/z4Xr/mYnu sxiw==; 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 a640c23a62f3a-ac314aab644si706431566b.568.2025.03.17.01.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 01:35:34 -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 2F6D5811B2; Mon, 17 Mar 2025 09:34:51 +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 3100881A04; Mon, 17 Mar 2025 09:34:50 +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 E31D1811B2 for ; Mon, 17 Mar 2025 09:34:47 +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 5753813D5; Mon, 17 Mar 2025 01:34:56 -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 E888D3F673; Mon, 17 Mar 2025 01:34:44 -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 7/8] blkmap: add an attribute to preserve the mem mapping Date: Mon, 17 Mar 2025 14:04:01 +0530 Message-Id: <20250317083402.412310-8-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 Some blkmap memory mapped devices might have to 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 V8: * Add comments to the macro added in the patch cmd/blkmap.c | 9 +++++++-- drivers/block/blkmap.c | 19 +++++++++++++++---- drivers/block/blkmap_helper.c | 2 +- include/blkmap.h | 4 +++- 4 files changed, 26 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