编译cubieboard android 源码过程详解之(七):lichee build
lichee貌似是aliwinner的一个开发代号,目录下存放这与BSP相关的文件,如boot uboot kernel buildroot tools等。在该目录下执行如下命令可以看到可用的功能:
./build.sh -h NAME build - The top level build script for Lichee Linux BSP SYNOPSIS build [-h] | [-p platform] [-k kern_version] [-m module] | pack OPTIONS -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 program Examples: ./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/bash 2 set -e 3 4 buildroot/scripts/common.sh $@
buildroot/scripts/common.sh
1 if [ "$1" = "pack" ]; then 2 ${BR_DIR}/scripts/build_pack.sh 3 exit 0 4 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=$OPTARG 10 ;; 11 k) KERN_VER=$OPTARG 12 update_kdir $KERN_VER 13 ;; 14 *) show_help 15 exit 1 16 ;; 17 esac 18 done
之前设置的 “-p sun4i_crane -k 3.0” 在这里起作用了,有一点很重要,没有设置 -m 参数,所以是编译所有,后面会提到。
1 if [ -z "$PLATFORM" ]; then 2 show_help 3 exit 1 4 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} in 10 a12*) 11 echo "build uboot for sun5i_a12" 12 cd ${U_BOOT_DIR} && ./build.sh -p sun5i_a12 13 ;; 14 a13*) 15 echo "build uboot for sun5i_a13" 16 cd ${U_BOOT_DIR} && ./build.sh -p sun5i_a13 17 ;; 18 *) 19 echo "build uboot for ${PLATFORM}" 20 cd ${U_BOOT_DIR} && ./build.sh -p ${PLATFORM} 21 ;; 22 esac 23 else #编译所有的 24 cd ${BR_DIR} && ./build.sh -p ${PLATFORM} 25 export PATH=${BR_OUT_DIR}/external-toolchain/bin:$PATH 26 cd ${KERN_DIR} && ./build.sh -p ${PLATFORM} 27 28 case ${PLATFORM} in 29 a12*) 30 echo "build uboot for sun5i_a12" 31 #cd ${U_BOOT_DIR} && ./build.sh -p sun5i_a12 32 ;; 33 a13*) 34 echo "build uboot for sun5i_a13" 35 #cd ${U_BOOT_DIR} && ./build.sh -p sun5i_a13 36 ;; 37 sun4i-test) 38 echo "build uboot for sun4i test" 39 #cd ${U_BOOT_DIR} && ./build.sh -p sun4i 40 ;; 41 *) 42 echo "build uboot for ${PLATFORM}" 43 cd ${U_BOOT_DIR} && ./build.sh -p ${PLATFORM} 44 ;; 45 esac 46 47 regen_rootfs 48 gen_output_${PLATFORM} 49 echo "###############################" 50 echo "# compile success #" 51 echo "###############################" 52 fi
实际上执行的最后一个 if-else 分支的内容,为了方便阅读,将变量替换为值:
cd buildroot && ./build.sh -p sun4i_crane cd linux-3.0 && ./build.sh -p sun4i_crane cd 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 $MODULE else printf "\nERROR: Invalid Platform\n" show_help exit 1 fi
替换变量后,相当于执行了
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 $MODULE else printf "\nERROR: Invalid Platform\n" show_help exit 1 fi
替换变量后,相当于执行了
linux-3.0/scripts/build_sun4i_crane.sh all
linux-3.0/scripts/build_sun4i_crane.sh all
case "$1" in kernel) 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,分析完毕。
posted on 2014-03-15 14:20 JonnyLulu 阅读(1570) 评论(0) 编辑 收藏 举报