arm - 如何为arm gcc构建mbedtls

标签 arm stm32 freertos mbedtls

我想在我的 stm32 项目中使用 mbedtls,但在构建时遇到一些问题。 我必须使用arm-none-gcc编译器构建mbedtls,对吧? 我的命令是:(在构建目录中)。

CC=/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc CFLAGS='-fstack-protector-strong' cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On ../

编译测试程序时出现错误:

none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc CFLAGS='-fstack-protector-strong' cmake - 
DUSE_SHARED_MBEDTLS_LIBRARY=On ../
-- The C compiler identification is GNU 10.2.1
-- Check for working C compiler: 
/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc
-- Check for working C compiler: 
/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler

"/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /home/jareeeeczek/Arczbit/Projects/Parkometr/software/FreeRtos/FreeRTOS- 
Plus/ThirdParty/mbedtls/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_47d0a/fast && /usr/bin/make -f 
CMakeFiles/cmTC_47d0a.dir/build.make CMakeFiles/cmTC_47d0a.dir/build
make[1]: Entering directory 
'/home/jareeeeczek/Arczbit/Projects/Parkometr/software/FreeRtos/FreeRTOS- 
Plus/ThirdParty/mbedtls/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_47d0a.dir/testCCompiler.c.o
/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc   -fstack-protector-strong    -o 
CMakeFiles/cmTC_47d0a.dir/testCCompiler.c.o   -c 
/home/jareeeeczek/Arczbit/Projects/Parkometr/software/FreeRtos/FreeRTOS- 
Plus/ThirdParty/mbedtls/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_47d0a
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_47d0a.dir/link.txt --verbose=1
/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc -fstack-protector-strong     -rdynamic 
CMakeFiles/cmTC_47d0a.dir/testCCompiler.c.o  -o cmTC_47d0a 
arm-none-eabi-gcc: error: unrecognized command-line option '-rdynamic'
make[1]: *** [CMakeFiles/cmTC_47d0a.dir/build.make:87: cmTC_47d0a] Error 1
make[1]: Leaving directory 
'/home/jareeeeczek/Arczbit/Projects/Parkometr/software/FreeRtos/FreeRTOS  - 
Plus/ThirdParty/mbedtls/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_47d0a/fast] Error 2

有人知道为什么 cmake 在编译测试程序时出现问题吗?

最佳答案

我认为您没有配置mbedtls,以便为裸机系统构建它。一些默认选项需要禁用,因为您的目标不是通用操作系统:(没有文件系统,因此标准 BSD 套接字接口(interface),...)。

这就是为什么您无法编译测试程序的原因,以及为什么您需要通过在 cmake 构建命令中指定 -DENABLE_TESTING=OFF 来禁用它们的编译。

请参阅 mbedtls-2.25.0/include/mbedtls/config.h 中的大量有用注释,以获取有关各种可用配置选项的更多详细信息。

下文描述的过程确实有效,您应该能够通过使用它作为工作示例来修改您自己的构建过程。

toochain.cmake:

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR armv7-m)
set(CMAKE_STAGING_PREFIX /tmp/staging)
set(CMAKE_C_COMPILER /opt/arm/10/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER /opt/arm/10/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-g++)
set(CMAKE_MAKE_PROGRAM=/usr/bin/make)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_C_FLAGS=-mtune=cortex-m3)
set(CMAKE_EXE_LINKER_FLAGS " --specs=nosys.specs")

构建过程:

# extracting
tar zxf v2.25.0.tar.gz

# modifying default configuration using config.py:
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h set MBEDTLS_NO_PLATFORM_ENTROPY 1
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_FS_IO
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_PSA_CRYPTO_STORAGE_C
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_TIMING_C
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_NET_C
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_PSA_CRYPTO_CONFIG
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_PSA_ITS_FILE_C

# building:
mkdir mbedtls
pushd mbedtls
cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON -DENABLE_ZLIB_SUPPORT=OFF -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake ../mbedtls-2.25.0
make all install
popd

