blob: ae3b7a3295c8c499386981e5495985beb76170eb [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>
Anup Patelef191312022-01-27 11:41:09 +05308#include <dm/ofnode.h>
Simon Glassc7694dd2019-08-01 09:46:46 -06009#include <env.h>
Bin Meng510e3792018-09-26 06:55:21 -070010#include <fdtdec.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060011#include <image.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Lukas Auere456a812019-08-21 21:14:49 +020013#include <spl.h>
Simon Glass52559322019-11-14 12:57:46 -070014#include <init.h>
Bin Meng3c5196d2018-10-15 02:21:13 -070015#include <virtio_types.h>
16#include <virtio.h>
Bin Meng510e3792018-09-26 06:55:21 -070017
Ilias Apalodimas2e8d2f82021-10-12 00:00:13 +030018DECLARE_GLOBAL_DATA_PTR;
19
Anup Patelef191312022-01-27 11:41:09 +053020#if IS_ENABLED(CONFIG_MTD_NOR_FLASH)
21int 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
Bin Meng510e3792018-09-26 06:55:21 -070031int board_init(void)
32{
Bin Meng3c5196d2018-10-15 02:21:13 -070033 /*
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
Bin Meng510e3792018-09-26 06:55:21 -070039 return 0;
40}
Lukas Auer66ffe572018-11-22 11:26:36 +010041
42int 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}
Lukas Auer897206c2018-11-22 11:26:37 +010070
Lukas Auere456a812019-08-21 21:14:49 +020071#ifdef CONFIG_SPL
72u32 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
80int board_fit_config_name_match(const char *name)
81{
82 /* boot using first FIT config */
83 return 0;
84}
85#endif
Ilias Apalodimas2e8d2f82021-10-12 00:00:13 +030086
Ilias Apalodimase7fb7892021-10-26 09:12:33 +030087void *board_fdt_blob_setup(int *err)
Ilias Apalodimas2e8d2f82021-10-12 00:00:13 +030088{
Ilias Apalodimase7fb7892021-10-26 09:12:33 +030089 *err = 0;
Ilias Apalodimas2e8d2f82021-10-12 00:00:13 +030090 /* Stored the DTB address there during our init */
91 return (void *)(ulong)gd->arch.firmware_fdt_addr;
92}