OpenHarmony-4.0-Release source code compilation record

This article is based on Ubuntu 20.04.4 LTS

1. Environment preparation

There’s nothing to say about this. They’re all hackers. Just use the Linux environment in which aosp was compiled before. Some friends are worried that the previous environment will collapse.

It can also be compiled with docker. I did it directly in the aosp environment here, which saves trouble.

Install the following three things in order to download the Harmony source code

sudo apt install curl
sudo apt install python3-pip
sudo apt install git-lfs

Install the following five things to solve the problem of errors reported at the end of compilation (if you don’t believe it, you can try it and install it again at the end)

sudo apt install default-jdk
sudo apt install mtd-utils
sudo apt install scons
sudo apt install gcc-arm-none-eabi
sudo apt install gcc-arm-linux-gnueabi

2. Install repo

Be sure to follow this step to install the repo. The repo provided by ubuntu by default will access the googlge server every time it is started, and will be blocked.
In addition, under 20.04, it needs to be executed as root - otherwise it will prompt that there is no permission.
curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo
chmod a +x /usr/local/bin/repo
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests

3. Download source code

[Official website version update instructions}(https://gitee.com/openharmony/docs/tree/master/zh-cn/release-notes)

The latest version is currently version 4.0, and the kernel is based on 5.10. The old version 2.x 1.x has stopped maintenance, and the kernel is based on 4.19.

Refer to the official website for downloading methods

repo init -u https://gitee.com/openharmony/manifest -b OpenHarmony-4.0-Release --no-repo-verify
repo sync -c
repo forall -c ‘git lfs pull’

Note that there is no v before 4.0. The previous version has this v, otherwise the initialization will fail. Also, pay attention to check whether the computer is disconnected from the Internet.

4. Download the compilation dependency toolkit

After the source code is downloaded, enter the root directory and execute bash build/prebuilts_download.sh

It depends on your internet speed. It takes about 20 minutes for me. After the download is completed, there will be an openharmony_prebuilts folder.

5. Compile source code

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

The first stage of compilation requires more than 2W files, and the later stage requires more than 6W files. The overall time depends on the performance of your computer.

If something goes wrong during compilation, just check the prompts. If there is anything missing, just install it yourself, such as this

default-jdk is not installed. please install it.
mtd-utils is not installed. please install it.
scons is not installed. please install it.
gcc-arm-none-eabi is not installed. please install it.
gcc-arm-linux-gnueabi is not installed. please install it.
Missing dependencies, please check!
[OHOS INFO] Set cache size limit to 100.0 GB
[OHOS INFO] generated build prop info to /hom

6. Flash the firmware (I advise you not to flash it yet)

Final firmware path out\rk3568\packages\phone\images\

The files inside are very different from the ordinary rk3568 aosp project, so the programming method is also the same.

Open the rk programming tool, select load configuration, select config.cfg in images, and put the corresponding image

Just reselect and replace them. If you want to see pictures, you can refer to thisOpenHarmony Getting Started

7. Kernel and driver transplantation

The compiled firmware without any modifications will definitely not be able to run on the board. I have been modifying it for a long time but still can't get it right. I will record some experiences here.

The main reason is that the kernel versions are too different to be transplanted in parallel. Some friends just replaced the entire kernel and ran successfully.

3568 Some versions of the kernel use 4.19 (the one I use here), and the latest harmony is based on 5.10.

Harmony kernel source code modification path out\kernel\src_tmp\linux-5.10

If the kernel version is consistent, you can directly replace all files, and then slightly modify the following compilation rule file

out\kernel\src_tmp\linux-5.10\make-ohos.sh

Replace the original TOYBRICK_DTB with your own, such as MY3568_DTB, a total of 4 modifications

#!/bin/bash

set -e

SCRIPTPATH=$(dirname $realpath "$0")
export PATH=$(realpath $SCRIPTPATH/../../../../)/prebuilts/clang/ohos/linux-x86_64/llvm/bin/:$(realpath $SCRIPTPATH/../../../../)/prebuilts/develop_tools/pahole/bin/:$PATH
export PRODUCT_PATH=vendor/hihope/rk3568
IMAGE_SIZE=64  # 64M
IMAGE_BLOCKS=4096
ENABLE_LTO_O0=${
    
    3}

CPUs=`sed -n "N;/processor/p" /proc/cpuinfo|wc -l`
MAKE="make LLVM=1 LLVM_IAS=1 CROSS_COMPILE=aarch64-linux-gnu-"
[ "${ENABLE_LTO_O0}" == "enable_lto_O0" ] && MAKE="${MAKE} KCFLAGS=-Wl,--lto-O0"
BUILD_PATH=boot_linux
EXTLINUX_PATH=${
    
    BUILD_PATH}/extlinux
EXTLINUX_CONF=${
    
    EXTLINUX_PATH}/extlinux.conf
# TOYBRICK_DTB=toybrick.dtb
MY3568_DTB=rk3568-evb1-ddr4-v10.dtb
if [ ${
    
    KBUILD_OUTPUT} ]; then
	OBJ_PATH=${
    
    KBUILD_OUTPUT}/
fi

ID_MODEL=1
ID_ARCH=2
ID_UART=3
ID_DTB=4
ID_IMAGE=5
ID_CONF=6
model_list=(
	"TB-RK3568X0   arm64 0xfe660000 rk3568-toybrick-x0-linux  Image rockchip_linux_defconfig"
	"TB-RK3568X10  arm64 0xfe660000 rk3568-toybrick-x10-linux Image rockchip_linux_defconfig"
	"MYBOARD3568   arm64 0xfe660000 rk3568-evb1-ddr4-v10 Image rockchip_linux_defconfig"
)


function help()
{
    
    
	echo "Usage: ./make-ohos.sh {BOARD_NAME}"
	echo "e.g."
	for i in "${model_list[@]}"; do
		echo "  ./make-ohos.sh $(echo $i | awk '{print $1}')"
	done
}


function make_extlinux_conf()
{
    
    
	dtb_path=$1
	uart=$2
	image=$3
	
	echo "label rockchip-kernel-5.10" > ${
    
    EXTLINUX_CONF}
	echo "	kernel /extlinux/${image}" >> ${
    
    EXTLINUX_CONF}
	# echo "	fdt /extlinux/${TOYBRICK_DTB}" >> ${
    
    EXTLINUX_CONF}
	echo "	fdt /extlinux/${MY3568_DTB}" >> ${
    
    EXTLINUX_CONF}
	cmdline="append earlycon=uart8250,mmio32,${uart} root=PARTUUID=614e0000-0000-4b53-8000-1d28000054a9 rw rootwait rootfstype=ext4"
	echo "  ${cmdline}" >> ${
    
    EXTLINUX_CONF}
}

