| Gunnar Mills | 6a3e4e4 | 2017-10-23 11:05:03 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | set -eo pipefail | 
|  | 3 |  | 
|  | 4 | help=$'Generate PNOR UBI image from a PNOR SquashFS Tarball | 
|  | 5 |  | 
|  | 6 | Generates a UBI, Unsorted Block Images, PNOR image from a PNOR SquashFS Tarball. | 
|  | 7 | The PNOR SquashFS Tarball is generated from the generate-squashfs script. | 
|  | 8 |  | 
|  | 9 | usage: generate-ubi [OPTION] <PNOR SquashFS Tarball>... | 
|  | 10 |  | 
|  | 11 | Options: | 
|  | 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 |  | 
|  | 19 | while [[ $# -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 | 
|  | 35 | done | 
|  | 36 |  | 
|  | 37 | if [ ! -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 | 
|  | 42 | fi | 
|  | 43 |  | 
|  | 44 | if [[ -z $outfile ]]; then | 
|  | 45 | # Remove .squashfs.tar from end if present and add .ubi.mtd | 
|  | 46 | outfile=`pwd`/${tarball%".squashfs.tar"}.ubi.mtd | 
|  | 47 | else | 
|  | 48 | if [[ $outfile != /* ]]; then | 
|  | 49 | outfile=`pwd`/$outfile | 
|  | 50 | fi | 
|  | 51 | fi | 
|  | 52 |  | 
| Gunnar Mills | f821084 | 2017-10-23 13:08:38 -0500 | [diff] [blame^] | 53 | echo "Generating PNOR UBI image." | 
|  | 54 |  | 
|  | 55 | squashfs_file_name="pnor.xz.squashfs" | 
|  | 56 |  | 
|  | 57 | # Scratch directory for untarring and config file | 
|  | 58 | scratch_dir=`mktemp -d` | 
|  | 59 |  | 
|  | 60 | # Untar tarball | 
|  | 61 | tar -xvf ${tarball} -C ${scratch_dir} ${squashfs_file_name} | 
|  | 62 |  | 
|  | 63 | # All valid PNOR SquashFS Tarballs have a file named "pnor.xz.squashfs" | 
|  | 64 | if [ ! -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 | 
|  | 68 | fi | 
|  | 69 |  | 
|  | 70 | rm -r "${scratch_dir}" |