diff --git a/auto_zvm.sh b/auto_zvm.sh index 29aad59b27040cba72ec3bed75b8e628024265b0..c3ea5298dcdeaba24c9db63f4e309af6ab6994ae 100755 --- a/auto_zvm.sh +++ b/auto_zvm.sh @@ -52,8 +52,7 @@ if [ "$OPS" = "${ops_array[0]}" ]; then -DARMFVP_BL1_FILE=$(pwd)/zvm_config/fvp_platform/hub/bl1.bin \ -DARMFVP_FIP_FILE=$(pwd)/zvm_config/fvp_platform/hub/fip.bin elif [ "$PLAT" = "${plat_array[2]}" ]; then - west build -b roc_rk3568_pc_smp samples/_zvm && \ - cp build/zephyr/zvm_host.bin /home/proctor-a/tftp_server/master_test/ + west build -b roc_rk3568_pc_smp samples/_zvm else echo "Error arguments for this auto.sh! \n Please input command like: ./auto_build.sh build qemu. " fi diff --git a/boards/arm64/roc_rk3568_pc/roc_rk3568_pc.dts b/boards/arm64/roc_rk3568_pc/roc_rk3568_pc.dts index d90fbd9eb51cb08003a9fa7516c98da0c8b852d8..ab31fef6a4f77365e695e6de386a8a3cfffe6963 100644 --- a/boards/arm64/roc_rk3568_pc/roc_rk3568_pc.dts +++ b/boards/arm64/roc_rk3568_pc/roc_rk3568_pc.dts @@ -14,12 +14,12 @@ compatible = "rockchip,rk3568"; aliases { - serial2 = &uart2; + serial2 = &uart9; }; chosen { - zephyr,console = &uart2; - zephyr,shell-uart = &uart2; + zephyr,console = &uart9; + zephyr,shell-uart = &uart9; zephyr,sram = &sram0; }; @@ -31,7 +31,7 @@ }; -&uart2 { +&uart9 { status = "okay"; current-speed = <1500000>; }; diff --git a/dts/arm64/rockchip/rk3568.dtsi b/dts/arm64/rockchip/rk3568.dtsi index 9f0b700112bd6ebe73290b92e316fcda07ecf74d..a2f8bb43770fb180c93d14d3c850b26a5dcab29f 100644 --- a/dts/arm64/rockchip/rk3568.dtsi +++ b/dts/arm64/rockchip/rk3568.dtsi @@ -117,14 +117,14 @@ #clock-cells = <0>; }; - uart2: serial@fe6d0000 { + uart9: serial@fe6d0000 { compatible = "rockchip,rk3568-uart", "ns16550"; reg = <0x0 0xfe6d0000 0x0 0x10000>; interrupts = ; clock-frequency = <12000000>; reg-shift = <2>; status = "disabled"; - label = "UART2"; + label = "UART9"; }; }; diff --git a/include/virtualization/zvm.h b/include/virtualization/zvm.h index 9fff1ee0c9dbdba72d916a6b1011ae65541dee77..092c56240dd2698cb40d10b979973d4500b2d43b 100644 --- a/include/virtualization/zvm.h +++ b/include/virtualization/zvm.h @@ -48,10 +48,9 @@ #define EPANO (155) /* Erorr on vm input parameter */ #define EVIRQ (156) /* VM's virq error */ #define EVMOS (157) /* VM's os type error */ -#endif -#define ZVM_EXIT_UNKNOWN (11) -#define ZVM_DEV_NAME_LENGTH (32) +#endif /* CONFIG_ZVM */ + /** * @brief We should define overall priority for zvm system. @@ -74,7 +73,6 @@ #else #define ZVM_LOG_INFO(...) #endif -#define ZVM_PRINTK(...) LOG_PRINTK(__VA_ARGS__) #else diff --git a/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.overlay b/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.overlay index 76d9325ed02889833997e1217ab1643971095d40..090a475ce2b075614b05b87791d81ec59ad42eea 100644 --- a/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.overlay +++ b/samples/_zvm/boards/fvp_cortex_a55x4_a75x2_smp.overlay @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 HNU + * Copyright 2021-2022 HNU-ESNL * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/samples/_zvm/boards/qemu_cortex_max_smp.overlay b/samples/_zvm/boards/qemu_cortex_max_smp.overlay index 5a7f4bb2a32e554053e5a46529370f8b3a35a008..351b2efb45231908862b769cf9aa9bef837ad2b7 100644 --- a/samples/_zvm/boards/qemu_cortex_max_smp.overlay +++ b/samples/_zvm/boards/qemu_cortex_max_smp.overlay @@ -144,7 +144,7 @@ compatible = "zephyr-vm"; dtb_address = <0x00000000>; dtb_size = ; - vcpu_num = <0x02>; + vcpu_num = <0x01>; zephyr_ddr: memory@c8000000 { compatible = "vm-dram"; diff --git a/samples/_zvm/boards/roc_rk3568_pc_smp.overlay b/samples/_zvm/boards/roc_rk3568_pc_smp.overlay index c1eaa70fdcd84e5e73df81b6f6d2e17caec6ba64..38d99bb95911be3100462ea8b891c3cc1ee717b4 100644 --- a/samples/_zvm/boards/roc_rk3568_pc_smp.overlay +++ b/samples/_zvm/boards/roc_rk3568_pc_smp.overlay @@ -23,7 +23,7 @@ }; chosen { - vm,console = &uart9; + vm,console = &uart2; }; @@ -66,8 +66,7 @@ label = "PTUART8"; }; - /* VM1's uart here! rk3568's port num is uart9 */ - uart9: serial@fe660000 { + uart2: serial@fe660000 { compatible = "rockchip,rk3568-uart", "ns16550"; reg = <0x0 0xfe660000 0x0 0x10000>; interrupts = ; @@ -76,7 +75,7 @@ reg-shift = <2>; status = "reserved"; current-speed = <1500000>; - label = "UART9"; + label = "UART2"; }; gpio3: gpio@fe760000 { diff --git a/samples/_zvm/prj.conf b/samples/_zvm/prj.conf index 2ec55749a97c70b3f5acdc1468e4a5df7f66c530..ac6d08790449e4e2f0d07f6dc86b71f48f2d79a5 100644 --- a/samples/_zvm/prj.conf +++ b/samples/_zvm/prj.conf @@ -12,6 +12,11 @@ CONFIG_SHELL_THREAD_PRIORITY_OVERRIDE=y CONFIG_SHELL_THREAD_PRIORITY=4 CONFIG_SHELL_PROMPT_UART="zvm_host:~#" +# if CONFIG_SHELL is n, must set CONFIG_GETOPT to y +CONFIG_GETOPT=y +# if CONFIG_SHELL is n, must set CONFIG_THREAD_NAME to y +CONFIG_THREAD_NAME=y + #CPU MASK, this feature work only `CONFIG_SCHED_DUMB` is the selected CONFIG_SCHED_CPU_MASK=y CONFIG_SCHED_CPU_MASK_PIN_ONLY=y diff --git a/samples/_zvm/src/main.c b/samples/_zvm/src/main.c index 0e42864b7f0fcba8eb83b1a721d669f67015e659..4500d7089b779411b6e2b6b61c53e53f9a430c15 100644 --- a/samples/_zvm/src/main.c +++ b/samples/_zvm/src/main.c @@ -1,9 +1,8 @@ /* - * Copyright 2021-2022 HNU - * - * SPDX-License-Identifier: Apache-2.0 - */ - + * Copyright 2021-2022 HNU-ESNL + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include #include @@ -14,12 +13,13 @@ #include #include #include +#include /* For test time slice vm change */ int main(int argc, char **argv) { - printk("--Init zvm successful! --\n"); - printk("--Ready to input shell cmd to create and build vm!--\n"); + ZVM_LOG_INFO("--Init zvm successful! --\n"); + ZVM_LOG_INFO("--Ready to input shell cmd to create and build vm!--\n"); return 0; } diff --git a/subsys/virtualization/CMakeLists.txt b/subsys/virtualization/CMakeLists.txt index 5b578afb0cb43d3a78e3da9e91a1c51d32062e39..1f981d5cffc409de5a330e3d95c9f5c930c19576 100644 --- a/subsys/virtualization/CMakeLists.txt +++ b/subsys/virtualization/CMakeLists.txt @@ -14,6 +14,9 @@ zephyr_sources_ifdef( vm_manager.c vm_mm.c vm.c - zvm_shell.c zvm.c ) + +if(CONFIG_SHELL AND CONFIG_ZVM) + zephyr_sources(zvm_shell.c) +endif() diff --git a/subsys/virtualization/os/os.c b/subsys/virtualization/os/os.c index d82a504027891a08985f67443b85830d613a140d..c738f3cd4e43b72262e56a8b38e4b2dbe395fa70 100644 --- a/subsys/virtualization/os/os.c +++ b/subsys/virtualization/os/os.c @@ -6,7 +6,7 @@ #include #include - +#include #include #include #include diff --git a/subsys/virtualization/vdev/virt_syscon.c b/subsys/virtualization/vdev/virt_syscon.c index a29ba1bca2b381451e60da7fd7b52bac44794f8e..32d0f2c7459999fcf35c9cc5f70a0fc47ca8cfd7 100644 --- a/subsys/virtualization/vdev/virt_syscon.c +++ b/subsys/virtualization/vdev/virt_syscon.c @@ -48,7 +48,6 @@ int z_info_syscon(const char *name, uint32_t addr_base, /* Add clock syscon info to overall lists. */ key = k_spin_lock(&overall_syscons.vsyscon_lock); - /*dlist must be init to address to itself.*/ if(!first_entry_flag){ sys_dlist_init(&overall_syscons.syscon_list); first_entry_flag = true; @@ -87,7 +86,7 @@ static int syscon_vdev_mem_read(struct virt_dev *vdev, uint64_t addr, uint64_t * read_value = sys_read32(addr); *(uint32_t *)value = read_value; - printk("Syscon-%s Read:addr is %llx, value is %x\n", vdev->name, addr, read_value); + ZVM_LOG_INFO("Syscon-%s Read:addr is %llx, value is %x\n", vdev->name, addr, read_value); return 0; } @@ -101,7 +100,7 @@ static int syscon_vdev_mem_write(struct virt_dev *vdev, uint64_t addr, uint64_t sys_write32(write_value, addr); af_write_value = sys_read32(addr); - printk("Syscon-%s Write:addr is %llx, be_value is %x, ne_value is %x, af_value is %x\n", + ZVM_LOG_INFO("Syscon-%s Write:addr is %llx, be_value is %x, ne_value is %x, af_value is %x\n", vdev->name, addr, be_write_value, write_value, af_write_value); return 0; diff --git a/subsys/virtualization/vm.c b/subsys/virtualization/vm.c index d39fa62f7b560c0c58b466b185aa530594246f16..511ba1e3171419c2fc9e237f69f16bbaa0f67ad8 100644 --- a/subsys/virtualization/vm.c +++ b/subsys/virtualization/vm.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/subsys/virtualization/vm_irq.c b/subsys/virtualization/vm_irq.c index b5ec6921e888b9c5ffcea6d93b28fbf82cc83e56..775974f6c803696c85aebd28bed0f10962f1ab89 100644 --- a/subsys/virtualization/vm_irq.c +++ b/subsys/virtualization/vm_irq.c @@ -139,16 +139,16 @@ void vm_device_irq_init(struct vm *vm, struct virt_dev *vm_dev) struct virt_irq_desc *desc; desc = get_virt_irq_desc(vm->vcpus[DEFAULT_VCPU], vm_dev->virq); - if(vm_dev->dev_pt_flag){ + if(vm_dev->dev_pt_flag) { desc->virq_flags |= VIRQ_HW_FLAG; - }else{ - ZVM_LOG_ERR("There is no supported virtual interrupt"); + }else { + ZVM_LOG_WARN("There is no supported virtual interrupt for %s device !\n", vm_dev->name); } desc->id = desc->virq_num; desc->pirq_num = vm_dev->hirq; desc->virq_num = vm_dev->virq; - /*For passthrough device, using fast irq path. */ - if(vm_dev->dev_pt_flag){ + /* For passthrough device, using fast irq path. */ + if(vm_dev->dev_pt_flag) { bit_map = vm->vm_irq_block.irq_bitmap; bit_map[vm_dev->hirq] = true; } diff --git a/subsys/virtualization/vm_manager.c b/subsys/virtualization/vm_manager.c index 4577d98ad1c80cfd0d92616aeb0cff418b285975..fa21f40d8c2d47a0606fc99850fecebfeb7249b2 100644 --- a/subsys/virtualization/vm_manager.c +++ b/subsys/virtualization/vm_manager.c @@ -97,26 +97,26 @@ int zvm_new_guest(size_t argc, char **argv) k_free(vm_info); - ZVM_PRINTK("\n|*********************************************|\n"); - ZVM_PRINTK("|******\t Create vm successful! **************| \n"); - ZVM_PRINTK("|******\t\t VM INFO \t \t******| \n"); - ZVM_PRINTK("|******\t VM-NAME: %s \t******| \n", new_vm->vm_name); - ZVM_PRINTK("|******\t VM-ID: \t %d \t\t******| \n", new_vm->vmid); - ZVM_PRINTK("|******\t VCPU NUM: \t %d \t\t******| \n", new_vm->vcpu_num); + ZVM_LOG_INFO("\n|*********************************************|\n"); + ZVM_LOG_INFO("|******\t Create vm successful! **************| \n"); + ZVM_LOG_INFO("|******\t\t VM INFO \t \t******| \n"); + ZVM_LOG_INFO("|******\t VM-NAME: %s \t******| \n", new_vm->vm_name); + ZVM_LOG_INFO("|******\t VM-ID: \t %d \t\t******| \n", new_vm->vmid); + ZVM_LOG_INFO("|******\t VCPU NUM: \t %d \t\t******| \n", new_vm->vcpu_num); switch (new_vm->os->type) { case OS_TYPE_LINUX: - ZVM_PRINTK("|******\t VMEM SIZE: \t %d(M) \t******| \n", + ZVM_LOG_INFO("|******\t VMEM SIZE: \t %d(M) \t******| \n", LINUX_VMSYS_SIZE/(1024*1024)); break; case OS_TYPE_ZEPHYR: - ZVM_PRINTK("|******\t VMEM SIZE: \t %d(M) \t\t******| \n", + ZVM_LOG_INFO("|******\t VMEM SIZE: \t %d(M) \t\t******| \n", ZEPHYR_VMSYS_SIZE/(1024*1024)); break; default: - ZVM_PRINTK("|******\t OTHER VM, NO MEMORY MSG \t\t******| \n"); + ZVM_LOG_INFO("|******\t OTHER VM, NO MEMORY MSG \t\t******| \n"); } - ZVM_PRINTK("|*********************************************|\n"); + ZVM_LOG_INFO("|*********************************************|\n"); return 0; } @@ -151,13 +151,13 @@ int zvm_run_guest(size_t argc, char **argv) return -ENODEV; } - ZVM_PRINTK("\n|*********************************************|\n"); - ZVM_PRINTK("|******\t Start vm successful! ***************| \n"); - ZVM_PRINTK("|******\t\t VM INFO \t \t******| \n"); - ZVM_PRINTK("|******\t VM-NAME: %s \t******| \n", vm->vm_name); - ZVM_PRINTK("|******\t VM-ID: \t %d \t\t******| \n", vm->vmid); - ZVM_PRINTK("|******\t VCPU NUM: \t %d \t\t******| \n", vm->vcpu_num); - ZVM_PRINTK("|*********************************************|\n"); + ZVM_LOG_INFO("\n|*********************************************|\n"); + ZVM_LOG_INFO("|******\t Start vm successful! ***************| \n"); + ZVM_LOG_INFO("|******\t\t VM INFO \t \t******| \n"); + ZVM_LOG_INFO("|******\t VM-NAME: %s \t******| \n", vm->vm_name); + ZVM_LOG_INFO("|******\t VM-ID: \t %d \t\t******| \n", vm->vmid); + ZVM_LOG_INFO("|******\t VCPU NUM: \t %d \t\t******| \n", vm->vcpu_num); + ZVM_LOG_INFO("|*********************************************|\n"); return ret; } @@ -205,15 +205,15 @@ int zvm_delete_guest(size_t argc, char **argv) vm = zvm_overall_info->vms[vm_id]; switch (vm->vm_status) { case VM_STATE_RUNNING: - ZVM_PRINTK("This vm is running!\n Try to stop and delete it!\n"); + ZVM_LOG_INFO("This vm is running!\n Try to stop and delete it!\n"); vm_vcpus_halt(vm); break; case VM_STATE_PAUSE: - ZVM_PRINTK("This vm is paused!\n Just delete it!\n"); + ZVM_LOG_INFO("This vm is paused!\n Just delete it!\n"); vm_delete(vm); break; case VM_STATE_NEVER_RUN: - ZVM_PRINTK("This vm is created but not run!\n Just delete it!\n"); + ZVM_LOG_INFO("This vm is created but not run!\n Just delete it!\n"); vm_delete(vm); break; default: diff --git a/subsys/virtualization/zvm.c b/subsys/virtualization/zvm.c index ffb672844b9920bdeb7cfc2c5e97b2da56a48484..39a989ac3e92bb6b8f9c441af922f91d0991fce7 100644 --- a/subsys/virtualization/zvm.c +++ b/subsys/virtualization/zvm.c @@ -223,8 +223,8 @@ static int zvm_init_idle_device_1(const struct device *dev, struct virt_dev *vde vm_dev->vm = NULL; vm_dev->priv_data = (void *)dev; - printk("Init idle device %s successful! \n", vm_dev->name); - printk("The device's paddress is 0x%x, paddress is 0x%x, size is 0x%x, hirq is %d, virq is %d. \n", + ZVM_LOG_INFO("Init idle device %s successful! \n", vm_dev->name); + ZVM_LOG_INFO("The device's paddress is 0x%x, paddress is 0x%x, size is 0x%x, hirq is %d, virq is %d. \n", vm_dev->vm_vdev_paddr, vm_dev->vm_vdev_vaddr, vm_dev->vm_vdev_size, vm_dev->hirq, vm_dev->virq); sys_dnode_init(&vm_dev->vdev_node); diff --git a/zvm_doc/3_Run_on_ARM64_QEMU.rst b/zvm_doc/3_Run_on_ARM64_QEMU.rst index f8ccc1b8f7cb1f6cdaeb8f7a36923640c2344d34..b45d2c8e2b205408cdcd5e87563278116b3b5c7a 100644 --- a/zvm_doc/3_Run_on_ARM64_QEMU.rst +++ b/zvm_doc/3_Run_on_ARM64_QEMU.rst @@ -189,7 +189,7 @@ BusyBox,配置CONFIG_STATIC参数,编译静态版BusyBox,编译好的可 最终在qemu平台,生成如下文件: .. code:: shell - + # maybe you need to change the name of rootfs in auto_zvm.sh zephyr.bin, linux-qemu-virt.dtb, Image, initramfs.cpio.gz diff --git a/zvm_doc/4_Run_on_ROC_RK3568_PC.rst b/zvm_doc/4_Run_on_ROC_RK3568_PC.rst index 67d71d905d7638244d599475827111ff903b0d64..870673e224bfdda3d14a2a0a7af933a84bb28ac9 100644 --- a/zvm_doc/4_Run_on_ROC_RK3568_PC.rst +++ b/zvm_doc/4_Run_on_ROC_RK3568_PC.rst @@ -201,4 +201,124 @@ uart3: 用作主机shell控制 具体主机如何连接到串口uart3,需要看不同板卡的设计手册并自主引出串口线。 + +4. 串口调试说明 +----------------------- +前面已经说过,本文给到的例子中,涉及的串口为uart2,3,9。即正常启动两个虚拟机时两个虚拟机各 +分配一个串口。现有的sample中分配如下: + +- uart2: Linux 虚拟机; +- uart3: Zephyr 虚拟机; +- uart9: zvm虚拟机管理器; + +这么分配的原因是Linux虚拟机只能使用uart2作为其debug串口(和瑞芯微rk3568的bsp相关)。 +串口的具体分配原理如下,涉及的多个串口的设备树在*rk3568.dtsi*和*roc_rk3568_pc_smp.overlay*文件中,如下: + +.. code:: dts + + uart9: serial@fe6d0000 { + compatible = "rockchip,rk3568-uart", "ns16550"; + reg = <0x0 0xfe6d0000 0x0 0x10000>; + interrupts = ; + clock-frequency = <12000000>; + reg-shift = <2>; + status = "disabled"; + label = "UART9"; + }; + + uart3: serial@fe670000 { + compatible = "rockchip,rk3568-uart", "ns16550"; + reg = <0x0 0xfe670000 0x0 0x10000>; + interrupts = ; + clocks = <&uartclk>; + clock-frequency = <12000000>; + reg-shift = <2>; + status = "reserved"; + current-speed = <1500000>; + label = "UART3"; + }; + + uart2: serial@fe660000 { + compatible = "rockchip,rk3568-uart", "ns16550"; + reg = <0x0 0xfe660000 0x0 0x10000>; + interrupts = ; + clocks = <&uartclk>; + clock-frequency = <12000000>; + reg-shift = <2>; + status = "reserved"; + current-speed = <1500000>; + label = "UART2"; + }; + +正常来说,这些串口都是使能的,因此会在zvm以及虚拟机启动过程中分配给不同的系统。 +分配的顺序是从地址高位到地址低位,例如我们先启动zvm,zvm会分配uart9,此时还剩下uart2和uart3, +接着启动zephyr虚拟机,zephyr虚拟机会分配uart3,最后启动linux虚拟机,linux虚拟机会分配uart2, +此时系统能正常启动。 +如果你的板卡上不是这些个串口,你仅需要修改overlay中的uart设备树文件即可。例如你的板卡能用uart8, +那么你只需要将uart9/uart3改为uart8即可。 + +下面介绍板卡上分别使用两个串口和一个串口的情况: + +1)板卡上只有两个串口(例如串口上只有uart9和uart2) + +此时,仅需要将uart3的label从*UART3*修改*PTUART3*即可(debug串口的识别逻辑是匹配UARTx字符串)。 +这个时候的串口分配如下: + +- uart2: Linux/Zephyr 虚拟机; +- uart9: zvm虚拟机管理器; + +2)板卡上只有一个串口(例如串口上只有uart2,分配给Linux虚拟机) + +此时,我们可以通过编写自定义的VM启动程序,在zvm启动后直接启动相关的虚拟机,但不给其分配串口。 + +.. code:: c++ + + void auto_run(void) + { + zvm_init(); + //启动Zephyr虚拟机 + start_linux_vm(); + + //启动Linux虚拟机 + start_linux_vm(); + } + +此时,我们考虑将uart3/uart9都关掉。这个时候的串口分配如下: + +- uart2: Linux 虚拟机; + +此时需要修改*prj.conf*中的多个配置项,如下: + +.. code:: shell + + CONFIG_SHELL=n + CONFIG_ZVM_DEBUG_LOG_INFO=n + +同时,需要修改roc_rk3568_pc_smp.dts中的内容,将uart9的status改为disabled。 + +.. code:: dts + + &uart9 { + status = "disabled"; + current-speed = <1500000>; + }; + +最后,将uart3关闭,在*roc_rk3568_pc_smp.overlay*中将串口的label改为*PTUART3*。 + +.. code:: dts + + uart3: serial@fe670000 { + compatible = "rockchip,rk3568-uart", "ns16550"; + reg = <0x0 0xfe670000 0x0 0x10000>; + interrupts = ; + clocks = <&uartclk>; + clock-frequency = <12000000>; + reg-shift = <2>; + status = "disabled"; + current-speed = <1500000>; + label = "PTUART3"; + }; + +最后,编写自动启动虚拟机的代码,将其编译进zvm_host.bin中即可。 + `Prev>> 在QEMU上运行ZVM `__