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
|
|
|
|
|
|
|
|
import command
|
2017-11-14 10:54:54 +09:00
|
|
|
import elf
|
2016-11-26 12:15:53 +09:00
|
|
|
from entry import Entry
|
|
|
|
from blob import Entry_blob
|
|
|
|
import fdt_util
|
|
|
|
import tools
|
|
|
|
|
|
|
|
class Entry_u_boot_with_ucode_ptr(Entry_blob):
|
|
|
|
"""U-Boot with embedded microcode pointer
|
|
|
|
|
|
|
|
See Entry_u_boot_ucode for full details of the 3 entries involved in this
|
|
|
|
process.
|
|
|
|
"""
|
2018-06-02 00:38:14 +09:00
|
|
|
def __init__(self, section, etype, node):
|
|
|
|
Entry_blob.__init__(self, section, etype, node)
|
2016-11-26 12:15:53 +09:00
|
|
|
self.elf_fname = 'u-boot'
|
|
|
|
self.target_pos = None
|
|
|
|
|
|
|
|
def GetDefaultFilename(self):
|
|
|
|
return 'u-boot-nodtb.bin'
|
|
|
|
|
|
|
|
def ObtainContents(self):
|
|
|
|
# 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:
|
|
|
|
self.target_pos = 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')
|
|
|
|
|
|
|
|
return Entry_blob.ObtainContents(self)
|
|
|
|
|
|
|
|
def ProcessContents(self):
|
|
|
|
# If the image does not need microcode, there is nothing to do
|
|
|
|
if not self.target_pos:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Get the position 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
|
2016-11-26 12:15:53 +09:00
|
|
|
# being linked incorrectly, or is being placed at the wrong position
|
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-06-02 00:38:14 +09:00
|
|
|
# the U-Boot region must start at position 7MB in the section. In this
|
2016-11-26 12:15:53 +09:00
|
|
|
# case the ROM starts at 0xff800000, so the position of the first
|
2018-06-02 00:38:14 +09:00
|
|
|
# entry in the section corresponds to that.
|
2016-11-26 12:15:53 +09:00
|
|
|
if (self.target_pos < self.pos or
|
|
|
|
self.target_pos >= self.pos + self.size):
|
|
|
|
self.Raise('Microcode pointer _dt_ucode_base_size at %08x is '
|
2018-06-02 00:38:14 +09:00
|
|
|
'outside the section ranging from %08x to %08x' %
|
2016-11-26 12:15:53 +09:00
|
|
|
(self.target_pos, self.pos, self.pos + self.size))
|
|
|
|
|
|
|
|
# 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
|
|
|
|
# in the former. If we extracted the microcode from the device tree
|
|
|
|
# and collated it in one place, it will be in the latter.
|
|
|
|
if ucode_entry.size:
|
|
|
|
pos, size = ucode_entry.pos, ucode_entry.size
|
|
|
|
else:
|
2018-06-02 00:38:14 +09:00
|
|
|
dtb_entry = self.section.FindEntryType('u-boot-dtb-with-ucode')
|
2016-11-26 12:15:53 +09:00
|
|
|
if not dtb_entry:
|
|
|
|
self.Raise('Cannot find microcode region u-boot-dtb-with-ucode')
|
|
|
|
pos = dtb_entry.pos + dtb_entry.ucode_offset
|
|
|
|
size = dtb_entry.ucode_size
|
|
|
|
|
|
|
|
# Write the microcode position and size into the entry
|
|
|
|
pos_and_size = struct.pack('<2L', pos, size)
|
|
|
|
self.target_pos -= self.pos
|
2018-07-07 01:27:19 +09:00
|
|
|
self.ProcessContentsUpdate(self.data[:self.target_pos] + pos_and_size +
|
|
|
|
self.data[self.target_pos + 8:])
|