Bin Meng | 510e379 | 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 | 3c5196d | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | c7694dd | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 8 | #include <env.h> |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 9 | #include <fdtdec.h> |
Lukas Auer | e456a81 | 2019-08-21 21:14:49 +0200 | [diff] [blame^] | 10 | #include <spl.h> |
Bin Meng | 3c5196d | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 11 | #include <virtio_types.h> |
| 12 | #include <virtio.h> |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 13 | |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 14 | int board_init(void) |
| 15 | { |
Bin Meng | 3c5196d | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 16 | /* |
| 17 | * Make sure virtio bus is enumerated so that peripherals |
| 18 | * on the virtio bus can be discovered by their drivers |
| 19 | */ |
| 20 | virtio_init(); |
| 21 | |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 22 | return 0; |
| 23 | } |
Lukas Auer | 66ffe57 | 2018-11-22 11:26:36 +0100 | [diff] [blame] | 24 | |
| 25 | int board_late_init(void) |
| 26 | { |
| 27 | ulong kernel_start; |
| 28 | ofnode chosen_node; |
| 29 | int ret; |
| 30 | |
| 31 | chosen_node = ofnode_path("/chosen"); |
| 32 | if (!ofnode_valid(chosen_node)) { |
| 33 | debug("No chosen node found, can't get kernel start address\n"); |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | #ifdef CONFIG_ARCH_RV64I |
| 38 | ret = ofnode_read_u64(chosen_node, "riscv,kernel-start", |
| 39 | (u64 *)&kernel_start); |
| 40 | #else |
| 41 | ret = ofnode_read_u32(chosen_node, "riscv,kernel-start", |
| 42 | (u32 *)&kernel_start); |
| 43 | #endif |
| 44 | if (ret) { |
| 45 | debug("Can't find kernel start address in device tree\n"); |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | env_set_hex("kernel_start", kernel_start); |
| 50 | |
| 51 | return 0; |
| 52 | } |
Lukas Auer | 897206c | 2018-11-22 11:26:37 +0100 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * QEMU specifies the location of Linux (supplied with the -kernel argument) |
| 56 | * in the device tree using the riscv,kernel-start and riscv,kernel-end |
| 57 | * properties. We currently rely on the SBI implementation of BBL to run |
| 58 | * Linux and therefore embed Linux as payload in BBL. This causes an issue, |
| 59 | * because BBL detects the kernel properties in the device tree and ignores |
| 60 | * the Linux payload as a result. To work around this issue, we clear the |
| 61 | * kernel properties before booting Linux. |
| 62 | * |
| 63 | * This workaround can be removed, once we do not require BBL for its SBI |
| 64 | * implementation anymore. |
| 65 | */ |
| 66 | int ft_board_setup(void *blob, bd_t *bd) |
| 67 | { |
| 68 | int chosen_offset, ret; |
| 69 | |
| 70 | chosen_offset = fdt_path_offset(blob, "/chosen"); |
| 71 | if (chosen_offset < 0) |
| 72 | return 0; |
| 73 | |
| 74 | #ifdef CONFIG_ARCH_RV64I |
| 75 | ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-start", 0); |
| 76 | #else |
| 77 | ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-start", 0); |
| 78 | #endif |
| 79 | if (ret) |
| 80 | return ret; |
| 81 | |
| 82 | #ifdef CONFIG_ARCH_RV64I |
| 83 | ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-end", 0); |
| 84 | #else |
| 85 | ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-end", 0); |
| 86 | #endif |
| 87 | if (ret) |
| 88 | return ret; |
| 89 | |
| 90 | return 0; |
| 91 | } |
Lukas Auer | e456a81 | 2019-08-21 21:14:49 +0200 | [diff] [blame^] | 92 | |
| 93 | #ifdef CONFIG_SPL |
| 94 | u32 spl_boot_device(void) |
| 95 | { |
| 96 | /* RISC-V QEMU only supports RAM as SPL boot device */ |
| 97 | return BOOT_DEVICE_RAM; |
| 98 | } |
| 99 | #endif |
| 100 | |
| 101 | #ifdef CONFIG_SPL_LOAD_FIT |
| 102 | int board_fit_config_name_match(const char *name) |
| 103 | { |
| 104 | /* boot using first FIT config */ |
| 105 | return 0; |
| 106 | } |
| 107 | #endif |