Skip to content

Commit 96a175f

Browse files
committed
Sort files in the squashfs by load order
This adds support for specifying the order of files in the squashfs so that it matches the load order in the release scripts. This reduces boot time.
1 parent 161beb2 commit 96a175f

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

scripts/merge-squashfs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Merge an overlay directory into a squashfs
44
#
5-
# Usage: merge-squashfs input.squashfs output.squashfs overlay-dir
5+
# Usage: merge-squashfs input.squashfs output.squashfs overlay-dir squashfs-priorities
66
#
77

88
set -e
@@ -145,14 +145,15 @@ readlink_f () {
145145
fi
146146
}
147147

148-
if [[ $# -ne 3 ]]; then
149-
echo "Usage: merge-squashfs input.squashfs output.squashfs overlay-dir"
148+
if [[ $# -lt 4 ]]; then
149+
echo "Usage: merge-squashfs input.squashfs output.squashfs overlay-dir squashfs_priorities"
150150
exit 1
151151
fi
152152

153153
input_squashfs=$(readlink_f "$1")
154154
output_squashfs=$(readlink_f "$2")
155155
overlay_dir=$(readlink_f "$3")
156+
squashfs_priorities=$(readlink_f "$4")
156157

157158
if [[ ! -f $input_squashfs ]]; then
158159
echo "Can't open $input_squashfs"
@@ -174,7 +175,7 @@ awk '!x[$1]++' pseudofile.in > pseudofile
174175

175176
unsquashfs "$input_squashfs" >/dev/null 2>/dev/null
176177
cp -Rf "$overlay_dir/." "$workdir/squashfs-root"
177-
mksquashfs squashfs-root "$output_squashfs" -pf pseudofile -noappend -no-recovery -no-progress
178+
mksquashfs squashfs-root "$output_squashfs" -pf pseudofile -sort "$squashfs_priorities" -noappend -no-recovery -no-progress
178179

179180
# cleanup
180181
popd >/dev/null

scripts/rel2fw.sh

+18-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ usage() {
2626
echo " -c <fwup.conf> Default is $NERVES_SDK_IMAGES/fwup.conf"
2727
echo " -f <firmware output file> Default is $PROJECT_DIR.fw"
2828
echo " -o <image output file> Default is $PROJECT_DIR.img"
29+
echo " -p <file priorities> The ordering of files in the rootfs (may be specified more than once)"
2930
echo
3031
echo "Barring errors, the firmware file is always created. The raw image is only"
3132
echo "created if specified."
@@ -35,7 +36,18 @@ usage() {
3536
echo "$SCRIPT_NAME -f $PROJECT_DIR.fw -o $PROJECT_DIR.img _rel"
3637
}
3738

38-
while getopts ":a:c:f:o:" opt; do
39+
# Create a base priority file
40+
#
41+
# Seed it with erlinit being the highest priority since we know those
42+
# files are guaranteed to be in the filesystem and accessed first on
43+
# boot.
44+
SQUASHFS_PRIORITIES="$TMP_DIR/squashfs.priority"
45+
cat > "$SQUASHFS_PRIORITIES" <<END
46+
sbin/init 32764
47+
etc/erlinit.config 32763
48+
END
49+
50+
while getopts "a:c:f:o:p:" opt; do
3951
case $opt in
4052
a)
4153
ROOTFS_ADDITIONS="$ROOTFS_ADDITIONS $OPTARG"
@@ -49,6 +61,10 @@ while getopts ":a:c:f:o:" opt; do
4961
o)
5062
IMG_FILENAME="$OPTARG"
5163
;;
64+
p)
65+
# Append priorities to the master list
66+
cat "$OPTARG" >> "$SQUASHFS_PRIORITIES"
67+
;;
5268
\?)
5369
echo "$SCRIPT_NAME: ERROR: Invalid option: -$OPTARG"
5470
usage
@@ -138,7 +154,7 @@ if [[ "$ROOTFS_ADDITIONS" ]]; then
138154
fi
139155

140156
# Merge the Erlang/OTP release onto the base image
141-
"$NERVES_SYSTEM/scripts/merge-squashfs" "$NERVES_SDK_IMAGES/rootfs.squashfs" "$TMP_DIR/combined.squashfs" "$TMP_DIR/rootfs-additions"
157+
"$NERVES_SYSTEM/scripts/merge-squashfs" "$NERVES_SDK_IMAGES/rootfs.squashfs" "$TMP_DIR/combined.squashfs" "$TMP_DIR/rootfs-additions" "$SQUASHFS_PRIORITIES"
142158

143159
# Build the firmware image
144160
echo "Building $FW_FILENAME..."

0 commit comments

Comments
 (0)