1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
15 #include <asm/global_data.h>
16 #include <linux/kernel.h>
17 #include <linux/sizes.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 * Image booting support
23 static int booti_start(struct cmd_tbl *cmdtp, int flag, int argc,
24 char *const argv[], bootm_headers_t *images)
33 unsigned long comp_len;
34 unsigned long decomp_len;
37 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
40 /* Setup Linux kernel Image entry point */
43 debug("* kernel: default image load address = 0x%08lx\n",
46 ld = hextoul(argv[0], NULL);
47 debug("* kernel: cmdline image address = 0x%08lx\n", ld);
50 temp = map_sysmem(ld, 0);
51 ctype = image_decomp_type(temp, 2);
53 dest = env_get_ulong("kernel_comp_addr_r", 16, 0);
54 comp_len = env_get_ulong("kernel_comp_size", 16, 0);
55 if (!dest || !comp_len) {
56 puts("kernel_comp_addr_r or kernel_comp_size is not provided!\n");
59 if (dest < gd->ram_base || dest > gd->ram_top) {
60 puts("kernel_comp_addr_r is outside of DRAM range!\n");
64 debug("kernel image compression type %d size = 0x%08lx address = 0x%08lx\n",
65 ctype, comp_len, (ulong)dest);
66 decomp_len = comp_len * 10;
67 ret = image_decomp(ctype, 0, ld, IH_TYPE_KERNEL,
68 (void *)dest, (void *)ld, comp_len,
69 decomp_len, &dest_end);
72 /* dest_end contains the uncompressed Image size */
73 memmove((void *) ld, (void *)dest, dest_end);
75 unmap_sysmem((void *)ld);
77 ret = booti_setup(ld, &relocated_addr, &image_size, false);
81 /* Handle BOOTM_STATE_LOADOS */
82 if (relocated_addr != ld) {
83 printf("Moving Image from 0x%lx to 0x%lx, end=%lx\n", ld,
84 relocated_addr, relocated_addr + image_size);
85 memmove((void *)relocated_addr, (void *)ld, image_size);
88 images->ep = relocated_addr;
89 images->os.start = relocated_addr;
90 images->os.end = relocated_addr + image_size;
92 lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
95 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
96 * have a header that provide this informaiton.
98 if (bootm_find_images(flag, argc, argv, relocated_addr, image_size))
104 int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
108 /* Consume 'booti' */
111 if (booti_start(cmdtp, flag, argc, argv, &images))
115 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
116 * disable interrupts ourselves
118 bootm_disable_interrupts();
120 images.os.os = IH_OS_LINUX;
121 #ifdef CONFIG_RISCV_SMODE
122 images.os.arch = IH_ARCH_RISCV;
124 images.os.arch = IH_ARCH_ARM64;
126 ret = do_bootm_states(cmdtp, flag, argc, argv,
127 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
128 BOOTM_STATE_RAMDISK |
130 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
137 #ifdef CONFIG_SYS_LONGHELP
138 static char booti_help_text[] =
139 "[addr [initrd[:size]] [fdt]]\n"
140 " - boot Linux flat or compressed 'Image' stored at 'addr'\n"
141 "\tThe argument 'initrd' is optional and specifies the address\n"
142 "\tof an initrd in memory. The optional parameter ':size' allows\n"
143 "\tspecifying the size of a RAW initrd.\n"
144 "\tCurrently only booting from gz, bz2, lzma and lz4 compression\n"
145 "\ttypes are supported. In order to boot from any of these compressed\n"
146 "\timages, user have to set kernel_comp_addr_r and kernel_comp_size environment\n"
147 "\tvariables beforehand.\n"
148 #if defined(CONFIG_OF_LIBFDT)
149 "\tSince booting a Linux kernel requires a flat device-tree, a\n"
150 "\tthird argument providing the address of the device-tree blob\n"
151 "\tis required. To boot a kernel with a device-tree blob but\n"
152 "\twithout an initrd image, use a '-' for the initrd argument.\n"
158 booti, CONFIG_SYS_MAXARGS, 1, do_booti,
159 "boot Linux kernel 'Image' format from memory", booti_help_text