1#!/bin/bash 2# 3# To call this script, make sure mksquashfs is somewhere in PATH 4 5function usage() { 6cat<<EOT 7Usage: 8${0##*/} SRC_DIR OUTPUT_FILE [-s] [-m MOUNT_POINT] [-d PRODUCT_OUT] [-C FS_CONFIG ] [-c FILE_CONTEXTS] [-B BLOCK_MAP_FILE] [-b BLOCK_SIZE] [-z COMPRESSOR] [-zo COMPRESSOR_OPT] [-t COMPRESS_THRESHOLD] [-a] 9EOT 10} 11 12echo "in mksquashfsimage.sh PATH=$PATH" 13 14if [ $# -lt 2 ]; then 15 usage 16 exit 1 17fi 18 19SRC_DIR=$1 20if [ ! -d $SRC_DIR ]; then 21 echo "Can not find directory $SRC_DIR!" 22 exit 2 23fi 24OUTPUT_FILE=$2 25shift; shift 26 27SPARSE=false 28if [[ "$1" == "-s" ]]; then 29 SPARSE=true 30 shift; 31fi 32 33MOUNT_POINT= 34if [[ "$1" == "-m" ]]; then 35 MOUNT_POINT=$2 36 shift; shift 37fi 38 39PRODUCT_OUT= 40if [[ "$1" == "-d" ]]; then 41 PRODUCT_OUT=$2 42 shift; shift 43fi 44 45FS_CONFIG= 46if [[ "$1" == "-C" ]]; then 47 FS_CONFIG=$2 48 shift; shift 49fi 50 51FILE_CONTEXTS= 52if [[ "$1" == "-c" ]]; then 53 FILE_CONTEXTS=$2 54 shift; shift 55fi 56 57BLOCK_MAP_FILE= 58if [[ "$1" == "-B" ]]; then 59 BLOCK_MAP_FILE=$2 60 shift; shift 61fi 62 63BLOCK_SIZE=131072 64if [[ "$1" == "-b" ]]; then 65 BLOCK_SIZE=$2 66 shift; shift 67fi 68 69COMPRESSOR="lz4" 70COMPRESSOR_OPT="-Xhc" 71if [[ "$1" == "-z" ]]; then 72 COMPRESSOR=$2 73 COMPRESSOR_OPT= 74 shift; shift 75fi 76 77if [[ "$1" == "-zo" ]]; then 78 COMPRESSOR_OPT=$2 79 shift; shift 80fi 81 82COMPRESS_THRESHOLD=0 83if [[ "$1" == "-t" ]]; then 84 COMPRESS_THRESHOLD=$2 85 shift; shift 86fi 87 88 89DISABLE_4K_ALIGN=false 90if [[ "$1" == "-a" ]]; then 91 DISABLE_4K_ALIGN=true 92 shift; 93fi 94 95OPT="" 96if [ -n "$MOUNT_POINT" ]; then 97 OPT="$OPT -mount-point $MOUNT_POINT" 98fi 99if [ -n "$PRODUCT_OUT" ]; then 100 OPT="$OPT -product-out $PRODUCT_OUT" 101fi 102if [ -n "$FS_CONFIG" ]; then 103 OPT="$OPT -fs-config-file $FS_CONFIG" 104fi 105if [ -n "$FILE_CONTEXTS" ]; then 106 OPT="$OPT -context-file $FILE_CONTEXTS" 107fi 108if [ -n "$BLOCK_MAP_FILE" ]; then 109 OPT="$OPT -block-map $BLOCK_MAP_FILE" 110fi 111if [ -n "$BLOCK_SIZE" ]; then 112 OPT="$OPT -b $BLOCK_SIZE" 113fi 114if [ -n "$COMPRESS_THRESHOLD" ]; then 115 OPT="$OPT -t $COMPRESS_THRESHOLD" 116fi 117if [ "$DISABLE_4K_ALIGN" = true ]; then 118 OPT="$OPT -disable-4k-align" 119fi 120 121MAKE_SQUASHFS_CMD="mksquashfs $SRC_DIR/ $OUTPUT_FILE -no-progress -comp $COMPRESSOR $COMPRESSOR_OPT -no-exports -noappend -no-recovery -no-fragments -no-duplicates -android-fs-config $OPT" 122echo $MAKE_SQUASHFS_CMD 123$MAKE_SQUASHFS_CMD 124 125if [ $? -ne 0 ]; then 126 exit 4 127fi 128 129SPARSE_SUFFIX=".sparse" 130if [ "$SPARSE" = true ]; then 131 img2simg $OUTPUT_FILE $OUTPUT_FILE$SPARSE_SUFFIX 132 if [ $? -ne 0 ]; then 133 exit 4 134 fi 135 mv $OUTPUT_FILE$SPARSE_SUFFIX $OUTPUT_FILE 136fi 137 138