From 96d6d380c14c13eb898dc5bea52cf2a090c737f3 Mon Sep 17 00:00:00 2001 From: Joacim Zetterling Date: Sun, 3 Dec 2023 20:22:52 +0100 Subject: [PATCH] scripts: board: common: add new FIT support for all platforms Adds new FIT support to all platforms to enable internal data support for FIT files. To enable the new internal data support for FIT files, use the normal NETBOX_IMAGE_FIT config param. If a need of an old FIT image support, You can use the NETBOX_IMAGE_FIT_LEGACY config param. In this case an FIT image with old external data will be generated. Signed-off-by: Joacim Zetterling --- board/common/post-image.sh | 7 ++ support/scripts/fitimage.sh | 86 +++++++++++++++----- support/scripts/fitimage_legacy.sh | 126 +++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 22 deletions(-) create mode 100755 support/scripts/fitimage_legacy.sh diff --git a/board/common/post-image.sh b/board/common/post-image.sh index c37dc43..cf9e00b 100755 --- a/board/common/post-image.sh +++ b/board/common/post-image.sh @@ -3,6 +3,7 @@ imagesh=$BR2_EXTERNAL_NETBOX_PATH/support/scripts/image.sh fitimagesh=$BR2_EXTERNAL_NETBOX_PATH/support/scripts/fitimage.sh +fitimagesh_legacy=$BR2_EXTERNAL_NETBOX_PATH/support/scripts/fitimage_legacy.sh md5() { @@ -63,6 +64,12 @@ if [ "$BR2_TARGET_ROOTFS_SQUASHFS" = "y" ]; then $imagesh "$squash" "$img" md5 "$img" + if [ "$NETBOX_IMAGE_FIT_LEGACY" ]; then + itb=$(dirname "${img}")/$(basename "${img}" .img).itb + $fitimagesh_legacy "$NETBOX_PLAT" "$squash" "$itb" + md5 "$itb" + fi + if [ "$NETBOX_IMAGE_FIT" ]; then itb=$(dirname "${img}")/$(basename "${img}" .img).itb $fitimagesh "$NETBOX_PLAT" "$squash" "$itb" diff --git a/support/scripts/fitimage.sh b/support/scripts/fitimage.sh index 06cbe28..e5b4833 100755 --- a/support/scripts/fitimage.sh +++ b/support/scripts/fitimage.sh @@ -9,30 +9,36 @@ die() { plat=$1 squash=$2 out=$3 -load=0 +kernelcomp="none"; +dtbcomp="none"; +opts="" case $plat in basis) arch="arm" load="0x20000000" + opts="-E -p 0x1000" ;; byron) arch="arm" - load="0x20000000" + kernelcomp="gzip" ;; coronet) arch="powerpc" + kernelcomp="xz" ;; dagger) arch="arm" + kernelcomp="xz" ;; envoy) arch="arm64" - load="0x40000000" + kernelcomp="xz" ;; ember) arch="arm64" load="0x40000000" + opts="-E -p 0x1000" ;; zero) arch="x86_64" @@ -48,7 +54,32 @@ unsquashfs -f -d $workdir $squash boot || die "Invalid SquashFS" kernel=$(echo $workdir/boot/*Image | cut -d\ -f1) [ "$kernel" ] || die "No kernel found" +case ${kernelcomp} in + "gzip") + gzip -c -9 ${kernel} > ${workdir}/boot/$(basename ${kernel}).${kernelcomp} + ;; + "xz") + xz --check=crc32 -c ${kernel} > ${workdir}/boot/$(basename ${kernel}).${kernelcomp} + ;; + "zstd") + zstd -19 --stdout ${kernel} > ${workdir}/boot/$(basename ${kernel}).${kernelcomp} + ;; + "none") + ;; +esac + +if [ "${kernelcomp}" != "none" ]; then + kernel=$(echo $workdir/boot/*Image.${kernelcomp} | cut -d\ -f1) + [ "$kernel" ] || die "No kernel found" +fi + dtbs=$workdir/boot/*/device-tree.dtb +dtbs_default=$(echo ${dtbs} | cut -d " " -f1 | cut -d "/" -f5) + +# If not specified, set dtbcomp to same method as kernelcomp. +if [ -z "${dtbcomp}" ]; then + dtbcomp=${kernelcomp} +fi # mkimage will only align images to 4 bytes, but U-Boot will leave # both DTB and ramdisk in place when starting the kernel. So we pad @@ -56,23 +87,29 @@ dtbs=$workdir/boot/*/device-tree.dtb truncate -s %4k $kernel $dtbs for dtb in $dtbs; do - name=$(basename $(dirname $dtb)) + name=$(basename $(dirname $dtb) | cut -d "-" -f1) cat <>$workdir/netbox-dtbs.itsi - $name { - description = "$name"; + fdt-$name { + description = "dtb"; type = "flat_dt"; arch = "$arch"; - compression = "none"; + compression = "$dtbcomp"; data = /incbin/("$dtb"); + hash { + algo = "sha256"; + }; }; EOF cat <>$workdir/netbox-cfgs.itsi $name { description = "$name"; - kernel = "kernel"; - ramdisk = "ramdisk"; - fdt = "$name"; + kernel = "kernel-1"; + ramdisk = "ramdisk-1"; + fdt = "fdt-$name"; + hash { + algo = "sha256"; + }; }; EOF done @@ -87,40 +124,45 @@ cat <$workdir/netbox.its #address-cells = <0x1>; images { - - kernel { - description = "Linux"; + kernel-1 { + description = "kernel"; type = "kernel"; arch = "$arch"; os = "linux"; - load = <$load>; - entry = <$load>; - compression = "none"; + compression = "$kernelcomp"; data = /incbin/("$kernel"); + hash { + algo = "sha256"; + }; }; - ramdisk { - description = "Netbox"; + ramdisk-1 { + description = "ramdisk"; type = "ramdisk"; os = "linux"; arch = "$arch"; compression = "none"; data = /incbin/("$squash"); + hash { + algo = "sha256"; + }; }; $(cat $workdir/netbox-dtbs.itsi) - }; configurations { + default = "$dtbs_default"; + $(cat $workdir/netbox-cfgs.itsi) }; }; EOF mkimage \ - -E -p 0x1000 \ - -f $workdir/netbox.its $out \ - || die "Unable to create FIT image" + ${opts} \ + -f $workdir/netbox.its $out \ + || die "Unable to create FIT image" rm -rf $workdir + diff --git a/support/scripts/fitimage_legacy.sh b/support/scripts/fitimage_legacy.sh new file mode 100755 index 0000000..06cbe28 --- /dev/null +++ b/support/scripts/fitimage_legacy.sh @@ -0,0 +1,126 @@ +#!/bin/sh + +die() { + echo "$1" >&2 + rm -rf $workdir + exit 1 +} + +plat=$1 +squash=$2 +out=$3 +load=0 + +case $plat in + basis) + arch="arm" + load="0x20000000" + ;; + byron) + arch="arm" + load="0x20000000" + ;; + coronet) + arch="powerpc" + ;; + dagger) + arch="arm" + ;; + envoy) + arch="arm64" + load="0x40000000" + ;; + ember) + arch="arm64" + load="0x40000000" + ;; + zero) + arch="x86_64" + ;; + *) + arch="$plat" + ;; +esac + +workdir=$(mktemp -d) +unsquashfs -f -d $workdir $squash boot || die "Invalid SquashFS" + +kernel=$(echo $workdir/boot/*Image | cut -d\ -f1) +[ "$kernel" ] || die "No kernel found" + +dtbs=$workdir/boot/*/device-tree.dtb + +# mkimage will only align images to 4 bytes, but U-Boot will leave +# both DTB and ramdisk in place when starting the kernel. So we pad +# all components up to a 4k boundary. +truncate -s %4k $kernel $dtbs + +for dtb in $dtbs; do + name=$(basename $(dirname $dtb)) + + cat <>$workdir/netbox-dtbs.itsi + $name { + description = "$name"; + type = "flat_dt"; + arch = "$arch"; + compression = "none"; + data = /incbin/("$dtb"); + }; +EOF + cat <>$workdir/netbox-cfgs.itsi + $name { + description = "$name"; + kernel = "kernel"; + ramdisk = "ramdisk"; + fdt = "$name"; + }; +EOF +done + +cat <$workdir/netbox.its +/dts-v1/; + +/ { + timestamp = <$(date +%s)>; + description = "Netbox ($plat)"; + creator = "netbox"; + #address-cells = <0x1>; + + images { + + kernel { + description = "Linux"; + type = "kernel"; + arch = "$arch"; + os = "linux"; + load = <$load>; + entry = <$load>; + compression = "none"; + data = /incbin/("$kernel"); + }; + + ramdisk { + description = "Netbox"; + type = "ramdisk"; + os = "linux"; + arch = "$arch"; + compression = "none"; + data = /incbin/("$squash"); + }; + +$(cat $workdir/netbox-dtbs.itsi) + + }; + + configurations { +$(cat $workdir/netbox-cfgs.itsi) + }; +}; +EOF + +mkimage \ + -E -p 0x1000 \ + -f $workdir/netbox.its $out \ + || die "Unable to create FIT image" + +rm -rf $workdir