How to Adapt Rockchip Chip Board to OpenHarmony

How to Adapt Rockchip Chip Board to OpenHarmony

1 overall idea

OpenHarmony is an upper-level user operating system, which is designed to be compatible with different underlying systems. For L2 Linux standard devices, OpenHarmony does not rely too much on underlying systems such as Linux and Uboot, and in terms of drivers, HDF is also compatible with Linux standard drivers.

Therefore, the underlying system can basically directly use the original chip manufacturer or OEM manufacturer, and the upper system is compiled using OpenHarmony.

In terms of the overall idea, you can use the method of partition image splicing to transplant and adapt:

  • The underlying system, that is, the kernel and previous images: uboot, boot (including dtb, kenel, driver), etc., use the original ones of chip manufacturers or OEM manufacturers;

  • The upper system, that is, the image above the kernel: rootfs, vendor (or oem), userdata, using OpenHarmony.

If the compilation toolchain of the single-board SDK is compatible with that of OpenHarmony, the image compiled by the single-board SDK for the boot (including dtb, kernel, and driver) part of the underlying system is fine.

If it is not compatible, the boot part of the underlying system needs to use the OpenHarmony compilation toolchain to recompile the image. You can refer to zh-cn/device-dev/porting/porting-linux-kernel.md · OpenHarmony/docs - Gitee.com

2 version options

1.1 OpenHarmony version selection

It is recommended to choose a newer and more stable version. Do not choose the development branch master for now. The current choice is OpenHarmony-v3.1-Beta. This version already has the Rockchip chip product "Runhe DAYU200", so it is easier to transplant.

1.2 SDK version selection

It is recommended to choose a pure Linux SDK.

Some single boards based on RK chips support multiple operating systems, such as Android, Ubuntu, Buildroot (pure Linux), corresponding to different SDKs, it is recommended to choose the pure Linux SDK, do not use Android and Ubuntu, one is because of Android and Ubuntu The kernel mechanism has been modified, which increases the difficulty and workload of transplantation. For example, Android's AVB, dynamic partition and other mechanisms affect our transplantation; second, the compilation toolchain of the pure Linux SDK of RK's main chip is compatible with the toolchain of OpenHarmony of.

3 adaptation method

Taking Firefly's RK series as an example, the adaptation method is as follows.

This method has been verified to be compatible with the following Firefly products, and it has been verified that the OpenHarmony system can be started correctly and the Launcher will be displayed on the screen.

  • ROC-RK3568-PC, the chip is rk3568
  • AIO-3568J, the chip is rk3568
  • AIO-3399J, the chip is rk3399

Step 1 Prepare the basic environment

Choose to use the Buildroot firmware of the pure Linux SDK, and download the Buildroot firmware of the corresponding product from the Firefly official website for burning.

For example,

Download link of ROC-RK3568-PC: https://www.t-firefly.com/doc/download/107.html

Burning method of ROC-RK3568-PC: https://wiki.t-firefly.com/zh_CN/ROC-RK3568-PC/03-upgrade_firmware.html

Step 2 Modify the compiled kernel

OpenHarmony needs to use the IPC binder to communicate, which is not enabled in the pure Linux SDK, and the kernel needs to be recompiled after enabling the IPC binder.

After obtaining the source code, modify the kernel configuration to open the CONFIG_ANDROID_BINDER_IPC macro and recompile the kernel.

For example, the operation method of the Firefly series:

First, download the Linux_SDK source code package of the corresponding product from the official website of Firefly. Note that Kernel needs to select version 4.19.

Then, modify the config file corresponding to the product and add CONFIG_ANDROID_BINDER_IPC=y. for example

Add CONFIG_ANDROID_BINDER_IPC=y in kernel/arch/arm64/configs/firefly_linux_defconfig.

Then, follow the instructions on the official website to configure the compilation environment, compile the kernel ./build.sh kernel, and get the boot.img.

Finally, burn the compiled boot.img separately using the method of burning by partition. After burning the board successfully, make sure that the basic functions of the board are still normal, and ensure that there is a /sys/module/binder/ directory.

# ls /sys/module/binder/ -l
total 0
drwxr-xr-x 2 root root    0 2022-01-25 07:20 parameters
--w------- 1 root root 4096 2022-01-25 07:18 uevent

