Yocto参考文档
Yocto官网:https://www.yoctoproject.org/
Project仓库:https://git.yoctoproject.org/
Reference Manual:https://docs.yoctoproject.org/
Quick Start Guide:https://docs.yoctoproject.org/brief-yoctoprojectqs/index.html
AGL:https://wiki.automotivelinux.org/agl-distro/source-code
1、在已有meta层中添加
比如yocto工程目录meta-semidrive/recipes-bsp文件夹下,新建hello-bsp文件夹,
hello-bsp文件夹添加如下源文件:
.
├── hello-bsp
│ ├── inc
│ ├── LICENSE
│ ├── Makefile
│ └── src
│ └── hello_bsp.c
└── hello-bsp.bb
2、bb文件写法
hello-bsp.bb文件中SRC_URI指定编译使用的文件路径,S指定生成的镜像路径位于build/work/下;
do_compile、do_install指定编译和部署方法
1 SUMMARY = "hello examples demo"
2
3 LICENSE = "BSD"
4 LIC_FILES_CHKSUM = "file://LICENSE;md5=b30cbe0b980e98bfd9759b1e6ba3d107"
5
6
7 SRC_URI = "\
8 file://LICENSE \
9 file://Makefile \
10 file://src/hello_bsp.c \
11 "
12
13 S = "${WORKDIR}"
14
15 FILES_${PN} = "\
16 /usr/bin/hello_bsp\
17 "
18 do_compile() {
19 make MACHINE=${MACHINE}
20 }
21
22 do_install () {
23 install -d ${D}/usr/bin
24 install -m 0755 hello_bsp ${D}/usr/bin/hello_bsp
25 }
3、Makefile
1 APP := hello_bsp
2
3 HELLO_BSP_OBJ := src/hello_bsp.o
4
5 CFLAGS += -Wall -Werror
6
7 all: $(APP)
8
9 hello_bsp: $(HELLO_BSP_OBJ)
10 $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) -lpthread
11
12 %.o: %.c
13 $(CC) -c $(CFLAGS) -o $@ $^ -I inc/
14
15 clean:
16 rm -rf $(APP) hello_bsp src/*.o
4、hello_bsp.c源文件
1 /*
2 * hello.c
3 *
4 * Copyright (c) 2020 Slamdunk.
5 * All rights reserved.
6 *
7 * Description:
8 *
9 * Revision History:
10 * -----------------
11 */
12 #include <stdio.h>
13
14 int main()
15 {
16 printf("hello yfve bsp\r\n");
17 return 0;
18 }
5、编译
bitbake hello-bsp
$ bitbake hello-bsp
WARNING: Layer x9-gen1 should set LAYERSERIES_COMPAT_x9-gen1 in its conf/layer.conf file to list the core layer names it is compatible with.
WARNING: Layer x9-gen1 should set LAYERSERIES_COMPAT_x9-gen1 in its conf/layer.conf file to list the core layer names it is compatible with.
WARNING: You have included the meta-gnome layer, but 'x11' has not been enabled in your DISTRO_FEATURES. Some bbappend files may not take effect. See the meta-gnome README for details on enabling meta-gnome support.
Loading cache: 100% |###############################################################################################################################| Time: 0:00:00
Loaded 3118 entries from dependency cache.
Parsing recipes: 85% |########################################################################################################### | ETA: 0:00:00
编译生成的文件位于:
tmp/work/aarch64-sdrv-linux/hello-bsp/1.0-r0/image/usr/bin/hello_bsp
file tmp/work/aarch64-sdrv-linux/hello-bsp/1.0-r0/image/usr/bin/hello_bsp
tmp/work/aarch64-sdrv-linux/hello-bsp/1.0-r0/image/usr/bin/hello_bsp: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=ae7bf505abc6b562980916ef1f64c519055ce77e, not stripped
6、添加到yocto整合的rootfs中
IMAGE_INSTALL_append = "hello-bsp \"
重新编译整个工程即可:bitbake core-image-base
tmp/work/x9h_ref_serdes-sdrv-linux/core-image-base/1.0-r0/rootfs/usr/bin/hello_bsp