summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut+renesas@mailbox.org>2023-03-02 04:08:14 +0100
committerSimon Glass <sjg@chromium.org>2023-03-08 11:40:56 -0800
commit56915fa4ccc7d995f832723b62ed403bd9a4cf44 (patch)
treecff9bbed63e1af246d6ee91272449facdedec956 /cmd
parentc21a5286af8571c4c729914edd2b2e4c478ad696 (diff)
downloadu-boot-56915fa4ccc7d995f832723b62ed403bd9a4cf44.tar.gz
u-boot-56915fa4ccc7d995f832723b62ed403bd9a4cf44.tar.bz2
u-boot-56915fa4ccc7d995f832723b62ed403bd9a4cf44.zip
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> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/fdt.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/cmd/fdt.c b/cmd/fdt.c
index 1972490bdc..bf2415661e 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