Tutorial :GCC, ARMboot - Creating standalone application without any library and any OS



Question:

I have an embedded hardware system which contains a bootloader based on ARMboot (which is very similar to Uboot and PPCboot).

This bootloader normally serves to load uClinux image from the flash. However, now I am trying to use this bootloader to run a standalone helloworld application, which does not require any linked library. Actually, it contains only while(1){} code in the main function.

My problem is that I cannot find out what GCC settings should I use in order to build a standalone properly formatted binary.

I do use following build command:

cr16-elf-gcc -o helloworld helloworld.c -nostdlib  

which produces warning message:
warning: cannot find entry symbol _start; defaulting to 00000004

Thereafter, within the bootloader, I upload a produced application and start it at some address:

tftpboot 0xa00000 helloworld  go 0xa00004  

But it doesn't work :( The system reboots.

Normally it should just hang (because of while(1)).


Solution:1

I don't know that loader, but I think you should use objcopy like this to dump your executable data to a raw binary file. Don't jump to ELF headers, people :)

objcopy -O binary ./a.out o.bin  

Also try to compile position independent code and to read ld and gcc manuals.


Solution:2

The linker is complaining about missing startup code.

You need to provide two things: startup code and a linker command file that defines the address map of your target processor.

In your case the startup code is as "bl main", but usually the startup code will initialize the stack pointer at least before branching to main.

If you know you are loading your example into RAM, you can start your program at main directly. You'll need to determine main()'s address ate use that for your "go" command.


Solution:3

I operate on the ARM non-os non-lib all day every day. This is my current gcc options:

arm-whatever-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -c hello.c -o hello.o

then I use the linker to combine the C code with the vector tables and such, even if it is not an image that needs a vector table using a vector table makes it easy to put your entry point on the first instruction.


Solution:4

Any reason you can't statically link at least the standard libraries in? You should have a working program and the benefits of the standard libraries without external dependencies.

Also, does your toolchain/IDE provide differentiate between "standalone application" and "linux application"? The IDE for the AVR32 has that distinction and is able to generate either a program that runs within the embedded linux environment or a standalone program that basically becomes the OS.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »