[ImageBuilder] Add config option to use separate load commands for Xen, DOM0 and DOMU binaries

Ayan Kumar Halder posted 1 patch 4 months, 2 weeks ago
Failed in applying to current master (apply log)
There is a newer version of this series
README.md                | 14 ++++++++++++++
scripts/uboot-script-gen | 32 +++++++++++++++++++++++---------
2 files changed, 37 insertions(+), 9 deletions(-)
[ImageBuilder] Add config option to use separate load commands for Xen, DOM0 and DOMU binaries
Posted by Ayan Kumar Halder 4 months, 2 weeks ago
Introduce the following options :-
1. XEN_LOAD - This specifies command to load xen hypervisor binary and device
tree.
2. DOM0_LOAD - This specifies command to load Dom0 binaries.
3. DOMU_LOAD[] - This specifies command to load DomU binaries.

There can be situations where Xen, Dom0 and DomU binaries are stored in
different partitions. Thus, imagebuilder should provide a way the binaries
using different commands.

If any of the above options are not specified, LOAD_CMD is used by default.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
---
 README.md                | 14 ++++++++++++++
 scripts/uboot-script-gen | 32 +++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index b7be268..4be6efb 100644
--- a/README.md
+++ b/README.md
@@ -33,10 +33,12 @@ BOOT_CMD="booti"
 
 DEVICE_TREE="mpsoc.dtb"
 XEN="xen"
+XEN_LOAD="ext4load mmc 0:1"
 XEN_CMD="console=dtuart dtuart=serial0 dom0_mem=1G dom0_max_vcpus=1 bootscrub=0 vwfi=native sched=null"
 PASSTHROUGH_DTS_REPO="git@github.com:Xilinx/xen-passthrough-device-trees.git device-trees-2021.2/zcu102"
 DOM0_KERNEL="Image-dom0"
 DOM0_CMD="console=hvc0 earlycon=xen earlyprintk=xen clk_ignore_unused"
+DOM0_LOAD="ext4load mmc 2:1"
 DOM0_RAMDISK="dom0-ramdisk.cpio"
 DOM0_MEM=1024
 DOM0_VCPUS=1
@@ -46,11 +48,13 @@ DT_OVERLAY[0]="host_dt_overlay.dtbo"
 
 NUM_DOMUS=2
 DOMU_KERNEL[0]="zynqmp-dom1/Image-domU"
+DOMU_LOAD[0]="ext4load mmc 4:1"
 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_COLORS[0]="6-14"
 DOMU_KERNEL[1]="zynqmp-dom2/Image-domU"
+DOMU_LOAD[1]="ext4load mmc 5:1"
 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"
 DOMU_MEM[1]=512
@@ -99,6 +103,9 @@ Where:
 - XEN_CMD specifies the command line arguments used for Xen.  If not
   set, the default one will be used.
 
+- XEN_LOAD specifies the command to load XEN and DEVICE_TREE. If not set,
+  LOAD_CMD will be used.
+
 - XEN_STATIC_HEAP="baseaddr1 size1 ... baseaddrN sizeN"
   if specified, indicates the host physical address regions
   [baseaddr, baseaddr + size) to be reserved as Xen static heap.
@@ -109,6 +116,9 @@ Where:
   uboot-script-gen will compile the partial device trees which have
   been specified in DOMU_PASSTHROUGH_PATHS[number].
 
+- DOM0_LOAD specifies the command to load DOM0_KERNEL and DOM0_RAMDISK. If not
+  set, LOAD_CMD will be used.
+
 - DOM0_KERNEL specifies the Dom0 kernel file to load.
   For dom0less configurations, the parameter is optional.
 
@@ -159,6 +169,10 @@ Where:
   kernel. If not set and DOMU_VPL011[number] is not set to 0, then
   "console=ttyAMA0" is used.
 
