xref: /openbmc/u-boot/include/binman_sym.h (revision e8f80a5a)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
219790632SSimon Glass /*
319790632SSimon Glass  * Symbol access for symbols set up by binman as part of the build.
419790632SSimon Glass  *
519790632SSimon Glass  * This allows C code to access the position of a particular part of the image
619790632SSimon Glass  * assembled by binman.
719790632SSimon Glass  *
819790632SSimon Glass  * Copyright (c) 2017 Google, Inc
919790632SSimon Glass  */
1019790632SSimon Glass 
1119790632SSimon Glass #ifndef __BINMAN_SYM_H
1219790632SSimon Glass #define __BINMAN_SYM_H
1319790632SSimon Glass 
1419790632SSimon Glass #define BINMAN_SYM_MISSING	(-1UL)
1519790632SSimon Glass 
1619790632SSimon Glass #ifdef CONFIG_BINMAN
1719790632SSimon Glass 
1819790632SSimon Glass /**
1919790632SSimon Glass  * binman_symname() - Internal fnuction to get a binman symbol name
2019790632SSimon Glass  *
2119790632SSimon Glass  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
2219790632SSimon Glass  * @_prop_name: Property value to get from that entry (e.g. 'pos')
2319790632SSimon Glass  * @returns name of the symbol for that entry and property
2419790632SSimon Glass  */
2519790632SSimon Glass #define binman_symname(_entry_name, _prop_name) \
2619790632SSimon Glass 	_binman_ ## _entry_name ## _prop_ ## _prop_name
2719790632SSimon Glass 
2819790632SSimon Glass /**
2919790632SSimon Glass  * binman_sym_declare() - Declare a symbol that will be used at run-time
3019790632SSimon Glass  *
3119790632SSimon Glass  * @_type: Type f the symbol (e.g. unsigned long)
3219790632SSimon Glass  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
3319790632SSimon Glass  * @_prop_name: Property value to get from that entry (e.g. 'pos')
3419790632SSimon Glass  */
3519790632SSimon Glass #define binman_sym_declare(_type, _entry_name, _prop_name) \
3619790632SSimon Glass 	_type binman_symname(_entry_name, _prop_name) \
3719790632SSimon Glass 		__attribute__((aligned(4), unused, section(".binman_sym")))
3819790632SSimon Glass 
3919790632SSimon Glass /**
408bee2d25SSimon Glass  * binman_sym_extern() - Declare a extern symbol that will be used at run-time
418bee2d25SSimon Glass  *
428bee2d25SSimon Glass  * @_type: Type f the symbol (e.g. unsigned long)
438bee2d25SSimon Glass  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
448bee2d25SSimon Glass  * @_prop_name: Property value to get from that entry (e.g. 'pos')
458bee2d25SSimon Glass  */
468bee2d25SSimon Glass #define binman_sym_extern(_type, _entry_name, _prop_name) \
478bee2d25SSimon Glass 	extern _type binman_symname(_entry_name, _prop_name) \
488bee2d25SSimon Glass 		__attribute__((aligned(4), unused, section(".binman_sym")))
498bee2d25SSimon Glass 
508bee2d25SSimon Glass /**
5119790632SSimon Glass  * binman_sym_declare_optional() - Declare an optional symbol
5219790632SSimon Glass  *
5319790632SSimon Glass  * If this symbol cannot be provided by binman, an error will not be generated.
5419790632SSimon Glass  * Instead the image will be assigned the value BINMAN_SYM_MISSING.
5519790632SSimon Glass  *
5619790632SSimon Glass  * @_type: Type f the symbol (e.g. unsigned long)
5719790632SSimon Glass  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
5819790632SSimon Glass  * @_prop_name: Property value to get from that entry (e.g. 'pos')
5919790632SSimon Glass  */
6019790632SSimon Glass #define binman_sym_declare_optional(_type, _entry_name, _prop_name) \
6119790632SSimon Glass 	_type binman_symname(_entry_name, _prop_name) \
6219790632SSimon Glass 		__attribute__((aligned(4), weak, unused, \
6319790632SSimon Glass 		section(".binman_sym")))
6419790632SSimon Glass 
6519790632SSimon Glass /**
6619790632SSimon Glass  * binman_sym() - Access a previously declared symbol
6719790632SSimon Glass  *
6819790632SSimon Glass  * This is used to get the value of a symbol. E.g.:
6919790632SSimon Glass  *
7019790632SSimon Glass  *    ulong address = binman_sym(ulong, u_boot_spl, pos);
7119790632SSimon Glass  *
7219790632SSimon Glass  * @_type: Type f the symbol (e.g. unsigned long)
7319790632SSimon Glass  * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
7419790632SSimon Glass  * @_prop_name: Property value to get from that entry (e.g. 'pos')
7519790632SSimon Glass  * @returns value of that property (filled in by binman)
7619790632SSimon Glass  */
7719790632SSimon Glass #define binman_sym(_type, _entry_name, _prop_name) \
7819790632SSimon Glass 	(*(_type *)&binman_symname(_entry_name, _prop_name))
7919790632SSimon Glass 
8019790632SSimon Glass #else /* !BINMAN */
8119790632SSimon Glass 
8219790632SSimon Glass #define binman_sym_declare(_type, _entry_name, _prop_name)
8319790632SSimon Glass 
8419790632SSimon Glass #define binman_sym_declare_optional(_type, _entry_name, _prop_name)
8519790632SSimon Glass 
868bee2d25SSimon Glass #define binman_sym_extern(_type, _entry_name, _prop_name)
878bee2d25SSimon Glass 
8819790632SSimon Glass #define binman_sym(_type, _entry_name, _prop_name) BINMAN_SYM_MISSING
8919790632SSimon Glass 
9019790632SSimon Glass #endif /* BINMAN */
9119790632SSimon Glass 
9219790632SSimon Glass #endif
93