function make_kernel_image()
{
    
    
	arch=$1
	conf=$2
	dtb=$3
	
	if [ "$GPUDRIVER" == "mesa3d" ]; then 
		config_base="arch/${arch}/configs/${conf}"
		config_frag="../../../../device/soc/rockchip/panfrost.config"
		ARCH=${
    
    arch} ./scripts/kconfig/merge_config.sh ${
    
    config_base} ${
    
    config_frag}
	else
		${
    
    MAKE} ARCH=${
    
    arch} ${
    
    conf}
	fi

	if [ $? -ne 0 ]; then
		echo "FAIL: ${MAKE} ARCH=${arch} ${conf}"
		return -1
	fi

	${
    
    MAKE} ARCH=${
    
    arch} ${
    
    dtb}.img -j${
    
    CPUs}
	if [ $? -ne 0 ]; then
		echo "FAIL: ${MAKE} ARCH=${arch} ${dtb}.img"
		return -2
	fi

	return 0
}

function make_ext2_image()
{
    
    
	blocks=${
    
    IMAGE_BLOCKS}
	block_size=$((${
    
    IMAGE_SIZE} * 1024 * 1024 / ${
    
    blocks}))

	if [ "`uname -m`" == "aarch64" ]; then
		echo y | sudo mke2fs -b ${
    
    block_size} -d boot_linux -i 8192 -t ext2 boot_linux.img ${
    
    blocks}
	else
		genext2fs -B ${
    
    blocks} -b ${
    
    block_size} -d boot_linux -i 8192 -U boot_linux.img
	fi

	return $?
}

function make_boot_linux()
{
    
    
	arch=${
    
    !ID_ARCH}
	uart=${
    
    !ID_UART}
	dtb=${
    
    !ID_DTB}
	image=${
    
    !ID_IMAGE}
	conf=${
    
    !ID_CONF}
	if [ ${
    
    arch} == "arm" ]; then
		dtb_path=arch/arm/boot/dts
	else
		dtb_path=arch/arm64/boot/dts/rockchip
	fi

	rm -rf ${
    
    BUILD_PATH}
	mkdir -p ${
    
    EXTLINUX_PATH}

	make_kernel_image ${
    
    arch} ${
    
    conf} ${
    
    dtb}
	if [ $? -ne 0 ]; then
		exit 1
	fi
	make_extlinux_conf ${
    
    dtb_path} ${
    
    uart} ${
    
    image}
	cp -f ${
    
    OBJ_PATH}arch/${
    
    arch}/boot/${
    
    image} ${
    
    EXTLINUX_PATH}/
	# cp -f ${
    
    OBJ_PATH}${
    
    dtb_path}/${
    
    dtb}.dtb ${
    
    EXTLINUX_PATH}/${
    
    TOYBRICK_DTB}
	cp -f ${
    
    OBJ_PATH}${
    
    dtb_path}/${
    
    dtb}.dtb ${
    
    EXTLINUX_PATH}/${
    
    MY3568_DTB}
	cp -f logo*.bmp ${
    
    BUILD_PATH}/
	if [ "enable_ramdisk" != "${ramdisk_flag}" ]; then
		make_ext2_image
	fi
}

