blob: 2b5ccce9338ef16ec32694fd50f4a5a9f690d3e7 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rick Chen8bbb2902017-12-26 13:55:49 +08002/*
3 * Copyright (C) 2011 Andes Technology Corporation
4 * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
5 * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
6 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
Rick Chen8bbb2902017-12-26 13:55:49 +08007 */
8
9#include <common.h>
10#include <command.h>
11#include <image.h>
Rick Chen8bbb2902017-12-26 13:55:49 +080012#include <asm/byteorder.h>
Bin Menged49ba42018-09-26 06:55:16 -070013#include <asm/csr.h>
Bin Mengb1893a92018-10-15 02:20:59 -070014#include <dm/device.h>
15#include <dm/root.h>
16#include <u-boot/zlib.h>
Rick Chen8bbb2902017-12-26 13:55:49 +080017
18DECLARE_GLOBAL_DATA_PTR;
19
Alexander Grafb66babd2018-04-23 07:59:46 +020020__weak void board_quiesce_devices(void)
21{
22}
23
Rick Chen8bbb2902017-12-26 13:55:49 +080024int arch_fixup_fdt(void *blob)
25{
26 return 0;
27}
28
Rick Chen8bbb2902017-12-26 13:55:49 +080029int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
30{
Bin Meng4afeedf2018-09-26 06:55:08 -070031 void (*kernel)(ulong hart, void *dtb);
Rick Chen8bbb2902017-12-26 13:55:49 +080032
Rick Chen8bbb2902017-12-26 13:55:49 +080033 /*
34 * allow the PREP bootm subcommand, it is required for bootm to work
35 */
36 if (flag & BOOTM_STATE_OS_PREP)
37 return 0;
38
39 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
40 return 1;
41
Bin Meng4afeedf2018-09-26 06:55:08 -070042 kernel = (void (*)(ulong, void *))images->ep;
Rick Chen8bbb2902017-12-26 13:55:49 +080043
44 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
45
46 debug("## Transferring control to Linux (at address %08lx) ...\n",
Bin Meng4afeedf2018-09-26 06:55:08 -070047 (ulong)kernel);
Rick Chen8bbb2902017-12-26 13:55:49 +080048
49 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
50#ifdef CONFIG_OF_LIBFDT
51 debug("using: FDT\n");
52 if (image_setup_linux(images)) {
53 printf("FDT creation failed! hanging...");
54 hang();
55 }
56#endif
Rick Chen22b7e6f2018-03-13 14:59:41 +080057 }
Rick Chen8bbb2902017-12-26 13:55:49 +080058
59 /* we assume that the kernel is in place */
60 printf("\nStarting kernel ...\n\n");
61
Bin Mengb1893a92018-10-15 02:20:59 -070062 /*
63 * Call remove function of all devices with a removal flag set.
64 * This may be useful for last-stage operations, like cancelling
65 * of DMA operation or releasing device internal buffers.
66 */
67 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
68
Rick Chen8bbb2902017-12-26 13:55:49 +080069 cleanup_before_linux();
Bin Menged49ba42018-09-26 06:55:16 -070070
Rick Chen8bbb2902017-12-26 13:55:49 +080071 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
Bin Menged49ba42018-09-26 06:55:16 -070072 kernel(csr_read(mhartid), images->ft_addr);
Rick Chen22b7e6f2018-03-13 14:59:41 +080073
Rick Chen8bbb2902017-12-26 13:55:49 +080074 /* does not return */
75
76 return 1;
77}