1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Symbol access for symbols set up by binman as part of the build.
5 * This allows C code to access the position of a particular part of the image
8 * Copyright (c) 2017 Google, Inc
11 #ifndef __BINMAN_SYM_H
12 #define __BINMAN_SYM_H
14 /* BSYM in little endian, keep in sync with tools/binman/elf.py */
15 #define BINMAN_SYM_MAGIC_VALUE (0x4d595342UL)
16 #define BINMAN_SYM_MISSING (-1UL)
18 #if CONFIG_IS_ENABLED(BINMAN_SYMBOLS)
21 * binman_symname() - Internal function to get a binman symbol name
23 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
24 * @_prop_name: Property value to get from that entry (e.g. 'pos')
25 * @returns name of the symbol for that entry and property
27 #define binman_symname(_entry_name, _prop_name) \
28 _binman_ ## _entry_name ## _prop_ ## _prop_name
31 * binman_sym_declare() - Declare a symbol that will be used at run-time
33 * @_type: Type f the symbol (e.g. unsigned long)
34 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
35 * @_prop_name: Property value to get from that entry (e.g. 'pos')
37 #define binman_sym_declare(_type, _entry_name, _prop_name) \
38 _type binman_symname(_entry_name, _prop_name) \
39 __attribute__((aligned(4), unused, section(".binman_sym")))
42 * binman_sym_extern() - Declare a extern symbol that will be used at run-time
44 * @_type: Type f the symbol (e.g. unsigned long)
45 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
46 * @_prop_name: Property value to get from that entry (e.g. 'pos')
48 #define binman_sym_extern(_type, _entry_name, _prop_name) \
49 extern _type binman_symname(_entry_name, _prop_name) \
50 __attribute__((aligned(4), unused, section(".binman_sym")))
53 * binman_sym_declare_optional() - Declare an optional symbol
55 * If this symbol cannot be provided by binman, an error will not be generated.
56 * Instead the image will be assigned the value BINMAN_SYM_MISSING.
58 * @_type: Type f the symbol (e.g. unsigned long)
59 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
60 * @_prop_name: Property value to get from that entry (e.g. 'pos')
62 #define binman_sym_declare_optional(_type, _entry_name, _prop_name) \
63 _type binman_symname(_entry_name, _prop_name) \
64 __attribute__((aligned(4), weak, unused, \
65 section(".binman_sym")))
68 * _binman_sym_magic - Internal magic symbol for validity checks
70 * When building images, binman fills in this symbol with the magic
71 * value #defined above. This is used to check at runtime if the
72 * symbol values were filled in and are OK to use.
74 extern ulong _binman_sym_magic;
77 * DECLARE_BINMAN_MAGIC_SYM - Declare the internal magic symbol
79 * This macro declares the _binman_sym_magic symbol so that it exists.
80 * Declaring it here would cause errors during linking due to multiple
81 * definitions of the symbol.
83 #define DECLARE_BINMAN_MAGIC_SYM \
84 ulong _binman_sym_magic \
85 __attribute__((aligned(4), section(".binman_sym")))
88 * BINMAN_SYMS_OK - Check if the symbol values are valid
90 * This macro checks if the magic symbol's value is filled properly,
91 * which indicates that other symbols are OK to use as well.
93 * Return: 1 if binman symbol values are usable, 0 if not
95 #define BINMAN_SYMS_OK \
96 (*(ulong *)&_binman_sym_magic == BINMAN_SYM_MAGIC_VALUE)
99 * binman_sym() - Access a previously declared symbol
101 * This is used to get the value of a symbol. E.g.:
103 * ulong address = binman_sym(ulong, u_boot_spl, pos);
105 * @_type: Type f the symbol (e.g. unsigned long)
106 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
107 * @_prop_name: Property value to get from that entry (e.g. 'pos')
109 * Return: value of that property (filled in by binman), or
110 * BINMAN_SYM_MISSING if the value is unavailable
112 #define binman_sym(_type, _entry_name, _prop_name) \
114 (*(_type *)&binman_symname(_entry_name, _prop_name)) : \
117 #else /* !CONFIG_IS_ENABLED(BINMAN_SYMBOLS) */
119 #define binman_sym_declare(_type, _entry_name, _prop_name)
121 #define binman_sym_declare_optional(_type, _entry_name, _prop_name)
123 #define binman_sym_extern(_type, _entry_name, _prop_name)
125 #define DECLARE_BINMAN_MAGIC_SYM
127 #define BINMAN_SYMS_OK (0)
129 #define binman_sym(_type, _entry_name, _prop_name) BINMAN_SYM_MISSING
131 #endif /* CONFIG_IS_ENABLED(BINMAN_SYMBOLS) */