From 62dc8dc14aeb409b67073005ef631168c2263c66 Mon Sep 17 00:00:00 2001 From: Guoqi Xie Date: Sat, 23 Nov 2024 16:16:41 +0800 Subject: [PATCH] Board: support doc for fvp platform Added support for the use of the FVP platform, and improved the related documentation tutorials. Signed-off-by: Guoqi Xie --- .gitignore | 2 + auto_zvm.sh | 24 ++-- .../fvp_cortex_a55x4_a75x2_smp.dts | 3 - .../fvp_cortex_a55x4_a75x2_smp_defconfig | 3 - .../boards/fvp_cortex_a55x4_a75x2_smp.conf | 29 +++++ .../boards/fvp_cortex_a55x4_a75x2_smp.overlay | 108 +++++++++++++----- subsys/virtualization/os/CMakeLists.txt | 2 +- subsys/virtualization/vm_device.c | 7 +- zvm_doc/4_Run_on_ROC_RK3568_PC.rst | 4 +- zvm_doc/5_Run_on_ARM64_FVP.rst | 84 ++++++++++++++ 10 files changed, 209 insertions(+), 57 deletions(-) create mode 100644 zvm_doc/5_Run_on_ARM64_FVP.rst diff --git a/.gitignore b/.gitignore index 60d48244a..e5dca9281 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ build*/ !tests/drivers/build_all cscope.* .dir +*.launch /*.patch @@ -67,3 +68,4 @@ todo # ignore Image zvm_config/qemu_platform/hub/* +zvm_config/fvp_platform/hub/* diff --git a/auto_zvm.sh b/auto_zvm.sh index c3ea5298d..c0a0b4850 100755 --- a/auto_zvm.sh +++ b/auto_zvm.sh @@ -72,23 +72,13 @@ elif [ "$OPS" = "${ops_array[1]}" ]; then # gdb-multiarch -q -ex 'file ./build/zephyr/zvm_host.elf' -ex 'target remote localhost:1234' elif [ "$PLAT" = "${plat_array[1]}" ]; then - /opt/arm/developmentstudio-2021.2/bin/FVP_Base_Cortex-A55x4+Cortex-A75x2 \ - /path-to/FVP_Base_RevC-2xAEMvA \ - -C pctl.startup=0.0.0.* \ - -C bp.secure_memory=0 \ - -C cache_state_modelled=0 \ - -C bp.pl011_uart0.untimed_fifos=1 -C bp.pl011_uart0.unbuffered_output=1 -C bp.pl011_uart0.out_file=uart0.log \ - -C bp.pl011_uart1.out_file=uart1.log \ - -C bp.terminal_0.terminal_command=/usr/bin/gnome-terminal -C bp.terminal_0.mode=raw \ - -C bp.terminal_1.terminal_command=/usr/bin/gnome-terminal -C bp.terminal_1.mode=raw \ - -C bp.secureflashloader.fname=/path-to/bl1.bin \ - -C bp.flashloader0.fname=/path-to/fip.bin \ - -C bp.ve_sysregs.mmbSiteDefault=0 -C bp.ve_sysregs.exit_on_shutdown=1 \ - --data cluster0.cpu0=/path-to/zephyr.bin@0xa0000000 \ - --data cluster0.cpu0=/path-to/Image@0xb0000000 \ - --data cluster0.cpu0=/path-to/fvp-base-gicv3-psci.dtb@0xc0000000 \ - --cpulimit 4 \ - --iris-server +### export lib for Foundation_Platform, sometimes some lib may not be found +## export LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib + $(pwd)/zvm_config/fvp_platform/hub/Foundation_Platformpkg/models/Linux64_armv8l_GCC-9.3/Foundation_Platform \ + --no-secure-memory --cores 4 --arm-v8.1 --quantum=10000\ + --image $(pwd)/build/zephyr/zvm_host.elf \ + --nsdata $(pwd)/zvm_config/fvp_platform/hub/zephyr.elf@0xa0000000 \ + --cadi-server --print-port-number else echo "Error arguments for this auto.sh! \n Please input command like: ./z_auto.sh build qemu. " fi diff --git a/boards/arm64/fvp_cortex_a55x4_a75x2_smp/fvp_cortex_a55x4_a75x2_smp.dts b/boards/arm64/fvp_cortex_a55x4_a75x2_smp/fvp_cortex_a55x4_a75x2_smp.dts index 976acd522..ca4a65067 100644 --- a/boards/arm64/fvp_cortex_a55x4_a75x2_smp/fvp_cortex_a55x4_a75x2_smp.dts +++ b/boards/arm64/fvp_cortex_a55x4_a75x2_smp/fvp_cortex_a55x4_a75x2_smp.dts @@ -113,7 +113,6 @@ }; uart0: uart@1c090000 { - compatible = "arm,pl011"; reg = <0x0 0x1c090000 0x0 0x1000>; status = "disabled"; @@ -125,13 +124,11 @@ }; flash0: flash@0 { - compatible = "soc-nv-flash"; reg = <0x0 0x0 0x0 DT_SIZE_K(64)>; }; dram0: memory@80000000 { - compatible = "mmio-dram"; reg = <0x0 0x80000000 0x0 DT_SIZE_M(2048)>; }; diff --git a/boards/arm64/fvp_cortex_a55x4_a75x2_smp/fvp_cortex_a55x4_a75x2_smp_defconfig b/boards/arm64/fvp_cortex_a55x4_a75x2_smp/fvp_cortex_a55x4_a75x2_smp_defconfig index 145123d43..75d99901a 100644 --- a/boards/arm64/fvp_cortex_a55x4_a75x2_smp/fvp_cortex_a55x4_a75x2_smp_defconfig +++ b/boards/arm64/fvp_cortex_a55x4_a75x2_smp/fvp_cortex_a55x4_a75x2_smp_defconfig @@ -28,11 +28,8 @@ CONFIG_UART_PL011_PORT0=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y - # make more table for host's pgd CONFIG_MAX_XLAT_TABLES=16 -# make more table for vm's pgd -CONFIG_ZVM_MAX_XLAT_TABLES=128 #enable CONFIG_SMP=y diff --git a/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.conf b/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.conf index e69de29bb..45c99967c 100644 --- a/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.conf +++ b/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.conf @@ -0,0 +1,29 @@ +# Project configuration +# Copyright 2022-2023 HNU-ESNL + +#ARMV8 NO-SECURE MODE +CONFIG_ARMV8_A_NS=y + +# kernel vm size(16M virt ram start + size) +# It is the virt size of kernel, must bigger than true kernel size. +CONFIG_KERNEL_VM_SIZE=0x40000000 + +# uart +CONFIG_UART_PL011_PORT1=n + +# vgic device. +CONFIG_VM_VGICV3=y + +# vuart device. +CONFIG_VM_SERIAL1=y +CONFIG_VM_SERIAL2=y + +# make more table for vm's pgd +CONFIG_ZVM_ZEPHYR_MAX_XLAT_TABLES=512 +CONFIG_ZVM_LINUX_MAX_XLAT_TABLES=10240 + +# enable vm device below: +CONFIG_VM_VIRTIO_MMIO=y +CONFIG_VM_VIRTIO_BLOCK=y +CONFIG_MEM_INIT_PRIORITY=59 +CONFIG_MEMRW_INIT_PRIORITY=60 diff --git a/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.overlay b/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.overlay index 090a475ce..5f7ad9c94 100644 --- a/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.overlay +++ b/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.overlay @@ -5,48 +5,94 @@ */ /{ + + aliases { + vmvirtio1 = "/soc/virtio_mmio@1c130000"; + vmvirtio2 = "/soc/virtio_mmio@1c131000"; + linuxcpy = "/soc/linux_cpy@e0000000"; + linuxrfs = "/soc/linux_rootfs@e4000000"; + /*Passthrough device.*/ + ptdevice1 = "/soc/pass_through_device/uart@1c0a0000"; + ptdevice2 = "/soc/pass_through_device/uart@1c0b0000"; + }; + + chosen { + vm,console = &uart0; + zephyr_pcie_controller = "/soc/pcie@4010000000"; + }; + soc { - /* VM's uart0 here! */ - uart1: uart@1c0a0000 { - - compatible = "arm,pl011"; - reg = <0x0 0x1c0a0000 0x0 0x1000>; - status = "disabled"; - interrupts = ; // - interrupt-names = "irq_0"; - label = "UART_1"; - clocks = <&uartclk>; - }; - - /* VM's uart1 here! */ - uart2: uart@1c0b0000 { - - compatible = "arm,pl011"; - reg = <0x0 0x1c0b0000 0x0 0x1000>; - status = "disabled"; - interrupts = ; // - interrupt-names = "irq_0"; - label = "UART_2"; - clocks = <&uartclk>; - }; + virtio_mmio@1c130000 { + interrupts = ; + reg = <0x00 0x1c130000 0x00 0x1000>; + compatible = "virtio,mmio"; + device_type = "virtio"; + virtio_type = <2>; + }; + + virtio_mmio@1c131000 { + interrupts = ; + reg = <0x00 0x1c131000 0x00 0x1000>; + compatible = "virtio,mmio"; + device_type = "virtio"; + virtio_type = <2>; + }; + + linux_cpy@e0000000 { + reg = <0x0 0xe0000000 0x0 DT_SIZE_M(64)>; + }; + + linux_rootfs@e4000000 { + reg = <0x0 0xe4000000 0x0 DT_SIZE_M(180)>; + }; + + pass_through_device { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + uart1: uart@1c0a0000 { + + compatible = "arm,pl011"; + reg = <0x0 0x1c0a0000 0x0 0x1000>; + status = "disabled"; + interrupts = ; // + interrupt-names = "irq_0"; + label = "UART_1"; + clocks = <&uartclk>; + }; + + uart2: uart@1c0b0000 { + + compatible = "arm,pl011"; + reg = <0x0 0x1c0b0000 0x0 0x1000>; + status = "disabled"; + interrupts = ; // + interrupt-names = "irq_0"; + label = "UART_2"; + clocks = <&uartclk>; + }; + + }; + }; - /*TODO: The device that used by vm will be added below. */ vm_zephyr_space { #address-cells = <2>; #size-cells = <2>; compatible = "zephyr-vm"; dtb_address = <0xa9000000>; dtb_size = ; + vcpu_num = <0x01>; - memory@a0000000 { + zephyr_ddr: memory@a0000000 { compatible = "vm-dram"; - memmap_type = "dirct"; address_type = "normal_memory"; vm_reg_base = <0x88000000>; - reg = <0x0 0xa0000000 0x0 DT_SIZE_M(2)>; /* zephyr vm memory size (2M) */ + vm_reg_size = ; + reg = <0x0 0xa0000000 0x0 DT_SIZE_M(2)>; label = "VM0_MEM"; }; @@ -58,14 +104,16 @@ compatible = "linux-vm"; dtb_address = <0xc0000000>; dtb_size = ; + vcpu_num = <0x01>; + rootfs_address = <0xf8000000>; - memory@b0000000 { + linux_ddr: memory@b0000000 { compatible = "vm-dram"; - memmap_type = "dirct"; address_type = "normal_memory"; vm_reg_base = <0x80000000>; - reg = <0x0 0xb0000000 0x0 DT_SIZE_M(1024)>; /* linux vm memory size (1G)*/ + vm_reg_size = ; + reg = <0x0 0xb0000000 0x0 DT_SIZE_M(1024)>; label = "VM1_MEM"; }; }; diff --git a/subsys/virtualization/os/CMakeLists.txt b/subsys/virtualization/os/CMakeLists.txt index 542554003..91417cdae 100644 --- a/subsys/virtualization/os/CMakeLists.txt +++ b/subsys/virtualization/os/CMakeLists.txt @@ -1,5 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -# Copyright 2021-2022 HNU +# Copyright 2021-2022 HNU-ESNL zephyr_sources_ifdef( CONFIG_ZVM diff --git a/subsys/virtualization/vm_device.c b/subsys/virtualization/vm_device.c index 3d0312446..c37effa04 100644 --- a/subsys/virtualization/vm_device.c +++ b/subsys/virtualization/vm_device.c @@ -401,18 +401,21 @@ int vm_device_init(struct vm *vm) int ret, i; sys_dlist_init(&vm->vdev_list); + +#ifdef CONFIG_VM_SHMEM ret = vm_mem_create(vm); if (ret) { ZVM_LOG_WARN("Init vm mem error! \n"); return -EMMAO; } - +#endif +#ifdef CONFIG_VM_SHMEMRW ret = vm_mem_rw_create(vm); if (ret) { ZVM_LOG_WARN("Init vm mem_rw error! \n"); return -EMMAO; } - +#endif /* Assign ids to virtual devices. */ for (i = 0; i < zvm_virtual_devices_count_get(); i++) { const struct virtual_device_instance *virtual_device = zvm_virtual_device_get(i); diff --git a/zvm_doc/4_Run_on_ROC_RK3568_PC.rst b/zvm_doc/4_Run_on_ROC_RK3568_PC.rst index 870673e22..2d28f6f07 100644 --- a/zvm_doc/4_Run_on_ROC_RK3568_PC.rst +++ b/zvm_doc/4_Run_on_ROC_RK3568_PC.rst @@ -202,7 +202,7 @@ uart3: 用作主机shell控制 具体主机如何连接到串口uart3,需要看不同板卡的设计手册并自主引出串口线。 -4. 串口调试说明 +5. 串口调试说明 ----------------------- 前面已经说过,本文给到的例子中,涉及的串口为uart2,3,9。即正常启动两个虚拟机时两个虚拟机各 分配一个串口。现有的sample中分配如下: @@ -322,3 +322,5 @@ uart3: 用作主机shell控制 最后,编写自动启动虚拟机的代码,将其编译进zvm_host.bin中即可。 `Prev>> 在QEMU上运行ZVM `__ + +`Next>> 在ARM FVP上运行ZVM `__ diff --git a/zvm_doc/5_Run_on_ARM64_FVP.rst b/zvm_doc/5_Run_on_ARM64_FVP.rst new file mode 100644 index 000000000..f297834b8 --- /dev/null +++ b/zvm_doc/5_Run_on_ARM64_FVP.rst @@ -0,0 +1,84 @@ +在ARM FVP Model上运行ZVM +====================== + +1. 构建面向fvp_cortex_a55x4_a75x2平台的ZVM镜像 +----------------------- + +拉取镜像并进入工作区: + +.. code:: shell + + cd ~/zvm_workspace/zvm + +1) 使用脚本文件构建ZVM镜像: + +.. code:: shell + + ./auto_zvm.sh build fvp_cortex_a55x4_a75x2_smp + +或者使用命令行构建镜像: + +.. code:: shell + + west build -b fvp_cortex_a55x4_a75x2_smp samples/_zvm + + +2) 生成ZVM镜像文件如下: + +.. code:: shell + + build/zephyr/zvm_host.elf + + +2. FVP Model 平台下载 +------------------------------- + +这里使用的平台是 Foundation_Platform, 该平台是ARM提供的一个FVP模型,可以模拟ARM的处理器。 +具体可以通过如下方式下载: + +1)进入 www.arm.com 的官网,并注册账号(arm 的免费软件需要注册才能下载)。 + +2)然后访问如下地址下载- `[Armv-A Foundation AEM FVP (x86 Linux)] +`__ + +3) 下载完成后,可以在如下网址找到使用文档:`[Fixed Virtual Platforms] `__ 。 +随后,解压到自己的软件下载目录(建议直接放到zvm_workspace/zvm/zvm_config/fvp_platform/hub目录下,后面直接使用脚本即可): + +.. code:: shell + + tar zxvf Foundation_Platform_11.27_19_Linux64_armv8l.tgz + +4) 解压后,可以在models目录下找到 `Foundation_Platform` 可执行文件,可以在该目录下运行如下命令测试是否安装成功: + +.. code:: shell + + ./Foundation_Platform --image ../../examples/hello.axf + +成功会输出`Hello, 64-bit world!`。 + + +3. FVP Model 平台运行ZVM +------------------------------- + +首先拉取需要使用的镜像并进入工作区: + +.. code:: shell + cd ../ #返回到zvm_workspace + git clone https://gitee.com/hnu-esnl/zvm_vm_image.git + +其中,需要的镜像在fvp_platform目录下: + +.. code:: shell + + zvm_vm_image/fvp_platform/hub/* #启动需要的镜像文件 + +将其复制到zvm_workspace/zvm/zvm_config/fvp_platform/hub目录,然后进入zvm_workspace/zvm目录下, +执行如下命令开始调试: + +.. code:: shell + + ./auto_zvm.sh debugserver fvp_cortex_a55x4_a75x2_smp + +等待弹出zvm_host#的窗口即可。 + +`Prev>> 在RK3568上运行ZVM `__ -- Gitee