Support 'r' format for printing raw bytes with fdtget

FT is sometimes used for storing raw data. That is quite common for
U-Boot FIT images.

Extracting such data is not trivial currently. Using type 's' (string)
will replace every 0x00 (NUL) with 0x20 (space). Using type 'x' will
print bytes but in xxd incompatible format.

This commit adds support for 'r' (raw) format. Example usage:
fdtget -t r firmware.itb /images/foo data > image.raw

Support for encoding isn't added as there isn't any clean way of passing
binary data as command line argument.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Message-Id: <20211209061420.29466-1-zajec5@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Rafał Miłecki 2021-12-09 07:14:20 +01:00 committed by David Gibson
parent 45f3d1a095
commit 17739b7ef5
7 changed files with 18 additions and 5 deletions

View file

@ -73,6 +73,9 @@ static void check_sizes(char *modifier, int expected_size)
*ptr = 's';
check(fmt, 's', -1);
*ptr = 'r';
check(fmt, 'r', -1);
}
static void test_utilfdt_decode_type(void)
@ -90,7 +93,7 @@ static void test_utilfdt_decode_type(void)
/* try every other character */
checkfail("");
for (ch = ' '; ch < 127; ch++) {
if (!strchr("iuxs", ch)) {
if (!strchr("iuxsr", ch)) {
*fmt = ch;
fmt[1] = '\0';
checkfail(fmt);