Blame view
common/init/board_init.c
4.09 KB
af6bbd4da
|
1 2 3 4 5 6 7 8 9 10 11 12 |
/* * Code shared between SPL and U-Boot proper * * Copyright (c) 2015 Google, Inc * Written by Simon Glass <sjg@chromium.org> * * SPDX-License-Identifier: GPL-2.0+ */ #include <common.h> DECLARE_GLOBAL_DATA_PTR; |
adc421e4c
|
13 14 |
/* Unfortunately x86 or ARM can't compile this code as gd cannot be assigned */ #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) |
af6bbd4da
|
15 16 17 18 |
__weak void arch_setup_gd(struct global_data *gd_ptr) { gd = gd_ptr; } |
adc421e4c
|
19 |
#endif /* !CONFIG_X86 && !CONFIG_ARM */ |
af6bbd4da
|
20 |
|
ecc306639
|
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/* * Allocate reserved space for use as 'globals' from 'top' address and * return 'bottom' address of allocated space * * Notes: * * Actual reservation cannot be done from within this function as * it requires altering the C stack pointer, so this will be done by * the caller upon return from this function. * * IMPORTANT: * * Alignment constraints may differ for each 'chunk' allocated. For now: * * - GD is aligned down on a 16-byte boundary * * - the early malloc arena is not aligned, therefore it follows the stack * alignment constraint of the architecture for which we are bulding. * * - GD is allocated last, so that the return value of this functions is * both the bottom of the reserved area and the address of GD, should * the calling context need it. */ ulong board_init_f_alloc_reserve(ulong top) { /* Reserve early malloc arena */ |
f1896c45c
|
48 49 |
#if CONFIG_VAL(SYS_MALLOC_F_LEN) top -= CONFIG_VAL(SYS_MALLOC_F_LEN); |
ecc306639
|
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
#endif /* LAST : reserve GD (rounded up to a multiple of 16 bytes) */ top = rounddown(top-sizeof(struct global_data), 16); return top; } /* * Initialize reserved space (which has been safely allocated on the C * stack from the C runtime environment handling code). * * Notes: * * Actual reservation was done by the caller; the locations from base * to base+size-1 (where 'size' is the value returned by the allocation * function above) can be accessed freely without risk of corrupting the * C runtime environment. * * IMPORTANT: * * Upon return from the allocation function above, on some architectures * the caller will set gd to the lowest reserved location. Therefore, in * this initialization function, the global data MUST be placed at base. * * ALSO IMPORTANT: * * On some architectures, gd will already be good when entering this * function. On others, it will only be good once arch_setup_gd() returns. * Therefore, global data accesses must be done: * * - through gd_ptr if before the call to arch_setup_gd(); * * - through gd once arch_setup_gd() has been called. * * Do not use 'gd->' until arch_setup_gd() has been called! * * IMPORTANT TOO: * * Initialization for each "chunk" (GD, early malloc arena...) ends with * an incrementation line of the form 'base += <some size>'. The last of * these incrementations seems useless, as base will not be used any * more after this incrementation; but if/when a new "chunk" is appended, * this increment will be essential as it will give base right value for * this new chunk (which will have to end with its own incrementation * statement). Besides, the compiler's optimizer will silently detect * and remove the last base incrementation, therefore leaving that last * (seemingly useless) incrementation causes no code increase. */ void board_init_f_init_reserve(ulong base) |
af6bbd4da
|
100 101 |
{ struct global_data *gd_ptr; |
ecc306639
|
102 103 104 105 |
/* * clear GD entirely and set it up. * Use gd_ptr, as gd may not be properly set yet. */ |
af6bbd4da
|
106 |
|
ecc306639
|
107 108 |
gd_ptr = (struct global_data *)base; /* zero the area */ |
af6bbd4da
|
109 |
memset(gd_ptr, '\0', sizeof(*gd)); |
ecc306639
|
110 |
/* set GD unless architecture did it already */ |
af7a55514
|
111 |
#if !defined(CONFIG_ARM) |
af6bbd4da
|
112 |
arch_setup_gd(gd_ptr); |
ecc306639
|
113 114 115 116 117 118 119 120 |
#endif /* next alloc will be higher by one GD plus 16-byte alignment */ base += roundup(sizeof(struct global_data), 16); /* * record early malloc arena start. * Use gd as it is now properly set for all architectures. */ |
af6bbd4da
|
121 |
|
f1896c45c
|
122 |
#if CONFIG_VAL(SYS_MALLOC_F_LEN) |
ecc306639
|
123 124 125 |
/* go down one 'early malloc arena' */ gd->malloc_base = base; /* next alloc will be higher by one 'early malloc arena' size */ |
f1896c45c
|
126 |
base += CONFIG_VAL(SYS_MALLOC_F_LEN); |
af6bbd4da
|
127 |
#endif |
af6bbd4da
|
128 |
} |
496c5483e
|
129 130 131 132 133 |
/* * Board-specific Platform code can reimplement show_boot_progress () if needed */ __weak void show_boot_progress(int val) {} |