ARM环境下的裸机开发

目前,我正在学习做ARM裸机开发。 我使用的开发板是SAMA5D3x-EK。

我正在尝试构buildAtmel给出的示例代码(Atmel / sama5d3x-ek / examples / getting-started)。

IDE

eclipse with GNU ARM plugin 

链接器脚本

 Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/resources/gcc/sama5d3x/sram.ld 

启动代码

 Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/source/board_cstartup_gnu.S 

c运行时库存根

 Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/source/syscalls.c 

我已经build立了libboard_sama5d3x_ek_gcc_dbg.a 。 而且我非常确定所有的存根函数都被封装到.a静态库中。

  $ arm-none-eabi-nm libboard_sama5d3x_ek_gcc_dbg.a ... syscalls.o: 00000000 T _close U DBGU_PutChar 00000000 T _exit 00000000 T _fstat 00000000 T _getpid U _heap 00000000 b heap.9035 U iprintf 00000000 T _isatty 00000000 T _kill 00000000 r .LC0 00000000 T link 00000000 T _lseek 00000000 T _read 00000000 T _sbrk 00000000 T _write ... 

但是,当我尝试构build项目时,链接器部分出现以下错误:

 Building target: arm_sama5d3x_baremetal_template.elf Invoking: Cross ARM C Linker arm-none-eabi-gcc -mcpu=cortex-a5 -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=vfpv4-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -g3 -T "/home/yusheng/workspace/arm_sama5d3x_baremetal_template/sram.ld" -nostartfiles -Xlinker --gc-sections -L/usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib -L/usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib -Wl,-Map,"arm_sama5d3x_baremetal_template.map" -v -static -o "arm_sama5d3x_baremetal_template.elf" ./board_cstartup_gnu.o ./main.o /usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib/libboard_sama5d3x_ek_gcc_dbg.a /usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib/libchip_sama5d3x_gcc_dbg.a -lboard_sama5d3x_ek_gcc_dbg -lchip_sama5d3x_gcc_dbg Using built-in specs. COLLECT_GCC=arm-none-eabi-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-none-eabi/4.8.2/lto-wrapper Target: arm-none-eabi Configured with: ../gcc-4.8.2/configure --build=i686-linux-gnu --prefix=/usr --includedir='/usr/lib/include' --mandir='/usr/lib/share/man' --infodir='/usr/lib/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/lib/gcc-arm-none-eabi' --disable-maintainer-mode --disable-dependency-tracking --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/doc/gcc-arm-none-eabi/info --mandir=/usr/share/man --htmldir=/usr/share/doc/gcc-arm-none-eabi/html --pdfdir=/usr/share/doc/gcc-arm-none-eabi/pdf --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --with-system-zlib --enable-multilib --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-libstdc++-v3 --disable-nls --disable-shared --disable-threads --disable-tls --disable-plugin --build=i686-linux-gnu --host=i686-linux-gnu --target=arm-none-eabi --with-gnu-as --with-gnu-ld --with-headers=no --without-newlib --with-pkgversion=4.8.2-14ubuntu1+6 --without-included-gettext --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r CFLAGS='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat' CPPFLAGS=-D_FORTIFY_SOURCE=2 CXXFLAGS='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat' FFLAGS='-g -O2' LDFLAGS=-Wl,-z,relro AR_FOR_TARGET=arm-none-eabi-ar AS_FOR_TARGET=arm-none-eabi-as LD_FOR_TARGET=arm-none-eabi-ld NM_FOR_TARGET=arm-none-eabi-nm OBJDUMP_FOR_TARGET=arm-none-eabi-objdump RANLIB_FOR_TARGET=arm-none-eabi-ranlib READELF_FOR_TARGET=arm-none-eabi-readelf STRIP_FOR_TARGET=arm-none-eabi-strip Thread model: single gcc version 4.8.2 (4.8.2-14ubuntu1+6) COMPILER_PATH=/usr/lib/gcc/arm-none-eabi/4.8.2/:/usr/lib/gcc/arm-none-eabi/4.8.2/:/usr/lib/gcc/arm-none-eabi/:/usr/lib/gcc/arm-none-eabi/4.8.2/:/usr/lib/gcc/arm-none-eabi/:/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/bin/ LIBRARY_PATH=/usr/lib/gcc/arm-none-eabi/4.8.2/armv7-ar/thumb/fpu/:/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/:/usr/lib/gcc/arm-none-eabi/4.8.2/:/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/ COLLECT_GCC_OPTIONS='-mcpu=cortex-a5' '-march=armv7-a' '-marm' '-mthumb-interwork' '-mfloat-abi=hard' '-mfpu=vfpv4-d16' '-O0' '-fmessage-length=0' '-fsigned-char' '-ffunction-sections' '-fdata-sections' '-g3' '-T' '/home/yusheng/workspace/arm_sama5d3x_baremetal_template/sram.ld' '-nostartfiles' '-L/usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib' '-L/usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib' '-v' '-static' '-o' 'arm_sama5d3x_baremetal_template.elf' /usr/lib/gcc/arm-none-eabi/4.8.2/collect2 -Bstatic -X -o arm_sama5d3x_baremetal_template.elf -L/usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib -L/usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib -L/usr/lib/gcc/arm-none-eabi/4.8.2/armv7-ar/thumb/fpu -L/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu -L/usr/lib/gcc/arm-none-eabi/4.8.2 -L/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib --gc-sections -Map arm_sama5d3x_baremetal_template.map ./board_cstartup_gnu.o ./main.o /usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib/libboard_sama5d3x_ek_gcc_dbg.a /usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib/libchip_sama5d3x_gcc_dbg.a -lboard_sama5d3x_ek_gcc_dbg -lchip_sama5d3x_gcc_dbg --start-group -lgcc -lg -lc --end-group -T /home/yusheng/workspace/arm_sama5d3x_baremetal_template/sram.ld /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-init.o): In function `__libc_init_array': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/misc/../../../../../../../../newlib/libc/misc/init.c:37: undefined reference to `_init' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-abort.o): In function `abort': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/stdlib/../../../../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-sbrkr.o): In function `_sbrk_r': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/sbrkr.c:58: undefined reference to `_sbrk' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-signalr.o): In function `_kill_r': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-signalr.o): In function `_getpid_r': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/signalr.c:96: undefined reference to `_getpid' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-writer.o): In function `_write_r': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/writer.c:58: undefined reference to `_write' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-closer.o): In function `_close_r': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/closer.c:53: undefined reference to `_close' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-fstatr.o): In function `_fstat_r': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `_fstat' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-isattyr.o): In function `_isatty_r': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/isattyr.c:58: undefined reference to `_isatty' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-lseekr.o): In function `_lseek_r': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to `_lseek' /usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-readr.o): In function `_read_r': /build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/readr.c:58: undefined reference to `_read' collect2: error: ld returned 1 exit status make: *** [arm_sama5d3x_baremetal_template.elf] Error 1 

