#!/usr/bin/bash

if [ $# -eq 0 ]
then
    echo "usage: setsmem2size 64"
    echo "usage: setsmem2size 128"
    echo " Sets console simulated MEM2 size. Either 64MB or 128MB is set as the console simulated memory size."
    exit 1
fi

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

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

    #
    # change NDEV configuration
    #

    if [ $1 = 64 ]
    then
        if $REVOLUTION_SDK_ROOT/x86/bin/tickleBI2 -o "$REVOLUTION_SDK_ROOT/x86/bin/bi2.bin" 44 0x4000000
        then
            echo "Successfully done. Set 64MB as the console simulated mem size."
        else
            echo "Failed to set the console simulated mem size."
            exit 1
        fi
    elif [ $1 = 128 ]
    then
        if $REVOLUTION_SDK_ROOT/x86/bin/tickleBI2 -o "$REVOLUTION_SDK_ROOT/x86/bin/bi2.bin" 44 0x8000000
        then
            echo "Successfully done. Set 128MB as the console simulated mem size."
        else
            echo "Failed to set the console simulated mem size."
            exit 1
        fi
    elif [ $1 = "0" ]
    then
        if $REVOLUTION_SDK_ROOT/x86/bin/tickleBI2 -o "$REVOLUTION_SDK_ROOT/x86/bin/bi2.bin" 44 0x0
        then
            echo "Successfully done. Physical memory size is considered as the console simulated mem size."
        else
            echo "Failed to set the console simulated mem size."
            exit 1
        fi
    elif [ $1 = "0x0" ]
    then
        if $REVOLUTION_SDK_ROOT/x86/bin/tickleBI2 -o "$REVOLUTION_SDK_ROOT/x86/bin/bi2.bin" 44 0x0
        then
            echo "Successfully done. Physical memory size is considered as the console simulated mem size."
        else
            echo "Failed to set the console simulated mem size."
            exit 1
        fi
    else
        echo "usage: setsmem2size 64"
        echo "usage: setsmem2size 128"
        echo " Sets console simulated MEM2 size. Either 64MB or 128MB is set as the console simulated memory size."
        exit 1
    fi
fi

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

