@echo off

IF "%1"=="" GOTO Err1
if not exist %1 GOTO Err2

REN AFUDOSU.SMC AFUDOSU.EXE

DMI c %1
if errorlevel 10 if not errorlevel 11 goto DOWNGRADE
if errorlevel 20 if not errorlevel 21 goto UPGRADE
goto NORMAL

:NORMAL
AFUDOSU %1 /P /B /N /K /R
GOTO DONE


:DOWNGRADE
AFUDOSU A1.t01 /O
copy %1 A1.t02 /Y
dmi d A1.t01 A1.t02
AFUDOSU.EXE A1.t02 /P /B /N /K
GOTO DONE

:UPGRADE
AFUDOSU A1.t01 /O
copy %1 A1.t02 /Y
dmi u A1.t01 A1.t02
AFUDOSU.EXE A1.t02 /P /B /N /K
GOTO DONE

:DONE
if exist A1.t01 del A1.t01
if exist A1.t02 del A1.t02

REN AFUDOSU.EXE AFUDOSU.SMC


Goto END

:Err1
echo *********************************************************
echo   Usage:
echo			flash.bat romfile
echo *********************************************************
GOTO END

:Err2
echo *********************************************************
echo   File %1 dosn't exist
echo *********************************************************

:END