[PATCH 01/32] cmd: fdt: Import is_printable_string() from DTC to fix u32 misprint

Import is_printable_string() implementation from DTC 1.7.0 as of DTC commit 039a994 ("Bump version to v1.7.0") . This fixes a print of u32 property which so far used to be printed as string by U-Boot fdt print command.
We might see the case where the parsed property value, in this case it is a 32-bit integer, identified as a printable string or a null byte (concatenated strings) because of its last character happens to be: 0x00 (null character), 0xB (vertical tab character) or 0x10 (line feed character) In this situation, if the string is identified as printable string, it will be displayed as character instead of hex value
When the isprint() condition is true, there are two possibilities: 1) The character is ASCII character (except the first 32) 2) The character is extended ASCII character
For example, NG property in device tree: clock-frequency = <16640000>; by default, would be displayed as clock-frequency = "", "ýè"; and with this patch applied, would be displayed as clock-frequency = <0x00fde800>;
Full investigation was done by Nam and Hai, patch reworked by Marek to use common code from DTC.
Signed-off-by: Hai Pham hai.pham.ud@renesas.com Signed-off-by: Nam Nguyen nam.nguyen.yh@renesas.com Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index 1972490bdc2..bf2415661e2 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -878,41 +878,33 @@ static int fdt_parse_prop(char * const *newval, int count, char *data, int *len) static int is_printable_string(const void *data, int len) { const char *s = data; + const char *ss, *se;
/* zero length is not */ if (len == 0) return 0;
- /* must terminate with zero or '\n' */ - if (s[len - 1] != '\0' && s[len - 1] != '\n') + /* must terminate with zero */ + if (s[len - 1] != '\0') return 0;
- /* printable or a null byte (concatenated strings) */ - while (((*s == '\0') || isprint(*s) || isspace(*s)) && (len > 0)) { - /* - * If we see a null, there are three possibilities: - * 1) If len == 1, it is the end of the string, printable - * 2) Next character also a null, not printable. - * 3) Next character not a null, continue to check. - */ - if (s[0] == '\0') { - if (len == 1) - return 1; - if (s[1] == '\0') - return 0; - } + se = s + len; + + while (s < se) { + ss = s; + while (s < se && *s && isprint((unsigned char)*s)) + s++; + + /* not zero, or not done yet */ + if (*s != '\0' || s == ss) + return 0; + s++; - len--; }
- /* Not the null termination, or not done yet: not printable */ - if (*s != '\0' || (len != 0)) - return 0; - return 1; }
- /* * Print the property in the best format, a heuristic guess. Print as * a string, concatenated strings, a byte, word, double word, or (if all

It is perfectly valid to request an address or size of FDT property without value, the only special case if requesting of the value of FDT property without value. Invert the test such, that properties without value still set the variable from 'fdt get addr/size' to address of the property or size of the property, where the later is 0.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index bf2415661e2..56b3585c3ac 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -446,15 +446,17 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } else { nodep = fdt_getprop( working_fdt, nodeoffset, prop, &len); - if (len == 0) { - /* no property value */ - env_set(var, ""); - return 0; - } else if (nodep && len > 0) { + if (nodep && len >= 0) { if (subcmd[0] == 'v') { int index = 0; int ret;
+ if (len == 0) { + /* no property value */ + env_set(var, ""); + return 0; + } + if (argc == 7) index = simple_strtoul(argv[6], NULL, 10);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
It is perfectly valid to request an address or size of FDT property without value, the only special case if requesting of the value of FDT property without value. Invert the test such, that properties without value still set the variable from 'fdt get addr/size' to address of the property or size of the property, where the later is 0.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

In case an FDT contains a node '/test-node@1234' , with no property called 'noprop' in that node, the following command triggers a print of help message for 'fdt' command instead of erroring out: => fdt rm /test-node@1234 noprop This is because the subcommand errornously returns 'err' instead of CMD_RET_FAILURE, fix it. Furthermore, align the number of spaces past fdt_delprop() in error message with the rest of the code.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index 56b3585c3ac..644b58ac4d7 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -547,16 +547,16 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (argc > 3) { err = fdt_delprop(working_fdt, nodeoffset, argv[3]); if (err < 0) { - printf("libfdt fdt_delprop(): %s\n", + printf("libfdt fdt_delprop(): %s\n", fdt_strerror(err)); - return err; + return CMD_RET_FAILURE; } } else { err = fdt_del_node(working_fdt, nodeoffset); if (err < 0) { - printf("libfdt fdt_del_node(): %s\n", + printf("libfdt fdt_del_node(): %s\n", fdt_strerror(err)); - return err; + return CMD_RET_FAILURE; } }

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
In case an FDT contains a node '/test-node@1234' , with no property called 'noprop' in that node, the following command triggers a print of help message for 'fdt' command instead of erroring out: => fdt rm /test-node@1234 noprop This is because the subcommand errornously returns 'err' instead of CMD_RET_FAILURE, fix it. Furthermore, align the number of spaces past fdt_delprop() in error message with the rest of the code.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

In case 'fdt rsvmem delete index' is passed a non-existent index, one which does not exist in 'fdt rsvmem print', then the following command triggers a print of help message for 'fdt' command instead of erroring out: => fdt rsvmem delete 1234 This is because the subcommand errornously returns 'err' instead of CMD_RET_FAILURE, fix it. Furthermore, align the number of spaces past fdt_del_mem_rsv() and fdt_add_mem_rsv() in error message with the rest of the code.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index 644b58ac4d7..29d748891d0 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -644,18 +644,18 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) err = fdt_add_mem_rsv(working_fdt, addr, size);
if (err < 0) { - printf("libfdt fdt_add_mem_rsv(): %s\n", + printf("libfdt fdt_add_mem_rsv(): %s\n", fdt_strerror(err)); - return err; + return CMD_RET_FAILURE; } } else if (argv[2][0] == 'd') { unsigned long idx = hextoul(argv[3], NULL); int err = fdt_del_mem_rsv(working_fdt, idx);
if (err < 0) { - printf("libfdt fdt_del_mem_rsv(): %s\n", + printf("libfdt fdt_del_mem_rsv(): %s\n", fdt_strerror(err)); - return err; + return CMD_RET_FAILURE; } } else { /* Unrecognized command */

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
In case 'fdt rsvmem delete index' is passed a non-existent index, one which does not exist in 'fdt rsvmem print', then the following command triggers a print of help message for 'fdt' command instead of erroring out: => fdt rsvmem delete 1234 This is because the subcommand errornously returns 'err' instead of CMD_RET_FAILURE, fix it. Furthermore, align the number of spaces past fdt_del_mem_rsv() and fdt_add_mem_rsv() in error message with the rest of the code.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On case 'fdt bootcpu' is invoked without parameters, argv[2] is not valid and this command would SEGFAULT in sandbox environment. Add missing argc test to avoid the crash and rather print usage help message.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index 29d748891d0..734c9b36a07 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -597,7 +597,12 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) * Set boot cpu id */ } else if (strncmp(argv[1], "boo", 3) == 0) { - unsigned long tmp = hextoul(argv[2], NULL); + unsigned long tmp; + + if (argc != 3) + return CMD_RET_USAGE; + + tmp = hextoul(argv[2], NULL); fdt_set_boot_cpuid_phys(working_fdt, tmp);
/*

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
On case 'fdt bootcpu' is invoked without parameters, argv[2] is not valid and this command would SEGFAULT in sandbox environment. Add missing argc test to avoid the crash and rather print usage help message.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Yes sandbox is good for finding this sort of thing.
Reviewed-by: Simon Glass sjg@chromium.org

On case 'fdt memory' is invoked without parameters, argv[2]/argv[3] is not valid and this command would SEGFAULT in sandbox environment. Add missing argc test to avoid the crash and rather print usage help message.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/cmd/fdt.c b/cmd/fdt.c index 734c9b36a07..f257bee8643 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -611,6 +611,10 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } else if (strncmp(argv[1], "me", 2) == 0) { uint64_t addr, size; int err; + + if (argc != 4) + return CMD_RET_USAGE; + addr = simple_strtoull(argv[2], NULL, 16); size = simple_strtoull(argv[3], NULL, 16); err = fdt_fixup_memory(working_fdt, addr, size);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
On case 'fdt memory' is invoked without parameters, argv[2]/argv[3] is not valid and this command would SEGFAULT in sandbox environment. Add missing argc test to avoid the crash and rather print usage help message.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 4 ++++ 1 file changed, 4 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

The help text references 'addr' as an optional key start address, but the explanation references the same as 'start', make sure they both read as 'addr'. Also update the abbreviated 'addr' in the explanation to 'address'.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index f257bee8643..279dad9fe11 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -1138,8 +1138,8 @@ static char fdt_help_text[] = " <start>/<size> - initrd start addr/size\n" #if defined(CONFIG_FIT_SIGNATURE) "fdt checksign [<addr>] - check FIT signature\n" - " <start> - addr of key blob\n" - " default gd->fdt_blob\n" + " <addr> - address of key blob\n" + " default gd->fdt_blob\n" #endif "NOTE: Dereference aliases by omitting the leading '/', " "e.g. fdt print ethernet0.";

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
The help text references 'addr' as an optional key start address, but the explanation references the same as 'start', make sure they both read as 'addr'. Also update the abbreviated 'addr' in the explanation to 'address'.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

The command assumed 32bit pointers so far, with 64bit pointer the command would overwrite a piece of stack. Fix it by extending the array size to cater for 64bit pointer, and use snprintf() to avoid writing past the end of the array ever again.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index 279dad9fe11..bc19303159d 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -466,9 +466,9 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return ret; } else if (subcmd[0] == 'a') { /* Get address */ - char buf[11]; + char buf[19];
- sprintf(buf, "0x%p", nodep); + snprintf(buf, sizeof(buf), "0x%p", nodep); env_set(var, buf); } else if (subcmd[0] == 's') { /* Get size */

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
The command assumed 32bit pointers so far, with 64bit pointer the command would overwrite a piece of stack. Fix it by extending the array size to cater for 64bit pointer, and use snprintf() to avoid writing past the end of the array ever again.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
diff --git a/cmd/fdt.c b/cmd/fdt.c index 279dad9fe11..bc19303159d 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -466,9 +466,9 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return ret; } else if (subcmd[0] == 'a') { /* Get address */
char buf[11];
char buf[19];
sprintf(buf, "0x%p", nodep);
snprintf(buf, sizeof(buf), "0x%p", nodep);
Do we need the 0x? I believe that is always the base.
env_set(var, buf); } else if (subcmd[0] == 's') { /* Get size */
-- 2.39.2
Regards, Simon

On 3/1/23 16:02, Simon Glass wrote:
On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
The command assumed 32bit pointers so far, with 64bit pointer the command would overwrite a piece of stack. Fix it by extending the array size to cater for 64bit pointer, and use snprintf() to avoid writing past the end of the array ever again.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
diff --git a/cmd/fdt.c b/cmd/fdt.c index 279dad9fe11..bc19303159d 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -466,9 +466,9 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return ret; } else if (subcmd[0] == 'a') { /* Get address */
char buf[11];
char buf[19];
sprintf(buf, "0x%p", nodep);
snprintf(buf, sizeof(buf), "0x%p", nodep);
Do we need the 0x? I believe that is always the base.
I would argue this behavior is an ABI by now. I did send a separate patch on top, which can then be reverted if that would break anything:
https://patchwork.ozlabs.org/project/uboot/patch/20230302030440.322361-1-mar...

The address returned from 'fdt get addr' command must be mapped into sysmem, as this is a working FDT. Access to this address without mapping it would lead to crash e.g. in sandbox.
The following command triggers the crash: " ./u-boot -Dc 'fdt addr $fdtcontroladdr ; fdt get addr var / compatible ; md $var' "
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index bc19303159d..f2576ab4b38 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -468,7 +468,8 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) /* Get address */ char buf[19];
- snprintf(buf, sizeof(buf), "0x%p", nodep); + snprintf(buf, sizeof(buf), "0x%lx", + (ulong)map_to_sysmem(nodep)); env_set(var, buf); } else if (subcmd[0] == 's') { /* Get size */

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
The address returned from 'fdt get addr' command must be mapped into sysmem, as this is a working FDT. Access to this address without mapping it would lead to crash e.g. in sandbox.
The following command triggers the crash: " ./u-boot -Dc 'fdt addr $fdtcontroladdr ; fdt get addr var / compatible ; md $var' "
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org
diff --git a/cmd/fdt.c b/cmd/fdt.c index bc19303159d..f2576ab4b38 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -468,7 +468,8 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) /* Get address */ char buf[19];
snprintf(buf, sizeof(buf), "0x%p", nodep);
snprintf(buf, sizeof(buf), "0x%lx",
(ulong)map_to_sysmem(nodep)); env_set(var, buf); } else if (subcmd[0] == 's') { /* Get size */
-- 2.39.2

Currently any integer array value is set as long up-to-40 character hexadecimal string into environment variable when extracted from an FDT using 'fdt get value path prop index', because the support for handling integer arrays is not implemented, and fdt_value_env_set() code falls back into the hash handling behavior instead.
Implement this support simply by checking whether user supplied any index. If index is set and the property length is multiple of four, then this is an integer array, and the code would extract value at specified index.
There is a subtle change where default index is set to -1 instead of 0. This is OK, since the only place which checks for index to be less or equal zero is the string array handling code in fdt_value_env_set() and that code would work perfectly well with index -1 too.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- cmd/fdt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index f2576ab4b38..f38fe909c3e 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -77,7 +77,17 @@ static int fdt_value_env_set(const void *nodep, int len,
sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep)); env_set(var, buf); - } else if (len%4 == 0 && len <= 20) { + } else if (len % 4 == 0 && index >= 0) { + /* Needed to print integer arrays. */ + const unsigned int *nodec = (const unsigned int *)nodep; + char buf[11]; + + if (index * 4 >= len) + return 1; + + sprintf(buf, "0x%08X", fdt32_to_cpu(*(nodec + index))); + env_set(var, buf); + } else if (len % 4 == 0 && len <= 20) { /* Needed to print things like sha1 hashes. */ char buf[41]; int i; @@ -448,7 +458,7 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) working_fdt, nodeoffset, prop, &len); if (nodep && len >= 0) { if (subcmd[0] == 'v') { - int index = 0; + int index = -1; int ret;
if (len == 0) {

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Currently any integer array value is set as long up-to-40 character hexadecimal string into environment variable when extracted from an FDT using 'fdt get value path prop index', because the support for handling integer arrays is not implemented, and fdt_value_env_set() code falls back into the hash handling behavior instead.
Implement this support simply by checking whether user supplied any index. If index is set and the property length is multiple of four, then this is an integer array, and the code would extract value at specified index.
There is a subtle change where default index is set to -1 instead of 0. This is OK, since the only place which checks for index to be less or equal zero is the string array handling code in fdt_value_env_set() and that code would work perfectly well with index -1 too.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Add helper macro to test for empty lines, which is an inobvious wrapper around ut_assert_nextline("%s", "") .
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- include/test/ut.h | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/include/test/ut.h b/include/test/ut.h index 4d00b4eeca1..2b0dab32f68 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -334,6 +334,10 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); return CMD_RET_FAILURE; \ } \
+/* Assert that the next console output line is empty */ +#define ut_assert_nextline_empty() \ + ut_assert_nextline("%s", "") + /** * ut_check_free() - Return the number of bytes free in the malloc() pool *

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add helper macro to test for empty lines, which is an inobvious wrapper around ut_assert_nextline("%s", "") .
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
include/test/ut.h | 4 ++++ 1 file changed, 4 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

The 'fdt' command has a 'resize' subcommand, rename the fdt_test_resize() to fdt_test_addr_resize() to avoid confusion about what it is testing. There is currently no resize test.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 7974c88c0d6..a50285eafab 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -108,7 +108,7 @@ static int fdt_test_addr(struct unit_test_state *uts) FDT_TEST(fdt_test_addr, UT_TESTF_CONSOLE_REC);
/* Test 'fdt addr' resizing an fdt */ -static int fdt_test_resize(struct unit_test_state *uts) +static int fdt_test_addr_resize(struct unit_test_state *uts) { char fdt[256]; const int newsize = sizeof(fdt) / 2; @@ -140,7 +140,7 @@ static int fdt_test_resize(struct unit_test_state *uts)
return 0; } -FDT_TEST(fdt_test_resize, UT_TESTF_CONSOLE_REC); +FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
/* Test 'fdt get' reading an fdt */ static int fdt_test_get(struct unit_test_state *uts)

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
The 'fdt' command has a 'resize' subcommand, rename the fdt_test_resize() to fdt_test_addr_resize() to avoid confusion about what it is testing. There is currently no resize test.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

The 'fdt get' command has a 'get value' subcommand, rename the fdt_test_get() to fdt_test_get_value() to avoid confusion about what it is testing. There is currently no get 'get name', 'get addr', 'get size' subcommand test.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index a50285eafab..03a29c6b9c0 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -142,8 +142,8 @@ static int fdt_test_addr_resize(struct unit_test_state *uts) } FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
-/* Test 'fdt get' reading an fdt */ -static int fdt_test_get(struct unit_test_state *uts) +/* Test 'fdt get value' reading an fdt */ +static int fdt_test_get_value(struct unit_test_state *uts) { ulong addr;
@@ -193,7 +193,7 @@ static int fdt_test_get(struct unit_test_state *uts)
return 0; } -FDT_TEST(fdt_test_get, UT_TESTF_CONSOLE_REC); +FDT_TEST(fdt_test_get_value, UT_TESTF_CONSOLE_REC);
int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) {

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
The 'fdt get' command has a 'get value' subcommand, rename the fdt_test_get() to fdt_test_get_value() to avoid confusion about what it is testing. There is currently no get 'get name', 'get addr', 'get size' subcommand test.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Implement function to generate internal test DT fragment and switch the 'fdt get value' test to this instead of depending on the sandbox DT. Rename clk-test node to test-node node. This FDT fragment will be reused by other tests. No functional change.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 124 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 111 insertions(+), 13 deletions(-)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 03a29c6b9c0..21553a2f3dc 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -39,6 +39,102 @@ static int make_test_fdt(struct unit_test_state *uts, void *fdt, int size) return 0; }
+/** + * make_fuller_fdt() - Create an FDT with root node and properties + * + * The size is set to the minimum needed + * + * @uts: Test state + * @fdt: Place to write FDT + * @size: Maximum size of space for fdt + */ +static int make_fuller_fdt(struct unit_test_state *uts, void *fdt, int size) +{ + fdt32_t regs[2] = { cpu_to_fdt32(0x1234), cpu_to_fdt32(0x1000) }; + + /* + * Assemble the following DT for test purposes: + * + * / { + * #address-cells = <0x00000001>; + * #size-cells = <0x00000001>; + * compatible = "u-boot,fdt-test"; + * model = "U-Boot FDT test"; + * + * aliases { + * badalias = "/bad/alias"; + * subnodealias = "/test-node@1234/subnode"; + * testnodealias = "/test-node@1234"; + * }; + * + * test-node@1234 { + * #address-cells = <0x00000000>; + * #size-cells = <0x00000000>; + * compatible = "u-boot,fdt-test-device1"; + * clock-names = "fixed", "i2c", "spi", "uart2", "uart1"; + * u-boot,empty-property; + * clock-frequency = <0x00fde800>; + * regs = <0x00001234 0x00001000>; + * + * subnode { + * #address-cells = <0x00000000>; + * #size-cells = <0x00000000>; + * compatible = "u-boot,fdt-subnode-test-device"; + * }; + * }; + * }; + */ + + ut_assertok(fdt_create(fdt, size)); + ut_assertok(fdt_finish_reservemap(fdt)); + ut_assert(fdt_begin_node(fdt, "") >= 0); + + ut_assertok(fdt_property_u32(fdt, "#address-cells", 1)); + ut_assertok(fdt_property_u32(fdt, "#size-cells", 1)); + /* <string> */ + ut_assertok(fdt_property_string(fdt, "compatible", "u-boot,fdt-test")); + /* <string> */ + ut_assertok(fdt_property_string(fdt, "model", "U-Boot FDT test")); + + ut_assert(fdt_begin_node(fdt, "aliases") >= 0); + /* <string> */ + ut_assertok(fdt_property_string(fdt, "badalias", "/bad/alias")); + /* <string> */ + ut_assertok(fdt_property_string(fdt, "subnodealias", "/test-node@1234/subnode")); + /* <string> */ + ut_assertok(fdt_property_string(fdt, "testnodealias", "/test-node@1234")); + ut_assertok(fdt_end_node(fdt)); + + ut_assert(fdt_begin_node(fdt, "test-node@1234") >= 0); + ut_assertok(fdt_property_cell(fdt, "#address-cells", 0)); + ut_assertok(fdt_property_cell(fdt, "#size-cells", 0)); + /* <string> */ + ut_assertok(fdt_property_string(fdt, "compatible", "u-boot,fdt-test-device1")); + /* <stringlist> */ + ut_assertok(fdt_property(fdt, "clock-names", "fixed\0i2c\0spi\0uart2\0uart1\0", 26)); + /* <empty> */ + ut_assertok(fdt_property(fdt, "u-boot,empty-property", NULL, 0)); + /* + * <u32> + * This value is deliberate as it used to break cmd/fdt.c + * is_printable_string() implementation. + */ + ut_assertok(fdt_property_u32(fdt, "clock-frequency", 16640000)); + /* <prop-encoded-array> */ + ut_assertok(fdt_property(fdt, "regs", ®s, sizeof(regs))); + ut_assert(fdt_begin_node(fdt, "subnode") >= 0); + ut_assertok(fdt_property_cell(fdt, "#address-cells", 0)); + ut_assertok(fdt_property_cell(fdt, "#size-cells", 0)); + ut_assertok(fdt_property_string(fdt, "compatible", "u-boot,fdt-subnode-test-device")); + ut_assertok(fdt_end_node(fdt)); + ut_assertok(fdt_end_node(fdt)); + + ut_assertok(fdt_end_node(fdt)); + ut_assertok(fdt_finish(fdt)); + + return 0; +} + /* Test 'fdt addr' getting/setting address */ static int fdt_test_addr(struct unit_test_state *uts) { @@ -145,43 +241,45 @@ FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC); /* Test 'fdt get value' reading an fdt */ static int fdt_test_get_value(struct unit_test_state *uts) { + char fdt[4096]; ulong addr;
- addr = map_to_sysmem(gd->fdt_blob); + ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); set_working_fdt_addr(addr);
- /* Test getting default element of /clk-test node clock-names property */ + /* Test getting default element of /test-node@1234 node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_assertok(run_command("fdt get value fdflt /clk-test clock-names", 0)); + ut_assertok(run_command("fdt get value fdflt /test-node@1234 clock-names", 0)); ut_asserteq_str("fixed", env_get("fdflt")); ut_assertok(ut_check_console_end(uts));
- /* Test getting 0th element of /clk-test node clock-names property */ + /* Test getting 0th element of /test-node@1234 node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_assertok(run_command("fdt get value fzero /clk-test clock-names 0", 0)); + ut_assertok(run_command("fdt get value fzero /test-node@1234 clock-names 0", 0)); ut_asserteq_str("fixed", env_get("fzero")); ut_assertok(ut_check_console_end(uts));
- /* Test getting 1st element of /clk-test node clock-names property */ + /* Test getting 1st element of /test-node@1234 node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_assertok(run_command("fdt get value fone /clk-test clock-names 1", 0)); + ut_assertok(run_command("fdt get value fone /test-node@1234 clock-names 1", 0)); ut_asserteq_str("i2c", env_get("fone")); ut_assertok(ut_check_console_end(uts));
- /* Test getting 2nd element of /clk-test node clock-names property */ + /* Test getting 2nd element of /test-node@1234 node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_assertok(run_command("fdt get value ftwo /clk-test clock-names 2", 0)); + ut_assertok(run_command("fdt get value ftwo /test-node@1234 clock-names 2", 0)); ut_asserteq_str("spi", env_get("ftwo")); ut_assertok(ut_check_console_end(uts));
- /* Test missing 10th element of /clk-test node clock-names property */ + /* Test missing 10th element of /test-node@1234 node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_asserteq(1, run_command("fdt get value ftwo /clk-test clock-names 10", 0)); + ut_asserteq(1, run_command("fdt get value ften /test-node@1234 clock-names 10", 0)); ut_assertok(ut_check_console_end(uts));
- /* Test getting default element of /clk-test node nonexistent property */ + /* Test getting default element of /test-node@1234 node nonexistent property */ ut_assertok(console_record_reset_enable()); - ut_asserteq(1, run_command("fdt get value fnone /clk-test nonexistent", 1)); + ut_asserteq(1, run_command("fdt get value fnone /test-node@1234 nonexistent", 1)); ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); ut_assertok(ut_check_console_end(uts));

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Implement function to generate internal test DT fragment and switch the 'fdt get value' test to this instead of depending on the sandbox DT. Rename clk-test node to test-node node. This FDT fragment will be reused by other tests. No functional change.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 124 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 111 insertions(+), 13 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

