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
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
# Entry-type module for a U-Boot binary with an embedded microcode pointer
|
|
|
|
#
|
|
|
|
|
|
|
|
import struct
|
|
|
|
|
2020-04-18 09:09:03 +09:00
|
|
|
from binman import elf
|
|
|
|
from binman.entry import Entry
|
|
|
|
from binman.etype.blob import Entry_blob
|
|
|
|
from dtoc import fdt_util
|
2020-04-18 09:09:04 +09:00
|
|
|
from patman import tools
|
|
|
|
from patman import command
|
2016-11-26 12:15:53 +09:00
|
|
|
|
|
|
|
class Entry_u_boot_with_ucode_ptr(Entry_blob):
|
|
|
|
"""U-Boot with embedded microcode pointer
|
|
|
|
|
2018-07-18 04:25:35 +09:00
|
|
|
Properties / Entry arguments:
|
2019-12-14 13:47:26 +09:00
|
|
|
- filename: Filename of u-boot-nodtb.bin (default 'u-boot-nodtb.bin')
|
2018-09-14 19:57:07 +09:00
|
|
|
- optional-ucode: boolean property to make microcode optional. If the
|
|
|
|
u-boot.bin image does not include microcode, no error will
|
|
|
|
be generated.
|
2018-07-18 04:25:35 +09:00
|
|
|
|
|
|
|
See Entry_u_boot_ucode for full details of the three entries involved in
|
|
|
|
this process. This entry updates U-Boot with the offset and size of the
|
|
|
|
microcode, to allow early x86 boot code to find it without doing anything
|
|
|
|
complicated. Otherwise it is the same as the u_boot entry.
|
2016-11-26 12:15:53 +09:00
|
|
|
"""
|
2018-06-02 00:38:14 +09:00
|
|
|
def __init__(self, section, etype, node):
|
2020-07-10 09:39:35 +09:00
|
|
|
super().__init__(section, etype, node)
|
2016-11-26 12:15:53 +09:00
|
|
|
self.elf_fname = 'u-boot'
|
2018-08-02 06:22:37 +09:00
|
|
|
self.target_offset = None
|
2016-11-26 12:15:53 +09:00
|
|
|
|
|
|
|
def GetDefaultFilename(self):
|
|
|
|
return 'u-boot-nodtb.bin'
|
|
|
|
|
2018-07-07 01:27:40 +09:00
|
|
|
def ProcessFdt(self, fdt):
|
2016-11-26 12:15:53 +09:00
|
|
|
# Figure out where to put the microcode pointer
|
|
|
|
fname = tools.GetInputFilename(self.elf_fname)
|
2017-11-14 10:54:54 +09:00
|
|
|
sym = elf.GetSymbolAddress(fname, '_dt_ucode_base_size')
|
|
|
|
if sym:
|
2018-08-02 06:22:37 +09:00
|
|
|
self.target_offset = sym
|
2016-11-26 12:15:53 +09:00
|
|
|
elif not fdt_util.GetBool(self._node, 'optional-ucode'):
|
|
|
|
self.Raise('Cannot locate _dt_ucode_base_size symbol in u-boot')
|
2018-07-07 01:27:40 +09:00
|
|
|
return True
|
2016-11-26 12:15:53 +09:00
|
|
|
|
|
|
|
def ProcessContents(self):
|
|
|
|
# If the image does not need microcode, there is nothing to do
|
2018-08-02 06:22:37 +09:00
|
|
|
if not self.target_offset:
|
2019-07-09 05:25:37 +09:00
|
|
|
return True
|
2016-11-26 12:15:53 +09:00
|
|
|
|
2018-08-02 06:22:37 +09:00
|
|
|
# Get the offset of the microcode
|
2018-06-02 00:38:14 +09:00
|
|
|
ucode_entry = self.section.FindEntryType('u-boot-ucode')
|
2016-11-26 12:15:53 +09:00
|
|
|
if not ucode_entry:
|
|
|
|
self.Raise('Cannot find microcode region u-boot-ucode')
|
|
|
|
|
2018-06-02 00:38:14 +09:00
|
|
|
# Check the target pos is in the section. If it is not, then U-Boot is
|
2018-08-02 06:22:37 +09:00
|
|
|
# being linked incorrectly, or is being placed at the wrong offset
|
2018-06-02 00:38:14 +09:00
|
|
|
# in the section.
|
2016-11-26 12:15:53 +09:00
|
|
|
#
|
2018-06-02 00:38:14 +09:00
|
|
|
# The section must be set up so that U-Boot is placed at the
|
2016-11-26 12:15:53 +09:00
|
|
|
# flash address to which it is linked. For example, if
|
|
|
|
# CONFIG_SYS_TEXT_BASE is 0xfff00000, and the ROM is 8MB, then
|
2018-08-02 06:22:37 +09:00
|
|
|
# the U-Boot region must start at offset 7MB in the section. In this
|
|
|
|
# case the ROM starts at 0xff800000, so the offset of the first
|
2018-06-02 00:38:14 +09:00
|
|
|
# entry in the section corresponds to that.
|
2018-09-14 19:57:34 +09:00
|
|
|
if (self.target_offset < self.image_pos or
|
|
|
|
self.target_offset >= self.image_pos + self.size):
|
|
|
|
self.Raise('Microcode pointer _dt_ucode_base_size at %08x is outside the section ranging from %08x to %08x' %
|
|
|
|
(self.target_offset, self.image_pos,
|
|
|
|
self.image_pos + self.size))
|
2016-11-26 12:15:53 +09:00
|
|
|
|
|
|
|
# Get the microcode, either from u-boot-ucode or u-boot-dtb-with-ucode.
|
|
|
|
# If we have left the microcode in the device tree, then it will be
|
2018-09-14 19:57:32 +09:00
|
|
|
# in the latter. If we extracted the microcode from the device tree
|
|
|
|
# and collated it in one place, it will be in the former.
|
2016-11-26 12:15:53 +09:00
|
|
|
if ucode_entry.size:
|
2018-08-02 06:22:37 +09:00
|
|
|
offset, size = ucode_entry.offset, ucode_entry.size
|
2016-11-26 12:15:53 +09:00
|
|
|
else:
|
2018-06-02 00:38:14 +09:00
|
|
|
dtb_entry = self.section.FindEntryType('u-boot-dtb-with-ucode')
|
2018-09-14 19:57:32 +09:00
|
|
|
if not dtb_entry:
|
|
|
|
dtb_entry = self.section.FindEntryType(
|
|
|
|
'u-boot-tpl-dtb-with-ucode')
|
|
|
|
if not dtb_entry:
|
2016-11-26 12:15:53 +09:00
|
|
|
self.Raise('Cannot find microcode region u-boot-dtb-with-ucode')
|
2018-08-02 06:22:37 +09:00
|
|
|
offset = dtb_entry.offset + dtb_entry.ucode_offset
|
2016-11-26 12:15:53 +09:00
|
|
|
size = dtb_entry.ucode_size
|
|
|
|
|
2018-08-02 06:22:37 +09:00
|
|
|
# Write the microcode offset and size into the entry
|
|
|
|
offset_and_size = struct.pack('<2L', offset, size)
|
2018-09-14 19:57:34 +09:00
|
|
|
self.target_offset -= self.image_pos
|
2019-07-09 05:25:35 +09:00
|
|
|
return self.ProcessContentsUpdate(self.data[:self.target_offset] +
|
|
|
|
offset_and_size +
|
|
|
|
self.data[self.target_offset + 8:])
|