mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
Move property-printing into util
The function that prints a property can be useful to other programs, so move it into util. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
8055d77a5b
commit
d20391d6ff
3 changed files with 52 additions and 36 deletions
37
util.c
37
util.c
|
@ -335,3 +335,40 @@ int utilfdt_decode_type(const char *fmt, int *type, int *size)
|
|||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void utilfdt_print_data(const char *data, int len)
|
||||
{
|
||||
int i;
|
||||
const char *p = data;
|
||||
const char *s;
|
||||
|
||||
/* no data, don't print */
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
if (util_is_printable_string(data, len)) {
|
||||
printf(" = ");
|
||||
|
||||
s = data;
|
||||
do {
|
||||
printf("\"%s\"", s);
|
||||
s += strlen(s) + 1;
|
||||
if (s < data + len)
|
||||
printf(", ");
|
||||
} while (s < data + len);
|
||||
|
||||
} else if ((len % 4) == 0) {
|
||||
const uint32_t *cell = (const uint32_t *)data;
|
||||
|
||||
printf(" = <");
|
||||
for (i = 0; i < len; i += 4)
|
||||
printf("0x%08x%s", fdt32_to_cpu(cell[i]),
|
||||
i < (len - 4) ? " " : "");
|
||||
printf(">");
|
||||
} else {
|
||||
printf(" = [");
|
||||
for (i = 0; i < len; i++)
|
||||
printf("%02x%s", *p++, i < len - 1 ? " " : "");
|
||||
printf("]");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue