mirror of
https://xff.cz/git/u-boot/
synced 2025-11-02 03:17:29 +01:00
dtoc: Create a base class for Fdt
At present we have two separate implementations of the Fdt library, one which uses fdtget/fdtput and one which uses libfdt (via swig). Before adding more functionality it makes sense to create a base class for these. This will allow common functions to be shared, and make the Fdt API a little clearer. Create a new fdt.py file with the base class, and adjust fdt_normal.py and fdt_fallback.py to use it. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
68
tools/dtoc/fdt.py
Normal file
68
tools/dtoc/fdt.py
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2016 Google, Inc
|
||||
# Written by Simon Glass <sjg@chromium.org>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0+
|
||||
#
|
||||
|
||||
import struct
|
||||
import sys
|
||||
|
||||
import fdt_util
|
||||
|
||||
# This deals with a device tree, presenting it as an assortment of Node and
|
||||
# Prop objects, representing nodes and properties, respectively. This file
|
||||
# contains the base classes and defines the high-level API. Most of the
|
||||
# implementation is in the FdtFallback and FdtNormal subclasses. See
|
||||
# fdt_select.py for how to create an Fdt object.
|
||||
|
||||
def CheckErr(errnum, msg):
|
||||
if errnum:
|
||||
raise ValueError('Error %d: %s: %s' %
|
||||
(errnum, libfdt.fdt_strerror(errnum), msg))
|
||||
|
||||
class PropBase:
|
||||
"""A device tree property
|
||||
|
||||
Properties:
|
||||
name: Property name (as per the device tree)
|
||||
value: Property value as a string of bytes, or a list of strings of
|
||||
bytes
|
||||
type: Value type
|
||||
"""
|
||||
def __init__(self, node, offset, name):
|
||||
self._node = node
|
||||
self._offset = offset
|
||||
self.name = name
|
||||
self.value = None
|
||||
|
||||
class NodeBase:
|
||||
"""A device tree node
|
||||
|
||||
Properties:
|
||||
offset: Integer offset in the device tree
|
||||
name: Device tree node tname
|
||||
path: Full path to node, along with the node name itself
|
||||
_fdt: Device tree object
|
||||
subnodes: A list of subnodes for this node, each a Node object
|
||||
props: A dict of properties for this node, each a Prop object.
|
||||
Keyed by property name
|
||||
"""
|
||||
def __init__(self, fdt, offset, name, path):
|
||||
self._fdt = fdt
|
||||
self._offset = offset
|
||||
self.name = name
|
||||
self.path = path
|
||||
self.subnodes = []
|
||||
self.props = {}
|
||||
|
||||
class Fdt:
|
||||
"""Provides simple access to a flat device tree blob.
|
||||
|
||||
Properties:
|
||||
fname: Filename of fdt
|
||||
_root: Root of device tree (a Node object)
|
||||
"""
|
||||
def __init__(self, fname):
|
||||
self._fname = fname
|
||||
Reference in New Issue
Block a user