Yocto for Firefly ROC-RK3328-CC

3 minute read

Add machine roc-rk3328-cc

mkdir roc-rk3328-cc
cd roc-rk3328-cc

git clone https://git.yoctoproject.org/meta-rockchip -b kirkstone

In order to support this board, two changes should be made to meta-rockchip:

  • recipes-kernel/linux/linux-yocto%.bbappend
COMPATIBLE_MACHINE:roc-rk3328-cc = "roc-rk3328-cc"
  • conf/machine/roc-rk3328-cc.conf
require conf/machine/include/rk3328.inc

KERNEL_DEVICETREE = "rockchip/rk3328-roc-cc.dtb"
UBOOT_MACHINE = "roc-cc-rk3328_defconfig"

Prepare for build yocto project

git clone -b kirkstone git://git.yoctoproject.org/poky.git
git clone -b kirkstone https://git.yoctoproject.org/meta-arm
git clone -b kirkstone https://github.com/openembedded/meta-openembedded

Customize configuration

source poky/oe-init-build-env build-roc-rk3328-cc

bitbake-layers add-layer ../meta-openembedded/meta-oe
bitbake-layers add-layer ../meta-arm/meta-arm-toolchain
bitbake-layers add-layer ../meta-arm/meta-arm
bitbake-layers add-layer ../meta-rockchip

Then add following to conf/local.conf

DL_DIR ?= "/opt/dl/poky/downloads/"
# Download all the packages first
DISTRO=poky MACHINE=roc-rk3328-cc bitbake core-image-minimal --runall fetch
# Build minimal image
DISTRO=poky MACHINE=roc-rk3328-cc bitbake core-image-minimal
[...]
Currently  6 running tasks (70 of 3410)   2% |#                                                                                       |

Build SDK

DISTRO=poky MACHINE=roc-rk3328-cc bitbake core-image-minimal -c populate_sdk
[...]
Currently  6 running tasks (4121 of 4282)  96% |#############################################################################    |

tmp/deploy/sdk/poky-glibc-x86_64-core-image-minimal-cortexa53-crypto-roc-rk3328-cc-toolchain-4.0.15.sh

Add address sanitizer support

Add gcc-sanitizers to conf/local.conf

TOOLCHAIN_TARGET_TASK:append = " gcc-sanitizers"
TOOLCHAIN_TARGET_TASK:append = " compiler-rt-sanitizers"
Currently  1 running tasks (4285 of 4291)  99% |################################################################################ |
[...]
191M	poky-glibc-x86_64-core-image-minimal-cortexa53-crypto-roc-rk3328-cc-toolchain-4.0.15.sh

Add clang support

git clone https://github.com/kraj/meta-clang.git -b kirkstone
cd build-roc-rk3328-cc
bitbake-layers add-layer ../meta-clang
cat << EOF >> /conf/local.conf

CLANGSDK = "1"
EOF
DISTRO=poky MACHINE=roc-rk3328-cc bitbake core-image-minimal -c populate_sdk
Currently  6 running tasks (2057 of 4410)  46% |##########################################                                                  |
[...]
261M	tmp/deploy/sdk/poky-glibc-x86_64-core-image-minimal-cortexa53-crypto-roc-rk3328-cc-toolchain-4.0.15.sh

kas

To ease the process of building yocto image, we can use kas, kas was written in python, install it with:

pip install kas

With kas, the whole build process is simplified to the following:

mkdir roc-rk3328-cc
cd roc-rk3328-cc
git clone https://git.yoctoproject.org/meta-rockchip -b kirkstone
git clone -b kirkstone git://git.yoctoproject.org/poky.git
git clone -b kirkstone https://git.yoctoproject.org/meta-arm
git clone -b kirkstone https://github.com/openembedded/meta-openembedded

cat << EOF > kas-roc-rk3328-cc.yml
header:
  version: 11

machine: roc-rk3328-cc
distro: poky
target: core-image-minimal

