#!/bin/bash

cd spl_bsp
make config
make clean
#patch -N generated/reset_config.h ../socfpga_cyclone5_usb_pll1.patch
#patch -N generated/pinmux_config_cyclone5.c ../socfpga_cyclone5_usb_pll2.patch
patch -N uboot-socfpga/include/configs/socfpga_common.h ../socfpga_cyclone5_boot.patch
#patch -N uboot-socfpga/arch/arm/include/asm/arch-socfpga/clock_manager.h ../socfpga_cyclone5_PLL_loss_clear_h.patch # not longer necessary because of bug fix in Quartus 14.1
#patch -N uboot-socfpga/arch/arm/cpu/armv7/socfpga/clock_manager.c ../socfpga_cyclone5_PLL_loss_clear_c.patch
#patch -N uboot-socfpga/arch/arm/cpu/armv7/socfpga/reset_manager.c ../socfpga_cyclone5_usb.patch
patch -N uboot-socfpga/arch/arm/cpu/armv7/socfpga/sdram.c ../u-boot-socfpga_sdramTurnaround.patch
make
mkpimage --header-version 0 -o preloader-mkpimage.bin uboot-socfpga/spl/u-boot-spl.bin
arm-altera-eabi-objcopy -I binary -O ihex --adjust-vma -0x00000000 preloader-mkpimage.bin preload.hex
cp preload.hex ../../