作者: Linux-小企鹅
博客地址:http://blog.csdn.net/u012319379/article/details/77805449
itop4418 build_android.sh_4418分析
#!/bin/bash
set -e #一般写脚本时写在最前面,如果后面的脚本执行不是true则退出不执行,可以防止错误滚雪球导致更大的错误
TOP=`pwd` #TOP变量的为当前目录路径(这个径子错了,搜狗输入发在Ubuntu中打不出来,Windows平台我试一下),
RESULT_DIR=${TOP}/result #存放编译结果的目录路径
export TOP RESULT_DIR #导出环境变量
LINUX_DIR_TARGET=${TOP}/qt_system #linux目标目录
#变量赋值
BUILD_ALL=true
BUILD_UBOOT=false
BUILD_KERNEL=false
BUILD_MODULE=false
BUILD_ANDROID=false
BUILD_DIST=false
CLEAN_BUILD=false
ROOT_DEVICE_TYPE=sd
#WIFI_DEVICE_NAME=rtl8188
#BUILD_TAG=user
BUILD_TAG=userdebug
#WIFI_DRIVER_PATH="hardware/realtek/wlan/driver/rtl8188EUS_linux_v4.3.0.3_10997.20140327"
WIFI_DRIVER_PATH="hardware/realtek/wlan/driver/rtl8188eus"
VERBOSE=false
## OTA variables
OTA_INCREMENTAL=false
OTA_PREVIOUS_FILE=
OTA_UPDATE_2NDBOOT=true
OTA_UPDATE_UBOOT=true
CHIP_NAME=
BOARD_NAME="s5p4418_drone"
BOARD_PURE_NAME=
ANDROID_VERSION_MAJOR=
#检查当前目录是不是源码的顶层目录
function check_top()
{
if [ ! -d .repo ]; then #判断.repo目录是否存在,不存在则执行输出字符并退出
echo "You must execute this script at ANDROID TOP Directory"
exit 1
fi
}
#脚本的用法
function usage()
{
echo "Usage: $0 -b <board-name> [-r <root-device-type> -c -w <wifi-device-name> -t u-boot -t kernel -t module -t android -t dist [-i previous_target.zip -d 2ndboot -d u-boot ]]"
echo -e '\n -b <board-name> : target board name (available boards: "'"$(get_available_board)"'")'
echo " -r <root-device-type> : your root device type(sd, nand, usb), default sd"
echo " -c : clean build, default no"
echo " -w : wifi device name (rtl8188, rtl8712, bcm), default rtl8188"
echo " -v : if you want to view verbose log message, specify this, default no"
echo " -t u-boot : if you want to build u-boot, specify this, default yes"
echo " -t kernel : if you want to build kernel, specify this, default yes"
echo " -t module : if you want to build driver modules, specify this, default yes"
echo " -t android : if you want to build android, specify this, default yes"
echo " -t none : if you want to only post process, specify this, default no"
echo " -t dist : if you want to build distribute image, specify this, default no"
echo " -i previous_target.zip : if you want incremental OTA update, specify this, default no"
echo " -d 2ndboot : if you don't want to update OTA 2ndboot, specify this, default no"
echo " -d u-boot : if you don't want to update OTA u-boot, specify this, default no"
}
function parse_args()
{
TEMP=`getopt -o "b:r:t:i:d:chv" -- "$@"`
eval set -- "$TEMP"
while true; do
case "$1" in
-b ) BOARD_NAME=$2; shift 2 ;;
-r ) ROOT_DEVICE_TYPE=$2; shift 2 ;;
-c ) CLEAN_BUILD=true; shift 1 ;;
#-w ) WIFI_DEVICE_NAME=$2; shift 2 ;;
-t ) case "$2" in
u-boot ) BUILD_ALL=false; BUILD_UBOOT=true ;;
kernel ) BUILD_ALL=false; BUILD_KERNEL=true ;;
module ) BUILD_ALL=false; BUILD_MODULE=true ;;
android ) BUILD_ALL=false; BUILD_ANDROID=true ;;
dist ) BUILD_ALL=false; BUILD_DIST=true ;;
none ) BUILD_ALL=false ;;
esac
shift 2 ;;
-i ) OTA_INCREMENTAL=true; OTA_PREVIOUS_FILE=$2; shift 2 ;;
-d ) case "$2" in
2ndboot ) OTA_UPDATE_2NDBOOT=false ;;
u-boot ) OTA_UPDATE_UBOOT=false ;;
esac
shift 2 ;;
-h ) usage; exit 1 ;;
-v ) VERBOSE=true; shift 1 ;;
-- ) break ;;
* ) echo "invalid option $1"; usage; exit 1 ;;
esac
done
}
function print_args()
{
if [ ${VERBOSE} == "true" ]; then
echo "=============================================="
echo " print args"
echo "=============================================="
echo -e "BOARD_NAME:\t\t${BOARD_NAME}" ##echo -e 有转义功能,可以转义\t\t
#echo -e "WIFI_DEVICE_NAME:\t${WIFI_DEVICE_NAME}"
if [ ${BUILD_ALL} == "true" ]; then
echo -e "Build:\t\t\tAll"
else
if [ ${BUILD_UBOOT} == "true" ]; then
echo -e "Build:\t\t\tu-boot"
fi
if [ ${BUILD_KERNEL} == "true" ]; then
echo -e "Build:\t\t\tkernel"
fi
if [ ${BUILD_MODULE} == "true" ]; then
echo -e "Build:\t\t\tmodule"
fi
if [ ${BUILD_ANDROID} == "true" ]; then
echo -e "Build:\t\t\tandroid"
fi
if [ ${BUILD_DIST} == "true" ]; then
echo -e "Build:\t\t\tdistribution"
fi
fi
echo -e "ROOT_DEVICE_TYPE:\t${ROOT_DEVICE_TYPE}"
echo -e "CLEAN_BUILD:\t\t${CLEAN_BUILD}"
fi
}
#清除函数
function clean_up()
{
#CLEAN_BUILD变量的值为ture时才可以有清除功能
if [ ${CLEAN_BUILD} == "true" ]; then
echo ""
echo -e -n "clean up...\t"
if [ ${BUILD_ALL} == "true" ] || [ ${BUILD_ANDROID} == "true" ]; then
rm -rf ${RESULT_DIR}#清除所有就是把result目录删除并执行clean动作
make clean
fi
echo "End"
fi
}
#uboot nand 配置
function apply_uboot_nand_config()
{
if [ ${VERBOSE} == "true" ]; then
echo ""
echo -e -n "apply nand booting config to u-boot...\t"
fi
#定义局部变量dest_file
local dest_file=${TOP}/u-boot/include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h
# backup: include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h.org
cp ${dest_file} ${dest_file}.org
local config_text_base="#define CONFIG_SYS_TEXT_BASE 0x40C00000"
#在目标文档.h中取代CONFIG_SYS_TEXT_BASE的值为0x40c00000
sed -i "s/.*#define[[:space:]]CONFIG_SYS_TEXT_BASE.*/${config_text_base}/g" ${dest_file}
local config_malloc_start="#define CONFIG_MEM_MALLOC_START 0x41000000"
#在目标文档.h中取代CONFIG_MEM_MALLOC_START的值为0x41c000000
sed -i "s/.*#define[[:space:]]CONFIG_MEM_MALLOC_START.*/${config_malloc_start}/g" ${dest_file}
local config_malloc_length="#define CONFIG_MEM_MALLOC_LENGTH 64*1024*1024 /* more than 2M for ubifs: MAX 16M */"
#在目标文档.h中取代CONFIG_MEM_MALLOC_LENGTH的值为64Mb
sed -i "s/.*#define[[:space:]]CONFIG_MEM_MALLOC_LENGTH.*/${config_malloc_length}/g" ${dest_file}
#图片在nand的位置
local config_logo_load=" #define CONFIG_CMD_LOGO_LOAD \"ext4load nand 0:1 0x47000000 logo.bmp; drawbmp 0x47000000\""
sed -i "s/.*#define[[:space:]]CONFIG_CMD_LOGO_LOAD.*/${config_logo_load}/g" ${dest_file}
#bootcommand命令环境变量
local config_bootcommand="#define CONFIG_BOOTCOMMAND \"ext4load nand 0:1 0x48000000 uImage;ext4load nand 0:1 0x49000000 root.img.gz;bootm 0x48000000\""
sed -i "s/#define[[:space:]]CONFIG_BOOTCOMMAND.*/${config_bootcommand}/g" ${dest_file}
local config_cmd_nand="#define CONFIG_CMD_NAND"
sed -i "s/\/\/#define[[:space:]]CONFIG_CMD_NAND/${config_cmd_nand}/g" ${dest_file}
if [ ${VERBOSE} == "true" ]; then
echo "End"
fi
}
#uboot分区配置
function apply_uboot_partition_config()
{
if [ ${VERBOSE} == "true" ]; then
echo ""
echo -e -n "apply sd/usb partition info at android BoardConfig.mk to u-boot...\t"
fi
#include/configs/s5p4418_drone.h
local dest_file=${TOP}/u-boot/include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h
#device/nexell/s5p4418_drone/BoardConfig.mk
local src_file=${TOP}/device/nexell/${BOARD_NAME}/BoardConfig.mk
cp ${dest_file} ${dest_file}.org
#在BoardConfig.mk文件中查找BOARD_SYSTEMIMAGE_PARTITION_SIZE的值打印后赋值给局部变量
local system_partition_size=`awk '/BOARD_SYSTEMIMAGE_PARTITION_SIZE/{print $3}' ${src_file}`
local cache_partition_size=`awk '/BOARD_CACHEIMAGE_PARTITION_SIZE/{print $3}' ${src_file}`
echo "system_partition_size: ${system_partition_size}, cache_partition_size: ${cache_partition_size}"
#取代include/configs/s5p4418_drone.h的CFG_SYSTEM_PART_SIZE变量的值
sed -i "s/#define CFG_SYSTEM_PART_SIZE.*/#define CFG_SYSTEM_PART_SIZE (${system_partition_size})/g" ${dest_file}
sed -i "s/#define CFG_CACHE_PART_SIZE.*/#define CFG_CACHE_PART_SIZE (${cache_partition_size})/g" ${dest_file}
if [ ${VERBOSE} == "true" ]; then
echo "End"
fi
}
function enable_uboot_sd_root()
{
local src_file=${TOP}/u-boot/include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h
sed -i 's/^\/\/#define[[:space:]]CONFIG_CMD_MMC/#define CONFIG_CMD_MMC/g' ${src_file}
sed -i 's/^\/\/#define[[:space:]]CONFIG_LOGO_DEVICE_MMC/#define CONFIG_LOGO_DEVICE_MMC/g' ${src_file}
local root_device_num=$(get_sd_device_number ${TOP}/device/nexell/${BOARD_NAME}/fstab.${BOARD_NAME})
sed -i 's/^#define[[:space:]]CONFIG_BOOTCOMMAND.*/#define CONFIG_BOOTCOMMAND \"ext4load mmc '"${root_device_num}"':1 0x48000000 uImage;ext4load mmc '"${root_device_num}"':1 0x49000000 root.img.gz;bootm 0x48000000\"/g' ${src_file}
sed -i 's/.*#define[[:space:]]CONFIG_CMD_LOGO_WALLPAPERS.*/ #define CONFIG_CMD_LOGO_WALLPAPERS \"ext4load mmc '"${root_device_num}"':1 0x47000000 logo.bmp; drawbmp 0x47000000\"/g' ${src_file}
sed -i 's/.*#define[[:space:]]CONFIG_CMD_LOGO_BATTERY.*/ #define CONFIG_CMD_LOGO_BATTERY \"ext4load mmc '"${root_device_num}"':1 0x47000000 battery.bmp; drawbmp 0x47000000\"/g' ${src_file}
sed -i 's/.*#define[[:space:]]CONFIG_CMD_LOGO_UPDATE.*/ #define CONFIG_CMD_LOGO_UPDATE \"ext4load mmc '"${root_device_num}"':1 0x47000000 update.bmp; drawbmp 0x47000000\"/g' ${src_file}
}
function disable_uboot_sd_root()
{
local src_file=${TOP}/u-boot/include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h
echo "src_file: ${src_file}"
#nand:release)
#sed -i 's/^#define[[:space:]]CONFIG_CMD_MMC/\/\/#define CONFIG_CMD_MMC/g' ${src_file}
sed -i 's/^#define[[:space:]]CONFIG_LOGO_DEVICE_MMC/\/\/#define CONFIG_LOGO_DEVICE_MMC/g' ${src_file}
}
function enable_uboot_nand_memory_layout()
{
local src_file=${TOP}/u-boot/include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h
local config_text_base="#define CONFIG_SYS_TEXT_BASE 0x40C00000"
sed -i "s/.*#define[[:space:]]CONFIG_SYS_TEXT_BASE.*/${config_text_base}/g" ${src_file}
local config_malloc_start="#define CONFIG_MEM_MALLOC_START 0x41000000"
sed -i "s/.*#define[[:space:]]CONFIG_MEM_MALLOC_START.*/${config_malloc_start}/g" ${src_file}
local config_malloc_length="#define CONFIG_MEM_MALLOC_LENGTH 64*1024*1024"
sed -i "s/.*#define[[:space:]]CONFIG_MEM_MALLOC_LENGTH.*/${config_malloc_length}/g" ${src_file}
}
function disable_uboot_nand_memory_layout()
{
local src_file=${TOP}/u-boot/include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h
local config_text_base="#define CONFIG_SYS_TEXT_BASE 0x42C00000"
sed -i "s/.*#define[[:space:]]CONFIG_SYS_TEXT_BASE.*/${config_text_base}/g" ${src_file}
local config_malloc_start="#define CONFIG_MEM_MALLOC_START 0x43000000"
sed -i "s/.*#define[[:space:]]CONFIG_MEM_MALLOC_START.*/${config_malloc_start}/g" ${src_file}
local config_malloc_length="#define CONFIG_MEM_MALLOC_LENGTH 32*1024*1024"
sed -i "s/.*#define[[:space:]]CONFIG_MEM_MALLOC_LENGTH.*/${config_malloc_length}/g" ${src_file}
}
function enable_uboot_nand_root()
{
local src_file=${TOP}/u-boot/include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h
sed -i 's/^\/\/#define[[:space:]]CONFIG_CMD_NAND/#define CONFIG_CMD_NAND/g' ${src_file}
sed -i 's/^\/\/#define[[:space:]]CONFIG_NAND_FTL/#define CONFIG_NAND_FTL/g' ${src_file}
sed -i 's/^\/\/#define[[:space:]]CONFIG_LOGO_DEVICE_NAND/#define CONFIG_LOGO_DEVICE_NAND/g' ${src_file}
sed -i 's/^#define[[:space:]]CONFIG_BOOTCOMMAND.*/#define CONFIG_BOOTCOMMAND \"ext4load nand 0:1 0x48000000 uImage;ext4load nand 0:1 0x49000000 root.img.gz;bootm 0x48000000\"/g' ${src_file}
sed -i 's/.*#define[[:space:]]CONFIG_CMD_LOGO_WALLPAPERS.*/ #define CONFIG_CMD_LOGO_WALLPAPERS \"ext4load nand 0:1 0x47000000 logo.bmp; drawbmp 0x47000000\"/g' ${src_file}
sed -i 's/.*#define[[:space:]]CONFIG_CMD_LOGO_BATTERY.*/ #define CONFIG_CMD_LOGO_BATTERY \"ext4load nand 0:1 0x47000000 battery.bmp; drawbmp 0x47000000\"/g' ${src_file}
sed -i 's/.*#define[[:space:]]CONFIG_CMD_LOGO_UPDATE.*/ #define CONFIG_CMD_LOGO_UPDATE \"ext4load nand 0:1 0x47000000 update.bmp; drawbmp 0x47000000\"/g' ${src_file}
}
function disable_uboot_nand_root()
{
local src_file=${TOP}/u-boot/include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h
sed -i 's/^#define[[:space:]]CONFIG_CMD_NAND/\/\/#define CONFIG_CMD_NAND/g' ${src_file}
sed -i 's/^#define[[:space:]]CONFIG_NAND_FTL/\/\/#define CONFIG_NAND_FTL/g' ${src_file}
sed -i 's/^#define[[:space:]]CONFIG_LOGO_DEVICE_NAND/\/\/#define CONFIG_LOGO_DEVICE_NAND/g' ${src_file}
}
function apply_uboot_sd_root()
{
echo "====> apply sd root"
disable_uboot_nand_root
disable_uboot_nand_memory_layout
enable_uboot_sd_root
}
function apply_uboot_nand_root()
{
echo "====> apply nand root"
disable_uboot_sd_root
enable_uboot_nand_root
enable_uboot_nand_memory_layout
}
#上面的几个函数功能的理解都差不多,可以借鉴一下理解
#编译uboot
function build_uboot()
{
if [ ${BUILD_ALL} == "true" ] || [ ${BUILD_UBOOT} == "true" ]; then
echo ""
echo "=============================================="
echo "build u-boot"
echo "=============================================="
if [ ! -e ${TOP}/u-boot ]; then
cd ${TOP}
#创建符号链接
ln -s linux/bootloader/u-boot-2014.07 u-boot
fi
cd ${TOP}/u-boot
//清除配置和编译结果文件
make distclean
echo "ROOT_DEVICE_TYPE is ${ROOT_DEVICE_TYPE}"
#判断根设备的类型
case ${ROOT_DEVICE_TYPE} in
sd) apply_uboot_sd_root ;;
nand) apply_uboot_nand_root ;;
esac
#要想更清楚的理解uboot的编译过程请查看Makefile文件,后面我会分析下
cp Makefile_4418 Makefile
make s5p4418_drone2_config
#开起8个线程,估计没有8个线程的电脑需要改改
make -j8
#check_result "build-uboot"
#if [ -f include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h.org ]; then
# mv include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h.org include/configs/${CHIP_NAME}_${BOARD_PURE_NAME}.h
$fi
cd ${TOP}
echo "---------- End of build u-boot"
fi
}
#内核nand支持
function apply_kernel_nand_config()
{
local src_file=${TOP}/kernel/arch/arm/configs/${CHIP_NAME}_${BOARD_PURE_NAME}_android_defconfig
local dst_config=${CHIP_NAME}_${BOARD_PURE_NAME}_android_defconfig.nandboot
local dst_file=${src_file}.nandboot
cp ${src_file} ${dst_file}
# FTL
sed -i 's/.*CONFIG_NXP_FTL .*/CONFIG_NXP_FTL=y\nCONFIG_NAND_FTL=y/g' ${dst_file}
# DEFAULT GOVERNER CHANGE
sed -i 's/.*CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND.*/# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set/g' ${dst_file}
sed -i 's/.*CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE.*/CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE=y/g' ${dst_file}
echo ${dst_config}
}
#编译内核
function build_kernel()
{
if [ ${BUILD_ALL} == "true" ] || [ ${BUILD_KERNEL} == "true" ]; then
echo ""
echo "=============================================="
echo "build kernel"
echo "=============================================="
if [ ! -e ${TOP}/kernel ]; then
cd ${TOP}
ln -s linux/kernel/kernel-3.4.39 kernel
fi
cd ${TOP}/kernel
#根据ANDROID_VERSION_MAJOR变量的值选择配置文件
local kernel_config=
if [ ${ANDROID_VERSION_MAJOR} == "4" ]; then
kernel_config=${CHIP_NAME}_${BOARD_PURE_NAME}_android_defconfig
elif [ ${ANDROID_VERSION_MAJOR} == "5" ]; then
kernel_config=${CHIP_NAME}_${BOARD_PURE_NAME}_android_lollipop_defconfig
else
echo "ANDROID_VERSION_MAJOR is abnormal!!! ==> ${ANDROID_VERSION_MAJOR}"
exit 1
fi
if [ ${ROOT_DEVICE_TYPE} == "nand" ]; then
kernel_config=$(apply_kernel_nand_config)
echo "nand kernel config: ${kernel_config}"
fi
#make distclean
#cp arch/arm/configs/${kernel_config} .config
#cp arch/arm/configs/iTOP6818_android_defconfig .config
yes "" | make ARCH=arm oldconfig
make ARCH=arm uImage -j8
#make ARCH=arm modules
if [ ${ROOT_DEVICE_TYPE} == "nand" ]; then
rm -f ${TOP}/arch/arm/configs/${kernel_config}
fi
check_result "build-kernel"
echo "---------- End of build kernel"
fi
}
#模块编译
function build_module()
{
if [ ${BUILD_ALL} == "true" ] || [ ${BUILD_MODULE} == "true" ]; then
echo ""
echo "=============================================="
echo "build modules"
echo "=============================================="
local out_dir=${TOP}/out/target/product/${BOARD}
mkdir -p ${out_dir}/system/lib/modules
if [ ${VERBOSE} == "true" ]; then
echo -n -e "build vr driver..."
fi
cd ${TOP}/hardware/samsung_slsi/slsiap/prebuilt/modules/vr
./build.sh
if [ ${VERBOSE} == "true" ]; then
echo "End"
fi
if [ ${VERBOSE} == "true" ]; then
echo -n -e "build coda driver..."
fi
cd ${TOP}/linux/platform/${CHIP_NAME}/modules/coda960
./build.sh
if [ ${VERBOSE} == "true" ]; then
echo "End"
fi
#if [ ${VERBOSE} == "true" ]; then
# echo -n -e "build wifi driver..."
#fi
#cd ${TOP}/${WIFI_DRIVER_PATH}
#./build.sh
#if [ ${VERBOSE} == "true" ]; then
# echo "End"
#fi
cd ${TOP}
if [ ${VERBOSE} == "true" ]; then
echo "End"
fi
echo "---------- End of build modules"
fi
}
function make_android_root()
{
local out_dir=${TOP}/out/target/product/${BOARD_NAME}
cd ${out_dir}/root
sed -i -e '/mount\ yaffs2/ d' -e '/on\ fs/ d' -e '/mount\ mtd/ d' -e '/Mount\ \// d' init.rc
awk '/console\ \/system/{print; getline; print; getline; print; getline; print; getline; print " user root"; getline}1' init.rc > /tmp/init.rc
mv /tmp/init.rc init.rc
# handle nand boot
if [ ${ROOT_DEVICE_TYPE} == "nand" ]; then
sed -i 's/.*\/dev.*\/p2.*/\/dev\/block\/mio2 \/system ext4 rw wait/g' fstab.${BOARD_NAME}
sed -i 's/.*\/dev.*\/p3.*/\/dev\/block\/mio3 \/cache ext4 noatime,nosuid,nodev,nomblk_io_submit,discard,errors=panic wait,check/g' fstab.${BOARD_NAME}
sed -i 's/.*\/dev.*\/p7.*/\/dev\/block\/mio7 \/data ext4 noatime,nosuid,nodev,nomblk_io_submit,discard,errors=panic wait,check/g' fstab.${BOARD_NAME}
fi
# arrange permission
chmod 644 *.prop
chmod 644 *.${BOARD_NAME}
chmod 644 *.rc
cd ..
rm -f root.img.gz
cd ${TOP}
}
function apply_android_overlay()
{
cd ${TOP}
local overlay_dir=${TOP}/hardware/samsung_slsi/slsiap/overlay-apps
local overlay_list_file=${overlay_dir}/files.txt
local token1=""
while read line; do
token1=$(echo ${line} | awk '{print $1}')
if [ ${token1} == "replace" ]; then
local src_file=$(echo ${line} | awk '{print $2}')
local replace_file=$(echo ${line} | awk '{print $3}')
cp ${overlay_dir}/${src_file} ${RESULT_DIR}/${replace_file}
elif [ ${token1} == "remove" ]; then
local remove_file=$(echo ${line} | awk '{print $2}')
rm -f ${RESULT_DIR}/${remove_file}
fi
done < ${overlay_list_file}
}
function remove_android_banned_files()
{
rm -f ${RESULT_DIR}/system/xbin/su
}
function refine_android_system()
{
local out_dir=${TOP}/out/target/product/${BOARD_NAME}
cd ${out_dir}/system
chmod 644 *.prop
chmod 644 lib/modules/*
cd ${TOP}
}
function patch_android()
{
cd ${TOP}
local patch_dir=${TOP}/hardware/samsung_slsi/slsiap/patch
local patch_list_file=${patch_dir}/files.txt
local src_file=""
local dst_dir=""
while read line; do
src_file=$(echo ${line} | awk '{print $1}')
dst_dir=$(echo ${line} | awk '{print $2}')
echo "copy ${patch_dir}/${src_file} =====> ${TOP}/${dst_dir}"
cp ${patch_dir}/${src_file} ${TOP}/${dst_dir}
done < ${patch_list_file}
cd ${TOP}
}
function restore_patch()
{
cd ${TOP}
if [ -d ${TOP}/.repo ]; then
local patch_dir=${TOP}/hardware/samsung_slsi/slsiap/patch
local patch_list_file=${patch_dir}/files.txt
local src_file=""
local dst_dir=""
while read line; do
src_file=$(echo ${line} | awk '{print $1}')
dst_dir=$(echo ${line} | awk '{print $2}')
echo "restore ${TOP}/${dst_dir}/${src_file}"
cd ${TOP}/${dst_dir}
git status | grep -q Untracked || git checkout ${src_file}
done < ${patch_list_file}
cd ${TOP}
fi
}
function apply_kernel_headers()
{
# make install kernel header
#local tmp_install_header=/tmp/install_headers
#mkdir -p ${tmp_install_header}
#cd ${TOP}/kernel
#make headers_install ARCH=arm INSTALL_HDR_PATH=${tmp_install_header}
#cd ${TOP}
#local header_dir=${tmp_install_header}/include
#local asm_arm_header_dir=${tmp_install_header}/include/asm
local android_kernel_header=${TOP}/external/kernel-headers/original
#cp -a ${asm_arm_header_dir}/* ${android_kernel_header}/asm-arm
#cp -a ${header_dir}/asm-generic/* ${android_kernel_header}/asm-generic
#cp -a ${header_dir}/linux/* ${android_kernel_header}/linux
##cp -a ${header_dir}/media/* ${android_kernel_header}/media
#cp -a ${header_dir}/mtd/* ${android_kernel_header}/mtd
#cp -a ${header_dir}/sound/* ${android_kernel_header}/sound
##cp -a ${header_dir}/uapi/* ${android_kernel_header}/uapi
#cp -a ${header_dir}/video/* ${android_kernel_header}/video
cp kernel/include/linux/ion.h ${android_kernel_header}/linux
${TOP}/bionic/libc/kernel/tools/update_all.py
}
function apply_kernel_ion_header()
{
local kernel_ion_header=kernel/include/linux/ion.h
local bionic_ion_header=bionic/libc/kernel/common/linux/ion.h
local libion=system/core/libion/ion.c
cp ${kernel_ion_header} ${bionic_ion_header}
sed -i 's/heap_mask/heap_id_mask/g' ${libion}
}
function build_cts()
{
make -j8 PRODUCT-aosp_${BOARD_NAME}-${BUILD_TAG} cts
}
function sign_system_private_app()
{
java -jar out/host/linux-x86/framework/signapk.jar vendor/nexell/security/${BOARD_NAME}/platform.x509.pem vendor/nexell/security/${BOARD_NAME}/platform.pk8 out/target/product/${BOARD_NAME}/system/app/OTAUpdateCenter.apk /tmp/OTAUpdateCenter.apk
mv /tmp/OTAUpdateCenter.apk out/target/product/${BOARD_NAME}/system/app/
sync
}
function generate_key()
{
echo "key generation for ${BOARD_NAME}"
[ ! -e ${TOP}/vendor/nexell/security/${BOARD_NAME}/media.pk8 ] && ${TOP}/device/nexell/tools/mkkey.sh media ${BOARD_NAME}
[ ! -e ${TOP}/vendor/nexell/security/${BOARD_NAME}/platform.pk8 ] && $(${TOP}/device/nexell/tools/mkkey.sh platform ${BOARD_NAME})
[ ! -e ${TOP}/vendor/nexell/security/${BOARD_NAME}/release.pk8 ] && ${TOP}/device/nexell/tools/mkkey.sh release ${BOARD_NAME}
[ ! -e ${TOP}/vendor/nexell/security/${BOARD_NAME}/shared.pk8 ] && ${TOP}/device/nexell/tools/mkkey.sh shared ${BOARD_NAME}
[ ! -e ${TOP}/vendor/nexell/security/${BOARD_NAME}/testkey.pk8 ] && ${TOP}/device/nexell/tools/mkkey.sh testkey ${BOARD_NAME}
echo "End of generate_key"
}
function build_android()
{
if [ ${BUILD_ALL} == "true" ] || [ ${BUILD_ANDROID} == "true" ]; then
echo ""
echo "=============================================="
echo "build android"
echo "=============================================="
#patch_android
generate_key
if [ ${ANDROID_VERSION_MAJOR} == "4" ]; then
apply_kernel_ion_header
fi
make -j8 PRODUCT-aosp_${BOARD_NAME}-${BUILD_TAG}
check_result "build-android"
make_android_root
refine_android_system
#sign_system_private_app
#build_cts
#restore_patch
echo "---------- End of build android"
fi
}
function build_dist()
{
if [ ${BUILD_DIST} == "true" ]; then
echo ""
echo "=============================================="
echo "build dist"
echo "=============================================="
#patch_android
make -j8 PRODUCT-aosp_${BOARD_NAME}-${BUILD_TAG} dist
cp ${TOP}/out/dist/aosp_${BOARD_NAME}-target_files-eng.$(whoami).zip ${RESULT_DIR}/${BOARD_NAME}-target_files.zip
local tmpdir=${RESULT_DIR}/tmp
rm -rf ${tmpdir}
rm -f ${RESULT_DIR}/target.zip
mkdir -p ${tmpdir}
unzip -o -q ${RESULT_DIR}/${BOARD_NAME}-target_files.zip -d ${tmpdir}
mkdir -p ${tmpdir}/BOOTABLE_IMAGES/
local otaver=$(cat device/nexell/${BOARD_NAME}/otaver)
otaver=$((otaver+1))
sed -i "s/setprop otaupdater.otaver.*/setprop otaupdater.otaver ${otaver}/g" ${RESULT_DIR}/root/init.${BOARD_NAME}.rc
local release_date=$(date +%Y%m%d-%H%M)
sed -i "s/setprop otaupdater.otatime.*/setprop otaupdater.otatime ${release_date}/g" ${RESULT_DIR}/root/init.${BOARD_NAME}.rc
${TOP}/device/nexell/tools/mkinitramfs.sh ${RESULT_DIR}/root ${RESULT_DIR}
cp ${RESULT_DIR}/root.img.gz ${RESULT_DIR}/boot
cp ${RESULT_DIR}/root.img.gz ${TOP}/out/target/product/${BOARD_NAME}/ramdisk.img
#nand
#if [ ${ROOT_DEVICE_TYPE} != "nand" ]; then
make_ext4 ${BOARD_NAME} boot
#fi
cp ${RESULT_DIR}/boot.img ${tmpdir}/BOOTABLE_IMAGES
cp out/target/product/${BOARD_NAME}/recovery.img ${tmpdir}/BOOTABLE_IMAGES
if [ ${OTA_UPDATE_UBOOT} == "true" ] || [ ${OTA_UPDATE_2NDBOOT} == "true" ]; then
mkdir -p ${tmpdir}/RADIO
if [ ${OTA_UPDATE_2NDBOOT} == "true" ]; then
cp device/nexell/${BOARD_NAME}/boot/2ndboot.bin ${tmpdir}/RADIO/2ndbootloader
fi
if [ ${OTA_UPDATE_UBOOT} == "true" ]; then
cp ${RESULT_DIR}/u-boot.bin ${tmpdir}/RADIO/bootloader
fi
fi
cd ${tmpdir}
zip -r -q ../target *
cd ${TOP}
cp build/tools/releasetools/common.py /tmp/
cp device/nexell/tools/common.py build/tools/releasetools/
local ota_name="ota-${BOARD_NAME}-${release_date}.zip"
local i_option=
if [ ${OTA_INCREMENTAL} == "true" ]; then
if [ -f ${OTA_PREVIOUS_FILE} ]; then
local src_tmpdir=${RESULT_DIR}/src_tmp
rm -rf ${src_tmpdir}
rm -f ${RESULT_DIR}/src_target.zip
mkdir -p ${src_tmpdir}
unzip -o -q ${OTA_PREVIOUS_FILE} -d ${src_tmpdir}
cp ${RESULT_DIR}/boot.img ${src_tmpdir}/BOOTABLE_IMAGES
cd ${src_tmpdir}
zip -r -q ../src_target *
cd ${TOP}
i_option="-i ${RESULT_DIR}/src_target.zip"
fi
fi
echo "i_option ====> ${i_option}"
build/tools/releasetools/ota_from_target_files -v -p out/host/linux-x86 -k vendor/nexell/security/${BOARD_NAME}/release ${i_option} ${RESULT_DIR}/target.zip ${RESULT_DIR}/${ota_name}
mv /tmp/common.py build/tools/releasetools/
#restore_patch
local ota_desc=${RESULT_DIR}/OTA_DESC
echo "Rom Name: aosp_${BOARD_NAME}-${BUILD_TAG} 4.4.2 KOT49H ${release_date}" > ${ota_desc}
echo "Rom ID: samsung_slsiap_${BOARD_NAME}_kk" >> ${ota_desc}
echo -e ${otaver} | awk '{print "Rom Version: " $1}' >> ${ota_desc}
echo "Rom Date: ${release_date}" >> ${ota_desc}
echo "Download URL: http://git.nexell.co.kr/_builds/${ota_name}" >> ${ota_desc}
md5sum ${RESULT_DIR}/${ota_name} | awk '{print "MD5 Checksum: " $1}' >> ${ota_desc}
echo "Device(code)name: ${BOARD_NAME}" >> ${ota_desc}
echo -e ${otaver} > device/nexell/${BOARD_NAME}/otaver
echo "---------- End of build dist"
fi
}
function make_linux_boot()
{
rm -rf ${LINUX_DIR_TARGET}/boot
mkdir -p ${LINUX_DIR_TARGET}/boot
# generate boot.img
cd ${TOP} || return 1
echo 'boot.img ->' ${BS_DIR_RELEASE}
# Make boot.img with ext4 format, 64MB
cp -v ${TOP}/kernel/arch/arm/boot/uImage ${LINUX_DIR_TARGET}/boot
if [ -f ${LINUX_DIR_TARGET}/ramdisk.img ]; then
cp -v ${LINUX_DIR_TARGET}/ramdisk.img ${LINUX_DIR_TARGET}/boot/root.img.gz
fi
if [ -f ${LINUX_DIR_TARGET}/ramdisk-recovery.img ]; then
cp -v ${LINUX_DIR_TARGET}/ramdisk-recovery.img ${LINUX_DIR_TARGET}/boot/
fi
if [ -f ${TOP}/device/nexell/${BOARD_NAME}/boot/logo.bmp ]; then
cp ${TOP}/device/nexell/${BOARD_NAME}/boot/logo.bmp $LINUX_DIR_TARGET/boot
fi
if [ -f ${TOP}/device/nexell/${BOARD_NAME}/boot/logo_800_1280.bmp ]; then
cp ${TOP}/device/nexell/${BOARD_NAME}/boot/logo_800_1280.bmp $LINUX_DIR_TARGET/boot
fi
if [ -f ${TOP}/device/nexell/${BOARD_NAME}/boot/battery.bmp ]; then
cp ${TOP}/device/nexell/${BOARD_NAME}/boot/battery.bmp $LINUX_DIR_TARGET/boot
fi
if [ -f ${TOP}/device/nexell/${BOARD_NAME}/boot/update.bmp ]; then
cp ${TOP}/device/nexell/${BOARD_NAME}/boot/update.bmp $LINUX_DIR_TARGET/boot
fi
mkuserimg.sh -s ${LINUX_DIR_TARGET}/boot ${LINUX_DIR_TARGET}/boot.img ext4 boot 67108864
cp -av ${LINUX_DIR_TARGET}/boot.img ${RESULT_DIR} || return 1;
}
function make_boot()
{
vmsg "start make_boot"
local out_dir="${TOP}/out/target/product/${BOARD_NAME}"
mkdir -p ${RESULT_DIR}/boot
cp ${TOP}/kernel/arch/arm/boot/uImage ${RESULT_DIR}/boot
copy_bmp_files_to_boot ${BOARD_NAME}
cp -a ${out_dir}/root ${RESULT_DIR}
${TOP}/device/nexell/tools/mkinitramfs.sh ${RESULT_DIR}/root ${RESULT_DIR}
cp ${RESULT_DIR}/root.img.gz ${RESULT_DIR}/boot
cp ${RESULT_DIR}/root.img.gz ${TOP}/out/target/product/${BOARD_NAME}/ramdisk.img
if [ -f ${out_dir}/ramdisk-recovery.img ]; then
cp ${out_dir}/ramdisk-recovery.img ${RESULT_DIR}/boot
fi
make_ext4 ${BOARD_NAME} boot
vmsg "end make_boot"
}
function make_qt_system()
{
vmsg "start make_system"
PATH=$PATH_BAK
rm -rf ${RESULT_DIR}/system
local out_dir="${TOP}/qt_system"
cp -a ${out_dir}/system ${RESULT_DIR}
make_ext4fs -s -l 314572800 -a root -L linux ${RESULT_DIR}/system.img ${RESULT_DIR}/system
vmsg "end make_system"
}
function make_system()
{
vmsg "start make_system"
local out_dir="${TOP}/out/target/product/${BOARD_NAME}"
cp -a ${out_dir}/system ${RESULT_DIR}
#apply_android_overlay
remove_android_banned_files
#cp ${out_dir}/system.img ${RESULT_DIR}
make_ext4 ${BOARD_NAME} system
vmsg "end make_system"
}
function make_cache()
{
vmsg "start make_cache"
local out_dir="${TOP}/out/target/product/${BOARD_NAME}"
cp -a ${out_dir}/cache ${RESULT_DIR}
#cp ${out_dir}/cache.img ${RESULT_DIR}
make_ext4 ${BOARD_NAME} cache
vmsg "end make_cache"
}
function make_userdata()
{
vmsg "start make_userdata"
local out_dir="${TOP}/out/target/product/${BOARD_NAME}"
cp -a ${out_dir}/data ${RESULT_DIR}/userdata
cp ${out_dir}/userdata.img ${RESULT_DIR}
vmsg "end make_userdata"
}
function post_process()
{
if [ ${BUILD_DIST} == "false" ]; then
echo ""
echo "=============================================="
echo "post processing"
echo "=============================================="
local out_dir="${TOP}/out/target/product/${BOARD_NAME}"
echo ${out_dir}
rm -rf ${RESULT_DIR}
mkdir -p ${RESULT_DIR}
cp ${TOP}/u-boot/u-boot.bin ${RESULT_DIR}
cp ${TOP}/u-boot/u-boot-iTOP-4418.bin ${RESULT_DIR}
cp ${TOP}/u-boot/mkuboot ${RESULT_DIR}
cp ${TOP}/u-boot/sd_fusing_uboot.sh ${RESULT_DIR}
if [ ${ROOT_DEVICE_TYPE} == "nand" ]; then
query_nand_sizes ${BOARD_NAME}
fi
if [ "$kernel_type" = "ubuntu" ] || [ "$kernel_type" = "qt" ]
then
echo "************** build boot/system for QT/Ubuntu **************"
make_linux_boot
make_qt_system
else
echo "************** build boot/system for android **************"
local out_dir="${TOP}/out/target/product/${BOARD_NAME}"
echo ${out_dir}
make_boot
make_system
make_cache
make_userdata
cp out/target/product/${BOARD_NAME}/recovery.img ${RESULT_DIR}/
fi
#make_boot
#make_system
#make_cache
#make_userdata
echo "---------- End of post processing"
fi
}
#前面的都是函数功能及具体实现,下面的才是编译的入口
#check_top
#导出环境变量,这个脚本就是一些函数功能
source device/nexell/tools/common.sh
if [ "$1" = "ubuntu" ]
then
kernel_type="ubuntu"
PATH_BAK=$PATH
PATH=${TOP}/qt_system/linux-x86/bin:$PATH;
elif [ "$1" = "qt" ]
then
kernel_type="qt"
PATH_BAK=$PATH
PATH=${TOP}/qt_system/linux-x86/bin:$PATH;
#满足传参为clean就会清除kernel,uboot,android/result目录下的文件,需要谨慎,就好把Android的result哪一行注释掉,不然下次编译又得一个钟
elif [ "$1" = "clean" ]
then
echo "Clean Android ..."
make clobber
echo "Clean Kernel ..."
cd ${TOP}/kernel/
make distclean
cd -
echo "Clean U-boot ..."
cd ${TOP}/u-boot/
make distclean
cd -
rm -rf ${RESULT_DIR}
exit 1
else
kernel_type="android"
parse_args $@
fi
#parse_args $@
print_args
export VERBOSE
#是common.sh里面的函数,,返回Android的版本
export ANDROID_VERSION_MAJOR=$(get_android_version_major)
#是common.sh里面的函数,检查工具链的版本和有没有工具链
set_android_toolchain_and_check
#根据函数从BoardConfig.mk解析出CPU的名字
CHIP_NAME=$(get_cpu_variant2 ${BOARD_NAME})
#BOARD_PURE_NAME=${BOARD_NAME%_*}
BOARD_PURE_NAME=${BOARD_NAME#*_}
check_board_name ${BOARD_NAME}
#check_wifi_device ${WIFI_DEVICE_NAME}
#clean_up
build_uboot
build_kernel
build_module
if [ "$kernel_type" = "android" ]
then
build_android
fi
#打包编译 文件为img文件
post_process
#拷贝文件到统一的目录
build_dist
总结:里面有些是相同的就没有意义分析,因为这个脚本估计是itop编写的,主要是用于一次性编译源码验证源码可不可以一次性编译通过,如果可以的话,我们后面只对更改的部分进行编译就可以,所以我们后面还得专门学习单步编译,具体的分析我们后面看看。