Working directory development

When the application is being built by the Yocto build system, we use this workflow to debug sporadic problems. However, this is not the recommended workflow for long developments. We will use the helloworld_1.0.bb custom recipe we saw back in the Adding new packages recipe in Chapter 3, The Software Layer, meta-custom/recipes-example/helloworld/helloworld_1.0.bb, as an example. The following recipe should already be in your meta-custom layer:

DESCRIPTION = "Simple helloworld application" 
SECTION = "examples" 
LICENSE = "MIT" 
LIC_FILES_CHKSUM = 
"file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4
f302" SRC_URI = "file://helloworld.c" S = "${WORKDIR}" do_compile() { ${CC} ${LDFLAGS} helloworld.c -o helloworld } do_install() { install -d ${D}${bindir} install -m 0755 helloworld ${D}${bindir} }

Here, the helloworld.c source file is the following:

#include <stdio.h> 
 
int main(void) 
{ 
    return printf("Hello World"); 
} 

The workflow steps are as follows:

  1. Start the package compilation from scratch:
$ cd /opt/yocto/fsl-community-bsp/
$ source setup-environment wandboard
$ bitbake -c cleanall helloworld

This will erase the package's build folder, shared state cache, and downloaded package source.

  1. Start a development shell:
$ bitbake -c devshell helloworld

This will fetch, unpack, and patch the helloworld sources and spawn a new shell with the environment ready for compilation. The new shell will change to the package's build directory.

  1. Depending on the SRC_URI variable, the package's build directory might be revision-controlled already. If not, as is the case in this example, we will create a local Git repository, as follows:
$ git init
$ git add helloworld.c
$ git commit -s -m "Original revision"
  1. Perform the modifications we need; for example, change helloworld.c to print Howdy World as follows:
#include <stdio.h> 
 
int main(void) 
{ 
   return printf("Howdy World"); 
} 
  1. Exit devshell and build the package without erasing our modifications:
$ bitbake -C compile helloworld
Note the capital C (which invokes the compile task) and also all the tasks that follow it.
  1. Test your changes on the hardware by copying the generated package and installing it. Because you have only modified one package, the rest of the dependencies should be already installed in the running root filesystem. Run the following:
$ bitbake -e helloworld | grep ^WORKDIR=
WORKDIR="/usr/local/ssd/fsl-community-bsp/wandboard/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/helloworld/1.0-r0"
$ scp ${WORKDIR_PATH}/deploy-rpms/cortexa9hf_neon/helloworld-1.0-r0.cortexa9hf_neon.rpm root@<target_ip_address>:/
  1. In the target, we install the new package with the following:
$ dnf install /helloworld-1.0-r0.cortexa9hf_neon.rpm

This assumes the target's root filesystem has been built with the package-management feature and the helloworld package is added to the RM_WORK_EXCLUDE variable when using the rm_work class.

  1. Go back to the devshell and commit your change to the local Git repository, as follows:
$ bitbake -c devshell helloworld
$ git add helloworld.c
$ git commit -s -m "Change greeting message"
  1. Generate a patch into the recipe's patch directory:
$ git format-patch -1 -o /opt/yocto/fsl-community- 
bsp/sources/meta-custom/recipes-
example/helloworld/helloworld-1.0
  1. Finally, add the patch to the recipe's SRC_URI variable, as shown here:
-SRC_URI = "file://helloworld.c" 
+SRC_URI = "file://helloworld.c 
+           file://0001-Change-greeting-message.patch 
+" 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset