All of lore.kernel.org
 help / color / mirror / Atom feed
* [ImageBuilder][PATCH v2 0/4] Add extra ImageBuilder features
@ 2022-06-30 14:00 Andrei Cherechesu (OSS)
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 1/4] scripts: Add support for prepending path to file names Andrei Cherechesu (OSS)
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Andrei Cherechesu (OSS) @ 2022-06-30 14:00 UTC (permalink / raw)
  To: xen-devel; +Cc: viryaos-discuss, sstabellini, Andrei Cherechesu

From: Andrei Cherechesu <andrei.cherechesu@nxp.com>

Hello,

Sorry for the late re-submission of patches, but I had some
company internal work to take care of. I managed to include the
changes mentioned by Stefano S. and Ayan K. H. in the discussions
for the first version of patches.

Changes in v2:
 - Dropped the patch which added support for DOMU_DIRECT_MAP and
DOMU_STATIC_MEM from the set, since it was already submitted by
someone else
 - For PATCH 1/4: Added the PREPEND_PATH option in disk_image script
as well
 - For PATCH 2/4: Added support for dynamically computing load
addresses and storing them in variables for each loaded binary,
along with the size of each loaded binary. Now, there is no
hardcoded address inside the generated script.
 - For PATCH 3/4: Rebased
 - For PATCH 4/4: Skip adding boot command to script if BOOT_CMD
is set to "none", instead of via passing parameter to script.


Andrei Cherechesu (4):
  scripts: Add support for prepending path to file names
  uboot-script-gen: Dynamically compute addr and size when loading
    binaries
  uboot-script-gen: Enable appending extra commands to boot script
  uboot-script-gen: Enable not adding boot command to script

 README.md                |   5 +-
 scripts/disk_image       |  37 +++++----
 scripts/uboot-script-gen | 169 +++++++++++++++++++++++++++++++++------
 3 files changed, 172 insertions(+), 39 deletions(-)

-- 
2.35.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ImageBuilder][PATCH v2 1/4] scripts: Add support for prepending path to file names
  2022-06-30 14:00 [ImageBuilder][PATCH v2 0/4] Add extra ImageBuilder features Andrei Cherechesu (OSS)
@ 2022-06-30 14:00 ` Andrei Cherechesu (OSS)
  2022-07-07  0:08   ` Stefano Stabellini
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 2/4] uboot-script-gen: Dynamically compute addr and size when loading binaries Andrei Cherechesu (OSS)
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Andrei Cherechesu (OSS) @ 2022-06-30 14:00 UTC (permalink / raw)
  To: xen-devel; +Cc: viryaos-discuss, sstabellini, Andrei Cherechesu

From: Andrei Cherechesu <andrei.cherechesu@nxp.com>

Added support for prepending path to file names in the final generated
u-boot script, for the use-case where we have the files in a separate
folder that can be accessed with a given $LOAD_CMD.

For example, we can have "fatload mmc 0:2" as LOAD_CMD but the
files would need to be loaded from the /boot folder within the 2nd
partition, not from the root ("/"). By specifying the "-p <path>"
parameter when running the script, paths like "/boot" can be
automatically prepended to the generated u-boot commands used
to load the files in board's memory.

Also added the support to disk_image script, to enable generating
a FAT partition with the binaries deployed in a custom folder
within it, if the "-p" parameter is specified.

Signed-off-by: Andrei Cherechesu <andrei.cherechesu@nxp.com>
---
 scripts/disk_image       | 37 +++++++++++++++++++++++--------------
 scripts/uboot-script-gen | 12 ++++++++----
 2 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/scripts/disk_image b/scripts/disk_image
index 12fb06b..97e798f 100755
--- a/scripts/disk_image
+++ b/scripts/disk_image
@@ -539,7 +539,7 @@ function write_rootfs()
 function print_help
 {
     echo "usage:"
-    echo "	$0 -c CONFIG_FILE -d UBOOT_DIRECTORY -t UBOOT_TYPE <-w WORK_DIRECTORY> <-s SLACK> <-a> -o IMG_FILE"
+    echo "	$0 -c CONFIG_FILE -d UBOOT_DIRECTORY -t UBOOT_TYPE <-w WORK_DIRECTORY> <-s SLACK> <-a> -o IMG_FILE <-p PREPEND_PATH>"
     echo "	$0 -h"
     echo "where:"
     echo "	-c CONFIG_FILE - configuration file"
@@ -553,6 +553,7 @@ function print_help
     echo "	-s SLACK - free MB to add to each partition, default 128"
     echo "	-a specifies that the size of IMG_FILE has to be aligned to the nearest power of two"
     echo "	-o IMG_FILE - the output img file "
+    echo "	-p PREPEND_PATH - path to be appended before file names to customize deploy location within rootfs"
     echo "Example:"
     echo "	$0 -c ../config -d ./build42 -w tmp -o disk.img"
 }
@@ -564,7 +565,7 @@ then
     exit 1
 fi
 
-while getopts ":w:d:c:t:s:o:ah" opt
+while getopts ":w:d:c:t:s:o:ahp:" opt
 do
     case ${opt} in
     t )
@@ -606,6 +607,9 @@ do
     a )
         ALIGN=1
         ;;
+    p )
+        PREPEND_PATH="$OPTARG"
+        ;;
     h )
         print_help
         exit 0
@@ -828,56 +832,61 @@ mount /dev/mapper/diskimage1 $DESTDIR/part/disk1
 
 # only copy over files that were counted for the partition size
 cd "$UBOOT_OUT"
-cp --parents "$DOM0_KERNEL" "${DESTDIR_ABS}/part/disk1/"
-cp --parents "$DEVICE_TREE" "${DESTDIR_ABS}/part/disk1/"
-cp --parents "$UBOOT_SCRIPT" "${DESTDIR_ABS}/part/disk1/"
+if [ -n "$PREPEND_PATH" ]
+then
+    mkdir -p "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
+fi
+
+cp --parents "$DOM0_KERNEL" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
+cp --parents "$DEVICE_TREE" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
+cp --parents "$UBOOT_SCRIPT" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
 
 if test "${DOM0_RAMDISK}"
 then
-    cp --parents "$DOM0_RAMDISK" "${DESTDIR_ABS}/part/disk1/"
+    cp --parents "$DOM0_RAMDISK" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
 fi
 if test "$NUM_DT_OVERLAY" && test "$NUM_DT_OVERLAY" -gt 0
 then
     i=0
     while test $i -lt "$NUM_DT_OVERLAY"
     do
-        cp --parents "${DT_OVERLAY[$i]}" "${DESTDIR_ABS}/part/disk1/"
+        cp --parents "${DT_OVERLAY[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
         i=$(( $i + 1 ))
     done
 fi
 if test "${UBOOT_SOURCE}"
 then
