Bin Meng | 8a8694d | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com> |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Bin Meng | 184eadb | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 8 | #include <env.h> |
Bin Meng | 8a8694d | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 9 | #include <fdtdec.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 10 | #include <image.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Lukas Auer | df3f100 | 2019-08-21 21:14:49 +0200 | [diff] [blame] | 12 | #include <spl.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 13 | #include <init.h> |
Bin Meng | 184eadb | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 14 | #include <virtio_types.h> |
| 15 | #include <virtio.h> |
Bin Meng | 8a8694d | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 16 | |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Bin Meng | 8a8694d | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 19 | int board_init(void) |
| 20 | { |
Bin Meng | 184eadb | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 21 | /* |
| 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 Meng | 8a8694d | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 27 | return 0; |
| 28 | } |
Lukas Auer | 7fcf212 | 2018-11-22 11:26:36 +0100 | [diff] [blame] | 29 | |
| 30 | int 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 Auer | 74c2f12 | 2018-11-22 11:26:37 +0100 | [diff] [blame] | 58 | |
Lukas Auer | df3f100 | 2019-08-21 21:14:49 +0200 | [diff] [blame] | 59 | #ifdef CONFIG_SPL |
| 60 | u32 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 |
| 68 | int board_fit_config_name_match(const char *name) |
| 69 | { |
| 70 | /* boot using first FIT config */ |
| 71 | return 0; |
| 72 | } |
| 73 | #endif |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 74 | |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame^] | 75 | void *board_fdt_blob_setup(int *err) |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 76 | { |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame^] | 77 | *err = 0; |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 78 | /* Stored the DTB address there during our init */ |
| 79 | return (void *)(ulong)gd->arch.firmware_fdt_addr; |
| 80 | } |