3
votes

I'm trying to build my own toolchain for an Raspberry-Pi. I know there are plenty of prebuilt Toolchains. This work is for educational reasons. I'm following the embedded arm linux from scratch book. And succeeded in building a gcc and uClib so far. I'm building for the target arm-unknown-linux-eabi.

Now that it comes to preparing a bootable filesystem i'm questioning myself about the bootloader build.

The part about the bootloader for this System seems to be incomplete. Now I'm questioning myself how do I build a uboot for this System with my arm-unknown-linux-eabi toolchain.

Do I need to build a toolchain which doesn't depend on linux kernel calls. My first reasearch lead me to the point that there are separate kind of tool chain the OS dependent (linux kernel sys-calls etc...) and the ones which don't need to have a kernel underneath. Sometimes refered to as "Bare-Metal" toolchain or "standalone" toolchain.

Some sources mention that it would be possible to build an U-Boot with the linux toolchain. If this is true why and how should this work?

And if I have to build a second toolchain for "Bare Metal" Toolchain where can I find informations about the difference between these two. Do I need another libstdc?

2
You could have tried the Buildroot script. I believe there are one or two config files on the web for the RPI.sawdust

2 Answers

2
votes

You can built U-Boot with the same cross-toolchain used to build the kernel - and most probably the rest of the user-space of the system.

A bootloader is - by definition - self-contained and doesn't care about your choice of C-runtime library because it doesn't use it. Therefore the issue of sys-calls doesn't come into it.

A toolchain is always going to need to be hosted by a fully functioning development system - invariably not your target system. Whatever references you see to a 'bare-metal toolchain' are not referring to the compiler's use of sys-calls (it relies heavily on the operating system for I/O). What is important when building bootloaders and kernels is that compiler and linker are configured to produce statically linked code that can run at specific memory address.

1
votes

In almost all possible ways, there is no difference between the embedded and the Linux toolchain. But there is one exception.

That exception is __clear_cache - a function that can be generated by the compiler and in a "Linux"-toolchain includes a system call to synchronize instruction and data caches. (See http://blogs.arm.com/software-enablement/141-caches-and-self-modifying-code/ for more information about that bit.)

Now, unless you explicitly add a call to that function, the only way I know for it to be invoked is by writing nested functions in C (a GCC extension that should be avoided). But it is a difference.