Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Symbol access for symbols set up by binman as part of the build. |
| 4 | * |
| 5 | * This allows C code to access the position of a particular part of the image |
| 6 | * assembled by binman. |
| 7 | * |
| 8 | * Copyright (c) 2017 Google, Inc |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #ifndef __BINMAN_SYM_H |
| 12 | #define __BINMAN_SYM_H |
| 13 | |
| 14 | #define BINMAN_SYM_MISSING (-1UL) |
| 15 | |
| 16 | #ifdef CONFIG_BINMAN |
| 17 | |
| 18 | /** |
Michal Simek | 5594195d | 2020-08-26 15:34:24 +0200 | [diff] [blame] | 19 | * binman_symname() - Internal function to get a binman symbol name |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 20 | * |
| 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 |
| 24 | */ |
| 25 | #define binman_symname(_entry_name, _prop_name) \ |
| 26 | _binman_ ## _entry_name ## _prop_ ## _prop_name |
| 27 | |
| 28 | /** |
| 29 | * binman_sym_declare() - Declare a symbol that will be used at run-time |
| 30 | * |
| 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') |
| 34 | */ |
| 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"))) |
| 38 | |
| 39 | /** |
Simon Glass | 867a398 | 2017-11-13 18:55:03 -0700 | [diff] [blame] | 40 | * binman_sym_extern() - Declare a extern symbol that will be used at run-time |
| 41 | * |
| 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') |
| 45 | */ |
| 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"))) |
| 49 | |
| 50 | /** |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 51 | * binman_sym_declare_optional() - Declare an optional symbol |
| 52 | * |
| 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. |
| 55 | * |
| 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') |
| 59 | */ |
| 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"))) |
| 64 | |
| 65 | /** |
| 66 | * binman_sym() - Access a previously declared symbol |
| 67 | * |
| 68 | * This is used to get the value of a symbol. E.g.: |
| 69 | * |
| 70 | * ulong address = binman_sym(ulong, u_boot_spl, pos); |
| 71 | * |
| 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) |
| 76 | */ |
| 77 | #define binman_sym(_type, _entry_name, _prop_name) \ |
| 78 | (*(_type *)&binman_symname(_entry_name, _prop_name)) |
| 79 | |
| 80 | #else /* !BINMAN */ |
| 81 | |
| 82 | #define binman_sym_declare(_type, _entry_name, _prop_name) |
| 83 | |
| 84 | #define binman_sym_declare_optional(_type, _entry_name, _prop_name) |
| 85 | |
Simon Glass | 867a398 | 2017-11-13 18:55:03 -0700 | [diff] [blame] | 86 | #define binman_sym_extern(_type, _entry_name, _prop_name) |
| 87 | |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 88 | #define binman_sym(_type, _entry_name, _prop_name) BINMAN_SYM_MISSING |
| 89 | |
| 90 | #endif /* BINMAN */ |
| 91 | |
| 92 | #endif |