终于在树莓派4B上将OHOS3.0启动起来了,虽然还不完整,目前只能实现的显示和触摸。但是可以和大家分享下我的思路。
- make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
复制代码然后修改下面几项:
- Security options --->
- (32768) Low address space for LSM to protect from user allocation
- [*] NSA SELinux Support ([font=Cambria]选中[/font][font=Consolas])[/font]
- [*] NSA SELinux boot parameter ([font=Cambria]选中[/font][font=Consolas])[/font]
- [ ] NSA SELinux runtime disable
- [*] NSA SELinux Development Support
- [*] NSA SELinux AVC Statistics
- (1) NSA SELinux checkreqprot default value ([font=Cambria]设置为[/font][font=Consolas]1)[/font]
- (9) NSA SELinux sidtab hashtable size
- (256) NSA SELinux SID to context string translation cache size
- First legacy 'major LSM' to be initialized (SELinux) ---> ([font=Cambria]选中[/font][font=Consolas]) SELinux[/font]
- Ordered list of enabled LSMs ([font=Cambria]填入[/font][font=Consolas]:"lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf")[/font]
- Device Drivers --->
- Android --->
- [*] Android Drivers ([font=Cambria]开启[/font][font=Consolas])[/font]
- [*] Android Binder IPC Driver ([font=Cambria]开启[/font][font=Consolas])[/font]
复制代码目前发现开启这两项hilog就可以输出。
内核挂上根文件系统,至少可以启动串口有输出了。然后分析下OHOS的图形子系统。
OHOS目前是 内核 -> DRM -> libdrm -> wayland -> weston 这么个模式,如有错误欢迎指出。这里要感谢 @梁克雷 和钊哥ohos第三方板移植群各位的支持。
所以树莓派的DRM正常了,后面显示应该就是没为题的。好在树莓派的生态比较开放,资料还是比较好获取的,在树莓派官方论坛趴了一段时间。
Pi4的GPU是VideoCore VI支持OpenGL ES 3.2,而Pi3的GPU是VideoCore IV支持OpenGL ES 2.0。
VideoCore IV 驱动程序是 VC4,VideoCore VI 驱动程序的 V3D。
需要在 config.txt 中开启 vc4-fkms-v3d
而驱动kernal已经提供了模块,只要在init阶段将模块加载就可以了
这里有个比较恶心的地方,OHOS的根文件系统使用的是Toybox,但是很多工具不支持,比如modprobe就没有,所以只能根据modules.dep文件,一个一个insmod。当然可以直接将驱动编进内核也是可以的。
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/gpu/drm/drm_panel_orientation_quirks.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/video/backlight/backlight.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/gpu/drm/drm.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/media/cec/core/cec.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/video/fbdev/core/syscopyarea.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/video/fbdev/core/sysfillrect.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/video/fbdev/core/sysimgblt.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/video/fbdev/core/fb_sys_fops.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/gpu/drm/drm_kms_helper.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/sound/core/snd.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/sound/core/snd-timer.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/sound/core/snd-pcm.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/sound/core/snd-compress.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/sound/core/snd-pcm-dmaengine.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/sound/soc/snd-soc-core.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/gpu/drm/vc4/vc4.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/gpu/drm/scheduler/gpu-sched.ko",
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/gpu/drm/v3d/v3d.ko"
复制代码
为了验证drm和libdrm是否正常,我写了一个简单的测试
- fd = open("/dev/dri/card0", O_RDWR | O_CLOEXEC);
- if (fd < 0) {
- printf("open failed");
- }else{
- printf("open seccessn");
- }
- uint32_t conn_id;
- uint32_t crtc_id;
- res = drmModeGetResources(fd); // 获取 crtc_id 和 connector_id
- if (!res) {
- printf("ERROR: drmModeGetResources failed!n");
- drmClose(fd);
- return -1;
- }else{
- printf("drmModeGetResources seccessn");
- }
- crtc_id = res->crtcs[0];
- conn_id = res->connectors[0];
- conn = drmModeGetConnector(fd, conn_id); // 获取 drm_mode
- if (!conn) {
- printf("ERROR: drmModeGetConnector failed!n");
- }else{
- printf("drmModeGetConnector seccessn");
- }
复制代码
其实libdrm是自带测试的modetest,但是OHOS没有加入编译。也可以将modetest加入编译框架
1.为modetest添加BUILD.gn
- third_partylibdrmtestsmodetestBUILD.gn
复制代码- <span class="18">import("//build/ohos.gni")</span>
- <span class="18">ohos_executable("modetest") {</span>
- <span class="18"> sources = [</span>
- <span class="18"> "buffers.c",</span>
- <span class="18"> "cursor.c",</span>
- <span class="18"> "modetest.c",</span>
- <span class="18"> ]</span>
- <span class="18"> cflags = [</span>
- <span class="18"> "-Wno-pointer-arith",</span>
- <span class="18"> ]</span>
- <span class="18"> include_dirs = [</span>
- <span class="18"> "../",</span>
- <span class="18"> ".",</span>
- <span class="18"> ]</span>
- <span class="18"> </span>
- <span class="18"> configs = [ "//third_party/libdrm:libdrm_config" ]</span>
- <span class="18"> public_configs = [ "//third_party/libdrm:libdrm_public_config" ]</span>
- <span class="18"> deps = [</span>
- <span class="18"> "//third_party/libdrm:libdrm",</span>
- <span class="18"> "//third_party/libdrm/tests/util/:util",</span>
- <span class="18"> ]</span>
- <span class="18"> public_deps = []</span>
- <span class="18"> install_images = [</span>
- <span class="18"> "system",</span>
- <span class="18"> "updater",</span>
- <span class="18"> ]</span>
- <span class="18"> part_name = "graphic_standard"</span>
- <span class="18"> subsystem_name = "graphic"</span>
- <span class="18">}</span>
复制代码
2.modetest依赖这个
- third_partylibdrmtestsutilBUILD.gn
复制代码- <span class="18">import("//build/ohos.gni")</span>
- <span class="18">ohos_static_library("util") {</span>
- <span class="18"> sources = [</span>
- <span class="18"> "format.c",</span>
- <span class="18"> "kms.c",</span>
- <span class="18"> "pattern.c",</span>
- <span class="18"> ]</span>
- <span class="18"> cflags = []</span>
- <span class="18"> include_dirs = [</span>
- <span class="18"> "../",</span>
- <span class="18"> ".",</span>
- <span class="18"> ]</span>
- <span class="18"> </span>
- <span class="18"> configs = [ "//third_party/libdrm:libdrm_config" ]</span>
- <span class="18"> public_configs = [ "//third_party/libdrm:libdrm_public_config" ]</span>
- <span class="18"> deps = [</span>
- <span class="18"> "//third_party/libdrm:libdrm",</span>
- <span class="18"> ]</span>
- <span class="18"> public_deps = []</span>
- <span class="18">}</span>
复制代码
3.加入到OHOS编译框架,加在weston的依赖项里就可以了
- third_partywestonBUILD.gn
复制代码- <span class="18">"//third_party/libdrm:libdrm",</span>
- <span class="18">"//third_party/libdrm/tests/util/:util",</span>
- <span class="18">"//third_party/libdrm/tests/modetest/:modetest",</span>
复制代码有个报错:问题不大,提示这个未使用,注释的就好了
- <span class="18">third_partylibdrmtestsutilpattern.c<font face="Cambria">:</font><font face="Consolas">988</font></span>
- <span class="18"> // void *mem_base = mem;</span>
复制代码如果modetest通过了,那剩下的就简单了指定weston的后端就可以了。
systemetcweston.ini
- <span class="17">[</span><span class="19">output</span><span class="17">]</span>
- <span class="19">name</span><span class="17">=</span><span class="19">card0</span>
复制代码接下来是触摸部分,我使用的是DSI接口的触摸屏。
- <span class="19">hexdump </span><span class="17">/</span><span class="19">dev</span><span class="17">/</span><span class="19">input</span><span class="17">/</span><span class="19">event2 # <font face="Cambria">可以使用</font><font face="Consolas">hexdump</font><font face="Cambria">看触摸设备有没有输出,可惜这个命令也不支持</font></span>
- <span class="19">cat </span><span class="17">/</span><span class="19">dev</span><span class="17">/</span><span class="19">input</span><span class="17">/</span><span class="19">event2 # cat<font face="Cambria">也可以凑合用,只是输出乱码,但能证明触摸是否好用</font></span>
复制代码然后查看驱动模块
- <span class="19">ls </span><span class="17">-</span><span class="19">l </span><span class="17">/</span><span class="19">sys</span><span class="17">/</span><span class="19">dev</span><span class="17">/</span><span class="20">char</span><span class="17">/|</span><span class="19">grep input # <font face="Cambria">查看</font><font face="Consolas">input</font><font face="Cambria">下的触摸设备的主次设备号</font></span>
- <span class="19">cat </span><span class="17">/</span><span class="19">sys</span><span class="17">/</span><span class="19">dev</span><span class="17">/</span><span class="20">char</span><span class="17">/</span><span class="23">226</span><span class="19"></span><span class="17">:</span><span class="23">0</span><span class="17">/</span><span class="19">device</span><span class="17">/</span><span class="19">uevent # <font face="Cambria">然后输入主次设备号,查看设备的驱动程序</font></span>
- <span class="19">DRIVER</span><span class="17">=</span><span class="19">raspberrypi</span><span class="17">-</span><span class="19">ts</span>
- <span class="17">...</span><span class="19"> </span><span class="17">...</span>
复制代码发现驱动是raspberrypi-ts,那就好办了,在init的时候安装这个模块就好了。
- "insmod /lib/modules/5.10.76-v7l/kernel/drivers/input/touchscreen/raspberrypi-ts.ko"
复制代码基本是这么个思路,写出来和大家分享下,希望对正在移植的小伙伴能有些帮助。当然加到鸿蒙编译框架可能没有这么简单,接下来我会先整理这部分的文档,就更新在https://gitee.com/liangzili/harmony-raspberry这个仓把,这个码仓我之前移植过OHOS1.0 LiteOS-A内核到树莓派2ModuleB,就直接放到一起了,近期会更新,感兴趣的可以关注,一起讨论。