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

Nios without SystemLibrary

Altera_Forum
Honored Contributor II
1,523 Views

Hi, 

 

I am working for a shool projet on Nios II. I was wondering if it was possible to compile and link a program for Nios II without using the SystemLibrary at all. Meaning make the smallest programm possible for Nios 2. 

 

Thanks for you help, 

Sylvain
0 Kudos
11 Replies
Altera_Forum
Honored Contributor II
474 Views

Hi Sylvain 

 

> I was wondering if it was possible to compile and link a program for Nios II 

> without using the SystemLibrary at all 

 

Sure can. You can hoist some init code from the system library itself ... or from 

u-boot. But you might want to stick with the system library ... especially if 

your time is limited ... and you want a good grade :-) 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Why ditch the system library? There are options/examples in the Nios II kit to make your software quite small.  

 

If you do go without the system library you'll have to re-invent the wheel in several places where we've already written/optimzed the code for you.. for example, in the crt0 code executed at reset-time to initialize the caches. 

 

If you want the smallest possible executable code try the following: 

 

- Check out the "Hello Freestanding" Example in the IDE. This example shows commented-source-code showing how to use a system that starts in alt_main() and explains what the system library does before calling main() conventionally. This still uses a system library, but gives you more precise control over what code executes at startup. The only "lower level" you can go from there is to edit the crt0.S code for Nios II, which is physically what is executed at reset. 

 

- Check out the "Hello World Small" Example in the IDE. This example is more pre-fabricated, usin GUI options in the IDE to automatically configure the system library to be as small as possible. 

 

Both examples yield a hello-world of about the same size.. 3k or so if I remember correctly.
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Just out of curiosity, what development board are you using? Did you roll your own or did you buy an off the shelf board? Rumor has it the the Altera University Program is about to release thier UP3 (university program) board. It will have a Cyclone 1C12 on it. I ran some test cases with Quartus/SOPC builder and found that you can get a NIOS2f with 16K of internal program RAM, 4K of internal data/stack RAM, 512 Icache, and 512 Dcache. The 16K of program RAM should be plenty for a school project as long as you don't need the full blown printf stuff. I did a pinewood car timer using a 1C3 (4K program RAM), but had to stick with the SDK because of code size. The SDK seems to be 10-20% smaller for some reason. I'm not recomending using it though. I had to because of the 1C3. Anyone know when the UP3 is available? My local Altera distributor could only say it wasn't availble yet. 

 

Have Phun http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/tongue.gif , 

Rick
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Hi thanks for your answer, 

 

 

 

Actually I was asked to present the project with full asssembly program for Nios II, and without linking SystemLib. 

 

I believe it&#39;s a pain, since all interruption layer is defined there (alt_exception, init with crt0, and all others..). In the other hand, the program would be much smaller, and the Nios would boot much faster, so it&#39;s interesting. 

 

Since a multi-core platform sustain the code, one Nios can keep a SystemLib, whereas the second one can run an optimize way. So I think it makes sense.  

 

I just checked out hello_alt_main.c (Free Standing version), It can be interesting (maybe a compromise between full systemLib and no systemlib). 

 

Now I am writing the assembly program for the no-system-lib Nios, so still busy. But I am trying to find out a way not to use that SystemLib. If I want to remove the sysLib, Do you think I should make a copy of the linking script, and just put everything I need to link inside?? 

 

(Rick> Im using a small fpga, Stratix1-F780C6.. I think it&#39;s a 10k gates , I am not following news about up3 sorry ) 

 

Sylvain  

(who hopes to get a good grade for his last year project )
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Hi, 

 

projet&#39;s almost over, but I still have a problem: 

 

I wanted to linked without system library, I can do it providing an empty syslib, but code still link with altera device driver from Nios II. specially with crt0.s file that I would like to modify. 

 

But I dont want to touch to altera drivers. (cause I have some other system library that&#39;s actually need altera drivers). 

 

Do you if it&#39;s possible not to link with that?? 

 

thanks for your help, 

Sylvain
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

slvn, 

 

If avoiding the system lib is important to you, You can just grab the 

u-boot code & tear out all but the basics. It does not use the system 

library, has its own linker script, init, and has the exception code 

you can hack as you like. 

 

If nothing else, you might find the linker script and init handy. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

I agree. Trying to recreate the functionality that the system library provides is no small task. Refer to the code that Scott suggested since it&#39;ll point you in the right path (most of us haven&#39;t tried doing what you are attempting). 

 

This isn&#39;t constructive, but I have a question: Why have you been asked to do this from scratch? Did you offend your professor or something and this is the payback? 

 

Good-luck
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Hi, 

 

actually code "helloworld steady" is far to high http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif I want to skip crt0.s and every thing else. I already got rid of exception and interruptions stuff modyfiying linker script. 

 

I read altera low levels and there are no that complex to rewrite it.  

My teacher likes crazy projet and I am instered also in the subject. Since it&#39;s my last projet before graduating ( 10 days left lol). so I&#39;d better not miss it :/ 

Project is actually to use multicore Nios II plaforme, booting from scratch and doing a kind of task scheduler. so it&#39;s fun 

 

Actually my code is done, compiles and work well for the scheduler. I am trying now to boot from scratch, but linking is not good because of altera drivers, and sections that overlaps. 

 

I think it should work if altera is not linked, so I could do it by modifying makefiles, but that gonna screw up all libraries (device and other syslib)...maybe I can juste add so test case in the makefiles.. 

 

 

I think there are some people of altera here, if they can help there are welcome http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

 

Sylvain
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

hi, 

 

for those who are interested, I think i found out a way... 

Each Nios II device has a specific makefile called component.mk 

not to has a syslib i equivalent not to compile those components (actually Nios II and Hal ) 

so I just put a ifned CPU = MyCpu ...then I can create a much lighter syslib. 

 

I have also been able to rewrite crt0 a lighter way and exception sytem. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

 

Sylvain
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Sylvain, 

 

We&#39;re always interested to hear about potential improvements, and would be very interested to know how much you have saved in your re-write of crt0 and the exception system. Details of your re-write would be of interest to us. If you would not mind can you please post this information.
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Hi, 

 

I can&#39;t get you a precise description now ( code is still a school). 

But, my configuration just allows to get rid of standard code. 

 

crt0.s doesn&#39;t change much (I can skip some test and stuf, maybe some jump, and also probable the clear cache, and clear BSS). ( I am using only ASM so dont need BSS) 

 

exception.s should be much faster because everythiing is removed. In face, irq is kind of equivalient to a jump to the begining .irq section (or maybe .exception dont remember..) 

A few month ago I did a test and there was like 12 cycles between irq appearing on avalon bus and the beginning of the section.. meaning 12 cycle for the jump. But there were like 250 cycles between irq appearing and the beginning on the user handler. (so 240 cycle just for altera cycle). So I guess for high constraint works, they are lot of cycles to save. 

 

In my modification I put some very specific into the irq section in order to do a scheduler. I am losing most of altera features that I guess most of people would benefit of. 

 

Sylvain
0 Kudos
Reply