Skip to content

Instantly share code, notes, and snippets.

@bernardoaraujor
Last active March 23, 2023 02:49
Show Gist options
  • Save bernardoaraujor/6a7e34dee883803a2624dec0b65cd378 to your computer and use it in GitHub Desktop.
Save bernardoaraujor/6a7e34dee883803a2624dec0b65cd378 to your computer and use it in GitHub Desktop.
openembedded de10-nano

Building UBoot, linux-altera and core-image-minimal rootfs

1 - Clone poky and meta-altera (thud branch for both):

$ mkdir ~/yocto; cd ~/yocto
$ git clone git://git.yoctoproject.org/poky.git -b thud
$ git clone https://github.com/kraj/meta-altera -b thud

2 - Start a build environment:

$ cd poky
$ source oe-init-build-env

3 - Inform BitBake about meta-altera:

$ cat conf/bblayers.conf 
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
  /home/bernardo/yocto/poky/meta \
  /home/bernardo/yocto/poky/meta-poky \
  /home/bernardo/yocto/poky/meta-yocto-bsp \
  /home/bernardo/yocto/meta-altera \
  "

4 - Add these lines to conf/local.conf:

MACHINE = "cyclone5"
UBOOT_CONFIG = "de0-nano-soc"
UBOOT_EXTLINUX_FDT_default = "../socfpga_cyclone5_de0_nano_soc.dtb"
KERNEL_DEVICETREE = "socfpga_cyclone5_de0_nano_soc.dtb"
IMAGE_INSTALL_append = " openssh"
PREFERRED_PROVIDER_virtual/kernel = "linux-altera-ltsi"

5 - Start building:

$ bitbake core-image-minimal

6 - Find U-Boot, linux-altera and core-image-minimal rootfs:

bernardo@bernardo-UX51VZA:~/dev/yocto/poky/build$ ls tmp/deploy/images/cyclone5/
core-image-minimal-cyclone5-20191130125011.rootfs.cpio
core-image-minimal-cyclone5-20191130125011.rootfs.ext3
core-image-minimal-cyclone5-20191130125011.rootfs.jffs2
core-image-minimal-cyclone5-20191130125011.rootfs.manifest
core-image-minimal-cyclone5-20191130125011.rootfs.tar.gz
core-image-minimal-cyclone5-20191130125011.rootfs.wic
core-image-minimal-cyclone5-20191130125011.testdata.json
core-image-minimal-cyclone5.cpio
core-image-minimal-cyclone5.ext3
core-image-minimal-cyclone5.jffs2
core-image-minimal-cyclone5.manifest
core-image-minimal-cyclone5.tar.gz
core-image-minimal-cyclone5.testdata.json
core-image-minimal-cyclone5.wic
extlinux.conf
extlinux.conf-cyclone5
extlinux.conf-cyclone5-r0
modules--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.tgz
modules-cyclone5.tgz
socfpga_cyclone5_de0_nano_soc--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.dtb
socfpga_cyclone5_de0_nano_soc-cyclone5.dtb
socfpga_cyclone5_de0_nano_soc.dtb
socfpga_cyclone5_mcvevk--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.dtb
socfpga_cyclone5_mcvevk-cyclone5.dtb
socfpga_cyclone5_mcvevk.dtb
socfpga_cyclone5_socdk--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.dtb
socfpga_cyclone5_socdk-cyclone5.dtb
socfpga_cyclone5_socdk.dtb
socfpga_cyclone5_sockit--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.dtb
socfpga_cyclone5_sockit-cyclone5.dtb
socfpga_cyclone5_sockit.dtb
socfpga_cyclone5_socrates--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.dtb
socfpga_cyclone5_socrates-cyclone5.dtb
socfpga_cyclone5_socrates.dtb
socfpga_cyclone5_sodia--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.dtb
socfpga_cyclone5_sodia-cyclone5.dtb
socfpga_cyclone5_sodia.dtb
socfpga_cyclone5_trcom--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.dtb
socfpga_cyclone5_trcom-cyclone5.dtb
socfpga_cyclone5_trcom.dtb
socfpga_cyclone5_vining_fpga--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.dtb
socfpga_cyclone5_vining_fpga-cyclone5.dtb
socfpga_cyclone5_vining_fpga.dtb
u-boot-cyclone5.sfp
u-boot-cyclone5.sfp-cyclone5-socdk
u-boot-cyclone5-socdk-v2019.01+gitAUTOINC+d3689267f9-r0.sfp
u-boot-with-spl.sfp
u-boot-with-spl.sfp-cyclone5-socdk
zImage
zImage--5.0+git0+0ac4bbee4a-r0-cyclone5-20191130125011.bin
zImage-cyclone5.bin

Building SDK for DE10-nano

1 - You'll need the same setup needed to build UBoot, linux-altera and core-image-minimal (described above). However, on step 5, instead of telling bitbake to build an image, tell it to populate an SDK:

$ bitbake core-image-minimal -c populate_sdk

2 - Install the SDK into your development host:

