Skip to content

Commit 73498a5

Browse files
Build Yocto Image for Raspberry Pi with Kanto recepies (#351)
[#281] How to guide document for building yocto image for raspberry pi with kanto recipes added Signed-off-by: APAC\JSO2KOR <[email protected]>
1 parent 654129e commit 73498a5

File tree

4 files changed

+296
-0
lines changed

4 files changed

+296
-0
lines changed
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
---
2+
title: "Build Yocto Image for Raspberry Pi"
3+
type: docs
4+
description: >
5+
This page provides all the instructions needed to build yocto image for raspberry pi with kanto recipes
6+
weight: 9
7+
---
8+
9+
Building a Yocto Image for a Raspberry Pi involves several steps, including setting up the environment, download the necessary layers, configuring the build and compiling the image.
10+
11+
### Before you begin
12+
13+
* Install the required packages required for the build on a Ubuntu/Debian system
14+
```shell
15+
sudo apt-get update
16+
sudo apt install -y gawk wget git-core diffstat unzip texinfo gcc-multilib \
17+
build-essential chrpath socat cpio python3 python3-pip python3-pexpect \
18+
xz-utils debianutils iputils-ping libsdl1.2-dev xterm zstd liblz4-tool \
19+
```
20+
21+
### Clone the Yocto/Poky Repository
22+
23+
* Verify the Yocto Version of Kanto availabe in meta-kanto layer, {{% relrefn "hono" %}} https://github.com/eclipse-kanto/meta-kanto {{% /relrefn %}}, this example provides information for kirkstone branch.
24+
25+
* Create a Source folder
26+
```shell
27+
mkdir sources
28+
cd sources
29+
```
30+
31+
* If it is kirkstone branch then, clone poky for kirkstone version in source directory
32+
33+
```shell
34+
git clone https://github.com/yoctoproject/poky.git
35+
cd poky
36+
git checkout kirkstone
37+
```
38+
Note : Change branch based on meta-kanto layer.
39+
40+
### Add Meta Layers to the source directory
41+
42+
* Based on the yocto version, clone the meta layers in the source directory
43+
`meta-raspberrypi`
44+
`meta-openembedded`
45+
`meta-virtualization`
46+
`meta-lts-mixins`
47+
48+
* Clone meta-raspberry pi layer to sources directory
49+
```shell
50+
cd ..
51+
git clone git://git.yoctoproject.org/meta-raspberrypi
52+
cd meta-raspberrypi
53+
git checkout kirkstone
54+
```
55+
56+
* Clone meta-openembedded layer to sources directory
57+
```shell
58+
cd ..
59+
git clone https://github.com/openembedded/meta-openembedded.git
60+
cd meta-openembedded
61+
git checkout kirkstone
62+
```
63+
64+
* Clone meta-virtualization layer to sources directory
65+
```shell
66+
cd ..
67+
git clone https://git.yoctoproject.org/git/meta-virtualization
68+
cd meta-virtualization
69+
git checkout kirkstone
70+
```
71+
72+
* Clone meta-lts-mixins layers to source directory
73+
```shell
74+
cd ..
75+
git clone https://git.yoctoproject.org/git/meta-lts-mixins
76+
cd meta-lts-mixins
77+
git checkout kirkstone/go
78+
```
79+
80+
Note : The above layer is required to get the updated go version to be added in the yocto build, since kanto requires go version 1.19 and above.
81+
82+
### Add meta-kanto layer to the sources directory
83+
84+
* Clone meta-kanto layer to the sources directory
85+
```shell
86+
cd ..
87+
git clone https://github.com/eclipse-kanto/meta-kanto.git
88+
cd meta-kanto
89+
git checkout kirkstone
90+
```
91+
92+
Note : Make sure all the layers cloned are of same yocto version ( kirkstone in this case)
93+
94+
### Create Build Directory
95+
96+
* After cloning all the required meta layers, move out of source directory to create build directory
97+
98+
```shell
99+
cd ../..
100+
source sources/poky/oe-init-build-env
101+
```
102+
* Run the below command to view the layers present in `bblayers.conf` file
103+
104+
```shell
105+
bitbake-layers show-layers
106+
```
107+
Note : Resolve any dependendencies if occured while running bitbake command.
108+
109+
### Configure bblayer.conf file
110+
111+
* By Default in the bblayer.conf file some of the layers will be added
112+
113+
* Add all the layers to the bblayers.conf file with below command
114+
```shell
115+
bitbake-layers add-layer /home/path/to/meta/layer/directory
116+
```
117+
118+
The following layers should be added in the bblayer.conf file
119+
120+
```json
121+
meta-raspberrypi
122+
meta-openembedded
123+
meta-virtualization
124+
meta-lts-mixins
125+
meta-openembedded/meta-oe
126+
meta-openembedded/meta-python
127+
meta-opemembedded/meta-networking
128+
meta-openembedded/meta-filesystems
129+
meta-kanto
130+
```
131+
132+
* Example to add layers to bblayers.conf file
133+
134+
while adding layers bitbake might have dependencies, add the dependent layers first.
135+
Example,
136+
137+
To add meta-kanto layer to bblayer.conf file which is kept at `/home/yocto/sources/meta-kanto`
138+
139+
`bitbake-layers add-layers /home/yocto/sources/meta-kanto`
140+
141+
* After adding all the required layers in bblayer.conf file, verify again by running the below command
142+
143+
```shell
144+
bitbake-layers show-layers
145+
```
146+
147+
### Configure local.conf file
148+
149+
* Open local.conf file which is placed at the below location in build directory
150+
151+
```shell
152+
vi conf/local.conf
153+
```
154+
155+
* Change the machine variable in local.conf file to raspberry pi machine
156+
```json
157+
MACHINE ??= "raspberrypi4"
158+
```
159+
160+
Note: Check the sources/meta-raspberrypi/conf/machine for the availabe machines for raspberry pi.
161+
162+
* Add required variables in local.conf file as shown and provided in the link below,
163+
164+
{{% relrefn "hono" %}} https://github.com/eclipse-kanto/meta-kanto {{% /relrefn %}}
165+
166+
```json
167+
# Add the required DISTRO_FEATURES
168+
DISTRO_FEATURES:append = " virtualization systemd"
169+
170+
# Configure the kernel modules required to be included
171+
MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
172+
173+
# System initialization manager setup
174+
VIRTUAL-RUNTIME_init_manager = "systemd"
175+
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
176+
VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"
177+
178+
# Add the Eclipse Kanto components
179+
IMAGE_INSTALL:append = " mosquitto"
180+
IMAGE_INSTALL:append = " suite-connector"
181+
IMAGE_INSTALL:append = " aws-connector"
182+
IMAGE_INSTALL:append = " azure-connector"
183+
IMAGE_INSTALL:append = " software-updates"
184+
IMAGE_INSTALL:append = " file-upload"
185+
IMAGE_INSTALL:append = " file-backup"
186+
IMAGE_INSTALL:append = " update-manager"
187+
IMAGE_INSTALL:append = " container-management"
188+
IMAGE_INSTALL:append = " local-digital-twins"
189+
```
190+
191+
* Run bitbake `target-name' availabe as shown below,
192+
193+
```json
194+
Common targets are:
195+
core-image-minimal
196+
core-image-full-cmdline
197+
core-image-sato
198+
core-image-weston
199+
meta-toolchain
200+
meta-ide-support
201+
```
202+
203+
Note : If any build issues comes up, resolve the issue and run the bitbake `target-name' command again for the build.
204+
205+
206+
### Final Build Image Repository Location
207+
208+
* After the successful build, the image will be availabe at the below location.
209+
210+
```json
211+
build/tmp/deploy/images/`machine_name`/
212+
```
213+
214+
### Run & Test the image with QEMU (Quick Emulator)
215+
216+
* If RaspberryPi device is not availabe, the image can be run and tested on QEMU. Make the below changes to run on QEMU.
217+
218+
In `build/conf/local.conf' file
219+
220+
* Change the machine variable name to relevant qemu arch as shown below by changing the `MACHINE` varilabe from raspberrypi4 to 'qemux86_64`
221+
222+
```json
223+
# You need to select a specific machine to target the build with. There are a selection
224+
# of emulated machines available which can boot and run in the QEMU emulator:
225+
#
226+
#MACHINE ?= "qemuarm"
227+
#MACHINE ?= "qemuarm64"
228+
#MACHINE ?= "qemux86"
229+
#MACHINE ?= "qemux86-64"
230+
231+
# This sets the default machine to be qemux86-64 if no other machine is selected:
232+
MACHINE ??= "qemuarm64"
233+
234+
```
235+
236+
* Run bitbake `target-name` command by sourcing the `oe-init-build-env` script
237+
238+
* In the same build directory run the below command to run qemu
239+
240+
```shell
241+
runqemu qemuarm64
242+
```
243+
244+
![how-to-guides](/kanto/images/docs/how-to-guides/runqemu_qemuarm64.png)
245+
246+
![how-to-guides](/kanto/images/docs/how-to-guides/login_page.png)
247+
248+
* The above command will open a window which boots as "YOCTO PROJECT" and it enters to command line window. Enter login as `root', and check for kanto components with the below commands.
249+
250+
```shell
251+
systemctl status \
252+
suite-connector.service \
253+
container-management.service \
254+
software-update.service \
255+
file-upload.service \
256+
file-backup.service \
257+
system-metrics.service \
258+
kanto-update-manager.service
259+
```
260+
261+
All listed services must be in an active running state.
262+
263+
![how-to-guides](/kanto/images/docs/how-to-guides/verify_kanto_components.png)
264+
265+
### Flash the image on Raspberry Pi
266+
267+
* The build image will be availabe at `build/tmp/deploy/images/raspberrypi4/`
268+
269+
* Identify the SD Card Device with the below command to find the device name of your SD card
270+
271+
```shell
272+
lsblk
273+
```
274+
275+
* Flash the image to sd card
276+
277+
```shell
278+
sudo dd if=/path/to/image.wic of=/dev/sdX bs=4M status=progress
279+
```
280+
281+
* Boot the Raspberry Pi,
282+
283+
Insert the SD card into your Raspberry Pi and power it on. The Pi should boot from the Yocto image.Login to your device and run the below command to verify the kanto components.
284+
285+
```shell
286+
systemctl status \
287+
suite-connector.service \
288+
container-management.service \
289+
software-update.service \
290+
file-upload.service \
291+
file-backup.service \
292+
system-metrics.service \
293+
kanto-update-manager.service
294+
```
295+
296+
Loading
Loading
Loading

0 commit comments

Comments
 (0)