#!/bin/bash # Description: This shell script used to build linux system SDK. You can # use command line argument to specify build target, or select # it by hand if no argument given by command line. More detail # information can refer to the help message. # # Author: guowenxue # Version: 1.0.0 PROJ_PATH=`pwd` PACK_PATH=${PROJ_PATH}/tarballs PATCH_PATH=${PROJ_PATH}/patches PATCH_SUFIX=ok335x.patch LINUX_SRC=linux-3.2.0 UBOOT_SRC=u-boot-2011.09 ROOTFS_SRC=rootfs ROOTFS_IMG=ubifs.img TFTP_PATH=/tftp IMGS_PATH=images target= set -e function show_help() { printf "Usage: $1 [system/u-boot/kernel/rootfs/clean]\n\n" echo "system: build all source code " echo "u-boot: just build u-boot " echo "kernel: just build linux kernel " echo "rootfs: just build rootfs images" printf "clean : clean the source code\n\n" exit 0; } function show_banner() { echo "+---------------------------------------------+" printf "$1\n" echo "+---------------------------------------------+" } function select_target() { targets=("" "system" "u-boot" "kernel" "rootfs" "clean") echo "Please select a build target:" echo "1 , build all source code " echo "2 , just build u-boot " echo "3 , just build linux kernel " echo "4 , just build rootfs image" echo "5 , clean the source code" echo "" stty erase '^H' read -p "Enter your choise [1-5] : " choice if [ $choice -gt 5 ] ; then echo "ERROR: Invalid input choice, exit now..." exit 1; fi target=${targets[$choice]} } function build_uboot() { if [ ! -d ${UBOOT_SRC} ] ; then tar -xJf ${PACK_PATH}/${UBOOT_SRC}.tar.xz cd ${UBOOT_SRC} patch -p1 < ${PATCH_PATH}/${UBOOT_SRC}-${PATCH_SUFIX} else cd ${UBOOT_SRC} fi show_banner "| start uboot build task... |" chmod a+x build.sh bash build.sh show_banner "| uboot build task over! |" cd - } function build_kernel() { if [ ! -d ${ROOTFS_SRC} ] ; then echo "WARNNING: decompress rootfs need input sudo passwd here: " sudo tar -xJf ${PACK_PATH}/${ROOTFS_SRC}.tar.xz fi if [ ! -d ${LINUX_SRC} ] ; then tar -xJf ${PACK_PATH}/${LINUX_SRC}.tar.xz cd ${LINUX_SRC} patch -p1 < ${PATCH_PATH}/${LINUX_SRC}-${PATCH_SUFIX} else cd ${LINUX_SRC} fi show_banner "| start kernel build task... |" chmod a+x build.sh bash build.sh show_banner "| kernel build task over! |" cd - } #/tmp >: ubiattach -m 5 -d 5 /dev/ubi_ctrl #[ 822.268210] UBI: attaching mtd5 to ubi5 #[ 822.272237] UBI: physical eraseblock size: 131072 bytes (128 KiB) #[ 822.278848] UBI: logical eraseblock size: 126976 bytes #[ 822.284479] UBI: smallest flash I/O unit: 2048 #[ 822.289398] UBI: VID header offset: 2048 (aligned 2048) #[ 822.295665] UBI: data offset: 4096 function build_ubifs() { ubinize_cfg=ubinize.cfg ubimg_tmp=ubi.img partition_size=140 # MiB # PEB counter: PartitionSize / PagesPerBlock(64) / PageSize(2K) partition_peb_cnt=`expr $partition_size \* 1024 / 64 / 2` # LEB counter need reserved some blocks for UBI badblock used. partition_leb_cnt=`expr $partition_peb_cnt - 20` echo "Parition size ${partition_size}MiB set LEB=$partition_leb_cnt" set -x mkfs.ubifs -F -d ${ROOTFS_SRC} -m 2048 -e 126976 -c $partition_leb_cnt -o ubi.img set +x printf "[ubifs] \nmode=ubi \nimage=${ubimg_tmp} \nvol_id=0 \nvol_size=${partition_size}MiB\n" > $ubinize_cfg printf "vol_type=dynamic \nvol_name=rootfs \nvol_flags=autoresize\n" >> $ubinize_cfg ubinize -o ${ROOTFS_IMG} -m 2048 -p 128KiB $ubinize_cfg rm -f $ubimg_tmp $ubinize_cfg chmod a+x ${ROOTFS_IMG} } function build_rootfs() { if [ ! -d ${ROOTFS_SRC} ] ; then echo "WARNNING: decompress rootfs need input sudo passwd here: " sudo tar -xJf ${PACK_PATH}/${ROOTFS_SRC}.tar.xz fi show_banner "| start build rootfs image... |" build_ubifs show_banner "| rootfs image build over! |" if [ -d ${IMGS_PATH} ] ; then cp -f ${ROOTFS_IMG} ${IMGS_PATH} fi if [ -d ${TFTP_PATH} ] ; then cp -f ${ROOTFS_IMG} ${TFTP_PATH} fi rm -f ${ROOTFS_IMG} ls ${IMGS_PATH} } function do_clean() { show_banner "| clean project source code |" # cleanup rootfs image rm -rf ${ROOTFS_SRC} ${ROOTFS_IMG} # cleanup u-boot source code if [ -d ${UBOOT_SRC} ] ; then cd ${UBOOT_SRC} bash build.sh clean cd - fi # cleanup linux kernel source code if [ -d ${LINUX_SRC} ] ; then cd ${LINUX_SRC} bash build.sh clean cd - fi } function do_build() { if [ "$target" = "system" ] ; then build_uboot build_rootfs build_kernel elif [ "$target" = "u-boot" ] ; then build_uboot elif [ "$target" = "kernel" ] ; then build_kernel elif [ "$target" = "rootfs" ] ; then build_rootfs elif [ "$target" = "clean" ] ; then do_clean else show_help fi } mkdir -p ${IMGS_PATH} # check input arguments for build target if [ $# -ge 1 ] ; then target=$1 else select_target fi show_banner "| choose build target [$target] |" do_build