ramdisk_flag=$2
found=0
for i in "${model_list[@]}"; do
	if [ "$(echo $i | awk '{print $1}')" == "$1" ]; then
		make_boot_linux $i
		found=1
	fi
done

device\board\hihope\rk3568\kernel\build_kernel.sh

Modify the kernel compilation and specify to use the MYBOARD3568 just now, replacing the original TB-RK3568X0

# eval $MAKE_OHOS_ENV ./make-ohos.sh TB-RK3568X0 $RAMDISK_ARG ${
    
    ENABLE_LTO_O0}
eval $MAKE_OHOS_ENV ./make-ohos.sh MYBOARD3568 $RAMDISK_ARG ${
    
    ENABLE_LTO_O0}

Execute ./build.sh --product-name rk3568 --ccache again to recompile

8. Compilation error examples

Error 1. Difference in kernel version and incompatibility of dts file attributes. Appears in line 260 of rk3568-dram-default-timing.dtsi. Just modify the comments.

[OHOS ERROR] DTC arch/arm64/boot/dts/rockchip/rk3568-evb1-ddr4-v10.dtb
[OHOS ERROR] Error: /home/ubuntu/code/OpenHarmony4.0/out/kernel/src_tmp/linux-5.10/arch/arm64/boot/dts/rockchip/rk3568-dram-default-timing.dtsi:260.27-28 syntax error
[OHOS ERROR] FATAL ERROR: Unable to parse input tree
[OHOS ERROR] make[3]: *** [scripts/Makefile.lib:329: arch/arm64/boot/dts/rockchip/rk3568-evb1-ddr4-v10.dtb] Error 1
[OHOS ERROR] make[2]: *** [/home/ubuntu/code/OpenHarmony4.0/out/kernel/src_tmp/linux-5.10/Makefile:1405: rockchip/rk3568-evb1-ddr4-v10.dtb] Error 2
[OHOS ERROR] make[2]: *** Waiting for unfinished jobs…
[OHOS ERROR] make[1]: *** [arch/arm64/Makefile:208: rk3568-evb1-ddr4-v10.img] Error 2
[OHOS ERROR] make[1]: Leaving directory ‘/home/ubuntu/code/OpenHarmony4.0/out/kernel/OBJ/linux-5.10’
[OHOS ERROR] make: *** [Makefile:185: __sub-make] Error 2

Error 2. There is a problem with the modified configuration file

[OHOS ERROR] FAILED: …/kernel/src_tmp/linux-5.10/boot_linux …/kernel/checkpoint/compile_check
[OHOS ERROR] /usr/bin/env …/…/device/board/hihope/rk3568/kernel/build_kernel.sh …/…/kernel/linux/linux-5.10 /home/ubuntu/code/OpenHarmony4.0/out/rk3568/packages/phone/images /home/ubuntu/code/OpenHarmony4.0/device/board/hihope/rk3568 vendor/hihope/rk3568 /home/ubuntu/code/OpenHarmony4.0 rockchip rk3568 hihope root default disable_lto_O0

9. Boot logo replacement

device\board\hihope\rk3568\kernel\logo.bmp

device\board\hihope\rk3568\kernel\logo_kernel.bmp

10. Some common paths

applications\standard system core applications, including calendar, phone, camera, contacts, Setting, SystemUI, etc.

out\kernel\src_tmp\linux-5.10 final compiled kernel source code path

out\kernel\OBJ\linux-5.10 kernel source code compilation obj path

kernel\linux\linux-5.10 SDK comes with native kernel path

device\board\hihope\rk3568 compile script path

The openharmony kernel code is composed as follows:

①. The SDK comes with native kernel (kernel\linux\linux-5.10\)

②. openharmony HDF driver patch package hdf.patch (kernel\linux\patches\linux-5.10\rk3568_patch\)

③. Kernel patch package kernel.patch required by the solution provider (kernel\linux\patches\linux-5.10\rk3568_patch\)

The kernel in 1 plus the patches in 2 and 3 are combined into the final kernel code (out\kernel\src_tmp\linux-5.10)

This work is done by device\board\hihope\rk3568\kernel\build_kernel.sh

Each time the script is executed, the out\kernel\src_tmp\linux-5.10 directory will be deleted at the beginning and reassembled.

Guess you like

Origin blog.csdn.net/u012932409/article/details/134525109