提交 903fe17a 编写于 作者: S Simon Glass

pylibfdt: Sync up with upstream

Sync up the libfdt Python bindings with upstream, commit:

430419c (tests: fix some python warnings)
Signed-off-by: NSimon Glass <sjg@chromium.org>
上级 b4cf5f1d
...@@ -92,7 +92,7 @@ def check_err(val, quiet=()): ...@@ -92,7 +92,7 @@ def check_err(val, quiet=()):
Raises Raises
FdtException if val < 0 FdtException if val < 0
""" """
if val < 0: if isinstance(val, int) and val < 0:
if -val not in quiet: if -val not in quiet:
raise FdtException(val) raise FdtException(val)
return val return val
...@@ -417,7 +417,7 @@ class FdtRo(object): ...@@ -417,7 +417,7 @@ class FdtRo(object):
quiet) quiet)
if isinstance(pdata, (int)): if isinstance(pdata, (int)):
return pdata return pdata
return Property(prop_name, bytearray(pdata[0])) return Property(prop_name, bytes(pdata[0]))
def get_phandle(self, nodeoffset): def get_phandle(self, nodeoffset):
"""Get the phandle of a node """Get the phandle of a node
...@@ -431,6 +431,18 @@ class FdtRo(object): ...@@ -431,6 +431,18 @@ class FdtRo(object):
""" """
return fdt_get_phandle(self._fdt, nodeoffset) return fdt_get_phandle(self._fdt, nodeoffset)
def get_alias(self, name):
"""Get the full path referenced by a given alias
Args:
name: name of the alias to lookup
Returns:
Full path to the node for the alias named 'name', if it exists
None, if the given alias or the /aliases node does not exist
"""
return fdt_get_alias(self._fdt, name)
def parent_offset(self, nodeoffset, quiet=()): def parent_offset(self, nodeoffset, quiet=()):
"""Get the offset of a node's parent """Get the offset of a node's parent
...@@ -727,8 +739,10 @@ class FdtSw(FdtRo): ...@@ -727,8 +739,10 @@ class FdtSw(FdtRo):
# First create the device tree with a node and property: # First create the device tree with a node and property:
sw = FdtSw() sw = FdtSw()
with sw.add_node('node'): sw.finish_reservemap()
sw.property_u32('reg', 2) with sw.add_node(''):
with sw.add_node('node'):
sw.property_u32('reg', 2)
fdt = sw.as_fdt() fdt = sw.as_fdt()
# Now we can use it as a real device tree # Now we can use it as a real device tree
...@@ -1029,17 +1043,24 @@ typedef uint32_t fdt32_t; ...@@ -1029,17 +1043,24 @@ typedef uint32_t fdt32_t;
if (!$1) if (!$1)
$result = Py_None; $result = Py_None;
else else
$result = Py_BuildValue("s#", $1, *arg4); %#if PY_VERSION_HEX >= 0x03000000
$result = Py_BuildValue("y#", $1, *arg4);
%#else
$result = Py_BuildValue("s#", $1, *arg4);
%#endif
} }
/* typemap used for fdt_setprop() */ /* typemap used for fdt_setprop() */
%typemap(in) (const void *val) { %typemap(in) (const void *val) {
$1 = PyString_AsString($input); /* char *str */ %#if PY_VERSION_HEX >= 0x03000000
} if (!PyBytes_Check($input)) {
SWIG_exception_fail(SWIG_TypeError, "bytes expected in method '" "$symname"
/* typemap used for fdt_add_reservemap_entry() */ "', argument " "$argnum"" of type '" "$type""'");
%typemap(in) uint64_t { }
$1 = PyLong_AsUnsignedLong($input); $1 = PyBytes_AsString($input);
%#else
$1 = PyString_AsString($input); /* char *str */
%#endif
} }
/* typemaps used for fdt_next_node() */ /* typemaps used for fdt_next_node() */
...@@ -1061,7 +1082,7 @@ typedef uint32_t fdt32_t; ...@@ -1061,7 +1082,7 @@ typedef uint32_t fdt32_t;
} }
%typemap(argout) uint64_t * { %typemap(argout) uint64_t * {
PyObject *val = PyLong_FromUnsignedLong(*arg$argnum); PyObject *val = PyLong_FromUnsignedLongLong(*arg$argnum);
if (!result) { if (!result) {
if (PyTuple_GET_SIZE(resultobj) == 0) if (PyTuple_GET_SIZE(resultobj) == 0)
resultobj = val; resultobj = val;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册