Heinrich Schuchardt | e7d782f | 2025-05-09 08:42:07 +0200 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0-or-later |
Sean Anderson | 1ecc8d0 | 2022-03-22 16:59:09 -0400 | [diff] [blame] | 2 | .. Copyright 2014 Broadcom Corporation. |
| 3 | |
| 4 | Semihosting |
| 5 | =========== |
| 6 | |
Heinrich Schuchardt | e7d782f | 2025-05-09 08:42:07 +0200 | [diff] [blame] | 7 | Semihosting is a technique to let a real or virtual target communicate with a |
| 8 | host or host debugger for basic operations such as file I/O, console I/O, etc. |
| 9 | Originally introduced by ARM it has also been adopted for RISC-V. Please, see |
| 10 | `Arm's semihosting documentation |
| 11 | <https://developer.arm.com/documentation/dui0471/g/Semihosting>`_ and |
| 12 | `RISC-V Semihosting |
| 13 | <https://drive.google.com/file/d/1qu74D4_EmjGmc03qzfQ7Pf4g6m0fOtcD/view>`_ |
| 14 | for more information. |
Sean Anderson | 1ecc8d0 | 2022-03-22 16:59:09 -0400 | [diff] [blame] | 15 | |
Sean Anderson | bd027cf | 2022-03-22 16:59:25 -0400 | [diff] [blame] | 16 | Platform Support |
| 17 | ---------------- |
| 18 | |
| 19 | Versatile Express |
| 20 | ^^^^^^^^^^^^^^^^^ |
| 21 | |
Sean Anderson | 1ecc8d0 | 2022-03-22 16:59:09 -0400 | [diff] [blame] | 22 | For developing on armv8 virtual fastmodel platforms, semihosting is a |
| 23 | valuable tool since it allows access to image/configuration files before |
| 24 | eMMC or other NV media are available. |
| 25 | |
| 26 | There are two main ARM virtual Fixed Virtual Platform (FVP) models, |
| 27 | `Versatile Express (VE) FVP and BASE FVP |
| 28 | <http://www.arm.com/products/tools/models/fast-models/foundation-model.php>`_. |
Michal Simek | 4d0837b | 2023-09-08 09:11:31 +0200 | [diff] [blame] | 29 | The initial vexpress64 U-Boot board created here runs on the VE virtual |
Sean Anderson | 1ecc8d0 | 2022-03-22 16:59:09 -0400 | [diff] [blame] | 30 | platform using the license-free Foundation_v8 simulator. Fortunately, |
| 31 | the Foundation_v8 simulator also supports the BASE_FVP model which |
| 32 | companies can purchase licenses for and contain much more functionality. |
| 33 | So we can, in U-Boot, run either model by either using the VE FVP (default), |
| 34 | or turning on ``CONFIG_BASE_FVP`` for the more full featured model. |
| 35 | |
| 36 | Rather than create a new armv8 board similar to ``armltd/vexpress64``, add |
| 37 | semihosting calls to the existing one, enabled with ``CONFIG_SEMIHOSTING`` |
| 38 | and ``CONFIG_BASE_FVP`` both set. Also reuse the existing board config file |
| 39 | vexpress_aemv8.h but differentiate the two models by the presence or |
| 40 | absence of ``CONFIG_BASE_FVP``. This change is tested and works on both the |
| 41 | Foundation and Base fastmodel simulators. |
| 42 | |
Sean Anderson | bd027cf | 2022-03-22 16:59:25 -0400 | [diff] [blame] | 43 | QEMU |
| 44 | ^^^^ |
| 45 | |
Heinrich Schuchardt | e7d782f | 2025-05-09 08:42:07 +0200 | [diff] [blame] | 46 | Another emulator which supports semihosting is `QEMU |
Sean Anderson | bd027cf | 2022-03-22 16:59:25 -0400 | [diff] [blame] | 47 | <https://www.qemu.org/>`_. To enable semihosting, enable |
| 48 | ``CONFIG_SERIAL_PROBE_ALL`` when configuring U-Boot, and use |
| 49 | ``-semihosting`` when invoking QEMU. Adding ``-nographic`` can also be |
| 50 | helpful. When using a semihosted serial console, QEMU will block waiting |
| 51 | for input. This will cause the GUI to become unresponsive. To mitigate |
| 52 | this, try adding ``-nographic``. For more information about building and |
| 53 | running QEMU, refer to the :doc:`board documentation |
| 54 | <../board/emulation/qemu-arm>`. |
| 55 | |
| 56 | OpenOCD |
| 57 | ^^^^^^^ |
| 58 | |
Heinrich Schuchardt | e7d782f | 2025-05-09 08:42:07 +0200 | [diff] [blame] | 59 | Any ARM or RISC-V platform can use semihosting with an attached debugger. One |
| 60 | such debugger with good support for a variety of boards and JTAG adapters is |
Sean Anderson | bd027cf | 2022-03-22 16:59:25 -0400 | [diff] [blame] | 61 | `OpenOCD <https://openocd.org/>`_. Semihosting is not enabled by default, |
| 62 | so you will need to enable it:: |
| 63 | |
| 64 | $ openocd -f <your board config> -c init -c halt -c \ |
| 65 | 'arm semihosting enable' -c resume |
| 66 | |
| 67 | Note that enabling semihosting can only be done after attaching to the |
Sean Anderson | 99e1286 | 2022-03-22 17:16:05 -0400 | [diff] [blame] | 68 | board with ``init``, and must be done while the CPU is halted. For a more |
| 69 | extended example, refer to the :ref:`LS1046ARDB docs <ls1046ardb_jtag>`. |
Sean Anderson | bd027cf | 2022-03-22 16:59:25 -0400 | [diff] [blame] | 70 | |
Sean Anderson | 1ecc8d0 | 2022-03-22 16:59:09 -0400 | [diff] [blame] | 71 | Loading files |
| 72 | ------------- |
| 73 | |
Sean Anderson | bd027cf | 2022-03-22 16:59:25 -0400 | [diff] [blame] | 74 | The semihosting code adds a "semihosting filesystem":: |
Sean Anderson | 1ecc8d0 | 2022-03-22 16:59:09 -0400 | [diff] [blame] | 75 | |
Sean Anderson | bd027cf | 2022-03-22 16:59:25 -0400 | [diff] [blame] | 76 | load hostfs - <address> <image> |
Sean Anderson | 1ecc8d0 | 2022-03-22 16:59:09 -0400 | [diff] [blame] | 77 | |
| 78 | That will load an image from the host filesystem into RAM at the specified |
Sean Anderson | bd027cf | 2022-03-22 16:59:25 -0400 | [diff] [blame] | 79 | address. If you are using U-Boot SPL, you can also use ``BOOT_DEVICE_SMH`` |
| 80 | which will load ``CONFIG_SPL_FS_LOAD_PAYLOAD_NAME``. |
| 81 | |
| 82 | Host console |
| 83 | ------------ |
| 84 | |
| 85 | U-Boot can use the host's console instead of a physical serial device by |
| 86 | enabling ``CONFIG_SERIAL_SEMIHOSTING``. If you don't have |
| 87 | ``CONFIG_DM_SERIAL`` enabled, make sure you disable any other serial |
| 88 | drivers. |
| 89 | |
| 90 | Migrating from ``smhload`` |
| 91 | -------------------------- |
| 92 | |
| 93 | If you were using the ``smhload`` command, you can migrate commands like:: |
| 94 | |
| 95 | smhload <file> <address> [<end var>] |
| 96 | |
| 97 | to a generic load command like:: |
| 98 | |
| 99 | load hostfs - <address> <file> |
| 100 | |
| 101 | The ``load`` command will set the ``filesize`` variable with the size of |
| 102 | the file. The ``fdt chosen`` command has been updated to take a size |
| 103 | instead of an end address. If you were adding the initramfs to your device |
| 104 | tree like:: |
| 105 | |
| 106 | fdt chosen <address> <end var> |
| 107 | |
| 108 | you can now run:: |
| 109 | |
| 110 | fdt chosen <address> $filesize |