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