Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12589 Discussions

how to check the NIOSII code footprint size

Altera_Forum
Honored Contributor II
1,092 Views

Dear All, 

what's the best way in SBT 11.0 to analyze NIOSII program memory size? 

Thanks a lot, all.
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
359 Views

Depends to some extent on what you are tryign to find out. 

The actual sizes of the code/data sections can be found by running 'objdump' on the object and program files. 

The symbol table will give some idea as to the size of each function, and the included functions. 

If you want to know why some functions are included from a library (eg libc) the linker map file will tell you (if generated, and with appropriate linker options).
0 Kudos
Altera_Forum
Honored Contributor II
359 Views

Thanks dsl, I will take some time to uderstand objdump. 

At first I'm interested in memory occupation to be sure I can fit in on-chip memories, then I would like to investigate which optimization can be done.
0 Kudos
Altera_Forum
Honored Contributor II
359 Views

Assuming that the sections fit statically you should still evaluate if there is enough room for the stack and heap which grow and shrink at run time. I try to avoid using the heap if I can when possible (malloc allocates memory from the heap for example) since it's pretty difficult to determine what the maximum memory utilization is during run time. 

 

If the stack or heap grow too much they'll collide and corrupt eachother. There are tests you can do to detect these like pre-populating your memory with 0xdeadbeef for example, running your code, then inspecting the memory to see if that pattern is still present where the heap and stack are located. If the pattern doesn't appear then the stack and heap either collided or touched. This test isn't perfect since it assumes during the run time of your code it reached it's maximum memory utilization which might not be true depending on outside factors. 

 

If you want to reduce your code footprint, take a look at the hello_world_small software template. It'll show you a limited stdio library and optimizations you can use.
0 Kudos
Altera_Forum
Honored Contributor II
359 Views

If you need to fit code into internal memory, it is probably best to avoid as much of libc as possible. The hello_world_small template does some of that - but, IIRC, it still has sizable chunks of libc code. 

 

If you can remove all references to malloc() and free() things will be much safer! but that may require you write your own startup code (about 4 instructions!) and may stop you using any of the jtag uart functions or most of the Altera hardware drivers.
0 Kudos
Reply