mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jonas Rebmann <jre@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 BAREBOX <barebox@lists.infradead.org>
Cc: Jonas Rebmann <jre@pengutronix.de>
Subject: [PATCH RFC] bareboxtlv-generator: add raw "bytes"-format
Date: Wed, 12 Nov 2025 17:40:55 +0100	[thread overview]
Message-ID: <20251112-tlv-bytes-v1-1-d0ed7117e814@pengutronix.de> (raw)

Stores a byte sequence up to the maximum supported length of 65'535
bytes, encoded from and decoded to a hexadecimal representation.

Whitespace in the input string is skipped, allowing for arbitrary
grouping of the hexadecimal digits in the yaml input data.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
I did not end up using this format and no mappings/parsers exist on the
barebox end. Leaving the patch here for future reference.
---
 scripts/bareboxtlv-generator/bareboxtlv-generator.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/scripts/bareboxtlv-generator/bareboxtlv-generator.py b/scripts/bareboxtlv-generator/bareboxtlv-generator.py
index aa243d8b06..1fd5a45d43 100755
--- a/scripts/bareboxtlv-generator/bareboxtlv-generator.py
+++ b/scripts/bareboxtlv-generator/bareboxtlv-generator.py
@@ -320,6 +320,18 @@ class FactoryDataset:
                 if len(bin) > 2**16 - 1:
                     raise ValueError(f"String {name} is too long!")
 
+            elif tag_format == "bytes":
+                try:
+                    bin = bytes.fromhex(value)
+                except ValueError:
+                    raise ValueError(f"{name}: Invalid hex string for bytes format")
+                if "length" in tag:
+                    if tag["length"]!=len(bin):
+                        raise ValueError(f"{name}: schema requires this byte sequence to be {tag["length"]} bytes but the given sequence is {len(bin)} byte long.")
+                fmt = f"{len(bin)}s"
+                if len(bin) > 2**16 - 1:
+                    raise ValueError(f"Bytes {name} is too long!")
+
             elif tag_format == "decimal":
                 fmtl = tag["length"]
                 if fmtl == 1:
@@ -451,6 +463,8 @@ class FactoryDataset:
                 value = struct.unpack_from(fmt, bin, data_ptr)[0]
             elif tag_schema["format"] == "string":
                 value = bin[data_ptr : data_ptr + tag_len].decode("UTF-8")  # noqa E203
+            elif tag_schema["format"] == "bytes":
+                value = bin[data_ptr : data_ptr + tag_len].hex()
             elif tag_schema["format"] == "mac-sequence":
                 if tag_len != 7:
                     raise ValueError(f"Tag {name} has wrong length {hex(tag_len)} but expected 0x7.")

---
base-commit: f485ddfccf960959d25462073528d314b8bf1aea
change-id: 20251112-tlv-bytes-b007a9330be8

Best regards,
--  
Jonas Rebmann <jre@pengutronix.de>




                 reply	other threads:[~2025-11-12 16:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251112-tlv-bytes-v1-1-d0ed7117e814@pengutronix.de \
    --to=jre@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox