添加树莓派4B到OHOS3.0编译框架
之前在树莓派 4b 上点亮了 OHOS3.0,不过内核是用 tftp 拉取的,根文件系统挂在了 NFS 上,拔了网线就无法启动。

当然这么操作只是为了方便调试,而最终需要的是一个可以烧录到 TF 卡上的 img 镜像文件。
这就需要将所有调试好的内容添加到 OHOS3.0 的编译框架,本以为是很简单的事情,好家伙,整了这么久,感觉添加编译框架比移植本身更复杂。
于是我整理了添加树莓派单板到编译框架的内容,希望对各位有所帮助,为大家避坑。
添加编译配置文件和 gn
①添加 RPI4B.json
https://gitee.com/openharmony/device_hisilicon_build
添加一个 products 编译组件,这个组件是在产品配置文件中指定的。比如:
productdefine\common\products\RPI4B.json
...?..
"product_build_path":?"device/raspberrypi/build",
"parts":{
????...?...
????"raspberrypi_products:raspberrypi_products":{},
????...?...
????}
②添加ohos.build
device\raspberrypi\build\ohos.build:
{
????"subsystem":?"raspberrypi_products",
????"parts":?{
????????"raspberrypi_products":?{
????????????"module_list":?[
????????????????"//device/raspberrypi/build:products_group"
????????????]
????????}
????}
}
新建 device\raspberrypi\build\BUILD.gn 当然每个厂家不可能只有 1 个板子,如果有其他单板就在这里指定,比如树莓派 2B、3B 等。
import("//build/ohos.gni")
device_type?=?"rpi4b"
group("products_group")?{
??deps?+=?[
????"//device/raspberrypi/rpi4b:rpi4b_group"
??]
}
既然前面指定了 rpi4b 的编译配置组件,那么就在 device\raspberrypi 新建一个 rpi4b 的目录,可以参考 hi3516dv300 build 组件:
https://gitee.com/openharmony/device_hisilicon_hi3516dv300
device\raspberrypi\rpi4b\BUILD.gn:
import("//build/ohos.gni")
print("rpi4b_group?in")
group("rpi4b_group")?{
??deps?=?[
????"build/rootfs:init_configs",
????"//kernel/linux/build:linux_kernel"
??]
}
树莓派内核相关
①raspberrypi 内核补丁文件
关于补丁可以参考 Patch 组件:
https://gitee.com/openharmony/kernel_linux_patches
kernel\linux\build\kernel.mk:
DEVICE_PATCH_DIR?:=?$(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch
DEVICE_PATCH_FILE?:=?$(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch
...?...
$(KERNEL_IMAGE_FILE):
????$(hide)?echo?"build?kernel..."
????$(hide)?rm?-rf?$(KERNEL_SRC_TMP_PATH);mkdir?-p?$(KERNEL_SRC_TMP_PATH);cp?-arfL?$(KERNEL_SRC_PATH)/*?$(KERNEL_SRC_TMP_PATH)/
????$(hide)?cd?$(KERNEL_SRC_TMP_PATH)?&&?patch?-p1?<?$(HDF_PATCH_FILE)?&&?patch?-p1?<?$(DEVICE_PATCH_FILE)
ifneq?($(findstring?$(BUILD_TYPE),?small),)
????$(hide)?cd?$(KERNEL_SRC_TMP_PATH)?&&?patch?-p1?<?$(SMALL_PATCH_FILE)
endif
hdf.patch 补丁文件,现在还没有移植 HDF 相关内容,所以可以先使用 Hi3516 的 rpi4b.patch 补丁文件,使用树莓派的官方镜像:
https://github.com/raspberrypi/linux
kernel\linux\patches\linux-5.10\rpi4b_patch\hdf.patch
kernel\linux\patches\linux-5.10\rpi4b_patch\rpi4b.patch
②内核编译配置文件
kernel\linux\config\linux-5.10\arch\arm\configs\rpi4b_standard_defconfig
内核配置文件目前已知的需要开启下面内容,但是肯定不止这些,以后会继续更新:
~/ohos/kernel/linux/config/linux-5.10/arch/arm/configs/rpi4b_standard_defconfig
#####################################################################################
>?Security?options
????>?(32768)?Low?address?space?for?LSM?to?protect?from?user?allocation?
????[*]?NSA?SELinux?Support????????????????#(选中)
????[*]???NSA?SELinux?boot?parameter????#(选中)
????[?]???NSA?SELinux?runtime?disable
????[*]???NSA?SELinux?Development?Support
????[*]???NSA?SELinux?AVC?Statistics
????(1)???NSA?SELinux?checkreqprot?default?value????#(设置为1)
????(9)???NSA?SELinux?sidtab?hashtable?size
????(256)?NSA?SELinux?SID?to?context?string?translation?cache?size
????????First?legacy?'major?LSM'?to?be?initialized?(SELinux)??--->?#(选中)?SELinux
????????Ordered?list?of?enabled?LSMs?#(填入:"lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf")
#####################################################################################
>?Device?Drivers
????>?Android
????????[*]?Android?Drivers?#(开启)
????????[*]???Android?Binder?IPC?Driver?#(开启)
#####################################################################################
>?Device?Drivers?
????>?Sound?card?support
????????<*>?Advanced?Linux?Sound?Architecture?#(选中,直接编进内核)
????????????<*>???ALSA?for?SoC?audio?support?#(选中,直接编进内核)
>?Device?Drivers?
????>?Graphics?support
????????<*>?Direct?Rendering?Manager?(XFree86?4.1.0?and?higher?DRI?support)?#(选中,直接编进内核)
????????<*>?Broadcom?V3D?3.x?and?newer?#(选中,直接编进内核)
????????<*>?Broadcom?VC4?Graphics?#(选中,这个依赖前面的声卡设置,不然是无法编入内核的)
#####################################################################################
>?Device?Drivers?
????>?Input?device?support?
????????>?Touchscreens
????????????<*>???Raspberry?Pi's?firmware?base?touch?screen?support?#(选中,直接编进内核)
驱动适配
①显示配置
同时需要在 config.txt 中开启设置:
dtoverlay=vc4-fkms-v3d
system\etc\weston.ini:
[output]
name=card0
②触摸配置
具体思路就是先查找设备号,根据设备号找到驱动程序。
ls?-l?/sys/dev/char/|grep?input????#?查看input下的触摸设备的主次设备号
cat?/sys/dev/char/13\:64/device/uevent????#?然后输入主次设备号,查看设备的驱动程序
PRODUCT=19/0/0/0
NAME="raspberrypi-ts"
PROP=2
EV=b
KEY=400?0?0?0?0?0?0?0?0?0?0
ABS=2608000?3
MODALIAS=input:b0019v0000p0000e0000-e0,1,3,k14A,ra0,1,2F,35,36,39,mlsfw
third_party\eudev\rules.d\touchscreen.rules:
ATTRS{name}=="raspberrypi-ts",?ENV{ID_INPUT}="1",?ENV{ID_INPUT_TOUCHSCREEN}="1"
ATTRS{name}=="VSoC?keyboard",?ENV{ID_INPUT}="1",?ENV{ID_INPUT_KEYBOARD}="1"
DRIVERS=="hid-multitouch",?ENV{ID_INPUT}="1",?ENV{ID_INPUT_TOUCHSCREEN}="1"
制作镜像文件
①修改内核编译脚本
kernel\linux\build\kernel.mk 将 uImage 改为 zImage modules dtbs:
$(hide)?$(KERNEL_MAKE)?-C?$(KERNEL_SRC_TMP_PATH)?ARCH=$(KERNEL_ARCH)?$(KERNEL_CROSS_COMPILE)?-j64?zImage
kernel\linux\build\build_kernel.sh:
-?cp?${2}/kernel/src_tmp/${8}/arch/arm/boot/uImage?${3}/uImage
+?cp?${2}/kernel/src_tmp/${8}/arch/arm/boot/zImage?${3}/zImage
kernel\linux\build\BUILD.gn:
-?outputs?=?[?"$root_build_dir/packages/phone/images/uImage"?]
+?outputs?=?[?"$root_build_dir/packages/phone/images/zImage"?]
kernel\linux\build\kernel_module_build.sh:
-?LINUX_KERNEL_UIMAGE_FILE=${LINUX_KERNEL_OUT}/arch/arm/boot/uImage
+?LINUX_KERNEL_UIMAGE_FILE=${LINUX_KERNEL_OUT}/arch/arm/boot/zImage
这里内核编译会依赖 product_path="vendor/product_company/product?
ninja:?error:?‘…/…/vendor/raspberrypi/RPI4B/hdf_config/uhdf/hdf.hcs’,?needed?by?‘gen/drivers/adapter/uhdf2/hcs/hdf_default.hcb’,?missing?and?no?known?rule?to?make?it
root?{
????module?=?"default";
}
②制作树莓派 boot 目录
关注公众号:拾黑(shiheibook)了解更多 [广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/
关注网络尖刀微信公众号随时掌握互联网精彩
- 1 习近平将发表二〇二六年新年贺词 7904141
- 2 2026年国补政策来了 7808738
- 3 东部战区:开火!开火!全部命中! 7712893
- 4 2026年这些民生政策将惠及百姓 7616985
- 5 小学食堂米线过期2.5小时被罚5万 7519709
- 6 解放军喊话驱离台军 原声曝光 7428214
- 7 为博流量直播踩烈士陵墓?绝不姑息 7327605
- 8 每月最高800元!多地发放养老消费券 7238391
- 9 数字人民币升级 1月1日起将计付利息 7141831
- 10 2026年1月1日起 一批新规将施行 7040675








51CTO技术栈
