Skip to content

Commit

Permalink
Add option to rel2fw.sh to allow post-processing
Browse files Browse the repository at this point in the history
This would typically be invoked by `mix firmware` further up the
stack. It is at the right moment to allow operating on the squashfs
file system before it is packed up into the fw file.

The primary purpose is to allow signing the root filesystem for use
with dm-verity.
  • Loading branch information
lawik authored and fhunleth committed Jan 9, 2025
1 parent 7c7a399 commit 6b35817
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scripts/rel2fw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ usage() {
echo " -f <firmware output file> Default is $PROJECT_DIR.fw"
echo " -o <image output file> Default is $PROJECT_DIR.img"
echo " -p <file priorities> The ordering of files in the rootfs (may be specified more than once)"
echo " -s <script path> Post-processing script for rootfs (optional)"
echo
echo "Barring errors, the firmware file is always created. The raw image is only"
echo "created if specified."
Expand All @@ -48,7 +49,7 @@ sbin/init 32764
etc/erlinit.config 32763
END

while getopts "a:c:f:o:p:" opt; do
while getopts "a:c:f:o:p:s:" opt; do
case $opt in
a)
ROOTFS_OVERLAYS="$ROOTFS_OVERLAYS $OPTARG"
Expand All @@ -66,6 +67,9 @@ while getopts "a:c:f:o:p:" opt; do
# Append priorities to the master list
cat "$OPTARG" >> "$SQUASHFS_PRIORITIES"
;;
s)
POST_PROCESSING_SCRIPT="$OPTARG"
;;
\?)
echo "$SCRIPT_NAME: ERROR: Invalid option: -$OPTARG"
usage
Expand Down Expand Up @@ -157,6 +161,12 @@ fi
# Merge the Erlang/OTP release onto the base image
"$NERVES_SYSTEM/scripts/merge-squashfs" "$NERVES_SDK_IMAGES/rootfs.squashfs" "$TMP_DIR/combined.squashfs" "$TMP_DIR/rootfs_overlay" "$SQUASHFS_PRIORITIES"

# If a post processing script for the final rootfs was specified, run it
if [ ! -z "${POST_PROCESSING_SCRIPT}" ]; then
echo "Running post-processing script: ${POST_PROCESSING_SCRIPT}"
${POST_PROCESSING_SCRIPT} "$TMP_DIR/combined.squashfs";
fi

# Build the firmware image
echo "Building $FW_FILENAME..."
ROOTFS="$TMP_DIR/combined.squashfs" $FWUP -c -f "$FWUP_CONFIG" \
Expand Down

0 comments on commit 6b35817

Please sign in to comment.