blob: 728367ffaf5a0f3f0fca4785f7591f3aa907ab10 [file] [log] [blame]
Heinrich Schuchardte7d782f2025-05-09 08:42:07 +02001.. SPDX-License-Identifier: GPL-2.0-or-later
Sean Anderson1ecc8d02022-03-22 16:59:09 -04002.. Copyright 2014 Broadcom Corporation.
3
4Semihosting
5===========
6
Heinrich Schuchardte7d782f2025-05-09 08:42:07 +02007Semihosting is a technique to let a real or virtual target communicate with a
8host or host debugger for basic operations such as file I/O, console I/O, etc.
9Originally 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>`_
14for more information.
Sean Anderson1ecc8d02022-03-22 16:59:09 -040015
Sean Andersonbd027cf2022-03-22 16:59:25 -040016Platform Support
17----------------
18
19Versatile Express
20^^^^^^^^^^^^^^^^^
21
Sean Anderson1ecc8d02022-03-22 16:59:09 -040022For developing on armv8 virtual fastmodel platforms, semihosting is a
23valuable tool since it allows access to image/configuration files before
24eMMC or other NV media are available.
25
26There 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 Simek4d0837b2023-09-08 09:11:31 +020029The initial vexpress64 U-Boot board created here runs on the VE virtual
Sean Anderson1ecc8d02022-03-22 16:59:09 -040030platform using the license-free Foundation_v8 simulator. Fortunately,
31the Foundation_v8 simulator also supports the BASE_FVP model which
32companies can purchase licenses for and contain much more functionality.
33So we can, in U-Boot, run either model by either using the VE FVP (default),
34or turning on ``CONFIG_BASE_FVP`` for the more full featured model.
35
36Rather than create a new armv8 board similar to ``armltd/vexpress64``, add
37semihosting calls to the existing one, enabled with ``CONFIG_SEMIHOSTING``
38and ``CONFIG_BASE_FVP`` both set. Also reuse the existing board config file
39vexpress_aemv8.h but differentiate the two models by the presence or
40absence of ``CONFIG_BASE_FVP``. This change is tested and works on both the
41Foundation and Base fastmodel simulators.
42
Sean Andersonbd027cf2022-03-22 16:59:25 -040043QEMU
44^^^^
45
Heinrich Schuchardte7d782f2025-05-09 08:42:07 +020046Another emulator which supports semihosting is `QEMU
Sean Andersonbd027cf2022-03-22 16:59:25 -040047<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
50helpful. When using a semihosted serial console, QEMU will block waiting
51for input. This will cause the GUI to become unresponsive. To mitigate
52this, try adding ``-nographic``. For more information about building and
53running QEMU, refer to the :doc:`board documentation
54<../board/emulation/qemu-arm>`.
55
56OpenOCD
57^^^^^^^
58
Heinrich Schuchardte7d782f2025-05-09 08:42:07 +020059Any ARM or RISC-V platform can use semihosting with an attached debugger. One
60such debugger with good support for a variety of boards and JTAG adapters is
Sean Andersonbd027cf2022-03-22 16:59:25 -040061`OpenOCD <https://openocd.org/>`_. Semihosting is not enabled by default,
62so 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
67Note that enabling semihosting can only be done after attaching to the
Sean Anderson99e12862022-03-22 17:16:05 -040068board with ``init``, and must be done while the CPU is halted. For a more
69extended example, refer to the :ref:`LS1046ARDB docs <ls1046ardb_jtag>`.
Sean Andersonbd027cf2022-03-22 16:59:25 -040070
Sean Anderson1ecc8d02022-03-22 16:59:09 -040071Loading files
72-------------
73
Sean Andersonbd027cf2022-03-22 16:59:25 -040074The semihosting code adds a "semihosting filesystem"::
Sean Anderson1ecc8d02022-03-22 16:59:09 -040075
Sean Andersonbd027cf2022-03-22 16:59:25 -040076 load hostfs - <address> <image>
Sean Anderson1ecc8d02022-03-22 16:59:09 -040077
78That will load an image from the host filesystem into RAM at the specified
Sean Andersonbd027cf2022-03-22 16:59:25 -040079address. If you are using U-Boot SPL, you can also use ``BOOT_DEVICE_SMH``
80which will load ``CONFIG_SPL_FS_LOAD_PAYLOAD_NAME``.
81
82Host console
83------------
84
85U-Boot can use the host's console instead of a physical serial device by
86enabling ``CONFIG_SERIAL_SEMIHOSTING``. If you don't have
87``CONFIG_DM_SERIAL`` enabled, make sure you disable any other serial
88drivers.
89
90Migrating from ``smhload``
91--------------------------
92
93If you were using the ``smhload`` command, you can migrate commands like::
94
95 smhload <file> <address> [<end var>]
96
97to a generic load command like::
98
99 load hostfs - <address> <file>
100
101The ``load`` command will set the ``filesize`` variable with the size of
102the file. The ``fdt chosen`` command has been updated to take a size
103instead of an end address. If you were adding the initramfs to your device
104tree like::
105
106 fdt chosen <address> <end var>
107
108you can now run::
109
110 fdt chosen <address> $filesize