Simon Glass | ba48258 | 2016-07-25 18:59:02 -0600 | [diff] [blame] | 1 | #!/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 Glass | 3cb44ba | 2016-09-25 15:52:19 -0600 | [diff] [blame] | 9 | import fdt_fallback |
| 10 | |
Simon Glass | ba48258 | 2016-07-25 18:59:02 -0600 | [diff] [blame] | 11 | # 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. |
| 14 | try: |
Simon Glass | a06a34b | 2016-07-25 18:59:04 -0600 | [diff] [blame] | 15 | import fdt_normal |
Simon Glass | ba48258 | 2016-07-25 18:59:02 -0600 | [diff] [blame] | 16 | have_libfdt = True |
| 17 | except ImportError: |
| 18 | have_libfdt = False |
Simon Glass | ba48258 | 2016-07-25 18:59:02 -0600 | [diff] [blame] | 19 | |
Simon Glass | 3cb44ba | 2016-09-25 15:52:19 -0600 | [diff] [blame] | 20 | force_fallback = False |
| 21 | |
| 22 | def FdtScan(fname, _force_fallback=False): |
Simon Glass | ba48258 | 2016-07-25 18:59:02 -0600 | [diff] [blame] | 23 | """Returns a new Fdt object from the implementation we are using""" |
Simon Glass | 3cb44ba | 2016-09-25 15:52:19 -0600 | [diff] [blame] | 24 | if have_libfdt and not force_fallback and not _force_fallback: |
Simon Glass | a06a34b | 2016-07-25 18:59:04 -0600 | [diff] [blame] | 25 | dtb = fdt_normal.FdtNormal(fname) |
| 26 | else: |
| 27 | dtb = fdt_fallback.FdtFallback(fname) |
Simon Glass | ba48258 | 2016-07-25 18:59:02 -0600 | [diff] [blame] | 28 | dtb.Scan() |
| 29 | return dtb |
Simon Glass | 3cb44ba | 2016-09-25 15:52:19 -0600 | [diff] [blame] | 30 | |
| 31 | def UseFallback(fallback): |
| 32 | global force_fallback |
| 33 | |
| 34 | old_val = force_fallback |
| 35 | force_fallback = fallback |
| 36 | return old_val |