Search This Blog

Saturday, January 24, 2026

Custom Linux Image Build Using Yocto on WSL

ကိုယ်သုံးမယ့် Single Board Computer (SBC) က အထူးပြုလုပ်ထားတဲ့ ဟာ့ဒ်ဝဲတွေ နဲ့ ချိတ်ဆက်ထားရင်၊ သူနဲ့ လိုက်ဖက်မယ့် Linux image ကို Yocto သုံးပြီး ပြုလုပ်တာက စိတ်တိုင်းကျရနိုင်သလို၊ နောက်လည်းအလွယ်တကူ ပြန်လုပ်လို့ရတဲ့ အပြင်၊ ပေါ့ပါးသေးငယ်တဲ့ အတွက် ပိုကောင်းပါတယ်။ Linux image ကို build လုပ်ဖို့အတွက် environment ပြင်ဆင်ရတာ အချိန်ကုန်သက်သာ ချင်ရင် WSL နဲ့ Yocto Docker container ကို ပေါင်းပြီး သုံးလို့ရပါတယ်။



Installing WSL

WSL ကို ဝင်းဒိုး ပေါ်မှာ install လုပ်ဖို့အတွက် PowerShell ကို administrator privileges နဲ့ ဖွင့်ပါ။ ဥပမာအနေနဲ့ Ubuntu 22.04 ကို install လုပ်ဖို့ အောက်ပါ command တွေကို run ပါ။

wsl --install -d Ubuntu-22.04
wsl -l -v


ပြီးရင် Ubuntu ကို Start menu ကနေ ဖွင့်ပြီး Linux username နဲ့ password ကို ဖန်တီးပါ။ အသေးစိတ်အချက်အလက် တွေအတွက် WSL Setup Guide ကို ဒီမှာ [1] ကြည့်ပါ။ WSL ကို install လုပ်တဲ့ အချိန် ပြဿနာ ပေါ်ခဲ့ရင် Windows search bar ကနေ "Turn Windows features on or off" ကို ဖွင့်ပြီး Virtual Machine Platform နဲ့ Windows Subsystem for Linux ကို enable လုပ်ပါ။ အခါတလေ BIOS settings မှာ virtualization technology (Intel VT-x or AMD-V) ကို စစ်ဆေးပြီး enable လုပ်ဖို့လည်း လိုအပ်နိုင်ပါတယ်။


Figure 1. Turn Windows features on or off.
ပြီးရင် distribution ကို 300 GB ကျော်တဲ့ storage drive တစ်ခုခု ကို ရွှေ့တာ ပိုကောင်းတယ်။ အထူးသဖြင့် ဆိုရရင် tools အများကြီးကို install လုပ်မယ်၊ ဒါမှ မဟုတ် project အများကြီးကို သိမ်းမယ် စဉ်းစားထားရင် ပေါ့။

# powershell in admin mode
wsl --shutdown
wsl --export Ubuntu-22.04 "D:\WSL\temp\ubuntu-export.tar"
wsl --unregister Ubuntu-22.04
wsl --import Ubuntu D:\WSL\Ubuntu "D:\WSL\temp\ubuntu-export.tar"
# delete temp\ubuntu-export.tar

အဲဒီနောက်မှာတော့ သင်ရဲ့ WSL Ubuntu build host မှာ လိုအပ်တဲ့ host packages များကို install လုပ်ဖို့ အောက်ပါ command များကို run ပါ။

sudo apt-get update
sudo apt-get install build-essential chrpath cpio debianutils diffstat file gawk gcc git iputils-ping libacl1 liblz4-tool locales python3 python3-git python3-jinja2 python3-pexpect python3-pip python3-subunit socat texinfo unzip wget xz-utils zstd

ပြီးရင် locale en_US.UTF-8 သင့်စနစ်မှာ ရှိဖို့ လိုအပ်ပါတယ်။

locale -a # check if it lists en_US.UTF-8 
sudo nano /etc/locale.gen # uncomment en_US.UTF, write ctrl+o , and exit ctrl+x 
sudo locale-gen

တခြားနည်းလမ်း တခု ကတော့ poky container ကို သုံးခြင်းဖြစ်ပါတယ်။ Docker မသုံးချင်ရင် တော့ အောက်မှာ ဖေါ်ပြထားတဲ့ Setup Docker နဲ့ Poky container အပိုင်းတွေကို ကျော်သွားပြီး Yocto build ကနေ ဆက်ဖတ် နိုင်ပါတယ်။

Setup Docker

နောက် ရွေးချယ် စရာ တစ်ခု ကတော့ Docker ကို သင့်ရဲ့ WSL Ubuntu distribution မှာ install လုပ်ခြင်းဖြစ်ပါတယ်။ အောက်ပါ command များကို အသုံးပြု၍ Docker ကို non-interactively install လုပ်နိုင်ပါတယ်။

sudo apt install curl
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh


နောက်ထပ် အချက်အလက်များအတွက် အောက်ပါ resource များကို ကိုးကားပါ။ ပြီးရင် အောက်ပါ အတိုင်းပြန်စစ် ပါ။

