Bin Meng | 40046df | 2019-07-18 00:34:16 -0700 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | .. Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 3 | |
Bin Meng | 40046df | 2019-07-18 00:34:16 -0700 | [diff] [blame] | 4 | QEMU RISC-V |
| 5 | =========== |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 6 | |
| 7 | QEMU for RISC-V supports a special 'virt' machine designed for emulation and |
| 8 | virtualization purposes. This document describes how to run U-Boot under it. |
Lukas Auer | 8313fcd | 2019-08-21 21:14:50 +0200 | [diff] [blame] | 9 | Both 32-bit and 64-bit targets are supported, running in either machine or |
| 10 | supervisor mode. |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 11 | |
| 12 | The QEMU virt machine models a generic RISC-V virtual machine with support for |
| 13 | the VirtIO standard networking and block storage devices. It has CLINT, PLIC, |
| 14 | 16550A UART devices in addition to VirtIO and it also uses device-tree to pass |
| 15 | configuration information to guest software. It implements RISC-V privileged |
| 16 | architecture spec v1.10. |
| 17 | |
| 18 | Building U-Boot |
| 19 | --------------- |
| 20 | Set the CROSS_COMPILE environment variable as usual, and run: |
| 21 | |
Bin Meng | 40046df | 2019-07-18 00:34:16 -0700 | [diff] [blame] | 22 | - For 32-bit RISC-V:: |
| 23 | |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 24 | make qemu-riscv32_defconfig |
| 25 | make |
| 26 | |
Bin Meng | 40046df | 2019-07-18 00:34:16 -0700 | [diff] [blame] | 27 | - For 64-bit RISC-V:: |
| 28 | |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 29 | make qemu-riscv64_defconfig |
| 30 | make |
| 31 | |
Lukas Auer | 8313fcd | 2019-08-21 21:14:50 +0200 | [diff] [blame] | 32 | This will compile U-Boot for machine mode. To build supervisor mode binaries, |
| 33 | use the configurations qemu-riscv32_smode_defconfig and |
| 34 | qemu-riscv64_smode_defconfig instead. Note that U-Boot running in supervisor |
| 35 | mode requires a supervisor binary interface (SBI), such as RISC-V OpenSBI. |
| 36 | |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 37 | Running U-Boot |
| 38 | -------------- |
| 39 | The minimal QEMU command line to get U-Boot up and running is: |
| 40 | |
Bin Meng | 40046df | 2019-07-18 00:34:16 -0700 | [diff] [blame] | 41 | - For 32-bit RISC-V:: |
| 42 | |
Bin Meng | ba51269 | 2020-06-23 05:23:15 -0700 | [diff] [blame] | 43 | qemu-system-riscv32 -nographic -machine virt -bios u-boot |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 44 | |
Bin Meng | 40046df | 2019-07-18 00:34:16 -0700 | [diff] [blame] | 45 | - For 64-bit RISC-V:: |
| 46 | |
Bin Meng | ba51269 | 2020-06-23 05:23:15 -0700 | [diff] [blame] | 47 | qemu-system-riscv64 -nographic -machine virt -bios u-boot |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 48 | |
| 49 | The commands above create targets with 128MiB memory by default. |
| 50 | A freely configurable amount of RAM can be created via the '-m' |
| 51 | parameter. For example, '-m 2G' creates 2GiB memory for the target, |
| 52 | and the memory node in the embedded DTB created by QEMU reflects |
| 53 | the new setting. |
| 54 | |
Lukas Auer | 8313fcd | 2019-08-21 21:14:50 +0200 | [diff] [blame] | 55 | For instructions on how to run U-Boot in supervisor mode on QEMU |
| 56 | with OpenSBI, see the documentation available with OpenSBI: |
| 57 | https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md |
| 58 | |
Bin Meng | ba51269 | 2020-06-23 05:23:15 -0700 | [diff] [blame] | 59 | These have been tested in QEMU 5.0.0. |
Lukas Auer | 8313fcd | 2019-08-21 21:14:50 +0200 | [diff] [blame] | 60 | |
| 61 | Running U-Boot SPL |
| 62 | ------------------ |
| 63 | In the default SPL configuration, U-Boot SPL starts in machine mode. U-Boot |
| 64 | proper and OpenSBI (FW_DYNAMIC firmware) are bundled as FIT image and made |
| 65 | available to U-Boot SPL. Both are then loaded by U-Boot SPL and the location |
| 66 | of U-Boot proper is passed to OpenSBI. After initialization, U-Boot proper is |
| 67 | started in supervisor mode by OpenSBI. |
| 68 | |
| 69 | OpenSBI must be compiled before compiling U-Boot. Version 0.4 and higher is |
| 70 | supported by U-Boot. Clone the OpenSBI repository and run the following command. |
| 71 | |
| 72 | .. code-block:: console |
| 73 | |
| 74 | git clone https://github.com/riscv/opensbi.git |
| 75 | cd opensbi |
Atish Patra | 24c5689 | 2020-12-22 11:50:01 -0800 | [diff] [blame] | 76 | make PLATFORM=generic |
Lukas Auer | 8313fcd | 2019-08-21 21:14:50 +0200 | [diff] [blame] | 77 | |
| 78 | See the OpenSBI documentation for full details: |
| 79 | https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md |
| 80 | |
| 81 | To make the FW_DYNAMIC binary (build/platform/qemu/virt/firmware/fw_dynamic.bin) |
| 82 | available to U-Boot, either copy it into the U-Boot root directory or specify |
| 83 | its location with the OPENSBI environment variable. Afterwards, compile U-Boot |
| 84 | with the following commands. |
| 85 | |
| 86 | - For 32-bit RISC-V:: |
| 87 | |
| 88 | make qemu-riscv32_spl_defconfig |
| 89 | make |
| 90 | |
| 91 | - For 64-bit RISC-V:: |
| 92 | |
| 93 | make qemu-riscv64_spl_defconfig |
| 94 | make |
| 95 | |
| 96 | The minimal QEMU commands to run U-Boot SPL in both 32-bit and 64-bit |
| 97 | configurations are: |
| 98 | |
| 99 | - For 32-bit RISC-V:: |
| 100 | |
Bin Meng | ba51269 | 2020-06-23 05:23:15 -0700 | [diff] [blame] | 101 | qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl \ |
Lukas Auer | 8313fcd | 2019-08-21 21:14:50 +0200 | [diff] [blame] | 102 | -device loader,file=u-boot.itb,addr=0x80200000 |
| 103 | |
| 104 | - For 64-bit RISC-V:: |
| 105 | |
Bin Meng | ba51269 | 2020-06-23 05:23:15 -0700 | [diff] [blame] | 106 | qemu-system-riscv64 -nographic -machine virt -bios spl/u-boot-spl \ |
Lukas Auer | 8313fcd | 2019-08-21 21:14:50 +0200 | [diff] [blame] | 107 | -device loader,file=u-boot.itb,addr=0x80200000 |
Heinrich Schuchardt | f0b1831 | 2020-11-04 12:59:13 +0100 | [diff] [blame] | 108 | |
| 109 | An attached disk can be emulated by adding:: |
| 110 | |
| 111 | -device ich9-ahci,id=ahci \ |
| 112 | -drive if=none,file=riscv64.img,format=raw,id=mydisk \ |
| 113 | -device ide-hd,drive=mydisk,bus=ahci.0 |
| 114 | |
| 115 | You will have to run 'scsi scan' to use it. |