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