Skip to content

Commit b07065d

Browse files
lorcnashif
authored andcommitted
arm: aarch64: add Xen virtual machine support
This commit adds minimal support for running zephyr as Xen guest. It does not use xen PV console, which is somewhat hard to implement, as it depends on xenbus infrastructure. Instead SBSA-compatible PL011 uart is used. Signed-off-by: Volodymyr Babchuk <[email protected]>
1 parent 4fb1ee7 commit b07065d

File tree

12 files changed

+395
-0
lines changed

12 files changed

+395
-0
lines changed

boards/arm/xenvm/Kconfig.board

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2020 EPAM Systems
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config BOARD_XENVM
5+
bool "Xen Virtual Machine"
6+
depends on SOC_XENVM
7+
select ARM64

boards/arm/xenvm/Kconfig.defconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2020 EPAM Systems
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if BOARD_XENVM
5+
6+
config BUILD_OUTPUT_BIN
7+
default y
8+
9+
config BOARD
10+
default "xenvm"
11+
12+
endif # BOARD_XENVM

boards/arm/xenvm/doc/index.rst

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
.. xenvm:
2+
3+
ARMv8 Xen Virtual Machine Example
4+
#################################
5+
6+
Overview
7+
********
8+
9+
This board allows to run Zephyr as Xen guest on any ARMv8 board that supports
10+
ARM Virtualization Extensions. This is example configuration, as almost any VM
11+
configuration is unique in many aspects.
12+
13+
.. figure:: xen_project_logo.png
14+
:align: center
15+
:alt: XenVM
16+
17+
Xen virtual Guest (Credit: Xen Project)
18+
19+
It provides minimal set of devices:
20+
21+
* ARM Generic timer
22+
* GICv2
23+
* SBSA (subset of PL011) UART controller
24+
25+
26+
Hardware
27+
********
28+
Supported Features
29+
==================
30+
31+
The following hardware features are supported:
32+
33+
+--------------+-------------+----------------------+
34+
| Interface | Controller | Driver/Component |
35+
+==============+=============+======================+
36+
| GIC | virtualized | interrupt controller |
37+
+--------------+-------------+----------------------+
38+
| SBSA UART | emulated | serial port |
39+
+--------------+-------------+----------------------+
40+
| ARM TIMER | virtualized | system clock |
41+
+--------------+-------------+----------------------+
42+
43+
The kernel currently does not support other hardware features on this platform.
44+
45+
Devices
46+
========
47+
System Clock
48+
------------
49+
50+
This board configuration uses a system clock frequency of 8.32 MHz. This is the
51+
default value, which should be corrected for user's actual hardware.
52+
53+
You can determine clock frequency of your ARM Generic Timer by inspecting Xen
54+
boot log:
55+
56+
::
57+
58+
(XEN) [ 0.147541] Generic Timer IRQ: phys=30 hyp=26 virt=27 Freq: 8320 KHz
59+
60+
Serial Port
61+
-----------
62+
63+
This board configuration uses a single serial communication channel using SBSA
64+
UART. This is a minimal UART implementation provided by Xen. Xen PV Console is
65+
not supported at this moment.
66+
67+
Interrupt Controller
68+
--------------------
69+
70+
By default, GICv2 is selected. If your hardware is based on GICv3, you can
71+
configure Zephyr to use it, by amending device tree and Kconfig
72+
option in "xenvm" SoC as well as guest configuration file.
73+
74+
CPU Core type
75+
-------------
76+
77+
Default core in this configuration is Cortex A72. Depending on yours actual
78+
hardware you might want to change this option in the same way as Interrupt
79+
Controller configuration.
80+
81+
Known Problems or Limitations
82+
==============================
83+
84+
Xen configures guests in runtime by providing device tree that describes guest
85+
environment. On other hand, Zephyr uses static configuration that should be know
86+
at build time. So there are chances, that Zephyr image created with default
87+
configuration would not boot on your hardware. In this case you need to update
88+
configuration by altering device tree and Kconfig options. This will be covered
89+
in detail in next section.
90+
91+
No Xen-specific features are supported at the moment. This includes:
92+
93+
* Xen Enlighten memory page
94+
* XenBus
95+
* Xen event channels
96+
* Xen grant tables
97+
* Xen PV drivers (including PV console)
98+
99+
Building and Running
100+
********************
101+
102+
Use this configuration to run basic Zephyr applications and kernel tests as Xen
103+
guest, for example, with the :ref:`synchronization_sample`:
104+
105+
106+
.. code-block::
107+
108+
$ west build -b xenvm samples/synchronization
109+
110+
This will build an image with the synchronization sample app. Next, you need to
111+
create guest configuration file :code:`zephyr.conf`. There is example:
112+
113+
.. code-block::
114+
115+
kernel="zephyr.bin"
116+
name="zephyr"
117+
vcpus=1
118+
memory=16
119+
gic_version="v2"
120+
on_crash="preserve"
121+
vuart="sbsa_uart"
122+
123+
You need to upload both :code:`zephyr.bin` and :code:`zephyr.conf` to your Dom0
124+
and then you can run Zephyr by issuing
125+
126+
.. code-block::
127+
128+
$ xl create zephyr.conf
129+
130+
Next you need to attach to SBSA virtual console:
131+
132+
.. code-block::
133+
134+
$ xl console -t vuart zephyr
135+
136+
You will see Zephyr output:
137+
138+
.. code-block:: console
139+
140+
*** Booting Zephyr OS build zephyr-v2.4.0-1137-g5803ee1e8183 ***
141+
thread_a: Hello World from cpu 0 on xenvm!
142+
thread_b: Hello World from cpu 0 on xenvm!
143+
thread_a: Hello World from cpu 0 on xenvm!
144+
thread_b: Hello World from cpu 0 on xenvm!
145+
thread_a: Hello World from cpu 0 on xenvm!
146+
147+
Exit xen virtual console by pressing :kbd:`CTRL+[`
148+
149+
Updating configuration
150+
**********************
151+
152+
As was said earlier, Xen describes hardware using device tree and expects that
153+
guest will parse device tree in runtime. On other hand, Zephyr supports only
154+
static, build time configuration. While provided configuration should work on
155+
almost any ARMv8 host running in aarch64 mode, there is no guarantee, that Xen
156+
will not change some values (like RAM base address) in the future.
157+
158+
Also, frequency of system timer is board specific and should be updated when running
159+
Zephyr xenvm image on new hardware.
160+
161+
One can make Xen to dump generated DTB by using :code:`LIBXL_DEBUG_DUMP_DTB`
162+
environment variable, like so:
163+
164+
.. code-block::
165+
166+
$ LIBXL_DEBUG_DUMP_DTB=domu-libxl.dtb xl create zephyr.conf
167+
168+
Then, generated "domu-libxl.dtb" file can be de-compiled using "dtc" tool.
169+
170+
Use information from de-compiled DTB file to update all related entries in
171+
provided "xenvm.dts" file. If memory layout is also changed, you may need to
172+
update :code:`CONFIG_SRAM_BASE_ADDRESS` as well.
173+
174+
References
175+
**********
176+
177+
`Xen ARM with Virtualization Extensions <https://wiki.xenproject.org/wiki/Xen_ARM_with_Virtualization_Extensions>`_
178+
179+
`xl.conf (guest configuration file) manual <https://xenbits.xen.org/docs/unstable/man/xl.cfg.5.html>`_
66.4 KB
Loading

