先看技术架构:

ohos-arch.png

既然 OH 是多内核设计,那必然会有个抽象层(KAL)统一接口供上层使用,还多了个 HDF 驱动框架,官方的引入考虑:

How to smoothly adapt device drivers to different kernels on the same hardware and minimize the workloads on driver code porting and maintenance is an important issue to address in the OpenHarmony driver subsystem.

就是同一份 driver code 可以多个系统跑,有点那个 BPF CO-RE (compile once-run everywhere) 的味道。

此外,针对 Linux,OH 还添加了一些增强内核特性,比如 ESwap (内存融合相关)、任务调度。

OpenHarmony provides the enhanced swap (ESwap), related thread group (RTG), and lightweight CPU isolation features for the Linux kernel

还有一些基本特性,比如 hilog, hievent。

Currently, the basic kernel-mode code of OpenHarmony is related to the log service. The lightweight kernel log service code includes the following:

还有的藏的比较深,比如 accesstokenid:

tj@ubuntu:~/ohos-3.2.2/kernel/linux/linux-5.10/drivers/accesstokenid$ ls
Kconfig  Makefile  access_tokenid.c  access_tokenid.h

干啥用的?Kconfig:

config ACCESS_TOKENID
        bool "Access task's token"
        default n

这描述。。。貌似和 APP 权限有关。

当前 OH Linux 内核版本只有 4.19 和 5.10:

OpenHarmony uses Linux LTS versions as its base kernel. Currently, it supports Linux-4.19 and Linux-5.10.

既然用 Linux LTS 版本,为啥不用 5.4?I think it might not be related to technology... rt?

3.2.2 里只有 linux-5.10:

tj@ubuntu:~/ohos-3.2.2/kernel/linux$ ls
build  config  linux-5.10  patches

这种情况,如果 Vendor/SoC 不支持 5.10,那三方有的干了。

我们来看下内核提交日志,好家伙,下面这种 log 对我没有任何用处, I can't learn anything from this, what about you?

commit b840cb60753e1118e9d0e1eb4d2bfd353ec0e032 (grafted, HEAD, tag: OpenHarmony-v3.2.2-Release, m/refs/tags/OpenHarmony-v3.2.2-Release)
Author: openharmony_ci <120357966@qq.com>
Date:   Fri Jun 9 08:32:06 2023 +0000

    !896 master 分支CVE同步
    Merge pull request !896 from Ywenrui44091/OpenHarmony-3.2-Release

附带过下代码目录。

tj@ubuntu:~/ohos-3.2.2$ ls
applications  base   build.py  commonlibrary  device  drivers     ide        kernel          productdefine  test         vendor
arkcompiler   build  build.sh  developtools   docs    foundation  interface  napi_generator  qemu-run       third_party

有个 base 和 foundation 不太明白,其他目录看 name 还好。

官方解释:

base | Basic software service subsystem set and hardware service subsystem set.|
foundation | Basic system capability subsystem set.|

啊,就是架构图画到的。

Basic software service subsystem set: Provides OpenHarmony with common universal software services, including common event and notification, telephony, multimedia, and Design For X (DFX).

tj@ubuntu:~/ohos-3.2.2$ ls base
account        global     inputmethod  location  notification  request   sensors  telephony  time    usb      web
customization  hiviewdfx  iothardware  msdp      powermgr      security  startup  theme      update  useriam

Basic system capability subsystem set: Implements distributed application running, scheduling, and migration across OpenHarmony devices. This subsystem set provides the following basic capabilities: Distributed Soft Bus (DSoftBus), distributed data management, Distributed Scheduler, Utils, multimodal input, graphics, security, and AI.

tj@ubuntu:~/ohos-3.2.2$ ls foundation/
ability  arkui        bundlemanager  deviceprofile       distributedhardware  graphic     multimodalinput   systemabilitymgr
ai       barrierfree  communication  distributeddatamgr  filemanagement       multimedia  resourceschedule  window

都能对号入座,就这么多,done。

References