]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - tools/binman/etype/u_boot_dtb_with_ucode.py
1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2016 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
5 # Entry-type module for U-Boot device tree with the microcode removed
9 from entry
import Entry
10 from blob
import Entry_blob
13 class Entry_u_boot_dtb_with_ucode(Entry_blob
):
14 """A U-Boot device tree file, with the microcode removed
16 See Entry_u_boot_ucode for full details of the 3 entries involved in this
19 def __init__(self
, image
, etype
, node
):
20 Entry_blob
.__init
__(self
, image
, etype
, node
)
23 self
.ucode_offset
= None
24 self
.ucode_size
= None
26 def GetDefaultFilename(self
):
29 def ObtainContents(self
):
30 Entry_blob
.ObtainContents(self
)
32 # If the image does not need microcode, there is nothing to do
33 ucode_dest_entry
= self
.image
.FindEntryType('u-boot-spl-with-ucode-ptr')
34 if not ucode_dest_entry
or not ucode_dest_entry
.target_pos
:
35 ucode_dest_entry
= self
.image
.FindEntryType('u-boot-with-ucode-ptr')
36 if not ucode_dest_entry
or not ucode_dest_entry
.target_pos
:
39 # Create a new file to hold the copied device tree
40 dtb_name
= 'u-boot-dtb-with-ucode.dtb'
41 fname
= tools
.GetOutputFilename(dtb_name
)
42 with
open(fname
, 'wb') as fd
:
45 # Remove the microcode
46 dtb
= fdt
.FdtScan(fname
)
47 ucode
= dtb
.GetNode('/microcode')
49 raise self
.Raise("No /microcode node found in '%s'" % fname
)
51 # There's no need to collate it (move all microcode into one place)
52 # if we only have one chunk of microcode.
53 self
.collate
= len(ucode
.subnodes
) > 1
54 for node
in ucode
.subnodes
:
55 data_prop
= node
.props
.get('data')
57 self
.ucode_data
+= ''.join(data_prop
.bytes
)
59 prop
= node
.DeleteProp('data')
61 # Find the offset in the device tree of the ucode data
62 self
.ucode_offset
= data_prop
.GetOffset() + 12
63 self
.ucode_size
= len(data_prop
.bytes
)
68 # Make this file the contents of this entry
69 self
._pathname
= fname