From 8f973688c2a9c03b0546169f9ca38d1398fc7572 Mon Sep 17 00:00:00 2001 From: Brian Woods Date: Thu, 2 Sep 2021 16:52:19 -0700 Subject: Restructure uboot-script-gen for Linux support For later add Linux support, restructure the code so it's easier to add various other OSs configurartions. Signed-off-by: Brian Woods Reviewed-by: Stefano Stabellini Signed-off-by: Stefano Stabellini --- scripts/uboot-script-gen | 558 ++++++++++++++++++++++++----------------------- 1 file changed, 285 insertions(+), 273 deletions(-) (limited to 'scripts') diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen index 3677b20..9d692e9 100755 --- a/scripts/uboot-script-gen +++ b/scripts/uboot-script-gen @@ -256,6 +256,288 @@ function check_compressed_file_type() check_file_type $filename "$type" } +function xen_config() +{ + if [ -z "$XEN_CMD" ] + then + XEN_CMD="console=dtuart dtuart=serial0 dom0_mem=1G dom0_max_vcpus=1 bootscrub=0 vwfi=native sched=null" + fi + + if [ -z "$DOM0_CMD" ] + then + DOM0_CMD="console=hvc0 earlycon=xen earlyprintk=xen clk_ignore_unused" + fi + if [[ ! $DOM0_CMD =~ root= ]] + then + if test -z "$DOM0_ROOTFS" + then + DOM0_CMD="$DOM0_CMD root=/dev/ram0" + else + DEV=${LOAD_CMD%:*} + DEV=${DEV##* } + PAR=${LOAD_CMD#*:} + + if [ -z "$DEV" ] || [ -z "$PAR" ] + then + echo "Could not parse device and partition." + echo "Please make sure the load command is correct or manually set DOM0_CMD in the config file." + exit 1 + fi + + PAR=$((PAR + 1)) + + if [[ $LOAD_CMD =~ mmc ]] + then + DOM0_CMD="$DOM0_CMD root=/dev/mmcblk${DEV}p${PAR}" + elif [[ $LOAD_CMD =~ scsi ]] + then + # converts number to a scsi device character + DEV=$((DEV + 97)) + DEV=$(printf %x $DEV) + DEV=$(printf "\x$DEV") + + DOM0_CMD="$DOM0_CMD root=/dev/sd${DEV}${PAR}" + else + echo "Only mmc and scsi are supported for automatically setting the root partition." + echo "Manually set DOM0_CMD with the root device in the config file to bypass this." + exit 1 + fi + fi + fi + i=0 + while test $i -lt $NUM_DOMUS + do + if test -z "${DOMU_MEM[$i]}" + then + DOMU_MEM[$i]=512 + fi + DOMU_MEM[$i]=$((${DOMU_MEM[$i]} * 1024)) + if test -z "${DOMU_VCPUS[$i]}" + then + DOMU_VCPUS[$i]=1 + fi + i=$(( $i + 1 )) + done +} + +xen_file_loading() +{ + check_compressed_file_type $XEN "executable" + xen_addr=$memaddr + load_file "$XEN" "host_xen" + + check_compressed_file_type $DOM0_KERNEL "executable" + dom0_kernel_addr=$memaddr + load_file $DOM0_KERNEL "dom0_linux" + dom0_kernel_size=$filesize + + if test "$DOM0_RAMDISK" + then + check_compressed_file_type $DOM0_RAMDISK "cpio archive" + dom0_ramdisk_addr=$memaddr + load_file "$DOM0_RAMDISK" "dom0_ramdisk" + dom0_ramdisk_size=$filesize + else + dom0_ramdisk_addr="-" + fi + + i=0 + while test $i -lt $NUM_DOMUS + do + if test "${DOMU_ROOTFS[$i]}" || test "${DOMU_NOBOOT[$i]}" + then + if test -z "${DOMU_NOBOOT[$i]}" + then + echo "Skipping DomU[$i]: cannot handle non-ramdisk rootfs for dom0less VMs." + fi + i=$(( $i + 1 )) + continue + fi + check_compressed_file_type ${DOMU_KERNEL[$i]} "executable" + domU_kernel_addr[$i]=$memaddr + load_file ${DOMU_KERNEL[$i]} "domU${i}_kernel" + 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" + 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" + domU_passthrough_dtb_size[$i]=$filesize + fi + i=$(( $i + 1 )) + done +} + +create_its_file() +{ + load_files="\"dom0_linux\"" + cat >> "$its_file" <<- EOF +/dts-v1/; +/ { + description = "Configuration to load Xen"; + #address-cells = <1>; + images { + host_xen { + description = "host xen binary"; + data = /incbin/("$XEN"); + type = "kernel"; + arch = "arm64"; + os = "linux"; + compression = "none"; + load = <$xen_addr>; + entry = <$xen_addr>; + $fit_algo + }; + host_fdt { + description = "host fdt"; + data = /incbin/("$FDTEDIT"); + type = "flat_dt"; + arch = "arm64"; + compression = "none"; + load = <$device_tree_addr>; + $fit_algo + }; + dom0_linux { + description = "dom0 linux kernel binary"; + data = /incbin/("$DOM0_KERNEL"); + type = "kernel"; + arch = "arm64"; + os = "linux"; + compression = "none"; + load = <$dom0_kernel_addr>; + $fit_algo + }; + EOF + if test "$DOM0_RAMDISK" + then + load_files+=", \"dom0_ramdisk\"" + cat >> "$its_file" <<- EOF + dom0_ramdisk { + description = "dom0 ramdisk"; + data = /incbin/("$DOM0_RAMDISK"); + type = "ramdisk"; + arch = "arm64"; + os = "linux"; + compression = "none"; + load = <$dom0_ramdisk_addr>; + $fit_algo + }; + EOF + fi + # domUs + i=0 + while test $i -lt $NUM_DOMUS + do + if test "${DOMU_ROOTFS[$i]}" || test "${DOMU_NOBOOT[$i]}" + then + i=$(( $i + 1 )) + continue + fi + load_files+=", \"domU${i}_kernel\"" + cat >> "$its_file" <<- EOF + domU${i}_kernel { + description = "domU${i} kernel binary"; + data = /incbin/("${DOMU_KERNEL[$i]}"); + type = "kernel"; + arch = "arm64"; + os = "linux"; + compression = "none"; + load = <${domU_kernel_addr[$i]}>; + $fit_algo + }; + EOF + if test "${DOMU_RAMDISK[$i]}" + then + load_files+=", \"domU${i}_ramdisk\"" + cat >> "$its_file" <<- EOF + domU${i}_ramdisk { + description = "domU${i} ramdisk"; + data = /incbin/("${DOMU_RAMDISK[$i]}"); + type = "ramdisk"; + arch = "arm64"; + os = "linux"; + compression = "none"; + load = <${domU_ramdisk_addr[$i]}>; + $fit_algo + }; + EOF + fi + if test "${DOMU_PASSTHROUGH_DTB[$i]}" + then + load_files+=", \"domU${i}_fdt\"" + cat >> "$its_file" <<- EOF + domU${i}_fdt { + description = "domU${i} fdt"; + data = /incbin/("${DOMU_PASSTHROUGH_DTB[$i]}"); + type = "flat_dt"; + arch = "arm64"; + compression = "none"; + load = <${domU_passthrough_dtb_addr[$i]}>; + $fit_algo + }; + EOF + fi + i=$(( $i + 1 )) + done + fdt_line="fdt = \"host_fdt\"" + if test $NUM_DT_OVERLAY && test $NUM_DT_OVERLAY -gt 0 + then + i=0 + while test $i -lt $NUM_DT_OVERLAY + do + cat >> "$its_file" <<- EOF + host_fdto${i} { + description = "host fdt overlay ${i}"; + data = /incbin/("${DT_OVERLAY[$i]}"); + type = "flat_dt"; + arch = "arm64"; + compression = "none"; + load = <${dt_overlay_addr[$i]}>; + $fit_algo + }; + EOF + fdt_line+=", \"host_fdto${i}\"" + i=$(( $i + 1 )) + done + fi + fdt_line+=";" + # script for fit + cat >> "$its_file" <<- EOF + boot_scr { + description = "imagebuilder's boot script"; + data = /incbin/("$UBOOT_SOURCE"); + type = "script"; + compression = "none"; + load = <$uboot_addr>; + entry = <$uboot_addr>; + $fit_algo + }; + EOF + # end images + echo ' };' >> "$its_file" + # config, signing requires a config even if it isn't used + cat >> "$its_file" <<- EOF + configurations { + default = "config"; + config { + description = "Xen"; + kernel = "host_xen"; + $fdt_line + loadables = $load_files; + }; + }; + EOF + # end + echo '};' >> "$its_file" +} + function check_depends() { for ((i=0; i<${#prog_req[@]}; i++)) @@ -373,66 +655,7 @@ then UBOOT_SOURCE="$UBOOT_SCRIPT_ARG".source fi -if [ -z "$XEN_CMD" ] -then - XEN_CMD="console=dtuart dtuart=serial0 dom0_mem=1G dom0_max_vcpus=1 bootscrub=0 vwfi=native sched=null" -fi - -if [ -z "$DOM0_CMD" ] -then - DOM0_CMD="console=hvc0 earlycon=xen earlyprintk=xen clk_ignore_unused" -fi -if [[ ! $DOM0_CMD =~ root= ]] -then - if test -z "$DOM0_ROOTFS" - then - DOM0_CMD="$DOM0_CMD root=/dev/ram0" - else - DEV=${LOAD_CMD%:*} - DEV=${DEV##* } - PAR=${LOAD_CMD#*:} - - if [ -z "$DEV" ] || [ -z "$PAR" ] - then - echo "Could not parse device and partition." - echo "Please make sure the load command is correct or manually set DOM0_CMD in the config file." - exit 1 - fi - - PAR=$((PAR + 1)) - - if [[ $LOAD_CMD =~ mmc ]] - then - DOM0_CMD="$DOM0_CMD root=/dev/mmcblk${DEV}p${PAR}" - elif [[ $LOAD_CMD =~ scsi ]] - then - # converts number to a scsi device character - DEV=$((DEV + 97)) - DEV=$(printf %x $DEV) - DEV=$(printf "\x$DEV") - - DOM0_CMD="$DOM0_CMD root=/dev/sd${DEV}${PAR}" - else - echo "Only mmc and scsi are supported for automatically setting the root partition." - echo "Manually set DOM0_CMD with the root device in the config file to bypass this." - exit 1 - fi - fi -fi -i=0 -while test $i -lt $NUM_DOMUS -do - if test -z "${DOMU_MEM[$i]}" - then - DOMU_MEM[$i]=512 - fi - DOMU_MEM[$i]=$((${DOMU_MEM[$i]} * 1024)) - if test -z "${DOMU_VCPUS[$i]}" - then - DOMU_VCPUS[$i]=1 - fi - i=$(( $i + 1 )) -done +xen_config if test "$efi_opt" then @@ -532,57 +755,7 @@ uboot_addr=$memaddr memaddr=$(( $memaddr + $offset )) memaddr=`printf "0x%X\n" $memaddr` -check_compressed_file_type $XEN "executable" -xen_addr=$memaddr -load_file "$XEN" "host_xen" - -check_compressed_file_type $DOM0_KERNEL "executable" -dom0_kernel_addr=$memaddr -load_file $DOM0_KERNEL "dom0_linux" -dom0_kernel_size=$filesize - -if test "$DOM0_RAMDISK" -then - check_compressed_file_type $DOM0_RAMDISK "cpio archive" - dom0_ramdisk_addr=$memaddr - load_file "$DOM0_RAMDISK" "dom0_ramdisk" - dom0_ramdisk_size=$filesize -else - dom0_ramdisk_addr="-" -fi - -i=0 -while test $i -lt $NUM_DOMUS -do - if test "${DOMU_ROOTFS[$i]}" || test "${DOMU_NOBOOT[$i]}" - then - if test -z "${DOMU_NOBOOT[$i]}" - then - echo "Skipping DomU[$i]: cannot handle non-ramdisk rootfs for dom0less VMs." - fi - i=$(( $i + 1 )) - continue - fi - check_compressed_file_type ${DOMU_KERNEL[$i]} "executable" - domU_kernel_addr[$i]=$memaddr - load_file ${DOMU_KERNEL[$i]} "domU${i}_kernel" - 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" - 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" - domU_passthrough_dtb_size[$i]=$filesize - fi - i=$(( $i + 1 )) -done +xen_file_loading if test $NUM_DT_OVERLAY && test $NUM_DT_OVERLAY -gt 0 then @@ -617,168 +790,7 @@ fi if test "$FIT" then - # create start along with necessary binaries - load_files="\"dom0_linux\"" - its_dt="$FDTEDIT" - cat >> "$its_file" <<- EOF -/dts-v1/; -/ { - description = "Configuration to load Xen"; - #address-cells = <1>; - images { - host_xen { - description = "host xen binary"; - data = /incbin/("$XEN"); - type = "kernel"; - arch = "arm64"; - os = "linux"; - compression = "none"; - load = <$xen_addr>; - entry = <$xen_addr>; - $fit_algo - }; - host_fdt { - description = "host fdt"; - data = /incbin/("$its_dt"); - type = "flat_dt"; - arch = "arm64"; - compression = "none"; - load = <$device_tree_addr>; - $fit_algo - }; - dom0_linux { - description = "dom0 linux kernel binary"; - data = /incbin/("$DOM0_KERNEL"); - type = "kernel"; - arch = "arm64"; - os = "linux"; - compression = "none"; - load = <$dom0_kernel_addr>; - $fit_algo - }; - EOF - if test "$DOM0_RAMDISK" - then - load_files+=", \"dom0_ramdisk\"" - cat >> "$its_file" <<- EOF - dom0_ramdisk { - description = "dom0 ramdisk"; - data = /incbin/("$DOM0_RAMDISK"); - type = "ramdisk"; - arch = "arm64"; - os = "linux"; - compression = "none"; - load = <$dom0_ramdisk_addr>; - $fit_algo - }; - EOF - fi - # domUs - i=0 - while test $i -lt $NUM_DOMUS - do - if test "${DOMU_ROOTFS[$i]}" || test "${DOMU_NOBOOT[$i]}" - then - i=$(( $i + 1 )) - continue - fi - load_files+=", \"domU${i}_kernel\"" - cat >> "$its_file" <<- EOF - domU${i}_kernel { - description = "domU${i} kernel binary"; - data = /incbin/("${DOMU_KERNEL[$i]}"); - type = "kernel"; - arch = "arm64"; - os = "linux"; - compression = "none"; - load = <${domU_kernel_addr[$i]}>; - $fit_algo - }; - EOF - if test "${DOMU_RAMDISK[$i]}" - then - load_files+=", \"domU${i}_ramdisk\"" - cat >> "$its_file" <<- EOF - domU${i}_ramdisk { - description = "domU${i} ramdisk"; - data = /incbin/("${DOMU_RAMDISK[$i]}"); - type = "ramdisk"; - arch = "arm64"; - os = "linux"; - compression = "none"; - load = <${domU_ramdisk_addr[$i]}>; - $fit_algo - }; - EOF - fi - if test "${DOMU_PASSTHROUGH_DTB[$i]}" - then - load_files+=", \"domU${i}_fdt\"" - cat >> "$its_file" <<- EOF - domU${i}_fdt { - description = "domU${i} fdt"; - data = /incbin/("${DOMU_PASSTHROUGH_DTB[$i]}"); - type = "flat_dt"; - arch = "arm64"; - compression = "none"; - load = <${domU_passthrough_dtb_addr[$i]}>; - $fit_algo - }; - EOF - fi - i=$(( $i + 1 )) - done - fdt_line="fdt = \"host_fdt\"" - if test $NUM_DT_OVERLAY && test $NUM_DT_OVERLAY -gt 0 - then - i=0 - while test $i -lt $NUM_DT_OVERLAY - do - cat >> "$its_file" <<- EOF - host_fdto${i} { - description = "host fdt overlay ${i}"; - data = /incbin/("${DT_OVERLAY[$i]}"); - type = "flat_dt"; - arch = "arm64"; - compression = "none"; - load = <${dt_overlay_addr[$i]}>; - $fit_algo - }; - EOF - fdt_line+=", \"host_fdto${i}\"" - i=$(( $i + 1 )) - done - fi - fdt_line+=";" - # script for fit - cat >> "$its_file" <<- EOF - boot_scr { - description = "imagebuilder's boot script"; - data = /incbin/("$UBOOT_SOURCE"); - type = "script"; - compression = "none"; - load = <$uboot_addr>; - entry = <$uboot_addr>; - $fit_algo - }; - EOF - # end images - echo ' };' >> "$its_file" - # config, signing requires a config even if it isn't used - cat >> "$its_file" <<- EOF - configurations { - default = "config"; - config { - description = "Xen"; - kernel = "host_xen"; - $fdt_line - loadables = $load_files; - }; - }; - EOF - # end - echo '};' >> "$its_file" - + create_its_file mkimage -q -f "$its_file" $fit_enc_opt "$FIT" else mkimage -A arm64 -T script -C none -a $uboot_addr -e $uboot_addr -d $UBOOT_SOURCE "$UBOOT_SCRIPT" &> /dev/null -- cgit v1.2.3