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