sudo service docker start
sudo docker run hello-world


နောက် user ကို docker group ထဲထည့်ပြီး docker ကို sudo မလိုဘဲ run လုပ်နိုင်ဖို့ အောက်ပါ command များကို run ပါ။

# sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world


ပြီးတော့ local root ကို xserver အတွက် ခွင့်ပြုပါ။

sudo apt install x11-xserver-utils
xhost +local:root
grep -qxF 'xhost +local:root' ~/.profile || echo 'xhost +local:root' >> ~/.profile




Using Poky Container

Docker hub ကနေ Poky container ကို ရယူပါ။

docker pull crops/poky:ubuntu-22.04


ဒါမှမဟုတ် GitHub container registry က Poky Container ကို သုံးနိုင်ပါတယ်။ ဒီ ghcr.io က Docker image ကို ရယူဖို့ အောက်ပါ command ကို အသုံးပြုပါ [6]:

docker pull ghcr.io/crops/poky:ubuntu-22.04


အရေးကြီးတဲ့ အဆင့်တစ်ခု က workspace directory တစ်ခုကို Linux host မှာ ဖန်တီးတာပါ။ ဒါက container အတွင်းက output တွေကို host system မှာ user က အသုံးပြုနိုင်ဖို့ အထောက်အကူဖြစ်ပါတယ်။ WSL root directory ထဲမှာ workdir ဆိုတဲ့ directory တစ်ခုကို ဖန်တီးနိုင်ပါတယ်။ ဝင်းဒိုး file system (/mnt/c/) ထဲမှာ မဟုတ်ရပါ။

# in WSL root directory, it must not be in Windows file system like /mnt/c/
sudo mkdir /workdir
sudo chown $USER:$USER /workdir


Docker Hub က Container ကို run ဖို့အတွက် အောက်ပါ command ကို အသုံးပြုပါ။

docker run --rm -it -v /workdir:/workdir \
crops/poky:ubuntu-22.04 --workdir=/workdir


GitHub Container Registry က Poky Container ကို ရယူ run ဖို့ ဆိုရင်တော့ အောက်ပါ command ကို အသုံးပြုပါ။

docker run --rm -it -v /workdir:/workdir \
 ghcr.io/crops/poky:ubuntu-22.04 \
 --workdir=/workdir


Yocto Build

WSL root directory ထဲမှာ "workdir" ဆိုတဲ့ directory တစ်ခုကို ဖန်တီးနိုင်ပါတယ်။ မလုပ်ရသေးရင်တော့ အောက်ပါ command များကို run ပါ။

sudo mkdir /workdir
sudo chown $USER:$USER /workdir


အဲဒီ workdir ထဲကို ဝင်ပြီးရင် WSL သုံးတာပဲဖြစ်ဖြစ်၊ ဒါမှမဟုတ် container အတွင်းမှာ ပဲဖြစ်ဖြစ် အောက်က လမ်းညွှန်ချက်များကို လိုက်နာ ဆောင်ရွက်နိုင်ပါတယ်။ ပထမ အဆင့် ကတော့ အသုံးပြုမယ့် release ကို ရွေးချယ်ခြင်းဖြစ်ပါတယ်။ Yocto Project Releases စာမျက်နှာမှာ တည်ငြိမ်တဲ့ version ကို စစ်ဆေးပါ။ ဥပမာအနေနဲ့ Poky repository ကို clone ပြီး၊ scarthgap branch ကို checkout လုပ်ဖို့အတွက် အောက်ပါ command များကို အသုံးပြုပါ။

# navigate to work dir
cd /workdir
git clone git://git.yoctoproject.org/poky
cd poky
git branch -a
# check https://wiki.yoctoproject.org/wiki/Releases for stable
git checkout -t origin/scarthgap -b my-scarthgap
# go back to workdir
cd ..


ခုနက work directory ကို ပြန်သွားပြီး၊ build environment ကို initialize လုပ်ဖို့ oe-init-build-env script ကို run ပါ:

source poky/oe-init-build-env


အဲဒီ script က "build" directory တစ်ခုကို ဖန်တီးပြီး "build/conf" အတွင်းမှာ "local.conf" ဆိုတဲ့ local configuration file တစ်ခုကို generate လုပ်ပါတယ်။ ပထမ အဆင့် ကတော့ default qemux86-64 machine ကို build လုပ်ပြီး စမ်းသပ်ခြင်းဖြစ်ပါတယ်။ သင့်ရဲ့ build environment console မှာ -k (--continue) option နဲ့ BitBake command ကို run ပါ။ ဒါက အမှားတွေကို တစ်ခါတည်း အများကြီး ရှာဖွေဖို့ အထောက်အကူဖြစ်ပါတယ်။

bitbake -k core-image-minimal


