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 <dm/ofnode.h>
9 #include <env.h>
10 #include <fdtdec.h>
11 #include <image.h>
12 #include <log.h>
13 #include <spl.h>
14 #include <init.h>
15 #include <virtio_types.h>
16 #include <virtio.h>
17
18 DECLARE_GLOBAL_DATA_PTR;
19
20 #if IS_ENABLED(CONFIG_MTD_NOR_FLASH)
is_flash_available(void)21 int is_flash_available(void)
22 {
23 if (!ofnode_equal(ofnode_by_compatible(ofnode_null(), "cfi-flash"),
24 ofnode_null()))
25 return 1;
26
27 return 0;
28 }
29 #endif
30
board_init(void)31 int board_init(void)
32 {
33 /*
34 * Make sure virtio bus is enumerated so that peripherals
35 * on the virtio bus can be discovered by their drivers
36 */
37 virtio_init();
38
39 return 0;
40 }
41
board_late_init(void)42 int board_late_init(void)
43 {
44 ulong kernel_start;
45 ofnode chosen_node;
46 int ret;
47
48 chosen_node = ofnode_path("/chosen");
49 if (!ofnode_valid(chosen_node)) {
50 debug("No chosen node found, can't get kernel start address\n");
51 return 0;
52 }
53
54 #ifdef CONFIG_ARCH_RV64I
55 ret = ofnode_read_u64(chosen_node, "riscv,kernel-start",
56 (u64 *)&kernel_start);
57 #else
58 ret = ofnode_read_u32(chosen_node, "riscv,kernel-start",
59 (u32 *)&kernel_start);
60 #endif
61 if (ret) {
62 debug("Can't find kernel start address in device tree\n");
63 return 0;
64 }
65
66 env_set_hex("kernel_start", kernel_start);
67
68 return 0;
69 }
70
71 #ifdef CONFIG_SPL
spl_boot_device(void)72 u32 spl_boot_device(void)
73 {
74 /* RISC-V QEMU only supports RAM as SPL boot device */
75 return BOOT_DEVICE_RAM;
76 }
77 #endif
78
79 #ifdef CONFIG_SPL_LOAD_FIT
board_fit_config_name_match(const char * name)80 int board_fit_config_name_match(const char *name)
81 {
82 /* boot using first FIT config */
83 return 0;
84 }
85 #endif
86
board_fdt_blob_setup(int * err)87 void *board_fdt_blob_setup(int *err)
88 {
89 *err = 0;
90 /* Stored the DTB address there during our init */
91 return (void *)(ulong)gd->arch.firmware_fdt_addr;
92 }
93