1*4882a593Smuzhiyun/* 2*4882a593Smuzhiyun * pylibfdt - Flat Device Tree manipulation in Python 3*4882a593Smuzhiyun * Copyright (C) 2017 Google, Inc. 4*4882a593Smuzhiyun * Written by Simon Glass <sjg@chromium.org> 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause 7*4882a593Smuzhiyun */ 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun%module libfdt 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun%include <stdint.i> 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun%{ 14*4882a593Smuzhiyun#define SWIG_FILE_WITH_INIT 15*4882a593Smuzhiyun#include "libfdt.h" 16*4882a593Smuzhiyun%} 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun%pythoncode %{ 19*4882a593Smuzhiyun 20*4882a593Smuzhiyunimport struct 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun# Error codes, corresponding to FDT_ERR_... in libfdt.h 23*4882a593Smuzhiyun(NOTFOUND, 24*4882a593Smuzhiyun EXISTS, 25*4882a593Smuzhiyun NOSPACE, 26*4882a593Smuzhiyun BADOFFSET, 27*4882a593Smuzhiyun BADPATH, 28*4882a593Smuzhiyun BADPHANDLE, 29*4882a593Smuzhiyun BADSTATE, 30*4882a593Smuzhiyun TRUNCATED, 31*4882a593Smuzhiyun BADMAGIC, 32*4882a593Smuzhiyun BADVERSION, 33*4882a593Smuzhiyun BADSTRUCTURE, 34*4882a593Smuzhiyun BADLAYOUT, 35*4882a593Smuzhiyun INTERNAL, 36*4882a593Smuzhiyun BADNCELLS, 37*4882a593Smuzhiyun BADVALUE, 38*4882a593Smuzhiyun BADOVERLAY, 39*4882a593Smuzhiyun NOPHANDLES) = QUIET_ALL = range(1, 18) 40*4882a593Smuzhiyun# QUIET_ALL can be passed as the 'quiet' parameter to avoid exceptions 41*4882a593Smuzhiyun# altogether. All # functions passed this value will return an error instead 42*4882a593Smuzhiyun# of raising an exception. 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun# Pass this as the 'quiet' parameter to return -ENOTFOUND on NOTFOUND errors, 45*4882a593Smuzhiyun# instead of raising an exception. 46*4882a593SmuzhiyunQUIET_NOTFOUND = (NOTFOUND,) 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun 49*4882a593Smuzhiyunclass FdtException(Exception): 50*4882a593Smuzhiyun """An exception caused by an error such as one of the codes above""" 51*4882a593Smuzhiyun def __init__(self, err): 52*4882a593Smuzhiyun self.err = err 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun def __str__(self): 55*4882a593Smuzhiyun return 'pylibfdt error %d: %s' % (self.err, fdt_strerror(self.err)) 56*4882a593Smuzhiyun 57*4882a593Smuzhiyundef strerror(fdt_err): 58*4882a593Smuzhiyun """Get the string for an error number 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun Args: 61*4882a593Smuzhiyun fdt_err: Error number (-ve) 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun Returns: 64*4882a593Smuzhiyun String containing the associated error 65*4882a593Smuzhiyun """ 66*4882a593Smuzhiyun return fdt_strerror(fdt_err) 67*4882a593Smuzhiyun 68*4882a593Smuzhiyundef check_err(val, quiet=()): 69*4882a593Smuzhiyun """Raise an error if the return value is -ve 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun This is used to check for errors returned by libfdt C functions. 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun Args: 74*4882a593Smuzhiyun val: Return value from a libfdt function 75*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun Returns: 78*4882a593Smuzhiyun val if val >= 0 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun Raises 81*4882a593Smuzhiyun FdtException if val < 0 82*4882a593Smuzhiyun """ 83*4882a593Smuzhiyun if val < 0: 84*4882a593Smuzhiyun if -val not in quiet: 85*4882a593Smuzhiyun raise FdtException(val) 86*4882a593Smuzhiyun return val 87*4882a593Smuzhiyun 88*4882a593Smuzhiyundef check_err_null(val, quiet=()): 89*4882a593Smuzhiyun """Raise an error if the return value is NULL 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun This is used to check for a NULL return value from certain libfdt C 92*4882a593Smuzhiyun functions 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun Args: 95*4882a593Smuzhiyun val: Return value from a libfdt function 96*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun Returns: 99*4882a593Smuzhiyun val if val is a list, None if not 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun Raises 102*4882a593Smuzhiyun FdtException if val indicates an error was reported and the error 103*4882a593Smuzhiyun is not in @quiet. 104*4882a593Smuzhiyun """ 105*4882a593Smuzhiyun # Normally a list is returned which contains the data and its length. 106*4882a593Smuzhiyun # If we get just an integer error code, it means the function failed. 107*4882a593Smuzhiyun if not isinstance(val, list): 108*4882a593Smuzhiyun if -val not in quiet: 109*4882a593Smuzhiyun raise FdtException(val) 110*4882a593Smuzhiyun return val 111*4882a593Smuzhiyun 112*4882a593Smuzhiyunclass Fdt: 113*4882a593Smuzhiyun """Device tree class, supporting all operations 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun The Fdt object is created is created from a device tree binary file, 116*4882a593Smuzhiyun e.g. with something like: 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun fdt = Fdt(open("filename.dtb").read()) 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun Operations can then be performed using the methods in this class. Each 121*4882a593Smuzhiyun method xxx(args...) corresponds to a libfdt function fdt_xxx(fdt, args...). 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun All methods raise an FdtException if an error occurs. To avoid this 124*4882a593Smuzhiyun behaviour a 'quiet' parameter is provided for some functions. This 125*4882a593Smuzhiyun defaults to empty, but you can pass a list of errors that you expect. 126*4882a593Smuzhiyun If one of these errors occurs, the function will return an error number 127*4882a593Smuzhiyun (e.g. -NOTFOUND). 128*4882a593Smuzhiyun """ 129*4882a593Smuzhiyun def __init__(self, data): 130*4882a593Smuzhiyun self._fdt = bytearray(data) 131*4882a593Smuzhiyun check_err(fdt_check_header(self._fdt)); 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun def subnode_offset(self, parentoffset, name, quiet=()): 134*4882a593Smuzhiyun """Get the offset of a named subnode 135*4882a593Smuzhiyun 136*4882a593Smuzhiyun Args: 137*4882a593Smuzhiyun parentoffset: Offset of the parent node to check 138*4882a593Smuzhiyun name: Name of the required subnode, e.g. 'subnode@1' 139*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun Returns: 142*4882a593Smuzhiyun The node offset of the found node, if any 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun Raises 145*4882a593Smuzhiyun FdtException if there is no node with that name, or other error 146*4882a593Smuzhiyun """ 147*4882a593Smuzhiyun return check_err(fdt_subnode_offset(self._fdt, parentoffset, name), 148*4882a593Smuzhiyun quiet) 149*4882a593Smuzhiyun 150*4882a593Smuzhiyun def path_offset(self, path, quiet=()): 151*4882a593Smuzhiyun """Get the offset for a given path 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun Args: 154*4882a593Smuzhiyun path: Path to the required node, e.g. '/node@3/subnode@1' 155*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun Returns: 158*4882a593Smuzhiyun Node offset 159*4882a593Smuzhiyun 160*4882a593Smuzhiyun Raises 161*4882a593Smuzhiyun FdtException if the path is not valid or not found 162*4882a593Smuzhiyun """ 163*4882a593Smuzhiyun return check_err(fdt_path_offset(self._fdt, path), quiet) 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun def first_property_offset(self, nodeoffset, quiet=()): 166*4882a593Smuzhiyun """Get the offset of the first property in a node offset 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun Args: 169*4882a593Smuzhiyun nodeoffset: Offset to the node to check 170*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 171*4882a593Smuzhiyun 172*4882a593Smuzhiyun Returns: 173*4882a593Smuzhiyun Offset of the first property 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun Raises 176*4882a593Smuzhiyun FdtException if the associated node has no properties, or some 177*4882a593Smuzhiyun other error occurred 178*4882a593Smuzhiyun """ 179*4882a593Smuzhiyun return check_err(fdt_first_property_offset(self._fdt, nodeoffset), 180*4882a593Smuzhiyun quiet) 181*4882a593Smuzhiyun 182*4882a593Smuzhiyun def next_property_offset(self, prop_offset, quiet=()): 183*4882a593Smuzhiyun """Get the next property in a node 184*4882a593Smuzhiyun 185*4882a593Smuzhiyun Args: 186*4882a593Smuzhiyun prop_offset: Offset of the previous property 187*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 188*4882a593Smuzhiyun 189*4882a593Smuzhiyun Returns: 190*4882a593Smuzhiyun Offset of the next property 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun Raises: 193*4882a593Smuzhiyun FdtException if the associated node has no more properties, or 194*4882a593Smuzhiyun some other error occurred 195*4882a593Smuzhiyun """ 196*4882a593Smuzhiyun return check_err(fdt_next_property_offset(self._fdt, prop_offset), 197*4882a593Smuzhiyun quiet) 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun def get_name(self, nodeoffset): 200*4882a593Smuzhiyun """Get the name of a node 201*4882a593Smuzhiyun 202*4882a593Smuzhiyun Args: 203*4882a593Smuzhiyun nodeoffset: Offset of node to check 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun Returns: 206*4882a593Smuzhiyun Node name 207*4882a593Smuzhiyun 208*4882a593Smuzhiyun Raises: 209*4882a593Smuzhiyun FdtException on error (e.g. nodeoffset is invalid) 210*4882a593Smuzhiyun """ 211*4882a593Smuzhiyun return check_err_null(fdt_get_name(self._fdt, nodeoffset))[0] 212*4882a593Smuzhiyun 213*4882a593Smuzhiyun def get_property_by_offset(self, prop_offset, quiet=()): 214*4882a593Smuzhiyun """Obtains a property that can be examined 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun Args: 217*4882a593Smuzhiyun prop_offset: Offset of property (e.g. from first_property_offset()) 218*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 219*4882a593Smuzhiyun 220*4882a593Smuzhiyun Returns: 221*4882a593Smuzhiyun Property object, or None if not found 222*4882a593Smuzhiyun 223*4882a593Smuzhiyun Raises: 224*4882a593Smuzhiyun FdtException on error (e.g. invalid prop_offset or device 225*4882a593Smuzhiyun tree format) 226*4882a593Smuzhiyun """ 227*4882a593Smuzhiyun pdata = check_err_null( 228*4882a593Smuzhiyun fdt_get_property_by_offset(self._fdt, prop_offset), quiet) 229*4882a593Smuzhiyun if isinstance(pdata, (int)): 230*4882a593Smuzhiyun return pdata 231*4882a593Smuzhiyun return Property(pdata[0], pdata[1]) 232*4882a593Smuzhiyun 233*4882a593Smuzhiyun def first_subnode(self, nodeoffset, quiet=()): 234*4882a593Smuzhiyun """Find the first subnode of a parent node 235*4882a593Smuzhiyun 236*4882a593Smuzhiyun Args: 237*4882a593Smuzhiyun nodeoffset: Node offset of parent node 238*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 239*4882a593Smuzhiyun 240*4882a593Smuzhiyun Returns: 241*4882a593Smuzhiyun The offset of the first subnode, if any 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun Raises: 244*4882a593Smuzhiyun FdtException if no subnode found or other error occurs 245*4882a593Smuzhiyun """ 246*4882a593Smuzhiyun return check_err(fdt_first_subnode(self._fdt, nodeoffset), quiet) 247*4882a593Smuzhiyun 248*4882a593Smuzhiyun def next_subnode(self, nodeoffset, quiet=()): 249*4882a593Smuzhiyun """Find the next subnode 250*4882a593Smuzhiyun 251*4882a593Smuzhiyun Args: 252*4882a593Smuzhiyun nodeoffset: Node offset of previous subnode 253*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 254*4882a593Smuzhiyun 255*4882a593Smuzhiyun Returns: 256*4882a593Smuzhiyun The offset of the next subnode, if any 257*4882a593Smuzhiyun 258*4882a593Smuzhiyun Raises: 259*4882a593Smuzhiyun FdtException if no more subnode found or other error occurs 260*4882a593Smuzhiyun """ 261*4882a593Smuzhiyun return check_err(fdt_next_subnode(self._fdt, nodeoffset), quiet) 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun def totalsize(self): 264*4882a593Smuzhiyun """Return the total size of the device tree 265*4882a593Smuzhiyun 266*4882a593Smuzhiyun Returns: 267*4882a593Smuzhiyun Total tree size in bytes 268*4882a593Smuzhiyun """ 269*4882a593Smuzhiyun return check_err(fdt_totalsize(self._fdt)) 270*4882a593Smuzhiyun 271*4882a593Smuzhiyun def off_dt_struct(self): 272*4882a593Smuzhiyun """Return the start of the device tree struct area 273*4882a593Smuzhiyun 274*4882a593Smuzhiyun Returns: 275*4882a593Smuzhiyun Start offset of struct area 276*4882a593Smuzhiyun """ 277*4882a593Smuzhiyun return check_err(fdt_off_dt_struct(self._fdt)) 278*4882a593Smuzhiyun 279*4882a593Smuzhiyun def pack(self, quiet=()): 280*4882a593Smuzhiyun """Pack the device tree to remove unused space 281*4882a593Smuzhiyun 282*4882a593Smuzhiyun This adjusts the tree in place. 283*4882a593Smuzhiyun 284*4882a593Smuzhiyun Args: 285*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 286*4882a593Smuzhiyun 287*4882a593Smuzhiyun Raises: 288*4882a593Smuzhiyun FdtException if any error occurs 289*4882a593Smuzhiyun """ 290*4882a593Smuzhiyun return check_err(fdt_pack(self._fdt), quiet) 291*4882a593Smuzhiyun 292*4882a593Smuzhiyun def delprop(self, nodeoffset, prop_name): 293*4882a593Smuzhiyun """Delete a property from a node 294*4882a593Smuzhiyun 295*4882a593Smuzhiyun Args: 296*4882a593Smuzhiyun nodeoffset: Node offset containing property to delete 297*4882a593Smuzhiyun prop_name: Name of property to delete 298*4882a593Smuzhiyun 299*4882a593Smuzhiyun Raises: 300*4882a593Smuzhiyun FdtError if the property does not exist, or another error occurs 301*4882a593Smuzhiyun """ 302*4882a593Smuzhiyun return check_err(fdt_delprop(self._fdt, nodeoffset, prop_name)) 303*4882a593Smuzhiyun 304*4882a593Smuzhiyun def getprop(self, nodeoffset, prop_name, quiet=()): 305*4882a593Smuzhiyun """Get a property from a node 306*4882a593Smuzhiyun 307*4882a593Smuzhiyun Args: 308*4882a593Smuzhiyun nodeoffset: Node offset containing property to get 309*4882a593Smuzhiyun prop_name: Name of property to get 310*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 311*4882a593Smuzhiyun 312*4882a593Smuzhiyun Returns: 313*4882a593Smuzhiyun Value of property as a bytearray, or -ve error number 314*4882a593Smuzhiyun 315*4882a593Smuzhiyun Raises: 316*4882a593Smuzhiyun FdtError if any error occurs (e.g. the property is not found) 317*4882a593Smuzhiyun """ 318*4882a593Smuzhiyun pdata = check_err_null(fdt_getprop(self._fdt, nodeoffset, prop_name), 319*4882a593Smuzhiyun quiet) 320*4882a593Smuzhiyun if isinstance(pdata, (int)): 321*4882a593Smuzhiyun return pdata 322*4882a593Smuzhiyun return bytearray(pdata[0]) 323*4882a593Smuzhiyun 324*4882a593Smuzhiyun def get_phandle(self, nodeoffset): 325*4882a593Smuzhiyun """Get the phandle of a node 326*4882a593Smuzhiyun 327*4882a593Smuzhiyun Args: 328*4882a593Smuzhiyun nodeoffset: Node offset to check 329*4882a593Smuzhiyun 330*4882a593Smuzhiyun Returns: 331*4882a593Smuzhiyun phandle of node, or 0 if the node has no phandle or another error 332*4882a593Smuzhiyun occurs 333*4882a593Smuzhiyun """ 334*4882a593Smuzhiyun return fdt_get_phandle(self._fdt, nodeoffset) 335*4882a593Smuzhiyun 336*4882a593Smuzhiyun def parent_offset(self, nodeoffset, quiet=()): 337*4882a593Smuzhiyun """Get the offset of a node's parent 338*4882a593Smuzhiyun 339*4882a593Smuzhiyun Args: 340*4882a593Smuzhiyun nodeoffset: Node offset to check 341*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 342*4882a593Smuzhiyun 343*4882a593Smuzhiyun Returns: 344*4882a593Smuzhiyun The offset of the parent node, if any 345*4882a593Smuzhiyun 346*4882a593Smuzhiyun Raises: 347*4882a593Smuzhiyun FdtException if no parent found or other error occurs 348*4882a593Smuzhiyun """ 349*4882a593Smuzhiyun return check_err(fdt_parent_offset(self._fdt, nodeoffset), quiet) 350*4882a593Smuzhiyun 351*4882a593Smuzhiyun def node_offset_by_phandle(self, phandle, quiet=()): 352*4882a593Smuzhiyun """Get the offset of a node with the given phandle 353*4882a593Smuzhiyun 354*4882a593Smuzhiyun Args: 355*4882a593Smuzhiyun phandle: Phandle to search for 356*4882a593Smuzhiyun quiet: Errors to ignore (empty to raise on all errors) 357*4882a593Smuzhiyun 358*4882a593Smuzhiyun Returns: 359*4882a593Smuzhiyun The offset of node with that phandle, if any 360*4882a593Smuzhiyun 361*4882a593Smuzhiyun Raises: 362*4882a593Smuzhiyun FdtException if no node found or other error occurs 363*4882a593Smuzhiyun """ 364*4882a593Smuzhiyun return check_err(fdt_node_offset_by_phandle(self._fdt, phandle), quiet) 365*4882a593Smuzhiyun 366*4882a593Smuzhiyunclass Property: 367*4882a593Smuzhiyun """Holds a device tree property name and value. 368*4882a593Smuzhiyun 369*4882a593Smuzhiyun This holds a copy of a property taken from the device tree. It does not 370*4882a593Smuzhiyun reference the device tree, so if anything changes in the device tree, 371*4882a593Smuzhiyun a Property object will remain valid. 372*4882a593Smuzhiyun 373*4882a593Smuzhiyun Properties: 374*4882a593Smuzhiyun name: Property name 375*4882a593Smuzhiyun value: Proper value as a bytearray 376*4882a593Smuzhiyun """ 377*4882a593Smuzhiyun def __init__(self, name, value): 378*4882a593Smuzhiyun self.name = name 379*4882a593Smuzhiyun self.value = value 380*4882a593Smuzhiyun%} 381*4882a593Smuzhiyun 382*4882a593Smuzhiyun%rename(fdt_property) fdt_property_func; 383*4882a593Smuzhiyun 384*4882a593Smuzhiyuntypedef int fdt32_t; 385*4882a593Smuzhiyun 386*4882a593Smuzhiyun%include "libfdt/fdt.h" 387*4882a593Smuzhiyun 388*4882a593Smuzhiyun%include "typemaps.i" 389*4882a593Smuzhiyun 390*4882a593Smuzhiyun/* Most functions don't change the device tree, so use a const void * */ 391*4882a593Smuzhiyun%typemap(in) (const void *)(const void *fdt) { 392*4882a593Smuzhiyun if (!PyByteArray_Check($input)) { 393*4882a593Smuzhiyun SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" 394*4882a593Smuzhiyun "', argument " "$argnum"" of type '" "$type""'"); 395*4882a593Smuzhiyun } 396*4882a593Smuzhiyun $1 = (void *)PyByteArray_AsString($input); 397*4882a593Smuzhiyun fdt = $1; 398*4882a593Smuzhiyun fdt = fdt; /* avoid unused variable warning */ 399*4882a593Smuzhiyun} 400*4882a593Smuzhiyun 401*4882a593Smuzhiyun/* Some functions do change the device tree, so use void * */ 402*4882a593Smuzhiyun%typemap(in) (void *)(const void *fdt) { 403*4882a593Smuzhiyun if (!PyByteArray_Check($input)) { 404*4882a593Smuzhiyun SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" 405*4882a593Smuzhiyun "', argument " "$argnum"" of type '" "$type""'"); 406*4882a593Smuzhiyun } 407*4882a593Smuzhiyun $1 = PyByteArray_AsString($input); 408*4882a593Smuzhiyun fdt = $1; 409*4882a593Smuzhiyun fdt = fdt; /* avoid unused variable warning */ 410*4882a593Smuzhiyun} 411*4882a593Smuzhiyun 412*4882a593Smuzhiyun%typemap(out) (struct fdt_property *) { 413*4882a593Smuzhiyun PyObject *buff; 414*4882a593Smuzhiyun 415*4882a593Smuzhiyun if ($1) { 416*4882a593Smuzhiyun resultobj = PyString_FromString( 417*4882a593Smuzhiyun fdt_string(fdt1, fdt32_to_cpu($1->nameoff))); 418*4882a593Smuzhiyun buff = PyByteArray_FromStringAndSize( 419*4882a593Smuzhiyun (const char *)($1 + 1), fdt32_to_cpu($1->len)); 420*4882a593Smuzhiyun resultobj = SWIG_Python_AppendOutput(resultobj, buff); 421*4882a593Smuzhiyun } 422*4882a593Smuzhiyun} 423*4882a593Smuzhiyun 424*4882a593Smuzhiyun%apply int *OUTPUT { int *lenp }; 425*4882a593Smuzhiyun 426*4882a593Smuzhiyun/* typemap used for fdt_getprop() */ 427*4882a593Smuzhiyun%typemap(out) (const void *) { 428*4882a593Smuzhiyun if (!$1) 429*4882a593Smuzhiyun $result = Py_None; 430*4882a593Smuzhiyun else 431*4882a593Smuzhiyun $result = Py_BuildValue("s#", $1, *arg4); 432*4882a593Smuzhiyun} 433*4882a593Smuzhiyun 434*4882a593Smuzhiyun/* We have both struct fdt_property and a function fdt_property() */ 435*4882a593Smuzhiyun%warnfilter(302) fdt_property; 436*4882a593Smuzhiyun 437*4882a593Smuzhiyun/* These are macros in the header so have to be redefined here */ 438*4882a593Smuzhiyunint fdt_magic(const void *fdt); 439*4882a593Smuzhiyunint fdt_totalsize(const void *fdt); 440*4882a593Smuzhiyunint fdt_off_dt_struct(const void *fdt); 441*4882a593Smuzhiyunint fdt_off_dt_strings(const void *fdt); 442*4882a593Smuzhiyunint fdt_off_mem_rsvmap(const void *fdt); 443*4882a593Smuzhiyunint fdt_version(const void *fdt); 444*4882a593Smuzhiyunint fdt_last_comp_version(const void *fdt); 445*4882a593Smuzhiyunint fdt_boot_cpuid_phys(const void *fdt); 446*4882a593Smuzhiyunint fdt_size_dt_strings(const void *fdt); 447*4882a593Smuzhiyunint fdt_size_dt_struct(const void *fdt); 448*4882a593Smuzhiyun 449*4882a593Smuzhiyun%include <../libfdt/libfdt.h> 450