blob: 3811378f2cd5704d9056fdf7f24bc48c426a6146 [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
43 # This line looks like "ID=05 MVPD 000d9000..00169000 (actual=00090000)"
44 read -r -a fields <<< "$line"
45 # Need the partition ID, name, start location, and end location
46 echo "partition${fields[0]##*=}=${fields[1]},${fields[2]/../,}"
47 # Save the partition name
48 partitions+=(${fields[1]})
49 fi
50 done < <(pflash --info)
51} > ${scratch_dir}/${tocfile}
Gunnar Mills37751f92017-02-07 21:05:01 -060052
Gunnar Mills18f7cdb2017-02-07 16:44:19 -060053for partition in "${partitions[@]}"; do
54 echo "Reading ${partition}..."
Gunnar Mills37751f92017-02-07 21:05:01 -060055 pflash_cmd="pflash --partition=${partition} --read=${scratch_dir}/${partition}"
Gunnar Mills18f7cdb2017-02-07 16:44:19 -060056 ${pflash_cmd} || exit 1
57done
Gunnar Mills37751f92017-02-07 21:05:01 -060058
59echo "Creating SquashFS image..."
60
61cd "${scratch_dir}"
Gunnar Mills6b5b27e2017-03-01 21:37:01 -060062squashfs_cmd="mksquashfs ${tocfile} ${partitions[*]} ${outfile}"
Gunnar Mills37751f92017-02-07 21:05:01 -060063${squashfs_cmd} || exit 1
64
65echo "SquashFS Image at ${outfile}"
66rm -r "${scratch_dir}"