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 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 7 | #include <bootm.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 8 | #include <bootstage.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 10 | #include <efi_loader.h> |
Maxim Moskalets | e2b258c | 2024-06-21 14:42:10 +0300 | [diff] [blame] | 11 | #include <elf.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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 26 | static int do_bootm_standalone(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 27 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 28 | struct bootm_headers *images = bmi->images; |
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; |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 36 | appl(bmi->argc, bmi->argv); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 67 | static int do_bootm_netbsd(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 68 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 69 | struct bootm_headers *images = bmi->images; |
Simon Glass | bb7d3bb | 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 | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 73 | ulong kernel_data, kernel_len; |
Simon Glass | 3b5866d | 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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 105 | if (bmi->argc > 0) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 106 | ulong len; |
| 107 | int i; |
| 108 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 109 | for (i = 0, len = 0; i < bmi->argc; i += 1) |
| 110 | len += strlen(bmi->argv[i]) + 1; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 111 | cmdline = malloc(len); |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 112 | copy_args(cmdline, bmi->argc, bmi->argv, ' '); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 113 | } else { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 114 | cmdline = env_get("bootargs"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 115 | if (cmdline == NULL) |
| 116 | cmdline = ""; |
| 117 | } |
| 118 | |
Simon Glass | bb7d3bb | 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 | 3b5866d | 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 | 65d94db | 2017-06-07 17:33:09 +0200 | [diff] [blame] | 133 | (*loader)(gd->bd, os_hdr, "", cmdline); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 134 | |
| 135 | return 1; |
| 136 | } |
| 137 | #endif /* CONFIG_BOOTM_NETBSD*/ |
| 138 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 139 | #ifdef CONFIG_BOOTM_RTEMS |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 140 | static int do_bootm_rtems(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 141 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 142 | struct bootm_headers *images = bmi->images; |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 143 | void (*entry_point)(struct bd_info *); |
Simon Glass | 3b5866d | 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 | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 155 | entry_point = (void (*)(struct bd_info *))images->ep; |
Simon Glass | 3b5866d | 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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 173 | static int do_bootm_ose(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 174 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 175 | struct bootm_headers *images = bmi->images; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 206 | static int do_bootm_plan9(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 207 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 208 | struct bootm_headers *images = bmi->images; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 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 | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 223 | s = env_get("confaddr"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 224 | if (s != NULL) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 225 | char *confaddr = (char *)hextoul(s, NULL); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 226 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 227 | if (bmi->argc) { |
| 228 | copy_args(confaddr, bmi->argc, bmi->argv, '\n'); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 229 | } else { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 230 | s = env_get("bootargs"); |
Simon Glass | 3b5866d | 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 | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 256 | static void do_bootvx_fdt(struct bootm_headers *images) |
Simon Glass | 3b5866d | 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; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 263 | |
| 264 | if (*of_flat_tree) { |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 265 | boot_fdt_add_mem_rsv_regions(*of_flat_tree); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 266 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 267 | ret = boot_relocate_fdt(of_flat_tree, &of_size); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 313 | static int do_bootm_vxworks_legacy(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 314 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 315 | struct bootm_headers *images = bmi->images; |
| 316 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 317 | if (flag != BOOTM_STATE_OS_GO) |
| 318 | return 0; |
| 319 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 320 | do_bootvx_fdt(images); |
| 321 | |
| 322 | return 1; |
| 323 | } |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 324 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 325 | int do_bootm_vxworks(int flag, struct bootm_info *bmi) |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 326 | { |
| 327 | char *bootargs; |
| 328 | int pos; |
| 329 | unsigned long vxflags; |
| 330 | bool std_dtb = false; |
| 331 | |
| 332 | /* get bootargs env */ |
| 333 | bootargs = env_get("bootargs"); |
| 334 | |
| 335 | if (bootargs != NULL) { |
| 336 | for (pos = 0; pos < strlen(bootargs); pos++) { |
| 337 | /* find f=0xnumber flag */ |
| 338 | if ((bootargs[pos] == '=') && (pos >= 1) && |
| 339 | (bootargs[pos - 1] == 'f')) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 340 | vxflags = hextoul(&bootargs[pos + 1], NULL); |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 341 | if (vxflags & VXWORKS_SYSFLG_STD_DTB) |
| 342 | std_dtb = true; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | if (std_dtb) { |
| 348 | if (flag & BOOTM_STATE_OS_PREP) |
| 349 | printf(" Using standard DTB\n"); |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 350 | return do_bootm_linux(flag, bmi); |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 351 | } else { |
| 352 | if (flag & BOOTM_STATE_OS_PREP) |
| 353 | printf(" !!! WARNING !!! Using legacy DTB\n"); |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 354 | return do_bootm_vxworks_legacy(flag, bmi); |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 355 | } |
| 356 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 357 | #endif |
| 358 | |
| 359 | #if defined(CONFIG_CMD_ELF) |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 360 | static int do_bootm_qnxelf(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 361 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 362 | struct bootm_headers *images = bmi->images; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 363 | char *local_args[2]; |
| 364 | char str[16]; |
Emmanuel Vadot | 9a922b4 | 2017-01-19 10:23:56 +0100 | [diff] [blame] | 365 | int dcache; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 366 | |
| 367 | if (flag != BOOTM_STATE_OS_GO) |
| 368 | return 0; |
| 369 | |
| 370 | #if defined(CONFIG_FIT) |
| 371 | if (!images->legacy_hdr_valid) { |
| 372 | fit_unsupported_reset("QNX"); |
| 373 | return 1; |
| 374 | } |
| 375 | #endif |
| 376 | |
| 377 | sprintf(str, "%lx", images->ep); /* write entry-point into string */ |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 378 | local_args[0] = bmi->argv[0]; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 379 | local_args[1] = str; /* and provide it via the arguments */ |
Emmanuel Vadot | 9a922b4 | 2017-01-19 10:23:56 +0100 | [diff] [blame] | 380 | |
| 381 | /* |
| 382 | * QNX images require the data cache is disabled. |
| 383 | */ |
| 384 | dcache = dcache_status(); |
| 385 | if (dcache) |
| 386 | dcache_disable(); |
| 387 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 388 | do_bootelf(NULL, 0, 2, local_args); |
| 389 | |
Emmanuel Vadot | 9a922b4 | 2017-01-19 10:23:56 +0100 | [diff] [blame] | 390 | if (dcache) |
| 391 | dcache_enable(); |
| 392 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 393 | return 1; |
| 394 | } |
| 395 | #endif |
| 396 | |
Maxim Moskalets | e2b258c | 2024-06-21 14:42:10 +0300 | [diff] [blame] | 397 | #if defined(CONFIG_BOOTM_ELF) |
| 398 | static int do_bootm_elf(int flag, struct bootm_info *bmi) |
| 399 | { |
| 400 | Bootelf_flags flags = { .autostart = 1 }; |
| 401 | |
| 402 | if (flag != BOOTM_STATE_OS_GO) |
| 403 | return 0; |
| 404 | |
| 405 | bootelf(bmi->images->ep, flags, 0, NULL); |
| 406 | |
| 407 | return 1; |
| 408 | } |
| 409 | #endif |
| 410 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 411 | #ifdef CONFIG_INTEGRITY |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 412 | static int do_bootm_integrity(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 413 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 414 | struct bootm_headers *images = bmi->images; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 415 | void (*entry_point)(void); |
| 416 | |
| 417 | if (flag != BOOTM_STATE_OS_GO) |
| 418 | return 0; |
| 419 | |
| 420 | #if defined(CONFIG_FIT) |
| 421 | if (!images->legacy_hdr_valid) { |
| 422 | fit_unsupported_reset("INTEGRITY"); |
| 423 | return 1; |
| 424 | } |
| 425 | #endif |
| 426 | |
| 427 | entry_point = (void (*)(void))images->ep; |
| 428 | |
| 429 | printf("## Transferring control to INTEGRITY (at address %08lx) ...\n", |
| 430 | (ulong)entry_point); |
| 431 | |
| 432 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 433 | |
| 434 | /* |
| 435 | * INTEGRITY Parameters: |
| 436 | * None |
| 437 | */ |
| 438 | (*entry_point)(); |
| 439 | |
| 440 | return 1; |
| 441 | } |
| 442 | #endif |
| 443 | |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 444 | #ifdef CONFIG_BOOTM_OPENRTOS |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 445 | static int do_bootm_openrtos(int flag, struct bootm_info *bmi) |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 446 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 447 | struct bootm_headers *images = bmi->images; |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 448 | void (*entry_point)(void); |
| 449 | |
| 450 | if (flag != BOOTM_STATE_OS_GO) |
| 451 | return 0; |
| 452 | |
| 453 | entry_point = (void (*)(void))images->ep; |
| 454 | |
| 455 | printf("## Transferring control to OpenRTOS (at address %08lx) ...\n", |
| 456 | (ulong)entry_point); |
| 457 | |
| 458 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 459 | |
| 460 | /* |
| 461 | * OpenRTOS Parameters: |
| 462 | * None |
| 463 | */ |
| 464 | (*entry_point)(); |
| 465 | |
| 466 | return 1; |
| 467 | } |
| 468 | #endif |
| 469 | |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 470 | #ifdef CONFIG_BOOTM_OPTEE |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 471 | static int do_bootm_tee(int flag, struct bootm_info *bmi) |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 472 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 473 | struct bootm_headers *images = bmi->images; |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 474 | int ret; |
| 475 | |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 476 | /* Validate OPTEE header */ |
| 477 | ret = optee_verify_bootm_image(images->os.image_start, |
| 478 | images->os.load, |
| 479 | images->os.image_len); |
| 480 | if (ret) |
| 481 | return ret; |
| 482 | |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 483 | /* From here we can run the regular linux boot path */ |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 484 | return do_bootm_linux(flag, bmi); |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 485 | } |
| 486 | #endif |
| 487 | |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 488 | #ifdef CONFIG_BOOTM_EFI |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 489 | static int do_bootm_efi(int flag, struct bootm_info *bmi) |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 490 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 491 | struct bootm_headers *images = bmi->images; |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 492 | int ret; |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 493 | void *image_buf; |
| 494 | |
| 495 | if (flag != BOOTM_STATE_OS_GO) |
| 496 | return 0; |
| 497 | |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 498 | /* We expect to return */ |
| 499 | images->os.type = IH_TYPE_STANDALONE; |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 500 | |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 501 | image_buf = map_sysmem(images->ep, images->os.image_len); |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 502 | |
| 503 | /* Run EFI image */ |
| 504 | printf("## Transferring control to EFI (at address %08lx) ...\n", |
| 505 | images->ep); |
| 506 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 507 | |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 508 | ret = efi_binary_run(image_buf, images->os.image_len, |
| 509 | images->ft_len |
| 510 | ? images->ft_addr : EFI_FDT_USE_INTERNAL); |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 511 | |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 512 | return ret; |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 513 | } |
| 514 | #endif |
| 515 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 516 | static boot_os_fn *boot_os[] = { |
| 517 | [IH_OS_U_BOOT] = do_bootm_standalone, |
| 518 | #ifdef CONFIG_BOOTM_LINUX |
| 519 | [IH_OS_LINUX] = do_bootm_linux, |
| 520 | #endif |
| 521 | #ifdef CONFIG_BOOTM_NETBSD |
| 522 | [IH_OS_NETBSD] = do_bootm_netbsd, |
| 523 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 524 | #ifdef CONFIG_BOOTM_RTEMS |
| 525 | [IH_OS_RTEMS] = do_bootm_rtems, |
| 526 | #endif |
| 527 | #if defined(CONFIG_BOOTM_OSE) |
| 528 | [IH_OS_OSE] = do_bootm_ose, |
| 529 | #endif |
| 530 | #if defined(CONFIG_BOOTM_PLAN9) |
| 531 | [IH_OS_PLAN9] = do_bootm_plan9, |
| 532 | #endif |
| 533 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
Bin Meng | e63488f | 2018-12-21 07:13:41 -0800 | [diff] [blame] | 534 | (defined(CONFIG_PPC) || defined(CONFIG_ARM) || defined(CONFIG_RISCV)) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 535 | [IH_OS_VXWORKS] = do_bootm_vxworks, |
| 536 | #endif |
| 537 | #if defined(CONFIG_CMD_ELF) |
| 538 | [IH_OS_QNX] = do_bootm_qnxelf, |
| 539 | #endif |
| 540 | #ifdef CONFIG_INTEGRITY |
| 541 | [IH_OS_INTEGRITY] = do_bootm_integrity, |
| 542 | #endif |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 543 | #ifdef CONFIG_BOOTM_OPENRTOS |
| 544 | [IH_OS_OPENRTOS] = do_bootm_openrtos, |
| 545 | #endif |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 546 | #ifdef CONFIG_BOOTM_OPTEE |
| 547 | [IH_OS_TEE] = do_bootm_tee, |
| 548 | #endif |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 549 | #ifdef CONFIG_BOOTM_EFI |
| 550 | [IH_OS_EFI] = do_bootm_efi, |
| 551 | #endif |
Maxim Moskalets | e2b258c | 2024-06-21 14:42:10 +0300 | [diff] [blame] | 552 | #if defined(CONFIG_BOOTM_ELF) |
| 553 | [IH_OS_ELF] = do_bootm_elf, |
| 554 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 555 | }; |
| 556 | |
| 557 | /* Allow for arch specific config before we boot */ |
Jeroen Hofstee | f7d4a49 | 2014-07-10 23:06:25 +0200 | [diff] [blame] | 558 | __weak void arch_preboot_os(void) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 559 | { |
| 560 | /* please define platform specific arch_preboot_os() */ |
| 561 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 562 | |
Marek Vasut | 5b9fbd9 | 2018-10-04 21:16:31 +0200 | [diff] [blame] | 563 | /* Allow for board specific config before we boot */ |
| 564 | __weak void board_preboot_os(void) |
| 565 | { |
| 566 | /* please define board specific board_preboot_os() */ |
| 567 | } |
| 568 | |
Simon Glass | 454746d | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 569 | int boot_selected_os(int state, struct bootm_info *bmi, boot_os_fn *boot_fn) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 570 | { |
| 571 | arch_preboot_os(); |
Marek Vasut | 5b9fbd9 | 2018-10-04 21:16:31 +0200 | [diff] [blame] | 572 | board_preboot_os(); |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 573 | |
Simon Glass | 454746d | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 574 | boot_fn(state, bmi); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 575 | |
| 576 | /* Stand-alone may return when 'autostart' is 'no' */ |
Simon Glass | 454746d | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 577 | if (bmi->images->os.type == IH_TYPE_STANDALONE || |
Simon Glass | 43cdb79 | 2016-07-03 09:40:35 -0600 | [diff] [blame] | 578 | IS_ENABLED(CONFIG_SANDBOX) || |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 579 | state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */ |
| 580 | return 0; |
| 581 | bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED); |
Lukasz Majewski | 9167e10 | 2016-05-08 08:52:21 +0200 | [diff] [blame] | 582 | debug("\n## Control returned to monitor - resetting...\n"); |
| 583 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 584 | return BOOTM_ERR_RESET; |
| 585 | } |
| 586 | |
| 587 | boot_os_fn *bootm_os_get_boot_func(int os) |
| 588 | { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 589 | return boot_os[os]; |
| 590 | } |