{"id":254043,"date":"2013-01-08T11:32:46","date_gmt":"2013-01-08T03:32:46","guid":{"rendered":"http:\/\/blog.zhenglei.net\/?p=254043"},"modified":"2013-01-08T11:32:46","modified_gmt":"2013-01-08T03:32:46","slug":"script-to-build-android-kernel-under-ubuntu","status":"publish","type":"post","link":"https:\/\/blog.zhenglei.net\/?p=254043","title":{"rendered":"Script to Build Android Kernel Under Ubuntu"},"content":{"rendered":"<p>#!\/bin\/bash<br \/>\n#<br \/>\nANDROID=&#8221;android-4.1.1_r6.1&#8243;<br \/>\nGCC=4.4.3<\/p>\n<p>KERNEL=goldfish<br \/>\nKCONFIG=goldfish_armv7_defconfig<\/p>\n<p>#GIT_SERVER=aosp.zhenglei.net<br \/>\nGIT_SERVER=127.0.0.1<br \/>\nGIT_PATH=&#8221;git\/aosp&#8221;<\/p>\n<p>PREBUILT=prebuilt<br \/>\nHOST=&#8221;linux-x86&#8243;<br \/>\nARCH=&#8221;arm&#8221;<br \/>\nBUILD_PATH=&#8221;build&#8221;<\/p>\n<p>function get_Tool {<br \/>\nLOC=&#8221;$1&#8243;<br \/>\nTAG=&#8221;$2&#8243;<br \/>\nVER=&#8221;$3&#8243;<br \/>\nTOOL_CHAIN=${ARCH}-eabi-${GCC}<\/p>\n<p>if [ ! -d ${LOC}\/${TOOL_CHAIN} ];then<br \/>\nif [ ! -d ${PREBUILT}\/${TOOL_PATH} ];then<br \/>\nif [ -d ${PREBUILT} ];then<br \/>\nrm -rf ${PREBUILT}<br \/>\nfi<br \/>\ngit clone git:\/\/${GIT_SERVER}\/${GIT_PATH}\/platform\/prebuilt<br \/>\nfi<\/p>\n<p>cd ${PREBUILT}<br \/>\nCUR_BRANCH=`git branch|grep &#8220;^* &#8220;|sed &#8220;s\/^* \/\/&#8221;`<br \/>\nif [ &#8220;${CUR_BRANCH}&#8221; != &#8220;${TAG}&#8221; ];then<br \/>\n#\u00a0\u00a0\u00a0 git tag -l<br \/>\ngit checkout -b ${TAG}<br \/>\nfi<br \/>\ncd ..<\/p>\n<p>cp -r ${PREBUILT}\/${HOST}\/toolchain\/${TOOL_CHAIN} ${LOC}<\/p>\n<p>fi<br \/>\nTOOL_PATH=&#8221;`pwd`\/${LOC}\/${TOOL_CHAIN}&#8221;<br \/>\n}<\/p>\n<p>function get_Kernel {<br \/>\nkernel=&#8221;$1&#8243;<br \/>\nif [ ! -d ${kernel} ];then<br \/>\ngit clone git:\/\/${GIT_SERVER}\/${GIT_PATH}\/kernel\/${kernel}.git<br \/>\nfi<\/p>\n<p>cd ${kernel}<br \/>\n# git branch -a<br \/>\nCUR_BRANCH=`git branch|grep &#8220;^* &#8220;|sed &#8220;s\/^* \/\/&#8221;`<br \/>\nif [ &#8220;${CUR_BRANCH}&#8221; != &#8220;${kernel}&#8221; ];then<br \/>\ngit checkout -t remotes\/origin\/android-${kernel}-2.6.29 -b ${kernel}<br \/>\nfi<br \/>\nif [ ! -d ..\/${BUILD_PATH}\/${kernel} ];then<br \/>\nmkdir ..\/${BUILD_PATH}\/${kernel}<br \/>\ngit archive &#8211;format tar HEAD|tar x -C ..\/${BUILD_PATH}\/${kernel}\/<br \/>\nfi<br \/>\ncd ..<br \/>\n}<\/p>\n<p>function build_Kernel {<br \/>\nconfig=$1<br \/>\ncd ${BUILD_PATH}\/${kernel}<br \/>\n#ls -l arch\/${ARCH}\/configs\/<br \/>\nmake ${config}<\/p>\n<p>START=`date +%s`<br \/>\necho &#8220;Start to build at time:\u00a0 $START&#8221;<br \/>\necho &#8220;################################&#8221;<br \/>\necho<br \/>\necho<\/p>\n<p>make -j4<\/p>\n<p>echo<br \/>\necho<br \/>\necho &#8220;################################&#8221;<br \/>\nFINISH=`date +%s`<br \/>\necho &#8220;Finish build at time: $FINISH&#8221;<br \/>\necho<br \/>\nELAPSED=`expr $FINISH &#8211; $START`<br \/>\necho &#8220;Elapsed time: $ELAPSED&#8221;<br \/>\ncd ..<br \/>\ncd ..<br \/>\n}<\/p>\n<p>##### Main ######<br \/>\nif [ ! -d ${BUILD_PATH} ];then<br \/>\nmkdir ${BUILD_PATH}<br \/>\nfi<\/p>\n<p>rm -rf ${BUILD_PATH}\/*<\/p>\n<p>get_Tool $BUILD_PATH $ANDROID $GCC<\/p>\n<p>export ARCH=arm<br \/>\nexport SUBARCH=arm<br \/>\nexport CROSS_COMPILE=arm-eabi-<br \/>\nexport PATH=${TOOL_PATH}\/bin:$PATH<\/p>\n<p>get_Kernel $KERNEL<\/p>\n<p>build_Kernel $KCONFIG<\/p>\n<p># Output<\/p>\n<p>cp ${BUILD_PATH}\/${KERNEL}\/arch\/${ARCH}\/boot\/zImage ${BUILD_PATH}\/${KERNEL}\/<\/p>\n<p># Luanch emulator with build kernel<br \/>\n# emulator -kernel ${KERNEL}\/zImage<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/bash # ANDROID=&#8221;android-4.1 &hellip; <a href=\"https:\/\/blog.zhenglei.net\/?p=254043\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2],"tags":[71],"class_list":["post-254043","post","type-post","status-publish","format-standard","hentry","category-android","category-linux","tag-kernel"],"_links":{"self":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/254043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=254043"}],"version-history":[{"count":1,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/254043\/revisions"}],"predecessor-version":[{"id":254044,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/254043\/revisions\/254044"}],"wp:attachment":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=254043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=254043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=254043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}