嵌入式linux之yocto(八)标准SDK
标准SDK
·
1. 标准SDK
/* 生成对应镜像菜谱SDK */
$ bitbake image -c populate_sdk
image-镜像菜谱名
/* qemux86-64 */
~/yocto$ bitbake myimage -c populate_sdk
sdk路径:
tmp/deploy/sdk/poky-glibc-x86_64-myimage-core2-64-qemux86-64-toolchain-3.4.2.sh
这里我生成的是myimgae的SDK,myimage是我基于core-image-minimal拓展的镜像菜谱。
/* imx8mq */
~/imx8mq/yocto/imx8mq-build$ bitbake core-image-minimal-c populate_sdk
sdk路径:
tmp/deploy/sdkfsl-imx-xwayland-glibc-x86_64-core-image-minimal-cortexa53-crypto-imx8mqevk-toolchain-5.10-hardknott.sh
2. 安装标准SDK
$ chmod +x xxx.sh
$ ./xxx.sh
默认安装在opt目录
/* qemux86-64 */
/opt/poky/3.4.2$ tree -L 2
.
├── environment-setup-core2-64-poky-linux
├── site-config-core2-64-poky-linux
├── sysroots
│ ├── core2-64-poky-linux
│ └── x86_64-pokysdk-linux
└── version-core2-64-poky-linux
3 directories, 3 files
/* imx8mq */
/opt/fsl-imx-xwayland/5.10-hardknott$ tree -L 2
.
├── environment-setup-cortexa53-crypto-poky-linux
├── site-config-cortexa53-crypto-poky-linux
├── sysroots
│ ├── cortexa53-crypto-poky-linux /* 开发板头文件、库文件在此 */
│ └── x86_64-pokysdk-linux /* 交叉编译器在此 */
└── version-cortexa53-crypto-poky-linux
3 directories, 3 files
3. 设置交叉编译环境
/* qemux86-64 */
$ . /opt/poky/3.4.2/environment-setup-core2-64-poky-linux
$ echo $ARCH
x86
$ echo $CROSS_COMPILE
x86_64-poky-linux-
/* imx8mq */
$ . /opt/fsl-imx-xwayland/5.10-hardknott/environment-setup-cortexa53-crypto-poky-linux
$ echo $ARCH
arm64
$ echo $CROSS_COMPILE
aarch64-poky-linux-
4. 交叉编译
交叉编译需要设置开发板需要的头文件,这里要设置sysroots。
GCC系列编译器接受"–sysroot=dir "参数,用来指定系统根目录的路径。
/* 不指定sysroot */
app$ aarch64-poky-linux-gcc hello_world.c -o hello_world
hello_world.c:1:10: fatal error: stdio.h: No such file or directory
1 | #include <stdio.h>
| ^~~~~~~~~
compilation terminated.
/* app/hello_word.c */
#include <stdio.h>
int main(void)
{
printf("hello world!\r\n");
return 0;
}
/* qemux86-64 */
app$ . /opt/poky/3.4.2/environment-setup-core2-64-poky-linux
app$ x86_64-poky-linux-gcc --sysroot=/opt/poky/3.4.2/sysroots/core2-64-poky-linux hello_world.c -o hello_world
app$ cp hello_world ~/nfs_rootfs/mnt/
~/yocto$ source poky/oe-init-build-env qemux86-64-build/
~/yocto/qemux86-64-build$ runqemu qemux86-64
root@qemux86-64$ mount -t nfs -o nolock,vers=3 ###.###.###.###:/home/ubuntu18/nfs_rootfs/mnt /mnt
root@qemux86-64:/mnt$ ./hello_world
hello world!
/* imx8mq */
app$ . /opt/fsl-imx-xwayland/5.10-hardknott/environment-setup-cortexa53-crypto-poky-linux
app$ aarch64-poky-linux-gcc --sysroot=/opt/fsl-imx-xwayland/5.10-hardknott/sysroots/cortexa53-crypto-poky-linux hello_world.c -o hello_world
app$ cp hello_world ~/nfs_rootfs/mnt/
root@imx8mqevk:/mnt# ./hello_world
hello world!
5. CMake应用编程
为了保持可移植性,我们把与硬件相关的部分单独编写,如下imx8mq.cmake,以后缀的形式参与编译。
/* app/imx8mq.cmake */
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm) #设置目标处理器架构
# 设置sysroot
set(TOOLCHAIN_DIR /opt/fsl-imx-xwayland/5.10-hardknott/sysroots)
set(CMAKE_SYSROOT ${TOOLCHAIN_DIR}/cortexa53-crypto-poky-linux)
# 设置交叉编译器
SET(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
/* app/CMakeLists.txt */
cmake_minimum_required(VERSION 3.0.0)
project(hello_world VERSION 0.1.0)
include(CTest)
enable_testing()
add_executable(hello_world hello_world.c)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
app$ tree
.
├── build
├── CMakeLists.txt
├── hello_world.c
└── imx8mq.cmake
1 directory, 3 files
app/bulid$ cmake -DCMAKE_TOOLCHAIN_FILE=../imx8mq.cmake ..
app/bulid$ make
app/build$ cp hello_world ~/nfs_rootfs/mnt/
root@imx8mqevk:/mnt# ./hello_world
hello world!
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)