$ ./tmp/deploy/sdk/poky-glibc-x86_64-core-image-minimal-armv7at2hf-neon-toolchain-2.6.4.sh
Poky (Yocto Project Reference Distro) SDK installer version 2.6.4
=================================================================
Enter target directory for SDK (default: /opt/poky/2.6.4): 
You are about to install the SDK to "/opt/poky/2.6.4". Proceed[Y/n]? 
Extracting SDK..................................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
 $ . /opt/poky/2.6.4/environment-setup-armv7at2hf-neon-poky-linux-gnueabi

3 - Now, everytime you want to cross-compile some linux application for the DE10-nano HPS, you need to load the build environment. Don't do this in the same terminal you ran BitBake, to avoid mixing different build environments.

$ source /opt/poky/2.6.4/environment-setup-armv7at2hf-neon-poky-linux-gnueabi

Flashing the SD Card with built UBoot, linux-altera and core-image-minimal rootfs

1 - Insert the SD card on your desktop/laptop. In my case it showed up as /dev/sdc, might be something else for you. One way to find out is to use de lsblk command before and after inserting the SD card. Note that my SD shows up as /dev/sdc(along with my Ubuntu and Fedora HDs)

$ lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdb               8:16   0 238,5G  0 disk 
├─sdb2            8:18   0 230,1G  0 part /
├─sdb3            8:19   0   7,9G  0 part [SWAP]
└─sdb1            8:17   0   512M  0 part 
sda               8:0    0 238,5G  0 disk 
├─sda2            8:2    0     1G  0 part 
├─sda3            8:3    0 237,3G  0 part 
│ ├─fedora-home 253:1    0 179,5G  0 lvm  
│ ├─fedora-root 253:2    0    50G  0 lvm  
│ └─fedora-swap 253:0    0   7,8G  0 lvm  
└─sda1            8:1    0   200M  0 part /boot/efi
$
$ lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdb               8:16   0 238,5G  0 disk 
├─sdb2            8:18   0 230,1G  0 part /
├─sdb3            8:19   0   7,9G  0 part [SWAP]
└─sdb1            8:17   0   512M  0 part 
sdc               8:32   1  14,4G  0 disk 
└─sdc1            8:33   1  14,4G  0 part 
sda               8:0    0 238,5G  0 disk 
├─sda2            8:2    0     1G  0 part 
├─sda3            8:3    0 237,3G  0 part 
│ ├─fedora-home 253:1    0 179,5G  0 lvm  
│ ├─fedora-root 253:2    0    50G  0 lvm  
│ └─fedora-swap 253:0    0   7,8G  0 lvm  
└─sda1            8:1    0   200M  0 part /boot/efi

2 - Yocto provides a really useful tool called wic that packs up all the necessary build artifacts into a single .wicfile that already contains the partitioning scheme for the SD card or eMMC. The meta-altera BSP already gets BitBake to write a .wic image file. So all we need to do is use dd to flash the image file into the SD card.

$ cd ${HOME}/yocto/build/tmp/deploy/images/cyclone5/
$ sudo dd if=core-image-minimal-cyclone5.wic of=/dev/sdc bs=4M; sync
[sudo] password for bernardo: 
10+1 records in
10+1 records out
43550720 bytes (44 MB, 42 MiB) copied, 5,76661 s, 7,6 MB/s
$ sync
@marklin23
Copy link

Hello Sir,
I am a beginner of embedded developer and I got error at step 5 " bitbake core-image-minimal.
I want to double-check is step4 FILE: conf/local.conf is in yocto/poky/build/ directory?

Following is the error message in terminal:

ERROR: Nothing PROVIDES 'virtual/kernel'
linux-altera-ltsi PROVIDES virtual/kernel but was skipped: Set PREFERRED_PROVIDER_virtual/kernel to linux-altera-ltsi to enable it
linux-altera-lts PROVIDES virtual/kernel but was skipped: Set PREFERRED_PROVIDER_virtual/kernel to linux-altera-lts to enable it
linux-altera-lts PROVIDES virtual/kernel but was skipped: Set PREFERRED_PROVIDER_virtual/kernel to linux-altera-lts to enable it
linux-altera-ltsi-rt PROVIDES virtual/kernel but was skipped: Set PREFERRED_PROVIDER_virtual/kernel to linux-altera-ltsi-rt to enable it
linux-yocto PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-tiny PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-tiny PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-rt PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-rt PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-dev PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-dummy PROVIDES virtual/kernel but was skipped: PREFERRED_PROVIDER_virtual/kernel set to linux-altera, not linux-dummy
ERROR: Required build target 'core-image-minimal' has no buildable providers.
Missing or unbuildable dependency chain was: ['core-image-minimal', 'virtual/kernel']

@bernardoaraujor
Copy link
Author

Hello Sir,
I am a beginner of embedded developer and I got error at step 5 " bitbake core-image-minimal.
I want to double-check is step4 FILE: conf/local.conf is in yocto/poky/build/ directory?

Following is the error message in terminal:

