blob: ea78c527fc1e0faa02d28420a7bb1dbe1175199c [file] [log] [blame]
Simon Glassba482582016-07-25 18:59:02 -06001#!/usr/bin/python
2#
3# Copyright (C) 2016 Google, Inc
4# Written by Simon Glass <sjg@chromium.org>
5#
6# SPDX-License-Identifier: GPL-2.0+
7#
8
Simon Glass3cb44ba2016-09-25 15:52:19 -06009import fdt_fallback
10
Simon Glassba482582016-07-25 18:59:02 -060011# Bring in either the normal fdt library (which relies on libfdt) or the
12# fallback one (which uses fdtget and is slower). Both provide the same
13# interface for this file to use.
14try:
Simon Glassa06a34b2016-07-25 18:59:04 -060015 import fdt_normal
Simon Glassba482582016-07-25 18:59:02 -060016 have_libfdt = True
17except ImportError:
18 have_libfdt = False
Simon Glassba482582016-07-25 18:59:02 -060019
Simon Glass3cb44ba2016-09-25 15:52:19 -060020force_fallback = False
21
22def FdtScan(fname, _force_fallback=False):
Simon Glassba482582016-07-25 18:59:02 -060023 """Returns a new Fdt object from the implementation we are using"""
Simon Glass3cb44ba2016-09-25 15:52:19 -060024 if have_libfdt and not force_fallback and not _force_fallback:
Simon Glassa06a34b2016-07-25 18:59:04 -060025 dtb = fdt_normal.FdtNormal(fname)
26 else:
27 dtb = fdt_fallback.FdtFallback(fname)
Simon Glassba482582016-07-25 18:59:02 -060028 dtb.Scan()
29 return dtb
Simon Glass3cb44ba2016-09-25 15:52:19 -060030
31def UseFallback(fallback):
32 global force_fallback
33
34 old_val = force_fallback
35 force_fallback = fallback
36 return old_val