blob: efbd3e23e7a570e3f693eca1645118ebb9c7277f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rick Chen6eedd922017-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 Chen6eedd922017-12-26 13:55:49 +08007 */
8
9#include <common.h>
10#include <command.h>
Lukas Auer86feab32018-11-22 11:26:32 +010011#include <dm.h>
12#include <dm/root.h>
Rick Chen6eedd922017-12-26 13:55:49 +080013#include <image.h>
Rick Chen6eedd922017-12-26 13:55:49 +080014#include <asm/byteorder.h>
Bin Meng8294bb52018-09-26 06:55:16 -070015#include <asm/csr.h>
Lukas Auerc4a6c8f2019-03-17 19:28:38 +010016#include <asm/smp.h>
Bin Meng635a2532018-10-15 02:20:59 -070017#include <dm/device.h>
18#include <dm/root.h>
19#include <u-boot/zlib.h>
Rick Chen6eedd922017-12-26 13:55:49 +080020
21DECLARE_GLOBAL_DATA_PTR;
22
Alexander Graf7ea64b02018-04-23 07:59:46 +020023__weak void board_quiesce_devices(void)
24{
25}
26
Rick Chen6eedd922017-12-26 13:55:49 +080027int arch_fixup_fdt(void *blob)
28{
29 return 0;
30}
31
Lukas Auer86feab32018-11-22 11:26:32 +010032/**
33 * announce_and_cleanup() - Print message and prepare for kernel boot
34 *
35 * @fake: non-zero to do everything except actually boot
36 */
37static void announce_and_cleanup(int fake)
Rick Chen6eedd922017-12-26 13:55:49 +080038{
Lukas Auer86feab32018-11-22 11:26:32 +010039 printf("\nStarting kernel ...%s\n\n", fake ?
40 "(fake run for tracing)" : "");
41 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
42#ifdef CONFIG_BOOTSTAGE_FDT
43 bootstage_fdt_add_report();
44#endif
45#ifdef CONFIG_BOOTSTAGE_REPORT
46 bootstage_report();
47#endif
Rick Chen6eedd922017-12-26 13:55:49 +080048
Lukas Auer86feab32018-11-22 11:26:32 +010049#ifdef CONFIG_USB_DEVICE
50 udc_disconnect();
51#endif
Rick Chen6eedd922017-12-26 13:55:49 +080052
Lukas Auer86feab32018-11-22 11:26:32 +010053 board_quiesce_devices();
Rick Chen6eedd922017-12-26 13:55:49 +080054
Lukas Auer86feab32018-11-22 11:26:32 +010055 /*
56 * Call remove function of all devices with a removal flag set.
57 * This may be useful for last-stage operations, like cancelling
58 * of DMA operation or releasing device internal buffers.
59 */
60 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
Rick Chen6eedd922017-12-26 13:55:49 +080061
Lukas Auer86feab32018-11-22 11:26:32 +010062 cleanup_before_linux();
63}
Rick Chen6eedd922017-12-26 13:55:49 +080064
Lukas Auer86feab32018-11-22 11:26:32 +010065static void boot_prep_linux(bootm_headers_t *images)
66{
Rick Chen6eedd922017-12-26 13:55:49 +080067 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
68#ifdef CONFIG_OF_LIBFDT
69 debug("using: FDT\n");
70 if (image_setup_linux(images)) {
71 printf("FDT creation failed! hanging...");
72 hang();
73 }
74#endif
Lukas Auer86feab32018-11-22 11:26:32 +010075 } else {
76 printf("Device tree not found or missing FDT support\n");
77 hang();
Rick Chen53b47b82018-03-13 14:59:41 +080078 }
Lukas Auer86feab32018-11-22 11:26:32 +010079}
80
81static void boot_jump_linux(bootm_headers_t *images, int flag)
82{
83 void (*kernel)(ulong hart, void *dtb);
84 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
Lukas Auerc4a6c8f2019-03-17 19:28:38 +010085#ifdef CONFIG_SMP
86 int ret;
87#endif
Rick Chen6eedd922017-12-26 13:55:49 +080088
Lukas Auer86feab32018-11-22 11:26:32 +010089 kernel = (void (*)(ulong, void *))images->ep;
Rick Chen6eedd922017-12-26 13:55:49 +080090
Lukas Auer86feab32018-11-22 11:26:32 +010091 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Bin Meng635a2532018-10-15 02:20:59 -070092
Bin Menge63488f2018-12-21 07:13:41 -080093 debug("## Transferring control to kernel (at address %08lx) ...\n",
Lukas Auer86feab32018-11-22 11:26:32 +010094 (ulong)kernel);
Bin Meng8294bb52018-09-26 06:55:16 -070095
Lukas Auer86feab32018-11-22 11:26:32 +010096 announce_and_cleanup(fake);
Rick Chen53b47b82018-03-13 14:59:41 +080097
Lukas Auer86feab32018-11-22 11:26:32 +010098 if (!fake) {
Lukas Auerc4a6c8f2019-03-17 19:28:38 +010099 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
100#ifdef CONFIG_SMP
101 ret = smp_call_function(images->ep,
102 (ulong)images->ft_addr, 0);
103 if (ret)
104 hang();
105#endif
Bin Mengfda01b62018-12-12 06:12:46 -0800106 kernel(gd->arch.boot_hart, images->ft_addr);
Lukas Auerc4a6c8f2019-03-17 19:28:38 +0100107 }
Lukas Auer86feab32018-11-22 11:26:32 +0100108 }
109}
110
111int do_bootm_linux(int flag, int argc, char * const argv[],
112 bootm_headers_t *images)
113{
114 /* No need for those on RISC-V */
115 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
116 return -1;
Rick Chen6eedd922017-12-26 13:55:49 +0800117
Lukas Auer86feab32018-11-22 11:26:32 +0100118 if (flag & BOOTM_STATE_OS_PREP) {
119 boot_prep_linux(images);
120 return 0;
121 }
122
123 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
124 boot_jump_linux(images, flag);
125 return 0;
126 }
127
128 boot_prep_linux(images);
129 boot_jump_linux(images, flag);
130 return 0;
Rick Chen6eedd922017-12-26 13:55:49 +0800131}
Bin Menge63488f2018-12-21 07:13:41 -0800132
133int do_bootm_vxworks(int flag, int argc, char * const argv[],
134 bootm_headers_t *images)
135{
136 return do_bootm_linux(flag, argc, argv, images);
137}