blob: 49e304f7eb0e1927fb1f973363d9a921a8f6e4f9 [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>
Bin Meng3c5196d2018-10-15 02:21:13 -070010#include <virtio_types.h>
11#include <virtio.h>
Bin Meng510e3792018-09-26 06:55:21 -070012
Bin Meng510e3792018-09-26 06:55:21 -070013int board_init(void)
14{
Bin Meng3c5196d2018-10-15 02:21:13 -070015 /*
16 * Make sure virtio bus is enumerated so that peripherals
17 * on the virtio bus can be discovered by their drivers
18 */
19 virtio_init();
20
Bin Meng510e3792018-09-26 06:55:21 -070021 return 0;
22}
Lukas Auer66ffe572018-11-22 11:26:36 +010023
24int board_late_init(void)
25{
26 ulong kernel_start;
27 ofnode chosen_node;
28 int ret;
29
30 chosen_node = ofnode_path("/chosen");
31 if (!ofnode_valid(chosen_node)) {
32 debug("No chosen node found, can't get kernel start address\n");
33 return 0;
34 }
35
36#ifdef CONFIG_ARCH_RV64I
37 ret = ofnode_read_u64(chosen_node, "riscv,kernel-start",
38 (u64 *)&kernel_start);
39#else
40 ret = ofnode_read_u32(chosen_node, "riscv,kernel-start",
41 (u32 *)&kernel_start);
42#endif
43 if (ret) {
44 debug("Can't find kernel start address in device tree\n");
45 return 0;
46 }
47
48 env_set_hex("kernel_start", kernel_start);
49
50 return 0;
51}
Lukas Auer897206c2018-11-22 11:26:37 +010052
53/*
54 * QEMU specifies the location of Linux (supplied with the -kernel argument)
55 * in the device tree using the riscv,kernel-start and riscv,kernel-end
56 * properties. We currently rely on the SBI implementation of BBL to run
57 * Linux and therefore embed Linux as payload in BBL. This causes an issue,
58 * because BBL detects the kernel properties in the device tree and ignores
59 * the Linux payload as a result. To work around this issue, we clear the
60 * kernel properties before booting Linux.
61 *
62 * This workaround can be removed, once we do not require BBL for its SBI
63 * implementation anymore.
64 */
65int ft_board_setup(void *blob, bd_t *bd)
66{
67 int chosen_offset, ret;
68
69 chosen_offset = fdt_path_offset(blob, "/chosen");
70 if (chosen_offset < 0)
71 return 0;
72
73#ifdef CONFIG_ARCH_RV64I
74 ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-start", 0);
75#else
76 ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-start", 0);
77#endif
78 if (ret)
79 return ret;
80
81#ifdef CONFIG_ARCH_RV64I
82 ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-end", 0);
83#else
84 ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-end", 0);
85#endif
86 if (ret)
87 return ret;
88
89 return 0;
90}