blob: f36b8702ef3d3067f034bf5dd5b55004896f6610 [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>
Lukas Auerc3b1a992018-11-22 11:26:32 +010011#include <dm.h>
12#include <dm/root.h>
Rick Chen8bbb2902017-12-26 13:55:49 +080013#include <image.h>
Rick Chen8bbb2902017-12-26 13:55:49 +080014#include <asm/byteorder.h>
Bin Menged49ba42018-09-26 06:55:16 -070015#include <asm/csr.h>
Bin Mengb1893a92018-10-15 02:20:59 -070016#include <dm/device.h>
17#include <dm/root.h>
18#include <u-boot/zlib.h>
Rick Chen8bbb2902017-12-26 13:55:49 +080019
20DECLARE_GLOBAL_DATA_PTR;
21
Alexander Grafb66babd2018-04-23 07:59:46 +020022__weak void board_quiesce_devices(void)
23{
24}
25
Rick Chen8bbb2902017-12-26 13:55:49 +080026int arch_fixup_fdt(void *blob)
27{
28 return 0;
29}
30
Lukas Auerc3b1a992018-11-22 11:26:32 +010031/**
32 * announce_and_cleanup() - Print message and prepare for kernel boot
33 *
34 * @fake: non-zero to do everything except actually boot
35 */
36static void announce_and_cleanup(int fake)
Rick Chen8bbb2902017-12-26 13:55:49 +080037{
Lukas Auerc3b1a992018-11-22 11:26:32 +010038 printf("\nStarting kernel ...%s\n\n", fake ?
39 "(fake run for tracing)" : "");
40 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
41#ifdef CONFIG_BOOTSTAGE_FDT
42 bootstage_fdt_add_report();
Rick Chen8bbb2902017-12-26 13:55:49 +080043#endif
Lukas Auerc3b1a992018-11-22 11:26:32 +010044#ifdef CONFIG_BOOTSTAGE_REPORT
45 bootstage_report();
46#endif
Rick Chen8bbb2902017-12-26 13:55:49 +080047
Lukas Auerc3b1a992018-11-22 11:26:32 +010048#ifdef CONFIG_USB_DEVICE
49 udc_disconnect();
50#endif
51
52 board_quiesce_devices();
Rick Chen8bbb2902017-12-26 13:55:49 +080053
Bin Mengb1893a92018-10-15 02:20:59 -070054 /*
55 * Call remove function of all devices with a removal flag set.
56 * This may be useful for last-stage operations, like cancelling
57 * of DMA operation or releasing device internal buffers.
58 */
59 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
60
Rick Chen8bbb2902017-12-26 13:55:49 +080061 cleanup_before_linux();
Lukas Auerc3b1a992018-11-22 11:26:32 +010062}
Bin Menged49ba42018-09-26 06:55:16 -070063
Lukas Auerc3b1a992018-11-22 11:26:32 +010064static void boot_prep_linux(bootm_headers_t *images)
65{
66 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
67#ifdef CONFIG_OF_LIBFDT
68 debug("using: FDT\n");
69 if (image_setup_linux(images)) {
70 printf("FDT creation failed! hanging...");
71 hang();
72 }
73#endif
74 } else {
75 printf("Device tree not found or missing FDT support\n");
76 hang();
77 }
78}
Rick Chen22b7e6f2018-03-13 14:59:41 +080079
Lukas Auerc3b1a992018-11-22 11:26:32 +010080static void boot_jump_linux(bootm_headers_t *images, int flag)
81{
82 void (*kernel)(ulong hart, void *dtb);
83 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
Rick Chen8bbb2902017-12-26 13:55:49 +080084
Lukas Auerc3b1a992018-11-22 11:26:32 +010085 kernel = (void (*)(ulong, void *))images->ep;
86
87 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
88
Bin Meng08337cd2018-12-21 07:13:41 -080089 debug("## Transferring control to kernel (at address %08lx) ...\n",
Lukas Auerc3b1a992018-11-22 11:26:32 +010090 (ulong)kernel);
91
92 announce_and_cleanup(fake);
93
94 if (!fake) {
95 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
Bin Meng3c850992018-12-12 06:12:46 -080096 kernel(gd->arch.boot_hart, images->ft_addr);
Lukas Auerc3b1a992018-11-22 11:26:32 +010097 }
98}
99
100int do_bootm_linux(int flag, int argc, char * const argv[],
101 bootm_headers_t *images)
102{
103 /* No need for those on RISC-V */
104 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
105 return -1;
106
107 if (flag & BOOTM_STATE_OS_PREP) {
108 boot_prep_linux(images);
109 return 0;
110 }
111
112 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
113 boot_jump_linux(images, flag);
114 return 0;
115 }
116
117 boot_prep_linux(images);
118 boot_jump_linux(images, flag);
119 return 0;
Rick Chen8bbb2902017-12-26 13:55:49 +0800120}
Bin Meng08337cd2018-12-21 07:13:41 -0800121
122int do_bootm_vxworks(int flag, int argc, char * const argv[],
123 bootm_headers_t *images)
124{
125 return do_bootm_linux(flag, argc, argv, images);
126}