Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2009 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <bootm.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 9 | #include <bootstage.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 11 | #include <efi_loader.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 12 | #include <env.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 13 | #include <fdt_support.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 14 | #include <image.h> |
| 15 | #include <lmb.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 16 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 18 | #include <linux/libfdt.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 19 | #include <malloc.h> |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 20 | #include <mapmem.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 21 | #include <vxworks.h> |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 22 | #include <tee/optee.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 26 | static int do_bootm_standalone(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 27 | struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 28 | { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 29 | int (*appl)(int, char *const[]); |
| 30 | |
Simon Glass | 46b530a | 2021-10-21 21:08:52 -0600 | [diff] [blame] | 31 | if (!env_get_autostart()) { |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 32 | env_set_hex("filesize", images->os.image_len); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 33 | return 0; |
| 34 | } |
| 35 | appl = (int (*)(int, char * const []))images->ep; |
| 36 | appl(argc, argv); |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | /*******************************************************************/ |
| 41 | /* OS booting routines */ |
| 42 | /*******************************************************************/ |
| 43 | |
| 44 | #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 45 | static void copy_args(char *dest, int argc, char *const argv[], char delim) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 46 | { |
| 47 | int i; |
| 48 | |
| 49 | for (i = 0; i < argc; i++) { |
| 50 | if (i > 0) |
| 51 | *dest++ = delim; |
| 52 | strcpy(dest, argv[i]); |
| 53 | dest += strlen(argv[i]); |
| 54 | } |
| 55 | } |
| 56 | #endif |
| 57 | |
Simon Glass | 4a00af4 | 2021-09-25 19:43:32 -0600 | [diff] [blame] | 58 | static void __maybe_unused fit_unsupported_reset(const char *msg) |
| 59 | { |
| 60 | if (CONFIG_IS_ENABLED(FIT_VERBOSE)) { |
| 61 | printf("! FIT images not supported for '%s' - must reset board to recover!\n", |
| 62 | msg); |
| 63 | } |
| 64 | } |
| 65 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 66 | #ifdef CONFIG_BOOTM_NETBSD |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 67 | static int do_bootm_netbsd(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 68 | struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 69 | { |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 70 | void (*loader)(struct bd_info *, image_header_t *, char *, char *); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 71 | image_header_t *os_hdr, *hdr; |
| 72 | ulong kernel_data, kernel_len; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 73 | char *cmdline; |
| 74 | |
| 75 | if (flag != BOOTM_STATE_OS_GO) |
| 76 | return 0; |
| 77 | |
| 78 | #if defined(CONFIG_FIT) |
| 79 | if (!images->legacy_hdr_valid) { |
| 80 | fit_unsupported_reset("NetBSD"); |
| 81 | return 1; |
| 82 | } |
| 83 | #endif |
| 84 | hdr = images->legacy_hdr_os; |
| 85 | |
| 86 | /* |
| 87 | * Booting a (NetBSD) kernel image |
| 88 | * |
| 89 | * This process is pretty similar to a standalone application: |
| 90 | * The (first part of an multi-) image must be a stage-2 loader, |
| 91 | * which in turn is responsible for loading & invoking the actual |
| 92 | * kernel. The only differences are the parameters being passed: |
| 93 | * besides the board info strucure, the loader expects a command |
| 94 | * line, the name of the console device, and (optionally) the |
| 95 | * address of the original image header. |
| 96 | */ |
| 97 | os_hdr = NULL; |
| 98 | if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { |
| 99 | image_multi_getimg(hdr, 1, &kernel_data, &kernel_len); |
| 100 | if (kernel_len) |
| 101 | os_hdr = hdr; |
| 102 | } |
| 103 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 104 | if (argc > 0) { |
| 105 | ulong len; |
| 106 | int i; |
| 107 | |
| 108 | for (i = 0, len = 0; i < argc; i += 1) |
| 109 | len += strlen(argv[i]) + 1; |
| 110 | cmdline = malloc(len); |
| 111 | copy_args(cmdline, argc, argv, ' '); |
| 112 | } else { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 113 | cmdline = env_get("bootargs"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 114 | if (cmdline == NULL) |
| 115 | cmdline = ""; |
| 116 | } |
| 117 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 118 | loader = (void (*)(struct bd_info *, image_header_t *, char *, char *))images->ep; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 119 | |
| 120 | printf("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", |
| 121 | (ulong)loader); |
| 122 | |
| 123 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 124 | |
| 125 | /* |
| 126 | * NetBSD Stage-2 Loader Parameters: |
| 127 | * arg[0]: pointer to board info data |
| 128 | * arg[1]: image load address |
| 129 | * arg[2]: char pointer to the console device to use |
| 130 | * arg[3]: char pointer to the boot arguments |
| 131 | */ |
Heiko Schocher | 65d94db | 2017-06-07 17:33:09 +0200 | [diff] [blame] | 132 | (*loader)(gd->bd, os_hdr, "", cmdline); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 133 | |
| 134 | return 1; |
| 135 | } |
| 136 | #endif /* CONFIG_BOOTM_NETBSD*/ |
| 137 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 138 | #ifdef CONFIG_BOOTM_RTEMS |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 139 | static int do_bootm_rtems(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 140 | struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 141 | { |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 142 | void (*entry_point)(struct bd_info *); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 143 | |
| 144 | if (flag != BOOTM_STATE_OS_GO) |
| 145 | return 0; |
| 146 | |
| 147 | #if defined(CONFIG_FIT) |
| 148 | if (!images->legacy_hdr_valid) { |
| 149 | fit_unsupported_reset("RTEMS"); |
| 150 | return 1; |
| 151 | } |
| 152 | #endif |
| 153 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 154 | entry_point = (void (*)(struct bd_info *))images->ep; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 155 | |
| 156 | printf("## Transferring control to RTEMS (at address %08lx) ...\n", |
| 157 | (ulong)entry_point); |
| 158 | |
| 159 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 160 | |
| 161 | /* |
| 162 | * RTEMS Parameters: |
| 163 | * r3: ptr to board info data |
| 164 | */ |
| 165 | (*entry_point)(gd->bd); |
| 166 | |
| 167 | return 1; |
| 168 | } |
| 169 | #endif /* CONFIG_BOOTM_RTEMS */ |
| 170 | |
| 171 | #if defined(CONFIG_BOOTM_OSE) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 172 | static int do_bootm_ose(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 173 | struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 174 | { |
| 175 | void (*entry_point)(void); |
| 176 | |
| 177 | if (flag != BOOTM_STATE_OS_GO) |
| 178 | return 0; |
| 179 | |
| 180 | #if defined(CONFIG_FIT) |
| 181 | if (!images->legacy_hdr_valid) { |
| 182 | fit_unsupported_reset("OSE"); |
| 183 | return 1; |
| 184 | } |
| 185 | #endif |
| 186 | |
| 187 | entry_point = (void (*)(void))images->ep; |
| 188 | |
| 189 | printf("## Transferring control to OSE (at address %08lx) ...\n", |
| 190 | (ulong)entry_point); |
| 191 | |
| 192 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 193 | |
| 194 | /* |
| 195 | * OSE Parameters: |
| 196 | * None |
| 197 | */ |
| 198 | (*entry_point)(); |
| 199 | |
| 200 | return 1; |
| 201 | } |
| 202 | #endif /* CONFIG_BOOTM_OSE */ |
| 203 | |
| 204 | #if defined(CONFIG_BOOTM_PLAN9) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 205 | static int do_bootm_plan9(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 206 | struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 207 | { |
| 208 | void (*entry_point)(void); |
| 209 | char *s; |
| 210 | |
| 211 | if (flag != BOOTM_STATE_OS_GO) |
| 212 | return 0; |
| 213 | |
| 214 | #if defined(CONFIG_FIT) |
| 215 | if (!images->legacy_hdr_valid) { |
| 216 | fit_unsupported_reset("Plan 9"); |
| 217 | return 1; |
| 218 | } |
| 219 | #endif |
| 220 | |
| 221 | /* See README.plan9 */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 222 | s = env_get("confaddr"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 223 | if (s != NULL) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 224 | char *confaddr = (char *)hextoul(s, NULL); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 225 | |
| 226 | if (argc > 0) { |
| 227 | copy_args(confaddr, argc, argv, '\n'); |
| 228 | } else { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 229 | s = env_get("bootargs"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 230 | if (s != NULL) |
| 231 | strcpy(confaddr, s); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | entry_point = (void (*)(void))images->ep; |
| 236 | |
| 237 | printf("## Transferring control to Plan 9 (at address %08lx) ...\n", |
| 238 | (ulong)entry_point); |
| 239 | |
| 240 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 241 | |
| 242 | /* |
| 243 | * Plan 9 Parameters: |
| 244 | * None |
| 245 | */ |
| 246 | (*entry_point)(); |
| 247 | |
| 248 | return 1; |
| 249 | } |
| 250 | #endif /* CONFIG_BOOTM_PLAN9 */ |
| 251 | |
| 252 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
| 253 | (defined(CONFIG_PPC) || defined(CONFIG_ARM)) |
| 254 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 255 | static void do_bootvx_fdt(struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 256 | { |
| 257 | #if defined(CONFIG_OF_LIBFDT) |
| 258 | int ret; |
| 259 | char *bootline; |
| 260 | ulong of_size = images->ft_len; |
| 261 | char **of_flat_tree = &images->ft_addr; |
| 262 | struct lmb *lmb = &images->lmb; |
| 263 | |
| 264 | if (*of_flat_tree) { |
| 265 | boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree); |
| 266 | |
| 267 | ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size); |
| 268 | if (ret) |
| 269 | return; |
| 270 | |
Hannes Schmelzer | 51962ee | 2017-08-25 14:27:37 +0200 | [diff] [blame] | 271 | /* Update ethernet nodes */ |
| 272 | fdt_fixup_ethernet(*of_flat_tree); |
| 273 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 274 | ret = fdt_add_subnode(*of_flat_tree, 0, "chosen"); |
| 275 | if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 276 | bootline = env_get("bootargs"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 277 | if (bootline) { |
| 278 | ret = fdt_find_and_setprop(*of_flat_tree, |
| 279 | "/chosen", "bootargs", |
| 280 | bootline, |
| 281 | strlen(bootline) + 1, 1); |
| 282 | if (ret < 0) { |
| 283 | printf("## ERROR: %s : %s\n", __func__, |
| 284 | fdt_strerror(ret)); |
| 285 | return; |
| 286 | } |
| 287 | } |
| 288 | } else { |
| 289 | printf("## ERROR: %s : %s\n", __func__, |
| 290 | fdt_strerror(ret)); |
| 291 | return; |
| 292 | } |
| 293 | } |
| 294 | #endif |
| 295 | |
| 296 | boot_prep_vxworks(images); |
| 297 | |
| 298 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 299 | |
| 300 | #if defined(CONFIG_OF_LIBFDT) |
| 301 | printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n", |
| 302 | (ulong)images->ep, (ulong)*of_flat_tree); |
| 303 | #else |
| 304 | printf("## Starting vxWorks at 0x%08lx\n", (ulong)images->ep); |
| 305 | #endif |
Pali Rohár | 937b7d8 | 2022-09-05 11:31:21 +0200 | [diff] [blame] | 306 | flush(); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 307 | |
| 308 | boot_jump_vxworks(images); |
| 309 | |
| 310 | puts("## vxWorks terminated\n"); |
| 311 | } |
| 312 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 313 | static int do_bootm_vxworks_legacy(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 314 | struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 315 | { |
| 316 | if (flag != BOOTM_STATE_OS_GO) |
| 317 | return 0; |
| 318 | |
| 319 | #if defined(CONFIG_FIT) |
| 320 | if (!images->legacy_hdr_valid) { |
| 321 | fit_unsupported_reset("VxWorks"); |
| 322 | return 1; |
| 323 | } |
| 324 | #endif |
| 325 | |
| 326 | do_bootvx_fdt(images); |
| 327 | |
| 328 | return 1; |
| 329 | } |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 330 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 331 | int do_bootm_vxworks(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 332 | struct bootm_headers *images) |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 333 | { |
| 334 | char *bootargs; |
| 335 | int pos; |
| 336 | unsigned long vxflags; |
| 337 | bool std_dtb = false; |
| 338 | |
| 339 | /* get bootargs env */ |
| 340 | bootargs = env_get("bootargs"); |
| 341 | |
| 342 | if (bootargs != NULL) { |
| 343 | for (pos = 0; pos < strlen(bootargs); pos++) { |
| 344 | /* find f=0xnumber flag */ |
| 345 | if ((bootargs[pos] == '=') && (pos >= 1) && |
| 346 | (bootargs[pos - 1] == 'f')) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 347 | vxflags = hextoul(&bootargs[pos + 1], NULL); |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 348 | if (vxflags & VXWORKS_SYSFLG_STD_DTB) |
| 349 | std_dtb = true; |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | if (std_dtb) { |
| 355 | if (flag & BOOTM_STATE_OS_PREP) |
| 356 | printf(" Using standard DTB\n"); |
| 357 | return do_bootm_linux(flag, argc, argv, images); |
| 358 | } else { |
| 359 | if (flag & BOOTM_STATE_OS_PREP) |
| 360 | printf(" !!! WARNING !!! Using legacy DTB\n"); |
| 361 | return do_bootm_vxworks_legacy(flag, argc, argv, images); |
| 362 | } |
| 363 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 364 | #endif |
| 365 | |
| 366 | #if defined(CONFIG_CMD_ELF) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 367 | static int do_bootm_qnxelf(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 368 | struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 369 | { |
| 370 | char *local_args[2]; |
| 371 | char str[16]; |
Emmanuel Vadot | 9a922b4 | 2017-01-19 10:23:56 +0100 | [diff] [blame] | 372 | int dcache; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 373 | |
| 374 | if (flag != BOOTM_STATE_OS_GO) |
| 375 | return 0; |
| 376 | |
| 377 | #if defined(CONFIG_FIT) |
| 378 | if (!images->legacy_hdr_valid) { |
| 379 | fit_unsupported_reset("QNX"); |
| 380 | return 1; |
| 381 | } |
| 382 | #endif |
| 383 | |
| 384 | sprintf(str, "%lx", images->ep); /* write entry-point into string */ |
| 385 | local_args[0] = argv[0]; |
| 386 | local_args[1] = str; /* and provide it via the arguments */ |
Emmanuel Vadot | 9a922b4 | 2017-01-19 10:23:56 +0100 | [diff] [blame] | 387 | |
| 388 | /* |
| 389 | * QNX images require the data cache is disabled. |
| 390 | */ |
| 391 | dcache = dcache_status(); |
| 392 | if (dcache) |
| 393 | dcache_disable(); |
| 394 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 395 | do_bootelf(NULL, 0, 2, local_args); |
| 396 | |
Emmanuel Vadot | 9a922b4 | 2017-01-19 10:23:56 +0100 | [diff] [blame] | 397 | if (dcache) |
| 398 | dcache_enable(); |
| 399 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 400 | return 1; |
| 401 | } |
| 402 | #endif |
| 403 | |
| 404 | #ifdef CONFIG_INTEGRITY |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 405 | static int do_bootm_integrity(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 406 | struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 407 | { |
| 408 | void (*entry_point)(void); |
| 409 | |
| 410 | if (flag != BOOTM_STATE_OS_GO) |
| 411 | return 0; |
| 412 | |
| 413 | #if defined(CONFIG_FIT) |
| 414 | if (!images->legacy_hdr_valid) { |
| 415 | fit_unsupported_reset("INTEGRITY"); |
| 416 | return 1; |
| 417 | } |
| 418 | #endif |
| 419 | |
| 420 | entry_point = (void (*)(void))images->ep; |
| 421 | |
| 422 | printf("## Transferring control to INTEGRITY (at address %08lx) ...\n", |
| 423 | (ulong)entry_point); |
| 424 | |
| 425 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 426 | |
| 427 | /* |
| 428 | * INTEGRITY Parameters: |
| 429 | * None |
| 430 | */ |
| 431 | (*entry_point)(); |
| 432 | |
| 433 | return 1; |
| 434 | } |
| 435 | #endif |
| 436 | |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 437 | #ifdef CONFIG_BOOTM_OPENRTOS |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 438 | static int do_bootm_openrtos(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 439 | struct bootm_headers *images) |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 440 | { |
| 441 | void (*entry_point)(void); |
| 442 | |
| 443 | if (flag != BOOTM_STATE_OS_GO) |
| 444 | return 0; |
| 445 | |
| 446 | entry_point = (void (*)(void))images->ep; |
| 447 | |
| 448 | printf("## Transferring control to OpenRTOS (at address %08lx) ...\n", |
| 449 | (ulong)entry_point); |
| 450 | |
| 451 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 452 | |
| 453 | /* |
| 454 | * OpenRTOS Parameters: |
| 455 | * None |
| 456 | */ |
| 457 | (*entry_point)(); |
| 458 | |
| 459 | return 1; |
| 460 | } |
| 461 | #endif |
| 462 | |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 463 | #ifdef CONFIG_BOOTM_OPTEE |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 464 | static int do_bootm_tee(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 465 | struct bootm_headers *images) |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 466 | { |
| 467 | int ret; |
| 468 | |
| 469 | /* Verify OS type */ |
| 470 | if (images->os.os != IH_OS_TEE) { |
| 471 | return 1; |
| 472 | }; |
| 473 | |
| 474 | /* Validate OPTEE header */ |
| 475 | ret = optee_verify_bootm_image(images->os.image_start, |
| 476 | images->os.load, |
| 477 | images->os.image_len); |
| 478 | if (ret) |
| 479 | return ret; |
| 480 | |
| 481 | /* Locate FDT etc */ |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 482 | ret = bootm_find_images(flag, argc, argv, 0, 0); |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 483 | if (ret) |
| 484 | return ret; |
| 485 | |
| 486 | /* From here we can run the regular linux boot path */ |
| 487 | return do_bootm_linux(flag, argc, argv, images); |
| 488 | } |
| 489 | #endif |
| 490 | |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 491 | #ifdef CONFIG_BOOTM_EFI |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 492 | static int do_bootm_efi(int flag, int argc, char *const argv[], |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 493 | struct bootm_headers *images) |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 494 | { |
| 495 | int ret; |
| 496 | efi_status_t efi_ret; |
| 497 | void *image_buf; |
| 498 | |
| 499 | if (flag != BOOTM_STATE_OS_GO) |
| 500 | return 0; |
| 501 | |
| 502 | /* Locate FDT, if provided */ |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 503 | ret = bootm_find_images(flag, argc, argv, 0, 0); |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 504 | if (ret) |
| 505 | return ret; |
| 506 | |
| 507 | /* Initialize EFI drivers */ |
| 508 | efi_ret = efi_init_obj_list(); |
| 509 | if (efi_ret != EFI_SUCCESS) { |
| 510 | printf("## Failed to initialize UEFI sub-system: r = %lu\n", |
| 511 | efi_ret & ~EFI_ERROR_MASK); |
| 512 | return 1; |
| 513 | } |
| 514 | |
| 515 | /* Install device tree */ |
| 516 | efi_ret = efi_install_fdt(images->ft_len |
| 517 | ? images->ft_addr : EFI_FDT_USE_INTERNAL); |
| 518 | if (efi_ret != EFI_SUCCESS) { |
| 519 | printf("## Failed to install device tree: r = %lu\n", |
| 520 | efi_ret & ~EFI_ERROR_MASK); |
| 521 | return 1; |
| 522 | } |
| 523 | |
| 524 | /* Run EFI image */ |
| 525 | printf("## Transferring control to EFI (at address %08lx) ...\n", |
| 526 | images->ep); |
| 527 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 528 | |
Heinrich Schuchardt | c663fa4 | 2020-07-18 10:54:26 +0200 | [diff] [blame] | 529 | /* We expect to return */ |
| 530 | images->os.type = IH_TYPE_STANDALONE; |
| 531 | |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 532 | image_buf = map_sysmem(images->ep, images->os.image_len); |
| 533 | |
| 534 | efi_ret = efi_run_image(image_buf, images->os.image_len); |
Heinrich Schuchardt | c663fa4 | 2020-07-18 10:54:26 +0200 | [diff] [blame] | 535 | if (efi_ret != EFI_SUCCESS) |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 536 | return 1; |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 537 | return 0; |
| 538 | } |
| 539 | #endif |
| 540 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 541 | static boot_os_fn *boot_os[] = { |
| 542 | [IH_OS_U_BOOT] = do_bootm_standalone, |
| 543 | #ifdef CONFIG_BOOTM_LINUX |
| 544 | [IH_OS_LINUX] = do_bootm_linux, |
| 545 | #endif |
| 546 | #ifdef CONFIG_BOOTM_NETBSD |
| 547 | [IH_OS_NETBSD] = do_bootm_netbsd, |
| 548 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 549 | #ifdef CONFIG_BOOTM_RTEMS |
| 550 | [IH_OS_RTEMS] = do_bootm_rtems, |
| 551 | #endif |
| 552 | #if defined(CONFIG_BOOTM_OSE) |
| 553 | [IH_OS_OSE] = do_bootm_ose, |
| 554 | #endif |
| 555 | #if defined(CONFIG_BOOTM_PLAN9) |
| 556 | [IH_OS_PLAN9] = do_bootm_plan9, |
| 557 | #endif |
| 558 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
Bin Meng | e63488f | 2018-12-21 07:13:41 -0800 | [diff] [blame] | 559 | (defined(CONFIG_PPC) || defined(CONFIG_ARM) || defined(CONFIG_RISCV)) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 560 | [IH_OS_VXWORKS] = do_bootm_vxworks, |
| 561 | #endif |
| 562 | #if defined(CONFIG_CMD_ELF) |
| 563 | [IH_OS_QNX] = do_bootm_qnxelf, |
| 564 | #endif |
| 565 | #ifdef CONFIG_INTEGRITY |
| 566 | [IH_OS_INTEGRITY] = do_bootm_integrity, |
| 567 | #endif |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 568 | #ifdef CONFIG_BOOTM_OPENRTOS |
| 569 | [IH_OS_OPENRTOS] = do_bootm_openrtos, |
| 570 | #endif |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 571 | #ifdef CONFIG_BOOTM_OPTEE |
| 572 | [IH_OS_TEE] = do_bootm_tee, |
| 573 | #endif |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 574 | #ifdef CONFIG_BOOTM_EFI |
| 575 | [IH_OS_EFI] = do_bootm_efi, |
| 576 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 577 | }; |
| 578 | |
| 579 | /* Allow for arch specific config before we boot */ |
Jeroen Hofstee | f7d4a49 | 2014-07-10 23:06:25 +0200 | [diff] [blame] | 580 | __weak void arch_preboot_os(void) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 581 | { |
| 582 | /* please define platform specific arch_preboot_os() */ |
| 583 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 584 | |
Marek Vasut | 5b9fbd9 | 2018-10-04 21:16:31 +0200 | [diff] [blame] | 585 | /* Allow for board specific config before we boot */ |
| 586 | __weak void board_preboot_os(void) |
| 587 | { |
| 588 | /* please define board specific board_preboot_os() */ |
| 589 | } |
| 590 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 591 | int boot_selected_os(int argc, char *const argv[], int state, |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame^] | 592 | struct bootm_headers *images, boot_os_fn *boot_fn) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 593 | { |
| 594 | arch_preboot_os(); |
Marek Vasut | 5b9fbd9 | 2018-10-04 21:16:31 +0200 | [diff] [blame] | 595 | board_preboot_os(); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 596 | boot_fn(state, argc, argv, images); |
| 597 | |
| 598 | /* Stand-alone may return when 'autostart' is 'no' */ |
| 599 | if (images->os.type == IH_TYPE_STANDALONE || |
Simon Glass | 43cdb79 | 2016-07-03 09:40:35 -0600 | [diff] [blame] | 600 | IS_ENABLED(CONFIG_SANDBOX) || |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 601 | state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */ |
| 602 | return 0; |
| 603 | bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED); |
Lukasz Majewski | 9167e10 | 2016-05-08 08:52:21 +0200 | [diff] [blame] | 604 | debug("\n## Control returned to monitor - resetting...\n"); |
| 605 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 606 | return BOOTM_ERR_RESET; |
| 607 | } |
| 608 | |
| 609 | boot_os_fn *bootm_os_get_boot_func(int os) |
| 610 | { |
| 611 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
| 612 | static bool relocated; |
| 613 | |
| 614 | if (!relocated) { |
| 615 | int i; |
| 616 | |
| 617 | /* relocate boot function table */ |
| 618 | for (i = 0; i < ARRAY_SIZE(boot_os); i++) |
| 619 | if (boot_os[i] != NULL) |
| 620 | boot_os[i] += gd->reloc_off; |
| 621 | |
| 622 | relocated = true; |
| 623 | } |
| 624 | #endif |
| 625 | return boot_os[os]; |
| 626 | } |