首先感谢永恒666分享的
4412开发板移植openharmony3.0标准版-原来移植ohos可以这样简单!
本文参考这种方式在友善之臂NanoPi M1 Plus上移植了Openharmony标准版
用的方法比较简单粗暴,目前只是能成功跑起来看到画面。
整理实现方式如下:
一 OpenHarmony Linux内核移植
参考:一种快速移植OpenHarmony Linux内核的方法
1.按照Building U-boot and Linux for H5/H3/H2+/zh获取NanoPi M1 Plus内核
主要步骤如下:
1.1 安装交叉编译器
下载交叉编译器arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz,然后解压编译器:
- $ mkdir -p /opt/FriendlyARM/toolchain
- $ tar xf arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz -C /opt/FriendlyARM/toolchain/
然后将编译器的路径加入到PATH中,用vi编辑vi ~/.bashrc,在末尾加入以下内容,
此处建议使用每次重开终端前输入以下指令的方式:
- $ export PATH=/opt/FriendlyARM/toolchain/4.9.3/bin:$PATH
- $ export GCC_COLORS=auto
执行一下~/.bashrc脚本让设置立即在当前shell窗口中生效,注意"."后面有个空格:
- $ . ~/.bashrc
这个编译器是64位的,不能在32位的Linux系统上运行,安装完成后,你可以快速的验证是否安装成功:
- $ arm-linux-gcc -v
- gcc version 4.9.3 (ctng-1.21.0-229g-FA)
1.2 编译Linux内核
在编译过ipcamera_hispark_taurus的源码中下载NanoPi M1 Plus Linux4.14内核源码,并切换分支:
我的ohos3.0路径是/home/soon/ohos300/,这个路径替换成你自己的
- $ cd /home/soon/ohos300/out/KERNEL_OBJ/kernel/src_tmp
- $ git clone https://github.com/friendlyarm/linux.git -b sunxi-4.14.y --depth 1
- $ mv linux linux-nanopi
编译确认环境没有问题:
- $ sudo apt-get install u-boot-tools
- $ cd /home/soon/ohos300/out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi
- $ touch .scmversion
- $ make sunxi_defconfig ARCH=arm CROSS_COMPILE=arm-linux-
- $ make zImage dtbs ARCH=arm CROSS_COMPILE=arm-linux-
编译完成后会在arch/arm/boot/目录下生成zImage,并且在arch/arm/boot/dts/目录下生成dtb文件。
2 内核态基础代码的移植
将以下路径代码,从OpenHarmony3.0内核代码目录kernel/linux/linux-4.19/drivers/staging中,拷贝到out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi/drivers/staging 下。
- drivers/staging/hilog
- drivers/staging/hievent
- soon@soon-u20:~/ohos300/out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi/drivers/staging $ ls -al
- total 224
- drwxrwxr-x 52 soon soon 4096 12月 29 22:51 .
- drwxrwxr-x 132 soon soon 4096 12月 29 22:53 ..
- drwxrwxr-x 4 soon soon 4096 12月 29 22:51 android
- drwxrwxr-x 2 soon soon 4096 12月 29 19:24 board
- -rw-rw-r-- 1 soon soon 628 12月 29 22:51 built-in.o
- -rw-rw-r-- 1 soon soon 251 12月 29 22:51 .built-in.o.cmd
- drwxrwxr-x 3 soon soon 4096 12月 29 19:24 ccree
- drwxrwxr-x 2 soon soon 4096 12月 29 19:24 clocking-wizard
- drwxrwxr-x 4 soon soon 4096 12月 29 19:24 comedi
- drwxrwxr-x 2 soon soon 4096 12月 29 19:24 dgnc
- drwxrwxr-x 2 soon soon 4096 12月 29 19:24 emxx_udc
- drwxrwxr-x 2 soon soon 4096 12月 29 22:51 fbtft
- drwxrwxr-x 3 soon soon 4096 12月 29 19:24 fsl-dpaa2
- drwxrwxr-x 4 soon soon 4096 12月 29 19:24 fsl-mc
- drwxrwxr-x 2 soon soon 4096 12月 29 19:24 fwserial
- drwxrwxr-x 2 soon soon 4096 12月 29 19:24 gdm724x
- drwxrwxr-x 2 soon soon 4096 12月 29 19:24 goldfish
- drwxrwxr-x 4 soon soon 4096 12月 29 19:24 greybus
- drwxrwxr-x 2 soon soon 4096 12月 29 19:24 gs_fpgaboot
- drwxr-xr-x 2 soon soon 4096 12月 29 19:49 hievent
- drwxr-xr-x 2 soon soon 4096 12月 29 19:49 hilog
在三方内核的drivers/staging/Kconfig文件内增加如下代码:
- source "drivers/staging/hilog/Kconfig"
- source “drivers/staging/hievent/Kconfig”
在内核config项中打开对应的CONFIG控制宏:CONFIG_HILOG和CONFIG_HIEVENT。
- CONFIG_HILOG=y
- CONFIG_HI_LOG_BUFFER_SIZE=2048
- CONFIG_HIEVENT=y
3 内核态必选特性HDF的移植
3.1打HDF补丁
因为patch_hdf.sh是最近才上传的,如果用repo下载的,先更新下/home/soon/ohos300/drivers/adapter/khdf/linux这个目录
也可以去把整个仓库下载来替换。指令更新可以使用如下
- git pull
- git checkout master
在Linux内核打HDF补丁时,执行补丁shell脚本合入HDF补丁。
配置HDF补丁脚本的三个变量参数。
获取patch_hdf.sh脚本。
执行patch_hdf.sh脚本依次传入三个变量参数。
patch_hdf.sh脚本三个参数含义为:
第一个入参为工程根目录路径,第二入参为内核目录路径,第三个入参为hdf补丁文件。
./patch_hdf.sh [工程根目录路径] [内核目录路径] [hdf补丁文件]
我这边用的指令如下
- /home/soon/ohos300/drivers/adapter/khdf/linux/patch_hdf.sh \
- /home/soon/ohos300 \
- /home/soon/ohos300/out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi \
- /home/soon/ohos300/kernel/linux/patches/linux-4.19/hi3516dv300_patch/hdf.patch
3.2配置config
提供HDF基本配置,如果需要其他功能,通过menuconfig打开对应驱动开关即可。
HDF补丁执行成功后,默认HDF开关是关闭的,打开HDF基本配置选项如下:
- CONFIG_DRIVERS_HDF=y
- CONFIG_HDF_SUPPORT_LEVEL=2
- CONFIG_DRIVERS_HDF_PLATFORM=y
- CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
- CONFIG_DRIVERS_HDF_PLATFORM_GPIO=y
- CONFIG_DRIVERS_HDF_PLATFORM_I2C=y
- CONFIG_DRIVERS_HDF_PLATFORM_UART=y
- CONFIG_DRIVERS_HDF_TEST=y
4 打开内核的一些关键配置
4.1 打开 Android Drivers 和Android Binder IPC Driver
Device Drivers —>
Android —>
[] Android Drivers (开启)
[] Android Binder IPC Driver (开启)
4.2 打开SELinux Support相关配置
参考亮子力的整理,树莓派4B移植OHOS 3.0 LTS标准系统
可以在make menuconfig 下用/ 执行查找关键字,看配置项的位置和依赖,
也可以参考文章附件配置。
5 重新编译生成zImage 和dtb
配置完成后直接下以下指令:
- $ make zImage dtbs ARCH=arm CROSS_COMPILE=arm-linux-
编译完成后会在arch/arm/boot/目录下生成zImage,并且在arch/arm/boot/dts/目录下生成dtb文件。把这两个文件拷贝出来备用。
二 合成boot.img
1. 先拷贝一份NanoPi M1 Plus的boot 分区到~/ohos300/out/ohos-arm-release/packages/phone/boot/下。
可以从制作的SD卡上拷贝,如何制作SD 启动卡参考NanoPi M1 Plus 4.3.3.1 烧写到TF卡。
2.替换zImage和dtb文件
- cp -f /home/soon/ohos300/out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi/arch/arm/boot/zImage /home/soon/ohos300/out/ohos-arm-release/packages/phone/boot/
- cp -f /home/soon/ohos300/out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi/arch/arm/boot/dts/sun8i-*-nanopi-*.dtb /home/soon/ohos300/out/ohos-arm-release/packages/phone/boot/
3.用build_boot.py生成boot.img
参考树莓派rpi3的device\rpi3\rpi3\kernel\build_kernel.py脚本,修改:
- #!/usr/bin/env python3
- import sys
- import os
- import os.path
- import subprocess
- import multiprocessing
- import shutil
- import pathlib
- bootimgsize = 64*1024*1024
- command = sys.argv[1]
- output_dir = sys.argv[2]
- def make_boot_img():
- oldpwd = os.getcwd()
- os.chdir(output_dir)
- imagefile = 'images/boot.img'
- imagefile_tmp = imagefile + '.tmp'
- boot_dir = 'boot'
- with open(imagefile_tmp, 'wb') as writer:
- writer.truncate(bootimgsize)
- subprocess.run(F'mkfs.vfat {imagefile_tmp} -n BOOT', shell=True, check=True)
- subprocess.run(F'mcopy -i {imagefile_tmp} {boot_dir}/* ::/', shell=True, check=True)
- os.rename(imagefile_tmp, imagefile)
- os.chdir(oldpwd)
- command_table = {
- 'bootimg': make_boot_img,
- }
- command_table[command]()
把build_boot.py放到~/ohos300 执行以下指令生成boot.img,
- soon@soon-u20:~/ohos300 $ python3 build_boot.py bootimg /home/soon/ohos300/out/ohos-arm-release/packages/phone
- mkfs.fat 4.1 (2017-01-24)
三 合成SD卡烧录img
参考Make Image Files for H3
1 下载Build an sd card image环境
- git clone https://github.com/friendlyarm/sd-fuse_h3.git
- cd sd-fuse_h3
- wget http://112.124.9.243/dvdfiles/H3/images-for-eflasher/friendlycore-focal_4.14_armhf.tgz
- tar xvzf friendlycore-focal_4.14_armhf.tgz
2 准备system.img、vendor.img、userdata.img
这边用的之前编译的树莓派rpi3的img
将friendlycore-focal_4.14_armhf下的.img 删除
并将之前合好的boot.img、system.img、vendor.img、userdata.img拷贝到该目录下。
3 修改partmap.txt
- # sd0 partition map
- # flash= <device>.<dev no>:<partition>:<fstype>:<start>,<length>
- # support device : eeprom, nand, mmc
- # support fstype : 2nd, boot, raw, fat, ext4, ubi
- #
- # CPU=h3
- flash=mmc,0:boot0:raw:0x2000,0x17FE000:u-boot-sunxi-with-spl.bin;
- flash=mmc,0:boot:fat:0x1800000,0x4000000:boot.img;
- flash=mmc,0:system:ext4:0x5800000,0x20000000:system.img;
- flash=mmc,0:vendor:ext4:0x025800000,0x4000000:vendor.img;
- flash=mmc,0:userdata:ext4:0x29800000,0x12C00000:userdata.img;
4 合成SD卡烧录img
在sd-fuse_h3目录下执行:
- sudo ./mk-sd-image.sh friendlycore-focal_4.14_armhf h3-sd-friendlycore.img
- soon@soon-u20:~/nanopi-m1-plus/sd-fuse_h3 $ sudo ./mk-sd-image.sh friendlycore-focal_4.14_armhf h3-sd-friendlycore.img
- [sudo] password for soon:
- Creating RAW image: out/h3-sd-friendlycore.img (7800 MB)
- ---------------------------------
- 0+0 records in
- 0+0 records out
- 0 bytes copied, 0.0010239 s, 0.0 kB/s
- Using device: /dev/loop14
- ---------------------------------
- Friendlycore-focal_4.14_armhf filesystem fusing
- Image root: ./friendlycore-focal_4.14_armhf
- ----------------------------------------------------------------
- [/dev/loop14] capacity = 7438MB, 7799999488 bytes
- current /dev/loop14 partition:
- MBR.0 start : 0x0000100000 size 0x01d0da8c00 kB
- ----------------------------------------------------------------
- parsing ./friendlycore-focal_4.14_armhf/partmap.txt:
- part.0 flash=mmc,0:boot0:raw:0x2000,0x17fe000:u-boot-sunxi-with-spl.bin:[RAW] ./friendlycore-focal_4.14_armhf/u-boot-sunxi-with-spl.bin
- part.1 flash=mmc,0:boot:fat:0x1800000,0x4000000:boot.img:[MBR] ./friendlycore-focal_4.14_armhf/boot.img
- part.2 flash=mmc,0:system:ext4:0x5800000,0x20000000:system.img:[MBR] ./friendlycore-focal_4.14_armhf/system.img
- part.3 flash=mmc,0:vendor:ext4:0x25800000,0x4000000:vendor.img:[MBR] ./friendlycore-focal_4.14_armhf/vendor.img
- part.4 flash=mmc,0:userdata:ext4:0x29800000,0x12c00000:userdata.img:[MBR] ./friendlycore-focal_4.14_armhf/userdata.img
- ----------------------------------------------------------------
- create new MBR 4:
- [MBR.0] start : 0x0001800000 size 0x0004000000
- [MBR.1] start : 0x0005800000 size 0x0020000000
- [MBR.2] start : 0x0025800000 size 0x0004000000
- [MBR.3] start : 0x0029800000 size 0x0012c00000
- ----------------------------------------------------------------
- copy from: ./friendlycore-focal_4.14_armhf to /dev/loop14
- [RAW. 0]: 2040 KB | ./friendlycore-focal_4.14_armhf/u-boot-sunxi-with-spl.bin > 100% : done.
- [MBR. 0]: 65536 KB | ./friendlycore-focal_4.14_armhf/boot.img > 100% : done.
- [MBR. 1]: 524288 KB | ./friendlycore-focal_4.14_armhf/system.img > 100% : done.
- [MBR. 2]: 65536 KB | ./friendlycore-focal_4.14_armhf/vendor.img > 100% : done.
- [MBR. 3]: 307200 KB | ./friendlycore-focal_4.14_armhf/userdata.img > 21 100% : done.
- ----------------------------------------------------------------
- /dev/loop14: msdos partitions 1 2 3 4
- ### try to resize2fs: /dev/loop14p3
- resize2fs 1.45.5 (07-Jan-2020)
- The filesystem is already 16384 (4k) blocks long. Nothing to do!
- ---------------------------------
- Friendlycore-focal_4.14_armhf is fused successfully.
- All done.
- ---------------------------------
- RAW image successfully created (23:44:53).
- -rw-r--r-- 1 root root 7799999488 12月 30 23:44 out/h3-sd-friendlycore.img
- Tip: You can compress it to save disk space.
- soon@soon-u20:~/nanopi-m1-plus/sd-fuse_h3 $
会在out目录下生成img
- soon@soon-u20:~/nanopi-m1-plus/sd-fuse_h3/out $ ls -al
- total 964620
- drwxrwxr-x 2 soon soon 4096 12月 30 23:46 .
- drwxrwxr-x 10 soon soon 4096 12月 30 23:46 ..
- -rw-rw-r-- 1 soon soon 167 12月 6 22:28 .gitignore
- -rw-r--r-- 1 root root 7799999488 12月 30 23:44 h3-sd-friendlycore.img
- soon@soon-u20:~/nanopi-m1-plus/sd-fuse_h3/out $
5 烧录img
可以用dd 也可以用Win32DiskImager,dd指令如下:
- sudo dd if=out/h3-sd-friendlycore.img bs=1M of=/dev/sdX