echo off
rem runflash.bat
rem Reflashes a Set 5.24 target
cls
if !%1==%1! goto error_usage
rem
set FILE_DA=%1\Genie.fsh
set FILE_GDM=%1\gm2_6_0h.fsh
set FILE_BOOT=%1\btrf5001.bin
rem
if not exist %FILE_DA% goto no_da
if not exist %FILE_GDM% goto no_gdm
if not exist %FILE_BOOT% goto no_boot
echo This process will update your Development System with current
echo debug adapter, GD-ROM, and boot ROM firmware.  In order to run
echo this process, you must have a Set 5.24 development system connected
echo to your PC, and the latest ASPI drivers must be installed on the
echo PC.  See readme.txt for details.
echo.
echo.
echo This process does *NOT* work on Set 5.23 systems.  Check the serial
echo number on the bottom of the unit if you are unsure of the version
echo number of your system.
echo.
echo To stop this process, press [Ctrl-C] then Y to quit or
pause
if not exist %1\dbflash.exe goto error_noutil
start /wait %1\dbflash.exe /D%FILE_DA% /G%FILE_GDM% /B%FILE_BOOT%
cls
:check
echo Please set the switch marked SLIDE_SW on the front of the development
echo system to the LEFT now.  Then, turn the power of the development
echo system OFF for thirty seconds.  Finally, turn the development system
echo back on.
echo.
if not "%OS%"=="Windows_NT" goto notnt
echo You will also need to reboot your PC for these changes to take effect.
echo.
:notnt
if errorlevel 10 goto error_10
if errorlevel 9 goto error_9
if errorlevel 8 goto error_8
if errorlevel 7 goto error_7
if errorlevel 6 goto error_6
if errorlevel 5 goto error_5
if errorlevel 4 goto error_4
if errorlevel 3 goto error_3
if errorlevel 2 goto error_2
if errorlevel 1 goto error_1
echo The reflashing process was successful.
goto done

:error_1
echo The filename for the debug adapter flash file was invalid.
goto help

:error_2
echo The filename for the GD-ROM flash file was invalid.
goto help

:error_3
echo The filename for the boot ROM flash file was invalid.
goto help

:error_4
echo The filename for the log file was invalid.
goto help

:error_5
echo The debug adapter could not be reflashed.
goto help

:error_6
echo The GD-ROM could not be reflashed.
goto help

:error_7
echo The boot ROM could not be reflashed.
goto help

:error_8
echo The boot ROM could not be reflashed due to a timeout communication
echo error.  Was the SLIDE_SW moved to the right before flashing?
goto help

:error_9
echo No flash files were defined; see the switch definitions in readme.txt.
goto help

:error_10
echo Another copy of the DBFlash utility was already running.
goto help

:error_util
echo The reflashing program, DBFlash.exe, could not be found.
goto help

:error_usage
echo Usage: %0 [path to firmware images]
goto help

:no_da
echo The debug adapter firmware file could not be found.  Please check
echo that the Testing Utilities were correctly installed.
goto help

:no_gdm
echo The GD-M firmware file could not be found.  Please check that the
echo Testing Utilities were correctly installed.

:no_boot
echo The boot ROM file could not be found.  Please check that the Testing
echo Utilities were correctly installed.

:help
echo.
echo Please check the target system and try reflashing the target.  If you
echo are unable to reflash the system after multiple attempts, please
echo contact Sega Developer Technical Support.

:done
pause
cls
