All of lore.kernel.org
 help / color / mirror / Atom feed
From: <rs@ti.com>
To: <robertcnelson@gmail.com>, <ayush@beagleboard.org>,
	<Erik.Welsh@octavosystems.com>, <anshuld@ti.com>, <bb@ti.com>,
	<trini@konsulko.com>, <afd@ti.com>, <xypron.glpk@gmx.de>,
	<ilias.apalodimas@linaro.org>, <sjg@chromium.org>
Cc: <u-boot@lists.denx.de>
Subject: [PATCHv8 2/3] test: boot: add a fdt reserved region check
Date: Wed, 13 May 2026 15:49:42 -0500	[thread overview]
Message-ID: <20260513204943.736142-3-rs@ti.com> (raw)
In-Reply-To: <20260513204943.736142-1-rs@ti.com>

From: Randolph Sapp <rs@ti.com>

Add a image_fdt suite and a check for boot_fdt_add_mem_rsv_regions. This
will ensure the user is properly informed of any reservation failures.
It will also validate that reservations are cleaned up correctly when
switching FDTs.

Signed-off-by: Randolph Sapp <rs@ti.com>
---

v8:
	- Rework test_boot_fdt_add_mem_rsv_regions to mitigate lingering state 

 test/boot/Makefile          |  1 +
 test/boot/image_fdt.c       | 70 +++++++++++++++++++++++++++++++++++++
 test/cmd_ut.c               |  2 ++
 test/py/tests/test_suite.py |  2 +-
 4 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 test/boot/image_fdt.c

diff --git a/test/boot/Makefile b/test/boot/Makefile
index 89538d4f0a6..640af6593cd 100644
--- a/test/boot/Makefile
+++ b/test/boot/Makefile
@@ -14,6 +14,7 @@ endif
 
 ifdef CONFIG_SANDBOX
 obj-$(CONFIG_$(PHASE_)CMDLINE) += bootm.o
+obj-$(CONFIG_$(PHASE_)OF_LIBFDT) += image_fdt.o
 endif
 obj-$(CONFIG_MEASURED_BOOT) += measurement.o
 
diff --git a/test/boot/image_fdt.c b/test/boot/image_fdt.c
new file mode 100644
index 00000000000..778951c1290
--- /dev/null
+++ b/test/boot/image_fdt.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include <config.h>
+
+#include <fdt_support.h>
+#include <image.h>
+#include <lmb.h>
+#include <malloc.h>
+
+#include <asm/global_data.h>
+
+#include <test/test.h>
+#include <test/ut.h>
+
+#define IMAGE_FDT_TEST(_name, _flags) UNIT_TEST(_name, _flags, image_fdt)
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static int test_boot_fdt_add_mem_rsv_regions(struct unit_test_state *uts)
+{
+	phys_addr_t start = CFG_SYS_SDRAM_BASE + 0x100000;
+	const void *old_blob = gd->fdt_blob;
+	int ret = CMD_RET_FAILURE;
+	ulong fdt_sz;
+	int nodeoffset;
+	void *new_blob;
+
+	/* Default reservation should exist */
+	ut_asserteq(1, lmb_is_reserved_flags(start, LMB_NOMAP));
+
+	/* Attempting to re-reserve should warn the user */
+	boot_fdt_add_mem_rsv_regions(gd->fdt_blob);
+	ut_assert_nextlinen("ERROR: reserving");
+	ut_assert_console_end();
+
+	/* Loading a new_blob device tree should be allowed */
+	fdt_sz = fdt_totalsize(gd->fdt_blob);
+	new_blob = malloc(fdt_sz);
+	ut_assertok_ptr(new_blob);
+	memcpy(new_blob, gd->fdt_blob, fdt_sz);
+
+	nodeoffset = fdt_path_offset(new_blob, "/reserved-memory");
+	if (nodeoffset < 0)
+		goto free_blob;
+
+	if (fdt_del_node(new_blob, nodeoffset))
+		goto free_blob;
+
+	boot_fdt_add_mem_rsv_regions(new_blob);
+	gd->fdt_blob = new_blob;
+
+	if (ut_assert_console_end())
+		goto switch_fdt;
+
+	/* Reservation should not exist now */
+	if (!lmb_is_reserved_flags(start, LMB_NOMAP))
+		ret = 0;
+
+	/* Cleanup */
+switch_fdt:
+	boot_fdt_add_mem_rsv_regions(old_blob);
+	gd->fdt_blob = old_blob;
+free_blob:
+	free(new_blob);
+	return ret;
+}
+IMAGE_FDT_TEST(test_boot_fdt_add_mem_rsv_regions, UTF_LIVE_TREE | UTF_CONSOLE);
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 44e5fdfdaa6..363ed4eab30 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -61,6 +61,7 @@ SUITE_DECL(fdt);
 SUITE_DECL(fdt_overlay);
 SUITE_DECL(font);
 SUITE_DECL(hush);
+SUITE_DECL(image_fdt);
 SUITE_DECL(lib);
 SUITE_DECL(loadm);
 SUITE_DECL(log);
@@ -88,6 +89,7 @@ static struct suite suites[] = {
 	SUITE(fdt_overlay, "device tree overlays"),
 	SUITE(font, "font command"),
 	SUITE(hush, "hush behaviour"),
+	SUITE(image_fdt, "image fdt parsing"),
 	SUITE(lib, "library functions"),
 	SUITE(loadm, "loadm command parameters and loading memory blob"),
 	SUITE(log, "logging functions"),
diff --git a/test/py/tests/test_suite.py b/test/py/tests/test_suite.py
index 7fe9a90dfd3..08285f12a5f 100644
--- a/test/py/tests/test_suite.py
+++ b/test/py/tests/test_suite.py
@@ -8,7 +8,7 @@ import re
 EXPECTED_SUITES = [
     'addrmap', 'bdinfo', 'bloblist', 'bootm', 'bootstd',
     'cmd', 'common', 'dm', 'env', 'exit', 'fdt_overlay',
-    'fdt', 'font', 'hush', 'lib',
+    'fdt', 'font', 'hush', 'image_fdt', 'lib',
     'loadm', 'log', 'mbr', 'measurement', 'mem',
     'pci_mps', 'setexpr', 'upl',
     ]
-- 
2.54.0


  parent reply	other threads:[~2026-05-13 20:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13 20:49 [PATCHv8 0/3] various memory related fixups rs
2026-05-13 20:49 ` [PATCHv8 1/3] boot: image-fdt: free old dtb reservations rs
2026-05-13 20:49 ` rs [this message]
2026-05-15  7:33   ` [PATCHv8 2/3] test: boot: add a fdt reserved region check Ilias Apalodimas
2026-05-15 14:03   ` Simon Glass
2026-05-13 20:49 ` [PATCHv8 3/3] memory: reserve from start_addr_sp to initial_relocaddr rs
2026-05-15  7:38   ` Ilias Apalodimas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260513204943.736142-3-rs@ti.com \
    --to=rs@ti.com \
    --cc=Erik.Welsh@octavosystems.com \
    --cc=afd@ti.com \
    --cc=anshuld@ti.com \
    --cc=ayush@beagleboard.org \
    --cc=bb@ti.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=robertcnelson@gmail.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.