barebox/scripts/gen-dtb-s
Sascha Hauer 58eae8361c ARM: Allow compressed dtb binaries
In the current multi image build process the DTBs end up uncompressed
in the PBL. This can be annoying because the PBL is often very size
constrained.
This patch allows to put the DTBs in as lzo compressed binary into
the PBL. Since lzo offers quite good compression ratios for DTBs no
other compression algorithm has been implemented for now.
Boards which want to use the compressed DTBs only have to change
the __dtb_ prefix in the DTB name to __dtb_z_. Also they should select
ARM_USE_COMPRESSED_DTB to make sure barebox supports uncompressing
the DTB.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-10-27 10:02:28 +01:00

76 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
name=$1
dtb=$2
imd=$3
echo "#include <asm-generic/barebox.lds.h>"
le32() {
printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
$(($1 & 0xff)) \
$((($1 >> 8) & 0xff)) \
$((($1 >> 16) & 0xff)) \
$((($1 >> 24) & 0xff))
}
FDTGET=scripts/dtc/fdtget
if [ "$imd" = "y" ]; then
echo ".section .barebox_imd_0.${name},\"a\""
echo ".global __imd_${name}_start"
echo "__imd_${name}_start:"
compat=$($FDTGET -d notfound -t bi "$dtb" / compatible | sed "s^ ^,^g")
if [ "$compat" != "notfound" ]; then
compatlen=$($FDTGET -t s "$dtb" / compatible | wc -c)
le32 0x640c8005
le32 $compatlen
echo ".byte " $compat
echo ".balign 4"
fi
model=$($FDTGET -d notfound -t bi "$dtb" / model | sed "s^ ^,^g")
if [ "$model" != "notfound" ]; then
modellen=$($FDTGET -t s "$dtb" / model | wc -c)
le32 0x640c8004
le32 $modellen
echo ".byte " $model
echo ".balign 4"
fi
fi
echo ".section .dtb.rodata.${name},\"a\""
echo ".balign STRUCT_ALIGNMENT"
echo ".global __dtb_${name}_start"
echo "__dtb_${name}_start:"
echo ".incbin \"$dtb\""
echo "__dtb_${name}_end:"
echo ".global __dtb_${name}_end"
echo ".balign STRUCT_ALIGNMENT"
lzop -f -9 $dtb -o $dtb.lzo
if [ $? != 0 ]; then
exit 1
fi
compressed=$(stat $dtb.lzo -c "%s")
uncompressed=$(stat $dtb -c "%s")
echo ".section .dtb.rodata.${name}.z,\"a\""
echo ".balign STRUCT_ALIGNMENT"
echo ".global __dtb_z_${name}_start"
echo "__dtb_z_${name}_start:"
printf ".word 0x%08x\n" 0x7b66bcbd
printf ".word 0x%08x\n" $compressed
printf ".word 0x%08x\n" $uncompressed
echo ".incbin \"$dtb.lzo\""
echo "__dtb_z_${name}_end:"
echo ".global __dtb_z_${name}_end"
echo ".balign STRUCT_ALIGNMENT"
if [ "$imd" = "y" ]; then
echo ".word __imd_${name}_start"
fi