relocate.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2011
  4. * Graeme Russ, <graeme.russ@gmail.com>
  5. */
  6. #ifndef _RELOCATE_H_
  7. #define _RELOCATE_H_
  8. #ifndef USE_HOSTCC
  9. #include <asm/global_data.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. #endif
  12. /**
  13. * copy_uboot_to_ram() - Copy U-Boot to its new relocated position
  14. *
  15. * Return: 0 if OK, -ve on error
  16. */
  17. int copy_uboot_to_ram(void);
  18. /**
  19. * clear_bss() - Clear the BSS (Blocked Start by Symbol) segment
  20. *
  21. * This clears the memory used by global variables
  22. *
  23. * Return: 0 if OK, -ve on error
  24. */
  25. int clear_bss(void);
  26. /**
  27. * do_elf_reloc_fixups() - Fix up ELF relocations in the relocated code
  28. *
  29. * This processes the relocation tables to ensure that the code can run in its
  30. * new location.
  31. *
  32. * Return: 0 if OK, -ve on error
  33. */
  34. int do_elf_reloc_fixups(void);
  35. /**
  36. * manual_reloc() - Manually relocate a pointer if needed
  37. *
  38. * This is a nop in almost all cases, except for the systems with a broken gcc
  39. * which need to manually relocate some things.
  40. *
  41. * @ptr: Pointer to relocate
  42. * Return: new pointer value
  43. */
  44. static inline void *manual_reloc(void *ptr)
  45. {
  46. #ifndef USE_HOSTCC
  47. if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC))
  48. return ptr + gd->reloc_off;
  49. #endif
  50. return ptr;
  51. }
  52. #if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
  53. #define MANUAL_RELOC(ptr) (ptr) = manual_reloc(ptr)
  54. #else
  55. #define MANUAL_RELOC(ptr) (void)(ptr)
  56. #endif
  57. #endif /* _RELOCATE_H_ */