အဲဒီ command ကို run လုပ်ပြီးရင် build process အောင်မြင်စွာ ပြီးဆုံးဖို့၊ ပြန် ပြန်ပြီး run လုပ်ဖို့ လိုနိုင်ပါတယ်။ BitBake ကို run လုပ်တဲ့အခါ AppArmor error ကို တွေ့ရင်၊ Ubuntu 24.04 နဲ့ အထက် version တွေမှာ ဖြစ်တဲ့ ပြဿနာပါ။ ဒါကို ဖြေရှင်းဖို့အတွက် /etc/apparmor.d/bitbake ဖိုင်ကို ဖန်တီးပြီး အောက်ပါ ဟာတွေကို ထည့်သွင်းပါ။

abi < abi/4.0 >,
include < tunables/global >
# Profile for the bitbake executable to allow unconfined execution
profile bitbake /**/bitbake/bin/bitbake flags=(unconfined) {
  userns,
}


ဖိုင်ကို save လုပ်ပြီးရင်၊ အဲဒီ changes တွေကို reboot မလုပ်ပဲ အမြန်ဆုံး အသုံးပြုနိုင်ဖို့ terminal မှာ အောက်ပါ command ကို run ပါ။

sudo apparmor_parser -r /etc/apparmor.d/bitbake


Build လုပ်တာ ပြီးရင် တော့၊ qemu ကို graphic မသုံးဘဲ run ပါ။

runqemu qemux86-64 slirp nographic


Username အတွက် root လို့ ထည့်ပြီး login လုပ်ပါမယ်။ Password မလိုပါဘူး။


Figure 2. Running qemux86-64.


Qemu က နေ ctrl+a x ကို နှိပ်ပြီး ထွက် နိုင်ပါတယ်။

ctrl+a x




Beaglebone Black

နောက်တဆင့်ကတော့ "local.conf" ကို edit လုပ်ပြီး target machine ကို Beaglebone Black အဖြစ် ပြောင်းလဲခြင်းဖြစ်ပါတယ်။ Raspberry Pi အတွက် build လုပ်ချင်ရင်တော့ နောက်တစ်ဆင့် - Raspberry Pi ဆိုတဲ့ အပိုင်း ကို ကျော်သွားနိုင်ပါတယ်။ သင့်ရဲ့ console က Docker container အတွင်းမှာရှိရင်၊ host system အတွင်း configuration file ကို access လုပ်ပြီး edit လုပ်ဖို့အတွက် WSL Ubuntu 22.04 terminal အသစ်ကို ဖွင့်နိုင်ပါတယ်။ workdir အောက် "build/conf" directory သို့ သွားပြီး "local.conf" ကို သင့်ရဲ့ ကြိုက်နှစ်သက်ရာ editor နဲ့ ဖွင့်ပါ၊ ဥပမာအားဖြင့်။

# navigate to work dir
cd /workdir
cd build/conf
nano local.conf 
# or if you prefer to use Visual Studio Code
# code local.conf 


လိုင်းနံပါတ် ၃၃ လောက်မှာ MACHINE ?= "beaglebone-yocto" ဆိုတဲ့ line ကို uncomment လုပ်ပါ။

MACHINE ?= "beaglebone-yocto"
#MACHINE ?= "genericarm64"
#MACHINE ?= "genericx86"


ပြီးရင် သင့်ရဲ့ build environment console ကို ပြန်သွားပြီး BitBake command ကို ထပ်မံ run ပါ။

bitbake -k core-image-minimal


Build လုပ်တာ ပြီးရင်၊ ရလာတဲ့ image ကို ရှာဖွေပြီး micro SD card တစ်ခုထဲကို flash လုပ်နိုင်ပါတယ်။ ဝင်းဒိုး file explorer မှာ "Linux > Ubuntu-22.04 " ကို သွားပြီး build directory ကို ဖွင့်ပါ။ ပြီးရင် "tmp/deploy/images/beaglebone-yocto" ကို သွားပြီး .wic extension နဲ့ အကြီးဆုံးဖိုင်ကို ရှာပါ။ နမူနာ အနေနဲ့ ဆိုရင် အောက်မှာ ဖော်ပြထားတဲ့ လမ်းကြောင်း ဖြစ်ပါတယ်။

\\wsl.localhost\Ubuntu-22.04\workdir\build\tmp\deploy\images\beaglebone-yocto


ပြီးရင် အဲဒီ ဖိုင်ကို ဝင်းဒိုး folder တစ်ခုထဲကို ကူးပါ၊ ဥပမာအားဖြင့် Downloads folder ထဲကို။ ပြီးရင် balenaEtcher ကို အသုံးပြုပြီး အဲဒီ image ကို micro SD card တစ်ခုထဲကို flash လုပ်နိုင်ပါတယ်။


Figure 3. Using balenaEtcher to flash the image onto a micro SD card.


