#!/usr/bin/bash

if [ $# -eq 0 ]
then
    echo "usage: setcountrycode [jp|us|eu]"
    echo " Sets the country code on disc."
    exit 0
fi

if [ $1 != "jp" -a $1 != "us" -a $1 != "eu" ]
then
    echo "Illegal argument. Do nothing and exit."
    exit 1
fi

if [ "$NDEV" = "" ]
then
    echo "NDEV is not found. Do nothing and exit."
    exit 0
fi

if [ "$NDEV" != "" ]
then
    echo "NDEV detected"

    #
    # change NDEV configuration
    #
    if   [ $1 = "jp" ]
    then
        CPARA=0
        CNAME=Japan
    elif [ $1 = "us" ]
    then
        CPARA=1
        CNAME=US
    elif [ $1 = "eu" ]
    then
        CPARA=2
        CNAME=Europe
    fi
#     echo ${CPARA}
#     echo ${CNAME}
    
    for i in "$REVOLUTION_SDK_ROOT"/X86/bin/rvl*.bin
    do
#         echo "$i"
        if ! $REVOLUTION_SDK_ROOT/x86/bin/tickleBI3 -o "$i" 0x0 ${CPARA}
        then
            echo "Failed to set the country code on disc."
            exit 1
    
        fi
    done
    if [ -e $REVOLUTION_SDK_ROOT/x86/bin/wbi.bin ]
    then
        if ! $REVOLUTION_SDK_ROOT/x86/bin/tickleWBI "$REVOLUTION_SDK_ROOT/X86/bin/wbi.bin" -c ${CPARA}
        then
            echo "Failed to set the contry code for nand application."
            exit 1
	fi
    fi
    echo "Successfully done. Set the country code for the disc to ${CNAME}."
fi

echo
echo "**********************************************************************"
echo "* If you make master data, you must execute ndrun before you do so!! *"
echo "**********************************************************************"
echo