+- DOMU_LOAD[number] specifies the command to load DOMU_KERNEL[number],
+  DOMU_RAMDISK[number] and DOMU_PASSTHROUGH_DTB[number]. If not set, then
+  LOAD_CMD is used.
+
 - DOMU_RAMDISK[number] specifies the DomU ramdisk to use.
 
 - DOMU_PASSTHROUGH_PATHS[number] specifies the passthrough devices (
diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index b81e614..fed53aa 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -737,6 +737,7 @@ function load_file()
 {
     local filename=$1
     local fit_scr_name=$2
+    local load_cmd=$3
 
     local absolute_path="$(realpath --no-symlinks $filename)"
     local base="$(realpath $PWD)"/
@@ -748,10 +749,10 @@ function load_file()
         add_size_from_file $filename
     else
         if test "$CALC"; then
-            echo "$LOAD_CMD \${memaddr} ${prepend_path:+$prepend_path/}$relative_path" >> $UBOOT_SOURCE
+            echo "$load_cmd \${memaddr} ${prepend_path:+$prepend_path/}$relative_path" >> $UBOOT_SOURCE
             add_size_calculate $fit_scr_name
         else
-            echo "$LOAD_CMD $memaddr ${prepend_path:+$prepend_path/}$relative_path" >> $UBOOT_SOURCE
+            echo "$load_cmd $memaddr ${prepend_path:+$prepend_path/}$relative_path" >> $UBOOT_SOURCE
             add_size_from_file $filename
         fi
     fi
@@ -1003,11 +1004,15 @@ generate_uboot_images()
 
 xen_file_loading()
 {
+    if test -z "$DOM0_LOAD"
+    then
+        DOM0_LOAD="$LOAD_CMD"
+    fi
     if test "$DOM0_KERNEL"
     then
         check_compressed_file_type $DOM0_KERNEL "executable\|uImage"
         dom0_kernel_addr=$memaddr
-        load_file $DOM0_KERNEL "dom0_linux"
+        load_file $DOM0_KERNEL "dom0_linux" "$DOM0_LOAD"
         dom0_kernel_size=$filesize
     fi
     if test "$DOM0_RAMDISK"
@@ -1015,7 +1020,7 @@ xen_file_loading()
         check_compressed_file_type $DOM0_RAMDISK "cpio archive"
         ramdisk_addr=$memaddr
         ramdisk_path=$DOM0_RAMDISK
-        load_file "$DOM0_RAMDISK" "dom0_ramdisk"
+        load_file "$DOM0_RAMDISK" "dom0_ramdisk" "$DOM0_LOAD"
         ramdisk_size=$filesize
     else
         ramdisk_addr="-"
@@ -1024,6 +1029,10 @@ xen_file_loading()
     i=0
     while test $i -lt $NUM_DOMUS
     do
+        if test -z "${DOMU_LOAD[$i]}"
+        then
+            DOMU_LOAD[$i]="$LOAD_CMD"
+        fi
         if test "${DOMU_ROOTFS[$i]}" || test "${DOMU_NOBOOT[$i]}"
         then
             if test -z "${DOMU_NOBOOT[$i]}"
@@ -1042,20 +1051,20 @@ xen_file_loading()
 
         check_compressed_file_type ${DOMU_KERNEL[$i]} "executable\|uImage"
         domU_kernel_addr[$i]=$memaddr
-        load_file ${DOMU_KERNEL[$i]} "domU${i}_kernel"
+        load_file ${DOMU_KERNEL[$i]} "domU${i}_kernel" "${DOMU_LOAD[$i]}"
         domU_kernel_size[$i]=$filesize
         if test "${DOMU_RAMDISK[$i]}"
         then
             check_compressed_file_type ${DOMU_RAMDISK[$i]} "cpio archive"
             domU_ramdisk_addr[$i]=$memaddr
-            load_file ${DOMU_RAMDISK[$i]} "domU${i}_ramdisk"
+            load_file ${DOMU_RAMDISK[$i]} "domU${i}_ramdisk" "${DOMU_LOAD[$i]}"
             domU_ramdisk_size[$i]=$filesize
         fi
         if test "${DOMU_PASSTHROUGH_DTB[$i]}"
         then
             check_compressed_file_type ${DOMU_PASSTHROUGH_DTB[$i]} "Device Tree Blob"
             domU_passthrough_dtb_addr[$i]=$memaddr
-            load_file ${DOMU_PASSTHROUGH_DTB[$i]} "domU${i}_fdt"
+            load_file ${DOMU_PASSTHROUGH_DTB[$i]} "domU${i}_fdt" "${DOMU_LOAD[$i]}"
             domU_passthrough_dtb_size[$i]=$filesize
         fi
         i=$(( $i + 1 ))
@@ -1070,9 +1079,14 @@ xen_file_loading()
         generate_uboot_images
     fi
 
+    if test -z "${XEN_LOAD}"
+    then
+        XEN_LOAD="$LOAD_CMD"
+    fi
+
     kernel_addr=$memaddr
     kernel_path=$XEN
-    load_file "$XEN" "host_kernel"
+    load_file "$XEN" "host_kernel" "$XEN_LOAD"
 
     xen_policy_addr="-"
     if test -n "$XEN_POLICY"
@@ -1691,7 +1705,7 @@ fi
 
 check_file_type $DEVICE_TREE "Device Tree Blob"
 device_tree_addr=$memaddr
-load_file $DEVICE_TREE "host_fdt"
+load_file $DEVICE_TREE "host_fdt" "$XEN_LOAD"
 bitstream_load_and_config  # bitstream is loaded last but used first
 device_tree_editing $device_tree_addr
 
-- 
2.25.1
Re: [ImageBuilder] Add config option to use separate load commands for Xen, DOM0 and DOMU binaries
Posted by Stefano Stabellini 4 months, 1 week ago
On Wed, 6 Aug 2025, Ayan Kumar Halder wrote:
> Introduce the following options :-
> 1. XEN_LOAD - This specifies command to load xen hypervisor binary and device
> tree.
> 2. DOM0_LOAD - This specifies command to load Dom0 binaries.
> 3. DOMU_LOAD[] - This specifies command to load DomU binaries.
> 
> There can be situations where Xen, Dom0 and DomU binaries are stored in
> different partitions. Thus, imagebuilder should provide a way the binaries
> using different commands.
> 
> If any of the above options are not specified, LOAD_CMD is used by default.
> 
> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>

The patch is correct and the new config options look good. Two things.

The following check should be removed or, better, modified to account
for the new options:

    if test ! "$LOAD_CMD"
    then
        echo "LOAD_CMD not set, either specify it in the config or set it with the -t option"
        exit 1
    fi

Thanks to this patch, it shouldn't be necessary to specify LOAD_CMD any
longer.

find_root_dev and fit are the only two remaining users of LOAD_CMD.
While I think it makes sense to keep LOAD_CMD for fit, find_root_dev
should probably use DOM0_LOAD instead.

This incremental change (untested) should work. What do you think?



diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 9e97944..867876f 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -824,10 +824,10 @@ function check_compressed_file_type()
 
 function find_root_dev()
 {
-
-    local dev=${LOAD_CMD%:*}
+    local load_cmd=$1
+    local dev=${load_cmd%:*}
     dev=${dev##* }
-    local par=${LOAD_CMD#*:}
+    local par=${load_cmd#*:}
 
     if [ -z "$dev" ] || [ -z "$par" ]
     then
@@ -838,10 +838,10 @@ function find_root_dev()
 
     par=$((par + 1))
 
-    if [[ $LOAD_CMD =~ mmc ]]
+    if [[ $load_cmd =~ mmc ]]
     then
         root_dev="/dev/mmcblk${dev}p${par}"
-    elif [[ $LOAD_CMD =~ scsi ]]
+    elif [[ $load_cmd =~ scsi ]]
     then
         # converts number to a scsi device character
         dev=$((dev + 97))
@@ -912,7 +912,7 @@ function xen_config()
         then
             DOM0_CMD="$DOM0_CMD root=/dev/ram0"
         else
-            find_root_dev
+            find_root_dev "$DOM0_LOAD"
             # $root_dev is set by find_root_dev
             DOM0_CMD="$DOM0_CMD root=$root_dev"
         fi
@@ -960,7 +960,7 @@ function linux_config()
         then
             LINUX_CMD="$LINUX_CMD root=/dev/ram0"
         else
-            find_root_dev
+            find_root_dev "$LOAD_CMD"
             # $root_dev is set by find_root_dev
             LINUX_CMD="$LINUX_CMD root=$root_dev"
         fi
@@ -990,10 +990,6 @@ generate_uboot_images()
 
 xen_file_loading()
 {
-    if test -z "$DOM0_LOAD"
-    then
-        DOM0_LOAD="$LOAD_CMD"
-    fi
     if test "$DOM0_KERNEL"
     then
         check_compressed_file_type $DOM0_KERNEL "executable\|uImage"
@@ -1065,11 +1061,6 @@ xen_file_loading()
         generate_uboot_images
     fi
 
-    if test -z "${XEN_LOAD}"
-    then
-        XEN_LOAD="$LOAD_CMD"
-    fi
-
     kernel_addr=$memaddr
     kernel_path=$XEN
     load_file "$XEN" "host_kernel" "$XEN_LOAD"
@@ -1518,12 +1509,22 @@ then
     FIT="${UBOOT_SOURCE%.source}.fit"
 fi
 
-if test ! "$LOAD_CMD"
+if test ! "$LOAD_CMD" && ! test "$XEN_LOAD"
 then
     echo "LOAD_CMD not set, either specify it in the config or set it with the -t option"
     exit 1
 fi
 
+if test -z "$DOM0_LOAD"
+then
+    DOM0_LOAD="$LOAD_CMD"
+fi
+
+if test -z "${XEN_LOAD}"
+then
+    XEN_LOAD="$LOAD_CMD"
+fi
+
 if test ! "$BOOT_CMD"
 then
     BOOT_CMD="booti"
Re: [ImageBuilder] Add config option to use separate load commands for Xen, DOM0 and DOMU binaries
Posted by Ayan Kumar Halder 4 months, 1 week ago
Hi Stefano,

On 11/08/2025 22:38, Stefano Stabellini wrote:
> On Wed, 6 Aug 2025, Ayan Kumar Halder wrote:
>> Introduce the following options :-
>> 1. XEN_LOAD - This specifies command to load xen hypervisor binary and device
>> tree.
>> 2. DOM0_LOAD - This specifies command to load Dom0 binaries.
>> 3. DOMU_LOAD[] - This specifies command to load DomU binaries.
>>
>> There can be situations where Xen, Dom0 and DomU binaries are stored in
>> different partitions. Thus, imagebuilder should provide a way the binaries
>> using different commands.
>>
>> If any of the above options are not specified, LOAD_CMD is used by default.
>>
>> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
> The patch is correct and the new config options look good. Two things.
>
> The following check should be removed or, better, modified to account
> for the new options:
>
>      if test ! "$LOAD_CMD"
>      then
>          echo "LOAD_CMD not set, either specify it in the config or set it with the -t option"
>          exit 1
>      fi
>
> Thanks to this patch, it shouldn't be necessary to specify LOAD_CMD any
> longer.

Actually, we should keep this check when Linux is loaded (without Xen). IOW,

@@ -1557,6 +1551,11 @@ then
  elif test "$LINUX"
  then
      os="linux"
+    if test ! "$LOAD_CMD"
+    then
+        echo "LOAD_CMD not set, either specify it in the config or set 
it with the -t option"
+        exit 1
+    fi
      linux_config

>
> find_root_dev and fit are the only two remaining users of LOAD_CMD.
> While I think it makes sense to keep LOAD_CMD for fit, find_root_dev
> should probably use DOM0_LOAD instead.
yes.
>
> This incremental change (untested) should work. What do you think?
>
>
>
> diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
> index 9e97944..867876f 100755
> --- a/scripts/uboot-script-gen
> +++ b/scripts/uboot-script-gen
> @@ -824,10 +824,10 @@ function check_compressed_file_type()
>   
>   function find_root_dev()
>   {
> -
> -    local dev=${LOAD_CMD%:*}
> +    local load_cmd=$1
> +    local dev=${load_cmd%:*}
>       dev=${dev##* }
> -    local par=${LOAD_CMD#*:}
> +    local par=${load_cmd#*:}
>   
>       if [ -z "$dev" ] || [ -z "$par" ]
>       then
> @@ -838,10 +838,10 @@ function find_root_dev()
>   
>       par=$((par + 1))
>   
> -    if [[ $LOAD_CMD =~ mmc ]]
> +    if [[ $load_cmd =~ mmc ]]
>       then
>           root_dev="/dev/mmcblk${dev}p${par}"
> -    elif [[ $LOAD_CMD =~ scsi ]]
> +    elif [[ $load_cmd =~ scsi ]]
>       then
>           # converts number to a scsi device character
>           dev=$((dev + 97))
> @@ -912,7 +912,7 @@ function xen_config()
>           then
>               DOM0_CMD="$DOM0_CMD root=/dev/ram0"
>           else
> -            find_root_dev
> +            find_root_dev "$DOM0_LOAD"
>               # $root_dev is set by find_root_dev
>               DOM0_CMD="$DOM0_CMD root=$root_dev"
>           fi
> @@ -960,7 +960,7 @@ function linux_config()
>           then
>               LINUX_CMD="$LINUX_CMD root=/dev/ram0"
>           else
> -            find_root_dev
> +            find_root_dev "$LOAD_CMD"
>               # $root_dev is set by find_root_dev
>               LINUX_CMD="$LINUX_CMD root=$root_dev"
>           fi
Till here the change looks ok.
> @@ -990,10 +990,6 @@ generate_uboot_images()
>   
>   xen_file_loading()
>   {
> -    if test -z "$DOM0_LOAD"
> -    then
> -        DOM0_LOAD="$LOAD_CMD"
> -    fi
This and
>       if test "$DOM0_KERNEL"
>       then
>           check_compressed_file_type $DOM0_KERNEL "executable\|uImage"
> @@ -1065,11 +1061,6 @@ xen_file_loading()
>           generate_uboot_images
>       fi
>   
> -    if test -z "${XEN_LOAD}"
> -    then
> -        XEN_LOAD="$LOAD_CMD"
> -    fi
> -

this, I have a concern about moving the changes out of xen_file_loading()

In xen_file_loading(), we set DOM0_LOAD, XEN_LOAD and DOMU_LOAD[i]. With 
this change, we set DOM0_LOAD , XEN_LOAD at the beginning of the script 
and DOMU_LOAD[i] in the function. This looks a bit odd to me.

Further DOM0_LOAD and XEN_LOAD should be set only when "$XEN" is set.

I can leave the change as it is in the current patch or I can move them 
to xen_config().

Please let me know your thoughts.

I have sent "[ImageBuilder v2] Add config option to use separate load 
commands for Xen, DOM0 and DOMU binaries" so that it becomes a bit clear.

- Ayan

>       kernel_addr=$memaddr
>       kernel_path=$XEN
>       load_file "$XEN" "host_kernel" "$XEN_LOAD"
> @@ -1518,12 +1509,22 @@ then
>       FIT="${UBOOT_SOURCE%.source}.fit"
>   fi
>   
> -if test ! "$LOAD_CMD"
> +if test ! "$LOAD_CMD" && ! test "$XEN_LOAD"
>   then
>       echo "LOAD_CMD not set, either specify it in the config or set it with the -t option"
>       exit 1
>   fi
>   
> +if test -z "$DOM0_LOAD"
> +then
> +    DOM0_LOAD="$LOAD_CMD"
> +fi
> +
> +if test -z "${XEN_LOAD}"
> +then
> +    XEN_LOAD="$LOAD_CMD"
> +fi
> +
>   if test ! "$BOOT_CMD"
>   then
>       BOOT_CMD="booti"