mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-17 02:07:42 -04:00
pylibfdt: Add functions to update properties
Allow updating and creating properties, including special methods for integers. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
5a598671fd
commit
9aafa33d99
3 changed files with 110 additions and 0 deletions
|
@ -49,6 +49,7 @@
|
|||
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
import struct
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
|
@ -57,6 +58,18 @@ sys.path.insert(0, '../pylibfdt')
|
|||
import libfdt
|
||||
from libfdt import Fdt, FdtException, QUIET_NOTFOUND, QUIET_ALL
|
||||
|
||||
small_size = 160
|
||||
full_size = 1024
|
||||
|
||||
TEST_VALUE_1 = 0xdeadbeef
|
||||
|
||||
TEST_VALUE64_1H = 0xdeadbeef
|
||||
TEST_VALUE64_1L = 0x01abcdef
|
||||
TEST_VALUE64_1 = (TEST_VALUE64_1H << 32) | TEST_VALUE64_1L
|
||||
|
||||
TEST_STRING_1 = 'hello world'
|
||||
|
||||
|
||||
def get_err(err_code):
|
||||
"""Convert an error code into an error message
|
||||
|
||||
|
@ -380,6 +393,41 @@ class PyLibfdtTests(unittest.TestCase):
|
|||
fdt.pack()
|
||||
self.assertTrue(fdt.totalsize() < 128)
|
||||
|
||||
def testSetProp(self):
|
||||
"""Test that we can update and create properties"""
|
||||
node = self.fdt.path_offset('/subnode@1')
|
||||
self.fdt.setprop(node, 'compatible', TEST_STRING_1)
|
||||
self.assertEquals(TEST_STRING_1, self.fdt.getprop(node, 'compatible'))
|
||||
|
||||
# Check that this property is missing, and that we don't have space to
|
||||
# add it
|
||||
self.assertEquals(-libfdt.NOTFOUND,
|
||||
self.fdt.getprop(node, 'missing', QUIET_NOTFOUND))
|
||||
self.assertEquals(-libfdt.NOSPACE,
|
||||
self.fdt.setprop(node, 'missing', TEST_STRING_1,
|
||||
quiet=(libfdt.NOSPACE,)))
|
||||
|
||||
# Expand the device tree so we now have room
|
||||
self.fdt.resize(self.fdt.totalsize() + 50)
|
||||
self.fdt.setprop(node, 'missing', TEST_STRING_1)
|
||||
self.assertEquals(TEST_STRING_1, self.fdt.getprop(node, 'missing'))
|
||||
|
||||
def testSetPropU32(self):
|
||||
"""Test that we can update and create integer properties"""
|
||||
node = 0
|
||||
prop = 'prop-int'
|
||||
self.fdt.setprop_u32(node, prop, TEST_VALUE_1)
|
||||
self.assertEquals(struct.pack('>I', TEST_VALUE_1),
|
||||
self.fdt.getprop(node, prop))
|
||||
|
||||
def testSetPropU64(self):
|
||||
"""Test that we can update and create integer properties"""
|
||||
node = 0
|
||||
prop = 'prop-int64'
|
||||
self.fdt.setprop_u64(node, prop, TEST_VALUE64_1)
|
||||
self.assertEquals(struct.pack('>Q', TEST_VALUE64_1),
|
||||
self.fdt.getprop(node, prop))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue