blob: dcfd3f20bee66176f43716361ab5f4f372cf7371 [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>
Simon Glass4d72caa2020-05-10 11:40:01 -060010#include <image.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Lukas Auere456a812019-08-21 21:14:49 +020012#include <spl.h>
Simon Glass52559322019-11-14 12:57:46 -070013#include <init.h>
Bin Meng3c5196d2018-10-15 02:21:13 -070014#include <virtio_types.h>
15#include <virtio.h>
Bin Meng510e3792018-09-26 06:55:21 -070016
Bin Meng510e3792018-09-26 06:55:21 -070017int board_init(void)
18{
Bin Meng3c5196d2018-10-15 02:21:13 -070019 /*
20 * Make sure virtio bus is enumerated so that peripherals
21 * on the virtio bus can be discovered by their drivers
22 */
23 virtio_init();
24
Bin Meng510e3792018-09-26 06:55:21 -070025 return 0;
26}
Lukas Auer66ffe572018-11-22 11:26:36 +010027
28int board_late_init(void)
29{
30 ulong kernel_start;
31 ofnode chosen_node;
32 int ret;
33
34 chosen_node = ofnode_path("/chosen");
35 if (!ofnode_valid(chosen_node)) {
36 debug("No chosen node found, can't get kernel start address\n");
37 return 0;
38 }
39
40#ifdef CONFIG_ARCH_RV64I
41 ret = ofnode_read_u64(chosen_node, "riscv,kernel-start",
42 (u64 *)&kernel_start);
43#else
44 ret = ofnode_read_u32(chosen_node, "riscv,kernel-start",
45 (u32 *)&kernel_start);
46#endif
47 if (ret) {
48 debug("Can't find kernel start address in device tree\n");
49 return 0;
50 }
51
52 env_set_hex("kernel_start", kernel_start);
53
54 return 0;
55}
Lukas Auer897206c2018-11-22 11:26:37 +010056
Lukas Auere456a812019-08-21 21:14:49 +020057#ifdef CONFIG_SPL
58u32 spl_boot_device(void)
59{
60 /* RISC-V QEMU only supports RAM as SPL boot device */
61 return BOOT_DEVICE_RAM;
62}
63#endif
64
65#ifdef CONFIG_SPL_LOAD_FIT
66int board_fit_config_name_match(const char *name)
67{
68 /* boot using first FIT config */
69 return 0;
70}
71#endif