BBB နဲ့ ဆက်ဖို့ အတွက် ဆိုရင် serial console ကို သုံးနိုင်ပါတယ်။ FTDI ကြိုးတစ်ခုကို BeagleBone Black ရဲ့ J1 header ကို ချိတ်ဆက်ပါ၊ အနက်ရောင် GND ကြိုးကို pin 1 နဲ့ ချိတ်ဆက်ထားဖို့ သေချာပါစေ၊ ဒါက သေးငယ်တဲ့ '.' အမှတ်နားမှာ တည်ရှိပါတယ်။ ပြီးရင် PuTTY ဒါမှမဟုတ် Tera Term ကို အသုံးပြုပြီး COM port ကို ချိတ်ဆက်ပါ၊ baud rate ကို 115200 အဖြစ် သတ်မှတ်ပါ။

Figure 4. Connecting to the serial console.

ရလာတဲ့ image ကို flash လုပ်ပြီးရင် microSD card ကို Beaglebone Black (BBB) ထဲကို ထည့်ပါ၊ ပြီးရင် 5V power supply တစ်ခုကို ပြင်ဆင်ပြီး board ကို power on လုပ်ပါ။ ပုံမှန်အားဖြင့် BBB သည် onboard eMMC မှ boot လုပ်သည်။ SD card မှ boot လုပ်ရန် S2 boot button (USB port နားတွင် တည်ရှိသည်) ကို board ကို power on လုပ်နေစဉ် ဖိထားပါ။

Figure 5. The FTDI connector J1 and the boot button S2 on BBB.

Login prompt beaglebone-yocto login: ပေါ်လာတဲ့အခါမှာ username အဖြစ် root ကို ထည့်ပါ။ Password မလိုပါ။

Figure 6. Bealebone yocto console.



Raspberry Pi

Board Support Package (BSP) layer မှာ bootloader, device tree blobs, drivers, firmware, နဲ့ additional software များပါဝင်ပါတယ်။ Yocto ထဲမှာ သက်ဆိုင်ရာ hardware device သို့မဟုတ် device family အတွက် support ပေးဖို့ပါ။ စက်တစ်ခု အတွက် layer နာမည် က များသော အားဖြင့် meta- နဲ့ စပါတယ်။ OpenEmbedded Layer Index မှာ ရနိုင်တဲ့ layers တွေကို ရှာဖွေနိုင်ပါတယ်။

BSP layers တွေနဲ့၊ တခြား layers တွေကိုလည်း အောက်က ဒီ GitHub repositories တွေ မှာ ရှာဖွေနိုင်ပါတယ်။

Raspberry Pi အတွက် poky directory ရဲ့ အထက်မှာရှိတဲ့ working directory သို့ သွားပါ၊ BSP meta-raspberrypi layer နဲ့ အခြား dependency layers တွေရဲ့ သက်ဆိုင်ရာ branch ကို clone လုပ်ပါ။

# navigate to workdir 
cd /workdir
git clone git://git.yoctoproject.org/meta-raspberrypi -b scarthgap
git clone git://git.openembedded.org/meta-openembedded -b scarthgap


ပြီးရင် workdir directory ကို ပြန်သွားပြီး Raspberry Pi အတွက် build environment အသစ်ကို build-rpi ဆိုတဲ့ directory name နဲ့ အောက်ပါ အတိုင် set up လုပ်ပါ။

source poky/oe-init-build-env build-rpi 


အဲဒီ script က "build-rpi" directory ကို ဖန်တီးပြီး "build/conf" အတွင်းမှာ "local.conf" ဆိုတဲ့ local configuration file ကို generate လုပ်ပါတယ်။ Bitbake layers ကို ပြန်စစ်ဖို့အတွက် အောက်ပါ command ကို run ပါ။

bitbake-layers show-layers


ပြီးရင် meta-raspberrypi အပါအဝင် လိုအပ်တဲ့ layers တွေကို အောက်ပါအတိုင်း မှန်ကန်တဲ့ အစီအစဉ်နဲ့ ထည့်ဖို့ လိုပါတယ်။

# need ../ infront because the layers are in the dir 1 levels above the build dir
bitbake-layers add-layer ../meta-openembedded/meta-oe 
bitbake-layers add-layer ../meta-openembedded/meta-python 
bitbake-layers add-layer ../meta-openembedded/meta-networking 
bitbake-layers add-layer ../meta-openembedded/meta-multimedia
bitbake-layers add-layer ../meta-raspberrypi
bitbake-layers show-layers


BitBake layers တွေကို နောက်တစ်ခါ ပြန်ထပ်စစ်ကြည့်လိုက်ရင် စုစုပေါင်း ၈ လွှာ ရှိသင့်ပါတယ်။ ပြီးရင် meta-raspberrypi မှာ ထောက်ပံ့ထားတဲ့ machines တွေကို စစ်ကြည့်ပါ။

ls ../meta-raspberrypi/conf/machine 


Raspberry Pi 5 အတွက် build လုပ်ဖို့အတွက် conf/local.conf ဖိုင်ကို edit လုပ်ပြီး beaglebone-yocto configuration ရဲ့ အနားမှာ အောက်ပါလိုင်းကို ထည့်ပါ၊

nano conf/local.conf


