Skip to content

Latest commit

 

History

History
executable file
·
365 lines (261 loc) · 10.2 KB

helper_Yocto-RaspberryPi3.md

File metadata and controls

executable file
·
365 lines (261 loc) · 10.2 KB

Yocto Raspberry Pi 3

GitHub license GitHub stars GitHub forks GitHub issues GitHub watchers

1. Overview

The Yocto Project (YP) is an open source collaboration project that helps developers create custom Linux-based systems regardless of the hardware architecture.

2. Environment

$ 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

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

3.2. Building

A. Step by Step

$ cd /work/YoctoPI3
$ cooker init ./cooker-menu/pi3-sample-menu.json
$ cat .cookerconfig

$ cooker init
$ cooker update
$ cooker generate
$ cooker build

B. Quick Build

$ cd /work/YoctoPI3
$ cooker cook ./cooker-menu/pi3-sample-menu.json

3.3. Customize

yocto 版本相容性很低,或許目前的版本可以進行客製化;但是其它版本的語法可能就不同了,這個要小心!

$ cd /work/YoctoPI3

# provides you a new shell into the build directory with all the environment variables set.
$ cooker shell pi3

3.3.1. rootfs

$ ls -al ./builds/build-pi3/tmp/work/raspberrypi3-poky-linux-gnueabi/core-image-base/1.0-r0/rootfs/

3.3.2. Set root's password

$ 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
$ cat ./builds/build-pi3/tmp/work/raspberrypi3-poky-linux-gnueabi/core-image-base/1.0-r0/rootfs/etc/passwd
$ cat ./builds/build-pi3/tmp/work/raspberrypi3-poky-linux-gnueabi/core-image-base/1.0-r0/rootfs/etc/shadow

3.3.4. ssh

$ 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"
$ 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
# 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

D. Install into Image

$ 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

A. pi3-master

$ 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
A.1. Build BB
$ 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

B. qemux86-64

$ 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

4. Burn Your Image into SD CARD

$ ls -al ./builds/build-pi3/tmp/deploy/images/raspberrypi3/core-image-base-raspberrypi3.rpi-sdimg

5. Boot from SD Card

6. Build helloworld on Host

7. Run helloworld on Pi

8. QEMU

不建議使用 QEMU。因為在編譯時也是使用不同的軟體包,真實硬體也模擬不出來。

如果只是要驗證自己寫的程式,直接使用 ubuntu 的 native compiler 產出執行檔,然後執行即可。

你可以看看 helper_Docker.md也是有相同情況。

Appendix

I. Study

II. Debug

II.1. ../qemu-4.1.0/linux-user/syscall.c:7657: undefined reference to `stime'

$ 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

II.2. Fetcher failure for URL: 'git://github.com/RPi-Distro/firmware-nonfree'

II.3. it has a restricted license 'synaptics-killswitch'

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

- local.conf

LICENSE_FLAGS_ACCEPTED = 'synaptics-killswitch'

II.4. sh: no job control in this shell

[ 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

- busybox in rootfs ?

# check busybox exist
$ ls -al rootfs/bin/busybox

- local.conf

Fail:
,"IMAGE_INSTALL += ' example'"

Ok:
,"IMAGE_INSTALL:append = ' example'"

III. Glossary

IV. Tool Usage

Author

Created and designed by Lanka Hsu.

License

HelperX is available under the BSD-3-Clause license. See the LICENSE file for more info.