@echo off
setlocal ENABLEDELAYEDEXPANSION

set file_path=%1
set file_ext=!file_path:~-3!

IF /I "%file_ext%"=="elf" goto program_elf
IF /I "%file_ext%"=="bin" goto program_bin

echo %file_path%
echo File type unsupported
goto end

:program_elf
echo Program elf32-avr32 file...
avr32program chiperase
avr32program program -finternal@0x80000000,512Kb -cxtal -e -R -r -v "%file_path%"
goto end

:program_bin
echo Program binary file...
avr32program chiperase
avr32program program -Fbin -O0x80000000 -finternal@0x80000000,512Kb -cxtal -e -R -r -v "%file_path%"
goto end

:end
pause