The 'fdt' command help contains the following note: " Dereference aliases by omitting the leading '/', e.g. fdt print ethernet0. " Add test for it.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 65 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 20 deletions(-)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 21553a2f3dc..e04ba37f19f 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -239,56 +239,81 @@ static int fdt_test_addr_resize(struct unit_test_state *uts) FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
/* Test 'fdt get value' reading an fdt */ -static int fdt_test_get_value(struct unit_test_state *uts) +static int fdt_test_get_value_common(struct unit_test_state *uts, + const char *node) { - char fdt[4096]; - ulong addr; - - ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); - addr = map_to_sysmem(fdt); - set_working_fdt_addr(addr); - - /* Test getting default element of /test-node@1234 node clock-names property */ + /* Test getting default element of $node node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_assertok(run_command("fdt get value fdflt /test-node@1234 clock-names", 0)); + ut_assertok(run_commandf("fdt get value fdflt %s clock-names", node)); ut_asserteq_str("fixed", env_get("fdflt")); ut_assertok(ut_check_console_end(uts));
- /* Test getting 0th element of /test-node@1234 node clock-names property */ + /* Test getting 0th element of $node node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_assertok(run_command("fdt get value fzero /test-node@1234 clock-names 0", 0)); + ut_assertok(run_commandf("fdt get value fzero %s clock-names 0", node)); ut_asserteq_str("fixed", env_get("fzero")); ut_assertok(ut_check_console_end(uts));
- /* Test getting 1st element of /test-node@1234 node clock-names property */ + /* Test getting 1st element of $node node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_assertok(run_command("fdt get value fone /test-node@1234 clock-names 1", 0)); + ut_assertok(run_commandf("fdt get value fone %s clock-names 1", node)); ut_asserteq_str("i2c", env_get("fone")); ut_assertok(ut_check_console_end(uts));
- /* Test getting 2nd element of /test-node@1234 node clock-names property */ + /* Test getting 2nd element of $node node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_assertok(run_command("fdt get value ftwo /test-node@1234 clock-names 2", 0)); + ut_assertok(run_commandf("fdt get value ftwo %s clock-names 2", node)); ut_asserteq_str("spi", env_get("ftwo")); ut_assertok(ut_check_console_end(uts));
- /* Test missing 10th element of /test-node@1234 node clock-names property */ + /* Test missing 10th element of $node node clock-names property */ ut_assertok(console_record_reset_enable()); - ut_asserteq(1, run_command("fdt get value ften /test-node@1234 clock-names 10", 0)); + ut_asserteq(1, run_commandf("fdt get value ften %s clock-names 10", node)); ut_assertok(ut_check_console_end(uts));
- /* Test getting default element of /test-node@1234 node nonexistent property */ + /* Test getting default element of $node node nonexistent property */ ut_assertok(console_record_reset_enable()); - ut_asserteq(1, run_command("fdt get value fnone /test-node@1234 nonexistent", 1)); + ut_asserteq(1, run_commandf("fdt get value fnone %s nonexistent", node)); ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); ut_assertok(ut_check_console_end(uts));
+ return 0; +} + +static int fdt_test_get_value(struct unit_test_state *uts) +{ + char fdt[4096]; + ulong addr; + int ret; + + ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + ret = fdt_test_get_value_common(uts, "/test-node@1234"); + if (!ret) + ret = fdt_test_get_value_common(uts, "testnodealias"); + if (ret) + return ret; + /* Test getting default element of /nonexistent node */ ut_assertok(console_record_reset_enable()); ut_asserteq(1, run_command("fdt get value fnode /nonexistent nonexistent", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); ut_assertok(ut_check_console_end(uts));
+ /* Test getting default element of bad alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get value vbadalias badalias nonexistent", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting default element of nonexistent alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get value vnoalias noalias nonexistent", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); + ut_assertok(ut_check_console_end(uts)); + return 0; } FDT_TEST(fdt_test_get_value, UT_TESTF_CONSOLE_REC);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
The 'fdt' command help contains the following note: " Dereference aliases by omitting the leading '/', e.g. fdt print ethernet0. " Add test for it.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 65 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 20 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

The 'fdt get value' subcommand now supports extraction of integer value from integer arrays, add test for it, including a test for special case unindexed integer array read, which is handled as hash and treated as a long string instead of integer.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 58 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 16 deletions(-)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index e04ba37f19f..69a69c5c75c 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -239,38 +239,64 @@ static int fdt_test_addr_resize(struct unit_test_state *uts) FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
/* Test 'fdt get value' reading an fdt */ +static int fdt_test_get_value_string(struct unit_test_state *uts, + const char *node, const char *prop, + const char *idx, const char *strres, + const int intres) +{ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt get value var %s %s %s", + node, prop, idx ? : "")); + if (strres) { + ut_asserteq_str(strres, env_get("var")); + } else { + ut_asserteq(intres, env_get_hex("var", 0x1234)); + } + ut_assertok(ut_check_console_end(uts)); + + return 0; +} + static int fdt_test_get_value_common(struct unit_test_state *uts, const char *node) { /* Test getting default element of $node node clock-names property */ - ut_assertok(console_record_reset_enable()); - ut_assertok(run_commandf("fdt get value fdflt %s clock-names", node)); - ut_asserteq_str("fixed", env_get("fdflt")); - ut_assertok(ut_check_console_end(uts)); + fdt_test_get_value_string(uts, node, "clock-names", NULL, "fixed", 0);
/* Test getting 0th element of $node node clock-names property */ - ut_assertok(console_record_reset_enable()); - ut_assertok(run_commandf("fdt get value fzero %s clock-names 0", node)); - ut_asserteq_str("fixed", env_get("fzero")); - ut_assertok(ut_check_console_end(uts)); + fdt_test_get_value_string(uts, node, "clock-names", "0", "fixed", 0);
/* Test getting 1st element of $node node clock-names property */ - ut_assertok(console_record_reset_enable()); - ut_assertok(run_commandf("fdt get value fone %s clock-names 1", node)); - ut_asserteq_str("i2c", env_get("fone")); - ut_assertok(ut_check_console_end(uts)); + fdt_test_get_value_string(uts, node, "clock-names", "1", "i2c", 0);
/* Test getting 2nd element of $node node clock-names property */ - ut_assertok(console_record_reset_enable()); - ut_assertok(run_commandf("fdt get value ftwo %s clock-names 2", node)); - ut_asserteq_str("spi", env_get("ftwo")); - ut_assertok(ut_check_console_end(uts)); + fdt_test_get_value_string(uts, node, "clock-names", "2", "spi", 0); + + /* + * Test getting default element of $node node regs property. + * The result here is highly unusual, the non-index value read from + * integer array is a string of concatenated values from the array, + * but only if the array is shorter than 40 characters. Anything + * longer is an error. This is a special case for handling hashes. + */ + fdt_test_get_value_string(uts, node, "regs", NULL, "3412000000100000", 0); + + /* Test getting 0th element of $node node regs property */ + fdt_test_get_value_string(uts, node, "regs", "0", NULL, 0x1234); + + /* Test getting 1st element of $node node regs property */ + fdt_test_get_value_string(uts, node, "regs", "1", NULL, 0x1000);
/* Test missing 10th element of $node node clock-names property */ ut_assertok(console_record_reset_enable()); ut_asserteq(1, run_commandf("fdt get value ften %s clock-names 10", node)); ut_assertok(ut_check_console_end(uts));
+ /* Test missing 10th element of $node node regs property */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt get value ften %s regs 10", node)); + ut_assertok(ut_check_console_end(uts)); + /* Test getting default element of $node node nonexistent property */ ut_assertok(console_record_reset_enable()); ut_asserteq(1, run_commandf("fdt get value fnone %s nonexistent", node));

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
The 'fdt get value' subcommand now supports extraction of integer value from integer arrays, add test for it, including a test for special case unindexed integer array read, which is handled as hash and treated as a long string instead of integer.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 58 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 16 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt move' test which works as follows: - Create simple FDT, map it to sysmem - 'move' the FDT into new zeroed out sysmem location - Verify newly active FDT is in the new location - Compare both locations
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 69a69c5c75c..023b83eb019 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -238,6 +238,40 @@ static int fdt_test_addr_resize(struct unit_test_state *uts) } FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
+static int fdt_test_move(struct unit_test_state *uts) +{ + char fdt[256]; + ulong addr, newaddr = 0x10000; + const int size = sizeof(fdt); + uint32_t ts; + void *buf; + + /* Original source DT */ + ut_assertok(make_test_fdt(uts, fdt, size)); + ts = fdt_totalsize(fdt); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Moved target DT location */ + buf = map_sysmem(newaddr, size); + memset(buf, 0, size); + + /* Test moving the working FDT to a new location */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt move %08x %08x %x", addr, newaddr, ts)); + ut_assert_nextline("Working FDT set to %lx", newaddr); + ut_assertok(ut_check_console_end(uts)); + + /* Compare the source and destination DTs */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("cmp.b %08x %08x %x", addr, newaddr, ts)); + ut_assert_nextline("Total of %d byte(s) were the same", ts); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_move, UT_TESTF_CONSOLE_REC); + /* Test 'fdt get value' reading an fdt */ static int fdt_test_get_value_string(struct unit_test_state *uts, const char *node, const char *prop,

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt move' test which works as follows:
- Create simple FDT, map it to sysmem
- 'move' the FDT into new zeroed out sysmem location
- Verify newly active FDT is in the new location
- Compare both locations
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt resize' test which works as follows: - Create simple FDT with extra size 0, map it to sysmem - 'resize' the FDT by 0x2000 bytes - Verify the new space has been added to the FDT
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 023b83eb019..266fb6e3ed0 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -272,6 +272,30 @@ static int fdt_test_move(struct unit_test_state *uts) } FDT_TEST(fdt_test_move, UT_TESTF_CONSOLE_REC);
+static int fdt_test_resize(struct unit_test_state *uts) +{ + char fdt[256]; + const unsigned int newsize = 0x2000; + uint32_t ts; + ulong addr; + + /* Original source DT */ + ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt))); + fdt_shrink_to_minimum(fdt, 0); /* Resize with 0 extra bytes */ + ts = fdt_totalsize(fdt); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test resizing the working FDT and verify the new space was added */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt resize %x", newsize)); + ut_asserteq(ts + newsize, fdt_totalsize(fdt)); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_resize, UT_TESTF_CONSOLE_REC); + /* Test 'fdt get value' reading an fdt */ static int fdt_test_get_value_string(struct unit_test_state *uts, const char *node, const char *prop,

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt resize' test which works as follows:
- Create simple FDT with extra size 0, map it to sysmem
- 'resize' the FDT by 0x2000 bytes
- Verify the new space has been added to the FDT
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt print' and 'fdt list' test which works as follows: - Create fuller FDT, map it to sysmem - Print the entire FDT, parts of the FDT and select properties - Compare output from the print or list
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 266fb6e3ed0..793525c02c5 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -296,6 +296,149 @@ static int fdt_test_resize(struct unit_test_state *uts) } FDT_TEST(fdt_test_resize, UT_TESTF_CONSOLE_REC);
+static int fdt_test_print_list_common(struct unit_test_state *uts, + const char *opc, const char *node) +{ + /* + * Test printing/listing the working FDT + * subnode $node/subnode + */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt %s %s/subnode", opc, node)); + ut_assert_nextline("subnode {"); + ut_assert_nextline("\t#address-cells = <0x00000000>;"); + ut_assert_nextline("\t#size-cells = <0x00000000>;"); + ut_assert_nextline("\tcompatible = "u-boot,fdt-subnode-test-device";"); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + /* + * Test printing/listing the working FDT + * path / string property model + */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt %s / model", opc)); + ut_assert_nextline("model = "U-Boot FDT test""); + ut_assertok(ut_check_console_end(uts)); + + /* + * Test printing/listing the working FDT + * path $node string property compatible + */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt %s %s compatible", opc, node)); + ut_assert_nextline("compatible = "u-boot,fdt-test-device1""); + ut_assertok(ut_check_console_end(uts)); + + /* + * Test printing/listing the working FDT + * path $node stringlist property clock-names + */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt %s %s clock-names", opc, node)); + ut_assert_nextline("clock-names = "fixed", "i2c", "spi", "uart2", "uart1""); + ut_assertok(ut_check_console_end(uts)); + + /* + * Test printing/listing the working FDT + * path $node u32 property clock-frequency + */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt %s %s clock-frequency", opc, node)); + ut_assert_nextline("clock-frequency = <0x00fde800>"); + ut_assertok(ut_check_console_end(uts)); + + /* + * Test printing/listing the working FDT + * path $node empty property u-boot,empty-property + */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt %s %s u-boot,empty-property", opc, node)); + /* + * This is the only 'fdt print' / 'fdt list' incantation which + * prefixes the property with node path. This has been in U-Boot + * since the beginning of the command 'fdt', keep it. + */ + ut_assert_nextline("%s u-boot,empty-property", node); + ut_assertok(ut_check_console_end(uts)); + + /* + * Test printing/listing the working FDT + * path $node prop-encoded array property regs + */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt %s %s regs", opc, node)); + ut_assert_nextline("regs = <0x00001234 0x00001000>"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} + +static int fdt_test_print_list(struct unit_test_state *uts, bool print) +{ + const char *opc = print ? "print" : "list"; + char fdt[4096]; + ulong addr; + int ret; + + /* Original source DT */ + ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test printing/listing the working FDT -- node / */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt %s", opc)); + ut_assert_nextline("/ {"); + ut_assert_nextline("\t#address-cells = <0x00000001>;"); + ut_assert_nextline("\t#size-cells = <0x00000001>;"); + ut_assert_nextline("\tcompatible = "u-boot,fdt-test";"); + ut_assert_nextline("\tmodel = "U-Boot FDT test";"); + ut_assert_nextline("\taliases {"); + if (print) { + ut_assert_nextline("\t\tbadalias = "/bad/alias";"); + ut_assert_nextline("\t\tsubnodealias = "/test-node@1234/subnode";"); + ut_assert_nextline("\t\ttestnodealias = "/test-node@1234";"); + } + ut_assert_nextline("\t};"); + ut_assert_nextline("\ttest-node@1234 {"); + if (print) { + ut_assert_nextline("\t\t#address-cells = <0x00000000>;"); + ut_assert_nextline("\t\t#size-cells = <0x00000000>;"); + ut_assert_nextline("\t\tcompatible = "u-boot,fdt-test-device1";"); + ut_assert_nextline("\t\tclock-names = "fixed", "i2c", "spi", "uart2", "uart1";"); + ut_assert_nextline("\t\tu-boot,empty-property;"); + ut_assert_nextline("\t\tclock-frequency = <0x00fde800>;"); + ut_assert_nextline("\t\tregs = <0x00001234 0x00001000>;"); + ut_assert_nextline("\t\tsubnode {"); + ut_assert_nextline("\t\t\t#address-cells = <0x00000000>;"); + ut_assert_nextline("\t\t\t#size-cells = <0x00000000>;"); + ut_assert_nextline("\t\t\tcompatible = "u-boot,fdt-subnode-test-device";"); + ut_assert_nextline("\t\t};"); + } + ut_assert_nextline("\t};"); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + ret = fdt_test_print_list_common(uts, opc, "/test-node@1234"); + if (!ret) + ret = fdt_test_print_list_common(uts, opc, "testnodealias"); + + return 0; +} + +static int fdt_test_print(struct unit_test_state *uts) +{ + return fdt_test_print_list(uts, true); +} +FDT_TEST(fdt_test_print, UT_TESTF_CONSOLE_REC); + +static int fdt_test_list(struct unit_test_state *uts) +{ + return fdt_test_print_list(uts, false); +} +FDT_TEST(fdt_test_list, UT_TESTF_CONSOLE_REC); + /* Test 'fdt get value' reading an fdt */ static int fdt_test_get_value_string(struct unit_test_state *uts, const char *node, const char *prop,

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt print' and 'fdt list' test which works as follows:
- Create fuller FDT, map it to sysmem
- Print the entire FDT, parts of the FDT and select properties
- Compare output from the print or list
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt get name' test which works as follows: - Create fuller FDT, map it to sysmem - Get name of / node 0, 1 and /clk-test node 0 - Compare output and validate the node name - Get name of / node 2 and /clk-test node 1 - Compare output and validate the node is not present - Get name of / node -1 and /clk-test node -1 - Compare output and validate the node name equals node 0 name - Check nonexistent node, verify the command errors out
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 793525c02c5..fa95241c8f2 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -545,6 +545,85 @@ static int fdt_test_get_value(struct unit_test_state *uts) } FDT_TEST(fdt_test_get_value, UT_TESTF_CONSOLE_REC);
+static int fdt_test_get_name(struct unit_test_state *uts) +{ + char fdt[4096]; + ulong addr; + + ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test getting name of node 0 in /, which is /aliases node */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_command("fdt get name nzero / 0", 0)); + ut_asserteq_str("aliases", env_get("nzero")); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting name of node 1 in /, which is /test-node@1234 node */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_command("fdt get name none / 1", 0)); + ut_asserteq_str("test-node@1234", env_get("none")); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting name of node -1 in /, which is /aliases node, same as 0 */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_command("fdt get name nmone / -1", 0)); + ut_asserteq_str("aliases", env_get("nmone")); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting name of node 2 in /, which does not exist */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get name ntwo / 2", 1)); + ut_assert_nextline("libfdt node not found"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting name of node 0 in /test-node@1234, which is /subnode node */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_command("fdt get name snzero /test-node@1234 0", 0)); + ut_asserteq_str("subnode", env_get("snzero")); + ut_assertok(run_command("fdt get name asnzero testnodealias 0", 0)); + ut_asserteq_str("subnode", env_get("asnzero")); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting name of node 1 in /test-node@1234, which does not exist */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get name snone /test-node@1234 1", 1)); + ut_assert_nextline("libfdt node not found"); + ut_asserteq(1, run_command("fdt get name asnone testnodealias 1", 1)); + ut_assert_nextline("libfdt node not found"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting name of node -1 in /test-node@1234, which is /subnode node, same as 0 */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_command("fdt get name snmone /test-node@1234 -1", 0)); + ut_asserteq_str("subnode", env_get("snmone")); + ut_assertok(run_command("fdt get name asnmone testnodealias -1", 0)); + ut_asserteq_str("subnode", env_get("asnmone")); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting name of nonexistent node */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get name nonode /nonexistent 0", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting name of bad alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get name vbadalias badalias 0", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting name of nonexistent alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get name vnoalias noalias 0", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_get_name, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt get name' test which works as follows:
- Create fuller FDT, map it to sysmem
- Get name of / node 0, 1 and /clk-test node 0
- Compare output and validate the node name
- Get name of / node 2 and /clk-test node 1
- Compare output and validate the node is not present
- Get name of / node -1 and /clk-test node -1
- Compare output and validate the node name equals node 0 name
- Check nonexistent node, verify the command errors out
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt get addr' test which works as follows: - Create fuller FDT, map it to sysmem - Get address of various properties - Compare addresses calculated by UT and fdt command
This test is special in that it has to go through gruesome remapping scheme where the test calculates: - pointer offsets of the generated FDT root and the property being tested - map_sysmem() result of environment variable "fdtaddr" and the one set by the test matching address of property being tested - difference between the later and the former, to obtain offset of the DT property from start of DT The offsets must match in both the UT and the tested U-Boot, if they do not, the test fails.
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index fa95241c8f2..e829052bfd9 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -624,6 +624,72 @@ static int fdt_test_get_name(struct unit_test_state *uts) } FDT_TEST(fdt_test_get_name, UT_TESTF_CONSOLE_REC);
+static int fdt_test_get_addr_common(struct unit_test_state *uts, char *fdt, + const char *path, const char *prop) +{ + unsigned int offset; + int path_offset; + void *prop_ptr; + int len = 0; + + ut_assert((path_offset = fdt_path_offset(fdt, path)) >= 0); + ut_assertnonnull(prop_ptr = (void *)fdt_getprop(fdt, path_offset, + prop, &len)); + offset = (char *)prop_ptr - fdt; + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt get addr pstr %s %s", path, prop)); + ut_asserteq((ulong)map_sysmem(env_get_hex("fdtaddr", 0x1234), 0), + (ulong)(map_sysmem(env_get_hex("pstr", 0x1234), 0) - offset)); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} + +static int fdt_test_get_addr(struct unit_test_state *uts) +{ + char fdt[4096]; + ulong addr; + + ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test getting address of root node / string property "compatible" */ + fdt_test_get_addr_common(uts, fdt, "/", "compatible"); + + /* Test getting address of node /test-node@1234 stringlist property "clock-names" */ + fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "clock-names"); + fdt_test_get_addr_common(uts, fdt, "testnodealias", "clock-names"); + + /* Test getting address of node /test-node@1234 u32 property "clock-frequency" */ + fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "clock-frequency"); + fdt_test_get_addr_common(uts, fdt, "testnodealias", "clock-frequency"); + + /* Test getting address of node /test-node@1234 empty property "u-boot,empty-property" */ + fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "u-boot,empty-property"); + fdt_test_get_addr_common(uts, fdt, "testnodealias", "u-boot,empty-property"); + + /* Test getting address of node /test-node@1234 array property "regs" */ + fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "regs"); + fdt_test_get_addr_common(uts, fdt, "testnodealias", "regs"); + + /* Test getting address of node /test-node@1234/subnode non-existent property "noprop" */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get addr pnoprop /test-node@1234/subnode noprop", 1)); + ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting address of non-existent node /test-node@1234/nonode@1 property "noprop" */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get addr pnonode /test-node@1234/nonode@1 noprop", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_get_addr, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

