echo off
echo .
echo ............................................................
echo Program Flash input param(cmd=%1)(image=%2)(region start=%3)(region size=%4)
echo ............................................................
echo .

SET CHIP_VER=ATMx2xx-x1x
goto RUN

:RUN
SET FTDI_BENIGN_BOOT=1 
SET FTDI_HARD_RESET=1
SET PATH_OPENOCD_TCL_BASE=.\\fw_image\\openocd-0.10.0\\tcl
SET PATH_OPENOCD_EXE=.\\fw_image\\openocd-0.10.0\\openocd.exe 
SET PATH_OPENOCD_TCL=.\\fw_image\\%CHIP_VER%\\openocd
SET PATH_OPENOCD_CFG=.\\fw_image\\%CHIP_VER%\\openocd\\atm2x_openocd.cfg
SET SYDNEY_SWD_KHZ=12000

%PATH_OPENOCD_EXE% -s %PATH_OPENOCD_TCL_BASE% -s %PATH_OPENOCD_TCL% -f %PATH_OPENOCD_CFG% -c "init; exit"
SET FTDI_HARD_RESET=0
%PATH_OPENOCD_EXE% -s %PATH_OPENOCD_TCL_BASE% -s %PATH_OPENOCD_TCL% -f %PATH_OPENOCD_CFG% -c "init; exit"
SET FTDI_BENIGN_BOOT=0
%PATH_OPENOCD_EXE% -s %PATH_OPENOCD_TCL_BASE% -s %PATH_OPENOCD_TCL% -f %PATH_OPENOCD_CFG% -c "init; sleep 200; set_normal_boot; exit"

if %1 == flash (
%PATH_OPENOCD_EXE% -s %PATH_OPENOCD_TCL_BASE% -s %PATH_OPENOCD_TCL% -f %PATH_OPENOCD_CFG% -c "init; verify_rom_version; sydney_load_flash %2 %3 %4; exit"
)

if %1 == nvds (
%PATH_OPENOCD_EXE% -s %PATH_OPENOCD_TCL_BASE% -s %PATH_OPENOCD_TCL% -f %PATH_OPENOCD_CFG% -c "init; verify_rom_version; sydney_load_nvds %2 %3 %4; exit"
)

if %1 == erase (
%PATH_OPENOCD_EXE% -s %PATH_OPENOCD_TCL_BASE% -s %PATH_OPENOCD_TCL% -f %PATH_OPENOCD_CFG% -c "init; verify_rom_version; sydney_erase_nvds %2 %3; exit"
)

if %1 == dump (
%PATH_OPENOCD_EXE% -s %PATH_OPENOCD_TCL_BASE% -s %PATH_OPENOCD_TCL% -f %PATH_OPENOCD_CFG% -c "init; verify_rom_version; sydney_dump_nvds %2 %3 %4; exit"
)


if %1 == reboot (
%PATH_OPENOCD_EXE% -s %PATH_OPENOCD_TCL_BASE% -s %PATH_OPENOCD_TCL% -f %PATH_OPENOCD_CFG% -c "init; set _RESET_HARD_ON_EXIT 1; exit"
)
goto END

:END
echo we are done

