Commit c640ed0ce6b029f8cda62f2674a671a9c198410a

Authored by Simon Glass
1 parent a1e0085519

libfdt: Add get_property() and del_node()

Add support for these functions in the Python binding. This patch stands
in for a pending upstream change.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 1 changed file with 32 additions and 0 deletions Side-by-side Diff

scripts/dtc/pylibfdt/libfdt.i_shipped
... ... @@ -398,6 +398,27 @@
398 398 return pdata
399 399 return Property(pdata[0], pdata[1])
400 400  
  401 + def get_property(self, nodeoffset, prop_name, quiet=()):
  402 + """Obtains a property by name
  403 +
  404 + Args:
  405 + nodeoffset: Offset to the node to check
  406 + prop_name: Name of property to get
  407 + quiet: Errors to ignore (empty to raise on all errors)
  408 +
  409 + Returns:
  410 + Property object, or None if not found
  411 +
  412 + Raises:
  413 + FdtException on error (e.g. invalid prop_offset or device
  414 + tree format)
  415 + """
  416 + pdata = check_err_null(
  417 + fdt_get_property(self._fdt, nodeoffset, prop_name), quiet)
  418 + if isinstance(pdata, (int)):
  419 + return pdata
  420 + return Property(pdata[0], pdata[1])
  421 +
401 422 @staticmethod
402 423 def create_empty_tree(size, quiet=()):
403 424 """Create an empty device tree ready for use
... ... @@ -631,6 +652,17 @@
631 652 FdtException if no node found or other error occurs
632 653 """
633 654 return check_err(fdt_node_offset_by_phandle(self._fdt, phandle), quiet)
  655 +
  656 + def del_node(self, nodeoffset):
  657 + """Delete a node
  658 +
  659 + Args:
  660 + nodeoffset: Node offset containing property to delete
  661 +
  662 + Raises:
  663 + FdtError if the node does not exist, or another error occurs
  664 + """
  665 + return check_err(fdt_del_node(self._fdt, nodeoffset))
634 666  
635 667  
636 668 class Property(bytearray):