Yocto Raspberry Pi 3
The Yocto Project (YP) is an open source collaboration project that helps developers create custom Linux-based systems regardless of the hardware architecture.
$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat cpio python python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev pylint3 xterm
3. Yocto Cooker
Here, we use Cooker to build.
Yocto Project isn't friendly to programmer. We have to collect Menu-files and create local.conf by myself.
$ python3 -m pip install --upgrade git+https://github.com/cpb-/yocto-cooker.git
$ cooker --version
# 1.3.0
3.1. Cooker Menu - (pi3-sample-menu.json)
$ mkdir -p /work/YoctoPI3/cooker-menu
$ cd /work/YoctoPI3/cooker-menu
$ curl https://raw.githubusercontent.com/cpb-/yocto-cooker/master/sample-menus/pi3-sample-menu.json -o pi3-sample-menu.json
$ cd /work/YoctoPI3
$ cd /work/YoctoPI3
$ cooker init ./cooker-menu/pi3-sample-menu.json
$ cat .cookerconfig
$ cooker init
$ cooker update
$ cooker generate
$ cooker build
$ cd /work/YoctoPI3
$ cooker cook ./cooker-menu/pi3-sample-menu.json
yocto 版本相容性很低,或許目前的版本可以進行客製化;但是其它版本的語法可能就不同了,這個要小心!
$ cd /work/YoctoPI3
# provides you a new shell into the build directory with all the environment variables set.
$ cooker shell pi3
$ ls -al ./builds/build-pi3/tmp/work/raspberrypi3-poky-linux-gnueabi/core-image-base/1.0-r0/rootfs/
$ vi ./cooker-menu/pi3-sample-menu.json
"IMAGE_CLASSES += 'extrausers'",
"EXTRA_USERS_PARAMS = 'usermod -P 91005476 root;'",
$ cooker generate
$ cat ./builds/build-pi3/conf/local.conf
$ cat ./poky/meta/classes/extrausers.bbclass
A. /etc/passwd
$ cat ./builds/build-pi3/tmp/work/raspberrypi3-poky-linux-gnueabi/core-image-base/1.0-r0/rootfs/etc/passwd
B. /etc/shadow
$ cat ./builds/build-pi3/tmp/work/raspberrypi3-poky-linux-gnueabi/core-image-base/1.0-r0/rootfs/etc/shadow
$ vi ./cooker-menu/pi3-sample-menu.json
add into "local.conf"
"IMAGE_INSTALL += ' dropbear'",
$ cooker generate
$ cat ./builds/build-pi3/conf/local.conf
$ bitbake -s | grep dropbear
$ bitbake -c build dropbear
$ cat ./layers/poky/meta/recipes-core/dropbear/dropbear/init
$ vi ./layers/poky/meta/recipes-core/dropbear/dropbear/dropbear.default
# please mark
# DROPBEAR_EXTRA_ARGS="-w"
3.3.5. create a layer
$ cd /work/YoctoPI3/layers
$ bitbake-layers create-layer meta-lanka
NOTE: Starting bitbake server...
Add your new layer with 'bitbake-layers add-layer meta-lanka'
# we don't need to add-layer.
# The following steps don't have to be performed.
$ cd /work/YoctoPI3/layers
$ . ./poky/oe-init-build-env
$ cd /work/YoctoPI3/layers
$ yocto-check-layer meta-lanka
$ rm -rf build
A. meta-lanka
# check example exist
$ bitbake -s | grep example
# not found
$ vi ./cooker-menu/pi3-sample-menu.json
# add "meta-lanka" into "layers"
# prepare the build-dir and configuration files (local.conf, bblayers.conf, template.conf) needed by Yocto Project.
$ cooker generate
$ vi ./builds/build-pi3/conf/bblayers.conf
# check again
$ bitbake -s | grep example
example :0.1-r0
# Then update meta-lanka/recipes-example/example/example_0.1.bb and add meta-lanka/recipes-example/example/files/*
B. Update example_0.1.bb
C. Add files - helloworld-123.c and Makefile
$ vi ./cooker-menu/pi3-sample-menu.json
# add "example" into "local.conf"
# ,"IMAGE_INSTALL:append = ' example'"
3.4. cookerX
cookerX is based on Yocto Cooker. pi3-sample-menu.json 使用的版本過舊。
這個是將 cooker 再包裝一層。
meta branch rev poky master 7ec846be8b meta-openembedded master 7f15e7975 meta-raspberrypi master 2b733d5
$ cd cookerX
$ . conf/pi3-master.conf
$ make
# check rootfs
$ ls -al builds_lnk/pi3-master_rootfs/
# pi3-master_core-image-base-raspberrypi3.wic.bz2
$ ls -al images_pi3/pi3-master_core-image-base-raspberrypi3.wic.bz2
$ make build
BB_TASK=[build], BB=[]
Example:
make listtasks BB=avahi
make configure BB=avahi
make clean BB=avahi
make cleanall BB=avahi
make fetch BB=avahi
make compile BB=avahi
make build BB=avahi
make install BB=avahi
make package_qa BB=avahi
$ cd cookerX
$ . conf/qemux86_64.conf
$ make
# check rootfs
$ ls -al builds_lnk/qemux86_64-rootfs/
# bzImage and rootfs
$ ls -al builds/build-qemux86-64/tmp/deploy/images/qemux86-64/bzImage
$ ls -al builds/build-qemux86-64/tmp/deploy/images/qemux86-64/core-image-base-qemux86-64-*.rootfs.ext4
A. balenaEtcher
$ ls -al ./builds/build-pi3/tmp/deploy/images/raspberrypi3/core-image-base-raspberrypi3.rpi-sdimg
C. rpi-imager
不建議使用 QEMU。因為在編譯時也是使用不同的軟體包,真實硬體也模擬不出來。
如果只是要驗證自己寫的程式,直接使用 ubuntu 的 native compiler 產出執行檔,然後執行即可。
你可以看看 helper_Docker.md也是有相同情況。
$ bitbake -s | grep qemu
$ find -name qemu*.bb
./layers/poky/meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb
./layers/poky/meta/recipes-devtools/qemu/qemu-native_4.1.0.bb
./layers/poky/meta/recipes-devtools/qemu/qemuwrapper-cross_1.0.bb
./layers/poky/meta/recipes-devtools/qemu/qemu_4.1.0.bb
./layers/poky/meta/recipes-devtools/qemu/qemu-system-native_4.1.0.bb
修改
./layers/poky/meta/recipes-devtools/qemu/qemu-native.inc
新增檔案
./layers/poky/meta/recipes-devtools/qemu/qemu/0012-linux-user-remove-host-stime-syscall.patch
linux-firmware-rpidistro RPROVIDES linux-firmware-rpidistro-bcm43456 but was skipped: because it has a restricted license 'synaptics-killswitch'. Which is not listed in LICENSE_FLAGS_ACCEPTED
LICENSE_FLAGS_ACCEPTED = 'synaptics-killswitch'
[ 1.795126] Run /sbin/init as init process [ 1.795772] hid-generic 0003:0627:0001.0002: input: USB HID v1.11 Keyboard [QEMU QEMU USB Keyboard] on usb-0000:00:1d.7-2/input0 [ 1.796985] Run /etc/init as init process [ 1.797744] Run /bin/init as init process [ 1.798366] Run /bin/sh as init process sh: cannot set terminal process group (-1): Inappropriate ioctl for device sh: no job control in this shell sh-5.2# [ 2.108334] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
# check busybox exist
$ ls -al rootfs/bin/busybox
Fail:
,"IMAGE_INSTALL += ' example'"
Ok:
,"IMAGE_INSTALL:append = ' example'"
Created and designed by Lanka Hsu.
HelperX is available under the BSD-3-Clause license. See the LICENSE file for more info.