Skip to content

Commit 5207c6f

Browse files
firscityfabiobaltieri
authored andcommitted
snippets: add virtual Xen dom0 snippet support
Zephyr snippets allow to apply pre-defined build configuration and extentions to your build0. It is made by applying generic snippet conf/device-tree changes and may be extended with platform-specific files. It looks like great approach for convertion Zephyr OS build to Xen control domain on different boards, as it requires Kconfig changes and board device tree changes (configuration for memory node, hypervisor console, grant table region etc). Please note, that Xen hypervisor passes all selected parameters via domain device-tree, but Zephyr does not use it in runtime. So, user should keep values in board overlays in sync with real Xen values. Add example and docs for converting qemu_cortex_a53 board to Xen Domain-0 guest. This approach might be used for other boards, where Zephyr Dom0 is needed. Signed-off-by: Mykola Kvach <[email protected]> Signed-off-by: Dmytro Firsov <[email protected]>
1 parent 3942e3c commit 5207c6f

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

snippets/xen_dom0/README.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.. _xen_dom0:
2+
3+
Xen Dom0: universal snippet for XEN control domain
4+
##################################################
5+
6+
Overview
7+
********
8+
9+
This snippet allows user to build Zephyr as a Xen initial domain (Dom0). The feature
10+
is implemented as configuration snippet to allow support for any compatible platform.
11+
12+
How to add support of a new board
13+
*********************************
14+
15+
* add board dts overlay to this snippet which deletes/adds memory and deletes UART nodes;
16+
* add correct memory and hypervisor nodes, based on regions Xen picked for Domain-0 on your setup.
17+
18+
Programming
19+
***********
20+
21+
Correct snippet designation for Xen must
22+
be entered when you invoke ``west build``.
23+
For example:
24+
25+
.. code-block:: console
26+
27+
west build -b qemu_cortex_a53 -S xen_dom0 samples/synchronization
28+
29+
QEMU example with Xen
30+
***********************
31+
32+
Overlay for qemu_cortex_a53 board, that is present in `board/` directory of this snippet is QEMU
33+
Xen control domain example. To run such setup, you need to:
34+
35+
* fetch and build Xen (e.g. RELEASE-4.17.0) for arm64 platform
36+
* take and compile sample device tree from `example/` directory
37+
* build your Zephyr sample/application with `xen_dom0` snippet and start it as Xen control domain
38+
39+
For starting you can use QEMU from Zephyr SDK by following command:
40+
41+
.. code-block:: console
42+
43+
<path to Zephyr SDK>/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-system-aarch64 -cpu cortex-a53 \
44+
-m 6G -nographic -machine virt,gic-version=3,virtualization=true -chardev stdio,id=con,mux=on \
45+
-serial chardev:con -mon chardev=con,mode=readline -pidfile qemu.pid \
46+
-device loader,file=<path to Zephyr app build>/zephyr.bin,addr=0x40600000 \
47+
-dtb <path to DTB>/xen.dtb -kernel <path to Xen build>/xen
48+
49+
This will start you a Xen hypervisor with your application as Xen control domain. To make it usable,
50+
you can add `zephyr-xenlib` by Xen-troops library to your project. It'll provide basic domain
51+
management functionalities - domain creation and configuration.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2023 EPAM Systems
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/delete-node/ &sram0;
8+
9+
&uart0 {
10+
/* Xen consoleio will be used */
11+
status = "disabled";
12+
};
13+
14+
/ {
15+
/*
16+
* This node may differs on different setups, please check
17+
* following line in Xen boot log to set it right:
18+
* (XEN) Grant table range: 0x00000040200000-0x00000040240000
19+
*
20+
* Xen passes actual values for setup in domain device tree, but Zephyr
21+
* is not capable to parse and handle it in runtime.
22+
*/
23+
hypervisor: hypervisor@40200000 {
24+
compatible = "xen,xen";
25+
reg = <0x0 0x40200000 0x0 0x40000>;
26+
interrupts = <GIC_PPI 0x0 IRQ_TYPE_EDGE IRQ_DEFAULT_PRIORITY>;
27+
interrupt-parent = <&gic>;
28+
status = "okay";
29+
};
30+
31+
/*
32+
* This node may differs on different setups, because Xen picks
33+
* region for Domain-0 for every specific configuration. You can
34+
* start Xen for your platform and check following log:
35+
* (XEN) Allocating 1:1 mappings for dom0:
36+
* (XEN) BANK[0] 0x00000058000000-0x00000060000000 (128MB)
37+
*
38+
* Xen passes actual values for setup in domain device tree, but Zephyr
39+
* is not capable to parse and handle it in runtime.
40+
*/
41+
soc {
42+
sram0: memory@58000000 {
43+
device_type = "mmio-sram";
44+
reg = <0x00 0x58000000 0x00 DT_SIZE_M(128)>;
45+
};
46+
};
47+
};

snippets/xen_dom0/snippet.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: xen_dom0
2+
append:
3+
EXTRA_DTC_OVERLAY_FILE: xen_dom0.overlay
4+
EXTRA_CONF_FILE: xen_dom0.conf
5+
6+
boards:
7+
qemu_cortex_a53:
8+
append:
9+
EXTRA_DTC_OVERLAY_FILE: boards/qemu_cortex_a53.overlay

snippets/xen_dom0/xen_dom0.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_XEN_DOM0=y

snippets/xen_dom0/xen_dom0.overlay

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2023 EPAM Systems.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
interrupt-parent = <&gic>;
9+
#address-cells = <2>;
10+
#size-cells = <2>;
11+
12+
chosen {
13+
zephyr,console = &xen_consoleio_hvc;
14+
zephyr,shell-uart = &xen_consoleio_hvc;
15+
};
16+
17+
psci {
18+
method = "hvc";
19+
};
20+
21+
xen_consoleio_hvc: hvc {
22+
compatible = "xen,uart_hvc";
23+
status = "okay";
24+
};
25+
};

0 commit comments

Comments
 (0)