From b098f3d5d627ad40c000fa100f8a72d011dba15e Mon Sep 17 00:00:00 2001 From: Ayan Kumar Halder Date: Tue, 21 Dec 2021 13:04:47 +0000 Subject: Generate the domU partial dtb via disk_image Similar to uboot-script-gen, disk_image invokes compile_merge_partial_dts to generate the domU partial dtbs. It copies the dtbs to /etc/xen. Added functions to cleanup the temporary files. Also removed 'set -e'. This was causing the script to terminate if any of the functions returned non zero. In our approach, the functions in common script will return 1 (on failure), and the caller (ie disk_image) will check the return code and do the appropriate cleanup. Moreover, 'set -e' cannot be relied upon to terminate the script if any function returns error. Thus, it is not very useful. Details :- https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html Signed-off-by: Ayan Kumar Halder Reviewed-by: Stefano Stabellini Signed-off-by: Stefano Stabellini --- scripts/disk_image | 57 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/scripts/disk_image b/scripts/disk_image index 81bbee4..69b037f 100755 --- a/scripts/disk_image +++ b/scripts/disk_image @@ -1,11 +1,28 @@ #!/bin/bash -# This helps to see what is going on -set -e - PROG_REQ=( kpartx mkfs.ext4 losetup sgdisk readlink awk ) SLACK=128 +function cleanup_disk_image() +{ + kpartx -d /dev/mapper/diskimage + dmsetup remove diskimage + losetup -d $_loop_dev + + remove_tmp_files + + if [ "$DESTDIR_DEL" = true ] + then + rm -rf "$DESTDIR" + fi +} + +function cleanup_disk_image_error() +{ + cleanup_disk_image + rm $IMG +} + function check_depends() { for ((i=0; i<${#PROG_REQ[@]}; i++)) @@ -58,6 +75,7 @@ function generate_domU_configs() # $j + 1 - 1 as it is starting from 0 local n=$1 local dest + local dtb_name mount -t ext4 /dev/mapper/diskimage$j $DESTDIR/part/disk$j mkdir -p $DESTDIR/part/disk$j/etc/xen @@ -68,10 +86,30 @@ function generate_domU_configs() do if test "${DOMU_NOBOOT[$i]}" then + if test -z "${DOMU_PASSTHROUGH_DTB[$i]}" && test "${DOMU_PASSTHROUGH_PATHS[$i]}" + then + output_dir=`mktemp -d` + tmp_dirs+=($output_dir) + + # Check if the below function returns error + # and unmount the partition + compile_merge_partial_dts $output_dir "$PASSTHROUGH_DTS_REPO" + if test $? -ne 0 + then + umount $DESTDIR/part/disk$j + cleanup_disk_image_error + exit 1 + fi + fi + dest="$DESTDIR/part/disk$j/etc/xen/domU$i.cfg" + cp ${DOMU_PASSTHROUGH_DTB[$i]} $DESTDIR/part/disk$j/etc/xen/ echo "name=\"domU$i\"" >> $dest echo "memory=${DOMU_MEM[$i]}" >> $dest echo "vcpus=${DOMU_VCPUS[$i]}" >> $dest + + dtb_name="$(basename ${DOMU_PASSTHROUGH_DTB[$i]})" + echo "device_tree=\"/etc/xen/$dtb_name\"" >> $dest echo "# mount $first_part /boot" >> $dest echo "kernel=\"/boot/${DOMU_KERNEL[$i]}\"" >> $dest if test "${DOMU_RAMDISK[$i]}" @@ -302,6 +340,9 @@ check_depends source "$CFG_FILE" +SCRIPT_PATH=$(dirname "$0") +source "$SCRIPT_PATH/common" + i=0 while test $i -lt $NUM_DOMUS do @@ -546,12 +587,4 @@ do i=$(( $i + 1 )) done - -kpartx -d /dev/mapper/diskimage -dmsetup remove diskimage -losetup -d $_loop_dev - -if [ "$DESTDIR_DEL" = true ] -then - rm -rf "$DESTDIR" -fi +cleanup_disk_image -- cgit v1.2.3