boards/arm/xenvm/xenvm.dts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2020 EPAM Systems
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* This file was created by running
7+
*
8+
* # LIBXL_DEBUG_DUMP_DTB=domu-libxl.dtb xl create zephyr.conf
9+
*
10+
* decompilling resulting domu-libxl.dtb and then manually aligning it
11+
* with zephyr requirements.
12+
*/
13+
14+
/dts-v1/;
15+
16+
#include <mem.h>
17+
#include <arm/armv8-a.dtsi>
18+
#include <dt-bindings/interrupt-controller/arm-gic.h>
19+
20+
/ {
21+
model = "XENVM-4.15";
22+
compatible = "xen,xenvm-4.15", "xen,xenvm";
23+
interrupt-parent = <&gic>;
24+
#address-cells = <0x02>;
25+
#size-cells = <0x02>;
26+
27+
chosen {
28+
zephyr,console = &sbsa;
29+
zephyr,shell-uart = &sbsa;
30+
zephyr,sram = &ram;
31+
};
32+
33+
cpus {
34+
#address-cells = <0x01>;
35+
#size-cells = <0x00>;
36+
37+
cpu@0 {
38+
device_type = "cpu";
39+
compatible = "arm,armv8";
40+
enable-method = "psci";
41+
reg = <0x00>;
42+
};
43+
};
44+
45+
psci {
46+
compatible = "arm,psci-1.0", "arm,psci-0.2", "arm,psci";
47+
method = "hvc";
48+
label = "PSCI";
49+
};
50+
51+
ram: memory@40000000 {
52+
device_type = "mmio-sram";
53+
reg = <0x00 0x40000000 0x00 DT_SIZE_M(16)>;
54+
};
55+
56+
gic: interrupt-controller@3001000 {
57+
compatible = "arm,gic";
58+
label = "GIC";
59+
#interrupt-cells = <0x04>;
60+
#address-cells = <0x00>;
61+
interrupt-controller;
62+
reg = <0x00 0x3001000 0x00 0x1000 0x00 0x3002000 0x00 0x2000>;
63+
};
64+
65+
timer {
66+
compatible = "arm,arm-timer";
67+
interrupts = <GIC_PPI 0x0d IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY
68+
GIC_PPI 0x0e IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY
69+
GIC_PPI 0x0b IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
70+
interrupt-parent = <&gic>;
71+
label = "arch_timer";
72+
};
73+
74+
hypervisor: hypervisor@38000000 {
75+
compatible = "xen,xen-4.15", "xen,xen";
76+
reg = <0x00 0x38000000 0x00 0x1000000>;
77+
interrupts = <GIC_PPI 0x0f IRQ_TYPE_EDGE IRQ_DEFAULT_PRIORITY>;
78+
interrupt-parent = <&gic>;
79+
};
80+
81+
sbsa: sbsa-pl011@22000000 {
82+
compatible = "arm,sbsa-uart";
83+
reg = <0x00 0x22000000 0x00 0x1000>;
84+
interrupts = <GIC_SPI 0x00 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
85+
interrupt-parent = <&gic>;
86+
current-speed = <0x1c200>;
87+
label = "UART";
88+
};
89+
};

