5.2 kernle开发 - 构建脚本
- SS928 kernel 提供了 makefile 用于 kernel 构建。
- 想要得到最后的内核镜像,还要经过许多步骤,每次都手敲命令的话,会把我累死。
- 自己实现一个构建脚本,支持以下常用功能即可:
- 构建内核镜像
- 配置 kernel
- 清理所有的编译产物
构建脚本
-
创建脚本:
cd ~/hiss928/kernel/ss928_kernel_v4.19/ touch build.sh chmod a+x build.sh
-
脚本内容如下:
#!/bin/bash CUR_PATH=$(pwd) # 编译产物输出目录 OUTPUT_PATH=${CUR_PATH}/output HI_ARCH=arm64 # 默认使用的配置文件 HI_DEFCONFIG=ss928v100_emmc # 使用的工具链 TOOLCHAIN_PREFIX=aarch64-mix210-linux- print_help() { echo "Usage: $0 [OTIONS] COMMAND" echo "" echo "Options:" echo " -h show this message and exit" echo "" echo "Commands:" echo " -m show menuconfig" echo " -c clean all" } info() { echo -e "\033[32m"$1"\033[0m"; } error() { echo -e "\033[31m"$1"\033[0m"; } build_kernel() { echo "============Start build kernel============" echo "ARCH = ${HI_ARCH}" echo "CONFIG = ${HI_DEFCONFIG}_defconfig" echo "==========================================" # 编译 uImage make ARCH=${HI_ARCH} CROSS_COMPILE=${TOOLCHAIN_PREFIX} ${HI_DEFCONFIG}_defconfig make ARCH=${HI_ARCH} CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j16 uImage if [ ! -f arch/arm64/boot/uImage ]; then error "*** build uImage failed" exit 1; fi # 生成 fip.bin make -C atf PLAT=ss928v100 DEBUG=1 CROSS_COMPILE=${TOOLCHAIN_PREFIX} distclean make -C atf PLAT=ss928v100 SPD=none BL33=../arch/arm64/boot/uImage CCI_UP=0 DEBUG=0 \ BL33_SEC=0 HISILICON=1 CROSS_COMPILE=aarch64-mix210-linux- fip if [ ! -f atf/build/ss928v100/release/fip.bin ]; then error "*** build fip.bin failed" exit 1; fi # 拷贝 kernel 镜像至 output 目录 test -d ${OUTPUT_PATH} || mkdir -p ${OUTPUT_PATH} cp -f atf/build/ss928v100/release/fip.bin ${OUTPUT_PATH}/kernel } if [ "$1" == "-h" ]; then print_help $0 exit 0 fi # 清除所有编译生成的产物 if [ "$1" == "-c" ]; then make -C atf PLAT=ss928v100 DEBUG=1 CROSS_COMPILE=${TOOLCHAIN_PREFIX} distclean make ARCH=${HI_ARCH} CROSS_COMPILE=${TOOLCHAIN_PREFIX} distclean exit 0 fi # 进入 kernel 图形配置界面 if [ "$1" == "-m" ]; then make ARCH=${HI_ARCH} CROSS_COMPILE=${TOOLCHAIN_PREFIX} ${HI_DEFCONFIG}_defconfig make ARCH=${HI_ARCH} CROSS_COMPILE=${TOOLCHAIN_PREFIX} menuconfig make ARCH=${HI_ARCH} CROSS_COMPILE=${TOOLCHAIN_PREFIX} savedefconfig cp defconfig arch/arm64/configs/${HI_DEFCONFIG}_defconfig exit 0 fi build_kernel
使用方法
./build.sh
,构建 kernel 镜像,输出产物默认放入目录output
。./build.sh -m
,进入menuconfig
,默认会保存更改后的配置。./build.sh -c
,清除所有编译产物。./build.sh -h
,打印帮助。