前言 RT-Thread Smart (rt-smart)内核与用户APP分开编译,这点有点像嵌入式Linux的开发 折腾了一下,终于在 Ubuntu 20.04.4 上,搭建了基于 ART-Pi-smart 的编译环境
rt-smart 目前好像在RT-Thread Studio上不能直接开发,当前支持的BSP数量不算丰富,ART-Pi-smart 开发板是基于ARM平台的,rt-smart建议使用:arm-linux-musleabi- 系列的gcc 交叉编译环境,后面研究是否可以直接使用arm-none-linux-gnueabi- 系列的标准ARM Linux gcc 交叉编译工具链编译,这样就不用下载那么多的编译工具了。
编译环境 在ubuntu 下的shell 控制台,下载 ART-Pi-smart 的代码,使用git 克隆的方式 通过查看帮助文档,工具需要手动下载,并且在 ART-Pi-smart/tools 目录下,有一个编译工具下载的python 脚本,运行即可 cd tools python get_toolchain.py 默认会下载 arm的交叉工具链,通过查看脚本,可以下载多个平台的工具链,windows上也支持
设置环境变量 ART-Pi-smart 目录下,有个:smart-env.sh的脚本,我直接执行:./smart-env.sh,发现环境变量设置失败,也就是输入arm-linux- 按TAB键,无法自动补全找到:arm-linux-musleabi- 解决方法:这里不用直接执行脚本,使用Linux 的source 命令,source smart-env.sh /home/rtthread/smart/ART-Pi-smart# source smart-env.sh Arch => arm CC => gcc PREFIX => arm-linux-musleabi- EXEC_PATH => /home/rtthread/smart/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin
验证编译环境 在shell 终端输入 arm-linux-musleabi-gcc -v,如果命令能执行成功,交叉编译环境就设置好了 /home/rtthread/smart/ART-Pi-smart# arm-linux-musleabi-gcc -v Using built-in specs. COLLECT_GCC=arm-linux-musleabi-gcc COLLECT_LTO_WRAPPER=/home/rtthread/smart/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin/../libexec/gcc/arm-linux-musleabi/7.3.0/lto-wrapper Target: arm-linux-musleabi Configured with: ../src_gcc/configure --disable-werror --prefix= --target=arm-linux-musleabi --with-sysroot=/arm-linux-musleabi --with-build-sysroot=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/sysroot/ --enable-languages=c,c++ --disable-multilib --enable-tls --disable-libmudflap --disable-libsanitizer --disable-gnu-indirect-function --disable-libmpx --enable-libstdcxx-time --host=x86_64-pc-linux-gnu AR_FOR_TARGET=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/obj_binutils/binutils/ar AS_FOR_TARGET=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/obj_binutils/gas/as-new LD_FOR_TARGET=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/obj_binutils/ld/ld-new NM_FOR_TARGET=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/obj_binutils/binutils/nm-new OBJCOPY_FOR_TARGET=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/obj_binutils/binutils/objcopy OBJDUMP_FOR_TARGET=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/obj_binutils/binutils/objdump RANLIB_FOR_TARGET=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/obj_binutils/binutils/ranlib READELF_FOR_TARGET=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/obj_binutils/binutils/readelf STRIP_FOR_TARGET=/builds/research/musl-toolchain/build/arm-linux-musleabi_for_x86_64-pc-linux-gnu/obj_binutils/binutils/strip-new Thread model: posix gcc version 7.3.0 (GCC) build date: Jun 4 2022 14:27:28 build sha: c62796d937808ba24e789256d8d25a5c6d2284fd build job: 340427
备注 这个export 导出的环境变量,实际上是临时的,可以改为【永久的】,当然只要这个 shell 控制台终端不退出,还是可以一直生效的。
编译rt-smart kernel 进入:ART-Pi-smart/kernel/bsp/imx6ull-artpi-smart 目录下: scons --clean 清理一下工程 scons 就可以编译 kernel了 LINK rtthread.elf arm-linux-musleabi-objcopy -O binary rtthread.elf rtthread.bin arm-linux-musleabi-size rtthread.elf text data bss dec hex filename 1053508 34496 174016 1262020 1341c4 rtthread.elf python mkimage.py -t imximage -b rtthread.bin -o rtthread.imx -g rtthread.img -a 0x80001000 Image Type : Freescale i.MX Boot Image Bin File : rtthread.bin IMX File : rtthread.imx IMG File : rtthread.img Image Size : 1095360 bytes Image Load : 0x80001000 scons: done building targets.
编译用户程序 kernel 与用户程序分开了,所以进入用户的目录:ART-Pi-smart/userapps,与编译kernel的命令类似: scons --clean 清理一下工程 scons 就可以编译 了 LINK root/bin/cpp1114.elf LINK root/bin/gpio.elf LINK root/bin/hello.elf LINK root/bin/i2c.elf LINK root/bin/ntp.elf LINK root/bin/ping.elf LINK root/bin/pong.elf LINK root/bin/pwm.elf LINK root/bin/sysinfo.elf LINK root/bin/uPnP.elf LINK root/bin/uart.elf LINK root/bin/vi.elf LINK root/bin/webclient.elf CC services/webserver/packages/webnet-v2.0.2/src/webnet.o CC services/webserver/packages/webnet-v2.0.2/src/wn_mimetype.o CC services/webserver/packages/webnet-v2.0.2/src/wn_request.o CC services/webserver/packages/webnet-v2.0.2/src/wn_session.o CC services/webserver/packages/webnet-v2.0.2/src/wn_utils.o CC services/webserver/packages/webnet-v2.0.2/src/wn_module.o CC services/webserver/packages/webnet-v2.0.2/module/wn_module_asp.o CC services/webserver/packages/webnet-v2.0.2/module/wn_module_auth.o CC services/webserver/packages/webnet-v2.0.2/module/wn_module_cgi.o CC services/webserver/packages/webnet-v2.0.2/module/wn_module_index.o CC services/webserver/packages/webnet-v2.0.2/module/wn_module_alias.o CC services/webserver/packages/webnet-v2.0.2/module/wn_module_upload.o CC services/webserver/packages/webnet-v2.0.2/module/wn_module_ssi.o CC services/webserver/packages/webnet-v2.0.2/samples/wn_sample.o CC services/webserver/packages/webnet-v2.0.2/samples/wn_sample_upload.o LINK root/bin/webserver.elf scons: done building targets. 用户程序,最终的产物就是 elf 文件
小结 初步了解 RT-Thread Smart的编译环境的搭建 基于ubuntu 20.04.4 ,编译 倒是挺容易的,不过代码阅读、编辑,还是需要IDE,如VS Code,后面研究在VS Code 上搭建开发 rt-smart的环境。
原作者:张世争
|