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!

 



 

你可能感兴趣的:(qemu,package,custom,yocto,BitBake)