binman: Support accessing binman tables at run time
[oweals/u-boot.git] / include / binman_sym.h
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_declare_optional() - Declare an optional symbol
42  *
43  * If this symbol cannot be provided by binman, an error will not be generated.
44  * Instead the image will be assigned the value BINMAN_SYM_MISSING.
45  *
46  * @_type: Type f the symbol (e.g. unsigned long)
47  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
48  * @_prop_name: Property value to get from that entry (e.g. 'pos')
49  */
50 #define binman_sym_declare_optional(_type, _entry_name, _prop_name) \
51         _type binman_symname(_entry_name, _prop_name) \
52                 __attribute__((aligned(4), weak, unused, \
53                 section(".binman_sym")))
54
55 /**
56  * binman_sym() - Access a previously declared symbol
57  *
58  * This is used to get the value of a symbol. E.g.:
59  *
60  *    ulong address = binman_sym(ulong, u_boot_spl, pos);
61  *
62  * @_type: Type f the symbol (e.g. unsigned long)
63  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
64  * @_prop_name: Property value to get from that entry (e.g. 'pos')
65  * @returns value of that property (filled in by binman)
66  */
67 #define binman_sym(_type, _entry_name, _prop_name) \
68         (*(_type *)&binman_symname(_entry_name, _prop_name))
69
70 #else /* !BINMAN */
71
72 #define binman_sym_declare(_type, _entry_name, _prop_name)
73
74 #define binman_sym_declare_optional(_type, _entry_name, _prop_name)
75
76 #define binman_sym(_type, _entry_name, _prop_name) BINMAN_SYM_MISSING
77
78 #endif /* BINMAN */
79
80 #endif