[PATCH 04/17] pylibfdt: Add Property.as_stringlist()
Alexey Charkov <[email protected]>
| Newsgroups | org.u-boot-project.lists.u-boot |
|---|---|
| Message-ID | <[email protected]> |
From: Luca Weiss <[email protected]> Add a new method for decoding a string list property, useful for e.g. the "reg-names" property. This is a backport of dtc commit 83102717d7c4 ("pylibfdt: add Property.as_stringlist()"), without the dtc-side test, which has no counterpart in U-Boot's test suite. Signed-off-by: Luca Weiss <[email protected]> Signed-off-by: David Gibson <[email protected]> [adapted to U-Boot] Signed-off-by: Alexey Charkov <[email protected]> --- scripts/dtc/pylibfdt/libfdt.i_shipped | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/dtc/pylibfdt/libfdt.i_shipped b/scripts/dtc/pylibfdt/libfdt.i_shipped index 5025893b1e95..c8ac578b367b 100644 --- a/scripts/dtc/pylibfdt/libfdt.i_shipped +++ b/scripts/dtc/pylibfdt/libfdt.i_shipped @@ -728,6 +728,13 @@ class Property(bytearray): raise ValueError('Property contains embedded nul characters') return self[:-1].decode('utf-8') + def as_stringlist(self): + """Unicode is supported by decoding from UTF-8""" + if self[-1] != 0: + raise ValueError('Property lacks nul termination') + parts = self[:-1].split(b'\x00') + return list(map(lambda x: x.decode('utf-8'), parts)) + class FdtSw(FdtRo): """Software interface to create a device tree from scratch -- 2.54.0