သင့်ရဲ့ hardware board အညီ အလိုက်သင့် ပြင်ဆင်နိုင်ပါတယ်။

MACHINE ?= "raspberrypi5"


အဲ့က default machine line ကိုလည်း comment လုပ် ပေးလိုက်ပါ။

# MACHINE ??= "qemux86-64"


နောက်ထပ် ssh-server-openssh ကို conf/local.conf ဖိုင်ရဲ့ line 150 နားက EXTRA_IMAGE_FEATURES variable မှာ ထည့်ပါ။

EXTRA_IMAGE_FEATURES ?= "debug-tweaks ssh-server-openssh"


ပုံမှန်က commercial or restricted licenses များကို ခွင့်ပြုထားခြင်းမရှိပါ။ သတ်မှတ်ထားသော restricted licenses များကို ဖွင့်ရန်၊ ဥပမာ synaptics-killswitch ကို ဖွင့်ရန် local.conf ဖိုင်ထဲမှာ အောက်ပါလိုင်းကို ထည့်ပါ။

LICENSE_FLAGS_ACCEPTED = "synaptics-killswitch"


Raspberry Pi 5 မှာ HDMI connectors နှစ်ခုကြားမှာ UART debug port [2, 3] ပါ ပါတယ်။ သူ့ရဲ့ serial console က အမြဲတမ်း enabled ဖြစ်ပြီးသားပါ။ အရင် Raspberry Pi အဟောင်းတွေ အတွက် ဆိုရင် တော့ GPIO header က UART ကို enable လုပ်ဖို့ အောက်က လိုင်းကို local.conf ဖိုင် ထဲမှာ ထည့်ပါ။

ENABLE_UART = "1"


ပြီးရင် local.conf ဖိုင်ကို သိမ်းပြီး ထွက်ပါ။ ရနိုင်တဲ့ image recipes တွေကို ကြည့်ဖို့ အောက်ပါ command ကို run ပါ။

ls ../meta-raspberrypi/recipes-core/images/


နောက်ဆုံးမှာ Raspberry Pi 5 အတွက် rpi-test-image ကို build လုပ်ဖို့ အောက်ပါ BitBake command ကို run ပါ။

bitbake rpi-test-image


စက်ပေါ် မမူတည်တဲ့ core-image-minimal လို machine-agnostic images တွေကိုလည်း အသုံးပြုနိုင်ပါတယ်။ Build လုပ်တာ အောင်အောင်မြင်မြင် ပြီးသွားရင် ရလာမယ့် "rpi-test-image-raspberrypi5.rootfs-yyyymmddhhmmss.wic.bz2" ဆိုတဲ့ image ဖိုင်ကို အောက်ပါ directory မှာ ရှာဖွေနိုင်ပါတယ်။
\\wsl.localhost\Ubuntu-22.04\workdir\build-rpi\tmp\deploy\images\raspberrypi5

အဲဒီ image ဖိုင်ကို Downloads folder လိုမျိုး Windows folder တစ်ခုထဲသို့ ကူးပါ၊ ထို့နောက် wic image ကို ရယူရန် extract လုပ်ပါ။ နောက် နည်းလမ်းတစ်ခုက WSL မှာ extract လုပ်ပြီး ကူးလို့လည်း ရပါတယ်။
cd /workdir/build-rpi/tmp/deploy/images/raspberrypi5
ls *.wic.bz2
cp rpi-test-image-raspberrypi5.rootfs-yyyymmddhhmmss.wic.bz2 rpi-img.wic.bz2 
bunzip2 rpi-img.wic.bz2 
ls *.wic
cp  rpi-img.wic /mnt/c/Users/username/Downloads/

ပြီးရင်တော့ image ဖိုင်ကို microSD ကတ်ပေါ်မှာ flash လုပ်ဖို့ balenaEtcher ကို အသုံးပြုပါ၊

Raspberry Pi အတွက် USB-C power connector နားမှာ ရှိတဲ့ ပထမ HDMI port ကို display တစ်ခုကို ချိတ်ဆက်ပါ။ Console သုံးဖို့ USB ports တွေမှာလည်း keyboard နှင့် mouse ကို ချိတ်ဆက်ပါ၊ ။

ဒါမှမဟုတ်ရင် လည်း Raspberry Pi Debug Probe ကို Raspberry Pi ရဲ့ UART port နဲ့ ချိတ်ဆက်ပြီး serial console ကို အသုံးပြုနိုင်ပါတယ်။

Figure 7. Connecting a USB to UART cable to the Raspberry Pi's UART port.

အရင် Raspberry Pi မော်ဒယ်များအတွက် FTDI cable ကို GPIO header pins တွေနဲ့ အောက်က ပုံမှာ ပြထားသလို ချိတ်ဆက် နိုင်ပါတယ်။

Figure 8. Connecting an FTDI cable to the Raspberry Pi's header.

USB-C connector ကနေ power supply ပေးပြီးရင် login prompt raspberrypi5 login: မှာ username အနေနဲ့ root ကို ရိုက်ထည့်ပါ။ Password မလိုပါဘူး။

