Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # To call this script, make sure mksquashfs is somewhere in PATH |
| 4 | |
| 5 | function usage() { |
| 6 | cat<<EOT |
| 7 | Usage: |
Mohan Srinivasan | eb71705 | 2016-07-26 15:10:29 -0700 | [diff] [blame] | 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] [-w WHITELIST_FILE] [-a] |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 9 | EOT |
| 10 | } |
| 11 | |
| 12 | echo "in mksquashfsimage.sh PATH=$PATH" |
| 13 | |
| 14 | if [ $# -lt 2 ]; then |
| 15 | usage |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | SRC_DIR=$1 |
| 20 | if [ ! -d $SRC_DIR ]; then |
| 21 | echo "Can not find directory $SRC_DIR!" |
| 22 | exit 2 |
| 23 | fi |
| 24 | OUTPUT_FILE=$2 |
| 25 | shift; shift |
| 26 | |
Mohamad Ayyash | df1dea3 | 2015-06-24 10:36:40 -0700 | [diff] [blame] | 27 | SPARSE=false |
| 28 | if [[ "$1" == "-s" ]]; then |
| 29 | SPARSE=true |
| 30 | shift; |
| 31 | fi |
| 32 | |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 33 | MOUNT_POINT= |
| 34 | if [[ "$1" == "-m" ]]; then |
| 35 | MOUNT_POINT=$2 |
| 36 | shift; shift |
| 37 | fi |
| 38 | |
Thierry Strudel | b89e81d | 2015-07-09 16:31:39 -0700 | [diff] [blame] | 39 | PRODUCT_OUT= |
| 40 | if [[ "$1" == "-d" ]]; then |
| 41 | PRODUCT_OUT=$2 |
| 42 | shift; shift |
| 43 | fi |
| 44 | |
Mohamad Ayyash | aa8b355 | 2016-04-07 22:15:57 -0700 | [diff] [blame] | 45 | FS_CONFIG= |
| 46 | if [[ "$1" == "-C" ]]; then |
| 47 | FS_CONFIG=$2 |
| 48 | shift; shift |
| 49 | fi |
| 50 | |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 51 | FILE_CONTEXTS= |
| 52 | if [[ "$1" == "-c" ]]; then |
| 53 | FILE_CONTEXTS=$2 |
| 54 | shift; shift |
| 55 | fi |
| 56 | |
Mohamad Ayyash | f2053a3 | 2016-06-13 14:45:31 -0700 | [diff] [blame] | 57 | BLOCK_MAP_FILE= |
| 58 | if [[ "$1" == "-B" ]]; then |
| 59 | BLOCK_MAP_FILE=$2 |
| 60 | shift; shift |
| 61 | fi |
| 62 | |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 63 | BLOCK_SIZE=131072 |
| 64 | if [[ "$1" == "-b" ]]; then |
| 65 | BLOCK_SIZE=$2 |
| 66 | shift; shift |
| 67 | fi |
| 68 | |
Simon Wilson | b4cf7b3 | 2015-06-17 12:36:53 -0700 | [diff] [blame] | 69 | COMPRESSOR="lz4" |
| 70 | COMPRESSOR_OPT="-Xhc" |
| 71 | if [[ "$1" == "-z" ]]; then |
| 72 | COMPRESSOR=$2 |
| 73 | COMPRESSOR_OPT= |
| 74 | shift; shift |
| 75 | fi |
| 76 | |
| 77 | if [[ "$1" == "-zo" ]]; then |
| 78 | COMPRESSOR_OPT=$2 |
| 79 | shift; shift |
| 80 | fi |
| 81 | |
Mohamad Ayyash | 921ef8f | 2016-06-03 18:55:16 -0700 | [diff] [blame] | 82 | COMPRESS_THRESHOLD=0 |
| 83 | if [[ "$1" == "-t" ]]; then |
| 84 | COMPRESS_THRESHOLD=$2 |
| 85 | shift; shift |
| 86 | fi |
| 87 | |
Mohan Srinivasan | eb71705 | 2016-07-26 15:10:29 -0700 | [diff] [blame] | 88 | WHITELIST_FILE= |
| 89 | if [[ "$1" == "-w" ]]; then |
| 90 | WHITELIST_FILE=$2 |
| 91 | shift; shift |
| 92 | fi |
Mohamad Ayyash | 921ef8f | 2016-06-03 18:55:16 -0700 | [diff] [blame] | 93 | |
Mohamad Ayyash | 084df12 | 2016-06-15 15:53:55 -0700 | [diff] [blame] | 94 | DISABLE_4K_ALIGN=false |
| 95 | if [[ "$1" == "-a" ]]; then |
| 96 | DISABLE_4K_ALIGN=true |
| 97 | shift; |
| 98 | fi |
| 99 | |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 100 | OPT="" |
| 101 | if [ -n "$MOUNT_POINT" ]; then |
| 102 | OPT="$OPT -mount-point $MOUNT_POINT" |
| 103 | fi |
Thierry Strudel | b89e81d | 2015-07-09 16:31:39 -0700 | [diff] [blame] | 104 | if [ -n "$PRODUCT_OUT" ]; then |
| 105 | OPT="$OPT -product-out $PRODUCT_OUT" |
| 106 | fi |
Mohamad Ayyash | aa8b355 | 2016-04-07 22:15:57 -0700 | [diff] [blame] | 107 | if [ -n "$FS_CONFIG" ]; then |
| 108 | OPT="$OPT -fs-config-file $FS_CONFIG" |
| 109 | fi |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 110 | if [ -n "$FILE_CONTEXTS" ]; then |
| 111 | OPT="$OPT -context-file $FILE_CONTEXTS" |
| 112 | fi |
Mohamad Ayyash | f2053a3 | 2016-06-13 14:45:31 -0700 | [diff] [blame] | 113 | if [ -n "$BLOCK_MAP_FILE" ]; then |
| 114 | OPT="$OPT -block-map $BLOCK_MAP_FILE" |
| 115 | fi |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 116 | if [ -n "$BLOCK_SIZE" ]; then |
| 117 | OPT="$OPT -b $BLOCK_SIZE" |
| 118 | fi |
Mohamad Ayyash | 921ef8f | 2016-06-03 18:55:16 -0700 | [diff] [blame] | 119 | if [ -n "$COMPRESS_THRESHOLD" ]; then |
| 120 | OPT="$OPT -t $COMPRESS_THRESHOLD" |
| 121 | fi |
Mohamad Ayyash | 084df12 | 2016-06-15 15:53:55 -0700 | [diff] [blame] | 122 | if [ "$DISABLE_4K_ALIGN" = true ]; then |
| 123 | OPT="$OPT -disable-4k-align" |
| 124 | fi |
Mohan Srinivasan | eb71705 | 2016-07-26 15:10:29 -0700 | [diff] [blame] | 125 | if [ -n "$WHITELIST_FILE" ]; then |
| 126 | OPT="$OPT -whitelist $WHITELIST_FILE" |
| 127 | fi |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 128 | |
Mohamad Ayyash | 1908b38 | 2016-05-24 13:53:53 -0700 | [diff] [blame] | 129 | MAKE_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" |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 130 | echo $MAKE_SQUASHFS_CMD |
| 131 | $MAKE_SQUASHFS_CMD |
Mohamad Ayyash | df1dea3 | 2015-06-24 10:36:40 -0700 | [diff] [blame] | 132 | |
Mohamad Ayyash | c8f18c8 | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 133 | if [ $? -ne 0 ]; then |
| 134 | exit 4 |
| 135 | fi |
Mohamad Ayyash | df1dea3 | 2015-06-24 10:36:40 -0700 | [diff] [blame] | 136 | |
| 137 | SPARSE_SUFFIX=".sparse" |
| 138 | if [ "$SPARSE" = true ]; then |
| 139 | img2simg $OUTPUT_FILE $OUTPUT_FILE$SPARSE_SUFFIX |
| 140 | if [ $? -ne 0 ]; then |
| 141 | exit 4 |
| 142 | fi |
| 143 | mv $OUTPUT_FILE$SPARSE_SUFFIX $OUTPUT_FILE |
| 144 | fi |
| 145 | |