blob: 200974d35c322601be32769fdda34e64a3c7fe01 [file] [log] [blame]
Gunnar Millse8221902017-02-03 15:59:06 -06001#!/bin/sh
2
3help=$'Generate SquashFS image Script
4
5Generates a SquashFS image from the PNOR image
6
7usage: generate-squashfs [OPTION]
8
9Options:
Gunnar Mills37751f92017-02-07 21:05:01 -060010 -f, --file <file> Specify destination file. Defaults to
11 `pwd`/pnor.xz.squashfs if unspecified.
Gunnar Millse8221902017-02-03 15:59:06 -060012 -h, --help Display this help text and exit.
13'
14
Gunnar Mills37751f92017-02-07 21:05:01 -060015outfile=`pwd`"/pnor.xz.squashfs"
16
Gunnar Millse8221902017-02-03 15:59:06 -060017while [[ $# -gt 0 ]]; do
18 key="$1"
19 case $key in
Gunnar Mills37751f92017-02-07 21:05:01 -060020 -f|--file)
21 outfile="$2"
22 shift 2
23 ;;
Gunnar Millse8221902017-02-03 15:59:06 -060024 -h|--help)
25 echo "$help"
26 exit
27 ;;
28 *)
29 echo "Unknown option $1. Display available options with -h or --help"
30 exit
31 ;;
32 esac
33done
Gunnar Mills18f7cdb2017-02-07 16:44:19 -060034
Gunnar Mills37751f92017-02-07 21:05:01 -060035scratch_dir=`mktemp -d` || exit 1
Gunnar Mills41aa0a72017-02-08 10:03:35 -060036partitions=($(pflash --info | grep ID | awk '{print $2}'))
Gunnar Mills37751f92017-02-07 21:05:01 -060037
Gunnar Mills18f7cdb2017-02-07 16:44:19 -060038for partition in "${partitions[@]}"; do
39 echo "Reading ${partition}..."
Gunnar Mills37751f92017-02-07 21:05:01 -060040 pflash_cmd="pflash --partition=${partition} --read=${scratch_dir}/${partition}"
Gunnar Mills18f7cdb2017-02-07 16:44:19 -060041 ${pflash_cmd} || exit 1
42done
Gunnar Mills37751f92017-02-07 21:05:01 -060043
44echo "Creating SquashFS image..."
45
46cd "${scratch_dir}"
47squashfs_cmd="mksquashfs ${partitions[*]} ${outfile}"
48${squashfs_cmd} || exit 1
49
50echo "SquashFS Image at ${outfile}"
51rm -r "${scratch_dir}"