1#!/bin/bash 2 3# Copyright (C) 2022 iSoftStone Device 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 16 17set -e 18 19function build_setup() 20{ 21 local action=$1 22 23 # ARCH & CROSS_COMPILE 24 export ARCH=arm 25 export CROSS_COMPILE=arm-linux-gnueabi- 26 27 if [[ "${LICHEE_CHIP}" =~ ^sun5[0-9]i ]] && [ "x${LICHEE_ARCH}" = "xarm64" ]; then 28 export ARCH=arm64 29 export CROSS_COMPILE=aarch64-linux-gnu- 30 fi 31 32 if [ -n "${LICHEE_TOOLCHAIN_PATH}" -a -d "${LICHEE_TOOLCHAIN_PATH}" ]; then 33 local GCC=$(find ${LICHEE_TOOLCHAIN_PATH} -perm /a+x -a -regex '.*-gcc') 34 export CROSS_COMPILE="${GCC%-*}-"; 35 elif [ -n "${LICHEE_CROSS_COMPILER}" ]; then 36 export CROSS_COMPILE="${LICHEE_CROSS_COMPILER}-" 37 fi 38 39 # cc & make 40 if [ -n "$ANDROID_CLANG_PATH" ]; then 41 export PATH=$ANDROID_CLANG_PATH:$PATH 42 MAKE="make CC=clang HOSTCC=clang LD=ld.lld NM=llvm-nm OBJCOPY=llvm-objcopy" 43 MAKE+=" LLVM=1 LLVM_IAS=1" 44 local ARCH_PREFIX=arm 45 [ "x$ARCH" == "xarm64" ] && ARCH_PREFIX=aarch64 46 if [ -n "$ANDROID_TOOLCHAIN_PATH" ]; then 47 export CROSS_COMPILE=$ANDROID_TOOLCHAIN_PATH/$ARCH_PREFIX-linux-androidkernel- 48 export CLANG_TRIPLE=$ARCH_PREFIX-linux-gnu- 49 fi 50 else 51 MAKE="make CROSS_COMPILE="${CCACHE_Y}${CROSS_COMPILE}"" 52 fi 53 54 # kerneltree, out & staging 55 KERNEL_SRC=$LICHEE_KERN_DIR 56 BUILD_OUT_DIR=$LICHEE_KERN_DIR 57 STAGING_DIR=$LICHEE_OUT_DIR/kernel/staging 58 MAKE+=" ARCH=${ARCH} -j${LICHEE_JLEVEL} O=${BUILD_OUT_DIR}" 59 MAKE+=" KERNEL_SRC=$KERNEL_SRC INSTALL_MOD_PATH=${STAGING_DIR}" 60 cd $KERNEL_SRC 61 62 [[ "$action" =~ ^(dist)?clean|deal_verity ]] && return 0 63 64 rm -rf $STAGING_DIR && mkdir -p $STAGING_DIR 65 #rm -rf $BUILD_OUT_DIR && mkdir -p $BUILD_OUT_DIR 66 echo ${MAKE} 67 [ "$BUILD_OUT_DIR" != "$KERNEL_SRC" ] && ${MAKE} O= mrproper 68 69 if [ ! -f $BUILD_OUT_DIR/.config ]; then 70 printf "\n\033[0;31;1mUsing default config ${LICHEE_KERN_DEFCONF_ABSOLUTE} ...\033[0m\n\n" 71 ${MAKE} defconfig KBUILD_DEFCONFIG=${LICHEE_KERN_DEFCONF_RELATIVE} 72 fi 73 [ ! -f $BUILD_OUT_DIR/include/generated/utsrelease.h ] && ${MAKE} archprepare 74 75 # kernel version 76 KERNEL_VERSION=$(awk -F\" '/UTS_RELEASE/{print $2}' $BUILD_OUT_DIR/include/generated/utsrelease.h) 77} 78 79 80function build_check() 81{ 82 local SUNXI_SPARSE_CHECK SUNXI_SMATCH_CHECK SUNXI_STACK_CHECK 83 local checktools_dir tools_sparse tools_smatch CHECK 84 85 if [ "x$SUNXI_CHECK" = "x1" ];then 86 SUNXI_SPARSE_CHECK=1 87 SUNXI_SMATCH_CHECK=1 88 SUNXI_STACK_CHECK=1 89 fi 90 91 checktools_dir=$LICHEE_TOOLS_DIR/codecheck 92 tools_sparse=$checktools_dir/sparse/sparse 93 tools_smatch=$checktools_dir/smatch/smatch 94 95 if [ "x$SUNXI_SPARSE_CHECK" = "x1" ] && [ -f $tools_sparse ];then 96 echo "\n\033[0;31;1mBuilding Round for sparse check...\033[0m\n\n" 97 CHECK="$tools_sparse" 98 ${MAKE} CHECK=${CHECK} C=2 all modules 2>&1 | tee $STAGING_DIR/build_sparse.txt 99 egrep -w '(warn|error|warning)' $STAGING_DIR/build_sparse.txt > $STAGING_DIR/warn_sparse.txt 100 fi 101 102 if [ "x$SUNXI_SMATCH_CHECK" = "x1" ]&& [ -f $tools_smatch ];then 103 echo "\n\033[0;31;1mBuilding Round for smatch check...\033[0m\n\n" 104 CHECK="$tools_smatch --full-path --no-data -p=kkernel" 105 ${MAKE} CHECK=${CHECK} C=2 all modules 2>&1 | tee $STAGING_DIR/build_smatch.txt 106 egrep -w '(warn|error|warning)' $STAGING_DIR/build_smatch.txt > $STAGING_DIR/warn_smatch.txt 107 fi 108 109 if [ "x$SUNXI_STACK_CHECK" = "x1" ];then 110 ${MAKE} checkstack 2>&1 | tee $STAGING_DIR/warn_stack.txt 111 fi 112} 113 114function build_dts() 115{ 116 local kbuild=$1 117 118 echo "---build dts for ${LICHEE_CHIP} ${LICHEE_BOARD}-----" 119 120 local dtsfile=$LICHEE_BOARD_CONFIG_DIR/$LICHEE_KERN_VER/board.dts 121 local outpath=$STAGING_DIR 122 local DTC=$LICHEE_KERN_DIR/scripts/dtc/dtc 123 outname="sunxi.dtb" 124 125 dep=$STAGING_DIR/dts_dep 126 mkdir -p $dep 127 128 set -e 129 cpp \ 130 -Wp,-MD,${dep}/.${outname}.d.pre.tmp \ 131 -nostdinc \ 132 -I $LICHEE_KERN_DIR/include \ 133 -I $LICHEE_KERN_DIR/bsp/include \ 134 -I $LICHEE_CHIP_CONFIG_DIR/configs/default/${LICHEE_KERN_VER} \ 135 -undef \ 136 -D__DTS__ \ 137 -x assembler-with-cpp \ 138 -o ${dep}/.${outname}.dts.tmp \ 139 $dtsfile 140 141 $DTC \ 142 -O dtb \ 143 -o $outpath/$outname \ 144 -W no-unit_address_vs_reg \ 145 -W no-unit_address_format \ 146 -W no-unique_unit_address\ 147 -W no-simple_bus_reg \ 148 -b 0 \ 149 -@ \ 150 -i $LICHEE_CHIP_CONFIG_DIR/configs/default/${LICHEE_KERN_VER} \ 151 -d $dep/.${outname}.d.dtc.tmp $dep/.${outname}.dts.tmp 152 153 cat $dep/.${outname}.d.pre.tmp $dep/.${outname}.d.dtc.tmp > $dep/.${outname}.d 154} 155 156function merge_config() 157{ 158 local config_list=( 159 '[ "x$PACK_TINY_ANDROID" = "xtrue" ]:$KERNEL_SRC/linaro/configs/sunxi-tinyandroid.conf' 160 '[ -n "$PACK_AUTOTEST" ]:$KERNEL_SRC/linaro/configs/sunxi-common.conf' 161 '[ -n "$PACK_BSPTEST" -o -n "$BUILD_SATA" -o "x$LICHEE_LINUX_DEV" = "xsata" ]:$KERNEL_SRC/linaro/configs/sunxi-common.conf' 162 '[ -n "$PACK_BSPTEST" -o -n "$BUILD_SATA" -o "x$LICHEE_LINUX_DEV" = "xsata" ]:$KERNEL_SRC/linaro/configs/sunxi-sata.conf' 163 '[ -n "$PACK_BSPTEST" -o -n "$BUILD_SATA" -o "x$LICHEE_LINUX_DEV" = "xsata" ]:$KERNEL_SRC/linaro/configs/sunxi-sata-${LICHEE_CHIP}.conf' 164 '[ -n "$PACK_BSPTEST" -o -n "$BUILD_SATA" -o "x$LICHEE_LINUX_DEV" = "xsata" ]:$KERNEL_SRC/linaro/configs/sunxi-sata-${ARCH}.conf' 165 ) 166 167 local condition config 168 169 for e in "${config_list[@]}"; do 170 condition="${e/:*}" 171 config="$(eval echo ${e#*:})" 172 if eval $condition; then 173 if [ -f $config ]; then 174 (cd $KERNEL_SRC && ARCH=${ARCH} $KERNEL_SRC/scripts/kconfig/merge_config.sh -O $BUILD_OUT_DIR $BUILD_OUT_DIR/.config $config) 175 fi 176 fi 177 done 178} 179 180function exchange_sdc() 181{ 182 # exchange sdc0 and sdc2 for dragonBoard card boot 183 if [ "x${LICHEE_LINUX_DEV}" = "xdragonboard" -o "x${LICHEE_LINUX_DEV}" = "xdragonmat" ]; then 184 local SYS_BOARD_FILE=$LICHEE_BOARD_CONFIG_DIR/board.dts 185 186 if [ "x${ARCH}" = "xarm" ];then 187 local DTS_PATH=$KERNEL_SRC/arch/${ARCH}/boot/dts 188 else 189 local DTS_PATH=$KERNEL_SRC/arch/${ARCH}/boot/dts/sunxi 190 fi 191 192 if [ -f ${DTS_PATH}/${LICHEE_CHIP}_bak.dtsi ];then 193 rm -f ${DTS_PATH}/${LICHEE_CHIP}.dtsi 194 mv ${DTS_PATH}/${LICHEE_CHIP}_bak.dtsi ${DTS_PATH}/${LICHEE_CHIP}.dtsi 195 fi 196 # if find dragonboard_test=1 in board.dts ,then will exchange sdc0 and sdc2 197 if [ -n "`grep "dragonboard_test" $SYS_BOARD_FILE | grep "<1>;" `" ]; then 198 echo "exchange sdc0 and sdc2 for dragonboard card boot" 199 $LICHEE_BUILD_DIR/swapsdc.sh ${DTS_PATH}/${LICHEE_CHIP}.dtsi 200 fi 201 fi 202} 203 204function build_kernel() 205{ 206 echo "Building kernel" 207 208 local MAKE_ARGS="modules" 209 210 if [ "${ARCH}" = "arm" ]; then 211 # uImage is arm architecture specific target 212 MAKE_ARGS+=" uImage dtbs LOADADDR=0x40008000" 213 else 214 MAKE_ARGS+=" all" 215 fi 216 217 exchange_sdc 218 merge_config 219 ${MAKE} $MAKE_ARGS 220 221 # update kernel version 222 KERNEL_VERSION=$(awk -F\" '/UTS_RELEASE/{print $2}' $BUILD_OUT_DIR/include/generated/utsrelease.h) 223 224 build_check 225} 226 227function clean_kernel() 228{ 229 local clarg="clean" 230 [ "x$1" == "xdistclean" ] && clarg="distclean" 231 232 echo "Cleaning kernel, arg: $clarg ..." 233 ${MAKE} "$clarg" 234 235 rm -rf $STAGING_DIR $LICHEE_PLAT_OUT/lib $LICHEE_PLAT_OUT/dist 236 [ "$clarg" == "distclean" ] && rm -rf ${LICHEE_OUT_DIR}/kernel 237} 238 239function build_modules() 240{ 241 local module_list=( 242 "NAND:${KERNEL_SRC}/modules/nand" 243 "NAND:${KERNEL_SRC}/bsp/modules/nand" 244 "GPU:$KERNEL_SRC/modules/gpu" 245 "GPU:$KERNEL_SRC/bsp/modules/gpu" 246 ) 247 248 local module_name module_path 249 250 for e in "${module_list[@]}"; do 251 module_name="${e/:*}" 252 module_path="${e#*:}" 253 if [ ! -e $module_path ]; then 254 printf "$module_path does not exist!\n" 255 continue 256 fi 257 printf "\033[34;1m[%4s]: %s\033[0m\n" "$module_name" "Build module driver" 258 ${MAKE} -C $module_path M=$module_path -j1 259 ${MAKE} -C $module_path M=$module_path modules_install 260 printf "\033[34;1m[%4s]: %s\033[0m\n" "$module_name" "Build done" 261 done 262 263 return 0 264} 265 266function clean_modules() 267{ 268 local module_list=( 269 "NAND:${KERNEL_SRC}/modules/nand" 270 "GPU:$KERNEL_SRC/modules/gpu" 271 ) 272 273 local module_name module_path 274 275 for e in "${module_list[@]}"; do 276 module_name="${e/:*}" 277 module_path="${e#*:}" 278 [ ! -e $module_path ] && continue 279 280 printf "\033[34;1m[%4s]: %s\033[0m\n" "$module_name" "Clean module driver" 281 ${MAKE} -C $module_path M=$module_path clean 282 printf "\033[34;1m[%4s]: %s\033[0m\n" "$module_name" "Clean done" 283 done 284 285 return 0 286} 287 288function longan_modify_init() 289{ 290 local cmd="/\(\[ -x \/mnt\/sbin\/init\)/c" 291 292 cmd+="if [ -x /mnt/init ]; then\n" 293 cmd+=" mount -n --move /proc /mnt/proc\n" 294 cmd+=" mount -n --move /sys /mnt/sys\n" 295 cmd+=" mount -n --move /dev /mnt/dev\n" 296 cmd+=" exec switch_root /mnt /init\n" 297 cmd+="fi\n" 298 299 sed -i "$cmd" $STAGING_DIR/skel/init 300} 301 302function build_rootfs() 303{ 304 local action=$1 305 local src=$2 306 local dst=$3 307 case $action in 308 e) 309 # src is file & dst is path 310 rm -rf $dst 311 mkdir $dst 312 gzip -dc $src | (cd $dst; fakeroot cpio -i) 313 ;; 314 c) 315 # src is path & dst is file 316 rm -rf $dst 317 [ ! -d $src ] && echo "src not exist" && return 1 318 (cd $src && find . | fakeroot cpio -o -Hnewc | gzip > $dst) 319 ;; 320 esac 321} 322 323function build_ramfs() 324{ 325 local kernel_size=0 326 local bss_start=0 327 local bss_stop=0 328 local temp=0 329 local bss_section_size=0 330 local CHIP="${LICHEE_CHIP/iw*}i" 331 332 local DTB="$STAGING_DIR/sunxi.dtb" 333 334 if [ "${LICHEE_COMPRESS}" = "gzip" ]; then 335 if [ "${ARCH}" = "arm" ]; then 336 local BIMAGE="$STAGING_DIR/zImage"; 337 elif [ "${ARCH}" = "arm64" -o "${ARCH}" = "riscv" ]; then 338 local BIMAGE="$STAGING_DIR/Image.gz"; 339 fi 340 else 341 local BIMAGE="$STAGING_DIR/bImage"; 342 fi 343 344 local RAMDISK="$STAGING_DIR/rootfs.cpio.gz" 345 local TINYOS_RAMDISK="${LICHEE_BR_OUT}/images/rootfs.cpio.gz" 346 local BASE="0x40000000" 347 local RAMDISK_OFFSET="0x0" 348 local KERNEL_OFFSET="0x0" 349 local DTB_OFFSET="0x0" 350 351 if [ "x${LICHEE_LINUX_DEV}" = "xtinyos" -a -f ${TINYOS_RAMDISK} ]; then 352 RAMDISK=${TINYOS_RAMDISK} 353 else 354 # update rootfs.cpio.gz with new module files 355 build_rootfs e $STAGING_DIR/rootfs.cpio.gz $STAGING_DIR/skel >/dev/null 356 357 mkdir -p $STAGING_DIR/skel/lib/modules/${KERNEL_VERSION} 358 359 for e in $(find $STAGING_DIR/lib/modules/$KERNEL_VERSION -name "*.ko"); do 360 cp $e $STAGING_DIR/skel/lib/modules/$KERNEL_VERSION 361 done 362 363 [ "x${LICHEE_LINUX_DEV}" = "xlongan" ] && longan_modify_init 364 365 build_rootfs c $STAGING_DIR/skel $STAGING_DIR/rootfs.cpio.gz >/dev/null 366 rm -rf $STAGING_DIR/skel 367 fi 368 369 if [ "${ARCH}" = "arm" ]; then 370 KERNEL_OFFSET="0x8000" 371 elif [ "${ARCH}" = "arm64" ]; then 372 KERNEL_OFFSET="0x80000" 373 fi 374 375 if [ -f $STAGING_DIR/bImage ]; then 376 kernel_size="`stat $STAGING_DIR/bImage --format="%s"`" 377 fi 378 379 if [ -f $BUILD_OUT_DIR/System.map ]; then 380 temp=`grep "__bss_start" $BUILD_OUT_DIR/System.map | awk '{print $1}'` 381 bss_start=16#${temp: 0-7: 8} 382 temp=`grep "__bss_stop" $BUILD_OUT_DIR/System.map | awk '{print $1}'` 383 bss_stop=16#${temp: 0-7: 8} 384 bss_section_size=$[$bss_stop - $bss_start] 385 fi 386 387 DTB_OFFSET=`printf "(%d+%d+%d+%d)/%d*%d\n" $KERNEL_OFFSET $kernel_size $bss_section_size 0x1fffff 0x100000 0x100000 | bc` 388 RAMDISK_OFFSET=`printf "%d+%d\n" $DTB_OFFSET 0x100000 | bc` 389 390 local MKBOOTIMG=${LICHEE_TOOLS_DIR}/pack/android/mkbootimg 391 392 393 if [ "${LICHEE_KERN_SYSTEM}" = "kernel_recovery" ]; then 394 IMAGE_NAME="recovery.img" 395 else 396 IMAGE_NAME="boot.img" 397 fi 398 ${MKBOOTIMG} --kernel ${BIMAGE} \ 399 --ramdisk ${RAMDISK} \ 400 --board ${CHIP}_${ARCH} \ 401 --base ${BASE} \ 402 --kernel_offset ${KERNEL_OFFSET} \ 403 --ramdisk_offset ${RAMDISK_OFFSET} \ 404 --dtb ${DTB} \ 405 --dtb_offset ${DTB_OFFSET} \ 406 --header_version 2 \ 407 -o $STAGING_DIR/${IMAGE_NAME} 408 409 # If uboot use *bootm* to boot kernel, we should use uImage. 410 echo build_ramfs 411 echo "Copy ${IMAGE_NAME} to output directory ..." 412 cp $STAGING_DIR/${IMAGE_NAME} ${LICHEE_PLAT_OUT} 413} 414 415function build_output() 416{ 417 local ramdisk=rootfs.cpio.gz 418 local longan_ramdisk="${LICHEE_PLAT_OUT}/ramfs/images/rootfs.cpio.gz" 419 420 if [ "${ARCH}" = "arm" ]; then 421 ramdisk=rootfs_arm32.cpio.gz 422 elif [ "${ARCH}" = "arm64" ]; then 423 ramdisk=rootfs_arm64.cpio.gz 424 fi 425 426 427 # Copy all needed files to staging 428 mkdir -p $STAGING_DIR/lib/modules/$KERNEL_VERSION 429 (cd $BUILD_OUT_DIR && tar -jcf $STAGING_DIR/vmlinux.tar.bz2 vmlinux) 430 431 [ ! -f $STAGING_DIR/arisc ] && echo "arisc" > $STAGING_DIR/arisc 432 433 build_dts "false" 434 435 local copy_list=( 436 $BUILD_OUT_DIR/Module.symvers:$STAGING_DIR/lib/modules/$KERNEL_VERSION/Module.symvers 437 $BUILD_OUT_DIR/modules.order:$STAGING_DIR/lib/modules/$KERNEL_VERSION/modules.order 438 $BUILD_OUT_DIR/modules.builtin:$STAGING_DIR/lib/modules/$KERNEL_VERSION/modules.builtin 439 $BUILD_OUT_DIR/arch/${ARCH}/boot/Image:$STAGING_DIR/bImage 440 $BUILD_OUT_DIR/arch/${ARCH}/boot/zImage:$STAGING_DIR/zImage 441 $BUILD_OUT_DIR/arch/${ARCH}/boot/uImage:$STAGING_DIR/uImage 442 $BUILD_OUT_DIR/arch/${ARCH}/boot/Image.gz:$STAGING_DIR/Image.gz 443 $BUILD_OUT_DIR/scripts/dtc/dtc:$LICHEE_PLAT_OUT/dtc 444 $BUILD_OUT_DIR/.config:$STAGING_DIR/.config 445 $BUILD_OUT_DIR/System.map:$STAGING_DIR/System.map 446 $KERNEL_SRC/${ramdisk}:$STAGING_DIR/rootfs.cpio.gz 447 $KERNEL_SRC/bsp/ramfs/${ramdisk}:$STAGING_DIR/rootfs.cpio.gz 448 ) 449 # NOTE: 450 # '$KERNEL_SRC/${ramdisk}' and '$KERNEL_SRC/bsp/ramfs/${ramdisk}' must not both exist. Therefore, 451 # the existence of symlink '$KERNEL_SRC/bsp' is used to avoid an 'if independent_bsp_supported' statement. 452 453 for e in $(find $BUILD_OUT_DIR -name "*.ko"); do 454 copy_list+=($e:$STAGING_DIR/lib/modules/$KERNEL_VERSION) 455 done 456 457 if [ "x${LICHEE_LINUX_DEV}" = "xlongan" ]; then 458 copy_list+=(${longan_ramdisk}:$STAGING_DIR/rootfs.cpio.gz) 459 fi 460 461 for e in ${copy_list[@]}; do 462 [ -f ${e/:*} ] && cp -f ${e/:*} ${e#*:} 463 done 464 465 if [ -n "$(find $STAGING_DIR/lib/modules/$KERNEL_VERSION -name "*.ko")" ]; then 466 ${CROSS_COMPILE}strip -d $STAGING_DIR/lib/modules/$KERNEL_VERSION/*.ko 467 depmod -b $STAGING_DIR ${KERNEL_VERSION} 468 fi 469 470 # Copy file to plat out 471 rm -rf ${LICHEE_PLAT_OUT}/lib ${LICHEE_PLAT_OUT}/dist 472 cp -rax $STAGING_DIR/. ${LICHEE_PLAT_OUT} 473 (cd ${LICHEE_PLAT_OUT} && ln -sf lib/modules/$KERNEL_VERSION dist) 474 475 # Maybe need update modules file to buildroot output 476 if [ -d ${LICHEE_BR_OUT}/target ]; then 477 echo "Copy modules to target ..." 478 local module_dir="${LICHEE_BR_OUT}/target/lib/modules" 479 rm -rf ${module_dir} 480 mkdir -p ${module_dir} 481 cp -rf ${STAGING_DIR}/lib/modules/${KERNEL_VERSION} ${module_dir} 482 fi 483} 484 485function deal_verity_utils() 486{ 487 local action=$1 488 489 # current not implement, just return 490 echo "verity not supported yet" 491 [ "$action" == "clean" ] && return 0 || return 0 492 493 # check in the feature when supported 494 local blk_size=$1 495 local verity_dev=$2 496 local ROOTFSTYPE=$3 497 local key_file=$4 498 local verity_tools_dir="$KERNEL_SRC/verity_tools/32_bit" 499 500 [ "${ARCH}" = "arm64" ] && \ 501 verity_tools_dir="$KERNEL_SRC/verity_tools/64_bit" 502 503 if [ ! -d ${verity_tools_dir} ]; then 504 #no tools, obviously dont need to clean, do nothing 505 return 0 506 fi 507 508 build_rootfs e $STAGING_DIR/rootfs.cpio.gz $STAGING_DIR/skel >/dev/null 509 510 if [ "$action" == "clean" ]; then 511 rm -rf ${STAGING_DIR}/skel/verity_key ${STAGING_DIR}/skel/verityInfo 512 else 513 echo "blk_size="${blk_size} > ${STAGING_DIR}/skel/verityInfo 514 echo "verity_dev="${verity_dev} >> ${STAGING_DIR}/skel/verityInfo 515 echo "ROOTFSTYPE="${ROOTFSTYPE} >> ${STAGING_DIR}/skel/verityInfo 516 517 if [ ! -f ${STAGING_DIR}/skel/usr/bin/openssl ]; then 518 if [ -f ${verity_tools_dir}/openssl ]; then 519 echo "ramfs do not have openssl bin, use a prebuild one" 520 cp ${verity_tools_dir}/openssl ${STAGING_DIR}/skel/usr/bin 521 else 522 echo "no avaliable openssl found, can not enable dm-verity" 523 return 2 524 fi 525 fi 526 527 if [ ! -f ${STAGING_DIR}/skel/usr/sbin/veritysetup ]; then 528 if [ -f ${verity_tools_dir}/veritysetup ]; then 529 echo "ramfs do not have veritysetup bin, use a prebuild one" 530 cp ${verity_tools_dir}/veritysetup ${STAGING_DIR}/skel/usr/sbin 531 else 532 echo "no avaliable veritysetup found, can not enable dm-verity" 533 return 2 534 fi 535 fi 536 cp ${key_file} ${STAGING_DIR}/skel/verity_key 537 fi 538 539 build_rootfs c $STAGING_DIR/skel $STAGING_DIR/rootfs.cpio.gz >/dev/null 540 rm -rf ${STAGING_DIR}/skel1 ${STAGING_DIR}/skel 541 542 build_ramfs 543 return 0 544} 545 546function build_main() 547{ 548 case "$1" in 549 kernel) 550 build_kernel 551 build_output 552 build_ramfs 553 ;; 554 modules) 555 build_modules 556 build_output 557 build_ramfs 558 ;; 559 clean|distclean) 560 clean_modules 561 clean_kernel "$1" 562 ;; 563 deal_verity) 564 shift 565 deal_verity_utils $@ 566 ;; 567 dts) 568 build_dts 569 ;; 570 *) 571 build_kernel 572 build_modules 573 build_output 574 build_ramfs 575 echo -e "\n\033[0;31;1m${LICHEE_CHIP} compile Kernel successful\033[0m\n\n" 576 ;; 577 esac 578} 579 580build_setup $@ 581 582build_main $@ 583