-    cp --parents "$UBOOT_SOURCE" "${DESTDIR_ABS}/part/disk1/"
+    cp --parents "$UBOOT_SOURCE" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
 fi
 if test "${XEN}"
 then
-    cp --parents "$XEN" "${DESTDIR_ABS}/part/disk1/"
+    cp --parents "$XEN" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
 fi
 if test "$NUM_BOOT_AUX_FILE" && test "$NUM_BOOT_AUX_FILE" -gt 0
 then
     i=0
     while test $i -lt "$NUM_BOOT_AUX_FILE"
     do
-        cp --parents "${BOOT_AUX_FILE[$i]}" "${DESTDIR_ABS}/part/disk1/"
+        cp --parents "${BOOT_AUX_FILE[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
         i=$(( $i + 1 ))
     done
 fi
 if test "${BITSTREAM}"
 then
-    cp --parents "$BITSTREAM" "${DESTDIR_ABS}/part/disk1/"
+    cp --parents "$BITSTREAM" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
 fi
 
 i=0
 while test $i -lt $NUM_DOMUS
 do
-    cp --parents "${DOMU_KERNEL[$i]}" "${DESTDIR_ABS}/part/disk1/"
+    cp --parents "${DOMU_KERNEL[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
     if test "${DOMU_RAMDISK[$i]}"
     then
-        cp --parents "${DOMU_RAMDISK[$i]}" "${DESTDIR_ABS}/part/disk1/"
+        cp --parents "${DOMU_RAMDISK[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
     fi
     if test "${DOMU_PASSTHROUGH_DTB[$i]}"
     then
-        cp --parents "${DOMU_PASSTHROUGH_DTB[$i]}" "${DESTDIR_ABS}/part/disk1/"
+        cp --parents "${DOMU_PASSTHROUGH_DTB[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
     fi
     i=$(( $i + 1 ))
 done
diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 085e29f..8f08cd6 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -316,7 +316,7 @@ function load_file()
     then
         echo "imxtract \$fit_addr $fit_scr_name $memaddr" >> $UBOOT_SOURCE
     else
-        echo "$LOAD_CMD $memaddr $relative_path" >> $UBOOT_SOURCE
+        echo "$LOAD_CMD $memaddr ${prepend_path:+$prepend_path/}$relative_path" >> $UBOOT_SOURCE
     fi
     add_size $filename
 }
@@ -891,7 +891,7 @@ function print_help
 {
     script=`basename "$0"`
     echo "usage:"
-    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f]"
+    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f] [-p PREPEND_PATH]"
     echo "	$script -h"
     echo "where:"
     echo "	CONFIG_FILE - configuration file"
@@ -907,6 +907,7 @@ function print_help
     echo "	HINT - the file name of the crt and key file minus the suffix (ex, hint.crt and hint.key)"
     echo "	U-BOOT_DTB - u-boot control dtb so that the public key gets added to it"
     echo "	-f - enable generating a FIT image"
+    echo "	PREPEND_PATH - path to be appended before file names to match deploy location within rootfs"
     echo "	-h - prints out the help message and exits "
     echo "Defaults:"
     echo "	CONFIG_FILE=$cfg_file, UBOOT_TYPE=\"LOAD_CMD\" env var, DIRECTORY=$uboot_dir"
@@ -914,7 +915,7 @@ function print_help
     echo "	$script -c ../config -d ./build42 -t \"scsi load 1:1\""
 }
 
-while getopts ":c:t:d:ho:k:u:f" opt; do
+while getopts ":c:t:d:ho:k:u:fp:" opt; do
     case ${opt} in
     t )
         case $OPTARG in
@@ -953,6 +954,9 @@ while getopts ":c:t:d:ho:k:u:f" opt; do
     f )
         fit_opt=y
         ;;
+    p )
+        prepend_path="$OPTARG"
+        ;;
     h )
         print_help
         exit 0
@@ -1179,5 +1183,5 @@ then
     echo "$LOAD_CMD $fit_addr $FIT; source $fit_addr:boot_scr"
 else
     echo "Generated uboot script $UBOOT_SCRIPT, to be loaded at address $uboot_addr:"
