@echo off
:begin
if "%1"=="LM" goto 1
if "%1"=="lm" goto 1
if "%1"=="LCU" goto 2
if "%1"=="lcu" goto 2
if "%1"=="RDC" goto 3
if "%1"=="rdc" goto 3
if "%1"=="TX" goto 4
if "%1"=="tx" goto 4
if "%1"=="IOP" goto 5
if "%1"=="iop" goto 5
if "%1"=="-h" goto 6
if "%1"=="-H" goto 6
ECHO Invalid board type!
goto end

:1
IF NOT EXIST "%2" goto exit1
IF NOT EXIST "%3" goto exit2
REM Flash_LCU_sector "%2" "%3"  flash_lm.bin
Flash_sector "%2" "%3"  flash_lm.bin
flashenc 0x30 0x10 512 500000 100 flash_lm.bin flash_lm.enc
DEL flash_lm.bin
ECHO Encoded Output File : flash_lm.enc
goto end

:2
IF NOT EXIST "%2" goto exit1
IF NOT EXIST "%3" goto exit2
REM Flash_LCU_sector "%2" "%3"  flash_lcu.bin
Flash_sector "%2" "%3"  flash_lcu.bin
flashenc 0x20 0x10 512 500000 100 flash_lcu.bin flash_lcu.enc
DEL flash_lcu.bin
ECHO Encoded Output File : flash_lcu.enc
goto end

:3
IF NOT EXIST "%2" goto exit1
IF NOT EXIST "%3" goto exit2
IF NOT EXIST "%4" goto exit3
Flash_sector_RDC "%2" "%3" "%4" flash_rdc.bin
flashenc 0x26 0x10 512 500000 100 flash_rdc.bin flash_rdc.enc
DEL flash_rdc.bin
ECHO Encoded Output File : flash_rdc.enc
set %4=
goto end

:4
IF NOT EXIST "%2" goto exit1
IF NOT EXIST "%3" goto exit2
Flash_sector "%2" "%3"  flash_stx.bin
flashenc 0x2A 0x10 512 500000 100 flash_stx.bin flash_stx.enc
DEL flash_stx.bin
ECHO Encoded Output File : flash_stx.enc
goto end

:5
IF NOT EXIST "%2" goto exit1
IF NOT EXIST "%3" goto exit2
Flash_sector "%2" "%3"  flash_iop.bin
flashenc 0x25 0x10 512 500000 100 flash_iop.bin flash_iop.enc
DEL flash_iop.bin
ECHO Encoded Output File : flash_iop.enc
goto end

:6
ECHO.
ECHO **********************************
ECHO ************** HELP **************
ECHO **********************************
ECHO.
ECHO Creates a 4-to-5 encoded stream flash image.
ECHO.
ECHO syntax: flashfile BoardType DspHex FpgaBin FpgaRxBin (for RDC only)
ECHO.
ECHO BoardType = determines for which board the flash file is created:
ECHO              -type "LM"   or "lm"   for Link Module
ECHO              -type "LCU"  or "lcu"  for Link Controller Unit
ECHO              -type "RDC"  or "rdc"  for Receiver Digital Controller
ECHO              -type "TX"   or "tx"   for Transmitter
ECHO              -type "IOPW" or "iopw" for I/O Processor Wet
ECHO.
ECHO DspHex    = DSP hex filename (.hex)
ECHO FpgaBin   = FPGA bin filename (.bin)
ECHO FpgaRxBin = Receiver FPGA bin filename (.bin) (Needed only for RDC!)
ECHO.
goto end

:exit1
ECHO "%2" cannot be found!
goto end

:exit2
ECHO "%3" cannot be found!
goto end

:exit3
ECHO "%4" cannot be found!
goto end

:end


