blob: 5f45a648be20f3114a611885c7c168d42caf5830 [file] [log] [blame]
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -08001#!/bin/bash
2#
3# To call this script, make sure mksquashfs is somewhere in PATH
4
5function usage() {
6cat<<EOT
7Usage:
Mohamad Ayyash084df122016-06-15 15:53:55 -07008${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] [-a ]
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -08009EOT
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
Mohamad Ayyashdf1dea32015-06-24 10:36:40 -070027SPARSE=false
28if [[ "$1" == "-s" ]]; then
29 SPARSE=true
30 shift;
31fi
32
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080033MOUNT_POINT=
34if [[ "$1" == "-m" ]]; then
35 MOUNT_POINT=$2
36 shift; shift
37fi
38
Thierry Strudelb89e81d2015-07-09 16:31:39 -070039PRODUCT_OUT=
40if [[ "$1" == "-d" ]]; then
41 PRODUCT_OUT=$2
42 shift; shift
43fi
44
Mohamad Ayyashaa8b3552016-04-07 22:15:57 -070045FS_CONFIG=
46if [[ "$1" == "-C" ]]; then
47 FS_CONFIG=$2
48 shift; shift
49fi
50
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080051FILE_CONTEXTS=
52if [[ "$1" == "-c" ]]; then
53 FILE_CONTEXTS=$2
54 shift; shift
55fi
56
Mohamad Ayyashf2053a32016-06-13 14:45:31 -070057BLOCK_MAP_FILE=
58if [[ "$1" == "-B" ]]; then
59 BLOCK_MAP_FILE=$2
60 shift; shift
61fi
62
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080063BLOCK_SIZE=131072
64if [[ "$1" == "-b" ]]; then
65 BLOCK_SIZE=$2
66 shift; shift
67fi
68
Simon Wilsonb4cf7b32015-06-17 12:36:53 -070069COMPRESSOR="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
Mohamad Ayyash084df122016-06-15 15:53:55 -070082DISABLE_4K_ALIGN=false
83if [[ "$1" == "-a" ]]; then
84 DISABLE_4K_ALIGN=true
85 shift;
86fi
87
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080088OPT=""
89if [ -n "$MOUNT_POINT" ]; then
90 OPT="$OPT -mount-point $MOUNT_POINT"
91fi
Thierry Strudelb89e81d2015-07-09 16:31:39 -070092if [ -n "$PRODUCT_OUT" ]; then
93 OPT="$OPT -product-out $PRODUCT_OUT"
94fi
Mohamad Ayyashaa8b3552016-04-07 22:15:57 -070095if [ -n "$FS_CONFIG" ]; then
96 OPT="$OPT -fs-config-file $FS_CONFIG"
97fi
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080098if [ -n "$FILE_CONTEXTS" ]; then
99 OPT="$OPT -context-file $FILE_CONTEXTS"
100fi
Mohamad Ayyashf2053a32016-06-13 14:45:31 -0700101if [ -n "$BLOCK_MAP_FILE" ]; then
102 OPT="$OPT -block-map $BLOCK_MAP_FILE"
103fi
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -0800104if [ -n "$BLOCK_SIZE" ]; then
105 OPT="$OPT -b $BLOCK_SIZE"
106fi
Mohamad Ayyash084df122016-06-15 15:53:55 -0700107if [ "$DISABLE_4K_ALIGN" = true ]; then
108 OPT="$OPT -disable-4k-align"
109fi
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -0800110
Mohamad Ayyash1908b382016-05-24 13:53:53 -0700111MAKE_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 Ayyashc8f18c82015-03-03 12:33:48 -0800112echo $MAKE_SQUASHFS_CMD
113$MAKE_SQUASHFS_CMD
Mohamad Ayyashdf1dea32015-06-24 10:36:40 -0700114
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -0800115if [ $? -ne 0 ]; then
116 exit 4
117fi
Mohamad Ayyashdf1dea32015-06-24 10:36:40 -0700118
119SPARSE_SUFFIX=".sparse"
120if [ "$SPARSE" = true ]; then
121 img2simg $OUTPUT_FILE $OUTPUT_FILE$SPARSE_SUFFIX
122 if [ $? -ne 0 ]; then
123 exit 4
124 fi
125 mv $OUTPUT_FILE$SPARSE_SUFFIX $OUTPUT_FILE
126fi
127