aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyan Kumar Halder2021-12-15 17:39:28 +0000
committerStefano Stabellini2021-12-15 13:46:23 -0800
commit7ba9b416b052b4272c8bfc4c4f630ba39d8c8dd3 (patch)
treece2c85620e1ff65d0f7a62a6e5612b6b06b88838
parent4435825070fe062bb5576e9e048883191c0d87b7 (diff)
Add support for compiling and merging partial device trees
One can specify the repository and the directory holding the partial device trees via the config option PASSTHROUGH_DTS_REPO. This can be either a git url or a local directory containing the partial device trees. Also, the passthrough devices for each DOMU are specified via DOMU_PASSTHROUGH_PATHS config option. Imagebuilder will compile the partial device trees. The underlying assumption is that the name of the partial device tree should match to the name of the device specified in DOMU_PASSTHROUGH_PATHS. For example (in case of git repo) :- PASSTHROUGH_DTS_REPO="git@github.com:Xilinx/xen-passthrough-device-trees.git device-trees-2021.2" DOMU_PASSTHROUGH_PATHS[0]="/axi/serial@ff010000 /axi/mmc@ff170000" (This tells imagebuilder to clone the repo and use serial@ff010000.dts and mmc@ff170000.dts from device-trees-2021.2 folder, to compile and generate a partial dtb for DOMU[0]. If the files are absent, it will give an error. Also, if the files mismatching values for #address-cells and #size-cells, it will give an error. Signed-off-by: Ayan Kumar Halder <ayankuma@xilinx.com> Reviewed-by: Stefano Stabellini <stefano.stabellini@xilinx.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
-rw-r--r--README.md28
-rwxr-xr-xscripts/uboot-script-gen164
2 files changed, 179 insertions, 13 deletions
diff --git a/README.md b/README.md
index 1695c56..4b37db7 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ LOAD_CMD="tftpb"
DEVICE_TREE="mpsoc.dtb"
XEN="xen"
XEN_CMD="console=dtuart dtuart=serial0 dom0_mem=1G dom0_max_vcpus=1 bootscrub=0 vwfi=native sched=null"
-XEN_PASSTHROUGH_PATHS="/axi/ethernet@ff0e0000 /axi/serial@ff000000"
+PASSTHROUGH_DTS_REPO="git@github.com:Xilinx/xen-passthrough-device-trees.git device-trees-2021.2"
DOM0_KERNEL="Image-dom0"
DOM0_CMD="console=hvc0 earlycon=xen earlyprintk=xen clk_ignore_unused"
DOM0_RAMDISK="dom0-ramdisk.cpio"
@@ -44,9 +44,9 @@ DT_OVERLAY[0]="host_dt_overlay.dtbo"
NUM_DOMUS=2
DOMU_KERNEL[0]="zynqmp-dom1/Image-domU"
+DOMU_PASSTHROUGH_PATHS[0]="/axi/ethernet@ff0e0000 /axi/serial@ff000000"
DOMU_CMD[0]="console=ttyPS0 earlycon console=ttyPS0,115200 clk_ignore_unused rdinit=/sbin/init root=/dev/ram0 init=/bin/sh"
DOMU_RAMDISK[0]="zynqmp-dom1/domU-ramdisk.cpio"
-DOMU_PASSTHROUGH_DTB[0]="zynqmp-dom1/passthrough-example-part.dtb"
DOMU_KERNEL[1]="zynqmp-dom2/Image-domU"
DOMU_CMD[1]="console=ttyAMA0 clk_ignore_unused rdinit=/sbin/init root=/dev/ram0 init=/bin/sh"
DOMU_RAMDISK[1]="zynqmp-dom2/domU-ramdisk.cpio"
@@ -87,8 +87,11 @@ Where:
- XEN_CMD specifies the command line arguments used for Xen. If not
set, the default one will be used.
-- XEN_PASSTHROUGH_PATHS specifies the passthrough devices (separated
- by spaces). It adds "xen,passthrough" to the corresponding dtb nodes.
+- PASSTHROUGH_DTS_REPO specifies the git repository and/or the directory
+ which contains the partial device trees. This is optional. However, if
+ this is specified, then XEN_PASSTHROUGH_PATHS need to be specified.
+ uboot-script-gen will compile the partial device trees which have
+ been specified in XEN_PASSTHROUGH_PATHS.
- DOM0_KERNEL specifies the Dom0 kernel file to load.
@@ -114,8 +117,21 @@ Where:
- DOMU_RAMDISK[number] specifies the DomU ramdisk to use.
-- DOMU_PASSTHROUGH_DTB[number] specifies the device assignment
- configuration, see xen.git:docs/misc/arm/passthrough.txt
+- 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 only when PASSTHROUGH_DTS_REPO is provided.
+ With this option, the partial device trees (corresponding to the
+ passthrough devices) from the PASSTHROUGH_DTS_REPO, are compiled
+ merged and used as DOMU[number] device tree blob.
+ Note it assumes that the names of the partial device trees will match
+ to the names of the devices specified here.
+
+- DOMU_PASSTHROUGH_DTB[number] specifies the passthrough device trees
+ blob. This option is used when DOMU_PASSTHROUGH_PATHS[number] is not
+ specified by the user.
+ NOTE that with this option, user needs to manually set xen,passthrough
+ in xen.dtb.
- DOMU_MEM[number] is the amount of memory for the VM in MB, default 512MB
diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 4f9c04a..d8772bc 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -2,14 +2,153 @@
offset=$((2*1024*1024))
filesize=0
-prog_req=(mkimage file fdtput)
+prog_req=(mkimage file fdtput mktemp awk)
tmp_files=()
+tmp_dirs=()
function remove_tmp_files()
{
for i in "${tmp_files[@]}"
do
- rm -f "$i"
+ rm -r "$i"
+ done
+
+ for i in "${tmp_dirs[@]}"
+ do
+ rm -rf "$i"
+ done
+}
+
+function sanity_check_partial_dts()
+{
+ local domU_passthrough_path="$1"
+ local repo="$2"
+ local dir="$3"
+ local address_cells_val
+ local size_cells_val
+ local tmpdtb
+ local val
+ local file
+
+ for devpath in $domU_passthrough_path
+ do
+ file=${devpath##*/}
+ file="$repo"/"$dir"/"$file".dts
+
+ if ! test -f "$file"
+ then
+ echo "Device tree \"$file\" is not present"
+ cleanup_and_return_err
+ fi
+
+ tmpdtb=`mktemp`
+ dtc -I dts -O dtb -o $tmpdtb "$file"
+ tmp_files+=($tmpdtb)
+
+ val=$(fdtget $tmpdtb /passthrough \#address-cells)
+ if test -z "$address_cells_val"
+ then
+ address_cells_val="$val"
+ else
+ if test "$address_cells_val" -ne "$val"
+ then
+ echo "Address cells mismatch for ${DOMU_PASSTHROUGH_PATHS[$i]}"
+ cleanup_and_return_err
+ fi
+ fi
+
+ val=$(fdtget $tmpdtb /passthrough \#size-cells)
+ if test -z "$size_cells_val"
+ then
+ size_cells_val="$val"
+ else
+ if test "$size_cells_val" -ne "$val"
+ then
+ echo "Size cells mismatch for ${DOMU_PASSTHROUGH_PATHS[$i]}"
+ cleanup_and_return_err
+ fi
+ fi
+ done
+}
+
+function compile_merge_partial_dts()
+{
+ local repo=$(echo "$1" | awk '{print $1}')
+ local dir=$(echo "$1" | awk '{print $2}')
+ local tmp
+ local tmp_dtb_dir
+
+ if [[ "$repo" =~ .*@.*:.* ]]
+ then
+ tmp=`mktemp -d`
+ tmp_dirs+=($tmp)
+
+ echo "Cloning git repo \"$git_repo\""
+ git clone "$repo" $tmp
+ if [ $? -ne 0 ]
+ then
+ echo "Error occurred while cloning \"$git_repo\""
+ cleanup_and_return_err
+ fi
+
+ repo=$tmp
+ fi
+
+ tmp_dtb_dir=`mktemp -d "partial-dtbs-XXX"`
+
+ if test -z "$dir"
+ then
+ dir="."
+ fi
+
+ i=0
+ while test $i -lt $NUM_DOMUS
+ do
+ if test -z "${DOMU_PASSTHROUGH_PATHS[$i]}"
+ then
+ echo "DOMU_PASSTHROUGH_PATHS[$i] is not defined"
+ cleanup_and_return_err
+ fi
+
+ sanity_check_partial_dts "${DOMU_PASSTHROUGH_PATHS[$i]}" "$repo" "$dir"
+
+ tmp=`mktemp "$tmp_dtb_dir/partial-dts-domU$i-XXX"`
+ tmp_files+=($tmp)
+
+ j=1
+
+ for devpath in ${DOMU_PASSTHROUGH_PATHS[$i]}
+ do
+ file=${devpath##*/}
+ file="$repo"/"$dir"/"$file".dts
+
+ echo "/include/ \"$file\"" >> "$tmp"
+
+ # All the subsequent dts files should not have dts version mentioned
+ if [ $j -gt 1 ]
+ then
+ sed -i '/\/dts-v/d' "$file"
+ fi
+
+ j=$(( $j + 1 ))
+ done
+
+ dtc -I dts -O dtb -o "$tmp".dtb "$tmp"
+ if [ $? -ne 0 ]
+ then
+ echo "Could not compile \"$tmp\""
+ cleanup_and_return_err
+ fi
+
+ if test "${DOMU_PASSTHROUGH_DTB[$i]}"
+ then
+ echo "Can't set both PASSTHROUGH_DTS_REPO and DOMU_PASSTHROUGH_DTB"
+ cleanup_and_return_err
+ fi
+
+ DOMU_PASSTHROUGH_DTB[$i]="$tmp".dtb
+
+ i=$(( $i + 1 ))
done
}
@@ -133,14 +272,14 @@ function xen_device_tree_editing()
dt_set "/chosen/dom0-ramdisk" "reg" "hex" "0x0 $ramdisk_addr 0x0 $(printf "0x%x" $ramdisk_size)"
fi
- for devpath in $XEN_PASSTHROUGH_PATHS
- do
- dt_set "$devpath" "xen,passthrough" "str_a"
- done
-
i=0
while test $i -lt $NUM_DOMUS
do
+ for devpath in ${DOMU_PASSTHROUGH_PATHS[$i]}
+ do
+ dt_set "$devpath" "xen,passthrough" "str_a"
+ done
+
if test "${DOMU_ROOTFS[$i]}" || test "${DOMU_NOBOOT[$i]}"
then
i=$(( $i + 1 ))
@@ -815,6 +954,11 @@ then
exit 1
fi
+if test -z "$NUM_DOMUS"
+then
+ NUM_DOMUS=0
+fi
+
if test "$XEN"
then
os="xen"
@@ -852,6 +996,12 @@ fi
# tftp or move the files to a partition
cd "$uboot_dir"
+if test "$PASSTHROUGH_DTS_REPO"
+then
+ compile_merge_partial_dts "$PASSTHROUGH_DTS_REPO"
+ echo "Done compiling the partial device trees"
+fi
+
if test "$FIT"
then
if ! test "$FDTEDIT"