| #!/bin/bash |
| set -eo pipefail |
| |
| help=$'Generate PNOR UBI image from a PNOR SquashFS Tarball |
| |
| Generates a UBI, Unsorted Block Images, PNOR image from a PNOR SquashFS Tarball. |
| The PNOR SquashFS Tarball is generated from the generate-squashfs script. |
| |
| usage: generate-ubi [OPTION] <PNOR SquashFS Tarball>... |
| |
| Options: |
| -f, --file <file> Specify destination file. Defaults to |
| `pwd`/<PNOR Tarball FILE, removing .squashfs.tar>.ubi.mtd |
| (For example, "generate-ubi my.pnor.squashfs.tar" |
| would generate `pwd`/my.pnor.ubi.mtd output.) |
| -h, --help Display this help text and exit. |
| ' |
| |
| while [[ $# -gt 0 ]]; do |
| key="$1" |
| case $key in |
| -f|--file) |
| outfile="$2" |
| shift 2 |
| ;; |
| -h|--help) |
| echo "$help" |
| exit |
| ;; |
| *) |
| tarball="$1" |
| shift 1 |
| ;; |
| esac |
| done |
| |
| if [ ! -f "${tarball}" ]; then |
| echo "Please enter a PNOR SquashFS Tarball." |
| echo "To generate PNOR SquashFS Tarball see generate-squashfs" |
| echo "$help" |
| exit 1 |
| fi |
| |
| if [[ -z $outfile ]]; then |
| # Remove .squashfs.tar from end if present and add .ubi.mtd |
| outfile=`pwd`/${tarball%".squashfs.tar"}.ubi.mtd |
| else |
| if [[ $outfile != /* ]]; then |
| outfile=`pwd`/$outfile |
| fi |
| fi |
| |
| echo "Generating PNOR UBI image." |
| |
| squashfs_file_name="pnor.xz.squashfs" |
| |
| # Scratch directory for untarring and config file |
| scratch_dir=`mktemp -d` |
| |
| # Untar tarball |
| tar -xvf ${tarball} -C ${scratch_dir} ${squashfs_file_name} |
| |
| # All valid PNOR SquashFS Tarballs have a file named "pnor.xz.squashfs" |
| if [ ! -f "${scratch_dir}/${squashfs_file_name}" ]; then |
| echo "No \"${squashfs_file_name}\" file in the tarball!" |
| rm -r "${scratch_dir}" |
| exit 1 |
| fi |
| |
| rm -r "${scratch_dir}" |