blob: d1d1573c622c9241b05dd116849a6ab4b5809e84 [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>
Simon Glass807765b2019-12-28 10:44:54 -070012#include <fdt_support.h>
Lukas Auerc3b1a992018-11-22 11:26:32 +010013#include <dm/root.h>
Rick Chen8bbb2902017-12-26 13:55:49 +080014#include <image.h>
Rick Chen8bbb2902017-12-26 13:55:49 +080015#include <asm/byteorder.h>
Bin Menged49ba42018-09-26 06:55:16 -070016#include <asm/csr.h>
Lukas Auerf28ad252019-03-17 19:28:38 +010017#include <asm/smp.h>
Bin Mengb1893a92018-10-15 02:20:59 -070018#include <dm/device.h>
19#include <dm/root.h>
20#include <u-boot/zlib.h>
Rick Chen8bbb2902017-12-26 13:55:49 +080021
22DECLARE_GLOBAL_DATA_PTR;
23
Alexander Grafb66babd2018-04-23 07:59:46 +020024__weak void board_quiesce_devices(void)
25{
26}
27
Rick Chen8bbb2902017-12-26 13:55:49 +080028int arch_fixup_fdt(void *blob)
29{
30 return 0;
31}
32
Lukas Auerc3b1a992018-11-22 11:26:32 +010033/**
34 * announce_and_cleanup() - Print message and prepare for kernel boot
35 *
36 * @fake: non-zero to do everything except actually boot
37 */
38static void announce_and_cleanup(int fake)
Rick Chen8bbb2902017-12-26 13:55:49 +080039{
Lukas Auerc3b1a992018-11-22 11:26:32 +010040 printf("\nStarting kernel ...%s\n\n", fake ?
41 "(fake run for tracing)" : "");
42 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
43#ifdef CONFIG_BOOTSTAGE_FDT
44 bootstage_fdt_add_report();
Rick Chen8bbb2902017-12-26 13:55:49 +080045#endif
Lukas Auerc3b1a992018-11-22 11:26:32 +010046#ifdef CONFIG_BOOTSTAGE_REPORT
47 bootstage_report();
48#endif
Rick Chen8bbb2902017-12-26 13:55:49 +080049
Lukas Auerc3b1a992018-11-22 11:26:32 +010050#ifdef CONFIG_USB_DEVICE
51 udc_disconnect();
52#endif
53
54 board_quiesce_devices();
Rick Chen8bbb2902017-12-26 13:55:49 +080055
Bin Mengb1893a92018-10-15 02:20:59 -070056 /*
57 * Call remove function of all devices with a removal flag set.
58 * This may be useful for last-stage operations, like cancelling
59 * of DMA operation or releasing device internal buffers.
60 */
61 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
62
Rick Chen8bbb2902017-12-26 13:55:49 +080063 cleanup_before_linux();
Lukas Auerc3b1a992018-11-22 11:26:32 +010064}
Bin Menged49ba42018-09-26 06:55:16 -070065
Lukas Auerc3b1a992018-11-22 11:26:32 +010066static void boot_prep_linux(bootm_headers_t *images)
67{
68 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
69#ifdef CONFIG_OF_LIBFDT
70 debug("using: FDT\n");
71 if (image_setup_linux(images)) {
72 printf("FDT creation failed! hanging...");
73 hang();
74 }
75#endif
76 } else {
77 printf("Device tree not found or missing FDT support\n");
78 hang();
79 }
80}
Rick Chen22b7e6f2018-03-13 14:59:41 +080081
Lukas Auerc3b1a992018-11-22 11:26:32 +010082static void boot_jump_linux(bootm_headers_t *images, int flag)
83{
84 void (*kernel)(ulong hart, void *dtb);
85 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
Lukas Auerf28ad252019-03-17 19:28:38 +010086#ifdef CONFIG_SMP
87 int ret;
88#endif
Rick Chen8bbb2902017-12-26 13:55:49 +080089
Lukas Auerc3b1a992018-11-22 11:26:32 +010090 kernel = (void (*)(ulong, void *))images->ep;
91
92 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
93
Bin Meng08337cd2018-12-21 07:13:41 -080094 debug("## Transferring control to kernel (at address %08lx) ...\n",
Lukas Auerc3b1a992018-11-22 11:26:32 +010095 (ulong)kernel);
96
97 announce_and_cleanup(fake);
98
99 if (!fake) {
Lukas Auerf28ad252019-03-17 19:28:38 +0100100 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
101#ifdef CONFIG_SMP
102 ret = smp_call_function(images->ep,
Lukas Auer90ae2812019-12-08 23:28:51 +0100103 (ulong)images->ft_addr, 0, 0);
Lukas Auerf28ad252019-03-17 19:28:38 +0100104 if (ret)
105 hang();
106#endif
Bin Meng3c850992018-12-12 06:12:46 -0800107 kernel(gd->arch.boot_hart, images->ft_addr);
Lukas Auerf28ad252019-03-17 19:28:38 +0100108 }
Lukas Auerc3b1a992018-11-22 11:26:32 +0100109 }
110}
111
112int do_bootm_linux(int flag, int argc, char * const argv[],
113 bootm_headers_t *images)
114{
115 /* No need for those on RISC-V */
116 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
117 return -1;
118
119 if (flag & BOOTM_STATE_OS_PREP) {
120 boot_prep_linux(images);
121 return 0;
122 }
123
124 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
125 boot_jump_linux(images, flag);
126 return 0;
127 }
128
129 boot_prep_linux(images);
130 boot_jump_linux(images, flag);
131 return 0;
Rick Chen8bbb2902017-12-26 13:55:49 +0800132}
Bin Meng08337cd2018-12-21 07:13:41 -0800133
134int do_bootm_vxworks(int flag, int argc, char * const argv[],
135 bootm_headers_t *images)
136{
137 return do_bootm_linux(flag, argc, argv, images);
138}