blob: 6299073b0a40b9c9db225f11c4aa050136673e6b [file] [log] [blame]
Gunnar Mills6a3e4e42017-10-23 11:05:03 -05001#!/bin/bash
2set -eo pipefail
3
4help=$'Generate PNOR UBI image from a PNOR SquashFS Tarball
5
6Generates a UBI, Unsorted Block Images, PNOR image from a PNOR SquashFS Tarball.
7The PNOR SquashFS Tarball is generated from the generate-squashfs script.
8
9usage: generate-ubi [OPTION] <PNOR SquashFS Tarball>...
10
11Options:
12 -f, --file <file> Specify destination file. Defaults to
13 `pwd`/<PNOR Tarball FILE, removing .squashfs.tar>.ubi.mtd
14 (For example, "generate-ubi my.pnor.squashfs.tar"
15 would generate `pwd`/my.pnor.ubi.mtd output.)
16 -h, --help Display this help text and exit.
17'
18
19while [[ $# -gt 0 ]]; do
20 key="$1"
21 case $key in
22 -f|--file)
23 outfile="$2"
24 shift 2
25 ;;
26 -h|--help)
27 echo "$help"
28 exit
29 ;;
30 *)
31 tarball="$1"
32 shift 1
33 ;;
34 esac
35done
36
37if [ ! -f "${tarball}" ]; then
38 echo "Please enter a PNOR SquashFS Tarball."
39 echo "To generate PNOR SquashFS Tarball see generate-squashfs"
40 echo "$help"
41 exit 1
42fi
43
44if [[ -z $outfile ]]; then
45 # Remove .squashfs.tar from end if present and add .ubi.mtd
46 outfile=`pwd`/${tarball%".squashfs.tar"}.ubi.mtd
47else
48 if [[ $outfile != /* ]]; then
49 outfile=`pwd`/$outfile
50 fi
51fi
52
Gunnar Millsf8210842017-10-23 13:08:38 -050053echo "Generating PNOR UBI image."
54
55squashfs_file_name="pnor.xz.squashfs"
56
57# Scratch directory for untarring and config file
58scratch_dir=`mktemp -d`
59
60# Untar tarball
61tar -xvf ${tarball} -C ${scratch_dir} ${squashfs_file_name}
62
63# All valid PNOR SquashFS Tarballs have a file named "pnor.xz.squashfs"
64if [ ! -f "${scratch_dir}/${squashfs_file_name}" ]; then
65 echo "No \"${squashfs_file_name}\" file in the tarball!"
66 rm -r "${scratch_dir}"
67 exit 1
68fi
69
70rm -r "${scratch_dir}"