-    echo "$LOAD_CMD $uboot_addr $UBOOT_SCRIPT; source $uboot_addr"
+    echo "$LOAD_CMD $uboot_addr ${prepend_path:+$prepend_path/}$UBOOT_SCRIPT; source $uboot_addr"
 fi
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [ImageBuilder][PATCH v2 2/4] uboot-script-gen: Dynamically compute addr and size when loading binaries
  2022-06-30 14:00 [ImageBuilder][PATCH v2 0/4] Add extra ImageBuilder features Andrei Cherechesu (OSS)
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 1/4] scripts: Add support for prepending path to file names Andrei Cherechesu (OSS)
@ 2022-06-30 14:00 ` Andrei Cherechesu (OSS)
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 3/4] uboot-script-gen: Enable appending extra commands to boot script Andrei Cherechesu (OSS)
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 4/4] uboot-script-gen: Enable not adding boot command to script Andrei Cherechesu (OSS)
  3 siblings, 0 replies; 8+ messages in thread
From: Andrei Cherechesu (OSS) @ 2022-06-30 14:00 UTC (permalink / raw)
  To: xen-devel; +Cc: viryaos-discuss, sstabellini, Andrei Cherechesu

From: Andrei Cherechesu <andrei.cherechesu@nxp.com>

Normally, the script would precompute the sizes of the loaded binaries
and addresses where they are loaded before generating the script,
and the sizes and addresses that needed to be provided to Xen via
/chosen would be hardcoded in the boot script.

Added option via "-s" parameter to use the ${filesize} variable
in u-boot, which is set automatically after a *load command.
The value stored by filesize is now stored in a u-boot env variable
with the name corresponding to the binary that was loaded before.
The newly set variables are now used in setting the /chosen node,
instead of the hardcoded values.

Also, the loading addresses for the files are dynamically computed
and aligned to 0x200000 using the `setexpr` u-boot command. Basically,
if the option is used, there are zero hardcoded addresses inside the
boot script, and everything is determined based on the MEMORY_START
parameter and each binary's size.

If the "-s" parameter is not used, the script does not store the
binaries' sizes and addresses in variables and uses the precomputed
ones when advertising them in the /chosen node.

Signed-off-by: Andrei Cherechesu <andrei.cherechesu@nxp.com>
---
 scripts/uboot-script-gen | 136 ++++++++++++++++++++++++++++++++-------
 1 file changed, 114 insertions(+), 22 deletions(-)

diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 8f08cd6..f8d2fb0 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -4,6 +4,9 @@ offset=$((2*1024*1024))
 filesize=0
 prog_req=(mkimage file fdtput mktemp awk)
 
+padding_mask=`printf "0x%X\n" $(($offset - 1))`
+padding_mask_inv=`printf "0x%X\n" $((~$padding_mask))`
+
 function cleanup_and_return_err()
 {
     rm -f $UBOOT_SOURCE $UBOOT_SCRIPT
@@ -91,10 +94,18 @@ function add_device_tree_kernel()
     local size=$3
     local bootargs=$4
 
-    dt_mknode "$path" "module$addr"
-    dt_set "$path/module$addr" "compatible" "str_a" "multiboot,kernel multiboot,module"
-    dt_set "$path/module$addr" "reg" "hex"  "0x0 $addr 0x0 $(printf "0x%x" $size)"
-    dt_set "$path/module$addr" "bootargs" "str" "$bootargs"
+    if test "$dynamic_loading_opt"
+    then
+        dt_mknode "$path" "module\${"$addr"}"
+        dt_set "$path/module\${"$addr"}" "compatible" "str_a" "multiboot,kernel multiboot,module"
+        dt_set "$path/module\${"$addr"}" "reg" "hex"  "0x0 0x\${"$addr"} 0x0 0x\${"$size"}"
+        dt_set "$path/module\${"$addr"}" "bootargs" "str" "$bootargs"
+    else
+        dt_mknode "$path" "module$addr"
+        dt_set "$path/module$addr" "compatible" "str_a" "multiboot,kernel multiboot,module"
+        dt_set "$path/module$addr" "reg" "hex"  "0x0 $addr 0x0 $(printf "0x%x" $size)"
+        dt_set "$path/module$addr" "bootargs" "str" "$bootargs"
+    fi
 }
 
 
@@ -104,9 +115,16 @@ function add_device_tree_ramdisk()
     local addr=$2
     local size=$3
 
-    dt_mknode "$path"  "module$addr"
-    dt_set "$path/module$addr" "compatible" "str_a" "multiboot,ramdisk multiboot,module"
-    dt_set "$path/module$addr" "reg" "hex"  "0x0 $addr 0x0 $(printf "0x%x" $size)"
+    if test "$dynamic_loading_opt"
+    then
+        dt_mknode "$path" "module\${"$addr"}"
+        dt_set "$path/module\${"$addr"}" "compatible" "str_a" "multiboot,ramdisk multiboot,module"
+        dt_set "$path/module\${"$addr"}" "reg" "hex"  "0x0 0x\${"$addr"} 0x0 0x\${"$size"}"
+    else
+        dt_mknode "$path" "module$addr"
+        dt_set "$path/module$addr" "compatible" "str_a" "multiboot,ramdisk multiboot,module"
+        dt_set "$path/module$addr" "reg" "hex"  "0x0 $addr 0x0 $(printf "0x%x" $size)"
+    fi
 }
 
 
@@ -116,9 +134,16 @@ function add_device_tree_passthrough()
     local addr=$2
     local size=$3
 
-    dt_mknode "$path"  "module$addr"
-    dt_set "$path/module$addr" "compatible" "str_a" "multiboot,device-tree multiboot,module"
-    dt_set "$path/module$addr" "reg" "hex"  "0x0 $addr 0x0 $(printf "0x%x" $size)"
+    if test "$dynamic_loading_opt"
+    then
+        dt_mknode "$path" "module\${"$addr"}"
+        dt_set "$path/module\${"$addr"}" "compatible" "str_a" "multiboot,device-tree multiboot,module"
+        dt_set "$path/module\${"$addr"}" "reg" "hex"  "0x0 0x\${"$addr"} 0x0 0x\${"$size"}"
+    else
+        dt_mknode "$path" "module$addr"
+        dt_set "$path/module$addr" "compatible" "str_a" "multiboot,device-tree multiboot,module"
+        dt_set "$path/module$addr" "reg" "hex"  "0x0 $addr 0x0 $(printf "0x%x" $size)"
+    fi
 }
 
 function add_device_tree_mem()
@@ -186,7 +211,12 @@ function xen_device_tree_editing()
     then
         dt_mknode "/chosen" "dom0"
         dt_set "/chosen/dom0" "compatible" "str_a" "xen,linux-zimage xen,multiboot-module multiboot,module"
-        dt_set "/chosen/dom0" "reg" "hex" "0x0 $dom0_kernel_addr 0x0 $(printf "0x%x" $dom0_kernel_size)"
+        if test "$dynamic_loading_opt"
+        then
+            dt_set "/chosen/dom0" "reg" "hex" "0x0 0x\${dom0_linux_addr} 0x0 0x\${dom0_linux_size}"
+        else
+            dt_set "/chosen/dom0" "reg" "hex" "0x0 $dom0_kernel_addr 0x0 $(printf "0x%x" $dom0_kernel_size)"
+        fi
         dt_set "/chosen" "xen,dom0-bootargs" "str" "$DOM0_CMD"
     fi
 
@@ -194,7 +224,12 @@ function xen_device_tree_editing()
     then
         dt_mknode "/chosen" "dom0-ramdisk"
         dt_set "/chosen/dom0-ramdisk" "compatible" "str_a" "xen,linux-initrd xen,multiboot-module multiboot,module"
-        dt_set "/chosen/dom0-ramdisk" "reg" "hex" "0x0 $ramdisk_addr 0x0 $(printf "0x%x" $ramdisk_size)"
+        if test "$dynamic_loading_opt"
+        then
+            dt_set "/chosen/dom0-ramdisk" "reg" "hex" "0x0 0x\${dom0_ramdisk_addr} 0x0 0x\${dom0_ramdisk_size}"
+        else
+            dt_set "/chosen/dom0-ramdisk" "reg" "hex" "0x0 $ramdisk_addr 0x0 $(printf "0x%x" $ramdisk_size)"
+        fi
     fi
 
     i=0
@@ -241,14 +276,29 @@ function xen_device_tree_editing()
             dt_set "/chosen/domU$i" "colors" "hex" "$(printf "0x%x" $bitcolors)"
         fi
 
-        add_device_tree_kernel "/chosen/domU$i" ${domU_kernel_addr[$i]} ${domU_kernel_size[$i]} "${DOMU_CMD[$i]}"
+        if test "$dynamic_loading_opt"
+        then
+            add_device_tree_kernel "/chosen/domU$i" "domU${i}_kernel_addr" "domU${i}_kernel_size" "${DOMU_CMD[$i]}"
+        else
+            add_device_tree_kernel "/chosen/domU$i" ${domU_kernel_addr[$i]} ${domU_kernel_size[$i]} "${DOMU_CMD[$i]}"
+        fi
         if test "${domU_ramdisk_addr[$i]}"
         then
-            add_device_tree_ramdisk "/chosen/domU$i" ${domU_ramdisk_addr[$i]} ${domU_ramdisk_size[$i]}
+            if test "$dynamic_loading_opt"
+            then
+                add_device_tree_ramdisk "/chosen/domU$i" "domU${i}_ramdisk_addr" "domU${i}_ramdisk_size"
+            else
+                add_device_tree_ramdisk "/chosen/domU$i" ${domU_ramdisk_addr[$i]} ${domU_ramdisk_size[$i]}
+            fi
         fi
         if test "${domU_passthrough_dtb_addr[$i]}"
         then
-            add_device_tree_passthrough "/chosen/domU$i" ${domU_passthrough_dtb_addr[$i]} ${domU_passthrough_dtb_size[$i]}
+            if test "$dynamic_loading_opt"
+            then
+                add_device_tree_passthrough "/chosen/domU$i" "domU${i}_fdt_addr" "domU${i}_fdt_size"
+            else
+                add_device_tree_passthrough "/chosen/domU$i" ${domU_passthrough_dtb_addr[$i]} ${domU_passthrough_dtb_size[$i]}
+            fi
         fi
         i=$(( $i + 1 ))
     done
@@ -271,7 +321,12 @@ function device_tree_editing()
 
     if test $UBOOT_SOURCE
     then
-        echo "fdt addr $device_tree_addr" >> $UBOOT_SOURCE
+        if test $dynamic_loading_opt
+        then
+            echo "fdt addr \${host_fdt_addr}" >> $UBOOT_SOURCE
+        else
+            echo "fdt addr $device_tree_addr" >> $UBOOT_SOURCE
+        fi
         echo "fdt resize 1024" >> $UBOOT_SOURCE
 
         if test $NUM_DT_OVERLAY && test $NUM_DT_OVERLAY -gt 0
@@ -306,7 +361,7 @@ function add_size()
 function load_file()
 {
     local filename=$1
-    local fit_scr_name=$2
+    local binary_name=$2
 
     local absolute_path="$(realpath --no-symlinks $filename)"
     local base="$(realpath $PWD)"/
@@ -314,11 +369,30 @@ function load_file()
 
     if test "$FIT"
     then
-        echo "imxtract \$fit_addr $fit_scr_name $memaddr" >> $UBOOT_SOURCE
+        echo "imxtract \$fit_addr $binary_name $memaddr" >> $UBOOT_SOURCE
     else
-        echo "$LOAD_CMD $memaddr ${prepend_path:+$prepend_path/}$relative_path" >> $UBOOT_SOURCE
+        if test "$dynamic_loading_opt"
+        then
+            echo "$LOAD_CMD \${curr_addr} ${prepend_path:+$prepend_path/}$relative_path" >> $UBOOT_SOURCE
+        else
+            echo "$LOAD_CMD $memaddr ${prepend_path:+$prepend_path/}$relative_path" >> $UBOOT_SOURCE
+        fi
     fi
     add_size $filename
+
+    if test "$dynamic_loading_opt" && test ! "$FIT"
+    then
+        # Store each binary's load addr and size
+        local binary_name_addr="${binary_name}_addr"
+        local binary_name_size="${binary_name}_size"
+        echo "setenv $binary_name_addr \${curr_addr}" >> $UBOOT_SOURCE
+        echo "setenv $binary_name_size \${filesize}" >> $UBOOT_SOURCE
+        
+        # Compute load addr for next binary dynamically
+        echo "setexpr curr_addr \${curr_addr} \+ \${filesize}" >> $UBOOT_SOURCE
+        echo "setexpr curr_addr \${curr_addr} \+ \${padding_mask}" >> $UBOOT_SOURCE
+        echo "setexpr curr_addr \${curr_addr} \& \${padding_mask_inv}" >> $UBOOT_SOURCE
+    fi
 }
 
 function check_file_type()
@@ -536,6 +610,14 @@ generate_uboot_images()
 
 xen_file_loading()
 {
+    if test "$dynamic_loading_opt"
+    then
+        local curr_addr=`printf "%x\n" $memaddr`
+        echo "setenv curr_addr $curr_addr" >> $UBOOT_SOURCE
+        echo "setenv padding_mask $padding_mask" >> $UBOOT_SOURCE
+        echo "setenv padding_mask_inv $padding_mask_inv" >> $UBOOT_SOURCE
+    fi
+
     if test "$DOM0_KERNEL"
     then
         check_compressed_file_type $DOM0_KERNEL "executable"
@@ -891,7 +973,7 @@ function print_help
 {
     script=`basename "$0"`
     echo "usage:"
-    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f] [-p PREPEND_PATH]"
+    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f] [-p PREPEND_PATH] [-s]"
     echo "	$script -h"
     echo "where:"
     echo "	CONFIG_FILE - configuration file"
@@ -908,6 +990,7 @@ function print_help
     echo "	U-BOOT_DTB - u-boot control dtb so that the public key gets added to it"
     echo "	-f - enable generating a FIT image"
     echo "	PREPEND_PATH - path to be appended before file names to match deploy location within rootfs"
+    echo "	-s - enable dynamic loading of binaries by storing their addresses and sizes u-boot env variables"
     echo "	-h - prints out the help message and exits "
     echo "Defaults:"
     echo "	CONFIG_FILE=$cfg_file, UBOOT_TYPE=\"LOAD_CMD\" env var, DIRECTORY=$uboot_dir"
@@ -915,7 +998,7 @@ function print_help
     echo "	$script -c ../config -d ./build42 -t \"scsi load 1:1\""
 }
 
-while getopts ":c:t:d:ho:k:u:fp:" opt; do
+while getopts ":c:t:d:ho:k:u:fp:s" opt; do
     case ${opt} in
     t )
         case $OPTARG in
@@ -957,6 +1040,9 @@ while getopts ":c:t:d:ho:k:u:fp:" opt; do
     p )
         prepend_path="$OPTARG"
         ;;
+    s )
+        dynamic_loading_opt=y
+        ;;
     h )
         print_help
         exit 0
@@ -1151,7 +1237,13 @@ device_tree_editing $device_tree_addr
 
 # disable device tree reloation
 echo "setenv fdt_high 0xffffffffffffffff" >> $UBOOT_SOURCE
-echo "$BOOT_CMD $kernel_addr - $device_tree_addr" >> $UBOOT_SOURCE
+
+if test "$dynamic_loading_opt"
+then
+    echo "$BOOT_CMD \${host_kernel_addr} - \${host_fdt_addr}" >> $UBOOT_SOURCE
+else
+    echo "$BOOT_CMD $kernel_addr - $device_tree_addr" >> $UBOOT_SOURCE
+fi
 
 if test "$FIT"
 then
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [ImageBuilder][PATCH v2 3/4] uboot-script-gen: Enable appending extra commands to boot script
  2022-06-30 14:00 [ImageBuilder][PATCH v2 0/4] Add extra ImageBuilder features Andrei Cherechesu (OSS)
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 1/4] scripts: Add support for prepending path to file names Andrei Cherechesu (OSS)
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 2/4] uboot-script-gen: Dynamically compute addr and size when loading binaries Andrei Cherechesu (OSS)
@ 2022-06-30 14:00 ` Andrei Cherechesu (OSS)
  2022-07-07  0:17   ` Stefano Stabellini
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 4/4] uboot-script-gen: Enable not adding boot command to script Andrei Cherechesu (OSS)
  3 siblings, 1 reply; 8+ messages in thread
From: Andrei Cherechesu (OSS) @ 2022-06-30 14:00 UTC (permalink / raw)
  To: xen-devel; +Cc: viryaos-discuss, sstabellini, Andrei Cherechesu

From: Andrei Cherechesu <andrei.cherechesu@nxp.com>

Added the "-a" parameter which stands for APPEND_EXTRA_CMDS option,
which enables the user to specify the path to a text file that contains,
on each line, u-boot commands that will be added to the generated script as
"fixups", before the boot command.

The file specified via the "-a" parameter will be copied as-is in the
generated script.

Signed-off-by: Andrei Cherechesu <andrei.cherechesu@nxp.com>
---
 scripts/uboot-script-gen | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index f8d2fb0..444c65a 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -416,6 +416,10 @@ function check_file_type()
     elif [ "$type" = "Device Tree Blob" ]
     then
         type="Device Tree Blob\|data"
+
+    elif [ "$type" = "text" ]
+    then
+        type="ASCII text"
     fi
 
     file -L $filename | grep "$type" &> /dev/null
@@ -973,7 +977,7 @@ function print_help
 {
     script=`basename "$0"`
     echo "usage:"
-    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f] [-p PREPEND_PATH] [-s]"
+    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f] [-p PREPEND_PATH] [-s] [-a APPEND_EXTRA_CMDS]"
     echo "	$script -h"
     echo "where:"
     echo "	CONFIG_FILE - configuration file"
@@ -991,6 +995,7 @@ function print_help
     echo "	-f - enable generating a FIT image"
     echo "	PREPEND_PATH - path to be appended before file names to match deploy location within rootfs"
     echo "	-s - enable dynamic loading of binaries by storing their addresses and sizes u-boot env variables"
+    echo "	APPEND_EXTRA_CMDS - absolute path to file containing extra u-boot cmds (fixups) to be run before booting"
     echo "	-h - prints out the help message and exits "
     echo "Defaults:"
     echo "	CONFIG_FILE=$cfg_file, UBOOT_TYPE=\"LOAD_CMD\" env var, DIRECTORY=$uboot_dir"
@@ -998,7 +1003,7 @@ function print_help
     echo "	$script -c ../config -d ./build42 -t \"scsi load 1:1\""
 }
 
-while getopts ":c:t:d:ho:k:u:fp:s" opt; do
+while getopts ":c:t:d:ho:k:u:fp:sa:" opt; do
     case ${opt} in
     t )
         case $OPTARG in
@@ -1043,6 +1048,9 @@ while getopts ":c:t:d:ho:k:u:fp:s" opt; do
     s )
         dynamic_loading_opt=y
         ;;
+    a )
+        extra_cmds_file=$OPTARG
+        ;;
     h )
         print_help
         exit 0
@@ -1235,6 +1243,13 @@ load_file $DEVICE_TREE "host_fdt"
 bitstream_load_and_config  # bitstream is loaded last but used first
 device_tree_editing $device_tree_addr
 
+# append extra u-boot commands (fixups) to script before boot command
+if test "$extra_cmds_file"
+then
+    check_file_type "$extra_cmds_file" "text"
+    cat $extra_cmds_file >> $UBOOT_SOURCE
+fi
+
 # disable device tree reloation
 echo "setenv fdt_high 0xffffffffffffffff" >> $UBOOT_SOURCE
 
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [ImageBuilder][PATCH v2 4/4] uboot-script-gen: Enable not adding boot command to script
  2022-06-30 14:00 [ImageBuilder][PATCH v2 0/4] Add extra ImageBuilder features Andrei Cherechesu (OSS)
                   ` (2 preceding siblings ...)
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 3/4] uboot-script-gen: Enable appending extra commands to boot script Andrei Cherechesu (OSS)
@ 2022-06-30 14:00 ` Andrei Cherechesu (OSS)
  2022-07-07  0:56   ` Stefano Stabellini
  3 siblings, 1 reply; 8+ messages in thread
