From 1393caa374db807b7ece3fef18c00a4bffb5fa57 Mon Sep 17 00:00:00 2001 From: Ayan Kumar Halder Date: Fri, 21 Jan 2022 11:10:40 +0000 Subject: Added the lopper dts file to generate imagebuilder config from system-device-tree Lopper parses the device tree for a "xen" label. It parses the sub nodes to determine the DOM0_VCPUS, DOM0_MEM, NUM_DOMUS, DOMU_VCPUS[], DOMU_MEM[] and DOMU_PASSTHROUGH_PATHS[] As an example, consider the following snippet of system-device-tree xen: domain@2 { compatible = "openamp,domain-v1","openamp,hypervisor-v1"; cpus = <&cpus_a72 0x3 0x00000002>; memory = <0x0 0x500000 0x0 0x7fb00000>; dom0: domain@3 { compatible = "openamp,domain-v1","xen,domain-v2"; cpus = <&cpus_a72 0x3 0x00000001>; memory = <0x0 0x501000 0x0 0x3faff000>; }; linux1: domain@4 { compatible = "openamp,domain-v1","xen,domain-v2"; cpus = <&cpus_a72 0x3 0x00000001>; memory = <0x0 0x501000 0x0 0x3faff000>; access = <&mmc0 0x0>; }; linux2: domain@5 { compatible = "openamp,domain-v1","xen,domain-v2"; cpus = <&cpus_a72 0x3 0x00000001>; memory = <0x0 0x40000000 0x0 0x40000000>; firewallconfig = <&linux1 1 0>; }; }; python3 _path_to_/lopper.py -f --enhanced -i path_to_/lop-xen.dts device-trees/system-device-tree-xen.dts > config The contents of the 'config' will be as follows :- NUM_DOMUS=2 DOM0_VCPUS = 2 DOM0_MEM = 1018 DOMU_VCPUS[0] = 2 DOMU_MEM[0] = 1018 DOMU_PASSTHROUGH_PATHS[0] = "/bus@f1000000/sdhci@f1050000" DOMU_VCPUS[1] = 2 DOMU_MEM[1] = 1024 This is provided as the input configuration file for the imagebuilder. Signed-off-by: Bruce Ashfield Signed-off-by: Ayan Kumar Halder Reviewed-by: Stefano Stabellini [stefano: minor style and grammar fixes] Signed-off-by: Stefano Stabellini --- README_system_device_tree.md | 82 ++++++++++++++++++++++++++++++++++++ scripts/lop-xen.dts | 98 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 README_system_device_tree.md create mode 100644 scripts/lop-xen.dts diff --git a/README_system_device_tree.md b/README_system_device_tree.md new file mode 100644 index 0000000..5da8f06 --- /dev/null +++ b/README_system_device_tree.md @@ -0,0 +1,82 @@ +# ImageBuilder with System Device Tree + +Please refer to README.md to know more about ImageBuilder + +ImageBuilder can be used with System Device Tree to generate the +scripts, binaries, etc required to boot Xen, Dom0 and DomU kernels on +a hardware platform. +The System Device Tree contains the hardware information as well as +domain information. +Refer https://gitenterprise.xilinx.com/stefanos/system-device-tree/blob/master/system-device-tree.dts +for the system device tree example. + +## scripts/lop-xen.dts + +ImageBuilder derives its configuration from "domains" node in System +Device Tree, e.g.: + +xen: domain@2 { + compatible = "openamp,domain-v1","openamp,hypervisor-v1"; + cpus = <&cpus_a72 0x3 0x00000002>; + memory = <0x0 0x500000 0x0 0x7fb00000>; + + dom0: domain@3 { + compatible = "openamp,domain-v1","xen,domain-v2"; + cpus = <&cpus_a72 0x3 0x00000001>; + memory = <0x0 0x501000 0x0 0x3faff000>; + }; + + linux1: domain@4 { + compatible = "openamp,domain-v1","xen,domain-v2"; + cpus = <&cpus_a72 0x3 0x00000001>; + memory = <0x0 0x501000 0x0 0x3faff000>; + access = <&mmc0 0x0>; + }; + + linux2: domain@5 { + compatible = "openamp,domain-v1","xen,domain-v2"; + cpus = <&cpus_a72 0x3 0x00000001>; + memory = <0x0 0x40000000 0x0 0x40000000>; + + firewallconfig = <&linux1 1 0>; + }; +}; + +From the above snippet, ImageBuilder can deduce the number of domUs, +count of virtual CPUs for Dom0, amount of memory for Dom0, count of +virtual CPUs for each DomU, amount of memory for each DomU and device +assigned to each DomU. + +lop-xen.dts is the lopper dts file to generate the ImageBuilder config +file (containing the above information) from System Device Tree. + +To use it, one needs to checkout the following two repositories: + +``` +git clone git://github.com/devicetree-org/lopper +git clone https://gitenterprise.xilinx.com/stefanos/system-device-tree.git +``` + +Note: One needs to add a 'dom0' label (as shown in the previous snippet) +for the node which represents dom0. + +And then run the following command from the "lopper" directory: + +``` +python3 lopper.py -f --enhanced -i /imagebuilder/scripts/lop-xen.dts \ + /system-device-tree/system-device-tree-xen.dts > config +``` + +For the dts snippet shown before, the following 'config' file will be +generated: + +NUM_DOMUS=2 +DOM0_VCPUS = 2 +DOM0_MEM = 1018 +DOMU_VCPUS[0] = 2 +DOMU_MEM[0] = 1018 +DOMU_PASSTHROUGH_PATHS[0] = "/bus@f1000000/sdhci@f1050000" +DOMU_VCPUS[1] = 2 +DOMU_MEM[1] = 1024 + +Refer to README.md for a description of each of these options. diff --git a/scripts/lop-xen.dts b/scripts/lop-xen.dts new file mode 100644 index 0000000..6bf40eb --- /dev/null +++ b/scripts/lop-xen.dts @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2019,2020 Xilinx Inc. All rights reserved. + * + * Author: + * Bruce Ashfield + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/dts-v1/; + +/ { + compatible = "system-device-tree-v1,lop"; + lops { + compatible = "system-device-tree-v1,lop"; + lop_0_1 { + compatible = "system-device-tree-v1,lop,select-v1"; + select_1; + select_2 = "xen::"; + lop_0_2 { + compatible = "system-device-tree-v1,lop,code-v1"; + inherit = "lopper_lib"; + code = " + s = __selected__[0] + + ## Look for dom0 label to identify dom0, if no label + ## assume it is a domu + sn = s.subnodes( children_only = True ) + + domu_count = 0 + for n in sn: + if n.label != 'dom0': + domu_count += 1 + + print( 'NUM_DOMUS=%s' % domu_count ) + + domu_index = -1 + for node_count, domu_node in enumerate(sn): + dom0_flag = False + + if domu_node.label == 'dom0': + dom0_flag = True + else: + domu_index += 1 + + # cpus + try: + # note: this doesn't check the cpu mask, but probably should + cpus = domu_node['cpus'] + refd_cpus, unrefd_cpus = lopper_lib.cpu_refs( tree, cpus ) + cpu_count = len(refd_cpus) + + if dom0_flag: + print( 'DOM0_VCPUS = %s' % cpu_count ) + else: + print( 'DOMU_VCPUS[%s] = %s' % (domu_index,cpu_count) ) + except: + pass + + # memory + try: + ## memory is to allow + ## 64 bit memory, so we just want the 3rd and 4th + ## converted from bytes to MB in the output. + mem = domu_node['memory'] + mem_high = mem[2] + mem_low = mem[3] + + mem_low_mb = int(mem_low / (1024 * 1024)) + + if dom0_flag: + print( 'DOM0_MEM = %s' % mem_low_mb ) + else: + print( 'DOMU_MEM[%s] = %s' % (domu_index,mem_low_mb) ) + except Exception as e: + print( '[ERROR]: %s' % e ) + + # devices + try: + accessed_nodes = lopper_lib.node_accesses( tree, domu_node ) + access_paths = '' + if accessed_nodes: + # print( 'accesses! %s' % accessed_nodes ) + for a in accessed_nodes: + access_paths += '\"' + a.abs_path + '\"' + ',' + + # remove any possible trailing commas + access_paths = access_paths.rstrip(',') + print( 'DOMU_PASSTHROUGH_PATHS[%s] = %s' % (domu_index,access_paths )) + + except Exception as e: + print( '[ERROR]: %s' % e ) + + "; + }; + }; + }; +}; -- cgit v1.2.3