#!/bin/sh

echo "Generating U-Boot Environment"
echo -en "\0\0\0\0" >uboot.env
echo -en "bootargs=mac_adr=0x00,0xd0,0xb8,0x19,0x81,0xfb\0" >>uboot.env
echo -en "baudrate=115200\0" >>uboot.env
echo -en "loads_echo=0\0" >>uboot.env
echo -en "rootpath=/nfs/arm\0" >>uboot.env
echo -en "ethact=egiga0\0" >>uboot.env
echo -en "ethaddr=00:16:01:41:4E:2B\0" >>uboot.env
echo -en "ipaddr=192.168.11.150\0" >>uboot.env
echo -en "serverip=192.168.11.1\0" >>uboot.env
echo -en "stdin=serial\0" >>uboot.env
echo -en "stdout=serial\0" >>uboot.env
echo -en "stderr=serial\0" >>uboot.env
echo -en "ethprime=egiga0\0" >>uboot.env
echo -en "initrd=uInitrd\0" >>uboot.env
echo -en "kernel=uImage\0" >>uboot.env
echo -en "bootargs_base=console=ttyS0,115200\0" >>uboot.env
echo -en "bootargs_root=root=/dev/sda2 rw\0" >>uboot.env
echo -en "def_tftp=tftp 0x60100000 \${kernel};tftp 0x60800000 \${initrd};setenv bootargs_new \${bootargs};setenv bootargs \${bootargs_base} \${bootargs_root} \${bootargs_new} tftpboot=yes;bootm 0x60100000 0x60800000\0" >>uboot.env
echo -en "bootdelay=3\0" >>uboot.env
echo -en "force_tftp=1\0" >>uboot.env
echo -en "bootcmd=ide reset; fatload ide 0:1 0x60100000 /\${kernel};fatload ide 0:1 0x60800000 /\${initrd};setenv bootargs_new \${bootargs};setenv bootargs \${bootargs_base} \${bootargs_root} \${bootargs_new};bootm 0x60100000 0x60800000\0" >>uboot.env
echo -en "\0" >>uboot.env

if [ ! -e ./ubootcrc-8192bytes ] ; then
    echo "Compiling CRC calculation tool"
    gcc -o ubootcrc-8192bytes ubootcrc-8192bytes.c
fi
echo "Finalizing U-Boot Environment"
./ubootcrc-8192bytes <uboot.env >uboot.newenv

echo "uboot.newenv contains a valid environment for SATA disk"