From: Andrei Cherechesu (OSS) @ 2022-06-30 14:00 UTC (permalink / raw)
  To: xen-devel; +Cc: viryaos-discuss, sstabellini, Andrei Cherechesu

From: Andrei Cherechesu <andrei.cherechesu@nxp.com>

If the "BOOT_CMD" variable is set to "none" inside the config
file, the boot command (i.e. "booti") will not by added to the
generated script, to allow the user to customize the u-boot env
or the device-tree after executing the script commands and before
actually booting.

Added commands to store the addresses where the Xen image and
device-tree file are loaded, in 'host_kernel_addr' and 'host_fdt_addr'
variables, if the boot command is skipped and the "-s" parameter is
not used.

The `booti` command can then be executed as part of the 'bootcmd' variable
in u-boot, which should contain:
	1. fetching the generated u-boot script
	2. executing the script
	3. running `booti ${host_kernel_addr} - ${host_fdt_addr}` command

Signed-off-by: Andrei Cherechesu <andrei.cherechesu@nxp.com>
---
 README.md                |  5 ++++-
 scripts/uboot-script-gen | 16 +++++++++++++---
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index cb15ca5..b1a9b9d 100644
--- a/README.md
+++ b/README.md
@@ -80,7 +80,10 @@ Where:
 
 - BOOT_CMD specifies the u-boot command used to boot the binaries.
   By default, it is 'booti'. The acceptable values are 'booti', 'bootm'
