BareMetal environment

Table of Contents

none-eabi gcc

https://stackoverflow.com/questions/38956680/difference-between-arm-none-eabi-and-arm-linux-gnueabi/38989869#38989869

The bare-metal ABI will assume a different C library (newlib for example, or even no C library) to the Linux ABI (which assumes glibc). Therefore, the compiler may make different function calls depending on what it believes is available above and beyond the Standard C library.

gcc flags

-ffreestanding

gcc docs

Assert that compilation targets a freestanding environment. This implies -fno-builtin. A freestanding environment is one in which the standard library may not exist, and program startup may not necessarily be at main. The most obvious example is an OS kernel. This is equivalent to -fno-hosted.

See Language Standards Supported by GCC, for details of freestanding and hosted environments.

这个选项告诉gcc,目标系统上可能没有标准库的实现,比如libc库.

-specs=nosys.specs

gcc docs
这个选项告诉gcc,读取nosys.specs这个文件来获得编译参数
https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/Spec-Files.html#Spec-Files

/usr/aarch64-none-elf/lib/nosys.specs

%rename link_gcc_c_sequence                nosys_link_gcc_c_sequence

*nosys_libgloss:
-lnosys

*nosys_libc:
%{!specs=nano.specs:-lc} %{specs=nano.specs:-lc_nano}

*link_gcc_c_sequence:
%(nosys_link_gcc_c_sequence) --start-group %G %(nosys_libc) %(nosys_libgloss) --end-group

libc

baremetal中,也可以选择多种不通的libc实现,比较常用的有newlib和nanolibc这两种
newlib vs nanolibc

newlib

  • build

    mkdir build
    cd build
    ../configure --target=aarch64-none-elf --prefix=$(pwd)
    make -j8
    make install
    

refs

Footnotes:

Contact me via :)
虚怀乃若谷,水深则流缓。