Yocto: Hello World!

This blog describes in detail how to add a custom package into the Yocto project.

Step 1:

In order to add a package, you've got to let the bitbake know that which package's being added. There' are several ways to do this, of course. But I'll just show you the simplest way.

Copy the meta/recipes-sato/images/core-image-sato.bb to a new .bb (e.g. my-core-image-sato.bb) and add the following line to the end of the copy:

IMAGE_INSTALL += "helloworld"

Step 2:

Making a hello.c file with the following content:

#include "stdio.h"

void main() {
    printf("hello, world\n");
}

Step 3:

Create a helloworld_0.0.bb Bitbake recipe file which instructs Bitbake to cross-compile and package our hello world program.

Make a new directory under Poky, say, meta-custom, and put the recipe file there, together with the hello.c file. For simplicity, just copy the conf directory under meta to the meta-custom, make a new dir called recipes-demo and put the .bb file there, as well as the .c file.

Here's what the .bb file should look like:

DESCRIPTION = "Hello World sample program"
PR = "r0"
SRC_URI = "file://hello.c"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://hello.c;md5=a037431be1bc2056740c02eb59718e3f"
S = "${WORKDIR}"

do_compile() {
             ${CC} ${CFLAGS} ${LDFLAGS} -o hello hello.c
}

do_install() {
             install -d ${D}${bindir}/
             install -m 0755 ${S}/hello ${D}${bindir}/
}

FILES_${PN} = "${bindir}/hello"

For the md5 checksum, use the command "md5sum hello.c" to generate it.

step 4:

Add a new line the the bblayer.conf file.

BBLAYERS ?= " \
  /home/yocto/poky-denzil-7.0.1/meta \
  /home/yocto/poky-denzil-7.0.1/meta-yocto \
  /home/yocto/poky-denzil-7.0.1/meta-skeleton \
  /home/yocto/poky-denzil-7.0.1/meta-custom \
  "

In this way, BitBake knows where to search the .bb files.

step 5:

bitbake -k my-core-image-sato

step 6:

runqemu qemux86

DONE!

 



 

转载于:https://my.oschina.net/u/158589/blog/72589

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值