imx8mm除了支持4个Cortex-A53还带1个Cortex-M4核,运行频率高达400MHz,本文需要在Cortex-M4核运行裸机程序或者系统。
运行官方bin文件
u-boot=> tftp 0x7e0000 imx8mm_m4_TCM_hello_world.bin Using ethernet@30be0000 deviceTFTP from server 192.168.1.99; our IP address is 192.168.1.55Filename 'imx8mm_m4_TCM_hello_world.bin'.Load address: 0x7e0000Loading: #617.2 KiB/sdoneBytes transferred = 6320 (18b0 hex)u-boot=> u-boot=> bootaux 0x7e0000## Starting auxiliary core at 0x007E0000 ...
Cortex-M4串口打印:
hello world.
下载NXP官方SDK
SDK_2.5.0_EVK-MIMX8MM
安装交叉编译链
NXP官方编译链:gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu
aarch64-linux-gnu-gcc -v
gcc version 7.4.1 20181213 [linaro-7.4-2019.02 revision 56ec6f6b99cc167ff0c2f8e1a2eed33b1edc85d4] (Linaro GCC 7.4-2019.02)
设置环境变量:
export ARMGCC_DIR="/home/logread/imx8m-mini/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu"
export PATH=$PATH:/home/logread/imx8m-mini/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin
编译demo
进入目录:SDK_2.5.0_EVK-MIMX8MM/boards/evkmimx8mm/demo_apps/hello_world/armgcc
修改gcc:修改arm-none-eabi为aarch64-linux-gnu
SDK_2.5.0_EVK-MIMX8MM/tools/cmake_toolchain_files/armgcc.cmake +24
否则会报下面错误:
提示下面错误:
需要注释下面的参数:
还是会编译.s汇编文件的thumb指令问题,暂时放弃使用这个编译链。
更换编译链
编译链:gcc-arm-none-eabi-7-2017-q4-major-linux.bz2
/home/logread/imx8m-mini/gcc-arm-none-eabi-7-2017-q4-major
export ARMGCC_DIR="/home/logread/imx8m-mini/gcc-arm-none-eabi-7-2017-q4-major"
export PATH=$PATH:/home/logread/imx8m-mini/gcc-arm-none-eabi-7-2017-q4-major/bin
logread@logread:~/imx8m-mini/gcc-arm-none-eabi-7-2017-q4-major$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/home/logread/imx8m-mini/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/lto-wrapper
Target: arm-none-eabi
Configured with: /tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/src/gcc/configure --target=arm-none-eabi --prefix=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native --libexecdir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/lib --infodir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/arm-none-eabi --build=x86_64-linux-gnu --host=x86_64-linux-gnu --with-gmp=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-mpfr=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-mpc=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-isl=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-libelf=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Tools for Arm Embedded Processors 7-2017-q4-major' --with-multilib-list=rmprofile
Thread model: single
gcc version 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204] (GNU Tools for Arm Embedded Processors 7-2017-q4-major)
编译链改会arm-none-eabi,编译成功:
加载运行
拷贝debug/hello_world.bin,通过tftp加载,运行成功
u-boot=> tftp 0x7e0000 hello_world.bin
Using ethernet@30be0000 device
TFTP from server 192.168.1.99; our IP address is 192.168.1.55
Filename 'hello_world.bin'.
Load address: 0x7e0000
Loading: ##980.5 KiB/s
done
Bytes transferred = 15072 (3ae0 hex)
u-boot=> bootaux 0x7e0000
## Starting auxiliary core at 0x007E0000 ...Cortex-M4 serial:
hello world.
hello 2-che.
编译除的bin和elf文件差别,elf文件怎么跑的呢?
logread@logread:~/imx8m-mini/SDK_2.5.0_EVK-MIMX8MM/boards/evkmimx8mm/demo_apps/hello_world/armgcc$ file debug/hello_world.bin
debug/hello_world.bin: data
logread@logread:~/imx8m-mini/SDK_2.5.0_EVK-MIMX8MM/boards/evkmimx8mm/demo_apps/hello_world/armgcc$ file debug/hello_world.elf
debug/hello_world.elf: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped
elf文件需要使用J-LINK+gdb来运行在M4核:
$ arm-none-eabi-gdb hello_world.elf