Use lopper to generate partial dts
v2 cover Use lopper to generate partial dts
This patch series introduces support to generate automatically passthrough device trees using lopper. This feature should be used with care as the corresponding lopper changes are still in an early support state. Current integration has been tested with several devices from ZynqMP ZCU102 board e.g. serial, spi, ahci, mmc.
When using this feature, make sure to use the latest lopper's master branch status [1].
[1] https://github.com/devicetree-org/lopper
Michal Orzel (2):
Refactor sanity_check_partial_dts
Add support for lopper to generate partial dts
README.md | 23 ++++++++++- scripts/common | 84 ++++++++++++++++++++++++++++++---------- scripts/uboot-script-gen | 22 ++++++++++- 3 files changed, 104 insertions(+), 25 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 Refactor sanity_check_partial_dts
Currently function sanity_check_partial_dts from scripts/common takes three arguments where the last two (repo, dir) are used always in conjuction to form a path to a directory storing partial dts. Modify the function to take only two arguments where the second one is to be a path to a directory storing partial dts. This will help reusing this function in the future to perform sanity checks on partial dts that do not originate from a repository.
Modify compile_merge_partial_dts to take this change into account.
---
Changes in v2:
- none
--- scripts/common | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
scripts/common +6 -5
@@ -40,8 +40,7 @@ function get_next_phandle() function sanity_check_partial_dts() { local domU_passthrough_path="$1" - local repo="$2" - local dir="$3" + local partial_dts_dir="$2" local address_cells_val local size_cells_val local tmpdtb
@@ -51,7 +50,7 @@ function sanity_check_partial_dts() for devpath in $domU_passthrough_path do file=${devpath##*/} - file="$repo"/"$dir"/"$file".dts + file="$partial_dts_dir"/"$file".dts if ! test -f "$file" then
@@ -96,6 +95,7 @@ function compile_merge_partial_dts() local dtb_dir=$1 local repo=$(echo "$2" | awk '{print $1}') local dir=$(echo "$2" | awk '{print $2}') + local partial_dts_dir local tmp local tmpdts local file
@@ -123,6 +123,7 @@ function compile_merge_partial_dts() dir="." fi + partial_dts_dir="$repo"/"$dir" i=0 while test $i -lt $NUM_DOMUS do
@@ -132,7 +133,7 @@ function compile_merge_partial_dts() return 1 fi - sanity_check_partial_dts "${DOMU_PASSTHROUGH_PATHS[$i]}" "$repo" "$dir" + sanity_check_partial_dts "${DOMU_PASSTHROUGH_PATHS[$i]}" "$partial_dts_dir" if test $? -ne 0 then return 1
@@ -146,7 +147,7 @@ function compile_merge_partial_dts() for devpath in ${DOMU_PASSTHROUGH_PATHS[$i]} do file=${devpath##*/} - file="$repo"/"$dir"/"$file".dts + file="$partial_dts_dir"/"$file".dts # All the subsequent dts files should not have dts version mentioned if test $j -gt 1
Signature · 1 line
2.25.1
PATCH v2 2/2 Add support for lopper to generate partial dts
In reply to Michal OrzelCurrently ImageBuilder can compile and merge partial dts obtained from a repository specified using PASSTHROUGH_DTS_REPO. With the recent changes done in the lopper, we can use it to generate partial dts automatically (to some extent as this is still an early support).
Introduce LOPPER_PATH option to specify a path to a lopper.py script, the main script in the Lopper repository, that if set, will invoke lopper to generate partial dts for the passthrough devices specified in DOMU_PASSTHROUGH_PATHS.
Introduce LOPPER_CMD option to specify custom command line arguments (if needed) for lopper's extract assist.
Example usage:
LOPPER_PATH="/home/user/lopper/lopper.py" DOMU_PASSTHROUGH_PATHS[0]="/axi/spi@ff0f0000 /axi/serial@ff010000"
---
Changes in v2:
- improve documentation
- update commit msg
- use node=${devpath##*/} instead of file=${devpath##*/}
--- README.md | 23 ++++++++++-- scripts/common | 77 ++++++++++++++++++++++++++++++---------- scripts/uboot-script-gen | 22 ++++++++++-- 3 files changed, 100 insertions(+), 22 deletions(-)
README.md +21 -2
@@ -128,6 +128,20 @@ Where: - DT_OVERLAY[number] specifies the path to the hosts device tree overlays to be added at boot time in u-boot +- LOPPER_PATH specifies the path to lopper.py script, the main script in the + Lopper repository (https://github.com/devicetree-org/lopper). This is + optional. However, if this is specified, then DOMU_PASSTHROUGH_PATHS[number] + needs to be specified. uboot-script-gen will invoke lopper to generate the + partial device trees for devices which have been listed in + DOMU_PASSTHROUGH_PATHS[number]. This option is currently in experimental state + as the corresponding lopper changes are still in an early support state. + +- LOPPER_CMD specifies the command line arguments for lopper's extract assist. + This is optional and only applicable when LOPPER_PATH is specified. Only to be + used to specify which nodes to include (using -i <node_name>) and which + nodes/properties to exclude (using -x <regex>). If not set at all, the default + one is used applicable for ZynqMP MPSoC boards. + - NUM_DOMUS specifies how many Dom0-less DomUs to load - DOMU_KERNEL[number] specifies the DomU kernel to use.
@@ -140,7 +154,7 @@ Where: - DOMU_PASSTHROUGH_PATHS[number] specifies the passthrough devices ( separated by spaces). It adds "xen,passthrough" to the corresponding dtb nodes in xen device tree blob. - This option is valid in the following two cases: + This option is valid in the following cases: 1. When PASSTHROUGH_DTS_REPO is provided. With this option, the partial device trees (corresponding to the
@@ -149,7 +163,12 @@ Where: Note it assumes that the names of the partial device trees will match to the names of the devices specified here. - 2. When DOMU_NOBOOT[number] is provided. In this case, it will only + 2. When LOPPER_PATH is provided. + With this option, the partial device trees (corresponding to the + passthrough devices) are generated by the lopper and then compiled and merged + by ImageBuilder to be used as DOMU[number] device tree blob. + + 3. When DOMU_NOBOOT[number] is provided. In this case, it will only add "xen,passthrough" as mentioned before. - DOMU_PASSTHROUGH_DTB[number] specifies the passthrough device trees
scripts/common +59 -18
110 lines not on this page · raw message
scripts/uboot-script-gen +20 -2
@@ -1138,10 +1138,28 @@ fi # tftp or move the files to a partition cd "$uboot_dir" -if test "$PASSTHROUGH_DTS_REPO" +# If both PASSTHROUGH_DTS_REPO and LOPPER_PATH options are specified, +# the former takes precedence because the partial device trees are already +# created (probably tested), hence the reliability is higher than using lopper. +if test "$PASSTHROUGH_DTS_REPO" || test "$LOPPER_PATH" then output_dir=`mktemp -d "partial-dtbs-XXX"` - compile_merge_partial_dts $output_dir "$PASSTHROUGH_DTS_REPO" + if test "$PASSTHROUGH_DTS_REPO" + then + compile_merge_partial_dts $output_dir "$PASSTHROUGH_DTS_REPO" + else + if test -z "$LOPPER_CMD" + then + # Default for ZynqMP MPSoC. + # The following command instructs lopper's extract assist to always + # include zynqmp-firmware node (as it contains e.g. clock-controller + # required by most of the devices) in the extracted tree structure + # and to drop nodes/properties during the extraction process that + # are not needed. + LOPPER_CMD="-i zynqmp-firmware -x interrupt-controller -x pinctrl -x power-domains -x resets -x current-speed" + fi + compile_merge_partial_dts $output_dir + fi if test $? -ne 0 then # Remove the output dir holding the partial dtbs in case of any error
Signature · 1 line
2.25.1
Re: [ImageBuilder v2 2/2] Add support for lopper to generate partial dts
Quoted 10 lines · Michal Orzel
Currently ImageBuilder can compile and merge partial dts obtained from a repository specified using
PASSTHROUGH_DTS_REPO. With the recent changes done in the lopper, we can use it to generate partial dts automatically (to some extent as this is still an early support).Introduce
LOPPER_PATHoption to specify a path to alopper.pyscript, the main script in the Lopper repository, that if set, will invoke lopper to generate partial dts for the passthrough devices specified inDOMU_PASSTHROUGH_PATHS.
Quoted 8 lines
Introduce
LOPPER_CMDoption to specify custom command line arguments (if needed) for lopper's extract assist.Example usage:
LOPPER_PATH="/home/user/lopper/lopper.py" DOMU_PASSTHROUGH_PATHS[0]="/axi/spi@ff0f0000 /axi/serial@ff010000"Signed-off-by Michal Orzel <[email protected]>
Given the state of the release I would commit these two patches to a "master-next" branch to be merged into "master" later.
But I'll wait before committing to hear your thoughrs on the SRC_URI suggestion in the other email.
Quoted 215 lines
---
Changes in v2:
- improve documentation
- update commit msg
- use node=${devpath##*/} instead of file=${devpath##*/}--- README.md | 23 ++++++++++-- scripts/common | 77 ++++++++++++++++++++++++++++++---------- scripts/uboot-script-gen | 22 ++++++++++-- 3 files changed, 100 insertions(+), 22 deletions(-)README.md +21
-2@@ -128,6 +128,20 @@ Where: - DT_OVERLAY[number] specifies the path to the hosts device tree overlays to be added at boot time in u-boot +- LOPPER_PATH specifies the path to lopper.py script, the main script in the + Lopper repository (https://github.com/devicetree-org/lopper). This is + optional. However, if this is specified, then DOMU_PASSTHROUGH_PATHS[number] + needs to be specified. uboot-script-gen will invoke lopper to generate the + partial device trees for devices which have been listed in + DOMU_PASSTHROUGH_PATHS[number]. This option is currently in experimental state + as the corresponding lopper changes are still in an early support state. + +- LOPPER_CMD specifies the command line arguments for lopper's extract assist. + This is optional and only applicable when LOPPER_PATH is specified. Only to be + used to specify which nodes to include (using -i <node_name>) and which + nodes/properties to exclude (using -x <regex>). If not set at all, the default + one is used applicable for ZynqMP MPSoC boards. + - NUM_DOMUS specifies how many Dom0-less DomUs to load - DOMU_KERNEL[number] specifies the DomU kernel to use.@@ -140,7 +154,7 @@ Where: - DOMU_PASSTHROUGH_PATHS[number] specifies the passthrough devices ( separated by spaces). It adds "xen,passthrough" to the corresponding dtb nodes in xen device tree blob. - This option is valid in the following two cases: + This option is valid in the following cases: 1. When PASSTHROUGH_DTS_REPO is provided. With this option, the partial device trees (corresponding to the@@ -149,7 +163,12 @@ Where: Note it assumes that the names of the partial device trees will match to the names of the devices specified here. - 2. When DOMU_NOBOOT[number] is provided. In this case, it will only + 2. When LOPPER_PATH is provided. + With this option, the partial device trees (corresponding to the + passthrough devices) are generated by the lopper and then compiled and merged + by ImageBuilder to be used as DOMU[number] device tree blob. + + 3. When DOMU_NOBOOT[number] is provided. In this case, it will only add "xen,passthrough" as mentioned before. - DOMU_PASSTHROUGH_DTB[number] specifies the passthrough device treesscripts/common +59
-18@@ -9,6 +9,9 @@ # - NUM_DOMUS # - DOMU_PASSTHROUGH_PATHS # - DOMU_PASSTHROUGH_DTB +# - LOPPER_PATH +# - LOPPER_CMD +# - DEVICE_TREE tmp_files=() tmp_dirs=()@@ -99,31 +102,41 @@ function compile_merge_partial_dts() local tmp local tmpdts local file + local node local i local j - if [[ "$repo" =~ .*@.*:.* ]] + if test "$repo" then - tmp=`mktemp -d` - tmp_dirs+=($tmp) - - echo "Cloning git repo \"$git_repo\"" - git clone "$repo" $tmp - if test $? -ne 0 + # Partial dts will be obtained from PASSTHROUGH_DTS_REPO + if [[ "$repo" =~ .*@.*:.* ]] then - echo "Error occurred while cloning \"$git_repo\"" - return 1 - fi + tmp=`mktemp -d` + tmp_dirs+=($tmp) - repo=$tmp - fi + echo "Cloning git repo \"$git_repo\"" + git clone "$repo" $tmp + if test $? -ne 0 + then + echo "Error occurred while cloning \"$git_repo\"" + return 1 + fi - if test -z "$dir" - then - dir="." + repo=$tmp + fi + + if test -z "$dir" + then + dir="." + fi + partial_dts_dir="$repo"/"$dir" + else + # Partial dts will be generated by the lopper + tmp=`mktemp -d` + tmp_dirs+=($tmp) + partial_dts_dir="$tmp" fi - partial_dts_dir="$repo"/"$dir" i=0 while test $i -lt $NUM_DOMUS do@@ -133,6 +146,34 @@ function compile_merge_partial_dts() return 1 fi + if test -z "$repo" + then + # Generate partial dts using lopper + for devpath in ${DOMU_PASSTHROUGH_PATHS[$i]} + do + node=${devpath##*/} + file="$partial_dts_dir"/"$node".dts + + # Execute lopper with the following assists: + # - extract: used to take the target node, extract it from the + # system device tree, chase the phandle references and place + # it in a new extracted tree structure, + # - extract-xen: used to perform Xen specific modifications + # on the extracted tree structure e.g. adding "xen,path", + # "xen,reg", interrupt-parent properties. + # For additional information, please see the lopper's README + # file as well as usage of the mentioned assists. + $LOPPER_PATH --permissive -f $DEVICE_TREE \ + -- extract -t $devpath $LOPPER_CMD \ + -- extract-xen -t $node -o $file + + if test $? -ne 0 + then + return 1 + fi + done + fi + sanity_check_partial_dts "${DOMU_PASSTHROUGH_PATHS[$i]}" "$partial_dts_dir" if test $? -ne 0 then@@ -146,8 +187,8 @@ function compile_merge_partial_dts() for devpath in ${DOMU_PASSTHROUGH_PATHS[$i]} do - file=${devpath##*/} - file="$partial_dts_dir"/"$file".dts + node=${devpath##*/} + file="$partial_dts_dir"/"$node".dts # All the subsequent dts files should not have dts version mentioned if test $j -gt 1scripts/uboot-script-gen +20
-2@@ -1138,10 +1138,28 @@ fi # tftp or move the files to a partition cd "$uboot_dir" -if test "$PASSTHROUGH_DTS_REPO" +# If both PASSTHROUGH_DTS_REPO and LOPPER_PATH options are specified, +# the former takes precedence because the partial device trees are already +# created (probably tested), hence the reliability is higher than using lopper. +if test "$PASSTHROUGH_DTS_REPO" || test "$LOPPER_PATH" then output_dir=`mktemp -d "partial-dtbs-XXX"` - compile_merge_partial_dts $output_dir "$PASSTHROUGH_DTS_REPO" + if test "$PASSTHROUGH_DTS_REPO" + then + compile_merge_partial_dts $output_dir "$PASSTHROUGH_DTS_REPO" + else + if test -z "$LOPPER_CMD" + then + # Default for ZynqMP MPSoC. + # The following command instructs lopper's extract assist to always + # include zynqmp-firmware node (as it contains e.g. clock-controller + # required by most of the devices) in the extracted tree structure + # and to drop nodes/properties during the extraction process that + # are not needed. + LOPPER_CMD="-i zynqmp-firmware -x interrupt-controller -x pinctrl -x power-domains -x resets -x current-speed" + fi + compile_merge_partial_dts $output_dir + fi if test $? -ne 0 then # Remove the output dir holding the partial dtbs in case of any errorSignature · 1 line
2.25.1