该错误声称存根函数不能find,但function在静态库,我已经添加到项目。

如果有人能给我一些build议,我将不胜感激。 谢谢。

编辑1

@Valeri Atamaniouk /usr/lib/gcc/arm-none-eabi/4.8.2/collect2命令的选项是由eclipse生成的。 我不知道如何改变这个静态链接顺序。

同样在选项列表中给出,链接顺序如下:

 ./board_cstartup_gnu.o ./main.o /usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib/libboard_sama5d3x_ek_gcc_dbg.a /usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib/libchip_sama5d3x_gcc_dbg.a -lboard_sama5d3x_ek_gcc_dbg -lchip_sama5d3x_gcc_dbg --start-group -lgcc -lg -lc --end-group 

在这里,我不知道newlib库在哪里。假设newlib库被称为“ -lgcc -lg -lc ”,我们应该看到上面那个libboard_sama5d3x_ek_gcc_dbg.a在它们之前。

我有一个解决方法。 重build不包含syscalls.cboard_cstartup_gnu.S的静态库。 然后复制源文件并将其包含到项目中。 虽然解决方法的工作原理,我想了解问题来自哪里,以及正确的方法是解决这个问题。

把你的图书馆放在--start-group--end-group标签之间。 很有可能你有一个案例,当不同的图书馆彼此参照时,图书馆组是如何解决的。

你可以尝试在你的命令行(一次一个)下面的两个标志这将解决未解决的初始化问题。

 -Xlinker --specs=nosys.specs -Xlinker --specs=rdimon.specs 

剩下的问题与-Xlinker -start-group和-Xlinker -end-group在库加目标文件之前和之后有关(如前所述)

PS:我希望这能解决你的问题