ERROR: Nothing PROVIDES 'virtual/kernel'
linux-altera-ltsi PROVIDES virtual/kernel but was skipped: Set PREFERRED_PROVIDER_virtual/kernel to linux-altera-ltsi to enable it
linux-altera-lts PROVIDES virtual/kernel but was skipped: Set PREFERRED_PROVIDER_virtual/kernel to linux-altera-lts to enable it
linux-altera-lts PROVIDES virtual/kernel but was skipped: Set PREFERRED_PROVIDER_virtual/kernel to linux-altera-lts to enable it
linux-altera-ltsi-rt PROVIDES virtual/kernel but was skipped: Set PREFERRED_PROVIDER_virtual/kernel to linux-altera-ltsi-rt to enable it
linux-yocto PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-tiny PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-tiny PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-rt PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-rt PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-yocto-dev PROVIDES virtual/kernel but was skipped: incompatible with machine cyclone5 (not in COMPATIBLE_MACHINE)
linux-dummy PROVIDES virtual/kernel but was skipped: PREFERRED_PROVIDER_virtual/kernel set to linux-altera, not linux-dummy
ERROR: Required build target 'core-image-minimal' has no buildable providers.
Missing or unbuildable dependency chain was: ['core-image-minimal', 'virtual/kernel']

Hello @marklin23. Thanks for reporting the error.
Add this extra line to conf/local.conf:

PREFERRED_PROVIDER_virtual/kernel = "linux-altera-ltsi"

I fixed it in the steps above.

Yes, conf/local.conf is inside yocto/poky/build.

@marklin23
Copy link

Thank you @bernardoaraujor. But I encounter bibake an error when system can't find 'socfpga_cyclone5_de0_nano_soc.dtb' that I add in conf/local.conf

Error message as below:
Kernel: arch/arm/boot/zImage is ready
NOTE: make -j 2 HOSTCC=gcc -isystem/home/mark/yocto/poky/build/tmp/work/cyclone5-poky-linux-gnueabi/linux-altera-ltsi/4.14.130-ltsi+gitAUTOINC+78cbce0ccb-r0/recipe-sysroot-native/usr/include -O2 -pipe -L/home/mark/yocto/poky/build/tmp/work/cyclone5-poky-linux-gnueabi/linux-altera-ltsi/4.14.130-ltsi+gitAUTOINC+78cbce0ccb-r0/recipe-sysroot-native/usr/lib -L/home/mark/yocto/poky/build/tmp/work/cyclone5-poky-linux-gnueabi/linux-altera-ltsi/4.14.130-ltsi+gitAUTOINC+78cbce0ccb-r0/recipe-sysroot-native/lib -Wl,-rpath-link,/home/mark/yocto/poky/build/tmp/work/cyclone5-poky-linux-gnueabi/linux-altera-ltsi/4.14.130-ltsi+gitAUTOINC+78cbce0ccb-r0/recipe-sysroot-native/usr/lib -Wl,-rpath-link,/home/mark/yocto/poky/build/tmp/work/cyclone5-poky-linux-gnueabi/linux-altera-ltsi/4.14.130-ltsi+gitAUTOINC+78cbce0ccb-r0/recipe-sysroot-native/lib -Wl,-rpath,/home/mark/yocto/poky/build/tmp/work/cyclone5-poky-linux-gnueabi/linux-altera-ltsi/4.14.130-ltsi+gitAUTOINC+78cbce0ccb-r0/recipe-sysroot-native/usr/lib -Wl,-rpath,/home/mark/yocto/poky/build/tmp/work/cyclone5-poky-linux-gnueabi/linux-altera-ltsi/4.14.130-ltsi+gitAUTOINC+78cbce0ccb-r0/recipe-sysroot-native/lib -Wl,-O1 -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=/home/mark/yocto/poky/build/tmp/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 HOSTCPP=gcc -E socfpga_cyclone5_de0_nano_soc.dtb
CC scripts/mod/empty.o
CC scripts/mod/devicetable-offsets.s
MKELF scripts/mod/elfconfig.h
HOSTCC scripts/mod/modpost.o
CHK scripts/mod/devicetable-offsets.h
HOSTCC scripts/mod/sumversion.o
HOSTCC scripts/mod/file2alias.o
HOSTLD scripts/mod/modpost
make[3]: *** No rule to make target 'arch/arm/boot/dts/socfpga_cyclone5_de0_nano_soc.dtb'. Stop.
arch/arm/Makefile:343: recipe for target 'socfpga_cyclone5_de0_nano_soc.dtb' failed
make[2]: *** [socfpga_cyclone5_de0_nano_soc.dtb] Error 2
ERROR: oe_runmake failed
Makefile:146: recipe for target 'sub-make' failed
make[1]: *** [sub-make] Error 2
Makefile:24: recipe for target '__sub-make' failed
make: *** [__sub-make] Error 2
WARNING: exit code 1 from a shell command.
ERROR: Function failed: do_compile (log file is located at /home/mark/yocto/poky/build/tmp/work/cyclone5-poky-linux-gnueabi/linux-altera-ltsi/4.14.130-ltsi+gitAUTOINC+78cbce0ccb-r0/temp/log.do_compile.67975)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment