mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-20 22:21:41 +00:00
dtoc: Add functions to add integer properties
Add a few simple functions to add a placeholder integer property, and set its value. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
fe57c784ad
commit
116adecb5e
2 changed files with 47 additions and 0 deletions
|
@ -270,6 +270,33 @@ class Node:
|
||||||
del self.props[prop_name]
|
del self.props[prop_name]
|
||||||
self._fdt.Invalidate()
|
self._fdt.Invalidate()
|
||||||
|
|
||||||
|
def AddZeroProp(self, prop_name):
|
||||||
|
"""Add a new property to the device tree with an integer value of 0.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
prop_name: Name of property
|
||||||
|
"""
|
||||||
|
fdt_obj = self._fdt._fdt_obj
|
||||||
|
if fdt_obj.setprop_u32(self.Offset(), prop_name, 0,
|
||||||
|
(libfdt.NOSPACE,)) == -libfdt.NOSPACE:
|
||||||
|
fdt_obj.open_into(fdt_obj.totalsize() + 1024)
|
||||||
|
fdt_obj.setprop_u32(self.Offset(), prop_name, 0)
|
||||||
|
self.props[prop_name] = Prop(self, -1, prop_name, '\0' * 4)
|
||||||
|
self._fdt.Invalidate()
|
||||||
|
|
||||||
|
def SetInt(self, prop_name, val):
|
||||||
|
"""Update an integer property int the device tree.
|
||||||
|
|
||||||
|
This is not allowed to change the size of the FDT.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
prop_name: Name of property
|
||||||
|
val: Value to set
|
||||||
|
"""
|
||||||
|
fdt_obj = self._fdt._fdt_obj
|
||||||
|
fdt_obj.setprop_u32(self.Offset(), prop_name, val)
|
||||||
|
|
||||||
|
|
||||||
class Fdt:
|
class Fdt:
|
||||||
"""Provides simple access to a flat device tree blob using libfdts.
|
"""Provides simple access to a flat device tree blob using libfdts.
|
||||||
|
|
||||||
|
|
|
@ -319,6 +319,26 @@ class TestProp(unittest.TestCase):
|
||||||
self.assertTrue(isinstance(prop.value, list))
|
self.assertTrue(isinstance(prop.value, list))
|
||||||
self.assertEqual(3, len(prop.value))
|
self.assertEqual(3, len(prop.value))
|
||||||
|
|
||||||
|
def testAdd(self):
|
||||||
|
"""Test adding properties"""
|
||||||
|
self.fdt.pack()
|
||||||
|
# This function should automatically expand the device tree
|
||||||
|
self.node.AddZeroProp('one')
|
||||||
|
self.node.AddZeroProp('two')
|
||||||
|
self.node.AddZeroProp('three')
|
||||||
|
|
||||||
|
# Updating existing properties should be OK, since the device-tree size
|
||||||
|
# does not change
|
||||||
|
self.fdt.pack()
|
||||||
|
self.node.SetInt('one', 1)
|
||||||
|
self.node.SetInt('two', 2)
|
||||||
|
self.node.SetInt('three', 3)
|
||||||
|
|
||||||
|
# This should fail since it would need to increase the device-tree size
|
||||||
|
with self.assertRaises(libfdt.FdtException) as e:
|
||||||
|
self.node.SetInt('four', 4)
|
||||||
|
self.assertIn('FDT_ERR_NOSPACE', str(e.exception))
|
||||||
|
|
||||||
|
|
||||||
class TestFdtUtil(unittest.TestCase):
|
class TestFdtUtil(unittest.TestCase):
|
||||||
"""Tests for the fdt_util module
|
"""Tests for the fdt_util module
|
||||||
|
|
Loading…
Add table
Reference in a new issue