<code class="hljs vala has-numbering"><span class="hljs-preprocessor">#编译流程</span> <span class="hljs-preprocessor">#lichee 目录下 </span> ./build.sh -p sun7i_android -k <span class="hljs-number">3.4 </span></code><code class="hljs bash has-numbering"><span class="hljs-comment"></span> </code><code class="hljs vala has-numbering"><span class="hljs-number"></span></code>
<code class="hljs bash has-numbering"><span class="hljs-comment">#build.sh 解析</span> <span class="hljs-shebang">#!/bin/bash </span> <span style="color:#FF0000;"><strong><span class="hljs-keyword">set</span> <span class="hljs-operator">-e</span> </strong></span> <span class="hljs-comment">#"Exit immediately if a simple command exits with a non-zero status."</span> <span class="hljs-comment">#也就是说,在"set -e"之后出现的代码,一旦出现了返回值非零,整个脚本就会立即退出</span> <span style="color:#FF0000;"><strong>buildroot/scripts/mkcommon.sh <span class="hljs-variable">$@</span></strong></span> <span class="hljs-comment">#$@ 为参数 <strong>-p sun7i_android -k 3.4</strong></span><strong> </strong></code>
<code class="hljs bash has-numbering"><span class="hljs-comment">#mkcommon.sh</span> <span class="hljs-shebang">#!/bin/bash</span> <span class="hljs-comment">#</span> <span class="hljs-comment"># scripts/mkcommon.sh</span> <span class="hljs-comment"># (c) Copyright 2013</span> <span class="hljs-comment"># Allwinner Technology Co., Ltd. <www.allwinnertech.com></span> <span class="hljs-comment"># James Deng <csjamesdeng@allwinnertech.com></span> <span class="hljs-comment">#</span> <span class="hljs-comment"># This program is free software; you can redistribute it and/or modify</span> <span class="hljs-comment"># it under the terms of the GNU General Public License as published by</span> <span class="hljs-comment"># the Free Software Foundation; either version 2 of the License, or</span> <span class="hljs-comment"># (at your option) any later version.</span> <span style="color:#FF0000;"><strong>BR_SCRIPTS_DIR=`dirname <span class="hljs-variable">$0</span>`</strong></span> <span class="hljs-comment">#提取出运行目录 <strong>./buildroot/scripts/</strong></span> <span class="hljs-keyword">if</span> [ <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span> = <span class="hljs-string">"pack"</span> ] ; <span class="hljs-keyword">then</span> <span class="hljs-comment">#如果是运行打包动作</span> <span class="hljs-variable">${BR_SCRIPTS_DIR}</span>/build_pack.sh <span class="hljs-comment">#运行打包脚本</span> <span class="hljs-keyword">exit</span> <span class="hljs-number">0</span> <span class="hljs-keyword">fi</span> <span class="hljs-comment"># source shflags</span> <span style="color:#FF0000;"><strong>. <span class="hljs-variable">${BR_SCRIPTS_DIR}</span>/shflags/shflags</strong></span> <span class="hljs-comment">#加载命令行工具</span> <span style="color:#FF0000;"><strong>. <span class="hljs-variable">${BR_SCRIPTS_DIR}</span>/mkcmd.sh </strong></span> <span class="hljs-comment">#加载shell编译脚本</span> <span class="hljs-comment"># define option, format:</span> <span class="hljs-comment"># 'long option' 'default value' 'help message' 'short option'</span> <span class="hljs-comment">#命令行工具shflags使用</span> <span class="hljs-comment">#三个参数含义分别为命令行参数名,参数默认值,以及参数的帮助信息</span> <strong>DEFINE_string <span class="hljs-string">'platform'</span> <span class="hljs-string">'sun7i'</span> <span class="hljs-string">'platform to build, e.g. sun7i'</span> <span class="hljs-string">'p'</span> DEFINE_string <span class="hljs-string">'kernel'</span> <span class="hljs-string">'3.4'</span> <span class="hljs-string">'kernel to build, e.g. 3.3'</span> <span class="hljs-string">'k'</span> DEFINE_string <span class="hljs-string">'board'</span> <span class="hljs-string">''</span> <span class="hljs-string">'board to build, e.g. evb'</span> <span class="hljs-string">'b'</span> DEFINE_string <span class="hljs-string">'module'</span> <span class="hljs-string">''</span> <span class="hljs-string">'module to build, e.g. buildroot, kernel, uboot, clean'</span> <span class="hljs-string">'m'</span> DEFINE_boolean <span class="hljs-string">'independent'</span> <span class="hljs-literal">false</span> <span class="hljs-string">'output build to independent directory'</span> <span class="hljs-string">'i'</span></strong> <span class="hljs-comment"># parse the command-line</span> <span class="hljs-comment"># 解析传进来的参数</span> <strong>FLAGS <span class="hljs-string">"<span class="hljs-variable">$@</span>"</span> || <span class="hljs-keyword">exit</span> $?</strong> <span class="hljs-comment">#语法:eval cmdLine</span> <span class="hljs-comment">#eval会对后面的cmdLine进行两遍扫描,如果第一遍扫描后,cmdLine是个普通命令,则执行此命令;</span> <span class="hljs-comment">#如果cmdLine中含有变量的间接引用,则保证间接引用的语义。</span> <strong><span class="hljs-built_in">eval</span> <span class="hljs-keyword">set</span> -- <span class="hljs-string">"<span class="hljs-variable">${FLAGS_ARGV}</span>"</span> <span class="hljs-comment">#参数是: -p sun7i_android -k 3.4</span> chip=<span class="hljs-variable">${FLAGS_platform%%_*}</span> <span class="hljs-comment">#提取出chip sun7i</span> platform=<span class="hljs-variable">${FLAGS_platform##*_}</span> <span class="hljs-comment">#提取出平台 android</span> kernel=<span class="hljs-variable">${FLAGS_kernel}</span> <span class="hljs-comment">#提取出内核 3.4 </span> board=<span class="hljs-variable">${FLAGS_board}</span> <span class="hljs-comment">#提取出板子 这里空</span> module=<span class="hljs-variable">${FLAGS_module}</span> <span class="hljs-comment">#提取出模块 这里空</span> <span class="hljs-keyword">if</span> [ <span class="hljs-string">"<span class="hljs-variable">${platform}</span>"</span> = <span class="hljs-string">"<span class="hljs-variable">${chip}</span>"</span> ] ; <span class="hljs-keyword">then</span> <span class="hljs-comment">#如果未指定平台,默认为linux</span> platform=<span class="hljs-string">"linux"</span> <span class="hljs-keyword">fi</span> <span class="hljs-keyword">if</span> [ -z <span class="hljs-string">"<span class="hljs-variable">${module}</span>"</span> ] ; <span class="hljs-keyword">then</span> <span class="hljs-comment">#如果未指定模块,默认编译所有</span> module=<span class="hljs-string">"all"</span> <span class="hljs-keyword">fi</span> <span class="hljs-keyword">if</span> ! init_chips <span class="hljs-variable">${chip}</span> || \ <span class="hljs-comment">#初始化芯片参数: sun7i</span> <span class="hljs-comment">#查询该目录下{LICHEE_TOOLS_DIR}/pack/chips/是否有 以该芯片命名的目录</span> <span class="hljs-comment">#并导出该变量 export LICHEE_CHIP=${chip}</span> ! init_platforms <span class="hljs-variable">${chip}</span> <span class="hljs-variable">${platform}</span> ; <span class="hljs-keyword">then</span> <span class="hljs-comment">#检查是否支持该平台 </span> <span class="hljs-comment">#并导出 export LICHEE_PLATFORM=${platform}</span> mk_error <span class="hljs-string">"invalid platform '<span class="hljs-variable">${FLAGS_platform}</span>'"</span> <span class="hljs-keyword">exit</span> <span class="hljs-number">1</span> <span class="hljs-keyword">fi</span> <span class="hljs-keyword">if</span> [ <span class="hljs-variable">${FLAGS_board}</span> ] && \ <span class="hljs-comment">#如果指定了板子,检查是否支持该板子</span> ! init_boards <span class="hljs-variable">${chip}</span> <span class="hljs-variable">${platform}</span> <span class="hljs-variable">${board}</span> ; <span class="hljs-keyword">then</span> mk_error <span class="hljs-string">"invalid board '<span class="hljs-variable">${FLAGS_board}</span>'"</span> <span class="hljs-keyword">exit</span> <span class="hljs-number">1</span> <span class="hljs-keyword">fi</span> <span class="hljs-keyword">if</span> [ <span class="hljs-string">"<span class="hljs-variable">${kernel}</span>"</span> = <span class="hljs-string">"3.3"</span> ] ; <span class="hljs-keyword">then</span> <span class="hljs-comment">#如果指定了内核3.3 ,判断该目录是否存在</span> <span class="hljs-comment"># 3.4 就不检查了?</span> LICHEE_KERN_DIR=<span class="hljs-variable">${LICHEE_TOP_DIR}</span>/linux-<span class="hljs-number">3.3</span> <span class="hljs-keyword">if</span> [ ! <span class="hljs-operator">-d</span> <span class="hljs-variable">${LICHEE_KERN_DIR}</span> ] ; <span class="hljs-keyword">then</span> mk_error <span class="hljs-string">"invalid kernel '<span class="hljs-variable">${kernel}</span>'"</span> <span class="hljs-keyword">exit</span> <span class="hljs-number">1</span> <span class="hljs-keyword">fi</span> <span class="hljs-keyword">fi</span></strong> <span class="hljs-comment"># init output directory</span> <strong>init_outdir </strong> <span class="hljs-comment">#初始化输出目录,检查配置是否存在</span> <span class="hljs-comment">#这里默认配置:sun7ismp_android_defconfig,配置组成在check_kern_defconf 函数中</span> <span class="hljs-comment">#请自己查看</span> <span class="hljs-comment">#设置了导出目录:</span> <span class="hljs-comment"># export LICHEE_PLAT_OUT="${LICHEE_OUT_DIR}/${LICHEE_PLATFORM}/common" </span> <span class="hljs-comment">#导出plat 目录 .../lichee/out/android/common</span> <span class="hljs-comment">#export LICHEE_BR_OUT="${LICHEE_PLAT_OUT}/buildroot"</span> <span class="hljs-comment">#导出 br 目录 ../lichee/out/android/common/buildroot</span> <strong><span class="hljs-keyword">if</span> [ <span class="hljs-variable">${module}</span> = <span class="hljs-string">"all"</span> ]; <span class="hljs-keyword">then</span> mklichee <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${module}</span> = <span class="hljs-string">"boot"</span> ] ; <span class="hljs-keyword">then</span> mkboot <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${module}</span> = <span class="hljs-string">"buildroot"</span> ] ; <span class="hljs-keyword">then</span> mkbr <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${module}</span> = <span class="hljs-string">"kernel"</span> ] ; <span class="hljs-keyword">then</span> mkkernel <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${module}</span> = <span class="hljs-string">"uboot"</span> ] ; <span class="hljs-keyword">then</span> mkuboot <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${module}</span> = <span class="hljs-string">"clean"</span> ] ; <span class="hljs-keyword">then</span> mkclean <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${module}</span> = <span class="hljs-string">"mrproer"</span> ] ; <span class="hljs-keyword">then</span> mkmrproer <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${module}</span> = <span class="hljs-string">"distclean"</span> ] ; <span class="hljs-keyword">then</span> mkdistclean <span class="hljs-keyword">else</span> mk_error <span class="hljs-string">"invalid module '<span class="hljs-variable">${module}</span>'"</span> <span class="hljs-keyword">exit</span> <span class="hljs-number">1</span> <span class="hljs-keyword">fi</span> <span class="hljs-keyword">exit</span> $? </strong>#在 /home/work/CubieBoard2_SDK/lichee/buildroot/scripts </code><pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span style="color:#FF0000;"><strong>mkcmd.sh 中</strong></span></code>
<code class="hljs php has-numbering"><span class="hljs-comment">#编译all</span> <strong><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mklichee</span><span class="hljs-params">()</span> {</span> mksetting <span class="hljs-comment">#打印编译信息</span> mk_info <span class="hljs-string">"build lichee ..."</span> <span class="hljs-comment">#显示编译,带颜色显示</span></strong> <span class="hljs-comment">#编译交叉编译工具 ----这里就不分析了</span> <span class="hljs-comment">#编译内核 </span> <span class="hljs-comment">#编译uboot</span> <span class="hljs-comment">#编译文件系统</span> <strong> mkbr && mkkernel && mkuboot && mkrootfs [ $? -ne <span class="hljs-number">0</span> ] && <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> mk_info <span class="hljs-string">"build lichee OK."</span> }</strong></code>
编译内核所做的事情:
#,根据平台配置,编译内核 ,把编译好的内核,模块 以及.config 拷到了output 目录下
#把output 目录下的所有内容,LICHEE_PLAT_OUT
#也就是 …/lichee/out/android/common
编译uboot 所做的事情
# 根据平台选择编译脚本 —–其实这一步没起作用,最终用的build.sh
# 先make distclean ,再根据芯片 sun7i进行编译,生成u-boot.bin
#所有这里可以选择把distclean 去掉,节约编译时间
# 把u-boot.bin拷贝到了 lichee/out/android/common 目录下
编译rootfs所做的事情:
#根据linux 或者dragonboard 做相应的操作
# 而这 do nothing ,skip
//———————————-other ————————————
<code class="hljs bash has-numbering">function <span class="hljs-function"><span class="hljs-title">mkrootfs</span></span>() { mk_info <span class="hljs-string">"build rootfs ..."</span> <span class="hljs-keyword">if</span> [ <span class="hljs-variable">${LICHEE_PLATFORM}</span> = <span class="hljs-string">"linux"</span> ] ; <span class="hljs-keyword">then</span> make O=<span class="hljs-variable">${LICHEE_BR_OUT}</span> -C <span class="hljs-variable">${LICHEE_BR_DIR}</span> target-generic-getty-busybox [ $? <span class="hljs-operator">-ne</span> <span class="hljs-number">0</span> ] && mk_error <span class="hljs-string">"build rootfs Failed"</span> && <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> make O=<span class="hljs-variable">${LICHEE_BR_OUT}</span> -C <span class="hljs-variable">${LICHEE_BR_DIR}</span> target-finalize [ $? <span class="hljs-operator">-ne</span> <span class="hljs-number">0</span> ] && mk_error <span class="hljs-string">"build rootfs Failed"</span> && <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> make O=<span class="hljs-variable">${LICHEE_BR_OUT}</span> -C <span class="hljs-variable">${LICHEE_BR_DIR}</span> LICHEE_GEN_ROOTFS=y rootfs-ext4 [ $? <span class="hljs-operator">-ne</span> <span class="hljs-number">0</span> ] && mk_error <span class="hljs-string">"build rootfs Failed"</span> && <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> cp <span class="hljs-variable">${LICHEE_BR_OUT}</span>/images/rootfs.ext4 <span class="hljs-variable">${LICHEE_PLAT_OUT}</span> <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${LICHEE_PLATFORM}</span> = <span class="hljs-string">"dragonboard"</span> ] ; <span class="hljs-keyword">then</span> <span class="hljs-built_in">echo</span> <span class="hljs-string">"Regenerating dragonboard Rootfs..."</span> (<span class="hljs-built_in">cd</span> <span class="hljs-variable">${LICHEE_BR_DIR}</span>/target/dragonboard; \ <span class="hljs-keyword">if</span> [ ! <span class="hljs-operator">-d</span> <span class="hljs-string">"./rootfs"</span> ]; <span class="hljs-keyword">then</span> \ <span class="hljs-built_in">echo</span> <span class="hljs-string">"extract dragonboard rootfs.tar.gz"</span>; \ tar zxf rootfs.tar.gz; \ <span class="hljs-keyword">fi</span> \ ) mkdir -p <span class="hljs-variable">${LICHEE_BR_DIR}</span>/target/dragonboard/rootfs/lib/modules rm -rf <span class="hljs-variable">${LICHEE_BR_DIR}</span>/target/dragonboard/rootfs/lib/modules/* cp -rf <span class="hljs-variable">${LICHEE_KERN_DIR}</span>/output/lib/modules/* <span class="hljs-variable">${LICHEE_BR_DIR}</span>/target/dragonboard/rootfs/lib/modules/ (<span class="hljs-built_in">cd</span> <span class="hljs-variable">${LICHEE_BR_DIR}</span>/target/dragonboard; ./build.sh) cp <span class="hljs-variable">${LICHEE_BR_DIR}</span>/target/dragonboard/rootfs.ext4 <span class="hljs-variable">${LICHEE_PLAT_OUT}</span> <span class="hljs-keyword">else</span> mk_info <span class="hljs-string">"skip make rootfs for <span class="hljs-variable">${LICHEE_PLATFORM}</span>"</span> <span class="hljs-keyword">fi</span> mk_info <span class="hljs-string">"build rootfs OK."</span> }</code>
<code class="hljs bash has-numbering"><span class="hljs-comment"># return true if used default config</span> function <span class="hljs-function"><span class="hljs-title">check_uboot_defconf</span></span>() { local defconf local ret=<span class="hljs-number">1</span> defconf=<span class="hljs-string">"<span class="hljs-variable">${LICHEE_CHIP}</span>_<span class="hljs-variable">${LICHEE_PLATFORM}</span>_<span class="hljs-variable">${LICHEE_BOARD}</span>"</span> <span class="hljs-comment">#编译 sun7i_android</span> <span class="hljs-comment">#这里少了一个.sh,脚本有问题:sun7i_android.sh</span> <span class="hljs-keyword">if</span> [ ! <span class="hljs-operator">-f</span> <span class="hljs-variable">${LICHEE_UBOOT_DIR}</span>/include/configs/<span class="hljs-variable">${defconf}</span> ] ; <span class="hljs-keyword">then</span> ret=<span class="hljs-number">0</span> defconf=<span class="hljs-string">"<span class="hljs-variable">${LICHEE_CHIP}</span>"</span> <span class="hljs-comment">#这里少了一个.sh 应该为:sun7i.sh</span> <span class="hljs-keyword">fi</span> <span class="hljs-keyword">export</span> LICHEE_UBOOT_DEFCONF=<span class="hljs-variable">${defconf}</span> <span class="hljs-keyword">return</span> <span class="hljs-variable">${ret}</span> } function <span class="hljs-function"><span class="hljs-title">mkuboot</span></span>() { mk_info <span class="hljs-string">"build u-boot ..."</span> local build_script <span class="hljs-keyword">if</span> check_uboot_defconf ; <span class="hljs-keyword">then</span> <span class="hljs-comment">#查看配置是是否存在,指定编译脚本</span> build_script=<span class="hljs-string">"build.sh"</span> <span class="hljs-comment">#运行此编译脚本</span> <span class="hljs-keyword">else</span> build_script=<span class="hljs-string">"build_<span class="hljs-variable">${LICHEE_CHIP}</span>_<span class="hljs-variable">${LICHEE_PLATFORM}</span>_<span class="hljs-variable">${LICHEE_BOARD}</span>.sh"</span> <span class="hljs-keyword">fi</span> prepare_toolchain //运行编译脚本 (<span class="hljs-built_in">cd</span> <span class="hljs-variable">${LICHEE_UBOOT_DIR}</span> && [ -x <span class="hljs-variable">${build_script}</span> ] && ./<span class="hljs-variable">${build_script}</span>) [ $? <span class="hljs-operator">-ne</span> <span class="hljs-number">0</span> ] && mk_error <span class="hljs-string">"build u-boot Failed"</span> && <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> mk_info <span class="hljs-string">"build u-boot OK."</span> } <span class="hljs-comment">#关键的编译函数:</span> function <span class="hljs-function"><span class="hljs-title">build_uboot</span></span>() { <span class="hljs-keyword">case</span> <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span> <span class="hljs-keyword">in</span> clean) make distclean CROSS_COMPILE=arm-linux-gnueabi- ;; *) make distclean CROSS_COMPILE=arm-linux-gnueabi- <span class="hljs-comment">#清楚所有配置</span> make -j<span class="hljs-variable">${jobs}</span> <span class="hljs-variable">${LICHEE_CHIP}</span> CROSS_COMPILE=arm-linux-gnueabi- <span class="hljs-comment">#根据芯片 编译 这里是sun7i</span> [ $? <span class="hljs-operator">-ne</span> <span class="hljs-number">0</span> ] && <span class="hljs-keyword">exit</span> <span class="hljs-number">1</span> <span class="hljs-comment">#拷贝u-boot.bin 到输出目录</span> cp <span class="hljs-operator">-f</span> u-boot.bin ../out/<span class="hljs-variable">${LICHEE_PLATFORM}</span>/common/ ;; <span class="hljs-keyword">esac</span> } </code>
<code class="hljs bash has-numbering">function mksetting() <span class="hljs-comment">#打印要编译的信息</span> { <span class="hljs-built_in">printf</span> <span class="hljs-string">"\n"</span> <span class="hljs-built_in">printf</span> <span class="hljs-string">"mkscript current setting:\n"</span> <span class="hljs-built_in">printf</span> <span class="hljs-string">" Chip: <span class="hljs-variable">${LICHEE_CHIP}</span>\n"</span> <span class="hljs-built_in">printf</span> <span class="hljs-string">" Platform: <span class="hljs-variable">${LICHEE_PLATFORM}</span>\n"</span> <span class="hljs-built_in">printf</span> <span class="hljs-string">" Board: <span class="hljs-variable">${LICHEE_BOARD}</span>\n"</span> <span class="hljs-built_in">printf</span> <span class="hljs-string">" Output Dir: <span class="hljs-variable">${LICHEE_PLAT_OUT}</span>\n"</span> <span class="hljs-built_in">printf</span> <span class="hljs-string">"\n"</span> } </code>
编译内核函数
<code class="hljs bash has-numbering">function <span class="hljs-function"><span class="hljs-title">mkkernel</span></span>() { mk_info <span class="hljs-string">"build kernel ..."</span> local build_script <span class="hljs-keyword">if</span> check_kern_defconf ; <span class="hljs-keyword">then</span> <span class="hljs-comment">#检查设置,编译配置文件</span> <span class="hljs-keyword">if</span> [ <span class="hljs-variable">${LICHEE_PLATFORM}</span> = <span class="hljs-string">"linux"</span> ] ; <span class="hljs-keyword">then</span> build_script=<span class="hljs-string">"scripts/build_<span class="hljs-variable">${LICHEE_CHIP}</span>.sh"</span> <span class="hljs-keyword">else</span> build_script=<span class="hljs-string">"scripts/build_<span class="hljs-variable">${LICHEE_CHIP}</span>_<span class="hljs-variable">${LICHEE_PLATFORM}</span>.sh"</span> <span class="hljs-comment">#指定编译脚本 scripts/build_sun7i_android.sh</span> <span class="hljs-keyword">fi</span> <span class="hljs-keyword">else</span> build_script=<span class="hljs-string">"scripts/build_<span class="hljs-variable">${LICHEE_CHIP}</span>_<span class="hljs-variable">${LICHEE_PLATFORM}</span>_<span class="hljs-variable">${LICHEE_BOARD}</span>.sh"</span> <span class="hljs-keyword">fi</span> prepare_toolchain <span class="hljs-comment">#准备交叉编译工具,就是导出环境变量</span> <span class="hljs-comment">#lichee/out/android/common/buildroot/external-toolchain</span> <span class="hljs-comment"># mark kernel .config belong to which platform</span> local config_mark=<span class="hljs-string">"<span class="hljs-variable">${LICHEE_KERN_DIR}</span>/.config.mark"</span> <span class="hljs-comment">#标记编译平台 android</span> <span class="hljs-keyword">if</span> [ <span class="hljs-operator">-f</span> <span class="hljs-variable">${config_mark}</span> ] ; <span class="hljs-keyword">then</span> <span class="hljs-keyword">if</span> ! grep -q <span class="hljs-string">"<span class="hljs-variable">${LICHEE_PLATFORM}</span>"</span> <span class="hljs-variable">${config_mark}</span> ; <span class="hljs-keyword">then</span> mk_info <span class="hljs-string">"clean last time build for different platform"</span> (<span class="hljs-built_in">cd</span> <span class="hljs-variable">${LICHEE_KERN_DIR}</span> && [ -x <span class="hljs-variable">${build_script}</span> ] && ./<span class="hljs-variable">${build_script}</span> <span class="hljs-string">"clean"</span>) <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">${LICHEE_PLATFORM}</span>"</span> > <span class="hljs-variable">${config_mark}</span> <span class="hljs-keyword">fi</span> <span class="hljs-keyword">else</span> <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">${LICHEE_PLATFORM}</span>"</span> > <span class="hljs-variable">${config_mark}</span> <span class="hljs-keyword">fi</span> <span class="hljs-comment">#进入内核目录 ,检查编译脚本是否可执行,执行该脚本</span> <span class="hljs-comment">#./scripts/build_sun7i_android.sh</span> (<span class="hljs-built_in">cd</span> <span class="hljs-variable">${LICHEE_KERN_DIR}</span> && [ -x <span class="hljs-variable">${build_script}</span> ] && ./<span class="hljs-variable">${build_script}</span>) [ $? <span class="hljs-operator">-ne</span> <span class="hljs-number">0</span> ] && mk_error <span class="hljs-string">"build kernel Failed"</span> && <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> mk_info <span class="hljs-string">"build kernel OK."</span> } </code>脚本#build_sun7i_android.sh 如下
<code class="hljs bash has-numbering"><span class="hljs-shebang">#!/bin/bash</span> <span class="hljs-comment">#</span> <span class="hljs-comment"># scripts/build_sun7i_android.h</span> <span class="hljs-comment">#</span> <span class="hljs-comment"># (c) Copyright 2013</span> <span class="hljs-comment"># Allwinner Technology Co., Ltd. <www.allwinnertech.com></span> <span class="hljs-comment"># James Deng <csjamesdeng@allwinnertech.com></span> <span class="hljs-comment">#</span> <span class="hljs-comment"># This program is free software; you can redistribute it and/or modify</span> <span class="hljs-comment"># it under the terms of the GNU General Public License as published by</span> <span class="hljs-comment"># the Free Software Foundation; either version 2 of the License, or</span> <span class="hljs-comment"># (at your option) any later version.</span> <span class="hljs-keyword">set</span> <span class="hljs-operator">-e</span> cpu_cores=`cat /proc/cpuinfo | grep <span class="hljs-string">"processor"</span> | wc <span class="hljs-operator">-l</span>` <span class="hljs-keyword">if</span> [ <span class="hljs-variable">${cpu_cores}</span> -le <span class="hljs-number">8</span> ] ; <span class="hljs-keyword">then</span> jobs=<span class="hljs-variable">${cpu_cores}</span> <span class="hljs-keyword">else</span> jobs=`expr <span class="hljs-variable">${cpu_cores}</span> / <span class="hljs-number">2</span>` <span class="hljs-keyword">fi</span> <span class="hljs-comment"># Setup common variables</span> <span class="hljs-keyword">export</span> ARCH=arm <span class="hljs-keyword">export</span> CROSS_COMPILE=arm-linux-gnueabi- <span class="hljs-keyword">export</span> AS=<span class="hljs-variable">${CROSS_COMPILE}</span>as <span class="hljs-keyword">export</span> LD=<span class="hljs-variable">${CROSS_COMPILE}</span>ld <span class="hljs-keyword">export</span> CC=<span class="hljs-variable">${CROSS_COMPILE}</span>gcc <span class="hljs-keyword">export</span> AR=<span class="hljs-variable">${CROSS_COMPILE}</span>ar <span class="hljs-keyword">export</span> NM=<span class="hljs-variable">${CROSS_COMPILE}</span>nm <span class="hljs-keyword">export</span> STRIP=<span class="hljs-variable">${CROSS_COMPILE}</span>strip <span class="hljs-keyword">export</span> OBJCOPY=<span class="hljs-variable">${CROSS_COMPILE}</span>objcopy <span class="hljs-keyword">export</span> OBJDUMP=<span class="hljs-variable">${CROSS_COMPILE}</span>objdump KERNEL_VERSION=<span class="hljs-string">"3.4"</span> LICHEE_KDIR=`<span class="hljs-built_in">pwd</span>` LICHEE_MOD_DIR=<span class="hljs-variable">${LICHEE_KDIR}</span>/output/lib/modules/<span class="hljs-variable">${KERNEL_VERSION}</span> <span class="hljs-keyword">export</span> LICHEE_KDIR <span class="hljs-function"><span class="hljs-title">build_standby</span></span>() { <span class="hljs-built_in">echo</span> <span class="hljs-string">"build standby"</span> <span class="hljs-comment"># If .config is newer than include/config/auto.conf, someone tinkered</span> <span class="hljs-comment"># with it and forgot to run make oldconfig.</span> <span class="hljs-comment"># if auto.conf.cmd is missing then we are probably in a cleaned tree so</span> <span class="hljs-comment"># we execute the config step to be sure to catch updated Kconfig files</span> <span class="hljs-keyword">if</span> [ .config -nt include/config/auto.conf -o \ ! <span class="hljs-operator">-f</span> include/config/auto.conf.cmd ] ; <span class="hljs-keyword">then</span> <span class="hljs-built_in">echo</span> <span class="hljs-string">"Generating autoconf.h for standby"</span> make <span class="hljs-operator">-f</span> Makefile ARCH=arm CROSS_COMPILE=<span class="hljs-variable">${CROSS_COMPILE}</span> \ silentoldconfig <span class="hljs-keyword">fi</span> make ARCH=<span class="hljs-variable">${ARCH}</span> CROSS_COMPILE=<span class="hljs-variable">${CROSS_COMPILE}</span> KDIR=<span class="hljs-variable">${LICHEE_KDIR}</span> \ -C <span class="hljs-variable">${LICHEE_KDIR}</span>/arch/arm/mach-sun7i/pm/standby all } NAND_ROOT=<span class="hljs-variable">${LICHEE_KDIR}</span>/modules/nand <span class="hljs-function"><span class="hljs-title">build_nand_lib</span></span>() { <span class="hljs-built_in">echo</span> <span class="hljs-string">"build nand library <span class="hljs-variable">${NAND_ROOT}</span>/lib"</span> <span class="hljs-keyword">if</span> [ <span class="hljs-operator">-d</span> <span class="hljs-variable">${NAND_ROOT}</span>/lib ]; <span class="hljs-keyword">then</span> <span class="hljs-built_in">echo</span> <span class="hljs-string">"build nand library now"</span> make -C modules/nand/lib clean <span class="hljs-number">2</span>> /dev/null make -C modules/nand/lib lib install <span class="hljs-keyword">else</span> <span class="hljs-built_in">echo</span> <span class="hljs-string">"build nand with existing library"</span> <span class="hljs-keyword">fi</span> } HDMI_ROOT=<span class="hljs-variable">${LICHEE_KDIR}</span>/drivers/video/sun7i/hdmi/aw <span class="hljs-function"><span class="hljs-title">build_hdmi_lib</span></span>() { <span class="hljs-built_in">echo</span> <span class="hljs-string">"build hdcp library <span class="hljs-variable">${HDMI_ROOT}</span>/hdcp"</span> <span class="hljs-keyword">if</span> [ <span class="hljs-operator">-d</span> <span class="hljs-variable">${HDMI_ROOT}</span>/hdcp ]; <span class="hljs-keyword">then</span> <span class="hljs-built_in">echo</span> <span class="hljs-string">"build hdcp library now"</span> <span class="hljs-comment"># make -C ${HDMI_ROOT}/hdcp clean 2>/dev/null</span> make -C <span class="hljs-variable">${HDMI_ROOT}</span>/hdcp install <span class="hljs-keyword">else</span> <span class="hljs-built_in">echo</span> <span class="hljs-string">"build hdcp with existing library"</span> <span class="hljs-keyword">fi</span> } <span class="hljs-function"><span class="hljs-title">build_kernel</span></span>() { <span class="hljs-built_in">echo</span> <span class="hljs-string">"Building kernel"</span> <span class="hljs-keyword">if</span> [ ! <span class="hljs-operator">-f</span> .config ] ; <span class="hljs-keyword">then</span> <span class="hljs-comment">#如果配置文件不存在,则拷贝编译脚本</span> <span class="hljs-built_in">printf</span> <span class="hljs-string">"\n\033[0;31;1mUsing default config ...\033[0m\n\n"</span> cp arch/arm/configs/<span class="hljs-variable">${LICHEE_KERN_DEFCONF}</span> .config <span class="hljs-keyword">fi</span> build_standby <span class="hljs-comment">#编译内核</span> make ARCH=arm CROSS_COMPILE=<span class="hljs-variable">${CROSS_COMPILE}</span> -j<span class="hljs-variable">${jobs}</span> uImage modules <span class="hljs-comment">#二进制拷贝</span> <span class="hljs-variable">${OBJCOPY}</span> -R .note.gnu.build-id -S -O binary vmlinux bImage <span class="hljs-comment">#删除原来的输出目录</span> rm -rf output <span class="hljs-comment">#创建模块输出目录</span> mkdir -p <span class="hljs-variable">${LICHEE_MOD_DIR}</span> <span class="hljs-comment">#拷贝内核文件</span> cp bImage output/ <span class="hljs-comment">#把配置文件也拷贝到了输出目录</span> cp .config output/ <span class="hljs-comment">#把所有 模块拷贝到了 output/lib/modules/3.4/</span> <span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> $(find drivers sound crypto block fs security net -name <span class="hljs-string">"*.ko"</span>); <span class="hljs-keyword">do</span> cp <span class="hljs-variable">$file</span> <span class="hljs-variable">${LICHEE_MOD_DIR}</span> <span class="hljs-keyword">done</span> cp <span class="hljs-operator">-f</span> Module.symvers <span class="hljs-variable">${LICHEE_MOD_DIR}</span> <span class="hljs-comment">#cp drivers/net/wireless/bcm4330/firmware/bcm4330.bin ${LICHEE_MOD_DIR}</span> <span class="hljs-comment">#cp drivers/net/wireless/bcm4330/firmware/bcm4330.hcd ${LICHEE_MOD_DIR}</span> <span class="hljs-comment">#cp drivers/net/wireless/bcm4330/firmware/nvram.txt ${LICHEE_MOD_DIR}/bcm4330_nvram.txt</span> } <span class="hljs-function"><span class="hljs-title">build_modules</span></span>() { <span class="hljs-built_in">echo</span> <span class="hljs-string">"Building modules"</span> <span class="hljs-keyword">if</span> [ ! <span class="hljs-operator">-f</span> include/generated/utsrelease.h ]; <span class="hljs-keyword">then</span> <span class="hljs-built_in">printf</span> <span class="hljs-string">"Please build kernel first\n"</span> <span class="hljs-keyword">exit</span> <span class="hljs-number">1</span> <span class="hljs-keyword">fi</span> make -C modules/example LICHEE_MOD_DIR=<span class="hljs-variable">${LICHEE_MOD_DIR}</span> LICHEE_KDIR=<span class="hljs-variable">${LICHEE_KDIR}</span> \ install build_nand_lib make -C modules/nand LICHEE_MOD_DIR=<span class="hljs-variable">${LICHEE_MOD_DIR}</span> LICHEE_KDIR=<span class="hljs-variable">${LICHEE_KDIR}</span> \ install build_hdmi_lib make -C drivers/video/sun7i/hdmi/aw LICHEE_MOD_DIR=<span class="hljs-variable">${LICHEE_MOD_DIR}</span> LICHEE_KDIR=<span class="hljs-variable">${LICHEE_KDIR}</span> \ install ( <span class="hljs-keyword">export</span> LANG=en_US.UTF-<span class="hljs-number">8</span> <span class="hljs-built_in">unset</span> LANGUAGE make -C modules/mali LICHEE_MOD_DIR=<span class="hljs-variable">${LICHEE_MOD_DIR}</span> LICHEE_KDIR=<span class="hljs-variable">${LICHEE_KDIR}</span> \ install ) <span class="hljs-comment">##build ar6302 sdio wifi module</span> <span class="hljs-comment">#make -C modules/wifi/ar6302/AR6K_SDK_ISC.build_3.1_RC.329/host CROSS_COMPILE=${CROSS_COMPILE} \</span> <span class="hljs-comment"># ARCH=arm KERNEL_DIR=${LICHEE_KDIR} INSTALL_DIR=${LICHEE_MOD_DIR} \</span> <span class="hljs-comment"># all install</span> <span class="hljs-comment">##build ar6003 sdio wifi module</span> <span class="hljs-comment">#make -C modules/wifi/ar6003/AR6kSDK.build_3.1_RC.514/host CROSS_COMPILE=${CROSS_COMPILE} \</span> <span class="hljs-comment"># ARCH=arm KERNEL_DIR=${LICHEE_KDIR} INSTALL_DIR=${LICHEE_MOD_DIR} \</span> <span class="hljs-comment"># all</span> <span class="hljs-comment">##build usi-bmc4329 sdio wifi module</span> <span class="hljs-comment">#make -C modules/wifi/usi-bcm4329/v4.218.248.15/open-src/src/dhd/linux \</span> <span class="hljs-comment"># CROSS_COMPILE=${CROSS_COMPILE} ARCH=arm LINUXVER=${KERNEL_VERSION} \</span> <span class="hljs-comment"># LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LINUXDIR=${LICHEE_KDIR} \</span> <span class="hljs-comment"># INSTALL_DIR=${LICHEE_MOD_DIR} dhd-cdc-sdmmc-gpl</span> <span class="hljs-comment">##build bcm40181 sdio wifi module 5.90.125.69.2</span> <span class="hljs-comment">#make -C modules/wifi/bcm40181/5.90.125.69.2/open-src/src/dhd/linux \</span> <span class="hljs-comment"># CROSS_COMPILE=${CROSS_COMPILE} ARCH=arm LINUXVER=${KERNEL_VERSION} \</span> <span class="hljs-comment"># LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LINUXDIR=${LICHEE_KDIR} \</span> <span class="hljs-comment"># INSTALL_DIR=${LICHEE_MOD_DIR} OEM_ANDROID=1 dhd-cdc-sdmmc-gpl</span> <span class="hljs-comment">##build bcm40183 sdio wifi module</span> <span class="hljs-comment">#make -C modules/wifi/bcm40183/5.90.125.95.3/open-src/src/dhd/linux \</span> <span class="hljs-comment"># CROSS_COMPILE=${CROSS_COMPILE} ARCH=arm LINUXVER=${KERNEL_VERSION} \</span> <span class="hljs-comment"># LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LINUXDIR=${LICHEE_KDIR} \</span> <span class="hljs-comment"># INSTALL_DIR=${LICHEE_MOD_DIR} OEM_ANDROID=1 dhd-cdc-sdmmc-gpl</span> } <span class="hljs-function"><span class="hljs-title">gen_output</span></span>() { <span class="hljs-built_in">echo</span> <span class="hljs-string">"Copy output to target ..."</span> rm -rf <span class="hljs-variable">${LICHEE_PLAT_OUT}</span>/lib cp -rf <span class="hljs-variable">${LICHEE_KDIR}</span>/output/* <span class="hljs-variable">${LICHEE_PLAT_OUT}</span> } <span class="hljs-function"><span class="hljs-title">clean_kernel</span></span>() { <span class="hljs-built_in">echo</span> <span class="hljs-string">"Cleaning kernel"</span> make distclean rm -rf output/* } <span class="hljs-function"><span class="hljs-title">clean_modules</span></span>() { <span class="hljs-built_in">echo</span> <span class="hljs-string">"Cleaning modules"</span> make -C modules/example LICHEE_MOD_DIR=<span class="hljs-variable">${LICHEE_MOD_DIR}</span> LICHEE_KDIR=<span class="hljs-variable">${LICHEE_KDIR}</span> clean ( <span class="hljs-keyword">export</span> LANG=en_US.UTF-<span class="hljs-number">8</span> <span class="hljs-built_in">unset</span> LANGUAGE make -C modules/mali LICHEE_MOD_DIR=<span class="hljs-variable">${LICHEE_MOD_DIR}</span> LICHEE_KDIR=<span class="hljs-variable">${LICHEE_KDIR}</span> clean ) <span class="hljs-comment">##build ar6302 sdio wifi module</span> <span class="hljs-comment">#make -C modules/wifi/ar6302/AR6K_SDK_ISC.build_3.1_RC.329/host CROSS_COMPILE=${CROSS_COMPILE} \</span> <span class="hljs-comment"># ARCH=arm KERNEL_DIR=${LICHEE_KDIR} INSTALL_DIR=${LICHEE_MOD_DIR} \</span> <span class="hljs-comment"># clean</span> <span class="hljs-comment">##build ar6003 sdio wifi module</span> <span class="hljs-comment">#make -C modules/wifi/ar6003/AR6kSDK.build_3.1_RC.514/host CROSS_COMPILE=${CROSS_COMPILE} \</span> <span class="hljs-comment"># ARCH=arm KERNEL_DIR=${LICHEE_KDIR} INSTALL_DIR=${LICHEE_MOD_DIR} \</span> <span class="hljs-comment"># clean</span> <span class="hljs-comment">##build usi-bmc4329 sdio wifi module</span> <span class="hljs-comment">#make -C modules/wifi/usi-bcm4329/v4.218.248.15/open-src/src/dhd/linux \</span> <span class="hljs-comment"># CROSS_COMPILE=${CROSS_COMPILE} ARCH=arm LINUXVER=${KERNEL_VERSION} \</span> <span class="hljs-comment"># LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LINUXDIR=${LICHEE_KDIR} \</span> <span class="hljs-comment"># INSTALL_DIR=${LICHEE_MOD_DIR} clean</span> <span class="hljs-comment">##build bcm40181 sdio wifi module 5.90.125.69.2</span> <span class="hljs-comment">#make -C modules/wifi/bcm40181/5.90.125.69.2/open-src/src/dhd/linux \</span> <span class="hljs-comment"># CROSS_COMPILE=${CROSS_COMPILE} ARCH=arm LINUXVER=${KERNEL_VERSION} \</span> <span class="hljs-comment"># LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LINUXDIR=${LICHEE_KDIR} \</span> <span class="hljs-comment"># INSTALL_DIR=${LICHEE_MOD_DIR} clean</span> <span class="hljs-comment">##build bcm40183 sdio wifi module</span> <span class="hljs-comment">#make -C modules/wifi/bcm40183/5.90.125.95.3/open-src/src/dhd/linux \</span> <span class="hljs-comment"># CROSS_COMPILE=${CROSS_COMPILE} ARCH=arm LINUXVER=${KERNEL_VERSION} \</span> <span class="hljs-comment"># LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LINUXDIR=${LICHEE_KDIR} \</span> <span class="hljs-comment"># INSTALL_DIR=${LICHEE_MOD_DIR} OEM_ANDROID=1 clean</span> } <span class="hljs-keyword">case</span> <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span> <span class="hljs-keyword">in</span> kernel) build_kernel ;; modules) build_modules ;; clean) clean_modules clean_kernel ;; *) build_kernel <span class="hljs-comment">#编译内核 ,把编译好的内核,模块 拷到了output 目录下</span> build_modules <span class="hljs-comment">#变所有模块</span> gen_output <span class="hljs-comment">#把output 目录下的所有内核,LICHEE_PLAT_OUT</span> <span class="hljs-comment">#也就是 .../lichee/out/android/common</span> ;; <span class="hljs-keyword">esac</span></code>
<ul style="display: block;" class="pre-numbering"><li> </li></ul>
http://blog.csdn.net/jiege6699/article/details/44341551