Commit 070d00b8dc8453b8c2f12d74551919cf2b124136
1 parent
cb5f97f707
Exists in
v2017.01-smarct4x
and in
30 other branches
dm: spl: Allow device tree/driver model in board_init_f()
Add an spl_init() function that does basic init such that board_init_f() can use simple malloc(), device tree and driver model. Each one is set up only if enabled for SPL. Note: We really should refactor SPL such that there is a single board_init_f() and rename the existing weak board_init_f() functions provided by boards, calling them from the single board_init_f(). Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 3 changed files with 37 additions and 11 deletions Side-by-side Diff
common/spl/spl.c
... | ... | @@ -148,18 +148,12 @@ |
148 | 148 | } |
149 | 149 | #endif |
150 | 150 | |
151 | -void board_init_r(gd_t *dummy1, ulong dummy2) | |
151 | +int spl_init(void) | |
152 | 152 | { |
153 | - u32 boot_device; | |
154 | 153 | int ret; |
155 | 154 | |
156 | - debug(">>spl:board_init_r()\n"); | |
157 | - | |
158 | -#if defined(CONFIG_SYS_SPL_MALLOC_START) | |
159 | - mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START, | |
160 | - CONFIG_SYS_SPL_MALLOC_SIZE); | |
161 | - gd->flags |= GD_FLG_FULL_MALLOC_INIT; | |
162 | -#elif defined(CONFIG_SYS_MALLOC_F_LEN) | |
155 | + debug("spl_init()\n"); | |
156 | +#if defined(CONFIG_SYS_MALLOC_F_LEN) | |
163 | 157 | gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN; |
164 | 158 | gd->malloc_ptr = 0; |
165 | 159 | #endif |
166 | 160 | |
167 | 161 | |
168 | 162 | |
... | ... | @@ -168,17 +162,36 @@ |
168 | 162 | ret = fdtdec_setup(); |
169 | 163 | if (ret) { |
170 | 164 | debug("fdtdec_setup() returned error %d\n", ret); |
171 | - hang(); | |
165 | + return ret; | |
172 | 166 | } |
173 | 167 | } |
174 | 168 | if (IS_ENABLED(CONFIG_SPL_DM)) { |
175 | 169 | ret = dm_init_and_scan(true); |
176 | 170 | if (ret) { |
177 | 171 | debug("dm_init_and_scan() returned error %d\n", ret); |
178 | - hang(); | |
172 | + return ret; | |
179 | 173 | } |
180 | 174 | } |
175 | + gd->flags |= GD_FLG_SPL_INIT; | |
181 | 176 | |
177 | + return 0; | |
178 | +} | |
179 | + | |
180 | +void board_init_r(gd_t *dummy1, ulong dummy2) | |
181 | +{ | |
182 | + u32 boot_device; | |
183 | + | |
184 | + debug(">>spl:board_init_r()\n"); | |
185 | + | |
186 | +#if defined(CONFIG_SYS_SPL_MALLOC_START) | |
187 | + mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START, | |
188 | + CONFIG_SYS_SPL_MALLOC_SIZE); | |
189 | + gd->flags |= GD_FLG_FULL_MALLOC_INIT; | |
190 | +#endif | |
191 | + if (!(gd->flags & GD_FLG_SPL_INIT)) { | |
192 | + if (spl_init()) | |
193 | + hang(); | |
194 | + } | |
182 | 195 | #ifndef CONFIG_PPC |
183 | 196 | /* |
184 | 197 | * timer_init() does not exist on PPC systems. The timer is initialized |
include/asm-generic/global_data.h
... | ... | @@ -116,6 +116,7 @@ |
116 | 116 | #define GD_FLG_ENV_READY 0x00080 /* Env. imported into hash table */ |
117 | 117 | #define GD_FLG_SERIAL_READY 0x00100 /* Pre-reloc serial console ready */ |
118 | 118 | #define GD_FLG_FULL_MALLOC_INIT 0x00200 /* Full malloc() is ready */ |
119 | +#define GD_FLG_SPL_INIT 0x00400 /* spl_init() has been called */ | |
119 | 120 | |
120 | 121 | #endif /* __ASM_GENERIC_GBL_DATA_H */ |
include/spl.h
... | ... | @@ -81,6 +81,18 @@ |
81 | 81 | int spl_load_image_ext(block_dev_desc_t *block_dev, int partition, const char *filename); |
82 | 82 | int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition); |
83 | 83 | |
84 | +/** | |
85 | + * spl_init() - Set up device tree and driver model in SPL if enabled | |
86 | + * | |
87 | + * Call this function in board_init_f() if you want to use device tree and | |
88 | + * driver model early, before board_init_r() is called. This function will | |
89 | + * be called from board_init_r() if not called earlier. | |
90 | + * | |
91 | + * If this is not called, then driver model will be inactive in SPL's | |
92 | + * board_init_f(), and no device tree will be available. | |
93 | + */ | |
94 | +int spl_init(void); | |
95 | + | |
84 | 96 | #ifdef CONFIG_SPL_BOARD_INIT |
85 | 97 | void spl_board_init(void); |
86 | 98 | #endif |