qemu-riscv.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. .. Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
  3. QEMU RISC-V
  4. ===========
  5. QEMU for RISC-V supports a special 'virt' machine designed for emulation and
  6. virtualization purposes. This document describes how to run U-Boot under it.
  7. Both 32-bit and 64-bit targets are supported, running in either machine or
  8. supervisor mode.
  9. The QEMU virt machine models a generic RISC-V virtual machine with support for
  10. the VirtIO standard networking and block storage devices. It has CLINT, PLIC,
  11. 16550A UART devices in addition to VirtIO and it also uses device-tree to pass
  12. configuration information to guest software. It implements RISC-V privileged
  13. architecture spec v1.10.
  14. Building U-Boot
  15. ---------------
  16. Set the CROSS_COMPILE environment variable as usual, and run:
  17. - For 32-bit RISC-V::
  18. make qemu-riscv32_defconfig
  19. make
  20. - For 64-bit RISC-V::
  21. make qemu-riscv64_defconfig
  22. make
  23. This will compile U-Boot for machine mode. To build supervisor mode binaries,
  24. use the configurations qemu-riscv32_smode_defconfig and
  25. qemu-riscv64_smode_defconfig instead. Note that U-Boot running in supervisor
  26. mode requires a supervisor binary interface (SBI), such as RISC-V OpenSBI.
  27. Running U-Boot
  28. --------------
  29. The minimal QEMU command line to get U-Boot up and running is:
  30. - For 32-bit RISC-V::
  31. qemu-system-riscv32 -nographic -machine virt -bios u-boot
  32. - For 64-bit RISC-V::
  33. qemu-system-riscv64 -nographic -machine virt -bios u-boot
  34. The commands above create targets with 128MiB memory by default.
  35. A freely configurable amount of RAM can be created via the '-m'
  36. parameter. For example, '-m 2G' creates 2GiB memory for the target,
  37. and the memory node in the embedded DTB created by QEMU reflects
  38. the new setting.
  39. For instructions on how to run U-Boot in supervisor mode on QEMU
  40. with OpenSBI, see the documentation available with OpenSBI:
  41. https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
  42. These have been tested in QEMU 5.0.0.
  43. Running U-Boot SPL
  44. ------------------
  45. In the default SPL configuration, U-Boot SPL starts in machine mode. U-Boot
  46. proper and OpenSBI (FW_DYNAMIC firmware) are bundled as FIT image and made
  47. available to U-Boot SPL. Both are then loaded by U-Boot SPL and the location
  48. of U-Boot proper is passed to OpenSBI. After initialization, U-Boot proper is
  49. started in supervisor mode by OpenSBI.
  50. OpenSBI must be compiled before compiling U-Boot. Version 0.4 and higher is
  51. supported by U-Boot. Clone the OpenSBI repository and run the following command.
  52. .. code-block:: console
  53. git clone https://github.com/riscv/opensbi.git
  54. cd opensbi
  55. make PLATFORM=qemu/virt
  56. See the OpenSBI documentation for full details:
  57. https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
  58. To make the FW_DYNAMIC binary (build/platform/qemu/virt/firmware/fw_dynamic.bin)
  59. available to U-Boot, either copy it into the U-Boot root directory or specify
  60. its location with the OPENSBI environment variable. Afterwards, compile U-Boot
  61. with the following commands.
  62. - For 32-bit RISC-V::
  63. make qemu-riscv32_spl_defconfig
  64. make
  65. - For 64-bit RISC-V::
  66. make qemu-riscv64_spl_defconfig
  67. make
  68. The minimal QEMU commands to run U-Boot SPL in both 32-bit and 64-bit
  69. configurations are:
  70. - For 32-bit RISC-V::
  71. qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl \
  72. -device loader,file=u-boot.itb,addr=0x80200000
  73. - For 64-bit RISC-V::
  74. qemu-system-riscv64 -nographic -machine virt -bios spl/u-boot-spl \
  75. -device loader,file=u-boot.itb,addr=0x80200000