gpt4 book ai didi

c - Linux环境下的ARM裸机开发

转载 作者:太空狗 更新时间:2023-10-29 11:21:59 26 4
gpt4 key购买 nike

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

我正在尝试构建 Atmel 提供的示例代码 (Atmel/sama5d3x-ek/examples/getting-started)。

开发环境

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 运行时库 stub

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

我已经构建了 libboard_sama5d3x_ek_gcc_dbg.a。而且我非常确定所有 stub 函数都已打包到 .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
...

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

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

错误提示找不到 stub 函数,而这些函数在我已经添加到项目中的静态库中。

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

编辑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 排在他们前面。

我有一个解决方法。重建静态库,不包括 syscalls.cboard_cstartup_gnu.S。然后将源文件复制并包含到项目中。虽然解决方法有效,但我想了解问题出在哪里,以及解决此问题的正确方法是什么。

最佳答案

将您的库放在 --start-group--end-group 标签之间。很可能你有这样的情况,当不同的库相互引用时,库组是如何解决的。

关于c - Linux环境下的ARM裸机开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28507762/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com