From eff5c04efa94e581f45f9d5811f3184ddab6ba9c Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 Feb 2022 13:47:18 +0100 Subject: scripts: add tool to adjust bl33 load address in existing FIP Instead of rebuilding TF-A with a (newer) barebox, an existing image can be repacked: fiptool update fip.bin --nt-fw images/barebox-dt-2nd.img \ --hw-config build/arch/arm/dts/stm32mp157c-dk2.dtb This may fail at runtime though, because the STM32MP default is to place BL33 at the very start of RAM. The script introduced here offers an alternative to rebuilding TF-A with adjust FW_CONFIG: ./scripts/fiptool_fwconfig -l 0xc0001000 mmcblk0p3 This will have barebox loaded 4096 bytes into the STM32MP SDRAM. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220220124736.3052502-7-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- scripts/fiptool_fwconfig | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 scripts/fiptool_fwconfig diff --git a/scripts/fiptool_fwconfig b/scripts/fiptool_fwconfig new file mode 100755 index 0000000000..f76f450b04 --- /dev/null +++ b/scripts/fiptool_fwconfig @@ -0,0 +1,39 @@ +#!/bin/sh + +set -e + +# adjust bl33 load address in existing FIP + +FDTGET=${FDTGET:-fdtget} +FDTPUT=${FDTPUT:-fdtput} + +if [ "$1" != "-l" ] || [ "$#" -ne 3 ]; then + echo "USAGE: $0 -l NT_LOAD_ADDR FIP" 1>&2 + exit 1 +fi + +NEW_LOAD_ADDR=$(($2)) +FIP=$3 +FWCONFIG=".$FIP.fw-config.bin" + +fiptool unpack --fw-config "$FWCONFIG" --force "$FIP" + +MAX_SIZE="$($FDTGET -t u $FWCONFIG /dtb-registry/nt_fw max-size)" +set $($FDTGET -t u $FWCONFIG /dtb-registry/nt_fw load-address) +ENTRY=$1 +OLD_LOAD_ADDR=$2 + +if [ $NEW_LOAD_ADDR -lt $OLD_LOAD_ADDR ] || + [ $NEW_LOAD_ADDR -ge $((OLD_LOAD_ADDR + MAX_SIZE)) ]; then + printf "New load address 0x%08x out of bounds [0x%08x-0x%08x)\n" \ + $NEW_LOAD_ADDR $OLD_LOAD_ADDR $((OLD_LOAD_ADDR + MAX_SIZE)) 1>&2 + exit 1 +fi + +$FDTPUT -t u $FWCONFIG /dtb-registry/nt_fw load-address $ENTRY $NEW_LOAD_ADDR +$FDTPUT -t u $FWCONFIG /dtb-registry/nt_fw max-size \ + $((MAX_SIZE + OLD_LOAD_ADDR - NEW_LOAD_ADDR)) + +fiptool update $FIP --fw-config $FWCONFIG + +rm $FWCONFIG -- cgit v1.2.3