From 2ce914428c560325399c965040dbe945bb9afeb7 Mon Sep 17 00:00:00 2001 From: Kunhui-Li Date: Mon, 11 Apr 2022 20:51:13 +0800 Subject: [PATCH] config_tools: refine virtio in launch script 1. for virtio console, reference to the document https://projectacrn.github.io/latest/developer-guides/hld/virtio-console.html, the generated launch script will look like this: `virtio-console,[@]stdio|tty|pty|file:portname[=portpath]\ [,[@]stdio|tty|pty|file:portname[=portpath][:socket_type]]` *receding with @ marks the port as a console port, otherwise it is a normal virtio-serial port *The portpath can be omitted when backend is stdio or pty. 2. for virtio input, the generated launch script as below. `:,id=` The launch script will automatically find the specific /dev/input/eventX according to the event name and phys got from board.xml. Tracked-On: #6690 Signed-off-by: Kunhui-Li Reviewed-by: Junjie Mao --- .../launch_config/launch_cfg_gen.py | 32 ++++++++++++--- .../launch_config/launch_script_template.sh | 39 +++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/misc/config_tools/launch_config/launch_cfg_gen.py b/misc/config_tools/launch_config/launch_cfg_gen.py index 54044e805..3c8f56c85 100755 --- a/misc/config_tools/launch_config/launch_cfg_gen.py +++ b/misc/config_tools/launch_config/launch_cfg_gen.py @@ -254,14 +254,34 @@ def generate_for_one_vm(board_etree, hv_scenario_etree, vm_scenario_etree, vm_id for usb_xhci in eval_xpath_all(vm_scenario_etree, ".//usb_xhci[text() != '']/text()"): script.add_virtual_device("xhci", options=usb_xhci) - for virtio_input in eval_xpath_all(vm_scenario_etree, ".//virtio_devices/input[text() != '']/text()"): - script.add_virtual_device("virtio-input", options=virtio_input) + for virtio_input_etree in eval_xpath_all(vm_scenario_etree, ".//virtio_devices/input"): + backend_device_file = eval_xpath(virtio_input_etree, "./backend_device_file[text() != '']/text()") + unique_identifier = eval_xpath(virtio_input_etree, "./id[text() != '']/text()") + if backend_device_file is not None and unique_identifier is not None: + script.add_virtual_device("virtio-input", options=f"{backend_device_file},id={unique_identifier}") + elif backend_device_file is not None: + script.add_virtual_device("virtio-input", options=backend_device_file) - for virtio_console in eval_xpath_all(vm_scenario_etree, ".//virtio_devices/console[text() != '']/text()"): - script.add_virtual_device("virtio-console", options=virtio_console) + for backend_type in eval_xpath_all(vm_scenario_etree, ".//virtio_devices/console/backend_type[text() != '']/text()"): + preceding_mask = "" + use_type = eval_xpath(vm_scenario_etree, ".//virtio_devices/console/use_type/text()") + if use_type == "Virtio console": + preceding_mask = "@" - for virtio_network in eval_xpath_all(vm_scenario_etree, ".//virtio_devices/network[text() != '']/text()"): - params = virtio_network.split(",", maxsplit=1) + if backend_type == "file": + output_file_path = eval_xpath(vm_scenario_etree, ".//virtio_devices/console/output_file_path/text()") + script.add_virtual_device("virtio-console", options=f"{preceding_mask}file:file_port={output_file_path}") + elif backend_type == "tty": + tty_file_path = eval_xpath(vm_scenario_etree, ".//virtio_devices/console/tty_device_path/text()") + script.add_virtual_device("virtio-console", options=f"{preceding_mask}tty:tty_port={tty_file_path}") + elif backend_type == "sock server" or backend_type == "sock client": + sock_file_path = eval_xpath(vm_scenario_etree, ".//virtio_devices/console/sock_file_path/text()") + script.add_virtual_device("virtio-console", options=f"socket:{os.path.basename(sock_file_path).split('.')[0]}={sock_file_path}:{backend_type.replace('sock ', '')}") + else: + script.add_virtual_device("virtio-console", options=f"{preceding_mask}{backend_type}:{backend_type}_port") + + for interface_name in eval_xpath_all(vm_scenario_etree, ".//virtio_devices/network/interface_name[text() != '']/text()"): + params = interface_name.split(",", maxsplit=1) tap_conf = f"tap={params[0]}" params = [tap_conf] + params[1:] script.add_init_command(f"mac=$(cat /sys/class/net/e*/address)") diff --git a/misc/config_tools/launch_config/launch_script_template.sh b/misc/config_tools/launch_config/launch_script_template.sh index b0adb2be8..e948031c4 100644 --- a/misc/config_tools/launch_config/launch_script_template.sh +++ b/misc/config_tools/launch_config/launch_script_template.sh @@ -133,6 +133,45 @@ function add_virtual_device() { fi fi + if [ "${kind}" = "virtio-input" ]; then + if [[ "${options}" =~ id=([a-zA-Z0-9_\-]*) ]]; then + unique_identifier="${BASH_REMATCH[1]}" + options=${options/",id=${unique_identifier}"/''} + fi + + local IFS=$'\n' + device_name_path=$(grep -r "${options%:*}" /sys/class/input/event*/device/name) + if [ -n "${device_name_path}" ]; then + for device_path in ${device_name_path}; do + if [ "${options%:*}" = "${options#*:}" ]; then + options="/dev/input/${device_path:17:6}" + break + else + phys_path=$(grep -r "${options#*:}" /sys/class/input/event*/device/phys) + if [ "${device_path%/device*}" = "${phys_path%/device*}" ]; then + options="/dev/input/${device_path:17:6}" + break + fi + fi + done + else + echo "${options%:*} device path is not found in the service vm." >> /dev/stderr + return + fi + + if [[ ${options} =~ event([0-9]+) ]]; then + echo "${options} input device path is available in the service vm." >> /dev/stderr + else + echo "${options#*:} input phys path is not found in the service vm." >> /dev/stderr + return + fi + + if [ -n "${options}" ] && [ -n "${unique_identifier}" ]; then + options="${options},${unique_identifier}" + fi + + fi + echo -n "-s ${slot},${kind}" if [ -n "${options}" ]; then echo -n ",${options}"