From: Andrei Ziureaev <andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v2 2/6] dtc: Add bytestring type
Date: Tue, 14 Jul 2020 16:45:38 +0100 [thread overview]
Message-ID: <20200714154542.18064-3-andrei.ziureaev@arm.com> (raw)
In-Reply-To: <20200714154542.18064-1-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
Differentiate between the /bits/ 8 <...> and [...] formats in dts output
by adding a TYPE_BYTESTRING type. This could be useful if we later end
up exporting the internal livetree to plugins.
Signed-off-by: Andrei Ziureaev <andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
---
dtc-parser.y | 2 +-
dtc.h | 1 +
tests/type-preservation.dt.yaml | 2 ++
tests/type-preservation.dts | 6 ++++--
treesource.c | 24 +++++++++++++++---------
5 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/dtc-parser.y b/dtc-parser.y
index a0316a3..c8c1875 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -520,7 +520,7 @@ integer_unary:
bytestring:
/* empty */
{
- $$ = data_add_marker(empty_data, TYPE_UINT8, NULL);
+ $$ = data_add_marker(empty_data, TYPE_BYTESTRING, NULL);
}
| bytestring DT_BYTE
{
diff --git a/dtc.h b/dtc.h
index a08f415..e3225ab 100644
--- a/dtc.h
+++ b/dtc.h
@@ -100,6 +100,7 @@ enum markertype {
TYPE_UINT32,
TYPE_UINT64,
TYPE_STRING,
+ TYPE_BYTESTRING,
};
extern const char *markername(enum markertype markertype);
diff --git a/tests/type-preservation.dt.yaml b/tests/type-preservation.dt.yaml
index ee8cfde..98f05df 100644
--- a/tests/type-preservation.dt.yaml
+++ b/tests/type-preservation.dt.yaml
@@ -5,6 +5,8 @@
compatible: ["subnode1"]
reg: [[0x1]]
int-array: [[0x0, 0x1], [0x2, 0x3]]
+ byte: [!u8 [0x56]]
+ bytestring: [!u8 [0x0, 0x12, 0x34, 0x56]]
int8: [!u8 [0x56]]
int8-array: [!u8 [0x0, 0x12, 0x34, 0x56]]
int16: [!u16 [0x3210]]
diff --git a/tests/type-preservation.dts b/tests/type-preservation.dts
index 3e380ba..24c9eeb 100644
--- a/tests/type-preservation.dts
+++ b/tests/type-preservation.dts
@@ -8,8 +8,10 @@
prop_label: compatible = value_label: "subnode1";
reg = <0x01>;
int-array = <0x00 0x01>, int_value_label: <0x02 0x03>;
- int8 = [56];
- int8-array = [00 12 34 56] label:;
+ byte = [56];
+ bytestring = [00 12 34 56] label:;
+ int8 = /bits/ 8 <0x56>;
+ int8-array = /bits/ 8 <0x00 0x12 0x34 0x56> int8_label:;
int16 = /bits/ 16 <0x3210>;
int16-array = /bits/ 16 <0x1234 0x5678 0x90ab 0xcdef>;
int16-matrix = /bits/ 16 <0x1234 0x5678>, <0x90ab 0xcdef>;
diff --git a/treesource.c b/treesource.c
index 061ba8c..322d9e7 100644
--- a/treesource.c
+++ b/treesource.c
@@ -99,7 +99,8 @@ static void write_propval_string(FILE *f, const char *s, size_t len)
fprintf(f, "\"");
}
-static void write_propval_int(FILE *f, const char *p, size_t len, size_t width)
+static void write_propval_int(FILE *f, struct marker *markers,
+ const char *p, size_t len, size_t width)
{
const char *end = p + len;
assert(len % width == 0);
@@ -107,7 +108,10 @@ static void write_propval_int(FILE *f, const char *p, size_t len, size_t width)
for (; p < end; p += width) {
switch (width) {
case 1:
- fprintf(f, "%02"PRIx8, *(const uint8_t*)p);
+ if (markers->type == TYPE_BYTESTRING)
+ fprintf(f, "%02"PRIx8, *(const uint8_t*)p);
+ else
+ fprintf(f, "0x%02"PRIx8, *(const uint8_t*)p);
break;
case 2:
fprintf(f, "0x%02"PRIx16, dtb_ld16(p));
@@ -146,18 +150,20 @@ size_t type_marker_length(struct marker *m)
}
static const char *delim_start[] = {
- [TYPE_UINT8] = "[",
+ [TYPE_UINT8] = "/bits/ 8 <",
[TYPE_UINT16] = "/bits/ 16 <",
[TYPE_UINT32] = "<",
[TYPE_UINT64] = "/bits/ 64 <",
[TYPE_STRING] = "",
+ [TYPE_BYTESTRING] = "[",
};
static const char *delim_end[] = {
- [TYPE_UINT8] = "]",
+ [TYPE_UINT8] = ">",
[TYPE_UINT16] = ">",
[TYPE_UINT32] = ">",
[TYPE_UINT64] = ">",
[TYPE_STRING] = "",
+ [TYPE_BYTESTRING] = "]",
};
static enum markertype guess_value_type(struct property *prop)
@@ -190,7 +196,7 @@ static enum markertype guess_value_type(struct property *prop)
return TYPE_UINT32;
}
- return TYPE_UINT8;
+ return TYPE_BYTESTRING;
}
static void write_propval(FILE *f, struct property *prop)
@@ -245,19 +251,19 @@ static void write_propval(FILE *f, struct property *prop)
switch(emit_type) {
case TYPE_UINT16:
- write_propval_int(f, p, chunk_len, 2);
+ write_propval_int(f, m, p, chunk_len, 2);
break;
case TYPE_UINT32:
- write_propval_int(f, p, chunk_len, 4);
+ write_propval_int(f, m, p, chunk_len, 4);
break;
case TYPE_UINT64:
- write_propval_int(f, p, chunk_len, 8);
+ write_propval_int(f, m, p, chunk_len, 8);
break;
case TYPE_STRING:
write_propval_string(f, p, chunk_len);
break;
default:
- write_propval_int(f, p, chunk_len, 1);
+ write_propval_int(f, m, p, chunk_len, 1);
}
if (chunk_len == data_len) {
--
2.17.1
next prev parent reply other threads:[~2020-07-14 15:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-14 15:45 [PATCH v2 0/6] dtc: Add support for signed operations Andrei Ziureaev
[not found] ` <20200714154542.18064-1-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
2020-07-14 15:45 ` [PATCH v2 1/6] dtc: Avoid UB when shifting Andrei Ziureaev
[not found] ` <20200714154542.18064-2-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
2020-07-15 10:41 ` David Gibson
2020-07-14 15:45 ` Andrei Ziureaev [this message]
2020-07-14 15:45 ` [PATCH v2 3/6] dtc: Turn 'uint64_t integer' into a struct Andrei Ziureaev
2020-07-14 15:45 ` [PATCH v2 4/6] dtc: Add support for signed operations Andrei Ziureaev
[not found] ` <20200714154542.18064-5-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
2020-08-03 10:21 ` David Gibson
2020-07-14 15:45 ` [PATCH v2 5/6] dtc: Preserve negative integers in yaml and dts Andrei Ziureaev
2020-07-14 15:45 ` [PATCH v2 6/6] dtc: Add sign preservation and operation tests Andrei Ziureaev
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=20200714154542.18064-3-andrei.ziureaev@arm.com \
--to=andrei.ziureaev-5wv7dgnigg8@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).