Merge https://gitlab.denx.de/u-boot/custodians/u-boot-riscv
[platform/kernel/u-boot.git] / board / emulation / qemu-riscv / qemu-riscv.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <env.h>
9 #include <fdtdec.h>
10 #include <spl.h>
11 #include <init.h>
12 #include <virtio_types.h>
13 #include <virtio.h>
14
15 int board_init(void)
16 {
17         /*
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
23         return 0;
24 }
25
26 int 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 }
54
55 #ifdef CONFIG_SPL
56 u32 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
64 int board_fit_config_name_match(const char *name)
65 {
66         /* boot using first FIT config */
67         return 0;
68 }
69 #endif