]> Git Repo - J-u-boot.git/blame - cmd/booti.c
configs: Resync with savedefconfig
[J-u-boot.git] / cmd / booti.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
5db28905
TR
2/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, [email protected].
5db28905
TR
5 */
6
7#include <common.h>
8#include <bootm.h>
9#include <command.h>
10#include <image.h>
36bf446b 11#include <irq_func.h>
5db28905 12#include <lmb.h>
f7ae49fc 13#include <log.h>
5db28905 14#include <mapmem.h>
28085764
MY
15#include <linux/kernel.h>
16#include <linux/sizes.h>
5db28905 17
414c34ed 18DECLARE_GLOBAL_DATA_PTR;
5db28905
TR
19/*
20 * Image booting support
21 */
09140113
SG
22static int booti_start(struct cmd_tbl *cmdtp, int flag, int argc,
23 char *const argv[], bootm_headers_t *images)
5db28905
TR
24{
25 int ret;
6808ef9a
BC
26 ulong ld;
27 ulong relocated_addr;
28 ulong image_size;
414c34ed
AP
29 uint8_t *temp;
30 ulong dest;
31 ulong dest_end;
32 unsigned long comp_len;
33 unsigned long decomp_len;
34 int ctype;
5db28905
TR
35
36 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
37 images, 1);
38
39 /* Setup Linux kernel Image entry point */
40 if (!argc) {
bb872dd9 41 ld = image_load_addr;
5db28905 42 debug("* kernel: default image load address = 0x%08lx\n",
bb872dd9 43 image_load_addr);
5db28905 44 } else {
6808ef9a 45 ld = simple_strtoul(argv[0], NULL, 16);
bf14d9a7 46 debug("* kernel: cmdline image address = 0x%08lx\n", ld);
5db28905
TR
47 }
48
414c34ed
AP
49 temp = map_sysmem(ld, 0);
50 ctype = image_decomp_type(temp, 2);
51 if (ctype > 0) {
52 dest = env_get_ulong("kernel_comp_addr_r", 16, 0);
53 comp_len = env_get_ulong("kernel_comp_size", 16, 0);
54 if (!dest || !comp_len) {
55 puts("kernel_comp_addr_r or kernel_comp_size is not provided!\n");
56 return -EINVAL;
57 }
58 if (dest < gd->ram_base || dest > gd->ram_top) {
59 puts("kernel_comp_addr_r is outside of DRAM range!\n");
60 return -EINVAL;
61 }
62
63 debug("kernel image compression type %d size = 0x%08lx address = 0x%08lx\n",
64 ctype, comp_len, (ulong)dest);
65 decomp_len = comp_len * 10;
66 ret = image_decomp(ctype, 0, ld, IH_TYPE_KERNEL,
67 (void *)dest, (void *)ld, comp_len,
68 decomp_len, &dest_end);
69 if (ret)
70 return ret;
71 /* dest_end contains the uncompressed Image size */
72 memmove((void *) ld, (void *)dest, dest_end);
73 }
74 unmap_sysmem((void *)ld);
75
7f13b374 76 ret = booti_setup(ld, &relocated_addr, &image_size, false);
5db28905
TR
77 if (ret != 0)
78 return 1;
79
6808ef9a
BC
80 /* Handle BOOTM_STATE_LOADOS */
81 if (relocated_addr != ld) {
9b83f9c5
TK
82 printf("Moving Image from 0x%lx to 0x%lx, end=%lx\n", ld,
83 relocated_addr, relocated_addr + image_size);
6808ef9a
BC
84 memmove((void *)relocated_addr, (void *)ld, image_size);
85 }
5db28905 86
6808ef9a 87 images->ep = relocated_addr;
683cdd68
LV
88 images->os.start = relocated_addr;
89 images->os.end = relocated_addr + image_size;
90
6808ef9a 91 lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
5db28905
TR
92
93 /*
94 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
95 * have a header that provide this informaiton.
96 */
fbde7589 97 if (bootm_find_images(flag, argc, argv, relocated_addr, image_size))
5db28905
TR
98 return 1;
99
100 return 0;
101}
102
09140113 103int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
5db28905
TR
104{
105 int ret;
106
107 /* Consume 'booti' */
108 argc--; argv++;
109
110 if (booti_start(cmdtp, flag, argc, argv, &images))
111 return 1;
112
113 /*
114 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
115 * disable interrupts ourselves
116 */
117 bootm_disable_interrupts();
118
119 images.os.os = IH_OS_LINUX;
3cedc974
AP
120#ifdef CONFIG_RISCV_SMODE
121 images.os.arch = IH_ARCH_RISCV;
122#elif CONFIG_ARM64
0fff19a6 123 images.os.arch = IH_ARCH_ARM64;
3cedc974 124#endif
5db28905 125 ret = do_bootm_states(cmdtp, flag, argc, argv,
4943dc2f
CS
126#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
127 BOOTM_STATE_RAMDISK |
128#endif
5db28905
TR
129 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
130 BOOTM_STATE_OS_GO,
131 &images, 1);
132
133 return ret;
134}
135
136#ifdef CONFIG_SYS_LONGHELP
137static char booti_help_text[] =
138 "[addr [initrd[:size]] [fdt]]\n"
414c34ed 139 " - boot Linux flat or compressed 'Image' stored at 'addr'\n"
5db28905
TR
140 "\tThe argument 'initrd' is optional and specifies the address\n"
141 "\tof an initrd in memory. The optional parameter ':size' allows\n"
142 "\tspecifying the size of a RAW initrd.\n"
414c34ed
AP
143 "\tCurrently only booting from gz, bz2, lzma and lz4 compression\n"
144 "\ttypes are supported. In order to boot from any of these compressed\n"
d1896e36 145 "\timages, user have to set kernel_comp_addr_r and kernel_comp_size environment\n"
414c34ed 146 "\tvariables beforehand.\n"
5db28905
TR
147#if defined(CONFIG_OF_LIBFDT)
148 "\tSince booting a Linux kernel requires a flat device-tree, a\n"
149 "\tthird argument providing the address of the device-tree blob\n"
150 "\tis required. To boot a kernel with a device-tree blob but\n"
151 "\twithout an initrd image, use a '-' for the initrd argument.\n"
152#endif
153 "";
154#endif
155
156U_BOOT_CMD(
157 booti, CONFIG_SYS_MAXARGS, 1, do_booti,
3cedc974 158 "boot Linux kernel 'Image' format from memory", booti_help_text
5db28905 159);
This page took 0.197644 seconds and 4 git commands to generate.