41 Star 204 Fork 53

张明亮 / harmony-raspberry

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

harmony-raspberry

介绍

努力将 OpenHarmony 移植到树莓派 raspberryPi

OHOS3.0 - 树莓派4B

一、添加编译配置文件和gn

1.添加RPI4B.json

主要参考 hisilicon build组件仓,添加一个products编译组件,这个组件是在产品配置文件中指定的。比如

productdefine\common\products\RPI4B.json

其他部分参考Hi3516,但是其中2条,指定单板组件路径,并添加组件。如果删除这两条,将不能编译内核,只生成OHOS的文件系统。

... ..
"product_build_path": "device/raspberrypi/build",
"parts":{
    ... ...
	"raspberrypi_products:raspberrypi_products":{},
    ... ...
	}

2.添加ohos.build

接下来在device目录下,新建一个raspberrypi编译组件文件夹,并添加 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组件

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"
  ]
}

至此一个rpi4b build组件就添加到OHOS3.0的编译框架了,之后相关内容添加到这个文件夹下就可以了。

二、树莓派内核相关

接下来分析下目前移植了树莓派4B的哪些内容,如何将这些内容编译进OHOS3.0。

1.raspberrypi内核补丁文件

关于补丁可以参考 Patch组件,可以得知内核编译由kernel.mk来执行

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

所以补丁文件需要放到正确的路径下,以正确的名字命名就可以patch到内核。

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

2.内核编译配置文件

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 #(选中,直接编进内核)

三、驱动适配

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/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

前面内核配置的时候rpi4b_standard_defconfig中已经将触摸驱动编入内核,所以后面不需要在init加载模块了,修改下eudev的配置文件即可。

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"

四、制作镜像文件

1.修改内核编译脚本

正常情况下内核是由uboot进行引导的,而且OHOS默认生成uImage。但是树莓派自带BootLoader,虽然可以先用树莓派自带的BootLoader启动uboot,再用uboot加载uImage,但是这样会比较麻烦,而且会增加启动时间。不过目前 zImage是写死在kernel.mk中的,没办法改下编译脚本把。

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_name"下的hdf.hcs文件,得先新建一个应付下,不然会报下面这个错误。

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部分。

OHOS1.0 - 树莓派2B

1、前期准备

1.1、环境搭建

1.2、源码下载

1.3、树莓派启动流程

1.4、树莓派U-Boot编译.md

2、代码移植

2.1、增加新单板

2.2、启动设置

2.3、串口分析移植

2.4、系统时钟

2.5、块设备驱动程序

BSD 3-Clause License Copyright (c) 2021, liangzili All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

移植鸿蒙Harmony到树莓派 展开 收起
Shell 等 2 种语言
BSD-3-Clause
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/liangzili/harmony-raspberry.git
git@gitee.com:liangzili/harmony-raspberry.git
liangzili
harmony-raspberry
harmony-raspberry
master

搜索帮助