在 Yocto 里集成 Ambiorix(AMX):从 layer 到跑起来
在练习中成长
不用等读完,先测一下先给结论: 官方有
meta-amx(只兼容 honister);较新的 Yocto 要自己建一层,但不用从零写——照它的依赖链和 recipe 结构 port 即可。
一、官方 layer 先看一眼
仓库:
git clone -b honister https://gitlab.com/prpl-foundation/yocto/metalayers/meta-amx.git
bitbake-layers add-layer meta-amx
bitbake amxrt
- 它是 PRPL Foundation 官方的 Ambiorix Yocto 元数据(PRPL 自己的
sdk-builder就用它); honister分支仍在维护(tag 到honister_v15.17.1);main分支只有 README,是空壳;LAYERSERIES_COMPAT只写honister。
所以:honister 直接用;kirkstone/scarthgap 自己建层或 port。
二、依赖链(写 recipe 的顺序)
libamxc
├── libamxj (yajl)
├── libamxp (libcap-ng, bison-native, flex-native)
├── libamxd (libamxc, libamxp)
├── libamxb (libamxc, libamxp, libamxd, uriparser)
├── libamxs (libamxc, libamxp, libamxb, libamxd)
├── libamxo (libamxc, libamxp, libamxd, libamxs, bison/flex)
├── libamxrt (libamxc, libamxj, libamxp, libamxd, libamxo, libamxb, libevent, libcap-ng)
├── amxrt (libamxrt + 上面那些)
└── mod-amxb-ubus (libamxc, libamxb, libamxd, ubus)
yajl、uriparser、libcap-ng、libevent都在 meta-oe,所以 layer 要依赖meta-oe。
三、最小 layer 结构
meta-ambiorix/
├── conf/layer.conf
├── classes/config-amx.bbclass
├── recipes-ambiorix/
│ ├── libamxc/libamxc_git.bb
│ ├── libamxj/libamxj_git.bb
│ ├── libamxp/libamxp_git.bb
│ ├── libamxd/libamxd_git.bb
│ ├── libamxb/libamxb_git.bb
│ ├── libamxs/libamxs_git.bb
│ ├── libamxo/libamxo_git.bb
│ ├── libamxrt/libamxrt_git.bb
│ ├── amxrt/amxrt_git.bb
│ └── mod-amxb-ubus/mod-amxb-ubus_git.bb
└── recipes-core/packagegroups/packagegroup-ambiorix.bb
conf/layer.conf:
BBPATH .= ":${LAYERDIR}"
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
${LAYERDIR}/recipes-*/*/*.bbappend"
BBFILE_COLLECTIONS += "ambiorix"
BBFILE_PATTERN_ambiorix = "^${LAYERDIR}/"
BBFILE_PRIORITY_ambiorix = "10"
LICENSE_PATH += "${LAYERDIR}/licenses"
LAYERDEPENDS_ambiorix = "core meta-oe"
LAYERSERIES_COMPAT_ambiorix = "scarthgap styhead walnascar"
SAH不是 SPDX 里的常见许可证:把上游的licenses/SAH复制到你的 layer,否则 BitBake 会报license SAH not found。 另外,SAH是 SoftAtHome 的自有条款,量产前先确认授权(以各仓库LICENSE为准)。
四、recipe 模板(以 libamxc 为例)
SUMMARY = "Ambiorix generic containers"
LICENSE = "SAH & BSD-2-Clause-Patent"
LIC_FILES_CHKSUM = "file://LICENSE;md5=f8eaa5ae328592b1346db42ce2936d90"
SRC_URI = "git://gitlab.com/prpl-foundation/components/ambiorix/libraries/libamxc.git;protocol=https;nobranch=1"
SRCREV = "1623d9fc299c03c9d47adb95a884a0309cabf4eb"
S = "${WORKDIR}/git"
inherit pkgconfig
EXTRA_OEMAKE = " \
DEST=${D} \
PREFIX=${prefix} \
LIBDIR=${libdir} \
BINDIR=${bindir} \
INCLUDEDIR=${includedir} \
"
do_compile() {
oe_runmake
}
do_install() {
oe_runmake install
}
FILES:${PN} += "${libdir}/libamxc.so.*"
FILES:${PN}-dev += "${libdir}/libamxc.so ${includedir}/amxc/*.h"
FILES:${PN}-staticdev += "${libdir}/libamxc.a"
关键点:
DEST=${D}:BAF 的 makefile 用DEST当DESTDIR;LIBDIR=${libdir}:否则 makefile 会按$(CC) -dumpmachine生成/usr/lib/aarch64-...,打包对不上;PREFIX/BINDIR/INCLUDEDIR同理,统一到 Yocto 标准路径;- 交叉编译靠 BitBake 导出的
CC/CFLAGS/LDFLAGS,makefile 里是+=,不会被覆盖。
其余库只需改 SUMMARY、SRC_URI、SRCREV、DEPENDS/RDEPENDS 和 FILES。依赖照第二节的表抄。
五、config-amx.bbclass 要不要?
官方那个 class 其实只做两件事:
EXTRA_OEMAKE += "DEST=${D} D=${D}${base_prefix} PREFIX=${prefix} LIBDIR=${libdir} BINDIR=${bindir} INCLUDEDIR=${includedir}"
do_install() { oe_runmake install; }
一个容易踩的坑:recipe 里的
SAH_CONFIG/CONFIG_SAH_*是 BAF 构建时代的选项;走make时这些变量在libamxc/libamxo/libamxrt的 makefile 里并没有被引用。照抄无害,但别以为它们在起作用。
自己建层时,把这段直接写进 recipe(或复制一个精简版 class)就行。
六、加进镜像
packagegroup-ambiorix.bb:
inherit packagegroup
RDEPENDS:${PN} = " \
amxrt \
libamxd \
libamxo \
mod-amxb-ubus \
"
local.conf / image recipe:
IMAGE_INSTALL:append = " packagegroup-ambiorix"
构建:
bitbake libamxc libamxp libamxd libamxb libamxo libamxrt amxrt
bitbake core-image-minimal
七、跑起来:ODL + 总线 + systemd
一个纯数据模型的 hello.odl:
%config {
name = "hello";
}
%define {
object Hello {
string Greeting = "Hello, AMX";
uint32 Count = 0;
}
}
启动(ubus 后端):
amxrt -u ubus:/var/run/ubus/ubus.sock \
-B /usr/bin/mods/amxb/mod-amxb-ubus.so \
/etc/amx/hello/hello.odl
-A -C只是不自动探测、不连接;仍要用-B加载一个后端(如 ubus),否则amxrt会报No backends specified。 想被ubus/amx-cli访问,就必须有 ubusd + 后端。
systemd unit:
[Unit]
Description=AMX hello data model
After=network.target
# ubusd 的启动方式取决于你的镜像:systemd 用 ubusd.service,SysV 用 init 脚本
[Service]
ExecStart=/usr/bin/amxrt /etc/amx/hello/hello.odl
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target
recipe 里:
inherit systemd
SYSTEMD_SERVICE:${PN} = "hello.service"
SYSTEMD_AUTO_ENABLE:${PN} = "enable"
SRC_URI += "file://hello.odl file://hello.service"
do_install:append() {
install -d ${D}${sysconfdir}/amx/hello
install -m 0644 ${WORKDIR}/hello.odl ${D}${sysconfdir}/amx/hello/
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/hello.service ${D}${systemd_system_unitdir}/
}
FILES:${PN} += "${sysconfdir}/amx/hello/hello.odl"
验证:
ubus list | grep Hello
ubus call Hello _get
# 或(amx-cli 需额外加 libamxt/libamxm/amx-cli 三个 recipe)
amx-cli -u ubus:/var/run/ubus/ubus.sock
八、从 honister 到 scarthgap 要改什么
LAYERSERIES_COMPAT改成目标发行版;
- 老写法
FILES_${PN}→FILES:${PN}(上游新 recipe 已经是冒号写法);
LICENSE +=改成先LICENSE = "...",避免变量未初始化;
bison-native/flex-native别忘了(libamxp、libamxo);
- SysV 的
inherit update-rc.d换成systemd(如果镜像用 systemd);
- 新版本组件可能多依赖(如
libocispec、libevent),以各仓库baf.yml为准,别照抄旧 recipe 的 DEPENDS。
九、常见错误对照
| 现象 | 原因 |
|---|---|
cap-ng.h: No such file | 缺 libcap-ng(meta-oe) |
yajl/yajl_parse.h 找不到 | 缺 yajl |
uriparser/Uri.h 找不到 | 缺 uriparser |
cannot find -lamxc | DEPENDS 漏了,或没装进 sysroot |
libamxc.so.2: cannot open | RDEPENDS 漏了 / 包没进镜像 |
amxrt 起来但 ubus list 没有对象 | 后端没加载 / ubusd 没起 / URI 不对 |
安装到了 /usr/lib/aarch64-... | 没传 LIBDIR=${libdir} |
do_install 找不到 DEST | makefile 用的是 DEST 不是 DESTDIR |
一句话
Yocto 集成 AMX 的难点不在 recipe 语法,而在依赖链和总线后端。 把
libamxc → libamxp → libamxd → libamxb → libamxo → libamxrt这条链和DEST/LIBDIR摆对,剩下的就是打包和起服务。
原理部分:AMXD 的意义 · libamxd 实战 官方 layer:prpl-foundation/yocto/metalayers/meta-amx 可运行 demo:meta-ambiorix-demo(scarthgap + QEMU + ubus + ODL + systemd) 相关:prplOS vs OpenWrt:是什么、架构差在哪
评论 0
还没有评论,来抢沙发~