Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2009 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <bootm.h> |
| 9 | #include <command.h> |
| 10 | #include <image.h> |
| 11 | #include <lmb.h> |
| 12 | #include <mapmem.h> |
Masahiro Yamada | 56c4ed6 | 2017-03-09 16:28:25 +0900 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/sizes.h> |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 15 | |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 16 | /* |
| 17 | * Image booting support |
| 18 | */ |
| 19 | static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, |
| 20 | char * const argv[], bootm_headers_t *images) |
| 21 | { |
| 22 | int ret; |
Bin Chen | dac184b | 2018-01-27 16:59:09 +1100 | [diff] [blame] | 23 | ulong ld; |
| 24 | ulong relocated_addr; |
| 25 | ulong image_size; |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 26 | |
| 27 | ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, |
| 28 | images, 1); |
| 29 | |
| 30 | /* Setup Linux kernel Image entry point */ |
| 31 | if (!argc) { |
Bin Chen | dac184b | 2018-01-27 16:59:09 +1100 | [diff] [blame] | 32 | ld = load_addr; |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 33 | debug("* kernel: default image load address = 0x%08lx\n", |
| 34 | load_addr); |
| 35 | } else { |
Bin Chen | dac184b | 2018-01-27 16:59:09 +1100 | [diff] [blame] | 36 | ld = simple_strtoul(argv[0], NULL, 16); |
Masahiro Yamada | 7691325 | 2018-02-13 12:10:02 +0900 | [diff] [blame] | 37 | debug("* kernel: cmdline image address = 0x%08lx\n", ld); |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 38 | } |
| 39 | |
Marek Vasut | 85ed289 | 2018-06-13 06:13:32 +0200 | [diff] [blame] | 40 | ret = booti_setup(ld, &relocated_addr, &image_size, false); |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 41 | if (ret != 0) |
| 42 | return 1; |
| 43 | |
Bin Chen | dac184b | 2018-01-27 16:59:09 +1100 | [diff] [blame] | 44 | /* Handle BOOTM_STATE_LOADOS */ |
| 45 | if (relocated_addr != ld) { |
| 46 | debug("Moving Image from 0x%lx to 0x%lx\n", ld, relocated_addr); |
| 47 | memmove((void *)relocated_addr, (void *)ld, image_size); |
| 48 | } |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 49 | |
Bin Chen | dac184b | 2018-01-27 16:59:09 +1100 | [diff] [blame] | 50 | images->ep = relocated_addr; |
| 51 | lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size)); |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not |
| 55 | * have a header that provide this informaiton. |
| 56 | */ |
| 57 | if (bootm_find_images(flag, argc, argv)) |
| 58 | return 1; |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 64 | { |
| 65 | int ret; |
| 66 | |
| 67 | /* Consume 'booti' */ |
| 68 | argc--; argv++; |
| 69 | |
| 70 | if (booti_start(cmdtp, flag, argc, argv, &images)) |
| 71 | return 1; |
| 72 | |
| 73 | /* |
| 74 | * We are doing the BOOTM_STATE_LOADOS state ourselves, so must |
| 75 | * disable interrupts ourselves |
| 76 | */ |
| 77 | bootm_disable_interrupts(); |
| 78 | |
| 79 | images.os.os = IH_OS_LINUX; |
Atish Patra | 583b409 | 2019-05-06 17:49:39 -0700 | [diff] [blame] | 80 | #ifdef CONFIG_RISCV_SMODE |
| 81 | images.os.arch = IH_ARCH_RISCV; |
| 82 | #elif CONFIG_ARM64 |
Scott Wood | 4ba6a86 | 2017-01-26 16:55:44 -0600 | [diff] [blame] | 83 | images.os.arch = IH_ARCH_ARM64; |
Atish Patra | 583b409 | 2019-05-06 17:49:39 -0700 | [diff] [blame] | 84 | #endif |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 85 | ret = do_bootm_states(cmdtp, flag, argc, argv, |
Cédric Schieli | 80d5e6b | 2017-01-23 16:51:45 +0100 | [diff] [blame] | 86 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
| 87 | BOOTM_STATE_RAMDISK | |
| 88 | #endif |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 89 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
| 90 | BOOTM_STATE_OS_GO, |
| 91 | &images, 1); |
| 92 | |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | #ifdef CONFIG_SYS_LONGHELP |
| 97 | static char booti_help_text[] = |
| 98 | "[addr [initrd[:size]] [fdt]]\n" |
Atish Patra | 583b409 | 2019-05-06 17:49:39 -0700 | [diff] [blame] | 99 | " - boot Linux 'Image' stored at 'addr'\n" |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 100 | "\tThe argument 'initrd' is optional and specifies the address\n" |
| 101 | "\tof an initrd in memory. The optional parameter ':size' allows\n" |
| 102 | "\tspecifying the size of a RAW initrd.\n" |
| 103 | #if defined(CONFIG_OF_LIBFDT) |
| 104 | "\tSince booting a Linux kernel requires a flat device-tree, a\n" |
| 105 | "\tthird argument providing the address of the device-tree blob\n" |
| 106 | "\tis required. To boot a kernel with a device-tree blob but\n" |
| 107 | "\twithout an initrd image, use a '-' for the initrd argument.\n" |
| 108 | #endif |
| 109 | ""; |
| 110 | #endif |
| 111 | |
| 112 | U_BOOT_CMD( |
| 113 | booti, CONFIG_SYS_MAXARGS, 1, do_booti, |
Atish Patra | 583b409 | 2019-05-06 17:49:39 -0700 | [diff] [blame] | 114 | "boot Linux kernel 'Image' format from memory", booti_help_text |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 115 | ); |