2019-02-26 20:14:20 +08:00
|
|
|
.. _using_zephyr_as_uos:
|
2021-11-13 08:23:51 +08:00
|
|
|
.. _using_zephyr_as_user_vm:
|
2019-02-26 20:14:20 +08:00
|
|
|
|
2022-06-26 07:10:20 +08:00
|
|
|
Run Zephyr as the User RTVM OS
|
|
|
|
##############################
|
2019-02-26 20:14:20 +08:00
|
|
|
|
2020-04-11 01:44:30 +08:00
|
|
|
This tutorial describes how to run Zephyr as the User VM on the ACRN hypervisor. We are using
|
2020-09-26 07:24:35 +08:00
|
|
|
Kaby Lake-based Intel NUC (model NUC7i5DNHE) in this tutorial.
|
2019-02-26 20:14:20 +08:00
|
|
|
Other :ref:`ACRN supported platforms <hardware>` should work as well.
|
|
|
|
|
2020-05-06 19:39:59 +08:00
|
|
|
.. note::
|
2020-05-08 00:28:51 +08:00
|
|
|
This tutorial uses the (default) SDC scenario. If you use a different
|
|
|
|
scenario, you will need a serial port connection to your platform to see
|
|
|
|
Zephyr console output.
|
2020-05-06 19:39:59 +08:00
|
|
|
|
2019-02-26 20:14:20 +08:00
|
|
|
Introduction to Zephyr
|
|
|
|
**********************
|
|
|
|
|
2020-10-02 08:45:47 +08:00
|
|
|
The Zephyr RTOS is a scalable real-time operating system supporting multiple hardware architectures,
|
2019-02-26 20:14:20 +08:00
|
|
|
optimized for resource constrained devices, and built with safety and security in mind.
|
|
|
|
|
2020-04-11 01:44:30 +08:00
|
|
|
Steps for Using Zephyr as User VM
|
2019-02-26 20:14:20 +08:00
|
|
|
*********************************
|
|
|
|
|
|
|
|
#. Build Zephyr
|
|
|
|
|
|
|
|
Follow the `Zephyr Getting Started Guide <https://docs.zephyrproject.org/latest/getting_started/>`_ to
|
2020-09-26 07:24:35 +08:00
|
|
|
set up the Zephyr development environment.
|
2019-02-26 20:14:20 +08:00
|
|
|
|
2020-04-11 01:44:30 +08:00
|
|
|
The build process for ACRN User VM target is similar to other boards. We will build the `Hello World
|
2019-02-26 20:14:20 +08:00
|
|
|
<https://docs.zephyrproject.org/latest/samples/hello_world/README.html>`_ sample for ACRN:
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
$ cd samples/hello_world
|
2021-12-03 16:47:06 +08:00
|
|
|
$ west build -p auto -b acrn .
|
2019-02-26 20:14:20 +08:00
|
|
|
|
|
|
|
This will build the application ELF binary in ``samples/hello_world/build/zephyr/zephyr.elf``.
|
|
|
|
|
2020-10-02 08:45:47 +08:00
|
|
|
#. Build grub2 bootloader image
|
2019-02-26 20:14:20 +08:00
|
|
|
|
2020-09-26 07:24:35 +08:00
|
|
|
We can build the grub2 bootloader for Zephyr using ``boards/x86/common/scripts/build_grub.sh``
|
|
|
|
found in the `Zephyr source code <https://github.com/zephyrproject-rtos/zephyr>`_.
|
2019-02-26 20:14:20 +08:00
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
$ ./boards/x86/common/scripts/build_grub.sh x86_64
|
|
|
|
|
|
|
|
The EFI executable binary will be found at ``boards/x86/common/scripts/grub/bin/grub_x86_64.efi``.
|
|
|
|
|
|
|
|
#. Preparing the boot device
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
$ dd if=/dev/zero of=zephyr.img bs=1M count=35
|
|
|
|
$ mkfs.vfat -F 32 zephyr.img
|
|
|
|
$ sudo mount `sudo losetup -f -P --show zephyr.img` /mnt
|
|
|
|
|
|
|
|
Create the following directories.
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
$ sudo mkdir -p /mnt/efi/boot
|
|
|
|
$ sudo mkdir -p /mnt/kernel
|
|
|
|
|
|
|
|
Copy ``zephyr.elf`` and ``grub_x86_64.efi``
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
$ sudo cp boards/x86/common/scripts/grub/bin/grub_x86_64.efi /mnt/efi/boot/bootx64.efi
|
|
|
|
$ sudo cp samples/hello_world/build/zephyr/zephyr.elf /mnt/kernel
|
|
|
|
|
|
|
|
Create ``/mnt/efi/boot/grub.cfg`` containing the following:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
set default=0
|
|
|
|
set timeout=10
|
|
|
|
|
|
|
|
menuentry "Zephyr Kernel" {
|
|
|
|
multiboot /kernel/zephyr.elf
|
|
|
|
}
|
|
|
|
|
|
|
|
Unmount the loopback device:
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
$ sudo umount /mnt
|
|
|
|
|
|
|
|
You now have a virtual disk image with a bootable Zephyr in ``zephyr.img``. If the Zephyr build system is not
|
2020-09-26 07:24:35 +08:00
|
|
|
the ACRN Service VM, then you will need to transfer this image to the
|
2020-10-02 08:45:47 +08:00
|
|
|
ACRN Service VM (via, e.g, a USB drive or network)
|
2019-02-26 20:14:20 +08:00
|
|
|
|
2021-08-20 07:28:08 +08:00
|
|
|
#. Follow :ref:`gsg`
|
2020-11-12 10:08:14 +08:00
|
|
|
to boot "The ACRN Service OS" based on Ubnuntu OS (ACRN tag: v2.2)
|
2019-02-26 20:14:20 +08:00
|
|
|
|
2020-09-01 05:02:41 +08:00
|
|
|
|
2020-04-11 01:44:30 +08:00
|
|
|
#. Boot Zephyr as User VM
|
2019-02-26 20:14:20 +08:00
|
|
|
|
2020-04-11 01:44:30 +08:00
|
|
|
On the ACRN Service VM, prepare a directory and populate it with Zephyr files.
|
2019-02-26 20:14:20 +08:00
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
$ mkdir zephyr && cd zephyr
|
|
|
|
$ cp /usr/share/acrn/samples/nuc/launch_zephyr.sh .
|
|
|
|
|
|
|
|
You will also need to copy the ``zephyr.img`` created in the above section into directory ``zephyr``.
|
|
|
|
|
2020-04-11 01:44:30 +08:00
|
|
|
Run the ``launch_zephyr.sh`` script to launch Zephyr as User VM.
|
2019-02-26 20:14:20 +08:00
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
$ sudo ./launch_zephyr.sh
|
|
|
|
|
2020-08-20 08:42:04 +08:00
|
|
|
Then Zephyr will boot automatically. You will see a console message from the hello_world sample application:
|
2019-02-26 20:14:20 +08:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
Hello World! acrn
|