mirror of
https://github.com/dgibson/dtc.git
synced 2026-04-11 16:37:42 -04:00
pylibfdt: add Property.as_stringlist()
Add a new method for decoding a string list property, useful for e.g. the "reg-names" property. Also add a test for the new method. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Message-Id: <20211225132558.167123-2-luca@z3ntu.xyz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
d152126bb0
commit
83102717d7
2 changed files with 15 additions and 0 deletions
|
|
@ -724,6 +724,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue