#!/bin/sh
set -e

mtd erase bl2 && mtd write arm-trusted-firmware/build/ten64/debug/bl2_qspi.pbl bl2
mtd erase bl3 && mtd write arm-trusted-firmware/build/ten64/debug/fip.bin bl3
mtd erase mcfirmware && mtd write qoriq-mc-binary/ls1088a/mc_10.20.4_ls1088a.itb mcfirmware
mtd erase ubootenv
mtd erase dpl && mtd write "dpaa2/dpl/eth-dpl-all.dtb" dpl
mtd erase dpc && mtd write "dpaa2/dpc/dpc.0x1D-0x0D.dtb" dpc
mtd erase devicetree && mtd write recovery.itb recovery

UBIA_MTD_PART=$(cat /proc/mtd | grep ubia | awk -F ':' '{print $1}')
ubiformat "/dev/${UBIA_MTD_PART}" -f openwrt-nand.ubi
