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++
12612 Discussions

Size of RAM needed to store NiosII code

Altera_Forum
Honored Contributor II
3,090 Views

Hi, 

 

I'm currently working on porting a project from an Altera Dev Board (Nios II Embedded Evaluation Kit, Cyclone III Edition) to a self-designed PCB board.  

 

Currently, I have some code for Nios II stored in the 1 Mbyte SRAM on the Dev Board, however, I think 1Mbyte is too much for storing the Nios II code in this project, and would like to look for an SRAM with smaller capacity (cheaper) while moving to the self-designed PCB .  

 

So I would like to ask how to determine what is the size of the Nios II code?  

 

I notice while running the code on Nios II, the Console in the IDE shows the following: 

 

 

--- Quote Start ---  

 

Downloading 00400000 ( 0%) 

Downloading 00406F4C (76%) 

Downloaded 61kb in 0.4s (70.0KB/s) 

 

--- Quote End ---  

Does it mean that 61kb is the total size of the code, and I can safely use any SRAM larger than this size? 

 

Thanks for any answer. :)
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
1,181 Views

You can use nios2-elf-size from command shell to get information about memory usage. 

For more detailed information about memory sections, use nios2-elf-objdump with -h switch. 

 

This will tell you the minimal memory required now. The actual ram size choice should be based on how much headroom you want for possibly implementing new features in the future.
0 Kudos
Altera_Forum
Honored Contributor II
1,181 Views

Don't forget to allow for the stack and heap.

0 Kudos
Altera_Forum
Honored Contributor II
1,181 Views

Thanks for the answer and advice: 

 

--- Quote Start ---  

This will tell you the minimal memory required now. The actual ram size choice should be based on how much headroom you want for possibly implementing new features in the future. 

--- Quote End ---  

I tried : 

nios2-elf-size test_sram.elfresult: 

text data bss dec hex filename 21764 6728 736 29228 722c test_sram.elfHowever, I do not understand the result,  

 

  • what does "bss" stands for? 

 

 

  • what are the units of the numbers indicated, bits, bytes? 

 

I tried searching through command line document but there's no explanation included. (I can't post link of the document)
0 Kudos
Altera_Forum
Honored Contributor II
1,181 Views

http://en.wikipedia.org/wiki/.bss 

bss (Block Started Symbol) section contains uninitialized data, i.e. elements not  

initialized by the program which are set to zero before the process executes.  

Some linkers include bss in the data section which instead contains all other data required by the program, both read only and read&write data. 

 

Numbers are in bytes. As dsl remarked, you must add the stack/heap size: usually these are located in the remaining memory after the bss/data/text sections: stack grows from higher address backward; heap grows forward on the other side from lower addresses.
0 Kudos
Altera_Forum
Honored Contributor II
1,181 Views

Thanks for the replies.  

 

I'm still rather confuse with different elf file size reported in various places. 

 

When I use the command line: nios2-elf-size test_sram.elf 

Result: 29228Bytes = 29KB text data bss dec hex filename 21764 6728 736 29228 722c test_sram.elfWhen I checked the file size of the .elf file using window explorer 

 

 

--- Quote Start ---  

Result: 257KB 

--- Quote End ---  

Which should I refer to while estimating the size of the SRAM for this current application? 

 

Regarding the stack and heap, I tried:nios2-stackreport 

Result:  

 

 

--- Quote Start ---  

Info: (test_sram.elf) 28 KBytes program size (code + initialized data) 

Info: 4060 Bytes free for stack + heap. 

--- Quote End ---  

Does this mean that I need an SRAM with minimum size of = 

 

(4060KBytes + (size of elf which i'm still confused with) ) ? 

 

The code I'm trying with contains merely a printf of a Hello World, isnt 4MBytes a little too much for that?
0 Kudos
Altera_Forum
Honored Contributor II
1,181 Views

The windows 'explorer' gives you the file size - this includes a lot of stuff that isn't loaded (symbol tables, debug info, etc). 

'nios2-elf-size -A test_sram.elf' will give you the sizes of all the sections, butthe output from 'objdump -p' (program sections - for loader) and 'objdump -h' (elf sections) is normally more use. 

 

I suspect the heap size you have is the configured size, not the size used.
0 Kudos
Altera_Forum
Honored Contributor II
1,181 Views

Thanks dsl, the window explorer file size indeed includes a lot of stuff that isn't loaded. 

 

As for the stack and heap, 

 

I did a test by comparing the size of the program with 2 different hardware build in SOPC, one with on-chip memory and another with sram

 

http://i446.photobucket.com/albums/qq183/ahhbeng/SRAMonchip.png  

 

I believe the stack+heap reported here indicates the free space available on the memory, so on-chip memory version reports 12KB, while sram version reports much larger free space, 4060KB.
0 Kudos
Altera_Forum
Honored Contributor II
1,181 Views

Add the values together and compare against the size of the available memory block! 

 

17k + 12k = 29k I suspect that is a 32k on-chip memory block 

28k + 4060k = 4088k Looks like 4MB (4096k) 

The other few k is probably bss and other pad space. 

(The standard linker script probably puts a gap between the code and data for mmu page permissions)
0 Kudos
Reply