blob: 3811378f2cd5704d9056fdf7f24bc48c426a6146 [file] [log] [blame]
#!/bin/bash
help=$'Generate SquashFS image Script
Generates a SquashFS image from the PNOR image
usage: generate-squashfs [OPTION]
Options:
-f, --file <file> Specify destination file. Defaults to
`pwd`/pnor.xz.squashfs if unspecified.
-h, --help Display this help text and exit.
'
outfile=`pwd`"/pnor.xz.squashfs"
declare -a partitions=()
tocfile="pnor.toc"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-f|--file)
outfile="$2"
shift 2
;;
-h|--help)
echo "$help"
exit
;;
*)
echo "Unknown option $1. Display available options with -h or --help"
exit
;;
esac
done
scratch_dir=`mktemp -d` || exit 1
echo "Parsing PNOR TOC..."
{
while read line; do
if [[ $line == "ID="* ]]; then
# This line looks like "ID=05 MVPD 000d9000..00169000 (actual=00090000)"
read -r -a fields <<< "$line"
# Need the partition ID, name, start location, and end location
echo "partition${fields[0]##*=}=${fields[1]},${fields[2]/../,}"
# Save the partition name
partitions+=(${fields[1]})
fi
done < <(pflash --info)
} > ${scratch_dir}/${tocfile}
for partition in "${partitions[@]}"; do
echo "Reading ${partition}..."
pflash_cmd="pflash --partition=${partition} --read=${scratch_dir}/${partition}"
${pflash_cmd} || exit 1
done
echo "Creating SquashFS image..."
cd "${scratch_dir}"
squashfs_cmd="mksquashfs ${tocfile} ${partitions[*]} ${outfile}"
${squashfs_cmd} || exit 1
echo "SquashFS Image at ${outfile}"
rm -r "${scratch_dir}"