boards/arm/xenvm/xenvm_defconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CONFIG_SOC_XENVM=y
2+
CONFIG_BOARD_XENVM=y
3+
4+
# Enable UART driver
5+
CONFIG_SERIAL=y
6+
7+
CONFIG_XIP=n
8+
CONFIG_FLASH_BASE_ADDRESS=0x0
9+
CONFIG_FLASH_SIZE=0
10+
CONFIG_AARCH64_IMAGE_HEADER=y
11+
CONFIG_MAX_XLAT_TABLES=10
12+
13+
# Enable console
14+
CONFIG_CONSOLE=y
15+
CONFIG_UART_CONSOLE=y
16+
17+
# Enable serial port
18+
CONFIG_UART_PL011=y
19+
CONFIG_UART_PL011_SBSA=y
20+
CONFIG_UART_INTERRUPT_DRIVEN=n

soc/arm/xenvm/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_library_sources_ifdef(CONFIG_ARM_MMU mmu_regions.c)

soc/arm/xenvm/Kconfig.defconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2020 EPAM Systems
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if SOC_XENVM
5+
6+
config SOC
7+
default "xenvm"
8+
9+
config NUM_IRQS
10+
int
11+
default 500
12+
13+
config SYS_CLOCK_HW_CYCLES_PER_SEC
14+
int
15+
default 8320000
16+
17+
endif

soc/arm/xenvm/Kconfig.soc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2020 EPAM Systems
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_XENVM
5+
bool "Xen virtual machine on aarch64"
6+
select ARM
7+
select ARM64
8+
select ARM_ARCH_TIMER
9+
select GIC_V2
10+
select CPU_CORTEX_A72

soc/arm/xenvm/linker.ld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright 2020 EPAM Systems
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <autoconf.h>
8+
#include <arch/arm/aarch64/scripts/linker.ld>

0 commit comments

Comments
 (0)