Hi Marek,
On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt get addr' test which works as follows:
- Create fuller FDT, map it to sysmem
- Get address of various properties
- Compare addresses calculated by UT and fdt command
This test is special in that it has to go through gruesome remapping scheme where the test calculates:
- pointer offsets of the generated FDT root and the property being tested
- map_sysmem() result of environment variable "fdtaddr" and the one set by the test matching address of property being tested
- difference between the later and the former, to obtain offset of the DT property from start of DT
The offsets must match in both the UT and the tested U-Boot, if they do not, the test fails.
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index fa95241c8f2..e829052bfd9 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -624,6 +624,72 @@ static int fdt_test_get_name(struct unit_test_state *uts) } FDT_TEST(fdt_test_get_name, UT_TESTF_CONSOLE_REC);
+static int fdt_test_get_addr_common(struct unit_test_state *uts, char *fdt,
const char *path, const char *prop)
+{
unsigned int offset;
int path_offset;
void *prop_ptr;
int len = 0;
ut_assert((path_offset = fdt_path_offset(fdt, path)) >= 0);
I would suggest doing the assigning in a previous line, same below.
ut_assertnonnull(prop_ptr = (void *)fdt_getprop(fdt, path_offset,
prop, &len));
offset = (char *)prop_ptr - fdt;
ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt get addr pstr %s %s", path, prop));
ut_asserteq((ulong)map_sysmem(env_get_hex("fdtaddr", 0x1234), 0),
(ulong)(map_sysmem(env_get_hex("pstr", 0x1234), 0) - offset));
ut_assertok(ut_check_console_end(uts));
return 0;
+}
[..]
Regards, SImon