The partition table file parameter.txt during burning can be obtained from the source code downloaded in step 2, or can be obtained from the Buildroot firmware unpacked in step 1. For the method of unpacking, please refer to https://blog.csdn.net/Neutionwei/article/details/121886647

Step 3 Modify and compile OH

You need to have the image of the OpenHarmony-v3.1-Beta standard system, download the code of OpenHarmony-v3.1-Beta, and compile the hihope rk3568 product.

Code download path: zh-cn/release-notes/OpenHarmony-v3.1-beta.md · OpenHarmony/docs - Gitee.com

Modify the code: rk3399 needs to delete zpos related codes, and the codes listed below need to be deleted. rk3568 does not require this code modification.

// Code path: ./device/hihope/hardware/display/src/display_device/drm_plane.cpp 
// Function: int32_t DrmPlane::Init(DrmDevice &drmDevice) 
// Delete the following code: 
    ret = drmDevice.GetPlaneProperty(*this , PROP_ZPOS_ID, prop); 
    DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc prop id")); 

// Code path: ./device/hihope/hardware/display/src/display_device/ hdi_drm_composition.cpp 
// Function: int32_t HdiDrmComposition::ApplyPlane(HdiDrmLayer &layer, 
// HdiLayer &hlayer, 
// DrmPlane &drmPlane, 
// drmModeAtomicReqPtr pset) 
// Delete the following code:
    ret = drmModeAtomicAddProperty(pset, drmPlane.GetId(), drmPlane.GetPropZposId(), layer.GetZorder());
    DISPLAY_LOGI("set the fb planeid %{public}d, GetPropZposId %{public}d, zpos %{public}d", drmPlane.GetId(), drmPlane.GetPropZposId(), layer.GetZorder());
    DISPLAY_CHK_RETURN((ret < 0), DISPLAY_FAILURE, DISPLAY_LOGE("set the zpos fialed errno : %{public}d", errno));

Compilation method: compile Runhe DAYU200 products, see OpenHarmony/device_hihope for detailed compilation instructions

bash build/prebuilts_download.sh
./build.sh --product-name rk3568 --ccache

After compiling, get system.img, vendor.img, userdata.img

Step 4 Adjust the partition table

Because the image of OH is large, the partition table needs to be adjusted.

Modify the content of CMDLINE in the partition table file parameter.txt, adjust the partition size of oem, rootfs, and userdata according to the size of vendor.img, system.img, and userdata.img, and adjust the location of subsequent partitions accordingly.

For example, the adjusted partition table of the Firefly ROC-RK3568-PC product.

mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00020000@0x00008000(boot),0x00020000@0x00028000(recovery),0x00010000@0x00048000(backup),0x00150000@0x00058000(oem),0x30ce00@0x001A8000(rootfs),-@0x4B4e00(userdata:grow)

Step 5 Burn the modified partition table and image

Using the upgrade tool, first import the partition table file parameter.txt modified in step 4 (right click --> import configuration --> select the file type as txt), and then select each file to burn.

  • Parameter, select the modified partition table file parameter.txt in step 4

  • oem, select the vendor.img compiled in step 3

  • rootfs, select the system.img compiled in step 3

  • userdata, select the userdata.img compiled in step 3

    After this step is completed, rk3568 series products, OpenHarmony can be started, and the HDMI screen can display the OpenHarmony desktop.

Step 6 Modify the mount path

Mounting path description

The partition mounting paths of different products are different. When mounting partitions, you need to specify the actual partition mounting path of your product.

We use the images compiled by OpenHarmony hihope rk3568. The partition mount path configuration in these images is hihope rk3568, and needs to be modified to the actual partition mount path of our own products.

For hihope rk3568 on OpenHarmony, there are two files specifying the mount path, and these two files need to be modified.

The first file is /system/etc/init.without_two_stages.cfg (this is the path on the board), packaged in system.img, the code file path is device/hihope/rk3568/build/rootfs/init.without_two_stages .cfg

"mount ext4 /dev/block/platform/fe310000.sdhci/by-name/vendor /vendor wait rdonly barrier=1",
"mount ext4 /dev/block/platform/fe310000.sdhci/by-name/userdata  /data wait nosuid nodev noatime barrier=1,data=ordered,noauto_da_alloc"