Figure 9. Raspberry Pi 5 yocto console.

သင့် Raspberry Pi က network နဲ့ ချိတ်ဆက်ထားရင် IP address ကို ရှာဖွေရန် အောက်ပါ command ကို run ပါ။

ifconfig


SSH ချိတ်ဆက် သုံးမယ် ဆိုရင် PuTTY ကို အသုံးပြုလို့ လည်း ရပါတယ်။
  • connection type အတွက် SSH ကို ရွေးပါ၊
  • IP address သို့မဟုတ် hostname "raspberrypi5.local" ကို ရိုက်ထည့်ပါ။
  • Port ကို 22 သတ်မှတ်ပါ။
  • ပြီးရင် Raspberry Pi ကို ချိတ်ဆက်လို့ရပါပြီ။


Adding a Custom Layer

သင့်ရဲ့ custom image မှာ packages တွေကို ထည့်သွင်းဖို့ IMAGE_INSTALL variable ကို local.conf ဖိုင်ထဲမှာ append လုပ်နိုင်ပါတယ်။ local.conf ဖိုင်ကတော့ သင့်ရဲ့ build directory အောက်က 'conf' folder ထဲမှာ ရှိပါတယ်။ ဥပမာ nano text editor ကို သင့်ရဲ့ custom image ထဲမှာ ပါချင်ရင် nano ရဲ့ အရှေ့မှာ space တစ်ခု ထည့်ပြီး အောက်ပါ အတိုင်း append လုပ်နိုင်ပါတယ်။

IMAGE_INSTALL:append = " nano"


ပြီးရင် သင့် image ထဲမှာ predefined image features တွေကို enable လုပ်နိုင်ပါတယ်။ ၎င်းတို့က packages များသို့မဟုတ် configuration tweaks များကို pull in လုပ်ပေးပါတယ်။ ဥပမာ၊ SSH server နှင့် development tools များကို enable လုပ်ဖို့ အောက်ပါ အတိုင်း append လုပ်နိုင်ပါတယ်။

EXTRA_IMAGE_FEATURES ?= "debug-tweaks ssh-server-openssh tools-sdk"


သင့် Yocto build environment မှာ custom layer တစ်ခု ထည့်ရန် bitbake-layers command တစ်ခု ဖြစ်တဲ့ create-layer နဲ့ အောက်ပါအတိုင်း ထည့်နိုင်ပါတယ်။

# navigate to work dir
cd /workdir
# navigate to build dir or create build env if you hanen't done so
source poky/oe-init-build-env build-rpi 
bitbake-layers create-layer ../meta-myapp


အဲ့ဒီ command က workspace directory မှာ meta-myapp ဆိုတဲ့ layer အသစ်တစ်ခု ဖန်တီးပေးပါတယ်။ အသစ်ရလာတဲ့ layer directory သို့ သွားရောက်ပြီး structure ကို စစ်ဆေးနိုင်သလို၊ recipe directory နှင့် file names များကို လိုအပ်သလို အောက်ပါ နမူနာအတိုင်း ပြောင်းလဲနိုင်ပါတယ်။

cd /workdir/meta-myapp
tree
mv recipes-example recipes-myapp
cd recipes-myapp
mv example myapp
cd myapp
mv example_0.1.bb myapp_0.1.bb
mkdir -p files
cd files


ပြီးရင် myapp.cpp ဆိုတဲ့ C++ source file ကို 'files' directory အတွင်း ဖန်တီးပါ။

   
#include < iostream >
int main() {
    std::cout << "myapp: Hello Yocto World!" << std::endl;
    return 0;
}


နောက် meta-myapp directory ထဲက COPYING.MIT file ရဲ့ md5 checksum ကိုလည်း စစ်ကြည့်နိုင်ပါတယ်။

   
md5sum ../../../COPYING.MIT


နောက် အဆင့် အနေဖြင့် အပေါ် directory ထဲက myapp_0.1.bb ဆိုတဲ့ recipe file ကို အောက်ပါအတိုင်း ပြင်ဆင်ပါ။

   
SUMMARY = "Simple myapp application"
DESCRIPTION = "myapp test"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://../../../COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"

SRC_URI = "file://myapp.cpp \
           file://../../../COPYING.MIT"

S = "${WORKDIR}"

do_compile() {
    ${CXX} ${CXXFLAGS} ${LDFLAGS} -o myapp myapp.cpp
}

do_install() {
    install -d ${D}${bindir}
    install -m 0755 myapp ${D}${bindir}
}


နောက် application ကို သင့်ရဲ့ local.conf ဖိုင်ထဲမှာ ထည့်ပါ:

IMAGE_INSTALL:append = " nano myapp"


ပြီးရင် layer အသစ်ဖြစ်တဲ့ meta-myapp ကို သင့်ရဲ့ build environment ထဲမှာ ထည့်ပါ။ ထို့နောက် image ကို build ပြန်လုပ်ပါ:

   
cd /workdir/build-rpi
bitbake-layers add-layer ../meta-myapp
bitbake myapp
bitbake rpi-test-image


