1*b8ef5b6bSSimon Glass# SPDX-License-Identifier: GPL-2.0+
2*b8ef5b6bSSimon Glass# Copyright (c) 2016 Google, Inc
3*b8ef5b6bSSimon Glass# Written by Simon Glass <sjg@chromium.org>
4*b8ef5b6bSSimon Glass#
5*b8ef5b6bSSimon Glass# Entry-type module for tpl/u-boot-tpl.bin
6*b8ef5b6bSSimon Glass#
7*b8ef5b6bSSimon Glass
8*b8ef5b6bSSimon Glassimport elf
9*b8ef5b6bSSimon Glass
10*b8ef5b6bSSimon Glassfrom entry import Entry
11*b8ef5b6bSSimon Glassfrom blob import Entry_blob
12*b8ef5b6bSSimon Glass
13*b8ef5b6bSSimon Glassclass Entry_u_boot_tpl(Entry_blob):
14*b8ef5b6bSSimon Glass    """U-Boot TPL binary
15*b8ef5b6bSSimon Glass
16*b8ef5b6bSSimon Glass    Properties / Entry arguments:
17*b8ef5b6bSSimon Glass        - filename: Filename of u-boot-tpl.bin (default 'tpl/u-boot-tpl.bin')
18*b8ef5b6bSSimon Glass
19*b8ef5b6bSSimon Glass    This is the U-Boot TPL (Tertiary Program Loader) binary. This is a small
20*b8ef5b6bSSimon Glass    binary which loads before SPL, typically into on-chip SRAM. It is
21*b8ef5b6bSSimon Glass    responsible for locating, loading and jumping to SPL, the next-stage
22*b8ef5b6bSSimon Glass    loader. Note that SPL is not relocatable so must be loaded to the correct
23*b8ef5b6bSSimon Glass    address in SRAM, or written to run from the correct address if direct
24*b8ef5b6bSSimon Glass    flash execution is possible (e.g. on x86 devices).
25*b8ef5b6bSSimon Glass
26*b8ef5b6bSSimon Glass    SPL can access binman symbols at runtime. See:
27*b8ef5b6bSSimon Glass
28*b8ef5b6bSSimon Glass        'Access to binman entry offsets at run time (symbols)'
29*b8ef5b6bSSimon Glass
30*b8ef5b6bSSimon Glass    in the binman README for more information.
31*b8ef5b6bSSimon Glass
32*b8ef5b6bSSimon Glass    The ELF file 'tpl/u-boot-tpl' must also be available for this to work, since
33*b8ef5b6bSSimon Glass    binman uses that to look up symbols to write into the TPL binary.
34*b8ef5b6bSSimon Glass    """
35*b8ef5b6bSSimon Glass    def __init__(self, section, etype, node):
36*b8ef5b6bSSimon Glass        Entry_blob.__init__(self, section, etype, node)
37*b8ef5b6bSSimon Glass        self.elf_fname = 'tpl/u-boot-tpl'
38*b8ef5b6bSSimon Glass
39*b8ef5b6bSSimon Glass    def GetDefaultFilename(self):
40*b8ef5b6bSSimon Glass        return 'tpl/u-boot-tpl.bin'
41*b8ef5b6bSSimon Glass
42*b8ef5b6bSSimon Glass    def WriteSymbols(self, section):
43*b8ef5b6bSSimon Glass        elf.LookupAndWriteSymbols(self.elf_fname, self, section)
44