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> |
Anup Patel | 5c5f64c | 2022-01-27 11:41:09 +0530 | [diff] [blame] | 8 | #include <dm/ofnode.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 9 | #include <env.h> |
Bin Meng | 8a8694d | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 10 | #include <fdtdec.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Lukas Auer | df3f100 | 2019-08-21 21:14:49 +0200 | [diff] [blame] | 13 | #include <spl.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 14 | #include <init.h> |
Bin Meng | 184eadb | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 15 | #include <virtio_types.h> |
| 16 | #include <virtio.h> |
Bin Meng | 8a8694d | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 17 | |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Anup Patel | 5c5f64c | 2022-01-27 11:41:09 +0530 | [diff] [blame] | 20 | #if IS_ENABLED(CONFIG_MTD_NOR_FLASH) |
| 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 | |
Bin Meng | 8a8694d | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 31 | int board_init(void) |
| 32 | { |
Bin Meng | 184eadb | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 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 | |
Bin Meng | 8a8694d | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 39 | return 0; |
| 40 | } |
Lukas Auer | 7fcf212 | 2018-11-22 11:26:36 +0100 | [diff] [blame] | 41 | |
| 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 | } |
Lukas Auer | 74c2f12 | 2018-11-22 11:26:37 +0100 | [diff] [blame] | 70 | |
Lukas Auer | df3f100 | 2019-08-21 21:14:49 +0200 | [diff] [blame] | 71 | #ifdef CONFIG_SPL |
| 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 |
| 80 | int board_fit_config_name_match(const char *name) |
| 81 | { |
| 82 | /* boot using first FIT config */ |
| 83 | return 0; |
| 84 | } |
| 85 | #endif |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 86 | |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 87 | void *board_fdt_blob_setup(int *err) |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 88 | { |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 89 | *err = 0; |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 90 | /* Stored the DTB address there during our init */ |
| 91 | return (void *)(ulong)gd->arch.firmware_fdt_addr; |
| 92 | } |