riscv.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. .. Copyright (C) 2023, Yu Chien Peter Lin <peterlin@andestech.com>
  3. RISC-V
  4. ======
  5. Overview
  6. --------
  7. This document outlines the U-Boot boot process for the RISC-V architecture.
  8. RISC-V is an open-source instruction set architecture (ISA) based on the
  9. principles of reduced instruction set computing (RISC). It has been designed
  10. to be flexible and customizable, allowing it to be adapted to different use
  11. cases, from embedded systems to high performance servers.
  12. Typical Boot Process
  13. --------------------
  14. U-Boot can run in either M-mode or S-mode, depending on whether it runs before
  15. the initialization of the firmware providing SBI (Supervisor Binary Interface).
  16. The firmware is necessary in the RISC-V boot process as it serves as a SEE
  17. (Supervisor Execution Environment) to handle exceptions for the S-mode U-Boot
  18. or Operating System.
  19. In between the boot phases, the hartid is passed through the a0 register, and
  20. the start address of the devicetree is passed through the a1 register.
  21. As a reference, OpenSBI is an SBI implementation that can be used with U-Boot
  22. in different modes, see the
  23. `OpenSBI firmware document <https://github.com/riscv-software-src/opensbi/tree/master/docs/firmware>`_
  24. for more details.
  25. M-mode U-Boot
  26. ^^^^^^^^^^^^^
  27. When running in M-mode U-Boot, it will load the payload image (e.g.
  28. `fw_payload <https://github.com/riscv-software-src/opensbi/blob/master/docs/firmware/fw_payload.md>`_)
  29. which contains the firmware and the S-mode Operating System; in this case, you
  30. can use mkimage to package the payload image into an uImage format, and boot it
  31. using the bootm command.
  32. The following diagram illustrates the boot process::
  33. <-----------( M-mode )----------><--( S-mode )-->
  34. +----------+ +--------------+ +------------+
  35. | U-Boot |-->| SBI firmware |--->| OS |
  36. +----------+ +--------------+ +------------+
  37. To examine the boot process with the QEMU virt machine, you can follow the
  38. steps in the "Building U-Boot" section of the following document:
  39. :doc:`../board/emulation/qemu-riscv`.
  40. S-mode U-Boot
  41. ^^^^^^^^^^^^^
  42. RISC-V production boot images may include a U-Boot SPL for platform-specific
  43. initialization. The U-Boot SPL then loads a FIT image (u-boot.itb), which
  44. contains a firmware (e.g.
  45. `fw_dynamic <https://github.com/riscv-software-src/opensbi/blob/master/docs/firmware/fw_dynamic.md>`_)
  46. providing the SBI, as well as a regular U-Boot (or U-Boot proper) running in
  47. S-mode. Finally, the S-mode Operating
  48. System is loaded.
  49. The following diagram illustrates the boot process::
  50. <-------------( M-mode )----------><----------( S-mode )------->
  51. +------------+ +--------------+ +----------+ +----------+
  52. | U-Boot SPL |-->| SBI firmware |--->| U-Boot |-->| OS |
  53. +------------+ +--------------+ +----------+ +----------+
  54. To examine the boot process with the QEMU virt machine, you can follow the
  55. steps in the "Running U-Boot SPL" section of the following document:
  56. :doc:`../board/emulation/qemu-riscv`.
  57. Toolchain
  58. ---------
  59. You can build the
  60. `RISC-V GNU toolchain <https://github.com/riscv-collab/riscv-gnu-toolchain>`_
  61. from scratch, or download a pre-built toolchain from the
  62. `releases page <https://github.com/riscv-collab/riscv-gnu-toolchain/releases>`_.