binman_sym.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  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
  9. */
  10. #ifndef __BINMAN_SYM_H
  11. #define __BINMAN_SYM_H
  12. #define BINMAN_SYM_MISSING (-1UL)
  13. #ifdef CONFIG_BINMAN
  14. /**
  15. * binman_symname() - Internal function to get a binman symbol name
  16. *
  17. * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
  18. * @_prop_name: Property value to get from that entry (e.g. 'pos')
  19. * @returns name of the symbol for that entry and property
  20. */
  21. #define binman_symname(_entry_name, _prop_name) \
  22. _binman_ ## _entry_name ## _prop_ ## _prop_name
  23. /**
  24. * binman_sym_declare() - Declare a symbol that will be used at run-time
  25. *
  26. * @_type: Type f the symbol (e.g. unsigned long)
  27. * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
  28. * @_prop_name: Property value to get from that entry (e.g. 'pos')
  29. */
  30. #define binman_sym_declare(_type, _entry_name, _prop_name) \
  31. _type binman_symname(_entry_name, _prop_name) \
  32. __attribute__((aligned(4), unused, section(".binman_sym")))
  33. /**
  34. * binman_sym_extern() - Declare a extern symbol that will be used at run-time
  35. *
  36. * @_type: Type f the symbol (e.g. unsigned long)
  37. * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
  38. * @_prop_name: Property value to get from that entry (e.g. 'pos')
  39. */
  40. #define binman_sym_extern(_type, _entry_name, _prop_name) \
  41. extern _type binman_symname(_entry_name, _prop_name) \
  42. __attribute__((aligned(4), unused, section(".binman_sym")))
  43. /**
  44. * binman_sym_declare_optional() - Declare an optional symbol
  45. *
  46. * If this symbol cannot be provided by binman, an error will not be generated.
  47. * Instead the image will be assigned the value BINMAN_SYM_MISSING.
  48. *
  49. * @_type: Type f the symbol (e.g. unsigned long)
  50. * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
  51. * @_prop_name: Property value to get from that entry (e.g. 'pos')
  52. */
  53. #define binman_sym_declare_optional(_type, _entry_name, _prop_name) \
  54. _type binman_symname(_entry_name, _prop_name) \
  55. __attribute__((aligned(4), weak, unused, \
  56. section(".binman_sym")))
  57. /**
  58. * binman_sym() - Access a previously declared symbol
  59. *
  60. * This is used to get the value of a symbol. E.g.:
  61. *
  62. * ulong address = binman_sym(ulong, u_boot_spl, pos);
  63. *
  64. * @_type: Type f the symbol (e.g. unsigned long)
  65. * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl')
  66. * @_prop_name: Property value to get from that entry (e.g. 'pos')
  67. * @returns value of that property (filled in by binman)
  68. */
  69. #define binman_sym(_type, _entry_name, _prop_name) \
  70. (*(_type *)&binman_symname(_entry_name, _prop_name))
  71. #else /* !BINMAN */
  72. #define binman_sym_declare(_type, _entry_name, _prop_name)
  73. #define binman_sym_declare_optional(_type, _entry_name, _prop_name)
  74. #define binman_sym_extern(_type, _entry_name, _prop_name)
  75. #define binman_sym(_type, _entry_name, _prop_name) BINMAN_SYM_MISSING
  76. #endif /* BINMAN */
  77. #endif