2018-05-07 06:58:06 +09:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2016-11-26 12:15:53 +09:00
|
|
|
# Copyright (c) 2016 Google, Inc
|
2018-05-07 06:58:06 +09:00
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
2016-11-26 12:15:53 +09:00
|
|
|
#
|
|
|
|
# Entry-type module for U-Boot device tree with the microcode removed
|
|
|
|
#
|
|
|
|
|
|
|
|
from entry import Entry
|
2018-09-14 19:57:24 +09:00
|
|
|
from blob_dtb import Entry_blob_dtb
|
2016-11-26 12:15:53 +09:00
|
|
|
import tools
|
|
|
|
|
2018-09-14 19:57:24 +09:00
|
|
|
class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
|
2016-11-26 12:15:53 +09:00
|
|
|
"""A U-Boot device tree file, with the microcode removed
|
|
|
|
|
2018-07-18 04:25:35 +09:00
|
|
|
Properties / Entry arguments:
|
|
|
|
- filename: Filename of u-boot.dtb (default 'u-boot.dtb')
|
|
|
|
|
|
|
|
See Entry_u_boot_ucode for full details of the three entries involved in
|
|
|
|
this process. This entry provides the U-Boot device-tree file, which
|
|
|
|
contains the microcode. If the microcode is not being collated into one
|
|
|
|
place then the offset and size of the microcode is recorded by this entry,
|
|
|
|
for use by u_boot_with_ucode_ptr. If it is being collated, then this
|
|
|
|
entry deletes the microcode from the device tree (to save space) and makes
|
|
|
|
it available to u_boot_ucode.
|
2016-11-26 12:15:53 +09:00
|
|
|
"""
|
2018-06-02 00:38:14 +09:00
|
|
|
def __init__(self, section, etype, node):
|
2019-08-24 22:22:44 +09:00
|
|
|
# Put this here to allow entry-docs and help to work without libfdt
|
|
|
|
global state
|
|
|
|
import state
|
|
|
|
|
2018-09-14 19:57:24 +09:00
|
|
|
Entry_blob_dtb.__init__(self, section, etype, node)
|
2019-05-18 13:00:46 +09:00
|
|
|
self.ucode_data = b''
|
2016-11-26 12:15:53 +09:00
|
|
|
self.collate = False
|
|
|
|
self.ucode_offset = None
|
|
|
|
self.ucode_size = None
|
2018-07-07 01:27:40 +09:00
|
|
|
self.ucode = None
|
|
|
|
self.ready = False
|
2016-11-26 12:15:53 +09:00
|
|
|
|
|
|
|
def GetDefaultFilename(self):
|
|
|
|
return 'u-boot.dtb'
|
|
|
|
|
2019-07-21 03:23:31 +09:00
|
|
|
def GetFdtEtype(self):
|
|
|
|
return 'u-boot-dtb'
|
|
|
|
|
2018-07-07 01:27:40 +09:00
|
|
|
def ProcessFdt(self, fdt):
|
2018-07-18 04:25:36 +09:00
|
|
|
# So the module can be loaded without it
|
|
|
|
import fdt
|
|
|
|
|
2018-06-02 00:38:14 +09:00
|
|
|
# If the section does not need microcode, there is nothing to do
|
|
|
|
ucode_dest_entry = self.section.FindEntryType(
|
|
|
|
'u-boot-spl-with-ucode-ptr')
|
2018-09-14 19:57:32 +09:00
|
|
|
if not ucode_dest_entry or not ucode_dest_entry.target_offset:
|
|
|
|
ucode_dest_entry = self.section.FindEntryType(
|
|
|
|
'u-boot-tpl-with-ucode-ptr')
|
2018-08-02 06:22:37 +09:00
|
|
|
if not ucode_dest_entry or not ucode_dest_entry.target_offset:
|
2018-06-02 00:38:14 +09:00
|
|
|
ucode_dest_entry = self.section.FindEntryType(
|
|
|
|
'u-boot-with-ucode-ptr')
|
2018-08-02 06:22:37 +09:00
|
|
|
if not ucode_dest_entry or not ucode_dest_entry.target_offset:
|
2016-11-26 12:15:53 +09:00
|
|
|
return True
|
|
|
|
|
|
|
|
# Remove the microcode
|
2019-07-21 03:23:32 +09:00
|
|
|
etype = self.GetFdtEtype()
|
|
|
|
fdt = state.GetFdtForEtype(etype)
|
2018-07-07 01:27:40 +09:00
|
|
|
self.ucode = fdt.GetNode('/microcode')
|
|
|
|
if not self.ucode:
|
2019-07-21 03:23:32 +09:00
|
|
|
raise self.Raise("No /microcode node found in '%s'" % etype)
|
2016-11-26 12:15:53 +09:00
|
|
|
|
|
|
|
# There's no need to collate it (move all microcode into one place)
|
|
|
|
# if we only have one chunk of microcode.
|
2018-07-07 01:27:40 +09:00
|
|
|
self.collate = len(self.ucode.subnodes) > 1
|
|
|
|
for node in self.ucode.subnodes:
|
2016-11-26 12:15:53 +09:00
|
|
|
data_prop = node.props.get('data')
|
|
|
|
if data_prop:
|
2019-05-18 13:00:46 +09:00
|
|
|
self.ucode_data += data_prop.bytes
|
2016-11-26 12:15:53 +09:00
|
|
|
if self.collate:
|
2018-07-07 01:27:40 +09:00
|
|
|
node.DeleteProp('data')
|
|
|
|
return True
|
|
|
|
|
|
|
|
def ObtainContents(self):
|
|
|
|
# Call the base class just in case it does something important.
|
2018-09-14 19:57:24 +09:00
|
|
|
Entry_blob_dtb.ObtainContents(self)
|
2018-09-14 19:57:32 +09:00
|
|
|
if self.ucode and not self.collate:
|
2018-07-07 01:27:40 +09:00
|
|
|
for node in self.ucode.subnodes:
|
|
|
|
data_prop = node.props.get('data')
|
2018-09-14 19:57:32 +09:00
|
|
|
if data_prop:
|
2017-05-27 22:38:27 +09:00
|
|
|
# Find the offset in the device tree of the ucode data
|
|
|
|
self.ucode_offset = data_prop.GetOffset() + 12
|
|
|
|
self.ucode_size = len(data_prop.bytes)
|
2018-09-14 19:57:32 +09:00
|
|
|
self.ready = True
|
|
|
|
else:
|
|
|
|
self.ready = True
|
|
|
|
return self.ready
|