1 build_kernel() 2 { 3 # 进入源码顶层目录 4 cd ${BS_DIR_KERNEL} || return 1 5 # 编译配置文件 6 make ${BS_CONFIG_KERNEL} ARCH=arm CROSS_COMPILE=${BS_CROSS_TOOLCHAIN_KERNEL} || return 1 7 # 编译内核uImage(arm架构、交叉编译工具) 8 make -j${threads} ARCH=arm CROSS_COMPILE=${BS_CROSS_TOOLCHAIN_KERNEL} uImage || return 1 9 # 拷贝 uImage 到输出文件夹 10 cp -v ${BS_DIR_KERNEL}/arch/arm/boot/uImage ${BS_DIR_RELEASE} 11 12 echo "^_^ kernel path: ${BS_DIR_RELEASE}/uImage" 13 14 # 进入源码顶层目录 15 cd ${BS_DIR_TOP} || return 1 16 echo 'boot.img ->' ${BS_DIR_RELEASE} 17 # Make boot.img with ext4 format, 64MB 18 # 拷贝uImage到boot目录下 19 cp -v ${BS_DIR_RELEASE}/uImage ${BS_DIR_TARGET}/boot 20 # 使用mkuserimg.sh编译boot下文件为boot.img 21 mkuserimg.sh -s ${BS_DIR_TARGET}/boot ${BS_DIR_TARGET}/boot.img ext4 boot 67108864 22 # 将输出的boot.img拷贝到输出文件夹 23 cp -av ${BS_DIR_TARGET}/boot.img ${BS_DIR_RELEASE} || return 1; 24 25 return 0 26 } 27 28 mk脚本之内核编译及boot.img制作
1 #!/bin/bash -x 2 # 3 # To call this script, make sure make_ext4fs is somewhere in PATH 4 # 打印信息 5 function usage() { 6 cat<<EOT 7 Usage: 8 mkuserimg.sh [-s] SRC_DIR OUTPUT_FILE EXT_VARIANT MOUNT_POINT SIZE [FILE_CONTEXTS] 9 EOT 10 } 11 12 echo "in mkuserimg.sh PATH=$PATH" 13 14 ENABLE_SPARSE_IMAGE= 15 if [ "$1" = "-s" ]; then 16 ENABLE_SPARSE_IMAGE="-s" 17 shift 18 fi 19 # 判断参数长度 去除-s 5个或6个(可选参数) 20 if [ $# -ne 5 -a $# -ne 6 ]; then 21 usage 22 exit 1 23 fi 24 # 源码树不存在容错 25 SRC_DIR=$1 26 if [ ! -d $SRC_DIR ]; then 27 echo "Can not find directory $SRC_DIR!" 28 exit 2 29 fi 30 # 参数赋值 31 OUTPUT_FILE=$2 32 EXT_VARIANT=$3 33 MOUNT_POINT=$4 34 SIZE=$5 35 FC=$6 36 # 扩展类型仅支持ext4,其余则打印提示 37 case $EXT_VARIANT in 38 ext4) ;; 39 *) echo "Only ext4 is supported!"; exit 3 ;; 40 esac 41 # 挂载点长度为0容错 42 if [ -z $MOUNT_POINT ]; then 43 echo "Mount point is required" 44 exit 2 45 fi 46 # 文件系统长度为0容错 47 if [ -z $SIZE ]; then 48 echo "Need size of filesystem" 49 exit 2 50 fi 51 # 可选参数非零则赋值 52 if [ -n "$FC" ]; then 53 FCOPT="-S $FC" 54 fi 55 # 编译脚本命令 56 MAKE_EXT4FS_CMD="make_ext4fs $ENABLE_SPARSE_IMAGE $FCOPT -l $SIZE -a $MOUNT_POINT $OUTPUT_FILE $SRC_DIR" 57 echo $MAKE_EXT4FS_CMD 58 $MAKE_EXT4FS_CMD
# 最后执行的命令代码不为0,则执行异常 59 if [ $? -ne 0 ]; then 60 exit 4 61 fi
mkuserimg.sh脚本之打包
make_ext4fs各参数的含义
1. $simg2img system.img system_old.img
2. $mkdir system
3. mount -t ext4 -o loop system_old.img system
4. 修改system目录下的文件
5. $./make_ext4fs -s -l 512M -a system system_new.img system #512M表分区大小 第一个system表示挂载点为/system, 第二个system表示system目录。
6. system_new.img进行烧写