结构如下:
build_linux_targetfs.sh
#!/bin/bashCHECK_MARK="\033[0;32m\xE2\x9C\x94\033[0m"
X_MARK="\033[0;1;31mX\033[0m"export TOP_DIR=$PWD
export TARGET_IMAGE_PATH=$TOP_DIR/filesystem/targetfs-images
export BSP_IMAGE_PATH=${TOP_DIR}/../bsp_images
build_app=mpd#usage
function usage() {echo "Usage:percp : build percp imagepnc : build pnc imagemap : build map imagemodel : build model imageplatform_service : build platform_service imageplatform : build platform imageparameter : build parameter imageall : build all above imagesexample :1. build one image:./build_linux_targetfs.sh percp2. build any numbers images:./build_linux_targetfs.sh percp pncor./build_linux_targetfs.sh percp pnc map......3. build all partitions image:./build_linux_targetfs.sh all"
}#update bsp_images
function update_bsp_images() {FLASH_IMAGE_PATH=${BSP_IMAGE_PATH}/642-63663-0001-001_TS2/flash-imagesFLASH_FILE=${FLASH_IMAGE_PATH}/FileToFlash.txt TEMP_FILE=${FLASH_IMAGE_PATH}/temp.txtFLASH_IMAGE_NAME=$TARGET_IMAGE_PATH/$1.imggrep $1_ $FLASH_FILE > $TEMP_FILENEW_MD5=$(md5sum ${FLASH_IMAGE_NAME} | awk -F " " {'print $1'})while read LINEdoIMAGE_NAME=$(echo $LINE | awk -F " " {'print $3'})cp $FLASH_IMAGE_NAME $FLASH_IMAGE_PATH/$IMAGE_NAMEsyncBAK_MD5=$(echo $LINE | awk -F " " {'print $11'})if [ "${BAK_MD5}" != "${NEW_MD5}" ];thensed -i 's/'${BAK_MD5}'/'${NEW_MD5}'/g' ${FLASH_FILE}fidone < $TEMP_FILErm -f $TEMP_FILEecho -e "\033[2K\\r${CHECK_MARK} update $1.img to bsp_images successed!"sync
}#create linux extend targetfs
function build_linux_extend_targetfs() {if [ ! -d $TARGET_IMAGE_PATH ];thenmkdir -p $TARGET_IMAGE_PATHsyncfisudo dd if=/dev/zero of=$TARGET_IMAGE_PATH/$1.img bs=16384 count=$(($2/16384))ret_val_mkxfs=$?if [ $ret_val_mkxfs -ne 0 ]; thenprintf "${X_MARK} ***ERROR*** Failed to create the filesystem/targetfs/$1.img . error code = $ret_val_mkxfs ...\n"exit ${ret_val_mkxfs}fisudo mkfs.ext4 $TARGET_IMAGE_PATH/$1.imgsudo mkdir -p $3_baksudo mount $TARGET_IMAGE_PATH/$1.img $3_baksudo cp -raf $3/* $3_baksudo umount -f $3_baksudo rm -rf $3_baksyncecho -e "\033[2K\\r${CHECK_MARK} build $1.img successed!"if [ -d $BSP_IMAGE_PATH ];thenupdate_bsp_images $1elseecho -e "\033[2K\\r${CHECK_MARK} update $1.img to bsp_images error!"fi
}#build parameter.img
function build_parameter() {IMAGE_SIZE=16777216ROOTFS_LOCAL_DIR=${TOP_DIR}/filesystem/targetfs/vehicle_parameterTARGET_IMAGE_NAME=parameterbuild_linux_extend_targetfs $TARGET_IMAGE_NAME $IMAGE_SIZE $ROOTFS_LOCAL_DIR
}#build model.img
function build_model() {IMAGE_SIZE=6442450944ROOTFS_LOCAL_DIR=${TOP_DIR}/filesystem/targetfs/modelTARGET_IMAGE_NAME=modelbuild_linux_extend_targetfs $TARGET_IMAGE_NAME $IMAGE_SIZE $ROOTFS_LOCAL_DIR
}#build platform_service.img
function build_platform_service() {IMAGE_SIZE=1073741824ROOTFS_LOCAL_DIR=${TOP_DIR}/filesystem/targetfs/platform_serviceTARGET_IMAGE_NAME=platform_servicebuild_linux_extend_targetfs $TARGET_IMAGE_NAME $IMAGE_SIZE $ROOTFS_LOCAL_DIR
}#build platform.img
function build_platform() {IMAGE_SIZE=2684354560ROOTFS_LOCAL_DIR=${TOP_DIR}/filesystem/targetfs/platformTARGET_IMAGE_NAME=platformbuild_linux_extend_targetfs $TARGET_IMAGE_NAME $IMAGE_SIZE $ROOTFS_LOCAL_DIR
}#build map.img
function build_map() {IMAGE_SIZE=1289748480ROOTFS_LOCAL_DIR=${TOP_DIR}/filesystem/targetfs/mapTARGET_IMAGE_NAME=mapbuild_linux_extend_targetfs $TARGET_IMAGE_NAME $IMAGE_SIZE $ROOTFS_LOCAL_DIR
}#build pnc.img
function build_pnc() {IMAGE_SIZE=1610612736ROOTFS_LOCAL_DIR=${TOP_DIR}/filesystem/targetfs/pncTARGET_IMAGE_NAME=pncbuild_linux_extend_targetfs $TARGET_IMAGE_NAME $IMAGE_SIZE $ROOTFS_LOCAL_DIR
}#build percp.img
function build_percp() {IMAGE_SIZE=1289748480ROOTFS_LOCAL_DIR=${TOP_DIR}/filesystem/targetfs/percpTARGET_IMAGE_NAME=percpbuild_linux_extend_targetfs $TARGET_IMAGE_NAME $IMAGE_SIZE $ROOTFS_LOCAL_DIR
}if [ $# -ge 1 ];thenfor i in "$@";docase "$i" inpercp)build_percp;;pnc)build_pnc;;map)build_map;;platform)build_platform;;platform_service)build_platform_service;;model)build_model;;parameter)build_parameter;;all)build_percpbuild_pncbuild_mapbuild_platformbuild_platform_servicebuild_modelbuild_parameter;;?)usage;;esacdoneelseusage
fi
readme 使用方法
example :
a. build one image:
./build_linux_targetfs.sh percp
b. build any numbers images:./build_linux_targetfs.sh percp pncor./build_linux_targetfs.sh percp pnc platform......c. build all partitions image:./build_linux_targetfs.sh all
- The target image:
filesystem/targetfs-images
将需要打包进镜像的文件丢进target的对应文件下,先生成ext4文件进行,然后挂载,cp拷贝到镜像包,最后卸载,这样就做出了一个镜像包,
然后将文件替换,和md5 hash值,文件大小替换烧录文件里。记录烧录起始地址,结束地址,md5等等