Note: Products without ramdisk use /system/etc/init.without_two_stages.cfg, products with ramdisk use /system/etc/init.cfg. The currently tested Firefly products do not have the ramdisk enabled. If you are not sure whether the ramdisk is enabled, it is recommended to modify both cfg files.

The second file /vendor/etc/fstab.rk3568 (this is the path on the board), is packaged in vendor.img, and the code file path is ./device/hihope/rk3568/build/rootfs/fstab.rk3568.

# fstab file.
# <src>    <mnt_point>    <type>    <mnt_flags and options>    <fs_mgr_flags>
/dev/block/platform/fe310000.sdhci/by-name/system               /usr       ext4     ro,barrier=1  wait,required
/dev/block/platform/fe310000.sdhci/by-name/vendor              /vendor        ext4     ro,barrier=1  wait,required
/dev/block/platform/fe310000.sdhci/by-name/userdata               /data       ext4     nosuid,nodev,noatime,barrier=1,data=ordered,noauto_da_alloc wait,reservedsize=104857600

Modification method

First check the partition mount path, the prefix of the partition path of different products, you can use the following command to view. The found prefix plus the partition name is the complete mounting path.

# find /dev/ -name "by-name"
/dev/block/platform/fe310000.sdhci/by-name

Then modify the configuration file. You can modify it in the code and then compile it, or pack busybox into the system image and modify it through vi, or modify it directly based on the image file, the method is as follows.

  1. On the Linux server, get vendor.img and system.img

  2. Create a new empty folder, such as temp

  3. Mount system.img to the temp directory

  4. Modify the mount path in the temp/system/etc/init.without_two_stages.cfg file and save it. How to modify different products is listed in the back.

  5. umout temp

  6. Mount vendor.img to the temp directory

  7. Modify the mount path in the temp/etc/fstab.rk3568 file and save it. How to modify different products is listed in the back.

  8. umout temp

    Execution command can refer to:

tanpengju@OpenHarmony:~/firefly/hihope$ ls
system.img  userdata.img  vendor.img
tanpengju@OpenHarmony:~/firefly/hihope$ mkdir temp
tanpengju@OpenHarmony:~/firefly/hihope$ sudo mount system.img temp
tanpengju@OpenHarmony:~/firefly/hihope$ ls temp
bin  config  data  dev  etc  init  lib  lost+found  proc  sys  system  updater  vendor
tanpengju@OpenHarmony:~/firefly/hihope$ sudo vi temp/system/etc/init.without_two_stages.cfg
tanpengju@OpenHarmony:~/firefly/hihope$ sudo umount temp
tanpengju@OpenHarmony:~/firefly/hihope$ ls temp/
tanpengju@OpenHarmony:~/firefly/hihope$ sudo mount vendor.img temp
tanpengju@OpenHarmony:~/firefly/hihope$ ls temp/
etc  lost+found
tanpengju@OpenHarmony:~/firefly/hihope$ sudo vi temp/etc/fstab.rk3568
tanpengju@OpenHarmony:~/firefly/hihope$ sudo umount temp

After completing the modification, burn the modified system.img and vendor.img.

After burning, check the partition mount status through the mount command on the serial port of the board, and confirm that the oem and userdata partitions are successfully mounted to the /vendor and /data directories.

Modification points for different products

For Firefly ROC-RK3568-PC and Firefly AIO-3568J, the partition name is mainly modified.

# /system/etc/init.without_two_stages.cfg文件
"mount ext4 /dev/block/platform/fe310000.sdhci/by-name/oem /vendor wait rdonly barrier=1",
"mount ext4 /dev/block/platform/fe310000.sdhci/by-name/userdata /data wait nosuid nodev noatime barrier=1,data=ordered,noauto_da_alloc"
# /vendor/etc/fstab.rk3568文件
# fstab file.
# <src>    <mnt_point>    <type>    <mnt_flags and options>    <fs_mgr_flags>
/dev/block/platform/fe310000.sdhci/by-name/rootfs               /usr       ext4     ro,barrier=1  wait,required
/dev/block/platform/fe310000.sdhci/by-name/oem              /vendor        ext4     ro,barrier=1  wait,required
/dev/block/platform/fe310000.sdhci/by-name/userdata               /data       ext4     nosuid,nodev,noatime,barrier=1,data=ordered,noauto_da_alloc wait,reservedsize=104857600

