Skip to content

Commit

Permalink
scripts: board: common: add new FIT support for all platforms
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
joazet committed Dec 3, 2023
1 parent 2d6116d commit 96d6d38
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 22 deletions.
7 changes: 7 additions & 0 deletions board/common/post-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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"
Expand Down
86 changes: 64 additions & 22 deletions support/scripts/fitimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -48,31 +54,62 @@ 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
# all components up to a 4k boundary.
truncate -s %4k $kernel $dtbs

for dtb in $dtbs; do
name=$(basename $(dirname $dtb))
name=$(basename $(dirname $dtb) | cut -d "-" -f1)

cat <<EOF >>$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 <<EOF >>$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
Expand All @@ -87,40 +124,45 @@ cat <<EOF >$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

126 changes: 126 additions & 0 deletions support/scripts/fitimage_legacy.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF >>$workdir/netbox-dtbs.itsi
$name {
description = "$name";
type = "flat_dt";
arch = "$arch";
compression = "none";
data = /incbin/("$dtb");
};
EOF
cat <<EOF >>$workdir/netbox-cfgs.itsi
$name {
description = "$name";
kernel = "kernel";
ramdisk = "ramdisk";
fdt = "$name";
};
EOF
done

cat <<EOF >$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

0 comments on commit 96d6d38

Please sign in to comment.