productdefine\common\products\RPI4B.json
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等
device\raspberrypi\rpi4b\BUILD.gn
kernel\linux\build\kernel.mk
DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patchDEVICE_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) $(HDF_PATCH_FILE) $(DEVICE_PATCH_FILE)ifneq ($(findstring $(BUILD_TYPE), small),) $(hide) cd $(KERNEL_SRC_TMP_PATH) $(SMALL_PATCH_FILE)endif
所以补丁文件需要放到正确的路径下,以正确的名字命名就可以patch到内核。
hdf.patch补丁文件,现在还没有移植HDF相关内容,所以可以先使用Hi3516的
rpi4b.patch补丁文件,使用树莓派的官方镜像,
内核配置文件目前已知的需要开启下面内容,但是肯定不止这些,以后会继续更新
~/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 Pis firmware base touch screen support #(选中,直接编进内核)
三、驱动适配
1.显示配置
Pi4的GPU是VideoCore VI支持OpenGL ES 3.2,而Pi3的GPU是VideoCore IV支持OpenGL ES 2.0。VideoCore IV 驱动程序是 VC4,VideoCore VI 驱动程序的 V3D。内核已经提供驱动,参考rpi4b_standard_defconfig将驱动直接编入到内核。
同时需要在config.txt中开启设置
dtoverlay=vc4-fkms-v3d
OHOS中修改weston的配置文件,指定显示驱动
system\etc\weston.ini
[output]name=card0
2.触摸配置
具体思路就是先查找设备号,根据设备号找到驱动程序。
ls -l /sys/dev/char/|grep input # 查看input下的触摸设备的主次设备号cat /sys/dev/char/13\:64/device/uevent # 然后输入主次设备号,查看设备的驱动程序PRODUCT=19/0/0/0NAME=raspberrypi-tsPROP=2EV=bKEY=400 0 0 0 0 0 0 0 0 0 0ABS=2608000 3MODALIAS=input:b0019v0000p0000e0000-e0,1,3,k14A,ra0,1,2F,35,36,39,mlsfw
前面内核配置的时候rpi4b_standard_defconfig中已经将触摸驱动编入内核,所以后面不需要在init加载模块了,修改下eudev的配置文件即可。
third_party\eudev\rules.d\touchscreen.rules
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
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
新建:vendor/raspberrypi/RPI4B/hdf_config/uhdf/hdf.hcs
root { module = default;}
2.制作树莓派boot目录
对于镜像烧录,Hi3516会将uImage、system.img、vendor.img等镜像烧写到emmc,但是树莓派使用TF卡启动,所以需要对TF卡进行分区,然后复制对应的内容到各个分区。首先制作树莓派boot目录,这个用来目录存放树莓派设备树、config.txt、cmdline.txt、内核镜像等信息。写一个简单的mkboot.py脚本来实现这个功能,位置在码仓rpi4b\device\raspberrypi\images\mkboot.py将会生成boot.img。
为了方便烧录,需要将boot.img、system.img、updater.img、vendor.img、userdata.img合并成一个rpi4b.img。还是写一个简单的脚本来处理这个步骤rpi4b\device\raspberrypi\images\mkboot.py。
不过有个问题,主分区只支持4个,所以updater.img暂时先不合并了,这个问题等以后再来处理。
最后将会得到一个rpi4b.img的镜像文件,将这个文件烧录到SD卡就可以了。
Linux:可以使用dd命令
windows:使用Win32 Disk Imager工具烧录即可。
到这里总算是跑通了一个完整的添加新单板的流程,只不过目前只适配了显示和触摸。接下来打算尝试HDF或者distributed部分。