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> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 11 | #include <env.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 12 | #include <fdt_support.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 13 | #include <image.h> |
| 14 | #include <lmb.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 17 | #include <linux/libfdt.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 18 | #include <malloc.h> |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 19 | #include <mapmem.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 20 | #include <vxworks.h> |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 21 | #include <tee/optee.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 25 | static int do_bootm_standalone(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 26 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 27 | struct bootm_headers *images = bmi->images; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 28 | int (*appl)(int, char *const[]); |
| 29 | |
Simon Glass | 46b530a | 2021-10-21 21:08:52 -0600 | [diff] [blame] | 30 | if (!env_get_autostart()) { |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 31 | env_set_hex("filesize", images->os.image_len); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 32 | return 0; |
| 33 | } |
| 34 | appl = (int (*)(int, char * const []))images->ep; |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 35 | appl(bmi->argc, bmi->argv); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | /*******************************************************************/ |
| 40 | /* OS booting routines */ |
| 41 | /*******************************************************************/ |
| 42 | |
| 43 | #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 44 | 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] | 45 | { |
| 46 | int i; |
| 47 | |
| 48 | for (i = 0; i < argc; i++) { |
| 49 | if (i > 0) |
| 50 | *dest++ = delim; |
| 51 | strcpy(dest, argv[i]); |
| 52 | dest += strlen(argv[i]); |
| 53 | } |
| 54 | } |
| 55 | #endif |
| 56 | |
Simon Glass | 4a00af4 | 2021-09-25 19:43:32 -0600 | [diff] [blame] | 57 | static void __maybe_unused fit_unsupported_reset(const char *msg) |
| 58 | { |
| 59 | if (CONFIG_IS_ENABLED(FIT_VERBOSE)) { |
| 60 | printf("! FIT images not supported for '%s' - must reset board to recover!\n", |
| 61 | msg); |
| 62 | } |
| 63 | } |
| 64 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 65 | #ifdef CONFIG_BOOTM_NETBSD |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 66 | static int do_bootm_netbsd(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 67 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 68 | struct bootm_headers *images = bmi->images; |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 69 | void (*loader)(struct bd_info *bd, struct legacy_img_hdr *hdr, |
| 70 | char *console, char *cmdline); |
| 71 | struct legacy_img_hdr *os_hdr, *hdr; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 104 | if (bmi->argc > 0) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 105 | ulong len; |
| 106 | int i; |
| 107 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 108 | for (i = 0, len = 0; i < bmi->argc; i += 1) |
| 109 | len += strlen(bmi->argv[i]) + 1; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 110 | cmdline = malloc(len); |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 111 | copy_args(cmdline, bmi->argc, bmi->argv, ' '); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 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 | |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 118 | 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] | 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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 139 | static int do_bootm_rtems(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 140 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 141 | struct bootm_headers *images = bmi->images; |
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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 172 | static int do_bootm_ose(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 173 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 174 | struct bootm_headers *images = bmi->images; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 205 | static int do_bootm_plan9(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 206 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 207 | struct bootm_headers *images = bmi->images; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 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 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 226 | if (bmi->argc) { |
| 227 | copy_args(confaddr, bmi->argc, bmi->argv, '\n'); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 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 | 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 | |
| 397 | #ifdef CONFIG_INTEGRITY |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 398 | static int do_bootm_integrity(int flag, struct bootm_info *bmi) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 399 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 400 | struct bootm_headers *images = bmi->images; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 401 | void (*entry_point)(void); |
| 402 | |
| 403 | if (flag != BOOTM_STATE_OS_GO) |
| 404 | return 0; |
| 405 | |
| 406 | #if defined(CONFIG_FIT) |
| 407 | if (!images->legacy_hdr_valid) { |
| 408 | fit_unsupported_reset("INTEGRITY"); |
| 409 | return 1; |
| 410 | } |
| 411 | #endif |
| 412 | |
| 413 | entry_point = (void (*)(void))images->ep; |
| 414 | |
| 415 | printf("## Transferring control to INTEGRITY (at address %08lx) ...\n", |
| 416 | (ulong)entry_point); |
| 417 | |
| 418 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 419 | |
| 420 | /* |
| 421 | * INTEGRITY Parameters: |
| 422 | * None |
| 423 | */ |
| 424 | (*entry_point)(); |
| 425 | |
| 426 | return 1; |
| 427 | } |
| 428 | #endif |
| 429 | |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 430 | #ifdef CONFIG_BOOTM_OPENRTOS |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 431 | static int do_bootm_openrtos(int flag, struct bootm_info *bmi) |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 432 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 433 | struct bootm_headers *images = bmi->images; |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 434 | void (*entry_point)(void); |
| 435 | |
| 436 | if (flag != BOOTM_STATE_OS_GO) |
| 437 | return 0; |
| 438 | |
| 439 | entry_point = (void (*)(void))images->ep; |
| 440 | |
| 441 | printf("## Transferring control to OpenRTOS (at address %08lx) ...\n", |
| 442 | (ulong)entry_point); |
| 443 | |
| 444 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 445 | |
| 446 | /* |
| 447 | * OpenRTOS Parameters: |
| 448 | * None |
| 449 | */ |
| 450 | (*entry_point)(); |
| 451 | |
| 452 | return 1; |
| 453 | } |
| 454 | #endif |
| 455 | |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 456 | #ifdef CONFIG_BOOTM_OPTEE |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 457 | static int do_bootm_tee(int flag, struct bootm_info *bmi) |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 458 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 459 | struct bootm_headers *images = bmi->images; |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 460 | int ret; |
| 461 | |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 462 | /* Validate OPTEE header */ |
| 463 | ret = optee_verify_bootm_image(images->os.image_start, |
| 464 | images->os.load, |
| 465 | images->os.image_len); |
| 466 | if (ret) |
| 467 | return ret; |
| 468 | |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 469 | /* From here we can run the regular linux boot path */ |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 470 | return do_bootm_linux(flag, bmi); |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 471 | } |
| 472 | #endif |
| 473 | |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 474 | #ifdef CONFIG_BOOTM_EFI |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 475 | static int do_bootm_efi(int flag, struct bootm_info *bmi) |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 476 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 477 | struct bootm_headers *images = bmi->images; |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 478 | int ret; |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 479 | void *image_buf; |
| 480 | |
| 481 | if (flag != BOOTM_STATE_OS_GO) |
| 482 | return 0; |
| 483 | |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 484 | /* We expect to return */ |
| 485 | images->os.type = IH_TYPE_STANDALONE; |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 486 | |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 487 | image_buf = map_sysmem(images->ep, images->os.image_len); |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 488 | |
| 489 | /* Run EFI image */ |
| 490 | printf("## Transferring control to EFI (at address %08lx) ...\n", |
| 491 | images->ep); |
| 492 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 493 | |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 494 | ret = efi_binary_run(image_buf, images->os.image_len, |
| 495 | images->ft_len |
| 496 | ? images->ft_addr : EFI_FDT_USE_INTERNAL); |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 497 | |
AKASHI Takahiro | 9f097bc | 2023-11-21 10:29:46 +0900 | [diff] [blame] | 498 | return ret; |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 499 | } |
| 500 | #endif |
| 501 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 502 | static boot_os_fn *boot_os[] = { |
| 503 | [IH_OS_U_BOOT] = do_bootm_standalone, |
| 504 | #ifdef CONFIG_BOOTM_LINUX |
| 505 | [IH_OS_LINUX] = do_bootm_linux, |
| 506 | #endif |
| 507 | #ifdef CONFIG_BOOTM_NETBSD |
| 508 | [IH_OS_NETBSD] = do_bootm_netbsd, |
| 509 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 510 | #ifdef CONFIG_BOOTM_RTEMS |
| 511 | [IH_OS_RTEMS] = do_bootm_rtems, |
| 512 | #endif |
| 513 | #if defined(CONFIG_BOOTM_OSE) |
| 514 | [IH_OS_OSE] = do_bootm_ose, |
| 515 | #endif |
| 516 | #if defined(CONFIG_BOOTM_PLAN9) |
| 517 | [IH_OS_PLAN9] = do_bootm_plan9, |
| 518 | #endif |
| 519 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
Bin Meng | e63488f | 2018-12-21 07:13:41 -0800 | [diff] [blame] | 520 | (defined(CONFIG_PPC) || defined(CONFIG_ARM) || defined(CONFIG_RISCV)) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 521 | [IH_OS_VXWORKS] = do_bootm_vxworks, |
| 522 | #endif |
| 523 | #if defined(CONFIG_CMD_ELF) |
| 524 | [IH_OS_QNX] = do_bootm_qnxelf, |
| 525 | #endif |
| 526 | #ifdef CONFIG_INTEGRITY |
| 527 | [IH_OS_INTEGRITY] = do_bootm_integrity, |
| 528 | #endif |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 529 | #ifdef CONFIG_BOOTM_OPENRTOS |
| 530 | [IH_OS_OPENRTOS] = do_bootm_openrtos, |
| 531 | #endif |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 532 | #ifdef CONFIG_BOOTM_OPTEE |
| 533 | [IH_OS_TEE] = do_bootm_tee, |
| 534 | #endif |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 535 | #ifdef CONFIG_BOOTM_EFI |
| 536 | [IH_OS_EFI] = do_bootm_efi, |
| 537 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 538 | }; |
| 539 | |
| 540 | /* Allow for arch specific config before we boot */ |
Jeroen Hofstee | f7d4a49 | 2014-07-10 23:06:25 +0200 | [diff] [blame] | 541 | __weak void arch_preboot_os(void) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 542 | { |
| 543 | /* please define platform specific arch_preboot_os() */ |
| 544 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 545 | |
Marek Vasut | 5b9fbd9 | 2018-10-04 21:16:31 +0200 | [diff] [blame] | 546 | /* Allow for board specific config before we boot */ |
| 547 | __weak void board_preboot_os(void) |
| 548 | { |
| 549 | /* please define board specific board_preboot_os() */ |
| 550 | } |
| 551 | |
Simon Glass | 454746d | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 552 | 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] | 553 | { |
| 554 | arch_preboot_os(); |
Marek Vasut | 5b9fbd9 | 2018-10-04 21:16:31 +0200 | [diff] [blame] | 555 | board_preboot_os(); |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 556 | |
Simon Glass | 454746d | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 557 | boot_fn(state, bmi); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 558 | |
| 559 | /* Stand-alone may return when 'autostart' is 'no' */ |
Simon Glass | 454746d | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 560 | if (bmi->images->os.type == IH_TYPE_STANDALONE || |
Simon Glass | 43cdb79 | 2016-07-03 09:40:35 -0600 | [diff] [blame] | 561 | IS_ENABLED(CONFIG_SANDBOX) || |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 562 | state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */ |
| 563 | return 0; |
| 564 | bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED); |
Lukasz Majewski | 9167e10 | 2016-05-08 08:52:21 +0200 | [diff] [blame] | 565 | debug("\n## Control returned to monitor - resetting...\n"); |
| 566 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 567 | return BOOTM_ERR_RESET; |
| 568 | } |
| 569 | |
| 570 | boot_os_fn *bootm_os_get_boot_func(int os) |
| 571 | { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 572 | return boot_os[os]; |
| 573 | } |