183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
25db28905STom Rini /*
35db28905STom Rini * (C) Copyright 2000-2009
45db28905STom Rini * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
55db28905STom Rini */
65db28905STom Rini
75db28905STom Rini #include <common.h>
85db28905STom Rini #include <bootm.h>
95db28905STom Rini #include <command.h>
105db28905STom Rini #include <image.h>
115db28905STom Rini #include <lmb.h>
125db28905STom Rini #include <mapmem.h>
1328085764SMasahiro Yamada #include <linux/kernel.h>
1428085764SMasahiro Yamada #include <linux/sizes.h>
155db28905STom Rini
165db28905STom Rini /*
175db28905STom Rini * Image booting support
185db28905STom Rini */
booti_start(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[],bootm_headers_t * images)195db28905STom Rini static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
205db28905STom Rini char * const argv[], bootm_headers_t *images)
215db28905STom Rini {
225db28905STom Rini int ret;
236808ef9aSBin Chen ulong ld;
246808ef9aSBin Chen ulong relocated_addr;
256808ef9aSBin Chen ulong image_size;
265db28905STom Rini
275db28905STom Rini ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
285db28905STom Rini images, 1);
295db28905STom Rini
305db28905STom Rini /* Setup Linux kernel Image entry point */
315db28905STom Rini if (!argc) {
326808ef9aSBin Chen ld = load_addr;
335db28905STom Rini debug("* kernel: default image load address = 0x%08lx\n",
345db28905STom Rini load_addr);
355db28905STom Rini } else {
366808ef9aSBin Chen ld = simple_strtoul(argv[0], NULL, 16);
37bf14d9a7SMasahiro Yamada debug("* kernel: cmdline image address = 0x%08lx\n", ld);
385db28905STom Rini }
395db28905STom Rini
407f13b374SMarek Vasut ret = booti_setup(ld, &relocated_addr, &image_size, false);
415db28905STom Rini if (ret != 0)
425db28905STom Rini return 1;
435db28905STom Rini
446808ef9aSBin Chen /* Handle BOOTM_STATE_LOADOS */
456808ef9aSBin Chen if (relocated_addr != ld) {
466808ef9aSBin Chen debug("Moving Image from 0x%lx to 0x%lx\n", ld, relocated_addr);
476808ef9aSBin Chen memmove((void *)relocated_addr, (void *)ld, image_size);
486808ef9aSBin Chen }
495db28905STom Rini
506808ef9aSBin Chen images->ep = relocated_addr;
516808ef9aSBin Chen lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
525db28905STom Rini
535db28905STom Rini /*
545db28905STom Rini * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
555db28905STom Rini * have a header that provide this informaiton.
565db28905STom Rini */
575db28905STom Rini if (bootm_find_images(flag, argc, argv))
585db28905STom Rini return 1;
595db28905STom Rini
605db28905STom Rini return 0;
615db28905STom Rini }
625db28905STom Rini
do_booti(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])635db28905STom Rini int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
645db28905STom Rini {
655db28905STom Rini int ret;
665db28905STom Rini
675db28905STom Rini /* Consume 'booti' */
685db28905STom Rini argc--; argv++;
695db28905STom Rini
705db28905STom Rini if (booti_start(cmdtp, flag, argc, argv, &images))
715db28905STom Rini return 1;
725db28905STom Rini
735db28905STom Rini /*
745db28905STom Rini * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
755db28905STom Rini * disable interrupts ourselves
765db28905STom Rini */
775db28905STom Rini bootm_disable_interrupts();
785db28905STom Rini
795db28905STom Rini images.os.os = IH_OS_LINUX;
800fff19a6SScott Wood images.os.arch = IH_ARCH_ARM64;
815db28905STom Rini ret = do_bootm_states(cmdtp, flag, argc, argv,
824943dc2fSCédric Schieli #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
834943dc2fSCédric Schieli BOOTM_STATE_RAMDISK |
844943dc2fSCédric Schieli #endif
85*2502bfc4SEddie James BOOTM_STATE_MEASURE |
865db28905STom Rini BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
875db28905STom Rini BOOTM_STATE_OS_GO,
885db28905STom Rini &images, 1);
895db28905STom Rini
905db28905STom Rini return ret;
915db28905STom Rini }
925db28905STom Rini
935db28905STom Rini #ifdef CONFIG_SYS_LONGHELP
945db28905STom Rini static char booti_help_text[] =
955db28905STom Rini "[addr [initrd[:size]] [fdt]]\n"
965db28905STom Rini " - boot arm64 Linux Image stored in memory\n"
975db28905STom Rini "\tThe argument 'initrd' is optional and specifies the address\n"
985db28905STom Rini "\tof an initrd in memory. The optional parameter ':size' allows\n"
995db28905STom Rini "\tspecifying the size of a RAW initrd.\n"
1005db28905STom Rini #if defined(CONFIG_OF_LIBFDT)
1015db28905STom Rini "\tSince booting a Linux kernel requires a flat device-tree, a\n"
1025db28905STom Rini "\tthird argument providing the address of the device-tree blob\n"
1035db28905STom Rini "\tis required. To boot a kernel with a device-tree blob but\n"
1045db28905STom Rini "\twithout an initrd image, use a '-' for the initrd argument.\n"
1055db28905STom Rini #endif
1065db28905STom Rini "";
1075db28905STom Rini #endif
1085db28905STom Rini
1095db28905STom Rini U_BOOT_CMD(
1105db28905STom Rini booti, CONFIG_SYS_MAXARGS, 1, do_booti,
1115db28905STom Rini "boot arm64 Linux Image image from memory", booti_help_text
1125db28905STom Rini );
113