3 # Copyright (C) 2016 Google, Inc
4 # Written by Simon Glass <sjg@chromium.org>
6 # SPDX-License-Identifier: GPL-2.0+
16 def fdt32_to_cpu(val):
17 """Convert a device tree cell to an integer
20 Value to convert (4-character string representing the cell value)
23 A native-endian integer value
25 return struct.unpack('>I', val)[0]
27 def EnsureCompiled(fname):
28 """Compile an fdt .dts source file into a .dtb binary blob if needed.
31 fname: Filename (if .dts it will be compiled). It not it will be
35 Filename of resulting .dtb file
37 _, ext = os.path.splitext(fname)
41 dts_input = tools.GetOutputFilename('source.dts')
42 dtb_output = tools.GetOutputFilename('source.dtb')
44 search_paths = [os.path.join(os.getcwd(), 'include')]
45 root, _ = os.path.splitext(fname)
46 args = ['-E', '-P', '-x', 'assembler-with-cpp', '-D__ASSEMBLY__']
48 for path in search_paths:
49 args.extend(['-I', path])
50 args += ['-o', dts_input, fname]
51 command.Run('cc', *args)
53 # If we don't have a directory, put it in the tools tempdir
55 for path in search_paths:
56 search_list.extend(['-i', path])
57 args = ['-I', 'dts', '-o', dtb_output, '-O', 'dtb']
58 args.extend(search_list)
59 args.append(dts_input)
60 command.Run('dtc', *args)