blob: ea78c527fc1e0faa02d28420a7bb1dbe1175199c [file] [log] [blame]
Simon Glassb71ef892016-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 Glass0c1ee6c2016-09-25 15:52:19 -06009import fdt_fallback
10
Simon Glassb71ef892016-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 Glass1f941b62016-07-25 18:59:04 -060015 import fdt_normal
Simon Glassb71ef892016-07-25 18:59:02 -060016 have_libfdt = True
17except ImportError:
18 have_libfdt = False
Simon Glass0c1ee6c2016-09-25 15:52:19 -060019
20force_fallback = False
Simon Glassb71ef892016-07-25 18:59:02 -060021
Simon Glass0c1ee6c2016-09-25 15:52:19 -060022def FdtScan(fname, _force_fallback=False):
Simon Glassb71ef892016-07-25 18:59:02 -060023 """Returns a new Fdt object from the implementation we are using"""
Simon Glass0c1ee6c2016-09-25 15:52:19 -060024 if have_libfdt and not force_fallback and not _force_fallback:
Simon Glass1f941b62016-07-25 18:59:04 -060025 dtb = fdt_normal.FdtNormal(fname)
26 else:
27 dtb = fdt_fallback.FdtFallback(fname)
Simon Glassb71ef892016-07-25 18:59:02 -060028 dtb.Scan()
29 return dtb
Simon Glass0c1ee6c2016-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