Add 'fdt get size' test which works as follows: - Create fuller FDT, map it to sysmem - Get size of various properties - Get node count of available nodes - Test non-existent nodes and properties
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index e829052bfd9..ae67b468b71 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -690,6 +690,93 @@ static int fdt_test_get_addr(struct unit_test_state *uts) } FDT_TEST(fdt_test_get_addr, UT_TESTF_CONSOLE_REC);
+static int fdt_test_get_size_common(struct unit_test_state *uts, + const char *path, const char *prop, + const unsigned int val) +{ + ut_assertok(console_record_reset_enable()); + if (prop) { + ut_assertok(run_commandf("fdt get size sstr %s %s", path, prop)); + } else { + ut_assertok(run_commandf("fdt get size sstr %s", path)); + } + ut_asserteq(val, env_get_hex("sstr", 0x1234)); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} + +static int fdt_test_get_size(struct unit_test_state *uts) +{ + char fdt[4096]; + ulong addr; + + ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test getting size of root node / string property "compatible" */ + fdt_test_get_size_common(uts, "/", "compatible", 16); + + /* Test getting size of node /test-node@1234 stringlist property "clock-names" */ + fdt_test_get_size_common(uts, "/test-node@1234", "clock-names", 26); + fdt_test_get_size_common(uts, "testnodealias", "clock-names", 26); + + /* Test getting size of node /test-node@1234 u32 property "clock-frequency" */ + fdt_test_get_size_common(uts, "/test-node@1234", "clock-frequency", 4); + fdt_test_get_size_common(uts, "testnodealias", "clock-frequency", 4); + + /* Test getting size of node /test-node@1234 empty property "u-boot,empty-property" */ + fdt_test_get_size_common(uts, "/test-node@1234", "u-boot,empty-property", 0); + fdt_test_get_size_common(uts, "testnodealias", "u-boot,empty-property", 0); + + /* Test getting size of node /test-node@1234 array property "regs" */ + fdt_test_get_size_common(uts, "/test-node@1234", "regs", 8); + fdt_test_get_size_common(uts, "testnodealias", "regs", 8); + + /* Test getting node count of node / */ + fdt_test_get_size_common(uts, "/", NULL, 2); + + /* Test getting node count of node /test-node@1234/subnode */ + fdt_test_get_size_common(uts, "/test-node@1234/subnode", NULL, 0); + fdt_test_get_size_common(uts, "subnodealias", NULL, 0); + + /* Test getting size of node /test-node@1234/subnode non-existent property "noprop" */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get size pnoprop /test-node@1234/subnode noprop", 1)); + ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); + ut_asserteq(1, run_command("fdt get size pnoprop subnodealias noprop", 1)); + ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting size of non-existent node /test-node@1234/nonode@1 property "noprop" */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get size pnonode /test-node@1234/nonode@1 noprop", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting node count of non-existent node /test-node@1234/nonode@1 */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get size pnonode /test-node@1234/nonode@1", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting node count of bad alias badalias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get size pnonode badalias noprop", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting node count of non-existent alias noalias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt get size pnonode noalias", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_get_size, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt get size' test which works as follows:
- Create fuller FDT, map it to sysmem
- Get size of various properties
- Get node count of available nodes
- Test non-existent nodes and properties
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt set' test which works as follows: - Create fuller FDT, map it to sysmem - Set either existing property to overwrite it, or new property - Test setting both single properties as well as string and integer arrays - Test setting to non-existent nodes and aliases - Verify set values using 'fdt get value'
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index ae67b468b71..42d067090aa 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -777,6 +777,129 @@ static int fdt_test_get_size(struct unit_test_state *uts) } FDT_TEST(fdt_test_get_size, UT_TESTF_CONSOLE_REC);
+static int fdt_test_set_single(struct unit_test_state *uts, + const char *path, const char *prop, + const char *sval, int ival, bool integer) +{ + ut_assertok(console_record_reset_enable()); + if (sval) { + ut_assertok(run_commandf("fdt set %s %s %s", path, prop, sval)); + } else if (integer) { + ut_assertok(run_commandf("fdt set %s %s <%d>", path, prop, ival)); + } else { + ut_assertok(run_commandf("fdt set %s %s", path, prop)); + } + + ut_assertok(run_commandf("fdt get value svar %s %s", path, prop)); + if (sval) { + ut_asserteq_str(sval, env_get("svar")); + } else if (integer) { + ut_asserteq(ival, env_get_hex("svar", 0x1234)); + } else { + ut_assertnull(env_get("svar")); + } + ut_assertok(ut_check_console_end(uts)); + + return 0; +} + +static int fdt_test_set_multi(struct unit_test_state *uts, + const char *path, const char *prop, + const char *sval1, const char *sval2, + int ival1, int ival2) +{ + ut_assertok(console_record_reset_enable()); + if (sval1 && sval2) { + ut_assertok(run_commandf("fdt set %s %s %s %s end", path, prop, sval1, sval2)); + ut_assertok(run_commandf("fdt set %s %s %s %s", path, prop, sval1, sval2)); + } else { + ut_assertok(run_commandf("fdt set %s %s <%d %d 10>", path, prop, ival1, ival2)); + ut_assertok(run_commandf("fdt set %s %s <%d %d>", path, prop, ival1, ival2)); + } + + /* + * The "end/10" above and "svarn" below is used to validate that + * previous 'fdt set' to longer array does not polute newly set + * shorter array. + */ + ut_assertok(run_commandf("fdt get value svar1 %s %s 0", path, prop)); + ut_assertok(run_commandf("fdt get value svar2 %s %s 1", path, prop)); + ut_asserteq(1, run_commandf("fdt get value svarn %s %s 2", path, prop)); + if (sval1 && sval2) { + ut_asserteq_str(sval1, env_get("svar1")); + ut_asserteq_str(sval2, env_get("svar2")); + ut_assertnull(env_get("svarn")); + } else { + ut_asserteq(ival1, env_get_hex("svar1", 0x1234)); + ut_asserteq(ival2, env_get_hex("svar2", 0x1234)); + ut_assertnull(env_get("svarn")); + } + ut_assertok(ut_check_console_end(uts)); + + return 0; +} + +static int fdt_test_set_node(struct unit_test_state *uts, + const char *path, const char *prop) +{ + fdt_test_set_single(uts, path, prop, "new", 0, false); + fdt_test_set_single(uts, path, prop, "rewrite", 0, false); + fdt_test_set_single(uts, path, prop, NULL, 42, true); + fdt_test_set_single(uts, path, prop, NULL, 0, false); + fdt_test_set_multi(uts, path, prop, NULL, NULL, 42, 1701); + fdt_test_set_multi(uts, path, prop, NULL, NULL, 74656, 9); + fdt_test_set_multi(uts, path, prop, "42", "1701", 0, 0); + fdt_test_set_multi(uts, path, prop, "74656", "9", 0, 0); + + return 0; +} + +static int fdt_test_set(struct unit_test_state *uts) +{ + char fdt[8192]; + ulong addr; + + ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); + fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */ + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test setting of root node / existing property "compatible" */ + fdt_test_set_node(uts, "/", "compatible"); + + /* Test setting of root node / new property "newproperty" */ + fdt_test_set_node(uts, "/", "newproperty"); + + /* Test setting of subnode existing property "compatible" */ + fdt_test_set_node(uts, "/test-node@1234/subnode", "compatible"); + fdt_test_set_node(uts, "subnodealias", "compatible"); + + /* Test setting of subnode new property "newproperty" */ + fdt_test_set_node(uts, "/test-node@1234/subnode", "newproperty"); + fdt_test_set_node(uts, "subnodealias", "newproperty"); + + /* Test setting property of non-existent node */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt set /no-node noprop", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test setting property of non-existent alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt set noalias noprop", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); + ut_assertok(ut_check_console_end(uts)); + + /* Test setting property of bad alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_command("fdt set badalias noprop", 1)); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_set, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

Hi Marek,
On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt set' test which works as follows:
- Create fuller FDT, map it to sysmem
- Set either existing property to overwrite it, or new property
- Test setting both single properties as well as string and integer arrays
- Test setting to non-existent nodes and aliases
- Verify set values using 'fdt get value'
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index ae67b468b71..42d067090aa 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -777,6 +777,129 @@ static int fdt_test_get_size(struct unit_test_state *uts) } FDT_TEST(fdt_test_get_size, UT_TESTF_CONSOLE_REC);
+static int fdt_test_set_single(struct unit_test_state *uts,
const char *path, const char *prop,
const char *sval, int ival, bool integer)
Please add a comment for this function.
+{
ut_assertok(console_record_reset_enable());
if (sval) {
ut_assertok(run_commandf("fdt set %s %s %s", path, prop, sval));
} else if (integer) {
ut_assertok(run_commandf("fdt set %s %s <%d>", path, prop, ival));
} else {
ut_assertok(run_commandf("fdt set %s %s", path, prop));
}
Should drop {} on single-line statements - please check patman
ut_assertok(run_commandf("fdt get value svar %s %s", path, prop));
if (sval) {
ut_asserteq_str(sval, env_get("svar"));
} else if (integer) {
ut_asserteq(ival, env_get_hex("svar", 0x1234));
} else {
ut_assertnull(env_get("svar"));
}
ut_assertok(ut_check_console_end(uts));
return 0;
+}
+static int fdt_test_set_multi(struct unit_test_state *uts,
const char *path, const char *prop,
const char *sval1, const char *sval2,
int ival1, int ival2)
and this could use a comment too
+{
ut_assertok(console_record_reset_enable());
if (sval1 && sval2) {
ut_assertok(run_commandf("fdt set %s %s %s %s end", path, prop, sval1, sval2));
ut_assertok(run_commandf("fdt set %s %s %s %s", path, prop, sval1, sval2));
} else {
ut_assertok(run_commandf("fdt set %s %s <%d %d 10>", path, prop, ival1, ival2));
ut_assertok(run_commandf("fdt set %s %s <%d %d>", path, prop, ival1, ival2));
}
[..]
Regards, Simon

On 3/1/23 16:02, Simon Glass wrote:
Hi Marek,
On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt set' test which works as follows:
- Create fuller FDT, map it to sysmem
- Set either existing property to overwrite it, or new property
- Test setting both single properties as well as string and integer arrays
- Test setting to non-existent nodes and aliases
- Verify set values using 'fdt get value'
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index ae67b468b71..42d067090aa 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -777,6 +777,129 @@ static int fdt_test_get_size(struct unit_test_state *uts) } FDT_TEST(fdt_test_get_size, UT_TESTF_CONSOLE_REC);
+static int fdt_test_set_single(struct unit_test_state *uts,
const char *path, const char *prop,
const char *sval, int ival, bool integer)
Please add a comment for this function.
+{
ut_assertok(console_record_reset_enable());
if (sval) {
ut_assertok(run_commandf("fdt set %s %s %s", path, prop, sval));
} else if (integer) {
ut_assertok(run_commandf("fdt set %s %s <%d>", path, prop, ival));
} else {
ut_assertok(run_commandf("fdt set %s %s", path, prop));
}
Should drop {} on single-line statements - please check patman
This one isn't as simple as "drop the {}" in fact, I sent a separate series to address that:
https://patchwork.ozlabs.org/project/uboot/list/?series=344329

On Wed, 1 Mar 2023 at 20:07, Marek Vasut marek.vasut@mailbox.org wrote:
On 3/1/23 16:02, Simon Glass wrote:
Hi Marek,
On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt set' test which works as follows:
- Create fuller FDT, map it to sysmem
- Set either existing property to overwrite it, or new property
- Test setting both single properties as well as string and integer arrays
- Test setting to non-existent nodes and aliases
- Verify set values using 'fdt get value'
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index ae67b468b71..42d067090aa 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -777,6 +777,129 @@ static int fdt_test_get_size(struct unit_test_state *uts) } FDT_TEST(fdt_test_get_size, UT_TESTF_CONSOLE_REC);
+static int fdt_test_set_single(struct unit_test_state *uts,
const char *path, const char *prop,
const char *sval, int ival, bool integer)
Please add a comment for this function.
+{
ut_assertok(console_record_reset_enable());
if (sval) {
ut_assertok(run_commandf("fdt set %s %s %s", path, prop, sval));
} else if (integer) {
ut_assertok(run_commandf("fdt set %s %s <%d>", path, prop, ival));
} else {
ut_assertok(run_commandf("fdt set %s %s", path, prop));
}
Should drop {} on single-line statements - please check patman
This one isn't as simple as "drop the {}" in fact, I sent a separate series to address that:
https://patchwork.ozlabs.org/project/uboot/list/?series=344329
Oh yes, I hit that a while back.
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt mknode' test which works as follows: - Create fuller FDT, map it to sysmem - Create node either in / or subnode - Attempt to create node over existing node, which fails - Attempt to create subnodes in non-existing nodes or aliases - Verify created nodes using fdt list command
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 42d067090aa..dec783f6e26 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -900,6 +900,74 @@ static int fdt_test_set(struct unit_test_state *uts) } FDT_TEST(fdt_test_set, UT_TESTF_CONSOLE_REC);
+static int fdt_test_mknode(struct unit_test_state *uts) +{ + char fdt[8192]; + ulong addr; + + ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); + fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */ + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test creation of new node in / */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt mknode / newnode")); + ut_assertok(run_commandf("fdt list /newnode")); + ut_assert_nextline("newnode {"); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + /* Test creation of new node in /test-node@1234 */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt mknode /test-node@1234 newsubnode")); + ut_assertok(run_commandf("fdt list /test-node@1234/newsubnode")); + ut_assert_nextline("newsubnode {"); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + /* Test creation of new node in /test-node@1234 by alias */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt mknode testnodealias newersubnode")); + ut_assertok(run_commandf("fdt list testnodealias/newersubnode")); + ut_assert_nextline("newersubnode {"); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + /* Test creation of new node in /test-node@1234 over existing node */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt mknode testnodealias newsubnode")); + ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS"); + ut_assertok(ut_check_console_end(uts)); + + /* Test creation of new node in /test-node@1234 by alias over existing node */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt mknode testnodealias newersubnode")); + ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS"); + ut_assertok(ut_check_console_end(uts)); + + /* Test creation of new node in non-existent node */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt mknode /no-node newnosubnode")); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test creation of new node in non-existent alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt mknode noalias newfailsubnode")); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); + ut_assertok(ut_check_console_end(uts)); + + /* Test creation of new node in bad alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt mknode badalias newbadsubnode")); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_mknode, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt mknode' test which works as follows:
- Create fuller FDT, map it to sysmem
- Create node either in / or subnode
- Attempt to create node over existing node, which fails
- Attempt to create subnodes in non-existing nodes or aliases
- Verify created nodes using fdt list command
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt rm' test which works as follows: - Create fuller FDT, map it to sysmem - Selectively delete nodes or properties by both path and aliases - Verify created nodes or properties using fdt print command
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index dec783f6e26..39a20337c95 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -968,6 +968,90 @@ static int fdt_test_mknode(struct unit_test_state *uts) } FDT_TEST(fdt_test_mknode, UT_TESTF_CONSOLE_REC);
+static int fdt_test_rm(struct unit_test_state *uts) +{ + char fdt[4096]; + ulong addr; + + ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test removal of property in root node / */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt print / compatible")); + ut_assert_nextline("compatible = "u-boot,fdt-test""); + ut_assertok(run_commandf("fdt rm / compatible")); + ut_asserteq(1, run_commandf("fdt print / compatible")); + ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test removal of property clock-names in subnode /test-node@1234 */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt print /test-node@1234 clock-names")); + ut_assert_nextline("clock-names = "fixed", "i2c", "spi", "uart2", "uart1""); + ut_assertok(run_commandf("fdt rm /test-node@1234 clock-names")); + ut_asserteq(1, run_commandf("fdt print /test-node@1234 clock-names")); + ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test removal of property u-boot,empty-property in subnode /test-node@1234 by alias */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt print testnodealias u-boot,empty-property")); + ut_assert_nextline("testnodealias u-boot,empty-property"); + ut_assertok(run_commandf("fdt rm testnodealias u-boot,empty-property")); + ut_asserteq(1, run_commandf("fdt print testnodealias u-boot,empty-property")); + ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test removal of non-existent property noprop in subnode /test-node@1234 */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt rm /test-node@1234 noprop")); + ut_assert_nextline("libfdt fdt_delprop(): FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test removal of non-existent node /no-node@5678 */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt rm /no-node@5678")); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test removal of subnode /test-node@1234/subnode by alias */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt rm subnodealias")); + ut_asserteq(1, run_commandf("fdt print /test-node@1234/subnode")); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test removal of node by non-existent alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt rm noalias")); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); + ut_assertok(ut_check_console_end(uts)); + + /* Test removal of node by bad alias */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt rm noalias")); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); + ut_assertok(ut_check_console_end(uts)); + + /* Test removal of node /test-node@1234 */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt rm /test-node@1234")); + ut_asserteq(1, run_commandf("fdt print /test-node@1234")); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test removal of node / */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt rm /")); + ut_asserteq(1, run_commandf("fdt print /")); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_rm, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt rm' test which works as follows:
- Create fuller FDT, map it to sysmem
- Selectively delete nodes or properties by both path and aliases
- Verify created nodes or properties using fdt print command
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt header' test which works as follows: - Create basic FDT, map it to sysmem - Print the FDT header - Get all members of the FDT header into variable and verify the variables contain correct data
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 39a20337c95..b0c7ff52ca3 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -1052,6 +1052,65 @@ static int fdt_test_rm(struct unit_test_state *uts) } FDT_TEST(fdt_test_rm, UT_TESTF_CONSOLE_REC);
+static int fdt_test_header_get(struct unit_test_state *uts, char fdt[4096], + const char *field, const unsigned long val) +{ + /* Test getting valid header entry */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt header get fvar %s", field)); + ut_asserteq(val, env_get_hex("fvar", 0x1234)); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting malformed header entry */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt header get fvar typo%stypo", field)); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} + +static int fdt_test_header(struct unit_test_state *uts) +{ + char fdt[256]; + ulong addr; + + ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test header print */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt header")); + ut_assert_nextline("magic:\t\t\t0x%x", fdt_magic(fdt)); + ut_assert_nextline("totalsize:\t\t0x%x (%d)", fdt_totalsize(fdt), fdt_totalsize(fdt)); + ut_assert_nextline("off_dt_struct:\t\t0x%x", fdt_off_dt_struct(fdt)); + ut_assert_nextline("off_dt_strings:\t\t0x%x", fdt_off_dt_strings(fdt)); + ut_assert_nextline("off_mem_rsvmap:\t\t0x%x", fdt_off_mem_rsvmap(fdt)); + ut_assert_nextline("version:\t\t%d", fdt_version(fdt)); + ut_assert_nextline("last_comp_version:\t%d", fdt_last_comp_version(fdt)); + ut_assert_nextline("boot_cpuid_phys:\t0x%x", fdt_boot_cpuid_phys(fdt)); + ut_assert_nextline("size_dt_strings:\t0x%x", fdt_size_dt_strings(fdt)); + ut_assert_nextline("size_dt_struct:\t\t0x%x", fdt_size_dt_struct(fdt)); + ut_assert_nextline("number mem_rsv:\t\t0x%x", fdt_num_mem_rsv(fdt)); + ut_assert_nextline_empty(); + ut_assertok(ut_check_console_end(uts)); + + /* Test header get */ + fdt_test_header_get(uts, fdt, "magic", fdt_magic(fdt)); + fdt_test_header_get(uts, fdt, "totalsize", fdt_totalsize(fdt)); + fdt_test_header_get(uts, fdt, "off_dt_struct", fdt_off_dt_struct(fdt)); + fdt_test_header_get(uts, fdt, "off_dt_strings", fdt_off_dt_strings(fdt)); + fdt_test_header_get(uts, fdt, "off_mem_rsvmap", fdt_off_mem_rsvmap(fdt)); + fdt_test_header_get(uts, fdt, "version", fdt_version(fdt)); + fdt_test_header_get(uts, fdt, "last_comp_version", fdt_last_comp_version(fdt)); + fdt_test_header_get(uts, fdt, "boot_cpuid_phys", fdt_boot_cpuid_phys(fdt)); + fdt_test_header_get(uts, fdt, "size_dt_strings", fdt_size_dt_strings(fdt)); + fdt_test_header_get(uts, fdt, "size_dt_struct", fdt_size_dt_struct(fdt)); + + return 0; +} +FDT_TEST(fdt_test_header, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt header' test which works as follows:
- Create basic FDT, map it to sysmem
- Print the FDT header
- Get all members of the FDT header into variable and verify the variables contain correct data
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt bootcpu' test which works as follows: - Create basic FDT, map it to sysmem - Print the FDT bootcpu - Set the FDT bootcpu and read the value back using 'fdt header get' - Perform the previous step twice to validate bootcpu overwrite
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index b0c7ff52ca3..f4dd4238ad2 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -1111,6 +1111,39 @@ static int fdt_test_header(struct unit_test_state *uts) } FDT_TEST(fdt_test_header, UT_TESTF_CONSOLE_REC);
+static int fdt_test_bootcpu(struct unit_test_state *uts) +{ + char fdt[256]; + ulong addr; + int i; + + ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test getting default bootcpu entry */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt header get bootcpu boot_cpuid_phys")); + ut_asserteq(0, env_get_ulong("bootcpu", 10, 0x1234)); + ut_assertok(ut_check_console_end(uts)); + + /* Test setting and getting new bootcpu entry, twice, to test overwrite */ + for (i = 42; i <= 43; i++) { + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt bootcpu %d", i)); + ut_assertok(ut_check_console_end(uts)); + + /* Test getting new bootcpu entry */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt header get bootcpu boot_cpuid_phys")); + ut_asserteq(i, env_get_ulong("bootcpu", 10, 0x1234)); + ut_assertok(ut_check_console_end(uts)); + } + + return 0; +} +FDT_TEST(fdt_test_bootcpu, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt bootcpu' test which works as follows:
- Create basic FDT, map it to sysmem
- Print the FDT bootcpu
- Set the FDT bootcpu and read the value back using 'fdt header get'
- Perform the previous step twice to validate bootcpu overwrite
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt memory' test which works as follows: - Create custom FDT with /memory node, with select #*cells, map it to sysmem - Perform memory fixup - Read back the /memory node and validate its content
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index f4dd4238ad2..ff97571a64b 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -1144,6 +1144,89 @@ static int fdt_test_bootcpu(struct unit_test_state *uts) } FDT_TEST(fdt_test_bootcpu, UT_TESTF_CONSOLE_REC);
+static int fdt_test_memory_cells(struct unit_test_state *uts, + const unsigned int cells) +{ + unsigned char *pada, *pads; + unsigned char *seta, *sets; + char fdt[8192]; + const int size = sizeof(fdt); + fdt32_t *regs; + ulong addr; + char *spc; + int i; + + /* Create DT with node /memory { regs = <0x100 0x200>; } and #*cells */ + ut_assertnonnull(regs = calloc(2 * cells, sizeof(*regs))); + ut_assertnonnull(pada = calloc(12, cells)); + ut_assertnonnull(pads = calloc(12, cells)); + ut_assertnonnull(seta = calloc(12, cells)); + ut_assertnonnull(sets = calloc(12, cells)); + for (i = cells; i >= 1; i--) { + regs[cells - 1] = cpu_to_fdt32(i * 0x10000); + regs[(cells * 2) - 1] = cpu_to_fdt32(~i); + snprintf(seta + (8 * (cells - i)), 9, "%08x", i * 0x10000); + snprintf(sets + (8 * (cells - i)), 9, "%08x", ~i); + spc = (i != 1) ? " " : ""; + snprintf(pada + (11 * (cells - i)), 12, "0x%08x%s", i * 0x10000, spc); + snprintf(pads + (11 * (cells - i)), 12, "0x%08x%s", ~i, spc); + } + + ut_assertok(fdt_create(fdt, size)); + ut_assertok(fdt_finish_reservemap(fdt)); + ut_assert(fdt_begin_node(fdt, "") >= 0); + ut_assertok(fdt_property_u32(fdt, "#address-cells", cells)); + ut_assertok(fdt_property_u32(fdt, "#size-cells", cells)); + ut_assert(fdt_begin_node(fdt, "memory") >= 0); + ut_assertok(fdt_property_string(fdt, "device_type", "memory")); + ut_assertok(fdt_property(fdt, "reg", ®s, cells * 2)); + ut_assertok(fdt_end_node(fdt)); + ut_assertok(fdt_end_node(fdt)); + ut_assertok(fdt_finish(fdt)); + fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */ + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test updating the memory node */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt memory 0x%s 0x%s", seta, sets)); + ut_assertok(run_commandf("fdt print /memory")); + ut_assert_nextline("memory {"); + ut_assert_nextline("\tdevice_type = "memory";"); + ut_assert_nextline("\treg = <%s %s>;", pada, pads); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + free(sets); + free(seta); + free(pads); + free(pada); + free(regs); + + return 0; +} + +static int fdt_test_memory(struct unit_test_state *uts) +{ + /* + * Test memory fixup for 32 and 64 bit systems, anything bigger is + * so far unsupported and fails because of simple_stroull() being + * 64bit tops in the 'fdt memory' command implementation. + */ + fdt_test_memory_cells(uts, 1); + fdt_test_memory_cells(uts, 2); + + /* + * The 'fdt memory' command is limited to /memory node, it does + * not support any other valid DT memory node format, which is + * either one or multiple /memory@adresss nodes. Therefore, this + * DT variant is not tested here. + */ + + return 0; +} +FDT_TEST(fdt_test_memory, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt memory' test which works as follows:
- Create custom FDT with /memory node, with select #*cells, map it to sysmem
- Perform memory fixup
- Read back the /memory node and validate its content
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt rsvmem' test which works as follows: - Create custom FDT with single reserved memory (rsvmem) entry, map it to sysmem - Add new rsvmem entry - Delete existing older rsvmem entry - Add new rsvmem entry again - Always print the rsvmem list and validate it
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index ff97571a64b..8f7a62584da 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -1227,6 +1227,69 @@ static int fdt_test_memory(struct unit_test_state *uts) } FDT_TEST(fdt_test_memory, UT_TESTF_CONSOLE_REC);
+static int fdt_test_rsvmem(struct unit_test_state *uts) +{ + char fdt[8192]; + ulong addr; + + ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt))); + fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */ + fdt_add_mem_rsv(fdt, 0x42, 0x1701); + fdt_add_mem_rsv(fdt, 0x74656, 0x9); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test default reserved memory node presence */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt rsvmem print")); + ut_assert_nextline("index\t\t start\t\t size"); + ut_assert_nextline("------------------------------------------------"); + ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x42, 0x1701); + ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x74656, 0x9); + ut_assertok(ut_check_console_end(uts)); + + /* Test add new reserved memory node */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt rsvmem add 0x1234 0x5678")); + ut_assertok(run_commandf("fdt rsvmem print")); + ut_assert_nextline("index\t\t start\t\t size"); + ut_assert_nextline("------------------------------------------------"); + ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x42, 0x1701); + ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x74656, 0x9); + ut_assert_nextline(" %x\t%016x\t%016x", 2, 0x1234, 0x5678); + ut_assertok(ut_check_console_end(uts)); + + /* Test delete reserved memory node */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt rsvmem delete 0")); + ut_assertok(run_commandf("fdt rsvmem print")); + ut_assert_nextline("index\t\t start\t\t size"); + ut_assert_nextline("------------------------------------------------"); + ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x74656, 0x9); + ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x1234, 0x5678); + ut_assertok(ut_check_console_end(uts)); + + /* Test re-add new reserved memory node */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt rsvmem add 0x42 0x1701")); + ut_assertok(run_commandf("fdt rsvmem print")); + ut_assert_nextline("index\t\t start\t\t size"); + ut_assert_nextline("------------------------------------------------"); + ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x74656, 0x9); + ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x1234, 0x5678); + ut_assert_nextline(" %x\t%016x\t%016x", 2, 0x42, 0x1701); + ut_assertok(ut_check_console_end(uts)); + + /* Test delete nonexistent reserved memory node */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt rsvmem delete 10")); + ut_assert_nextline("libfdt fdt_del_mem_rsv(): FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_rsvmem, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt rsvmem' test which works as follows:
- Create custom FDT with single reserved memory (rsvmem) entry, map it to sysmem
- Add new rsvmem entry
- Delete existing older rsvmem entry
- Add new rsvmem entry again
- Always print the rsvmem list and validate it
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt chosen' test which works as follows: - Create basic DT, map it to sysmem - Print /chosen node, verify it is nonexistent - Create chosen node - Print /chosen node, verify it contains only version - Create /chosen node with initrd entries - Print /chosen node, verify it contains version and initrd entries
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 8f7a62584da..721916b070d 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -1290,6 +1290,54 @@ static int fdt_test_rsvmem(struct unit_test_state *uts) } FDT_TEST(fdt_test_rsvmem, UT_TESTF_CONSOLE_REC);
+static int fdt_test_chosen(struct unit_test_state *uts) +{ + const char *env_bootargs = env_get("bootargs"); + char fdt[8192]; + ulong addr; + + ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt))); + fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */ + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test default chosen node presence, fail as there is no /chosen node */ + ut_assertok(console_record_reset_enable()); + ut_asserteq(1, run_commandf("fdt print /chosen")); + ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); + ut_assertok(ut_check_console_end(uts)); + + /* Test add new chosen node without initrd */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt chosen")); + ut_assertok(run_commandf("fdt print /chosen")); + ut_assert_nextline("chosen {"); + ut_assert_nextlinen("\tu-boot,version = "); /* Ignore the version string */ + if (env_bootargs) + ut_assert_nextline("\tbootargs = "%s";", env_bootargs); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + /* Test add new chosen node with initrd */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt chosen 0x1234 0x5678")); + ut_assertok(run_commandf("fdt print /chosen")); + ut_assert_nextline("chosen {"); + ut_assert_nextline("\tlinux,initrd-end = <0x%08x 0x%08x>;", + upper_32_bits(0x1234 + 0x5678 - 1), + lower_32_bits(0x1234 + 0x5678 - 1)); + ut_assert_nextline("\tlinux,initrd-start = <0x%08x 0x%08x>;", + upper_32_bits(0x1234), lower_32_bits(0x1234)); + ut_assert_nextlinen("\tu-boot,version = "); /* Ignore the version string */ + if (env_bootargs) + ut_assert_nextline("\tbootargs = "%s";", env_bootargs); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_chosen, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt chosen' test which works as follows:
- Create basic DT, map it to sysmem
- Print /chosen node, verify it is nonexistent
- Create chosen node
- Print /chosen node, verify it contains only version
- Create /chosen node with initrd entries
- Print /chosen node, verify it contains version and initrd entries
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add 'fdt chosen' test which works as follows: - Create basic DT, map it to sysmem - Apply DTO which adds single property via fragment (without address spec) - Apply DTO which adds more properties (string, u32, empty) and a subnode, with phandle via frament@0 and thus tests /__symbols__ node - Apply DTO which modifies property of the previous DTO via phandle and thus tests the /__fixups__ node - Print modified DT, verify it contains updates from DTOs
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 721916b070d..02c13e2d9b9 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -1338,6 +1338,158 @@ static int fdt_test_chosen(struct unit_test_state *uts) } FDT_TEST(fdt_test_chosen, UT_TESTF_CONSOLE_REC);
+static int fdt_test_apply(struct unit_test_state *uts) +{ + char fdt[8192], fdto[8192]; + ulong addr, addro; + + /* Create base DT with __symbols__ node */ + ut_assertok(fdt_create(fdt, sizeof(fdt))); + ut_assertok(fdt_finish_reservemap(fdt)); + ut_assert(fdt_begin_node(fdt, "") >= 0); + ut_assert(fdt_begin_node(fdt, "__symbols__") >= 0); + ut_assertok(fdt_end_node(fdt)); + ut_assertok(fdt_end_node(fdt)); + ut_assertok(fdt_finish(fdt)); + fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */ + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Create DTO which adds single property to root node / */ + ut_assertok(fdt_create(fdto, sizeof(fdto))); + ut_assertok(fdt_finish_reservemap(fdto)); + ut_assert(fdt_begin_node(fdto, "") >= 0); + ut_assert(fdt_begin_node(fdto, "fragment") >= 0); + ut_assertok(fdt_property_string(fdto, "target-path", "/")); + ut_assert(fdt_begin_node(fdto, "__overlay__") >= 0); + ut_assertok(fdt_property_string(fdto, "newstring", "newvalue")); + ut_assertok(fdt_end_node(fdto)); + ut_assertok(fdt_end_node(fdto)); + ut_assertok(fdt_finish(fdto)); + addro = map_to_sysmem(fdto); + + /* Test default DT print */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt print /")); + ut_assert_nextline("/ {"); + ut_assert_nextline("\t__symbols__ {"); + ut_assert_nextline("\t};"); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + /* Test simple DTO application */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt apply 0x%08x", addro)); + ut_assertok(run_commandf("fdt print /")); + ut_assert_nextline("/ {"); + ut_assert_nextline("\tnewstring = "newvalue";"); + ut_assert_nextline("\t__symbols__ {"); + ut_assert_nextline("\t};"); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + /* + * Create complex DTO which: + * - modifies newstring property in root node / + * - adds new properties to root node / + * - adds new subnode with properties to root node / + * - adds phandle to the subnode and therefore __symbols__ node + */ + ut_assertok(fdt_create(fdto, sizeof(fdto))); + ut_assertok(fdt_finish_reservemap(fdto)); + ut_assert(fdt_begin_node(fdto, "") >= 0); + ut_assertok(fdt_property_cell(fdto, "#address-cells", 1)); + ut_assertok(fdt_property_cell(fdto, "#size-cells", 0)); + + ut_assert(fdt_begin_node(fdto, "fragment@0") >= 0); + ut_assertok(fdt_property_string(fdto, "target-path", "/")); + ut_assert(fdt_begin_node(fdto, "__overlay__") >= 0); + ut_assertok(fdt_property_string(fdto, "newstring", "newervalue")); + ut_assertok(fdt_property_u32(fdto, "newu32", 0x12345678)); + ut_assertok(fdt_property(fdto, "empty-property", NULL, 0)); + ut_assert(fdt_begin_node(fdto, "subnode") >= 0); + ut_assertok(fdt_property_string(fdto, "subnewstring", "newervalue")); + ut_assertok(fdt_property_u32(fdto, "subnewu32", 0x12345678)); + ut_assertok(fdt_property(fdto, "subempty-property", NULL, 0)); + ut_assertok(fdt_property_u32(fdto, "phandle", 0x01)); + ut_assertok(fdt_end_node(fdto)); + ut_assertok(fdt_end_node(fdto)); + ut_assertok(fdt_end_node(fdto)); + + ut_assert(fdt_begin_node(fdto, "__symbols__") >= 0); + ut_assertok(fdt_property_string(fdto, "subnodephandle", "/fragment@0/__overlay__/subnode")); + ut_assertok(fdt_end_node(fdto)); + ut_assertok(fdt_finish(fdto)); + addro = map_to_sysmem(fdto); + + /* Test complex DTO application */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt apply 0x%08x", addro)); + ut_assertok(run_commandf("fdt print /")); + ut_assert_nextline("/ {"); + ut_assert_nextline("\tempty-property;"); + ut_assert_nextline("\tnewu32 = <0x12345678>;"); + ut_assert_nextline("\tnewstring = "newervalue";"); + ut_assert_nextline("\tsubnode {"); + ut_assert_nextline("\t\tphandle = <0x00000001>;"); + ut_assert_nextline("\t\tsubempty-property;"); + ut_assert_nextline("\t\tsubnewu32 = <0x12345678>;"); + ut_assert_nextline("\t\tsubnewstring = "newervalue";"); + ut_assert_nextline("\t};"); + ut_assert_nextline("\t__symbols__ {"); + ut_assert_nextline("\t\tsubnodephandle = "/subnode";"); + ut_assert_nextline("\t};"); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + /* + * Create complex DTO which: + * - modifies subnewu32 property in subnode via phandle and uses __fixups__ node + */ + ut_assertok(fdt_create(fdto, sizeof(fdto))); + ut_assertok(fdt_finish_reservemap(fdto)); + ut_assert(fdt_begin_node(fdto, "") >= 0); + ut_assertok(fdt_property_cell(fdto, "#address-cells", 1)); + ut_assertok(fdt_property_cell(fdto, "#size-cells", 0)); + + ut_assert(fdt_begin_node(fdto, "fragment@0") >= 0); + ut_assertok(fdt_property_u32(fdto, "target", 0xffffffff)); + ut_assert(fdt_begin_node(fdto, "__overlay__") >= 0); + ut_assertok(fdt_property_u32(fdto, "subnewu32", 0xabcdef01)); + ut_assertok(fdt_end_node(fdto)); + ut_assertok(fdt_end_node(fdto)); + + ut_assert(fdt_begin_node(fdto, "__fixups__") >= 0); + ut_assertok(fdt_property_string(fdto, "subnodephandle", "/fragment@0:target:0")); + ut_assertok(fdt_end_node(fdto)); + ut_assertok(fdt_end_node(fdto)); + ut_assertok(fdt_finish(fdto)); + addro = map_to_sysmem(fdto); + + /* Test complex DTO application */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt apply 0x%08x", addro)); + ut_assertok(run_commandf("fdt print /")); + ut_assert_nextline("/ {"); + ut_assert_nextline("\tempty-property;"); + ut_assert_nextline("\tnewu32 = <0x12345678>;"); + ut_assert_nextline("\tnewstring = "newervalue";"); + ut_assert_nextline("\tsubnode {"); + ut_assert_nextline("\t\tphandle = <0x00000001>;"); + ut_assert_nextline("\t\tsubempty-property;"); + ut_assert_nextline("\t\tsubnewu32 = <0xabcdef01>;"); + ut_assert_nextline("\t\tsubnewstring = "newervalue";"); + ut_assert_nextline("\t};"); + ut_assert_nextline("\t__symbols__ {"); + ut_assert_nextline("\t\tsubnodephandle = "/subnode";"); + ut_assert_nextline("\t};"); + ut_assert_nextline("};"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_apply, UT_TESTF_CONSOLE_REC); + int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt chosen' test which works as follows:
- Create basic DT, map it to sysmem
- Apply DTO which adds single property via fragment (without address spec)
- Apply DTO which adds more properties (string, u32, empty) and a subnode, with phandle via frament@0 and thus tests /__symbols__ node
- Apply DTO which modifies property of the previous DTO via phandle and thus tests the /__fixups__ node
- Print modified DT, verify it contains updates from DTOs
The test case can be triggered using: " ./u-boot -Dc 'ut fdt' " To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add list of missing tests for the 'fdt' command, currently the missing sandbox tests are only 'fdt boardsetup' and 'fdt checksign' .
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com --- test/cmd/fdt.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 02c13e2d9b9..cb9379cdd4f 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -15,6 +15,13 @@ #include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR; +/* + * Missing tests: + * fdt boardsetup - Do board-specific set up + * fdt checksign [<addr>] - check FIT signature + * <addr> - address of key blob + * default gd->fdt_blob + */
/* Declare a new fdt test */ #define FDT_TEST(_name, _flags) UNIT_TEST(_name, _flags, fdt_test)

Hi Marek,
On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add list of missing tests for the 'fdt' command, currently the missing sandbox tests are only 'fdt boardsetup' and 'fdt checksign' .
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 7 +++++++ 1 file changed, 7 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
This is a huge step forward...if we end up supporting livetree in the 'fdt' command it will make it fairly easy since we can use the same tests!
Regards, Simon

On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Import is_printable_string() implementation from DTC 1.7.0 as of DTC commit 039a994 ("Bump version to v1.7.0") . This fixes a print of u32 property which so far used to be printed as string by U-Boot fdt print command.
We might see the case where the parsed property value, in this case it is a 32-bit integer, identified as a printable string or a null byte (concatenated strings) because of its last character happens to be: 0x00 (null character), 0xB (vertical tab character) or 0x10 (line feed character) In this situation, if the string is identified as printable string, it will be displayed as character instead of hex value
When the isprint() condition is true, there are two possibilities:
- The character is ASCII character (except the first 32)
- The character is extended ASCII character
For example, NG property in device tree: clock-frequency = <16640000>; by default, would be displayed as clock-frequency = "", "ýè"; and with this patch applied, would be displayed as clock-frequency = <0x00fde800>;
Full investigation was done by Nam and Hai, patch reworked by Marek to use common code from DTC.
Signed-off-by: Hai Pham hai.pham.ud@renesas.com Signed-off-by: Nam Nguyen nam.nguyen.yh@renesas.com Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
cmd/fdt.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
participants (3)
-
Marek Vasut
-
Marek Vasut
-
Simon Glass