blob: c3f96988b1d49c63ec012da5c09772db2304dfd7 [file] [log] [blame]
Bin Meng8a8694d2018-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 Meng184eadb2018-10-15 02:21:13 -07007#include <dm.h>
Simon Glass313112a2019-08-01 09:46:46 -06008#include <env.h>
Bin Meng8a8694d2018-09-26 06:55:21 -07009#include <fdtdec.h>
Lukas Auerdf3f1002019-08-21 21:14:49 +020010#include <spl.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Bin Meng184eadb2018-10-15 02:21:13 -070012#include <virtio_types.h>
13#include <virtio.h>
Bin Meng8a8694d2018-09-26 06:55:21 -070014
Bin Meng8a8694d2018-09-26 06:55:21 -070015int board_init(void)
16{
Bin Meng184eadb2018-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 Meng8a8694d2018-09-26 06:55:21 -070023 return 0;
24}
Lukas Auer7fcf2122018-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 Auer74c2f122018-11-22 11:26:37 +010054
Lukas Auerdf3f1002019-08-21 21:14:49 +020055#ifdef CONFIG_SPL
56u32 spl_boot_device(void)
57{
58 /* RISC-V QEMU only supports RAM as SPL boot device */
59 return BOOT_DEVICE_RAM;
60}
61#endif
62
63#ifdef CONFIG_SPL_LOAD_FIT
64int board_fit_config_name_match(const char *name)
65{
66 /* boot using first FIT config */
67 return 0;
68}
69#endif