tree /tmp/staging
/tmp/staging
├── include
│   ├── mbedtls
│   │   ├── aes.h
│   │   ├── aesni.h
│   │   ├── arc4.h
│   │   ├── aria.h
│   │   ├── asn1.h
│   │   ├── asn1write.h
│   │   ├── base64.h
│   │   ├── bignum.h
│   │   ├── blowfish.h
│   │   ├── bn_mul.h
│   │   ├── camellia.h
│   │   ├── ccm.h
│   │   ├── certs.h
│   │   ├── chacha20.h
│   │   ├── chachapoly.h
│   │   ├── check_config.h
│   │   ├── cipher.h
│   │   ├── cipher_internal.h
│   │   ├── cmac.h
│   │   ├── compat-1.3.h
│   │   ├── config.h
│   │   ├── config_psa.h
│   │   ├── ctr_drbg.h
│   │   ├── debug.h
│   │   ├── des.h
│   │   ├── dhm.h
│   │   ├── ecdh.h
│   │   ├── ecdsa.h
│   │   ├── ecjpake.h
│   │   ├── ecp.h
│   │   ├── ecp_internal.h
│   │   ├── entropy.h
│   │   ├── entropy_poll.h
│   │   ├── error.h
│   │   ├── gcm.h
│   │   ├── havege.h
│   │   ├── hkdf.h
│   │   ├── hmac_drbg.h
│   │   ├── md2.h
│   │   ├── md4.h
│   │   ├── md5.h
│   │   ├── md.h
│   │   ├── md_internal.h
│   │   ├── memory_buffer_alloc.h
│   │   ├── net.h
│   │   ├── net_sockets.h
│   │   ├── nist_kw.h
│   │   ├── oid.h
│   │   ├── padlock.h
│   │   ├── pem.h
│   │   ├── pkcs11.h
│   │   ├── pkcs12.h
│   │   ├── pkcs5.h
│   │   ├── pk.h
│   │   ├── pk_internal.h
│   │   ├── platform.h
│   │   ├── platform_time.h
│   │   ├── platform_util.h
│   │   ├── poly1305.h
│   │   ├── psa_util.h
│   │   ├── ripemd160.h
│   │   ├── rsa.h
│   │   ├── rsa_internal.h
│   │   ├── sha1.h
│   │   ├── sha256.h
│   │   ├── sha512.h
│   │   ├── ssl_cache.h
│   │   ├── ssl_ciphersuites.h
│   │   ├── ssl_cookie.h
│   │   ├── ssl.h
│   │   ├── ssl_internal.h
│   │   ├── ssl_ticket.h
│   │   ├── threading.h
│   │   ├── timing.h
│   │   ├── version.h
│   │   ├── x509_crl.h
│   │   ├── x509_crt.h
│   │   ├── x509_csr.h
│   │   ├── x509.h
│   │   └── xtea.h
│   └── psa
│       ├── crypto_accel_driver.h
│       ├── crypto_compat.h
│       ├── crypto_config.h
│       ├── crypto_driver_common.h
│       ├── crypto_entropy_driver.h
│       ├── crypto_extra.h
│       ├── crypto.h
│       ├── crypto_platform.h
│       ├── crypto_se_driver.h
│       ├── crypto_sizes.h
│       ├── crypto_struct.h
│       ├── crypto_types.h
│       └── crypto_values.h
└── lib
    ├── libmbedcrypto.a
    ├── libmbedtls.a
    └── libmbedx509.a

4 directories, 96 files

关于arm - 如何为arm gcc构建mbedtls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67122299/

相关文章:

c - STM32H743 nucleo 板,在轮询模式下同时使用 3 个 ADC(一次 1 个 ADC);不起作用

我可以/应该通过单个指针访问多个设备寄存器吗?

usb - STM32 USB CDC的最高速度是多少?

real-time - 如何使用freertos实时发送数据

arm - Raspberry Pi 1 和 2 中 ARM11 和 Cortex-A7 内核的每个周期峰值 FLOPs

c - 在适用于 ARM Cortex M4f 的 Code Composer studio 中将堆栈指针的值保存在 C 变量中

linux - 无法使用 libcurl(为 arm 交叉编译)应用程序发送电子邮件

node.js - npm -v 和 node.js 在交叉编译的 nodejs0.12.2 上抛出非法指令

c - STM32 - FreeRTOS xQueue 接收不完整的数组

c - FreeRTOS:为什么我的任务在调用 vTaskStartScheduler 后没有开始?