blob: b0d9dd59b12f719267c167b246c2cfac086c5754 [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>
Simon Glass2dc9c342020-05-10 11:40:01 -060010#include <image.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Lukas Auerdf3f1002019-08-21 21:14:49 +020012#include <spl.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Bin Meng184eadb2018-10-15 02:21:13 -070014#include <virtio_types.h>
15#include <virtio.h>
Bin Meng8a8694d2018-09-26 06:55:21 -070016
Ilias Apalodimasdc35df42021-10-12 00:00:13 +030017DECLARE_GLOBAL_DATA_PTR;
18
Bin Meng8a8694d2018-09-26 06:55:21 -070019int board_init(void)
20{
Bin Meng184eadb2018-10-15 02:21:13 -070021 /*
22 * Make sure virtio bus is enumerated so that peripherals
23 * on the virtio bus can be discovered by their drivers
24 */
25 virtio_init();
26
Bin Meng8a8694d2018-09-26 06:55:21 -070027 return 0;
28}
Lukas Auer7fcf2122018-11-22 11:26:36 +010029
30int board_late_init(void)
31{
32 ulong kernel_start;
33 ofnode chosen_node;
34 int ret;
35
36 chosen_node = ofnode_path("/chosen");
37 if (!ofnode_valid(chosen_node)) {
38 debug("No chosen node found, can't get kernel start address\n");
39 return 0;
40 }
41
42#ifdef CONFIG_ARCH_RV64I
43 ret = ofnode_read_u64(chosen_node, "riscv,kernel-start",
44 (u64 *)&kernel_start);
45#else
46 ret = ofnode_read_u32(chosen_node, "riscv,kernel-start",
47 (u32 *)&kernel_start);
48#endif
49 if (ret) {
50 debug("Can't find kernel start address in device tree\n");
51 return 0;
52 }
53
54 env_set_hex("kernel_start", kernel_start);
55
56 return 0;
57}
Lukas Auer74c2f122018-11-22 11:26:37 +010058
Lukas Auerdf3f1002019-08-21 21:14:49 +020059#ifdef CONFIG_SPL
60u32 spl_boot_device(void)
61{
62 /* RISC-V QEMU only supports RAM as SPL boot device */
63 return BOOT_DEVICE_RAM;
64}
65#endif
66
67#ifdef CONFIG_SPL_LOAD_FIT
68int board_fit_config_name_match(const char *name)
69{
70 /* boot using first FIT config */
71 return 0;
72}
73#endif
Ilias Apalodimasdc35df42021-10-12 00:00:13 +030074
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030075void *board_fdt_blob_setup(int *err)
Ilias Apalodimasdc35df42021-10-12 00:00:13 +030076{
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030077 *err = 0;
Ilias Apalodimasdc35df42021-10-12 00:00:13 +030078 /* Stored the DTB address there during our init */
79 return (void *)(ulong)gd->arch.firmware_fdt_addr;
80}