blob: cbce5ffe6e336fd52c9f86955aa81fae51337966 [file] [log] [blame]
Bin Meng510e3792018-09-26 06:55:21 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
4 */
5
6#include <common.h>
Bin Meng3c5196d2018-10-15 02:21:13 -07007#include <dm.h>
Simon Glassc7694dd2019-08-01 09:46:46 -06008#include <env.h>
Bin Meng510e3792018-09-26 06:55:21 -07009#include <fdtdec.h>
Lukas Auere456a812019-08-21 21:14:49 +020010#include <spl.h>
Simon Glass52559322019-11-14 12:57:46 -070011#include <init.h>
Bin Meng3c5196d2018-10-15 02:21:13 -070012#include <virtio_types.h>
13#include <virtio.h>
Bin Meng510e3792018-09-26 06:55:21 -070014
Bin Meng510e3792018-09-26 06:55:21 -070015int board_init(void)
16{
Bin Meng3c5196d2018-10-15 02:21:13 -070017 /*
18 * Make sure virtio bus is enumerated so that peripherals
19 * on the virtio bus can be discovered by their drivers
20 */
21 virtio_init();
22
Bin Meng510e3792018-09-26 06:55:21 -070023 return 0;
24}
Lukas Auer66ffe572018-11-22 11:26:36 +010025
26int board_late_init(void)
27{
28 ulong kernel_start;
29 ofnode chosen_node;
30 int ret;
31
32 chosen_node = ofnode_path("/chosen");
33 if (!ofnode_valid(chosen_node)) {
34 debug("No chosen node found, can't get kernel start address\n");
35 return 0;
36 }
37
38#ifdef CONFIG_ARCH_RV64I
39 ret = ofnode_read_u64(chosen_node, "riscv,kernel-start",
40 (u64 *)&kernel_start);
41#else
42 ret = ofnode_read_u32(chosen_node, "riscv,kernel-start",
43 (u32 *)&kernel_start);
44#endif
45 if (ret) {
46 debug("Can't find kernel start address in device tree\n");
47 return 0;
48 }
49
50 env_set_hex("kernel_start", kernel_start);
51
52 return 0;
53}
Lukas Auer897206c2018-11-22 11:26:37 +010054
55/*
56 * QEMU specifies the location of Linux (supplied with the -kernel argument)
57 * in the device tree using the riscv,kernel-start and riscv,kernel-end
58 * properties. We currently rely on the SBI implementation of BBL to run
59 * Linux and therefore embed Linux as payload in BBL. This causes an issue,
60 * because BBL detects the kernel properties in the device tree and ignores
61 * the Linux payload as a result. To work around this issue, we clear the
62 * kernel properties before booting Linux.
63 *
64 * This workaround can be removed, once we do not require BBL for its SBI
65 * implementation anymore.
66 */
67int ft_board_setup(void *blob, bd_t *bd)
68{
69 int chosen_offset, ret;
70
71 chosen_offset = fdt_path_offset(blob, "/chosen");
72 if (chosen_offset < 0)
73 return 0;
74
75#ifdef CONFIG_ARCH_RV64I
76 ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-start", 0);
77#else
78 ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-start", 0);
79#endif
80 if (ret)
81 return ret;
82
83#ifdef CONFIG_ARCH_RV64I
84 ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-end", 0);
85#else
86 ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-end", 0);
87#endif
88 if (ret)
89 return ret;
90
91 return 0;
92}
Lukas Auere456a812019-08-21 21:14:49 +020093
94#ifdef CONFIG_SPL
95u32 spl_boot_device(void)
96{
97 /* RISC-V QEMU only supports RAM as SPL boot device */
98 return BOOT_DEVICE_RAM;
99}
100#endif
101
102#ifdef CONFIG_SPL_LOAD_FIT
103int board_fit_config_name_match(const char *name)
104{
105 /* boot using first FIT config */
106 return 0;
107}
108#endif