public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH v3 1/5] fdtdec: Fix the types of addr and size in fdtdec_add_reserved_memory()
@ 2020-06-10  5:36 Bin Meng
  2020-06-10  5:36 ` [PATCH v3 2/5] fdtdec: Honor #address-cells and #size-cells " Bin Meng
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Bin Meng @ 2020-06-10  5:36 UTC (permalink / raw)
  To: u-boot

From: Bin Meng <bin.meng@windriver.com>

fdtdec_get_addr_size() expects size is of type 'fdt_size_t', and
return value is of type 'fdt_addr_t'. Adjust their types accordingly.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 lib/fdtdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 1f2b763..42f7a25 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1294,7 +1294,8 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
 	/* find a matching node and return the phandle to that */
 	fdt_for_each_subnode(node, blob, parent) {
 		const char *name = fdt_get_name(blob, node, NULL);
-		phys_addr_t addr, size;
+		fdt_addr_t addr;
+		fdt_size_t size;
 
 		addr = fdtdec_get_addr_size(blob, node, "reg", &size);
 		if (addr == FDT_ADDR_T_NONE) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/5] fdtdec: Honor #address-cells and #size-cells in fdtdec_add_reserved_memory()
  2020-06-10  5:36 [PATCH v3 1/5] fdtdec: Fix the types of addr and size in fdtdec_add_reserved_memory() Bin Meng
@ 2020-06-10  5:36 ` Bin Meng
  2020-06-10  5:36 ` [PATCH v3 3/5] test/dm: fdtdec: Add the missing gd declaration Bin Meng
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Bin Meng @ 2020-06-10  5:36 UTC (permalink / raw)
  To: u-boot

From: Bin Meng <bin.meng@windriver.com>

At present fdtdec_add_reserved_memory() calls fdtdec_get_addr_size()
to get address and size for the subnodes of /reserved-memory node.

We should honor #address-cells and #size-cells properties in the
parent node.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 lib/fdtdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 42f7a25..0dd7ff1 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1297,7 +1297,8 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
 		fdt_addr_t addr;
 		fdt_size_t size;
 
-		addr = fdtdec_get_addr_size(blob, node, "reg", &size);
+		addr = fdtdec_get_addr_size_fixed(blob, node, "reg", 0, na, ns,
+						  &size, false);
 		if (addr == FDT_ADDR_T_NONE) {
 			debug("failed to read address/size for %s\n", name);
 			continue;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 3/5] test/dm: fdtdec: Add the missing gd declaration
  2020-06-10  5:36 [PATCH v3 1/5] fdtdec: Fix the types of addr and size in fdtdec_add_reserved_memory() Bin Meng
  2020-06-10  5:36 ` [PATCH v3 2/5] fdtdec: Honor #address-cells and #size-cells " Bin Meng
@ 2020-06-10  5:36 ` Bin Meng
  2020-06-17  3:11   ` Simon Glass
  2020-06-10  5:36 ` [PATCH v3 4/5] test/dm: fdtdec: Corect a typo in dm_test_fdtdec_set_carveout() Bin Meng
  2020-06-10  5:36 ` [PATCH v3 5/5] test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory() Bin Meng
  3 siblings, 1 reply; 8+ messages in thread
From: Bin Meng @ 2020-06-10  5:36 UTC (permalink / raw)
  To: u-boot

From: Bin Meng <bin.meng@windriver.com>

Add DECLARE_GLOBAL_DATA_PTR since it is referenced in the test codes.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

(no changes since v1)

 test/dm/fdtdec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c
