• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16set -e
17
18SCRIPTPATH=$(dirname $realpath "$0")
19export PATH=$(realpath $SCRIPTPATH/../../../../)/prebuilts/clang/ohos/linux-x86_64/llvm/bin/:$(realpath $SCRIPTPATH/../../../../)/prebuilts/develop_tools/pahole/bin/:$PATH
20export PRODUCT_PATH=vendor/kaihong/khdvk_3566b
21IMAGE_SIZE=64  # 64M
22IMAGE_BLOCKS=4096
23
24CPUs=`sed -n "N;/processor/p" /proc/cpuinfo|wc -l`
25MAKE="make LLVM=1 LLVM_IAS=1 CROSS_COMPILE=../../../../prebuilts/gcc/linux-x86/aarch64/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-"
26
27BUILD_PATH=boot_linux
28EXTLINUX_PATH=${BUILD_PATH}/extlinux
29EXTLINUX_CONF=${EXTLINUX_PATH}/extlinux.conf
30TOYBRICK_DTB=toybrick.dtb
31if [ ${KBUILD_OUTPUT} ]; then
32	OBJ_PATH=${KBUILD_OUTPUT}/
33fi
34
35ID_MODEL=1
36ID_ARCH=2
37ID_UART=3
38ID_DTB=4
39ID_IMAGE=5
40ID_CONF=6
41model_list=(
42	"TB-RK3566X0   arm64 0xfe660000 rk3566-rp-kh  Image rk3566_rp_linux_defconfig"
43	"TB-RK3566X10  arm64 0xfe660000 rk3568-toybrick-x10-linux Image rk3566_rp_linux_defconfig"
44)
45
46
47function help()
48{
49	echo "Usage: ./make-ohos.sh {BOARD_NAME}"
50	echo "e.g."
51	for i in "${model_list[@]}"; do
52		echo "  ./make-ohos.sh $(echo $i | awk '{print $1}')"
53	done
54}
55
56
57function make_extlinux_conf()
58{
59	dtb_path=$1
60	uart=$2
61	image=$3
62
63	echo "label rockchip-kernel-5.10" > ${EXTLINUX_CONF}
64	echo "	kernel /extlinux/${image}" >> ${EXTLINUX_CONF}
65	echo "	fdt /extlinux/${TOYBRICK_DTB}" >> ${EXTLINUX_CONF}
66	cmdline="append earlycon=uart8250,mmio32,${uart} root=PARTUUID=614e0000-0000-4b53-8000-1d28000054a9 rw rootwait rootfstype=ext4 ramdisk=8192"
67	echo "  ${cmdline}" >> ${EXTLINUX_CONF}
68}
69
70function make_kernel_image()
71{
72	arch=$1
73	conf=$2
74	dtb=$3
75
76	config_base="arch/${arch}/configs/${conf}"
77	chmod u+x ./scripts/kconfig/merge_config.sh
78	ARCH=${arch} ./scripts/kconfig/merge_config.sh ${config_base}
79
80	if [ $? -ne 0 ]; then
81		echo "FAIL:ARCH=${arch} ./scripts/kconfig/merge_config.sh ${config_base}"
82		return -1
83	fi
84
85	${MAKE} ARCH=${arch} ${dtb}.img -j${CPUs}
86	if [ $? -ne 0 ]; then
87		echo "FAIL: ${MAKE} ARCH=${arch} ${dtb}.img"
88		return -2
89	fi
90
91	return 0
92}
93
94function make_ext2_image()
95{
96	blocks=${IMAGE_BLOCKS}
97	block_size=$((${IMAGE_SIZE} * 1024 * 1024 / ${blocks}))
98
99	if [ "`uname -m`" == "aarch64" ]; then
100		echo y | sudo mke2fs -b ${block_size} -d boot_linux -i 8192 -t ext2 boot_linux.img ${blocks}
101	else
102		genext2fs -B ${blocks} -b ${block_size} -d boot_linux -i 8192 -U boot_linux.img
103	fi
104
105	return $?
106}
107
108function make_boot_linux()
109{
110	arch=${!ID_ARCH}
111	uart=${!ID_UART}
112	dtb=${!ID_DTB}
113	image=${!ID_IMAGE}
114	conf=${!ID_CONF}
115	if [ ${arch} == "arm" ]; then
116		dtb_path=arch/arm/boot/dts
117	else
118		dtb_path=arch/arm64/boot/dts/rockchip
119	fi
120
121	rm -rf ${BUILD_PATH}
122	mkdir -p ${EXTLINUX_PATH}
123
124	make_kernel_image ${arch} ${conf} ${dtb}
125	if [ $? -ne 0 ]; then
126		exit 1
127	fi
128	make_extlinux_conf ${dtb_path} ${uart} ${image}
129	cp -f ${OBJ_PATH}arch/${arch}/boot/${image} ${EXTLINUX_PATH}/
130	cp -f ${OBJ_PATH}${dtb_path}/${dtb}.dtb ${EXTLINUX_PATH}/${TOYBRICK_DTB}
131	cp -f logo*.bmp ${BUILD_PATH}/
132	make_ext2_image
133}
134
135found=0
136for i in "${model_list[@]}"; do
137	if [ "$(echo $i | awk '{print $1}')" == "$1" ]; then
138		make_boot_linux $i
139		found=1
140	fi
141done
142
143