Reputation: 287
How to know the flash size of a bare metal arm code. If I have the elf is it possible to know how much flash will be required to store the program? For example if I have the elf file that is supposed to go into a ARM based MCU, how can I determine how much of the MCU's flash will be consumed by the code?
Upvotes: 1
Views: 1269
Reputation: 25599
The ELF headers should contain the information you need. You can use either the objdump
(with -h) or readelf
tool to read these. Those tools should be included with your toolchain.
Basically, you're looking to add up the size all the loadable sections, such as .text
and .data
. Look for the LOAD
flag in the output from objdump
, for example.
You can ignore non-loadable sections such as .comment
, .debug
and .bss
· Some of those are there for the benefit of the debugger, for example, and some are just placeholders for memory that will be used by the program at run time, but contains no pre-existing data.
When I say "add up the size", that's not strictly true; the linker will have already allocated each section to a specific address in flash (I'm assuming your program will run directly from ROM), so you need to find the end-address of the last section to determine how much is left.
Upvotes: 2