RZ-A/Boards/Flash-gr-peach.sh

From eLinux.org
Jump to: navigation, search
#!/bin/bash

JLINK_CMD="JLinkExe -speed 15000 -if JTAG -jtagconf -1,-1  -device R7S721001 -CommanderScript "

#this options targets GR-Peach board. Change accordingly to your setup
UBOOTNAME="u-boot.bin"
DTSNAME="r7s72100-gr-peach.dtb.bin"
INITRDNAME="rootfs.bin"

usage()
{
        echo $#
        echo $0 " target dest"
        echo "      target: dts linux initramfs boot all"
        echo "      dest: qspi ram"
}

if [ $# -lt 2 ]; then
	usage
	exit 0
fi

TARGET=$1
DEST=$2
CMDFILE=/tmp/jlinkcmd_$(date +%F%T)

if [ $# -lt 3 ]; then
        echo "Assume files location is /tmp/"
        FILEDIR=/tmp
else
        echo "Load file from location " $3
        FILEDIR=$3
fi

touch $CMDFILE
echo "rx 100" >> $CMDFILE
echo "g" >> $CMDFILE

case $DEST in
    qspi)
            UBOOTADDR=0x18000000
            DTSADDR=0x180C0000
            LINUXADDR=0x18100000
            INITRDADDR=0x18600000
            LINUXNAME="xipImage.bin"
            ;;
    ram)
            DTSADDR=0x20800000
            LINUXADDR=0x20508000
            INITRDADDR=0x18600000
            LINUXNAME="uImage.bin"

            # u-boot can only be written to qspi
            if [ $TARGET == "u-boot" ]; then
                    echo "Cannot load u-boot in RAM"
            fi
            ;;
    *)
            usage
            exit 0
            ;;
esac

echo "========================================================================="
echo "Prepare to load:"

case $TARGET in
        u-boot)
                echo $FILEDIR/$UBOOTNAME "to " $UBOOTADDR
                echo "loadbin " $FILEDIR/$UBOOTNAME  "," $UBOOTADDR >> $CMDFILE
                ;;
        dts)
                echo $FILEDIR/$DTSNAME "to " $DTSADDR
                echo "loadbin "  $FILEDIR/$DTSNAME "," $DTSADDR >> $CMDFILE
                ;;
        linux)
                echo $FILEDIR/$LINUXNAME "to " $LINUXADDR
                echo "loadbin "  $FILEDIR/$LINUXNAME "," $LINUXADDR >> $CMDFILE
                ;;
        initramfs)
                echo $FILEDIR/$INITRDNAME "to " $INITRDADDR
                echo "loadbin "  $FILEDIR/$INITRDNAME "," $INITRDADDR >> $CMDFILE
                ;;
        boot)
                echo $FILEDIR/$DTSNAME "to " $DTSADDR
                echo $FILEDIR/$LINUXNAME "to " $LINUXADDR
                echo "loadbin "  $FILEDIR/$DTSNAME "," $DTSADDR >> $CMDFILE
                echo "loadbin "  $FILEDIR/$LINUXNAME "," $LINUXADDR >> $CMDFILE
                ;;
        all)
                echo $FILEDIR/$DTSNAME "to " $DTSADDR
                echo $FILEDIR/$LINUXNAME "to " $LINUXADDR
                echo $FILEDIR/$INITRDNAME "to " $INITRDADDR
                echo "loadbin "  $FILEDIR/$DTSNAME "," $DTSADDR >> $CMDFILE
                echo "loadbin "  $FILEDIR/$LINUXNAME "," $LINUXADDR >> $CMDFILE
                echo "loadbin "  $FILEDIR/$INITRDNAME "," $INITRDADDR >> $CMDFILE
                ;;
        *)
            echo "========================================================================="
            echo
            usage
            exit 0
            ;;
esac

echo "========================================================================="
echo "g" >> $CMDFILE
echo "exit" >> $CMDFILE

echo "Continue with flash procedure? [Y/n]"
read INPUT
echo $INPUT
if [ $INPUT != "y" -a $INPUT != "Y" -a $INPUT == "\n" ]; then
        rm $CMDFILE
        echo "Aborting"
        exit 0
 fi

$JLINK_CMD $CMDFILE
rm $CMDFILE