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 v3 2/2] bareboxtlv-generator: add raw "bytes"-format
Date: Tue, 20 Jan 2026 17:11:12 +0100 [thread overview]
Message-ID: <20260120-tlv_bind_serial-v3-2-91db0e4b07fb@pengutronix.de> (raw)
In-Reply-To: <20260120-tlv_bind_serial-v3-0-91db0e4b07fb@pengutronix.de>
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>
---
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.")
--
2.51.2.535.g419c72cb8a
prev parent reply other threads:[~2026-01-20 16:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 16:11 [PATCH v3 0/2] Bind TLV to SoC-UID register value Jonas Rebmann
2026-01-20 16:11 ` [PATCH v3 1/2] tlv: Add tlv_bind_soc_uid mapping Jonas Rebmann
2026-01-20 16:11 ` Jonas Rebmann [this message]
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=20260120-tlv_bind_serial-v3-2-91db0e4b07fb@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