|
| 1 | +@echo off |
| 2 | +REM Windows batch file equivalent of progmemcheck.sh |
| 3 | +REM Checks if PROGMEM section is too large (over 65535 bytes) |
| 4 | +REM Usage: progmemcheck.bat <objdump_tool> <object_file> |
| 5 | + |
| 6 | +if "%1"=="" goto usage |
| 7 | +if "%2"=="" goto usage |
| 8 | + |
| 9 | +REM Execute objdump command and extract the address (should be decimal with -t d option) |
| 10 | +for /f "tokens=1" %%i in ('%1 -t d %2 ^| findstr "__ctors_start"') do set progmem_end=%%i |
| 11 | + |
| 12 | +REM Check if we got a result |
| 13 | +if "%progmem_end%"=="" ( |
| 14 | + exit /b 0 |
| 15 | +) |
| 16 | + |
| 17 | +REM Remove any leading/trailing spaces |
| 18 | +set progmem_end=%progmem_end: =% |
| 19 | + |
| 20 | +REM Remove leading zeros manually (batch treats leading zeros as octal) |
| 21 | +:strip_zeros |
| 22 | +if "%progmem_end:~0,1%"=="0" if not "%progmem_end%"=="0" ( |
| 23 | + set progmem_end=%progmem_end:~1% |
| 24 | + goto strip_zeros |
| 25 | +) |
| 26 | + |
| 27 | +REM If we stripped all digits, it was "000..." so set to 0 |
| 28 | +if "%progmem_end%"=="" set progmem_end=0 |
| 29 | + |
| 30 | +REM Check if progmem_end is greater than 65535 |
| 31 | +if %progmem_end% LEQ 65535 goto end |
| 32 | + |
| 33 | +REM Calculate the excess bytes |
| 34 | +set /a excess=%progmem_end% - 65535 |
| 35 | + |
| 36 | +set line="^| Severe Warning: PROGMEM section too large by %excess% bytes. " |
| 37 | +echo. |
| 38 | +echo _______________________________________________________________ |
| 39 | +echo %line:~1,63%^| |
| 40 | +echo ^| Your program will most probably be unstable! ^| |
| 41 | +echo ^| Use the macros PROGMEM_FAR from ^<progmem_far.h^> and ^| |
| 42 | +echo ^| pgm_get_far_address/pgm_read_xxxx_far from ^<avr/pgmspace.h^>.^| |
| 43 | +echo ^|_____________________________________________________________^| |
| 44 | +echo. |
| 45 | +goto end |
| 46 | + |
| 47 | +:usage |
| 48 | +echo Usage: %0 ^<objdump_tool^> ^<object_file^> |
| 49 | +echo Example: %0 avr-objdump firmware.elf |
| 50 | +exit /b 1 |
| 51 | + |
| 52 | +:end |
| 53 | +exit /b 0 |
0 commit comments