@echo off
setlocal enabledelayedexpansion

set argCount = 0
set cs_flag = 0
set fw_path=fw\126135.bin
for %%x in (%*) do (
    set /A argCount+=1
    set "argVec[!argCount!]=%%~x"
)

for /L %%i in (1,1,%argCount%) do (
    if !cs_flag! == "1" (
	    echo !argVec[%%i]!
	    set address=-cs !argVec[%%i]!
		set cs_flag="0"
	)
    if "!argVec[%%i]!" == "cs" (
	    set cs_flag="1"
    )
	if  "!argVec[%%i]!" == "flashall" (
	    set flashall_flag=-a
	)
    if  "!argVec[%%i]!" == "preserve" (
        set flashall_flag=-preserve
    )
	if  "!argVec[%%i]!" == "x32" (
	    set os_version=32
	)
)

if defined os_version (
	Tools\gigaflash.exe %fw_path% %flashall_flag% %address% -2500
) else (
    Tools\gigaflash_x64.exe %fw_path% %flashall_flag% %address% -2500
) 

@echo on