#!/bin/bash

# Catch Postbuild Error
function error {
  
  echo "Postbuild Failed."
  exit 1;
}

set -e
trap error ERR

echo "==>   POSTBUILD:"

echo "BR_STAGING: ${BR_STAGING}"
echo "BR_PROJECT: " ${BR_PROJECT}

cp -a ${BR_PROJECT}/configs/config.txt ${BR_STAGING}/buildroot/images/

if [ ! -f ${AW_STAGING}/buildroot/images/data.ext2 ];
then 
	echo "generate data image (10M)."
	dd if=/dev/zero of=${BR_STAGING}/buildroot/images/data.ext2 bs=1k count=10000
	${BR_STAGING}/cross/usr/sbin/mkfs.ext2 -i 1024 -b 1024 -F ${BR_STAGING}/buildroot/images/data.ext2
fi

cp -a ${BR_STAGING}/buildroot/images/uboot-env.bin ${BR_STAGING}/buildroot/images/uboot.env

make -C ${BR_PROJECT} dtb
