编译cubieboard android 源码过程详解之(七):lichee build
16lz
2021-01-26
lichee貌似是aliwinner的一个开发代号,目录下存放这与BSP相关的文件,如boot uboot kernel buildroot tools等。在该目录下执行如下命令可以看到可用的功能:
./build.sh -hNAME build - The top level build script for Lichee Linux BSPSYNOPSIS build [-h] | [-p platform] [-k kern_version] [-m module] | packOPTIONS -h Display help message -p [platform] platform, e.g. sun4i, sun4i-lite, sun4i-debug, sun4i_crane sun4i: full linux bsp sun4i-lite: linux bsp with less packages sun4i-debug: linux bsp for debug sun4i_crane: android kernel -k [kern_ver] 2.6.36(default), or 3.0 [OPTIONAL] -m [module] Use this option when you dont want to build all. [OPTIONAL] e.g. kernel, buildroot, uboot, all(default)... pack To start pack programExamples: ./build.sh -p sun4i-lite ./build.sh -p sun4i_crane ./build.sh -p sun4i-lite ./build.sh pack
对于编译安卓镜像来说,需要执行:
./build.sh -p sun4i_crane -k 3.0
build.sh
1 #!/bin/bash2 set -e3 4 buildroot/scripts/common.sh $@
buildroot/scripts/common.sh
1 if [ "$1" = "pack" ]; then2 ${BR_DIR}/scripts/build_pack.sh3 exit 04 fi
判断是否只是打包
1 while getopts hp:m:k: OPTION 2 do 3 case $OPTION in 4 h) show_help 5 exit 0 6 ;; 7 p) PLATFORM=$OPTARG 8 ;; 9 m) MODULE=$OPTARG10 ;;11 k) KERN_VER=$OPTARG12 update_kdir $KERN_VER13 ;;14 *) show_help15 exit 116 ;;17 esac18 done
之前设置的 “-p sun4i_crane -k 3.0” 在这里起作用了,有一点很重要,没有设置 -m 参数,所以是编译所有,后面会提到。
1 if [ -z "$PLATFORM" ]; then2 show_help3 exit 14 fi
不允许缺少 -p 参数
1 if [ "$MODULE" = buildroot ]; then #只编译buildroot 2 cd ${BR_DIR} && ./build.sh -p ${PLATFORM} 3 elif [ "$MODULE" = kernel ]; then #只编译kernel 4 export PATH=${BR_OUT_DIR}/external-toolchain/bin:$PATH 5 cd ${KERN_DIR} && ./build.sh -p ${PLATFORM} 6 regen_rootfs 7 gen_output_${PLATFORM} 8 elif [ "$MODULE" = "uboot" ]; then #只编译uboot 9 case ${PLATFORM} in10 a12*)11 echo "build uboot for sun5i_a12"12 cd ${U_BOOT_DIR} && ./build.sh -p sun5i_a1213 ;;14 a13*)15 echo "build uboot for sun5i_a13"16 cd ${U_BOOT_DIR} && ./build.sh -p sun5i_a1317 ;;18 *)19 echo "build uboot for ${PLATFORM}"20 cd ${U_BOOT_DIR} && ./build.sh -p ${PLATFORM}21 ;;22 esac23 else #编译所有的24 cd ${BR_DIR} && ./build.sh -p ${PLATFORM}25 export PATH=${BR_OUT_DIR}/external-toolchain/bin:$PATH26 cd ${KERN_DIR} && ./build.sh -p ${PLATFORM}27 28 case ${PLATFORM} in29 a12*)30 echo "build uboot for sun5i_a12"31 #cd ${U_BOOT_DIR} && ./build.sh -p sun5i_a1232 ;;33 a13*)34 echo "build uboot for sun5i_a13"35 #cd ${U_BOOT_DIR} && ./build.sh -p sun5i_a1336 ;;37 sun4i-test)38 echo "build uboot for sun4i test"39 #cd ${U_BOOT_DIR} && ./build.sh -p sun4i40 ;;41 *)42 echo "build uboot for ${PLATFORM}"43 cd ${U_BOOT_DIR} && ./build.sh -p ${PLATFORM}44 ;;45 esac46 47 regen_rootfs48 gen_output_${PLATFORM}49 echo "###############################"50 echo "# compile success #"51 echo "###############################"52 fi
实际上执行的最后一个 if-else 分支的内容,为了方便阅读,将变量替换为值:
cd buildroot && ./build.sh -p sun4i_cranecd linux-3.0 && ./build.sh -p sun4i_cranecd u-boot && ./build.sh -p sun4i_crane
相当于先后编译了 buildroot linux-3.0 u-boot,一个一个看。
buildroot/build.sh -p sun4i_crane
if [ -x ./scripts/build_${PLATFORM}.sh ]; then ./scripts/build_${PLATFORM}.sh $MODULEelse printf "\nERROR: Invalid Platform\n" show_help exit 1fi
替换变量后,相当于执行了
buildroot/scripts/build_sun4i_crane.sh all
查看脚本内容可知,对于android平台,跳过了buildroot。
linux-3.0/build.sh -p sun4i_crane
if [ -x ./scripts/build_${PLATFORM}.sh ]; then ./scripts/build_${PLATFORM}.sh $MODULEelse printf "\nERROR: Invalid Platform\n" show_help exit 1fi
替换变量后,相当于执行了
linux-3.0/scripts/build_sun4i_crane.sh all
linux-3.0/scripts/build_sun4i_crane.sh all
case "$1" inkernel) build_kernel ;;modules) build_modules ;;clean) clean_kernel clean_modules ;;all) build_kernel build_modules ;;*) show_help ;;esac
具体就是编译了内核和私有模块。内核当然包含kernel和modules,私有模块源码在linux-3.0/modules目录下。
最后将编译出的东西放在了 linux-3.0/output 目录下(已经根据需要就行了精简):
.├── bImage├── lib│ └── modules│ └── 3.0.8│ ├── mali.ko│ ├── Module.symvers│ └── ump.ko├── uImage└── zImage
u-boot/build.sh -p sun4i_crane
if [ "$PLATFORM" = "sun4i_crane" ]; then make distclean && make -j4 sun4i CROSS_COMPILE=arm-none-linux-gnueabi-else make distclean && make -j4 $PLATFORM CROSS_COMPILE=arm-none-linux-gnueabi-fi
正常编译 sun4i 的uboot
regen_rootfs
gen_output_sun4i_crane()
其实就是将编译出的kernel uboot modules等安装到 out 目录下:
out/├── android│ ├── bImage│ ├── lib│ │ └── modules│ │ └── 3.0.8│ │ ├── mali.ko│ │ ├── Module.symvers│ │ └── ump.ko│ ├── toolchain│ │ └── arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2│ ├── uImage│ └── zImage└── u-boot.bin
OK,分析完毕。
更多相关文章
- Android(安卓)Studio 初次见面(AVD加速)
- Android(安卓): 等待view加载完成后执行操作
- Android下用gdb远程调试
- 配置android的adb环境变量
- Ubuntu10.04下载并编译Android4.3源代码
- android源码学习之源码编译并nexus s真机刷机
- 【android studio】 gradle配置成本地离线zip包
- Android笔记之:onConfigurationChanged详解
- Android(安卓)获取APK编译时间