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