From: Rafał Miłecki <ra...@milecki.pl>

It's needed for extracting binary images.

Cc: Yousong Zhou <yszhou4t...@gmail.com>
Signed-off-by: Rafał Miłecki <ra...@milecki.pl>
---
 ...t-for-printing-raw-bytes-with-fdtget.patch | 78 +++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 
package/utils/dtc/patches/0001-Support-b-format-for-printing-raw-bytes-with-fdtget.patch

diff --git 
a/package/utils/dtc/patches/0001-Support-b-format-for-printing-raw-bytes-with-fdtget.patch
 
b/package/utils/dtc/patches/0001-Support-b-format-for-printing-raw-bytes-with-fdtget.patch
new file mode 100644
index 0000000000..388b25e7a7
--- /dev/null
+++ 
b/package/utils/dtc/patches/0001-Support-b-format-for-printing-raw-bytes-with-fdtget.patch
@@ -0,0 +1,78 @@
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <ra...@milecki.pl>
+Date: Mon, 6 Dec 2021 16:41:11 +0100
+Subject: [PATCH] Support 'b' format for printing raw bytes with fdtget
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+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 'b' (binary) format. Example usage:
+fdtget -t b firmware.itb /images/foo data > image.raw
+
+Signed-off-by: Rafał Miłecki <ra...@milecki.pl>
+---
+ fdtget.c |  5 +++++
+ util.c   | 24 ++++++++++++++----------
+ 2 files changed, 19 insertions(+), 10 deletions(-)
+
+--- a/fdtget.c
++++ b/fdtget.c
+@@ -91,6 +91,11 @@ static int show_data(struct display_info
+       if (len == 0)
+               return 0;
+ 
++      if (disp->type == 'b') {
++              fwrite(data, 1, len, stdout);
++              return 0;
++      }
++
+       is_string = (disp->type) == 's' ||
+               (!disp->type && util_is_printable_string(data, len));
+       if (is_string) {
+--- a/util.c
++++ b/util.c
+@@ -340,24 +340,28 @@ int utilfdt_decode_type(const char *fmt,
+ 
+       /* get the conversion qualifier */
+       *size = -1;
+-      if (strchr("hlLb", *fmt)) {
+-              qualifier = *fmt++;
+-              if (qualifier == *fmt) {
+-                      switch (*fmt++) {
+-/* TODO:              case 'l': qualifier = 'L'; break;*/
+-                      case 'h':
++      for (; *(fmt + 1); fmt++) {
++              if (!strchr("hlLb", *fmt))
++                      return -1;
++              if (qualifier) {
++                      if (*fmt == 'h' && qualifier == 'h')
+                               qualifier = 'b';
+-                              break;
+-                      }
++                      else
++                              return -1;
++              } else {
++                      qualifier = *fmt;
+               }
+       }
+ 
+       /* we should now have a type */
+-      if ((*fmt == '\0') || !strchr("iuxs", *fmt))
++      if (!strchr("iuxsb", *fmt)) {
++              if (*fmt)
++                      fprintf(stderr, "invalid type: %c\n", *fmt);
+               return -1;
++      }
+ 
+       /* convert qualifier (bhL) to byte size */
+-      if (*fmt != 's')
++      if (*fmt != 's' && *fmt != 'b')
+               *size = qualifier == 'b' ? 1 :
+                               qualifier == 'h' ? 2 :
+                               qualifier == 'l' ? 4 : -1;
-- 
2.31.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to