ရလာတဲ့ image ကို deploy လုပ်ပြီးရင် သင့် application ကို စမ်းသပ်နိုင်ပါတယ်:

   
my-app


သင့် program ထဲက အတိုင်း "myapp: Hello Yocto World!" ဆိုတဲ့ message ကို print ထုတ်ပေးပါလိမ့်မယ်။

Using wxWidgets

wxwidgets recipe က meta-oe layer (OpenEmbedded layer) ထဲမှာ ရှိတာမို့၊ သင့်ရဲ့ build environment ထဲမှာ meta-oe layer ကို Raspberry Pi section မှာ ပြောခဲ့ တဲ့ အတိုင်း သွင်းထားပါ။ ပြီးရင် တော့ wxwidgets application အတွက် layer အသစ်တစ်ခု ပြီးခဲ့ တဲ့ အပိုင်း က အတိုင်းပဲ ဖန်တီးနိုင်ပါတယ်။

cd /workdir/build-rpi
bitbake-layers create-layer ../meta-wxapp


WSL console မှာ ဖန်တီးထားတဲ့ directory သို့ သွားပြီး directory နှင့် file များကို လိုအပ်သလို ပြောင်းလဲနိုင်ပါတယ်။

cd /workdir/meta-wxapp
tree
mv recipes-example recipes-wxapp
cd recipes-wxapp
mv example wxapp
cd wxapp
mv example_0.1.bb wxapp_0.1.bb
mkdir -p files
cd files


နောက် wxapp.cpp ဆိုတဲ့ C++ source file ကို 'files' directory အတွင်း ဖန်တီးပါ။

#include < wx/wx.h >
class Simple : public wxFrame
{
public:
    Simple(const wxString& title);

};
Simple::Simple(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150))
{
  Centre();
}

class MyApp : public wxApp
{
  public:
    virtual bool OnInit();
};

IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
    Simple *simple = new Simple(wxT("Simple"));
    simple->Show(true);

    return true;
}


နောက် recipe file wxapp_0.1.bb ကို အောက်ပါအတိုင်း ပြင်ဆင်ပါ:

SUMMARY = "Simple wxapp application"
DESCRIPTION = "wxapp test"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://../../../COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"

SRC_URI = "file://wxapp.cpp \
           file://../../../COPYING.MIT"

DEPENDS += "wxwidgets"
inherit pkgconfig
S = "${WORKDIR}"

do_compile() {
    wx-config --version
    ${CXX}  ${CXXFLAGS} ${LDFLAGS} wxapp.cpp -o wxapp `wx-config --cxxflags --libs`
}

do_install() {
    install -d ${D}${bindir}
    install -m 0755 wxapp ${D}${bindir}
}


ပြီးတဲ့ အခါမှာတော့ mesa အတွက် patch လုပ်ပြီး wxwidgets နှင့် wxapp applications ကို IMAGE_INSTALL မှာ append လုပ်ပါ:

DEPENDS:append:pn-mesa = " libxshmfence"
IMAGE_INSTALL:append = " libxshmfence wxwidgets wxapp"


နောက်ဆုံးမှာ တော့ layer အသစ်ကို သင့်ရဲ့ build environment ထဲမှာ ထည့်ပါ။ ထို့နောက် GUI environment ပါတဲ့ core-image-weston image ကို build လုပ်ပါ။

   
# navigate back to build directory
cd /workdir/build-rpi
bitbake-layers add-layer ../meta-wxapp
bitbake wxapp
bitbake core-image-weston


အဲဒီ build ပြီးသွားတာနဲ့၊ ရလာတဲ့ image ကို microSD ကတ်ပေါ်မှာ flash လုပ်နိုင်ပါတယ်။ ပထမ HDMI port ကို display တစ်ခု ချိတ်ဆက်ပြီး Raspberry Pi 5 ကို power on လုပ်ပါ။ အောက်က ပုံမှာ terminal ကို ဖွင့် ပြီး၊ wxapp ဆိုတဲ့ command ရိုက်ထည့်တာကို ပြထားပါတယ်။

Figure 10. Running wxapp on core-image-weston.



Making an Image Recipe

