[Yocto for Milk-V Duo] 用 Yocto 为 Milk-V Duo 自定义构建 Linux 系统

Yocto

  • Yocto Project 是开源协作项目,以帮助开发者构建自定义的 Linux 系统, 主页: www.yoctoproject.org
  • Bitbake 是其构建工具,专注于交叉编译,其名也是它的脚本描述语言,文件后缀 .bb, .bbappend
  • 主要的系统参考实现叫 Poky
  • 主要由 Python 和 Bash 语言写成

构建

参考 Yocto Project Quick Build — The Yocto Project ® 4.3.999 documentation

构建主机推荐要求

Git >= 1.8.3.1
tar >= 1.28
Python >= 3.8.0
gcc >= 8.0
GNU make >= 4.0

宿主机安装所要的构建工具

$ sudo apt install gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev python3-subunit mesa-common-dev zstd liblz4-tool file locales libacl1
$ sudo locale-gen en_US.UTF-8

Milk-V Duo on meta-riscv

  • meta-riscv 是一套关于 RISC-V 的 yocto BSP layer,相当于专为 RISC-V 机器所写的构建配置文件
  • 基于 meta-riscv 本人向上游提交的关于 Milk-V Duo 的适配
  • kernel 和命令行基本可用,采用 UART 串口登陆
  • 内存默认分配与官方 SDK 一样,保留了 28M 给 FreeRTOS
  • adbd 和媒体相机栈等闭源软件和配置暂未推进

个人推荐构建方式

下载 poky 和 meta-riscv 仓库

git clone git://git.yoctoproject.org/poky
cd poky
git clone https://github.com/riscv/meta-riscv.git
source oe-init-build-env

修改 build/conf/local.conf

  • init manager 和 dev manager 皆用 busybox
  • musl 为 libc
DL_DIR ?= "${TOPDIR}/downloads"
SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
TMPDIR = "${TOPDIR}/tmp"
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
USER_CLASSES ?= "buildstats"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS ??= "\
    STOPTASKS,${TMPDIR},1G,100K \
    STOPTASKS,${DL_DIR},1G,100K \
    STOPTASKS,${SSTATE_DIR},1G,100K \
    STOPTASKS,/tmp,100M,100K \
    HALT,${TMPDIR},100M,1K \
    HALT,${DL_DIR},100M,1K \
    HALT,${SSTATE_DIR},100M,1K \
    HALT,/tmp,10M,1K"
DISTRO = "nodistro"
MACHINE="milkv-duo"
CONF_VERSION = "2"
TCLIBC="musl"
INIT_MANAGER="mdev-busybox"
VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
PREFERRED_VERSION_linux-libc-headers = "5.10%"

添加 meta-riscvconf/bblayers.conf

cd poky/build
bitbake-layers add-layer ../meta-riscv

开始构建 core-image-minimal

MACHINE=milkv-duo bitbake core-image-minimal

完成编译后的系统镜像

位于 build/tmp-musl/deploy/images/milkv-duo/core-image-minimal-milkv-duo.rootfs.wic.gz
强烈推荐用 bmaptool 来烧写镜像

$ sudo bmaptool copy <image>-<machine>.wic.gz /dev/sdX

可预见的问题

  • 软件源码下载时在国内较慢
  • 构建时间较长,因为是从宿主机的编译工具和交叉工具链开始构建
  • 某些软件可能存在编译问题

后言

Yocto 这套构建系统在国内了解的人可能不多,但是其功能上限高,自定义选项多,包括了完整的交叉工具链构建支持,目标系统的包管理 (deb rpm ipk), 且内核, bootloader, firmware 的详细构建配置都有涉及。虽学习时间较长,但如若熟练运用,定会有益于嵌入式系统开发和自定义项目。

3 Likes

you can use docker to build it! much easier kas-container build ./meta-riscv/kas/milkv-duo.yml

Hello
I am try to reproduce :slight_smile:

When I compile whith

MACHINE=milkv-duo bitbake core-image-minimal

I get

NOTE: Resolving any missing task queue dependencies
WARNING: preferred version 5.10.% of linux-libc-headers not available (for item linux-libc-headers-dev)
WARNING: versions of linux-libc-headers available: 6.5
WARNING: preferred version 5.10.% of linux-libc-headers not available (for item linux-libc-headers)
WARNING: versions of linux-libc-headers available: 6.5

and image do not run on my milkv

what version of yocto need?
git checkout yocto-4.3.2
or something

Last time I compile the image using yocto master branch and it runs, but now my milkv duo board is broken and I’m waiting for a new one.
Ideally, the linux-libc-headers version should match or be newer than the kernel version, otherwise there could be API or ABI breakages. Though it’s okay in my config when I test it before posting, I will test again as soon as I receive my board.
Besides, my yocto scripts currently only support milkv duo 64M, not milkv duo 256M nor milkv duo S, since there is an extra Arm CPU and different drivers.

Thank you for answer =)
I use milkv duo 64M too)
If you check this again, please write the result here)

Hi,
I have tested my image with yocto master branch. It boots and runs, using the UART port to login.
I forget to mention that RNDIS is not supported by yocto currently, since those setup scripts in milkv duo official image require certain network manager and related customized drivers, which are unlikely to merge into meta-riscv upstream repository.