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>
27 lines
681 B
Python
27 lines
681 B
Python
#!/usr/bin/python
|
|
#
|
|
# Copyright (C) 2016 Google, Inc
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0+
|
|
#
|
|
|
|
# Bring in either the normal fdt library (which relies on libfdt) or the
|
|
# fallback one (which uses fdtget and is slower). Both provide the same
|
|
# interface for this file to use.
|
|
try:
|
|
import fdt_normal
|
|
have_libfdt = True
|
|
except ImportError:
|
|
have_libfdt = False
|
|
import fdt_fallback
|
|
|
|
def FdtScan(fname):
|
|
"""Returns a new Fdt object from the implementation we are using"""
|
|
if have_libfdt:
|
|
dtb = fdt_normal.FdtNormal(fname)
|
|
else:
|
|
dtb = fdt_fallback.FdtFallback(fname)
|
|
dtb.Scan()
|
|
return dtb
|