index b2f75b5..c2f7b94 100644
--- a/test/dm/fdtdec.c
+++ b/test/dm/fdtdec.c
@@ -9,6 +9,8 @@
 #include <dm/test.h>
 #include <test/ut.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts)
 {
 	struct fdt_memory resv;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 4/5] test/dm: fdtdec: Corect a typo in dm_test_fdtdec_set_carveout()
  2020-06-10  5:36 [PATCH v3 1/5] fdtdec: Fix the types of addr and size in fdtdec_add_reserved_memory() Bin Meng
  2020-06-10  5:36 ` [PATCH v3 2/5] fdtdec: Honor #address-cells and #size-cells " Bin Meng
  2020-06-10  5:36 ` [PATCH v3 3/5] test/dm: fdtdec: Add the missing gd declaration Bin Meng
@ 2020-06-10  5:36 ` Bin Meng
  2020-06-17  3:11   ` Simon Glass
  2020-06-10  5:36 ` [PATCH v3 5/5] test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory() Bin Meng
  3 siblings, 1 reply; 8+ messages in thread
From: Bin Meng @ 2020-06-10  5:36 UTC (permalink / raw)
  To: u-boot

From: Bin Meng <bin.meng@windriver.com>

It should be "writable".

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

(no changes since v1)

 test/dm/fdtdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c
index c2f7b94..999d712 100644
--- a/test/dm/fdtdec.c
+++ b/test/dm/fdtdec.c
@@ -22,7 +22,7 @@ static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts)
 	blob = malloc(blob_sz);
 	ut_assertnonnull(blob);
 
-	/* Make a writtable copy of the fdt blob */
+	/* Make a writable copy of the fdt blob */
 	ut_assertok(fdt_open_into(gd->fdt_blob, blob, blob_sz));
 
 	resv.start = 0x1000;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 5/5] test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory()
  2020-06-10  5:36 [PATCH v3 1/5] fdtdec: Fix the types of addr and size in fdtdec_add_reserved_memory() Bin Meng
                   ` (2 preceding siblings ...)
  2020-06-10  5:36 ` [PATCH v3 4/5] test/dm: fdtdec: Corect a typo in dm_test_fdtdec_set_carveout() Bin Meng
@ 2020-06-10  5:36 ` Bin Meng
  2020-06-17  3:11   ` Simon Glass
  3 siblings, 1 reply; 8+ messages in thread
From: Bin Meng @ 2020-06-10  5:36 UTC (permalink / raw)
  To: u-boot

From: Bin Meng <bin.meng@windriver.com>

This adds a test case to test the functionality of the fdtdec API
fdtdec_add_reserved_memory().

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

Changes in v3:
- correct typo in the comments, and some minor rewording

 test/dm/fdtdec.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c
index 999d712..56f6f4f 100644
--- a/test/dm/fdtdec.c
+++ b/test/dm/fdtdec.c
@@ -59,3 +59,72 @@ static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_fdtdec_set_carveout,
 	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
+
+static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts)
+{
+	struct fdt_memory resv;
+	fdt_addr_t addr;
+	fdt_size_t size;
+	void *blob;
+	int blob_sz, parent, subnode;
+	uint32_t phandle, phandle1;
+
+	blob_sz = fdt_totalsize(gd->fdt_blob) + 128;
+	blob = malloc(blob_sz);
+	ut_assertnonnull(blob);
+
+	/* Make a writable copy of the fdt blob */
+	ut_assertok(fdt_open_into(gd->fdt_blob, blob, blob_sz));
+
+	/* Insert a memory region in /reserved-memory node */
+	resv.start = 0x1000;
+	resv.end = 0x1fff;
+	ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region",
+					       &resv, &phandle));
+
+	/* Test /reserve-memory and its subnode should exist */
+	parent = fdt_path_offset(blob, "/reserved-memory");
+	ut_assert(parent > 0);
+	subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region");
+	ut_assert(subnode > 0);
+
+	/* Test reg property of /reserved-memory/rsvd_region node */
+	addr = fdtdec_get_addr_size_auto_parent(blob, parent, subnode,
+						"reg", 0, &size, false);
+	ut_assert(addr == resv.start);
+	ut_assert(size == resv.end -  resv.start + 1);
+
+	/* Insert another memory region in /reserved-memory node */
+	subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region1");
+	ut_assert(subnode < 0);
+
+	resv.start = 0x2000;
+	resv.end = 0x2fff;
+	ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region1",
+					       &resv, &phandle1));
+	subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region1");
+	ut_assert(subnode > 0);
+
+	/* phandles must be different */
+	ut_assert(phandle != phandle1);
+
+	/*
+	 * Insert a 3rd memory region with the same addr/size as the 1st one,
+	 * but a new node should not be inserted due to the same addr/size.
+	 */
+	resv.start = 0x1000;
+	resv.end = 0x1fff;
+	ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region2",
+					       &resv, &phandle1));
+	subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region2");
+	ut_assert(subnode < 0);
+
+	/* phandle must be same as the 1st one */
+	ut_assert(phandle == phandle1);
+
+	free(blob);
+
+	return 0;
+}
+DM_TEST(dm_test_fdtdec_add_reserved_memory,
+	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 3/5] test/dm: fdtdec: Add the missing gd declaration
  2020-06-10  5:36 ` [PATCH v3 3/5] test/dm: fdtdec: Add the missing gd declaration Bin Meng