Local configuration တွေ ပြင်မယ့် အစား၊ ပြန်သုံးလို့ ရတဲ့ image recipe တစ်ခု ဖန်တီးနိုင်ပါတယ်။ Image recipes တွေက ပုံမှန်အားဖြင့် images directory ထဲမှာ ရှိပြီး၊ အောက်ပါအတိုင်း list လုပ်နိုင်ပါတယ်။

   
# from workdir
ls ./*/meta*/recipe*/images*/*.bb


myapp-image.bb ဆိုတဲ့ ဖိုင်တစ်ခုကို meta-myapp/recipes-local/images directory အတွင်း ဖန်တီးပါ။

   
cd /workdir
cd meta-myapp 
mkdir -p recipes-local/images
cd recipes-local/images 
cd images 
nano myapp-image.bb


အထဲမှာ base image ကို include လုပ်ပြီး conf/local.conf မှာ ပြင်ဆင်ခဲ့တဲ့ ပြင်ဆင်မှုတွေကို ထည့်ပါ။ Recipe က အောက်ပါအတိုင်း ဖြစ်နိုင်ပါတယ်။

   
require recipes-core/images/core-image-minimal.bb
# require recipes-graphics/images/core-image-weston.bb
IMAGE_INSTALL += "wxwidgets nano myapp"


နောက်ဆုံးမှာတော့ build environment ကို ပြင်ဆင်ပြီး meta-myapp layer ကို ထည့်သွင်းပြီးနောက်၊ အောက်ပါ command ကို အသုံးပြု၍ image ကို build လုပ်ပါ။

   
# The commented commands are only necessary if you haven't already 
# set up the environment and added the layer
# Navigate to your working directory
# cd /workdir
# Initialize the build environment for your build directory
# source poky/oe-init-build-env build-rpi
# Add the meta-myapp layer to your build configuration
# bitbake-layers add-layer ../meta-myapp

# Build your custom image
bitbake myapp-image


ဒီ myapp-image အတွက် ဆိုရင် local.conf ထဲသွားပြီး IMAGE_INSTALL:append line မှာ package တွေကို ထည့်ရန် မလိုတော့ပါ။

Generating an SDK

သင့်ရဲ့ image အတွက် SDK ကို bitbake သုံးပြီး populate_sdk နဲ့ generate လုပ်နိုင်ပါတယ်။

   
bitbake -c populate_sdk myapp-image


အဲဒီ command က toolchain ကို generate လုပ်ပြီး development libraries နဲ့ include files တွေကို target အတွက် ထည့်သွင်းပေးပါတယ်။ SDK installer script ကိုလည်း အောက်ပါ directory ထဲမှာ ထည့်သွင်းပေးပါတယ်။

   
tmp/deploy/sdk 


အဲဒီ script ရဲ့ နာမည်က machine နဲ့ settings ပေါ်မူတည်ပြီး၊ ဒီနမူနာ မှာ တော့ အောက်ပါအတိုင်း ဖြစ်ပါတယ်။

   
poky-glibc-x86_64-myapp-image-cortexa76-raspberrypi5-toolchain-5.0.11.sh


ဒီ script ကို share လို့ရပြီး၊ သင့်ရဲ့ host system ပေါ်မှာ run လိုက်ရင် SDK ကို install လုပ်နိုင်ပါတယ်။ သူ့ရဲ့ default installation directory က /opt/poky/5.0.11 ဖြစ်ပါတယ်။ SDK သုံးမယ် ဆိုရင် အောက်က command ကို run ပြီး environment ကို setup လုပ်ဖို့ လိုပါတယ်။

   
source /opt/poky/5.0.11/environment-setup-cortexa76-poky-linux


Toolchain environment ကို setup လုပ်ဖို့ terminal window အသစ် တစ်ခု ဖွင့်ဖို့ အကြံပြုပါတယ်။ လက်ရှိ terminal က build environment နဲ့ conflict မဖြစ်အောင် လို့ပါ။ Toolchain environment ကို setup လုပ်ခြင်းက $CC ကို C compiler အတွက်၊ $CXX ကို C++ compiler အတွက် environment variables တွေကို သတ်မှတ်ပေးပါတယ်။ C++ compiler variable ကို verify လုပ်ချင်ရင် အောက်ပါ command ကို run လုပ်နိုင်ပါတယ်။

   
echo $CXX


နောက်တော့ hello.cpp ဆိုတဲ့ C++ program လေးကို ဖန်တီးပါ။ အဲဒီ program က "hello" ဆိုတဲ့ string ကို print ထုတ်ဖို့ ရည်ရွယ်ထားပါတယ်။ အောက်ပါ command ကို အသုံးပြု၍ cross-compile လုပ်ပါ။

   
$CXX hello.cpp -o hello


Compile လုပ်ပြီးတဲ့ အခါ ရလာတဲ့ binary file ကို target machine ပေါ်ကို transfer လုပ်ပါ၊ အဲဒီမှာ အဆင်ပြေစွာ run လို့ ရပါလိမ့်မယ်။

References



[1] Microsoft. Set up a WSL development environment. 2025.
url: https://learn.microsoft.com/en-us/windows/wsl/setup/environment.

[2] Raspberry Pi. Raspberry Pi 3-pin Debug Connector Specification.
url: https://rptl.io/debug-spec.

[3] Raspberry Pi. Raspberry Pi Debug Probe.
url: https://www.raspberrypi.com/documentation/microcontrollers/debug-probe.html.

[4] Docker. Install Docker Engine on Ubuntu.
url: https://docs.docker.com/engine/install/ubuntu/.

[5] Docker. GitHub repository docker/docker-install.
url: https://github.com/docker/docker-install.

[6] crops. poky-container.
url: https://github.com/crops/poky-container.

No comments:

Post a Comment