u-boot/include/binman_sym.h

93 lines
3 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0+ */
binman: Support accessing binman tables at run time Binman construct images consisting of multiple binary files. These files sometimes need to know (at run timme) where their peers are located. For example, SPL may want to know where U-Boot is located in the image, so that it can jump to U-Boot correctly on boot. In general the positions where the binaries end up after binman has finished packing them cannot be known at compile time. One reason for this is that binman does not know the size of the binaries until everything is compiled, linked and converted to binaries with objcopy. To make this work, we add a feature to binman which checks each binary for symbol names starting with '_binman'. These are then decoded to figure out which entry and property they refer to. Then binman writes the value of this symbol into the appropriate binary. With this, the symbol will have the correct value at run time. Macros are used to make this easier to use. As an example, this declares a symbol that will access the 'u-boot-spl' entry to find the 'pos' value (i.e. the position of SPL in the image): binman_sym_declare(unsigned long, u_boot_spl, pos); This converts to a symbol called '_binman_u_boot_spl_prop_pos' in any binary that includes it. Binman then updates the value in that binary, ensuring that it can be accessed at runtime with: ulong u_boot_pos = binman_sym(ulong, u_boot_spl, pos); This assigns the variable u_boot_pos to the position of SPL in the image. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-11-14 01:55:01 +00:00
/*
* Symbol access for symbols set up by binman as part of the build.
*
* This allows C code to access the position of a particular part of the image
* assembled by binman.
*
* Copyright (c) 2017 Google, Inc
*/
#ifndef __BINMAN_SYM_H
#define __BINMAN_SYM_H
#define BINMAN_SYM_MISSING (-1UL)
#ifdef CONFIG_BINMAN
/**
* binman_symname() - Internal fnuction to get a binman symbol name
*
* @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
* @_prop_name: Property value to get from that entry (e.g. 'pos')
* @returns name of the symbol for that entry and property
*/
#define binman_symname(_entry_name, _prop_name) \
_binman_ ## _entry_name ## _prop_ ## _prop_name
/**
* binman_sym_declare() - Declare a symbol that will be used at run-time
*
* @_type: Type f the symbol (e.g. unsigned long)
* @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
* @_prop_name: Property value to get from that entry (e.g. 'pos')
*/
#define binman_sym_declare(_type, _entry_name, _prop_name) \
_type binman_symname(_entry_name, _prop_name) \
__attribute__((aligned(4), unused, section(".binman_sym")))
/**
* binman_sym_extern() - Declare a extern symbol that will be used at run-time
*
* @_type: Type f the symbol (e.g. unsigned long)
* @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
* @_prop_name: Property value to get from that entry (e.g. 'pos')
*/
#define binman_sym_extern(_type, _entry_name, _prop_name) \
extern _type binman_symname(_entry_name, _prop_name) \
__attribute__((aligned(4), unused, section(".binman_sym")))
binman: Support accessing binman tables at run time Binman construct images consisting of multiple binary files. These files sometimes need to know (at run timme) where their peers are located. For example, SPL may want to know where U-Boot is located in the image, so that it can jump to U-Boot correctly on boot. In general the positions where the binaries end up after binman has finished packing them cannot be known at compile time. One reason for this is that binman does not know the size of the binaries until everything is compiled, linked and converted to binaries with objcopy. To make this work, we add a feature to binman which checks each binary for symbol names starting with '_binman'. These are then decoded to figure out which entry and property they refer to. Then binman writes the value of this symbol into the appropriate binary. With this, the symbol will have the correct value at run time. Macros are used to make this easier to use. As an example, this declares a symbol that will access the 'u-boot-spl' entry to find the 'pos' value (i.e. the position of SPL in the image): binman_sym_declare(unsigned long, u_boot_spl, pos); This converts to a symbol called '_binman_u_boot_spl_prop_pos' in any binary that includes it. Binman then updates the value in that binary, ensuring that it can be accessed at runtime with: ulong u_boot_pos = binman_sym(ulong, u_boot_spl, pos); This assigns the variable u_boot_pos to the position of SPL in the image. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-11-14 01:55:01 +00:00
/**
* binman_sym_declare_optional() - Declare an optional symbol
*
* If this symbol cannot be provided by binman, an error will not be generated.
* Instead the image will be assigned the value BINMAN_SYM_MISSING.
*
* @_type: Type f the symbol (e.g. unsigned long)
* @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
* @_prop_name: Property value to get from that entry (e.g. 'pos')
*/
#define binman_sym_declare_optional(_type, _entry_name, _prop_name) \
_type binman_symname(_entry_name, _prop_name) \
__attribute__((aligned(4), weak, unused, \
section(".binman_sym")))
/**
* binman_sym() - Access a previously declared symbol
*
* This is used to get the value of a symbol. E.g.:
*
* ulong address = binman_sym(ulong, u_boot_spl, pos);
*
* @_type: Type f the symbol (e.g. unsigned long)
* @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
* @_prop_name: Property value to get from that entry (e.g. 'pos')
* @returns value of that property (filled in by binman)
*/
#define binman_sym(_type, _entry_name, _prop_name) \
(*(_type *)&binman_symname(_entry_name, _prop_name))
#else /* !BINMAN */
#define binman_sym_declare(_type, _entry_name, _prop_name)
#define binman_sym_declare_optional(_type, _entry_name, _prop_name)
#define binman_sym_extern(_type, _entry_name, _prop_name)
binman: Support accessing binman tables at run time Binman construct images consisting of multiple binary files. These files sometimes need to know (at run timme) where their peers are located. For example, SPL may want to know where U-Boot is located in the image, so that it can jump to U-Boot correctly on boot. In general the positions where the binaries end up after binman has finished packing them cannot be known at compile time. One reason for this is that binman does not know the size of the binaries until everything is compiled, linked and converted to binaries with objcopy. To make this work, we add a feature to binman which checks each binary for symbol names starting with '_binman'. These are then decoded to figure out which entry and property they refer to. Then binman writes the value of this symbol into the appropriate binary. With this, the symbol will have the correct value at run time. Macros are used to make this easier to use. As an example, this declares a symbol that will access the 'u-boot-spl' entry to find the 'pos' value (i.e. the position of SPL in the image): binman_sym_declare(unsigned long, u_boot_spl, pos); This converts to a symbol called '_binman_u_boot_spl_prop_pos' in any binary that includes it. Binman then updates the value in that binary, ensuring that it can be accessed at runtime with: ulong u_boot_pos = binman_sym(ulong, u_boot_spl, pos); This assigns the variable u_boot_pos to the position of SPL in the image. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-11-14 01:55:01 +00:00
#define binman_sym(_type, _entry_name, _prop_name) BINMAN_SYM_MISSING
#endif /* BINMAN */
#endif