xref: /openbmc/u-boot/include/binman_sym.h (revision baefb63a)
1 /*
2  * Symbol access for symbols set up by binman as part of the build.
3  *
4  * This allows C code to access the position of a particular part of the image
5  * assembled by binman.
6  *
7  * Copyright (c) 2017 Google, Inc
8  *
9  * SPDX-License-Identifier:     GPL-2.0+
10  */
11 
12 #ifndef __BINMAN_SYM_H
13 #define __BINMAN_SYM_H
14 
15 #define BINMAN_SYM_MISSING	(-1UL)
16 
17 #ifdef CONFIG_BINMAN
18 
19 /**
20  * binman_symname() - Internal fnuction to get a binman symbol name
21  *
22  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
23  * @_prop_name: Property value to get from that entry (e.g. 'pos')
24  * @returns name of the symbol for that entry and property
25  */
26 #define binman_symname(_entry_name, _prop_name) \
27 	_binman_ ## _entry_name ## _prop_ ## _prop_name
28 
29 /**
30  * binman_sym_declare() - Declare a symbol that will be used at run-time
31  *
32  * @_type: Type f the symbol (e.g. unsigned long)
33  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
34  * @_prop_name: Property value to get from that entry (e.g. 'pos')
35  */
36 #define binman_sym_declare(_type, _entry_name, _prop_name) \
37 	_type binman_symname(_entry_name, _prop_name) \
38 		__attribute__((aligned(4), unused, section(".binman_sym")))
39 
40 /**
41  * binman_sym_extern() - Declare a extern symbol that will be used at run-time
42  *
43  * @_type: Type f the symbol (e.g. unsigned long)
44  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
45  * @_prop_name: Property value to get from that entry (e.g. 'pos')
46  */
47 #define binman_sym_extern(_type, _entry_name, _prop_name) \
48 	extern _type binman_symname(_entry_name, _prop_name) \
49 		__attribute__((aligned(4), unused, section(".binman_sym")))
50 
51 /**
52  * binman_sym_declare_optional() - Declare an optional symbol
53  *
54  * If this symbol cannot be provided by binman, an error will not be generated.
55  * Instead the image will be assigned the value BINMAN_SYM_MISSING.
56  *
57  * @_type: Type f the symbol (e.g. unsigned long)
58  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
59  * @_prop_name: Property value to get from that entry (e.g. 'pos')
60  */
61 #define binman_sym_declare_optional(_type, _entry_name, _prop_name) \
62 	_type binman_symname(_entry_name, _prop_name) \
63 		__attribute__((aligned(4), weak, unused, \
64 		section(".binman_sym")))
65 
66 /**
67  * binman_sym() - Access a previously declared symbol
68  *
69  * This is used to get the value of a symbol. E.g.:
70  *
71  *    ulong address = binman_sym(ulong, u_boot_spl, pos);
72  *
73  * @_type: Type f the symbol (e.g. unsigned long)
74  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
75  * @_prop_name: Property value to get from that entry (e.g. 'pos')
76  * @returns value of that property (filled in by binman)
77  */
78 #define binman_sym(_type, _entry_name, _prop_name) \
79 	(*(_type *)&binman_symname(_entry_name, _prop_name))
80 
81 #else /* !BINMAN */
82 
83 #define binman_sym_declare(_type, _entry_name, _prop_name)
84 
85 #define binman_sym_declare_optional(_type, _entry_name, _prop_name)
86 
87 #define binman_sym_extern(_type, _entry_name, _prop_name)
88 
89 #define binman_sym(_type, _entry_name, _prop_name) BINMAN_SYM_MISSING
90 
91 #endif /* BINMAN */
92 
93 #endif
94