@ 2020-06-17  3:11   ` Simon Glass
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Glass @ 2020-06-17  3:11 UTC (permalink / raw)
  To: u-boot

On Tue, 9 Jun 2020 at 23:36, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> From: Bin Meng <bin.meng@windriver.com>
>
> Add DECLARE_GLOBAL_DATA_PTR since it is referenced in the test codes.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> (no changes since v1)
>
>  test/dm/fdtdec.c | 2 ++
>  1 file changed, 2 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

You may need to rebase this series on u-boot-dm/next

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 4/5] test/dm: fdtdec: Corect a typo in dm_test_fdtdec_set_carveout()
  2020-06-10  5:36 ` [PATCH v3 4/5] test/dm: fdtdec: Corect a typo in dm_test_fdtdec_set_carveout() Bin Meng
@ 2020-06-17  3:11   ` Simon Glass
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Glass @ 2020-06-17  3:11 UTC (permalink / raw)
  To: u-boot

On Tue, 9 Jun 2020 at 23:36, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> From: Bin Meng <bin.meng@windriver.com>
>
> It should be "writable".
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> (no changes since v1)
>
>  test/dm/fdtdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 5/5] test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory()
  2020-06-10  5:36 ` [PATCH v3 5/5] test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory() Bin Meng
@ 2020-06-17  3:11   ` Simon Glass
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Glass @ 2020-06-17  3:11 UTC (permalink / raw)
  To: u-boot

On Tue, 9 Jun 2020 at 23:36, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> From: Bin Meng <bin.meng@windriver.com>
>
> This adds a test case to test the functionality of the fdtdec API
> fdtdec_add_reserved_memory().
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v3:
> - correct typo in the comments, and some minor rewording
>
>  test/dm/fdtdec.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 69 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

I think this is useful. But do note that upstream libfdt has some tess also.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-06-17  3:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-10  5:36 [PATCH v3 1/5] fdtdec: Fix the types of addr and size in fdtdec_add_reserved_memory() Bin Meng
2020-06-10  5:36 ` [PATCH v3 2/5] fdtdec: Honor #address-cells and #size-cells " Bin Meng
2020-06-10  5:36 ` [PATCH v3 3/5] test/dm: fdtdec: Add the missing gd declaration Bin Meng
2020-06-17  3:11   ` Simon Glass
2020-06-10  5:36 ` [PATCH v3 4/5] test/dm: fdtdec: Corect a typo in dm_test_fdtdec_set_carveout() Bin Meng
2020-06-17  3:11   ` Simon Glass
2020-06-10  5:36 ` [PATCH v3 5/5] test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory() Bin Meng
2020-06-17  3:11   ` Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox