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 #define BINMAN_SYM_MISSING (-1UL)
19 * binman_symname() - Internal fnuction to get a binman symbol name
21 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
22 * @_prop_name: Property value to get from that entry (e.g. 'pos')
23 * @returns name of the symbol for that entry and property
25 #define binman_symname(_entry_name, _prop_name) \
26 _binman_ ## _entry_name ## _prop_ ## _prop_name
29 * binman_sym_declare() - Declare a symbol that will be used at run-time
31 * @_type: Type f the symbol (e.g. unsigned long)
32 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
33 * @_prop_name: Property value to get from that entry (e.g. 'pos')
35 #define binman_sym_declare(_type, _entry_name, _prop_name) \
36 _type binman_symname(_entry_name, _prop_name) \
37 __attribute__((aligned(4), unused, section(".binman_sym")))
40 * binman_sym_extern() - Declare a extern symbol that will be used at run-time
42 * @_type: Type f the symbol (e.g. unsigned long)
43 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
44 * @_prop_name: Property value to get from that entry (e.g. 'pos')
46 #define binman_sym_extern(_type, _entry_name, _prop_name) \
47 extern _type binman_symname(_entry_name, _prop_name) \
48 __attribute__((aligned(4), unused, section(".binman_sym")))
51 * binman_sym_declare_optional() - Declare an optional symbol
53 * If this symbol cannot be provided by binman, an error will not be generated.
54 * Instead the image will be assigned the value BINMAN_SYM_MISSING.
56 * @_type: Type f the symbol (e.g. unsigned long)
57 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
58 * @_prop_name: Property value to get from that entry (e.g. 'pos')
60 #define binman_sym_declare_optional(_type, _entry_name, _prop_name) \
61 _type binman_symname(_entry_name, _prop_name) \
62 __attribute__((aligned(4), weak, unused, \
63 section(".binman_sym")))
66 * binman_sym() - Access a previously declared symbol
68 * This is used to get the value of a symbol. E.g.:
70 * ulong address = binman_sym(ulong, u_boot_spl, pos);
72 * @_type: Type f the symbol (e.g. unsigned long)
73 * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
74 * @_prop_name: Property value to get from that entry (e.g. 'pos')
75 * @returns value of that property (filled in by binman)
77 #define binman_sym(_type, _entry_name, _prop_name) \
78 (*(_type *)&binman_symname(_entry_name, _prop_name))
82 #define binman_sym_declare(_type, _entry_name, _prop_name)
84 #define binman_sym_declare_optional(_type, _entry_name, _prop_name)
86 #define binman_sym_extern(_type, _entry_name, _prop_name)
88 #define binman_sym(_type, _entry_name, _prop_name) BINMAN_SYM_MISSING