From 8c9108a2ecf007f36b89184403d61abf852fdac5 Mon Sep 17 00:00:00 2001 From: Christopher Guikema Date: Tue, 30 Jan 2024 19:30:28 -0800 Subject: [PATCH] vm_virtio_net: add zcu102 support (#57) Signed-off-by: Chris Guikema --- apps/Arm/vm_virtio_net/CMakeLists.txt | 122 +++++++++++++----- .../init_scripts/zynqmp/arping_test | 31 +++++ .../init_scripts/zynqmp/ping_test | 31 +++++ apps/Arm/vm_virtio_net/settings.cmake | 8 +- .../zcu102/2022_1/devices.camkes | 104 +++++++++++++++ 5 files changed, 262 insertions(+), 34 deletions(-) create mode 100755 apps/Arm/vm_virtio_net/overlay_files/init_scripts/zynqmp/arping_test create mode 100755 apps/Arm/vm_virtio_net/overlay_files/init_scripts/zynqmp/ping_test create mode 100644 apps/Arm/vm_virtio_net/zcu102/2022_1/devices.camkes diff --git a/apps/Arm/vm_virtio_net/CMakeLists.txt b/apps/Arm/vm_virtio_net/CMakeLists.txt index 77fca436..ca3859c4 100644 --- a/apps/Arm/vm_virtio_net/CMakeLists.txt +++ b/apps/Arm/vm_virtio_net/CMakeLists.txt @@ -13,6 +13,8 @@ include(${CAMKES_ARM_VM_HELPERS_PATH}) find_package(camkes-vm-linux REQUIRED) include(${CAMKES_VM_LINUX_HELPERS_PATH}) +set(cpp_includes "${CAMKES_VM_DIR}/components/VM_Arm") + set(dtb_file "${CAMKES_VM_IMAGES_DIR}/${KernelARMPlatform}/linux-dtb") set(rootfs_file "${CAMKES_VM_IMAGES_DIR}/${KernelARMPlatform}/rootfs.cpio.gz") @@ -26,6 +28,34 @@ elseif("${KernelARMPlatform}" STREQUAL "tx2") set(rootfs_address "0xf7000000") set(dtb_file "${CAMKES_VM_IMAGES_DIR}/${KernelARMPlatform}/linux-pci-dtb") set(rootfs_file "${CAMKES_VM_IMAGES_DIR}/${KernelARMPlatform}/rootfs_crossvm.cpio.gz") + +elseif("${KernelARMPlatform}" STREQUAL "zcu102") + + if(NOT VmZynqmpPetalinux2022_1) + message(FATAL_ERROR "Petalinux 2022_1 is the only supported version for this application") + endif() + + set(dts_file "${CAMKES_VM_IMAGES_DIR}/zynqmp/${VmZynqmpPetalinuxVersion}/linux.dts") + set( + rootfs_file + "${CAMKES_VM_IMAGES_DIR}/zynqmp/${VmZynqmpPetalinuxVersion}/rootfs-minimal.cpio.gz" + ) + + add_custom_command( + OUTPUT linux/linux-dtb + COMMAND + dtc -q -I dts -O dtb -o linux/linux-dtb ${dts_file} + VERBATIM + DEPENDS ${dts_file} + ) + + # Create custom target for setting the dtb + add_custom_target(set_dtb DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/linux/linux-dtb") + AddToFileServer("linux-dtb" "${CMAKE_CURRENT_BINARY_DIR}/linux/linux-dtb" DEPENDS set_dtb) + + list(APPEND cpp_includes "${CAMKES_VM_DIR}/components/VM_Arm/plat_include/zynqmp") + + CAmkESAddImportPath(${KernelARMPlatform}/${VmZynqmpPetalinuxVersion}) endif() # Generate overlayed rootfs @@ -37,19 +67,47 @@ AddFileToOverlayDir( ) if(VIRTIO_NET_PING) - AddFileToOverlayDir( - "S90ping_test" - ${CMAKE_CURRENT_SOURCE_DIR}/overlay_files/init_scripts/ping_test - "etc/init.d" - overlay - ) + if("${KernelARMPlatform}" STREQUAL "zcu102") + set(name "ping_test") + set(file "${CMAKE_CURRENT_SOURCE_DIR}/overlay_files/init_scripts/zynqmp/ping_test") + else() + set(file "${CMAKE_CURRENT_SOURCE_DIR}/overlay_files/init_scripts/ping_test") + set(name "S90ping_test") + endif() + + AddFileToOverlayDir(${name} ${file} "etc/init.d" overlay) + + # The ZCU102 Filesystem expects init scripts to be setup like this, else they won't run + if("${KernelARMPlatform}" STREQUAL "zcu102") + AddLinkToOverlayDir("K20ping_test" "../init.d/ping_test" "etc/rc0.d/" overlay) + AddLinkToOverlayDir("K20ping_test" "../init.d/ping_test" "etc/rc1.d/" overlay) + AddLinkToOverlayDir("K20ping_test" "../init.d/ping_test" "etc/rc6.d/" overlay) + AddLinkToOverlayDir("S20ping_test" "../init.d/ping_test" "etc/rc2.d/" overlay) + AddLinkToOverlayDir("S20ping_test" "../init.d/ping_test" "etc/rc3.d/" overlay) + AddLinkToOverlayDir("S20ping_test" "../init.d/ping_test" "etc/rc4.d/" overlay) + AddLinkToOverlayDir("S20ping_test" "../init.d/ping_test" "etc/rc5.d/" overlay) + endif() else() - AddFileToOverlayDir( - "S90arping_test" - ${CMAKE_CURRENT_SOURCE_DIR}/overlay_files/init_scripts/arping_test - "etc/init.d" - overlay - ) + if("${KernelARMPlatform}" STREQUAL "zcu102") + set(name "arping_test") + set(file "${CMAKE_CURRENT_SOURCE_DIR}/overlay_files/init_scripts/zynqmp/arping_test") + else() + set(file "${CMAKE_CURRENT_SOURCE_DIR}/overlay_files/init_scripts/arping_test") + set(name "S90arping_test") + endif() + + AddFileToOverlayDir(${name} ${file} "etc/init.d" overlay) + + # The ZCU102 Filesystem expects init scripts to be setup like this, else they won't run + if("${KernelARMPlatform}" STREQUAL "zcu102") + AddLinkToOverlayDir("K20arping_test" "../init.d/arping_test" "etc/rc0.d/" overlay) + AddLinkToOverlayDir("K20arping_test" "../init.d/arping_test" "etc/rc1.d/" overlay) + AddLinkToOverlayDir("K20arping_test" "../init.d/arping_test" "etc/rc6.d/" overlay) + AddLinkToOverlayDir("S20arping_test" "../init.d/arping_test" "etc/rc2.d/" overlay) + AddLinkToOverlayDir("S20arping_test" "../init.d/arping_test" "etc/rc3.d/" overlay) + AddLinkToOverlayDir("S20arping_test" "../init.d/arping_test" "etc/rc4.d/" overlay) + AddLinkToOverlayDir("S20arping_test" "../init.d/arping_test" "etc/rc5.d/" overlay) + endif() endif() AddOverlayDirToRootfs( @@ -62,20 +120,24 @@ AddOverlayDirToRootfs( GZIP ) -# Updated dtb based on generated initrd -UpdateDtbFromInitrd( - ${dtb_file} - ${output_overlayed_rootfs_location} - ${rootfs_address} - dtb_gen_target - output_dtb_location - DEPENDS - rootfs_target -) - -AddToFileServer("linux-dtb" "${output_dtb_location}" DEPENDS dtb_gen_target) AddToFileServer("linux-initrd" ${output_overlayed_rootfs_location} DEPENDS rootfs_target) -AddToFileServer("linux" "${CAMKES_VM_IMAGES_DIR}/${KernelARMPlatform}/linux") + +if("${KernelARMPlatform}" STREQUAL "zcu102") + AddToFileServer("linux" "${CAMKES_VM_IMAGES_DIR}/zynqmp/${VmZynqmpPetalinuxVersion}/linux") +else() + # Updated dtb based on generated initrd + UpdateDtbFromInitrd( + ${dtb_file} + ${output_overlayed_rootfs_location} + ${rootfs_address} + dtb_gen_target + output_dtb_location + DEPENDS + rootfs_target + ) + AddToFileServer("linux" "${CAMKES_VM_IMAGES_DIR}/${KernelARMPlatform}/linux") + AddToFileServer("linux-dtb" "${output_dtb_location}" DEPENDS dtb_gen_target) +endif() AddCamkesCPPFlag( cpp_flags @@ -102,19 +164,13 @@ if(VIRTIO_NET_PING) sel4_autoconf ) - DeclareCAmkESRootserver( - vm_echo_ping.camkes - CPP_FLAGS - ${cpp_flags} - CPP_INCLUDES - ${CAMKES_VM_DIR}/components/VM_Arm - ) + DeclareCAmkESRootserver(vm_echo_ping.camkes CPP_FLAGS ${cpp_flags} CPP_INCLUDES ${cpp_includes}) else() DeclareCAmkESRootserver( vm_virtio_net.camkes CPP_FLAGS ${cpp_flags} CPP_INCLUDES - ${CAMKES_VM_DIR}/components/VM_Arm + ${cpp_includes} ) endif() diff --git a/apps/Arm/vm_virtio_net/overlay_files/init_scripts/zynqmp/arping_test b/apps/Arm/vm_virtio_net/overlay_files/init_scripts/zynqmp/arping_test new file mode 100755 index 00000000..77e0f7dc --- /dev/null +++ b/apps/Arm/vm_virtio_net/overlay_files/init_scripts/zynqmp/arping_test @@ -0,0 +1,31 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: arping_test +# Required-Start: $networking +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 1 +# Short-Description: Configure virtio-net device +### END INIT INFO + +# +# Copyright 2019, Data61, CSIRO (ABN 41 687 119 230) +# Copyright 2024, DornerWorks +# +# SPDX-License-Identifier: BSD-2-Clause +# + +echo "Testing arping on virtual interface:" > /dev/console + +# Petalinux 2022.1 doesn't seem to like the /etc/network/interfaces file +eth0_ip="192.168.1.1" +ifconfig eth0 $eth0_ip + +arping 192.168.1.2 -c 5 -w 2 +# Success code for arping: 0 (arping returns non-zero value if packet count and timeout is not met) +if [ $? -eq 0 ] +then + echo "arping test was successful" > /dev/console +else + echo "arping test failed" > /dev/console +fi diff --git a/apps/Arm/vm_virtio_net/overlay_files/init_scripts/zynqmp/ping_test b/apps/Arm/vm_virtio_net/overlay_files/init_scripts/zynqmp/ping_test new file mode 100755 index 00000000..66578504 --- /dev/null +++ b/apps/Arm/vm_virtio_net/overlay_files/init_scripts/zynqmp/ping_test @@ -0,0 +1,31 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: ping_test +# Required-Start: $networking +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 1 +# Short-Description: Configure virtio-net device +### END INIT INFO + +# +# Copyright 2019, Data61, CSIRO (ABN 41 687 119 230) +# Copyright 2024, DornerWorks +# +# SPDX-License-Identifier: BSD-2-Clause +# + +echo "Testing ping on virtual interface:" > /dev/console + +# Petalinux 2022.1 doesn't seem to like the /etc/network/interfaces file +eth0_ip="192.168.1.1" +ifconfig eth0 $eth0_ip + +ping 192.168.1.2 -v -c 5 -W 2 +# Success code for Ping: 0 (Ping returns non-zero value if packet count and timeout is not met) +if [ $? -eq 0 ] +then + echo "Ping test was successful" > /dev/console +else + echo "Ping test failed" > /dev/console +fi diff --git a/apps/Arm/vm_virtio_net/settings.cmake b/apps/Arm/vm_virtio_net/settings.cmake index 18a00b4d..422b1c35 100644 --- a/apps/Arm/vm_virtio_net/settings.cmake +++ b/apps/Arm/vm_virtio_net/settings.cmake @@ -4,7 +4,7 @@ # SPDX-License-Identifier: BSD-2-Clause # -set(supported "exynos5422;tx2") +set(supported "exynos5422;tx2;zcu102") if(NOT "${PLATFORM}" IN_LIST supported) message(FATAL_ERROR "PLATFORM: ${PLATFORM} not supported. Supported: ${supported}") @@ -18,3 +18,9 @@ else() endif() set(VmInitRdFile ON CACHE BOOL "" FORCE) set(VmDtbFile ON CACHE BOOL "provide dtb" FORCE) + +if(${PLATFORM} STREQUAL "zcu102") + set(AARCH64 ON CACHE BOOL "" FORCE) + set(KernelAllowSMCCalls ON CACHE BOOL "" FORCE) + set(VmZynqmpPetalinuxVersion 2022_1 CACHE STRING "" FORCE) +endif() diff --git a/apps/Arm/vm_virtio_net/zcu102/2022_1/devices.camkes b/apps/Arm/vm_virtio_net/zcu102/2022_1/devices.camkes new file mode 100644 index 00000000..a3758580 --- /dev/null +++ b/apps/Arm/vm_virtio_net/zcu102/2022_1/devices.camkes @@ -0,0 +1,104 @@ +/* + * Copyright 2023, DornerWorks + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +#define VM_INITRD_MAX_SIZE 0x1900000 //25 MB +#define VM_RAM_BASE 0x10000000 +#define VM_RAM_SIZE 0x10000000 +#define VM_ENTRY_ADDR 0x10080000 +#define VM_RAM_OFFSET 0 +#define VM_DTB_ADDR 0x12000000 +#define VM_INITRD_ADDR 0x13000000 + +assembly { + composition {} + configuration { + + vm0.vm_address_config = { + "ram_base" : VAR_STRINGIZE(VM_RAM_BASE), + "ram_paddr_base" : VAR_STRINGIZE(VM_RAM_BASE), + "ram_size" : VAR_STRINGIZE(VM_RAM_SIZE), + "dtb_addr" : VAR_STRINGIZE(VM_DTB_ADDR), + "initrd_addr" : VAR_STRINGIZE(VM_INITRD_ADDR), + "kernel_entry_addr" : VAR_STRINGIZE(VM_ENTRY_ADDR), + }; + vm0.num_vcpus = 4; + + /* Extra untyped pool to allow for 256MB of RAM */ + vm0.simple_untyped28_pool = 1; + + vm0.vm_image_config = { + "kernel_name" : "linux", + "initrd_name" : "linux-initrd", + "dtb_base_name" : "linux-dtb", + "kernel_bootcmdline" : "console=ttyPS0,115200 root=/dev/ram rw earlycon clk_ignore_unused net.ifnames=0", + "kernel_stdout" : "serial0:115200n8", + "generate_dtb" : true, + "provide_dtb" : false, + "map_one_to_one" : false, + "provide_initrd": true, + "clean_cache" : false, + }; + + vm0.dtb = dtb([{"path": "/amba/serial@ff000000"} ]); + + vm0.untyped_mmios = ["0xf9060000:12"]; // Interrupt Controller Virtual CPU interface (Virtual Machine view) + + vm0.plat_keep_devices = [ + "/pss_ref_clk", + "/gt_crx_ref_clk", + "/pss_alt_ref_clk", + "/aux_ref_clk", + "/video_clk", + "/pmu", + "/psci", + "/timer", + "/aliases", + "/axi/interrupt-controller@f9010000", + "/axi/serial@ff000000", + ]; + + vm0.plat_keep_devices_and_subtree = [ + "/firmware", + ]; + + vm0.allow_smc = true; + vm0.allowed_smc_functions = [ + SMC_PM_GET_API_VERSION, + SMC_PM_REQUEST_NODE, + SMC_PM_RELEASE_NODE, + SMC_PM_SET_REQUIREMENT, + SMC_PM_INIT_FINALIZE, + SMC_PM_FPGA_GET_STATUS, + SMC_PM_RESET_ASSERT, + SMC_PM_RESET_GET_STATUS, + SMC_PM_MMIO_WRITE, + SMC_PM_MMIO_READ, + SMC_PM_GET_CHIPID, + SMC_PM_PINCTRL_REQUEST, + SMC_PM_PINCTRL_RELEASE, + SMC_PM_PINCTRL_SET_FUNCTION, + SMC_PM_PINCTRL_CONFIG_PARAM_GET, + SMC_PM_PINCTRL_CONFIG_PARAM_SET, + SMC_PM_IOCTL, + SMC_PM_QUERY_DATA, + SMC_PM_CLOCK_ENABLE, + SMC_PM_CLOCK_DISABLE, + SMC_PM_CLOCK_GETSTATE, + SMC_PM_CLOCK_SETDIVIDER, + SMC_PM_CLOCK_GETDIVIDER, + SMC_PM_CLOCK_GETPARENT, + SMC_PM_GET_TRUSTZONE_VERSION, + SMC_PM_ADD_SUBSYSTEM, + SMC_PM_FEATURE_CHECK, + SMC_IPI_MAILBOX_OPEN, + SMC_IPI_MAILBOX_RELEASE, + SMC_IPI_MAILBOX_ENABLE_IRQ + ]; + } +}