Firefly AIO-3399J, mainly modify the partition path and name.

# /system/etc/init.without_two_stages.cfg文件
"mount ext4 /dev/block/platform/fe330000.sdhci/by-name/oem /vendor wait rdonly barrier=1",
"mount ext4 /dev/block/platform/fe330000.sdhci/by-name/userdata /data wait nosuid nodev noatime barrier=1,data=ordered,noauto_da_alloc"
# /vendor/etc/fstab.rk3568文件
# fstab file.
# <src>    <mnt_point>    <type>    <mnt_flags and options>    <fs_mgr_flags>
/dev/block/platform/fe330000.sdhci/by-name/rootfs               /usr       ext4     ro,barrier=1  wait,required
/dev/block/platform/fe330000.sdhci/by-name/oem              /vendor        ext4     ro,barrier=1  wait,required
/dev/block/platform/fe330000.sdhci/by-name/userdata               /data       ext4     nosuid,nodev,noatime,barrier=1,data=ordered,noauto_da_alloc wait,reservedsize=104857600

Step 7 Adaptation of the touch screen

First, find the device corresponding to the touch screen. Use cat /proc/bus/input/devices to find the device corresponding to the touch screen. For example, here the touch screen is the fourth device, and the record Name is "himax-touchscreen".

# cat /proc/bus/input/devices
I: Bus=0019 Vendor=524b Product=0006 Version=0100
N: Name="fe6e0030.pwm"
P: Phys=gpio-keys/remotectl
S: Sysfs=/devices/platform/fe6e0030.pwm/input/input0
U: Uniq=
H: Handlers=kbd event0 cpufreq
B: PROP=0
B: EV=3
B: KEY=100 0 0 40408800 1c16c0 0 0 0

I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="rk805 pwrkey"
P: Phys=rk805_pwrkey/input0
S: Sysfs=/devices/platform/fdd40000.i2c/i2c-0/0-0020/rk805-pwrkey/input/input1
U: Uniq=
H: Handlers=kbd event1 cpufreq
B: PROP=0
B: EV=3
B: KEY=100000 0 0 0

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="Typec_Headphone"
P: Phys=fusb302/typec
S: Sysfs=/devices/platform/fdd40000.i2c/i2c-0/0-0022/input/input2
U: Uniq=
H: Handlers=event2
B: PROP=0
B: EV=21
B: SW=4

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="himax-touchscreen"
P: Phys=
S: Sysfs=/devices/virtual/input/input3
U: Uniq=
H: Handlers=kbd event3 cpufreq
B: PROP=2
B: EV=b
B: KEY=10 0 0 0 0 0 0 0 400 0 0 0 2000000 0 40000800 40 0 0 0
B: ABS=6658000 0

I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="adc-keys"
P: Phys=adc-keys/input0
S: Sysfs=/devices/platform/adc-keys/input/input4
U: Uniq=
H: Handlers=kbd event4 cpufreq
B: PROP=0
B: EV=3
B: KEY=40000800 40000 1000000 0 0

Then, configure the Name of the touch screen device into the udev rule, so that udev automatically recognizes the device with the name as a touch screen device. At the end of the /etc/udev/rules.d/touchscreen.rules file, add the following sentence, where "himax-touchscreen" is the name queried in the previous step, which is different in different hardware environments.

ATTR{name}=="himax-touchscreen", ENV{ID_INPUT}="1", ENV{ID_INPUT_TOUCHSCREEN}="1"

The modified touchscreen.rules file is as follows:

# cat /etc/udev/rules.d/touchscreen.rules
ATTRS{name}=="VSoC touchscreen", 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"
ATTR{name}=="himax-touchscreen", ENV{ID_INPUT}="1", ENV{ID_INPUT_TOUCHSCREEN}="1"
#

After modifying touchscreen.rules, you need to restart the device to take effect.

4 adaptation effect

Firefly ROC-RK3568-PC:

Firefly AIO-3568J :

Firefly AIO-3399J:

After fitting, display and touch are available.

Guess you like

Origin blog.csdn.net/2301_76484015/article/details/130363374