diff --git a/scripts/dts/python-devicetree/src/devicetree/dtlib.py b/scripts/dts/python-devicetree/src/devicetree/dtlib.py index 0e07cf9d52c..e987ad5d9e9 100644 --- a/scripts/dts/python-devicetree/src/devicetree/dtlib.py +++ b/scripts/dts/python-devicetree/src/devicetree/dtlib.py @@ -641,11 +641,16 @@ class Property: elif marker_type is _MarkerType.PHANDLE: s += " &" + ref pos += 4 + if pos != len(self.value) and len(s) - array_start > 80: # noqa: F821 + s += array_newline # noqa: F821 + array_start = len(s) # Subtle: There might be more data between the phandle and # the next marker, so we can't 'continue' here else: # marker_type is _MarkerType.UINT* elm_size = _TYPE_TO_N_BYTES[marker_type] s += _N_BYTES_TO_START_STR[elm_size] + array_start = len(s) + array_newline = "\n" + " " * array_start while pos != end: num = int.from_bytes(self.value[pos:pos + elm_size], @@ -656,6 +661,9 @@ class Property: s += f" {hex(num)}" pos += elm_size + if pos != len(self.value) and len(s) - array_start > 80: + s += array_newline + array_start = len(s) if (pos != 0 and (not next_marker diff --git a/scripts/dts/python-devicetree/tests/test_dtlib.py b/scripts/dts/python-devicetree/tests/test_dtlib.py index 26f7b458e7e..6d3e02b7cf7 100644 --- a/scripts/dts/python-devicetree/tests/test_dtlib.py +++ b/scripts/dts/python-devicetree/tests/test_dtlib.py @@ -163,6 +163,8 @@ def test_cell_parsing(): j = /bits/ 32 < 0x10 0x20 (-1) >; k = /bits/ 64 < 0x10 0x20 (-1) >; l = < 'a' 'b' 'c' >; + m = [ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b ]; + n = < 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 >; }; """, """ @@ -181,6 +183,10 @@ def test_cell_parsing(): j = < 0x10 0x20 0xffffffff >; k = /bits/ 64 < 0x10 0x20 0xffffffffffffffff >; l = < 0x61 0x62 0x63 >; + m = [ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A + 1B ]; + n = < 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10 0x11 0x12 0x13 + 0x14 >; }; """)