repos:
  poky:
    url: https://git.yoctoproject.org/git/poky
    refspec: kirkstone
    layers:
      meta:
      meta-poky:
      meta-yocto-bsp:

  meta-openembedded:
    url: http://git.openembedded.org/meta-openembedded
    refspec: kirkstone
    path: meta-openembedded
    layers:
      meta-oe:

  meta-arm:
    url: https://git.yoctoproject.org/meta-arm
    refspec: kirkstone
    path: meta-arm
    layers:
      meta-arm-toolchain:
      meta-arm:

  meta-rockchip:
    url: https://git.yoctoproject.org/meta-rockchip
    path: meta-rockchip
    refspec: kirkstone

local_conf_header:
  standard: |
    PACKAGE_CLASSES = "package_ipk"
    DL_DIR = "/opt/dl/poky/downloads/"

  debug-tweaks: |
    EXTRA_IMAGE_FEATURES = "debug-tweaks ssh-server-dropbear"
EOF

export KAS_BUILD_DIR=$(pwd)/build-roc-rk3328-cc
kas build kas-roc-rk3328-cc.yml

Flash to emmc module

Add udev rules for maskrom device

cat << EOF | sudo tee -a /etc/udev/rules.d/99-rk-rockusb.rules
SUBSYSTEM!="usb", GOTO="end_rules"

# RK3036
ATTRS{idVendor}=="2207", ATTRS{idProduct}=="301a", MODE="0666", GROUP="users"
# RK3229
ATTRS{idVendor}=="2207", ATTRS{idProduct}=="320b", MODE="0666", GROUP="users"
# RK3288
ATTRS{idVendor}=="2207", ATTRS{idProduct}=="320a", MODE="0666", GROUP="users"
# RK3328
ATTRS{idVendor}=="2207", ATTRS{idProduct}=="320c", MODE="0666", GROUP="users"
# RK3368
ATTRS{idVendor}=="2207", ATTRS{idProduct}=="330a", MODE="0666", GROUP="users"
# RK3399
ATTRS{idVendor}=="2207", ATTRS{idProduct}=="330c", MODE="0666", GROUP="users"

LABEL="end_rules"
EOF


sudo udevadm control --reload-rules
sudo udevadm trigger

Flash wic image with upgrade_tool:

upgrade_tool db rk3328_loader_ddr786_v1.06.243.bin
upgrade_tool wl 0 core-image-minimal-roc-rk3328-cc.wic
Program Data in /home/fdbai/.config/upgrade_tool
Write LBA from file (100%)

Enlarge rootfs patition

Original image partition size:

fdisk -l deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic
Disk deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic: 280.99 MiB, 294641664 bytes, 575472 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: BCDB75A4-8566-460E-A420-09CCBBB62B9F

Device                                                             Start    End Sectors   Size Type
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic1     64   8063    8000   3.9M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic2   8064   8191     128    64K Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic3   8192  16383    8192     4M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic4  16384  24575    8192     4M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic5  24576  32767    8192     4M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic6  32768 330955  298188 145.6M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic7 330956 575437  244482 119.4M Linux filesystem

IMAGE_ROOTFS_EXTRA_SPACE = “10485760”

Extra 10GB Added to final image:

fdisk -l deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic
Disk deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic: 13.27 GiB, 14253285376 bytes, 27838448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: BF243B46-BD74-47F3-A0F9-BC2F15A1916D

Device                                                             Start      End  Sectors   Size Type
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic1     64     8063     8000   3.9M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic2   8064     8191      128    64K Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic3   8192    16383     8192     4M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic4  16384    24575     8192     4M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic5  24576    32767     8192     4M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic6  32768   330955   298188 145.6M Microsoft basic data
deploy/images/roc-rk3328-cc/core-image-minimal-roc-rk3328-cc.wic7 330956 27838413 27507458  13.1G Linux filesystem