-  and 'bootefi'.
+  and 'bootefi' and 'none'. If the value is 'none', the BOOT_CMD is not
+  added to the boot script, and the addresses for the Xen binary and the
+  DTB are stored in 'host_kernel_addr' and 'host_fdt_addr' u-boot
+  env variables respectively, to be used manually when booting.
 
 - DEVICE_TREE specifies the DTB file to load.
 
diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 444c65a..994369c 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -966,7 +966,7 @@ function check_depends()
 
 function check_boot_cmd()
 {
-    if ! [[ " bootm booti bootefi " =~ " ${BOOT_CMD}" ]]
+    if ! [[ " bootm booti bootefi none " =~ " ${BOOT_CMD}" ]]
     then
         echo "\"BOOT_CMD=$BOOT_CMD\" is not valid"
         exit 1
@@ -1255,9 +1255,19 @@ echo "setenv fdt_high 0xffffffffffffffff" >> $UBOOT_SOURCE
 
 if test "$dynamic_loading_opt"
 then
-    echo "$BOOT_CMD \${host_kernel_addr} - \${host_fdt_addr}" >> $UBOOT_SOURCE
+    if [ "$BOOT_CMD" != "none" ]
+    then
+        echo "$BOOT_CMD \${host_kernel_addr} - \${host_fdt_addr}" >> $UBOOT_SOURCE
+    fi
 else
-    echo "$BOOT_CMD $kernel_addr - $device_tree_addr" >> $UBOOT_SOURCE
+    if [ "$BOOT_CMD" != "none" ]
+    then
+        echo "$BOOT_CMD $kernel_addr - $device_tree_addr" >> $UBOOT_SOURCE
+    else
+        # skip boot command but store load addresses to be used later
+        echo "setenv host_kernel_addr $kernel_addr" >> $UBOOT_SOURCE
+        echo "setenv host_fdt_addr $device_tree_addr" >> $UBOOT_SOURCE
+    fi
 fi
 
 if test "$FIT"
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [ImageBuilder][PATCH v2 1/4] scripts: Add support for prepending path to file names
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 1/4] scripts: Add support for prepending path to file names Andrei Cherechesu (OSS)
@ 2022-07-07  0:08   ` Stefano Stabellini
  0 siblings, 0 replies; 8+ messages in thread
From: Stefano Stabellini @ 2022-07-07  0:08 UTC (permalink / raw)
  To: Andrei Cherechesu (OSS)
  Cc: xen-devel, viryaos-discuss, sstabellini, Andrei Cherechesu

On Thu, 30 Jun 2022, Andrei Cherechesu (OSS) wrote:
> From: Andrei Cherechesu <andrei.cherechesu@nxp.com>
> 
> Added support for prepending path to file names in the final generated
> u-boot script, for the use-case where we have the files in a separate
> folder that can be accessed with a given $LOAD_CMD.
> 
> For example, we can have "fatload mmc 0:2" as LOAD_CMD but the
> files would need to be loaded from the /boot folder within the 2nd
> partition, not from the root ("/"). By specifying the "-p <path>"
> parameter when running the script, paths like "/boot" can be
> automatically prepended to the generated u-boot commands used
> to load the files in board's memory.
> 
> Also added the support to disk_image script, to enable generating
> a FAT partition with the binaries deployed in a custom folder
> within it, if the "-p" parameter is specified.
> 
> Signed-off-by: Andrei Cherechesu <andrei.cherechesu@nxp.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>  scripts/disk_image       | 37 +++++++++++++++++++++++--------------
>  scripts/uboot-script-gen | 12 ++++++++----
>  2 files changed, 31 insertions(+), 18 deletions(-)
> 
> diff --git a/scripts/disk_image b/scripts/disk_image
> index 12fb06b..97e798f 100755
> --- a/scripts/disk_image
> +++ b/scripts/disk_image
> @@ -539,7 +539,7 @@ function write_rootfs()
>  function print_help
>  {
>      echo "usage:"
> -    echo "	$0 -c CONFIG_FILE -d UBOOT_DIRECTORY -t UBOOT_TYPE <-w WORK_DIRECTORY> <-s SLACK> <-a> -o IMG_FILE"
> +    echo "	$0 -c CONFIG_FILE -d UBOOT_DIRECTORY -t UBOOT_TYPE <-w WORK_DIRECTORY> <-s SLACK> <-a> -o IMG_FILE <-p PREPEND_PATH>"
>      echo "	$0 -h"
>      echo "where:"
>      echo "	-c CONFIG_FILE - configuration file"
> @@ -553,6 +553,7 @@ function print_help
>      echo "	-s SLACK - free MB to add to each partition, default 128"
>      echo "	-a specifies that the size of IMG_FILE has to be aligned to the nearest power of two"
>      echo "	-o IMG_FILE - the output img file "
> +    echo "	-p PREPEND_PATH - path to be appended before file names to customize deploy location within rootfs"
>      echo "Example:"
>      echo "	$0 -c ../config -d ./build42 -w tmp -o disk.img"
>  }
> @@ -564,7 +565,7 @@ then
>      exit 1
>  fi
>  
> -while getopts ":w:d:c:t:s:o:ah" opt
> +while getopts ":w:d:c:t:s:o:ahp:" opt
>  do
>      case ${opt} in
>      t )
> @@ -606,6 +607,9 @@ do
>      a )
>          ALIGN=1
>          ;;
> +    p )
> +        PREPEND_PATH="$OPTARG"
> +        ;;
>      h )
>          print_help
>          exit 0
> @@ -828,56 +832,61 @@ mount /dev/mapper/diskimage1 $DESTDIR/part/disk1
>  
>  # only copy over files that were counted for the partition size
>  cd "$UBOOT_OUT"
> -cp --parents "$DOM0_KERNEL" "${DESTDIR_ABS}/part/disk1/"
> -cp --parents "$DEVICE_TREE" "${DESTDIR_ABS}/part/disk1/"
> -cp --parents "$UBOOT_SCRIPT" "${DESTDIR_ABS}/part/disk1/"
> +if [ -n "$PREPEND_PATH" ]
> +then
> +    mkdir -p "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
> +fi
> +
> +cp --parents "$DOM0_KERNEL" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
> +cp --parents "$DEVICE_TREE" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
> +cp --parents "$UBOOT_SCRIPT" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>  
>  if test "${DOM0_RAMDISK}"
>  then
> -    cp --parents "$DOM0_RAMDISK" "${DESTDIR_ABS}/part/disk1/"
> +    cp --parents "$DOM0_RAMDISK" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>  fi
>  if test "$NUM_DT_OVERLAY" && test "$NUM_DT_OVERLAY" -gt 0
>  then
>      i=0
>      while test $i -lt "$NUM_DT_OVERLAY"
>      do
> -        cp --parents "${DT_OVERLAY[$i]}" "${DESTDIR_ABS}/part/disk1/"
> +        cp --parents "${DT_OVERLAY[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>          i=$(( $i + 1 ))
>      done
>  fi
>  if test "${UBOOT_SOURCE}"
>  then
> -    cp --parents "$UBOOT_SOURCE" "${DESTDIR_ABS}/part/disk1/"
> +    cp --parents "$UBOOT_SOURCE" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>  fi
>  if test "${XEN}"
>  then
> -    cp --parents "$XEN" "${DESTDIR_ABS}/part/disk1/"
> +    cp --parents "$XEN" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>  fi
>  if test "$NUM_BOOT_AUX_FILE" && test "$NUM_BOOT_AUX_FILE" -gt 0
>  then
>      i=0
>      while test $i -lt "$NUM_BOOT_AUX_FILE"
>      do
> -        cp --parents "${BOOT_AUX_FILE[$i]}" "${DESTDIR_ABS}/part/disk1/"
> +        cp --parents "${BOOT_AUX_FILE[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>          i=$(( $i + 1 ))
>      done
>  fi
>  if test "${BITSTREAM}"
>  then
> -    cp --parents "$BITSTREAM" "${DESTDIR_ABS}/part/disk1/"
> +    cp --parents "$BITSTREAM" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>  fi
>  
>  i=0
>  while test $i -lt $NUM_DOMUS
>  do
> -    cp --parents "${DOMU_KERNEL[$i]}" "${DESTDIR_ABS}/part/disk1/"
> +    cp --parents "${DOMU_KERNEL[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>      if test "${DOMU_RAMDISK[$i]}"
>      then
> -        cp --parents "${DOMU_RAMDISK[$i]}" "${DESTDIR_ABS}/part/disk1/"
> +        cp --parents "${DOMU_RAMDISK[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>      fi
>      if test "${DOMU_PASSTHROUGH_DTB[$i]}"
>      then
> -        cp --parents "${DOMU_PASSTHROUGH_DTB[$i]}" "${DESTDIR_ABS}/part/disk1/"
> +        cp --parents "${DOMU_PASSTHROUGH_DTB[$i]}" "${DESTDIR_ABS}/part/disk1/${PREPEND_PATH}"
>      fi
>      i=$(( $i + 1 ))
>  done
> diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
> index 085e29f..8f08cd6 100755
> --- a/scripts/uboot-script-gen
> +++ b/scripts/uboot-script-gen
> @@ -316,7 +316,7 @@ function load_file()
>      then
>          echo "imxtract \$fit_addr $fit_scr_name $memaddr" >> $UBOOT_SOURCE
>      else
> -        echo "$LOAD_CMD $memaddr $relative_path" >> $UBOOT_SOURCE
> +        echo "$LOAD_CMD $memaddr ${prepend_path:+$prepend_path/}$relative_path" >> $UBOOT_SOURCE
>      fi
>      add_size $filename
>  }
> @@ -891,7 +891,7 @@ function print_help
>  {
>      script=`basename "$0"`
>      echo "usage:"
> -    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f]"
> +    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f] [-p PREPEND_PATH]"
>      echo "	$script -h"
>      echo "where:"
>      echo "	CONFIG_FILE - configuration file"
> @@ -907,6 +907,7 @@ function print_help
>      echo "	HINT - the file name of the crt and key file minus the suffix (ex, hint.crt and hint.key)"
>      echo "	U-BOOT_DTB - u-boot control dtb so that the public key gets added to it"
>      echo "	-f - enable generating a FIT image"
> +    echo "	PREPEND_PATH - path to be appended before file names to match deploy location within rootfs"
>      echo "	-h - prints out the help message and exits "
>      echo "Defaults:"
>      echo "	CONFIG_FILE=$cfg_file, UBOOT_TYPE=\"LOAD_CMD\" env var, DIRECTORY=$uboot_dir"
> @@ -914,7 +915,7 @@ function print_help
>      echo "	$script -c ../config -d ./build42 -t \"scsi load 1:1\""
>  }
>  
> -while getopts ":c:t:d:ho:k:u:f" opt; do
> +while getopts ":c:t:d:ho:k:u:fp:" opt; do
>      case ${opt} in
>      t )
>          case $OPTARG in
> @@ -953,6 +954,9 @@ while getopts ":c:t:d:ho:k:u:f" opt; do
>      f )
>          fit_opt=y
>          ;;
> +    p )
> +        prepend_path="$OPTARG"
> +        ;;
>      h )
>          print_help
>          exit 0
> @@ -1179,5 +1183,5 @@ then
>      echo "$LOAD_CMD $fit_addr $FIT; source $fit_addr:boot_scr"
>  else
>      echo "Generated uboot script $UBOOT_SCRIPT, to be loaded at address $uboot_addr:"
> -    echo "$LOAD_CMD $uboot_addr $UBOOT_SCRIPT; source $uboot_addr"
> +    echo "$LOAD_CMD $uboot_addr ${prepend_path:+$prepend_path/}$UBOOT_SCRIPT; source $uboot_addr"
>  fi
> -- 
> 2.35.1
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ImageBuilder][PATCH v2 3/4] uboot-script-gen: Enable appending extra commands to boot script
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 3/4] uboot-script-gen: Enable appending extra commands to boot script Andrei Cherechesu (OSS)
@ 2022-07-07  0:17   ` Stefano Stabellini
  0 siblings, 0 replies; 8+ messages in thread
From: Stefano Stabellini @ 2022-07-07  0:17 UTC (permalink / raw)
  To: Andrei Cherechesu (OSS)
  Cc: xen-devel, viryaos-discuss, sstabellini, Andrei Cherechesu

On Thu, 30 Jun 2022, Andrei Cherechesu (OSS) wrote:
> From: Andrei Cherechesu <andrei.cherechesu@nxp.com>
> 
> Added the "-a" parameter which stands for APPEND_EXTRA_CMDS option,
> which enables the user to specify the path to a text file that contains,
> on each line, u-boot commands that will be added to the generated script as
> "fixups", before the boot command.
> 
> The file specified via the "-a" parameter will be copied as-is in the
> generated script.
> 
> Signed-off-by: Andrei Cherechesu <andrei.cherechesu@nxp.com>
> ---
>  scripts/uboot-script-gen | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
> index f8d2fb0..444c65a 100755
> --- a/scripts/uboot-script-gen
> +++ b/scripts/uboot-script-gen
> @@ -416,6 +416,10 @@ function check_file_type()
>      elif [ "$type" = "Device Tree Blob" ]
>      then
>          type="Device Tree Blob\|data"
> +
> +    elif [ "$type" = "text" ]
> +    then
> +        type="ASCII text"
>      fi
>  
>      file -L $filename | grep "$type" &> /dev/null
> @@ -973,7 +977,7 @@ function print_help
>  {
>      script=`basename "$0"`
>      echo "usage:"
> -    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f] [-p PREPEND_PATH] [-s]"
> +    echo "	$script -c CONFIG_FILE -d DIRECTORY [-t LOAD_CMD] [-o FILE] [-k KEY_DIR/HINT [-u U-BOOT_DTB]] [-e] [-f] [-p PREPEND_PATH] [-s] [-a APPEND_EXTRA_CMDS]"
>      echo "	$script -h"
>      echo "where:"
>      echo "	CONFIG_FILE - configuration file"
> @@ -991,6 +995,7 @@ function print_help
>      echo "	-f - enable generating a FIT image"
>      echo "	PREPEND_PATH - path to be appended before file names to match deploy location within rootfs"
>      echo "	-s - enable dynamic loading of binaries by storing their addresses and sizes u-boot env variables"
> +    echo "	APPEND_EXTRA_CMDS - absolute path to file containing extra u-boot cmds (fixups) to be run before booting"
>      echo "	-h - prints out the help message and exits "
>      echo "Defaults:"
>      echo "	CONFIG_FILE=$cfg_file, UBOOT_TYPE=\"LOAD_CMD\" env var, DIRECTORY=$uboot_dir"

Instead of adding it as a command line option, would it make sense to
just source it from the ImageBuilder config file? Like:

---
UBOOT_SOURCE="boot.source"
UBOOT_SCRIPT="boot.scr"
APPEND_EXTRA_CMDS="extra.txt"
---

In other words I think we can skip parsing "-a" and just check if
APPEND_EXTRA_CMDS is set


> @@ -998,7 +1003,7 @@ function print_help
>      echo "	$script -c ../config -d ./build42 -t \"scsi load 1:1\""
>  }
>  
> -while getopts ":c:t:d:ho:k:u:fp:s" opt; do
> +while getopts ":c:t:d:ho:k:u:fp:sa:" opt; do
>      case ${opt} in
>      t )
>          case $OPTARG in
> @@ -1043,6 +1048,9 @@ while getopts ":c:t:d:ho:k:u:fp:s" opt; do
>      s )
>          dynamic_loading_opt=y
>          ;;
> +    a )
> +        extra_cmds_file=$OPTARG
> +        ;;
>      h )
>          print_help
>          exit 0
> @@ -1235,6 +1243,13 @@ load_file $DEVICE_TREE "host_fdt"
>  bitstream_load_and_config  # bitstream is loaded last but used first
>  device_tree_editing $device_tree_addr
>  
> +# append extra u-boot commands (fixups) to script before boot command
> +if test "$extra_cmds_file"
> +then
> +    check_file_type "$extra_cmds_file" "text"
> +    cat $extra_cmds_file >> $UBOOT_SOURCE
> +fi

I think it should be below the setenv fdt_high command below. (Just
before the echo "$BOOT_CMD...

Other than that, it is fine, thank you!


>  # disable device tree reloation
>  echo "setenv fdt_high 0xffffffffffffffff" >> $UBOOT_SOURCE
>  
> -- 
> 2.35.1
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ImageBuilder][PATCH v2 4/4] uboot-script-gen: Enable not adding boot command to script
  2022-06-30 14:00 ` [ImageBuilder][PATCH v2 4/4] uboot-script-gen: Enable not adding boot command to script Andrei Cherechesu (OSS)
@ 2022-07-07  0:56   ` Stefano Stabellini
  0 siblings, 0 replies; 8+ messages in thread
From: Stefano Stabellini @ 2022-07-07  0:56 UTC (permalink / raw)
  To: Andrei Cherechesu (OSS)
  Cc: xen-devel, viryaos-discuss, sstabellini, Andrei Cherechesu

On Thu, 30 Jun 2022, Andrei Cherechesu (OSS) wrote:
> From: Andrei Cherechesu <andrei.cherechesu@nxp.com>
> 
> If the "BOOT_CMD" variable is set to "none" inside the config
> file, the boot command (i.e. "booti") will not by added to the
> generated script, to allow the user to customize the u-boot env
> or the device-tree after executing the script commands and before
> actually booting.
> 
> Added commands to store the addresses where the Xen image and
> device-tree file are loaded, in 'host_kernel_addr' and 'host_fdt_addr'
> variables, if the boot command is skipped and the "-s" parameter is
> not used.
> 
> The `booti` command can then be executed as part of the 'bootcmd' variable
> in u-boot, which should contain:
> 	1. fetching the generated u-boot script
> 	2. executing the script
> 	3. running `booti ${host_kernel_addr} - ${host_fdt_addr}` command
> 
> Signed-off-by: Andrei Cherechesu <andrei.cherechesu@nxp.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

I think this patch is fine in principle but I need to review in a bit
more details patch #2 before I am able to commit it


> ---
>  README.md                |  5 ++++-
>  scripts/uboot-script-gen | 16 +++++++++++++---
>  2 files changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/README.md b/README.md
> index cb15ca5..b1a9b9d 100644
> --- a/README.md
> +++ b/README.md
> @@ -80,7 +80,10 @@ Where:
>  
>  - BOOT_CMD specifies the u-boot command used to boot the binaries.
>    By default, it is 'booti'. The acceptable values are 'booti', 'bootm'
> -  and 'bootefi'.
> +  and 'bootefi' and 'none'. If the value is 'none', the BOOT_CMD is not
> +  added to the boot script, and the addresses for the Xen binary and the
> +  DTB are stored in 'host_kernel_addr' and 'host_fdt_addr' u-boot
> +  env variables respectively, to be used manually when booting.
>  
>  - DEVICE_TREE specifies the DTB file to load.
>  
> diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
> index 444c65a..994369c 100755
> --- a/scripts/uboot-script-gen
> +++ b/scripts/uboot-script-gen
> @@ -966,7 +966,7 @@ function check_depends()
>  
>  function check_boot_cmd()
>  {
> -    if ! [[ " bootm booti bootefi " =~ " ${BOOT_CMD}" ]]
> +    if ! [[ " bootm booti bootefi none " =~ " ${BOOT_CMD}" ]]
>      then
>          echo "\"BOOT_CMD=$BOOT_CMD\" is not valid"
>          exit 1
> @@ -1255,9 +1255,19 @@ echo "setenv fdt_high 0xffffffffffffffff" >> $UBOOT_SOURCE
>  
>  if test "$dynamic_loading_opt"
>  then
> -    echo "$BOOT_CMD \${host_kernel_addr} - \${host_fdt_addr}" >> $UBOOT_SOURCE
> +    if [ "$BOOT_CMD" != "none" ]
> +    then
> +        echo "$BOOT_CMD \${host_kernel_addr} - \${host_fdt_addr}" >> $UBOOT_SOURCE
> +    fi
>  else
> -    echo "$BOOT_CMD $kernel_addr - $device_tree_addr" >> $UBOOT_SOURCE
> +    if [ "$BOOT_CMD" != "none" ]
> +    then
> +        echo "$BOOT_CMD $kernel_addr - $device_tree_addr" >> $UBOOT_SOURCE
> +    else
> +        # skip boot command but store load addresses to be used later
> +        echo "setenv host_kernel_addr $kernel_addr" >> $UBOOT_SOURCE
> +        echo "setenv host_fdt_addr $device_tree_addr" >> $UBOOT_SOURCE
> +    fi
>  fi
>  
>  if test "$FIT"
> -- 
> 2.35.1
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-07  0:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 14:00 [ImageBuilder][PATCH v2 0/4] Add extra ImageBuilder features Andrei Cherechesu (OSS)
2022-06-30 14:00 ` [ImageBuilder][PATCH v2 1/4] scripts: Add support for prepending path to file names Andrei Cherechesu (OSS)
2022-07-07  0:08   ` Stefano Stabellini
2022-06-30 14:00 ` [ImageBuilder][PATCH v2 2/4] uboot-script-gen: Dynamically compute addr and size when loading binaries Andrei Cherechesu (OSS)
2022-06-30 14:00 ` [ImageBuilder][PATCH v2 3/4] uboot-script-gen: Enable appending extra commands to boot script Andrei Cherechesu (OSS)
2022-07-07  0:17   ` Stefano Stabellini
2022-06-30 14:00 ` [ImageBuilder][PATCH v2 4/4] uboot-script-gen: Enable not adding boot command to script Andrei Cherechesu (OSS)
2022-07-07  0:56   ` Stefano Stabellini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.