blob: e4c71ba4c400855b1e242b8196105f8861ebf78c [file] [log] [blame]
Gunnar Mills6b5b27e2017-03-01 21:37:01 -06001#!/bin/bash
Gunnar Millse8221902017-02-03 15:59:06 -06002
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"
Gunnar Mills6b5b27e2017-03-01 21:37:01 -060016declare -a partitions=()
17tocfile="pnor.toc"
Gunnar Mills37751f92017-02-07 21:05:01 -060018
Gunnar Millse8221902017-02-03 15:59:06 -060019while [[ $# -gt 0 ]]; do
20 key="$1"
21 case $key in
Gunnar Mills37751f92017-02-07 21:05:01 -060022 -f|--file)
23 outfile="$2"
24 shift 2
25 ;;
Gunnar Millse8221902017-02-03 15:59:06 -060026 -h|--help)
27 echo "$help"
28 exit
29 ;;
30 *)
31 echo "Unknown option $1. Display available options with -h or --help"
32 exit
33 ;;
34 esac
35done
Gunnar Mills18f7cdb2017-02-07 16:44:19 -060036
Gunnar Mills37751f92017-02-07 21:05:01 -060037scratch_dir=`mktemp -d` || exit 1
Gunnar Mills6b5b27e2017-03-01 21:37:01 -060038
39echo "Parsing PNOR TOC..."
40{
41 while read line; do
42 if [[ $line == "ID="* ]]; then
Gunnar Millse0ed3022017-03-02 16:16:19 -060043 # This line looks like
44 # "ID=05 MVPD 000d9000..00169000 (actual=00090000) [ECC]"
Gunnar Mills6b5b27e2017-03-01 21:37:01 -060045 read -r -a fields <<< "$line"
Gunnar Millse0ed3022017-03-02 16:16:19 -060046
47 # Get any flags attached to end (e.g. [ECC])
48 flags=""
49 for flag in "${fields[@]:4}"
50 do
51 flags+=",${flag//[\[\]]/}"
52 done
53
54 # Need the partition ID, name, start location, end location, and flags
55 echo "partition${fields[0]##*=}=${fields[1]},${fields[2]/../,}${flags}"
Gunnar Mills6b5b27e2017-03-01 21:37:01 -060056 # Save the partition name
57 partitions+=(${fields[1]})
58 fi
59 done < <(pflash --info)
60} > ${scratch_dir}/${tocfile}
Gunnar Mills37751f92017-02-07 21:05:01 -060061
Gunnar Mills18f7cdb2017-02-07 16:44:19 -060062for partition in "${partitions[@]}"; do
63 echo "Reading ${partition}..."
Gunnar Mills37751f92017-02-07 21:05:01 -060064 pflash_cmd="pflash --partition=${partition} --read=${scratch_dir}/${partition}"
Gunnar Mills18f7cdb2017-02-07 16:44:19 -060065 ${pflash_cmd} || exit 1
66done
Gunnar Mills37751f92017-02-07 21:05:01 -060067
68echo "Creating SquashFS image..."
69
70cd "${scratch_dir}"
Gunnar Mills6b5b27e2017-03-01 21:37:01 -060071squashfs_cmd="mksquashfs ${tocfile} ${partitions[*]} ${outfile}"
Gunnar Mills37751f92017-02-07 21:05:01 -060072${squashfs_cmd} || exit 1
73
74echo "SquashFS Image at ${outfile}"
75rm -r "${scratch_dir}"