beautysh: re-format

beautysh is enabled in the openbmc-build-scripts on Bash/Zsh/POSIX-sh
files to have a consistent formatting.  Re-run the formatter on the
whole repository.

Change-Id: I82c8272c4838e848615995a864dff3301d53925f
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/generate-tar b/generate-tar
index f23f513..8b36850 100755
--- a/generate-tar
+++ b/generate-tar
@@ -11,23 +11,23 @@
 usage: generate-tar [OPTION] <PNOR FILE>...
 
 Options:
-   -i, --image <squashfs|static>
-                          Generate SquashFS image or use static PNOR
-   -f, --file <file>      Specify destination file. Defaults to
-                          $(pwd)/<PNOR FILE>.pnor.<image_type>.tar[.gz] if
-                          unspecified.
-                          (For example,
-                          * "generate-tar -i squashfs my.pnor" would generate
-                          $(pwd)/my.pnor.squashfs.tar
-                          * "generate-tar -i static my.pnor" would generate
-                          $(pwd)/my.pnor.static.tar.gz)
-   -s, --sign <path>      Sign the image. The optional path argument specifies
-                          the private key file. Defaults to the bash variable
-                          PRIVATE_KEY_PATH if available, or else uses the
-                          open-source private key in this script.
-   -m, --machine <name>   Optionally specify the target machine name of this
-                          image.
-   -h, --help             Display this help text and exit.
+-i, --image <squashfs|static>
+Generate SquashFS image or use static PNOR
+-f, --file <file>      Specify destination file. Defaults to
+$(pwd)/<PNOR FILE>.pnor.<image_type>.tar[.gz] if
+unspecified.
+(For example,
+    * "generate-tar -i squashfs my.pnor" would generate
+    $(pwd)/my.pnor.squashfs.tar
+    * "generate-tar -i static my.pnor" would generate
+$(pwd)/my.pnor.static.tar.gz)
+-s, --sign <path>      Sign the image. The optional path argument specifies
+the private key file. Defaults to the bash variable
+PRIVATE_KEY_PATH if available, or else uses the
+open-source private key in this script.
+-m, --machine <name>   Optionally specify the target machine name of this
+image.
+-h, --help             Display this help text and exit.
 '
 
 private_key=$'-----BEGIN PRIVATE KEY-----
diff --git a/generate-ubi b/generate-ubi
index 7f7c144..a337782 100755
--- a/generate-ubi
+++ b/generate-ubi
@@ -9,13 +9,13 @@
 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.)
-   -s, --size <MiB>       Specify the size of the PNOR UBI image in MiBs.
-                          Defaults to 128.
-   -h, --help             Display this help text and exit.
+-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.)
+-s, --size <MiB>       Specify the size of the PNOR UBI image in MiBs.
+Defaults to 128.
+-h, --help             Display this help text and exit.
 '
 # 128MiB is the default image size
 image_size="128"
diff --git a/mmc/obmc-flash-bios b/mmc/obmc-flash-bios
index 988d9df..26bdc21 100644
--- a/mmc/obmc-flash-bios
+++ b/mmc/obmc-flash-bios
@@ -1,185 +1,185 @@
 #!/bin/sh
 
 bios_reset_if_needed() {
-  resetval=$(fw_printenv -n rwreset 2>/dev/nell)
-  if [ "$resetval" = "0" ] || [ "$resetval" = "1" ]; then
-    varstore="/media/hostfw/reset-gpio-val"
-    if [ -f "$varstore" ]; then
-      if [ "$resetval" != "$(cat $varstore)" ]; then
-        if busctl call org.open_power.Software.Host.Updater /xyz/openbmc_project/software xyz.openbmc_project.Common.FactoryReset Reset; then
-          echo "$resetval" > "$varstore"
+    resetval=$(fw_printenv -n rwreset 2>/dev/nell)
+    if [ "$resetval" = "0" ] || [ "$resetval" = "1" ]; then
+        varstore="/media/hostfw/reset-gpio-val"
+        if [ -f "$varstore" ]; then
+            if [ "$resetval" != "$(cat $varstore)" ]; then
+                if busctl call org.open_power.Software.Host.Updater /xyz/openbmc_project/software xyz.openbmc_project.Common.FactoryReset Reset; then
+                    echo "$resetval" > "$varstore"
+                fi
+            fi
+        else
+            echo "$resetval" > "$varstore"
         fi
-      fi
-    else
-      echo "$resetval" > "$varstore"
     fi
-  fi
 }
 
 mmc_init() {
-  base_dir="/media/hostfw"
-  ro_dir="${base_dir}/running-ro"
-  running_dir="${base_dir}/running"
-  prsv_dir="${base_dir}/prsv"
-  staging_dir="${base_dir}/staging"
-  nvram_dir="${base_dir}/nvram"
+    base_dir="/media/hostfw"
+    ro_dir="${base_dir}/running-ro"
+    running_dir="${base_dir}/running"
+    prsv_dir="${base_dir}/prsv"
+    staging_dir="${base_dir}/staging"
+    nvram_dir="${base_dir}/nvram"
 
-  if [ ! -d "${ro_dir}" ]; then
-    mkdir -p "${ro_dir}"
-  fi
-  if [ ! -d "${running_dir}" ]; then
-    mkdir -p ${running_dir}
-  fi
-  if [ ! -d "${prsv_dir}" ]; then
-    mkdir -p "${prsv_dir}"
-  fi
-  if [ ! -d "${staging_dir}" ]; then
-    mkdir -p "${staging_dir}"
-  fi
-  if [ ! -d "${nvram_dir}" ]; then
-    mkdir -p "${nvram_dir}"
-  fi
-
-  # Mount the image that corresponds to the boot label as read-only to be used
-  # to populate the running directory.
-  boot_label="$(fw_printenv -n bootside)"
-  if ! grep -q "${ro_dir}" /proc/mounts; then
-    mount ${base_dir}/hostfw-"${boot_label}" ${ro_dir} -o ro
-  fi
-
-  # Determine if the running dir contains the running version
-  running_label=""
-  running_label_file="${running_dir}/partlabel"
-  if [ -f "${running_label_file}" ]; then
-    running_label=$(cat ${running_label_file})
-  fi
-  if [ "${running_label}" != "${boot_label}" ]; then
-    # Copy off the preserved partitions
-    # A line in the pnor.toc (81e00994.lid) looks like this:
-    # partition05=SECBOOT,0x00381000,0x003a5000,00,ECC,PRESERVED
-    rm -f ${prsv_dir}/*
-    if [ -f "${ro_dir}/81e00994.lid" ]; then
-      prsvs=$(grep PRESERVED "${ro_dir}/81e00994.lid")
-      for prsv in ${prsvs}; do
-        prsv=${prsv##partition*=}
-        prsv=$(echo "${prsv}" | cut -d "," -f 1)
-        if [ -L "${running_dir}/${prsv}" ]; then
-          # Preserve the symlink target file
-          prsv="$(readlink "${running_dir}/${prsv}")"
-          if [ -f "${running_dir}/${prsv}" ] && [ -f "${ro_dir}/${prsv}" ]; then
-            runsize="$(stat -c '%s' "${running_dir}/${prsv}")"
-            rosize="$(stat -c '%s' "${ro_dir}/${prsv}")"
-            if [ "$runsize" != "$rosize" ]; then
-                # Partition size may have changed or became corrupted
-                # So it will not be copied to the preserved directory
-                # Log PEL to indicate such
-                busctl call xyz.openbmc_project.Logging \
-                /xyz/openbmc_project/logging \
-                xyz.openbmc_project.Logging.Create Create "ssa{ss}" \
-                xyz.openbmc_project.Software.Version.Error.HostFile \
-                xyz.openbmc_project.Logging.Entry.Level.Error 3 "FILE_NAME" \
-                "${prsv}" "CURRENT_FILE_SIZE" "${runsize}" "EXPECTED_FILE_SIZE" \
-                "${rosize}"
-                # Initiate dump
-                busctl call xyz.openbmc_project.Dump.Manager \
-                /xyz/openbmc_project/dump/bmc xyz.openbmc_project.Dump.Create \
-                CreateDump "a{sv}" 0
-            else
-                cp -p ${running_dir}/"${prsv}" ${prsv_dir}
-            fi
-          fi
-        fi
-      done
+    if [ ! -d "${ro_dir}" ]; then
+        mkdir -p "${ro_dir}"
+    fi
+    if [ ! -d "${running_dir}" ]; then
+        mkdir -p ${running_dir}
+    fi
+    if [ ! -d "${prsv_dir}" ]; then
+        mkdir -p "${prsv_dir}"
+    fi
+    if [ ! -d "${staging_dir}" ]; then
+        mkdir -p "${staging_dir}"
+    fi
+    if [ ! -d "${nvram_dir}" ]; then
+        mkdir -p "${nvram_dir}"
     fi
 
-    # Copy lid contents of running image to running dir
-    rm -f ${running_dir}/*
-    cp -p ${ro_dir}/*.lid ${running_dir}/
+    # Mount the image that corresponds to the boot label as read-only to be used
+    # to populate the running directory.
+    boot_label="$(fw_printenv -n bootside)"
+    if ! grep -q "${ro_dir}" /proc/mounts; then
+        mount ${base_dir}/hostfw-"${boot_label}" ${ro_dir} -o ro
+    fi
 
-    # Restore the preserved partitions. Ignore error, there may be none.
-    cp -p ${prsv_dir}/* ${running_dir}/ 2>/dev/null || true
-    rm -f "${prsv_dir:?}/"*
+    # Determine if the running dir contains the running version
+    running_label=""
+    running_label_file="${running_dir}/partlabel"
+    if [ -f "${running_label_file}" ]; then
+        running_label=$(cat ${running_label_file})
+    fi
+    if [ "${running_label}" != "${boot_label}" ]; then
+        # Copy off the preserved partitions
+        # A line in the pnor.toc (81e00994.lid) looks like this:
+        # partition05=SECBOOT,0x00381000,0x003a5000,00,ECC,PRESERVED
+        rm -f ${prsv_dir}/*
+        if [ -f "${ro_dir}/81e00994.lid" ]; then
+            prsvs=$(grep PRESERVED "${ro_dir}/81e00994.lid")
+            for prsv in ${prsvs}; do
+                prsv=${prsv##partition*=}
+                prsv=$(echo "${prsv}" | cut -d "," -f 1)
+                if [ -L "${running_dir}/${prsv}" ]; then
+                    # Preserve the symlink target file
+                    prsv="$(readlink "${running_dir}/${prsv}")"
+                    if [ -f "${running_dir}/${prsv}" ] && [ -f "${ro_dir}/${prsv}" ]; then
+                        runsize="$(stat -c '%s' "${running_dir}/${prsv}")"
+                        rosize="$(stat -c '%s' "${ro_dir}/${prsv}")"
+                        if [ "$runsize" != "$rosize" ]; then
+                            # Partition size may have changed or became corrupted
+                            # So it will not be copied to the preserved directory
+                            # Log PEL to indicate such
+                            busctl call xyz.openbmc_project.Logging \
+                                /xyz/openbmc_project/logging \
+                                xyz.openbmc_project.Logging.Create Create "ssa{ss}" \
+                                xyz.openbmc_project.Software.Version.Error.HostFile \
+                                xyz.openbmc_project.Logging.Entry.Level.Error 3 "FILE_NAME" \
+                                "${prsv}" "CURRENT_FILE_SIZE" "${runsize}" "EXPECTED_FILE_SIZE" \
+                                "${rosize}"
+                            # Initiate dump
+                            busctl call xyz.openbmc_project.Dump.Manager \
+                                /xyz/openbmc_project/dump/bmc xyz.openbmc_project.Dump.Create \
+                                CreateDump "a{sv}" 0
+                        else
+                            cp -p ${running_dir}/"${prsv}" ${prsv_dir}
+                        fi
+                    fi
+                fi
+            done
+        fi
 
-    # Clean up the staging dir in case of a failed update
-    rm -rf "${staging_dir:?}/"*
+        # Copy lid contents of running image to running dir
+        rm -f ${running_dir}/*
+        cp -p ${ro_dir}/*.lid ${running_dir}/
 
-    # Save the label
-    echo "${boot_label}" > "${running_label_file}"
+        # Restore the preserved partitions. Ignore error, there may be none.
+        cp -p ${prsv_dir}/* ${running_dir}/ 2>/dev/null || true
+        rm -f "${prsv_dir:?}/"*
 
-  fi
+        # Clean up the staging dir in case of a failed update
+        rm -rf "${staging_dir:?}/"*
 
-  # Mount alternate dir
-  if [ "${boot_label}" = "a" ]; then
-    alternate_label="b"
-  else
-    alternate_label="a"
-  fi
-  alternate_dir="${base_dir}/alternate"
-  if [ ! -d "${alternate_dir}" ]; then
-    mkdir -p ${alternate_dir}
-  fi
-  if ! grep -q "${alternate_dir}" /proc/mounts; then
-    mount ${base_dir}/hostfw-${alternate_label} ${alternate_dir} -o ro
-  fi
+        # Save the label
+        echo "${boot_label}" > "${running_label_file}"
+
+    fi
+
+    # Mount alternate dir
+    if [ "${boot_label}" = "a" ]; then
+        alternate_label="b"
+    else
+        alternate_label="a"
+    fi
+    alternate_dir="${base_dir}/alternate"
+    if [ ! -d "${alternate_dir}" ]; then
+        mkdir -p ${alternate_dir}
+    fi
+    if ! grep -q "${alternate_dir}" /proc/mounts; then
+        mount ${base_dir}/hostfw-${alternate_label} ${alternate_dir} -o ro
+    fi
 }
 
 mmc_patch() {
-  # Patching is disabled if field mode is set
-  if [ "$(fw_printenv fieldmode 2>/dev/null)" = "fieldmode=true" ]; then
-    return 0
-  fi
+    # Patching is disabled if field mode is set
+    if [ "$(fw_printenv fieldmode 2>/dev/null)" = "fieldmode=true" ]; then
+        return 0
+    fi
 
-  boot_label="$(fw_printenv -n bootside)"
-  if [ "${boot_label}" = "a" ]; then
-    alternate_label="b"
-  else
-    alternate_label="a"
-  fi
+    boot_label="$(fw_printenv -n bootside)"
+    if [ "${boot_label}" = "a" ]; then
+        alternate_label="b"
+    else
+        alternate_label="a"
+    fi
 
-  # Create patch directories
-  patch_dir="/media/hostfw/patch-"
-  running_patch_dir="${patch_dir}${boot_label}"
-  if [ ! -d "${running_patch_dir}" ]; then
-    mkdir -p "${running_patch_dir}"
-  fi
-  alternate_patch_dir="${patch_dir}${alternate_label}"
-  if [ ! -d "${alternate_patch_dir}" ]; then
-    mkdir -p "${alternate_patch_dir}"
-  fi
+    # Create patch directories
+    patch_dir="/media/hostfw/patch-"
+    running_patch_dir="${patch_dir}${boot_label}"
+    if [ ! -d "${running_patch_dir}" ]; then
+        mkdir -p "${running_patch_dir}"
+    fi
+    alternate_patch_dir="${patch_dir}${alternate_label}"
+    if [ ! -d "${alternate_patch_dir}" ]; then
+        mkdir -p "${alternate_patch_dir}"
+    fi
 
-  # Create patch symlinks
-  symlink_base="/usr/local/share"
-  if [ ! -d "${symlink_base}" ]; then
-    mkdir -p "${symlink_base}"
-  fi
-  hostfw_symlink_base="${symlink_base}/hostfw"
-  if [ ! -d "${hostfw_symlink_base}" ]; then
-    mkdir -p "${hostfw_symlink_base}"
-  fi
+    # Create patch symlinks
+    symlink_base="/usr/local/share"
+    if [ ! -d "${symlink_base}" ]; then
+        mkdir -p "${symlink_base}"
+    fi
+    hostfw_symlink_base="${symlink_base}/hostfw"
+    if [ ! -d "${hostfw_symlink_base}" ]; then
+        mkdir -p "${hostfw_symlink_base}"
+    fi
 
-  if [ "$(readlink -f "${symlink_base}/pnor")" != "${running_patch_dir}" ]; then
-    ln -s "${running_patch_dir}" "${symlink_base}/pnor"
-  fi
-  if [ "$(readlink -f "${hostfw_symlink_base}/running")" != "${running_patch_dir}" ]; then
-    ln -s "${running_patch_dir}" "${hostfw_symlink_base}/running"
-  fi
-  if [ "$(readlink -f "${hostfw_symlink_base}/alternate")" != "${alternate_patch_dir}" ]; then
-    ln -s "${alternate_patch_dir}" "${hostfw_symlink_base}/alternate"
-  fi
+    if [ "$(readlink -f "${symlink_base}/pnor")" != "${running_patch_dir}" ]; then
+        ln -s "${running_patch_dir}" "${symlink_base}/pnor"
+    fi
+    if [ "$(readlink -f "${hostfw_symlink_base}/running")" != "${running_patch_dir}" ]; then
+        ln -s "${running_patch_dir}" "${hostfw_symlink_base}/running"
+    fi
+    if [ "$(readlink -f "${hostfw_symlink_base}/alternate")" != "${alternate_patch_dir}" ]; then
+        ln -s "${alternate_patch_dir}" "${hostfw_symlink_base}/alternate"
+    fi
 }
 
 case "$1" in
-  bios-reset-if-needed)
-    bios_reset_if_needed
-    ;;
-  mmc-init)
-    mmc_init
-    ;;
-  mmc-patch)
-    mmc_patch
-    ;;
-  *)
-    echo "Invalid argument: $1" >&2
-    exit 1
-    ;;
+    bios-reset-if-needed)
+        bios_reset_if_needed
+        ;;
+    mmc-init)
+        mmc_init
+        ;;
+    mmc-patch)
+        mmc_patch
+        ;;
+    *)
+        echo "Invalid argument: $1" >&2
+        exit 1
+        ;;
 esac
diff --git a/ubi/obmc-flash-bios b/ubi/obmc-flash-bios
index d89c71b..47252c8 100644
--- a/ubi/obmc-flash-bios
+++ b/ubi/obmc-flash-bios
@@ -1,256 +1,256 @@
 #!/bin/bash
 
 # Get the mtd device number (mtdX)
-findmtd() {
-  m="$(grep -xl "$1" /sys/class/mtd/*/name)"
-  m="${m%/name}"
-  m="${m##*/}"
-  echo "${m}"
+function findmtd() {
+    m="$(grep -xl "$1" /sys/class/mtd/*/name)"
+    m="${m%/name}"
+    m="${m##*/}"
+    echo "${m}"
 }
 
 # Get the ubi device number (ubiX_Y)
-findubi() {
-  u="$(grep -xl "$1" /sys/class/ubi/ubi?/subsystem/ubi*/name)"
-  u="${u%/name}"
-  u="${u##*/}"
-  echo "${u}"
+function findubi() {
+    u="$(grep -xl "$1" /sys/class/ubi/ubi?/subsystem/ubi*/name)"
+    u="${u%/name}"
+    u="${u##*/}"
+    echo "${u}"
 }
 
 # Get the mount information
-is_mounted() {
-  grep -q "$1" /proc/mounts
-  return $?
+function is_mounted() {
+    grep -q "$1" /proc/mounts
+    return $?
 }
 
 # Attach the pnor mtd device to ubi.
-attach_ubi() {
-  pnormtd="$(findmtd pnor)"
-  pnor="${pnormtd#mtd}"
-  pnordev="/dev/mtd${pnor}"
+function attach_ubi() {
+    pnormtd="$(findmtd pnor)"
+    pnor="${pnormtd#mtd}"
+    pnordev="/dev/mtd${pnor}"
 
-  if [ -d "/sys/class/ubi/ubi${pnor}" ]; then
-    # Already attached
-    return 0
-  fi
-
-  ubiattach /dev/ubi_ctrl -m "${pnor}" -d "${pnor}"
-  rc=$?
-  if [ ${rc} -ne 0 ]; then
-    # Check the pnor mtd device is formatted as ubi by reading the first 3 byes,
-    # which should be the ascii chars 'UBI'
-    magic="$(hexdump -C -n 3 "${pnordev}")"
-    if [[ "${magic}" =~ "UBI" ]]; then
-      # Device already formatted as ubi, ubiattach failed for some other reason
-      return ${rc}
-    else
-      # Format device as ubi
-      echo "Starting ubiformat ${pnordev}"
-      ubiformat "${pnordev}" -y -q
-      # Retry the ubiattach
-      ubiattach /dev/ubi_ctrl -m "${pnor}" -d "${pnor}"
+    if [ -d "/sys/class/ubi/ubi${pnor}" ]; then
+        # Already attached
+        return 0
     fi
-  fi
-}
 
-mount_squashfs() {
-  pnormtd="$(findmtd pnor)"
-  ubidev="/dev/ubi${pnormtd#mtd}"
-  mountdir="/media/${name}"
-  vol="$(findubi "${name}")"
-  img="/tmp/images/${version}/pnor.xz.squashfs"
-  # shellcheck disable=SC2012 # ls provides the size in human-readable form
-  filesize="$(ls -sh "$img" | awk -F " " '{print $1}')"
-
-  if is_mounted "${name}"; then
-    echo "${name} is already mounted."
-    return 0
-  fi
-
-  if [ -n "${vol}" ]; then
-    ubirmvol "${ubidev}" -N "${name}"
-  fi
-
-  if [ ! -d "${mountdir}" ]; then
-    mkdir "${mountdir}"
-  fi
-
-  # Set size of read-only partition equal to pnor.xz.squashfs
-  ubimkvol "${ubidev}" -N "${name}" -s "${filesize}"KiB --type=static
-  if ! vol="$(findubi "${name}")"; then
-    echo "Unable to create RO volume!"
-    return 1
-  fi
-
-  ubidevid="${vol#ubi}"
-  if ! ubiupdatevol "/dev/ubi${ubidevid}" "${img}"; then
-    echo "Unable to update RO volume!"
-    return 1
-  fi
-
-  if ! ubiblock --create "/dev/ubi${ubidevid}"; then
-    echo "Unable to create UBI block for RO volume!"
-    return 1
-  fi
-
-  if ! mount -t squashfs -o ro "/dev/ubiblock${ubidevid}" "${mountdir}"; then
-    echo "Unable to mount RO volume!"
-    return 1
-  fi
-}
-
-mount_ubi() {
-  pnormtd="$(findmtd pnor)"
-  pnor="${pnormtd#mtd}"
-  ubidev="/dev/ubi${pnor}"
-  pnordev="/dev/mtd${pnor}"
-
-  if [[ "${name}" == "pnor-patch" ]]; then
-    if [[ "$(fw_printenv fieldmode 2>/dev/null)" == "fieldmode=true" ]]; then
-      return 0
-    fi
-    if [[ ! "$(hexdump -C -n 3 "${pnordev}")" =~ "UBI" ]]; then
-      return 0
-    fi
-    mountdir="/usr/local/share/pnor"
-  else
-    mountdir="/media/${name}"
-  fi
-
-  if [[ "${name}" == "pnor-prsv" ]]; then
-    size="2MiB"
-  else
-    size="16MiB"
-  fi
-
-  if [ ! -d "${mountdir}" ]; then
-    mkdir -p "${mountdir}"
-  fi
-
-  vol="$(findubi "${name}")"
-  if [ -z "${vol}" ]; then
-    ubimkvol "${ubidev}" -N "${name}" -s "${size}"
-  fi
-
-  if ! is_mounted "${name}"; then
-    mountdev="ubi${pnor}:${name}"
-    mount -t ubifs "${mountdev}" "${mountdir}"
-  fi
-}
-
-umount_ubi() {
-  pnormtd="$(findmtd pnor)"
-  pnor="${pnormtd#mtd}"
-  ubidev="/dev/ubi${pnor}"
-  mountdir="/media/${name}"
-
-  if is_mounted "${name}"; then
-    umount "${mountdir}"
-  fi
-
-  vol="$(findubi "${name}")"
-  id="${vol##*_}"
-  if [ -n "${id}" ]; then
-    ubirmvol "${ubidev}" -n "${id}"
-  fi
-
-  if [ -d "${mountdir}" ]; then
-    rm -r "${mountdir}"
-  fi
-}
-
-remount_ubi() {
-  pnormtd="$(findmtd pnor)"
-  pnor="${pnormtd#mtd}"
-  pnordev="/dev/mtd${pnor}"
-
-  # Re-Attach the pnor mtd device to ubi
-  if [[ $(hexdump -C -n 3 "${pnordev}") =~ "UBI" ]]; then
     ubiattach /dev/ubi_ctrl -m "${pnor}" -d "${pnor}"
-  else
-    # Device not formatted as ubi.
-    return 0
-  fi
-
-  # Get information on all ubi volumes
-  ubinfo=$(ubinfo -d "${pnor}")
-  presentVolumes=${ubinfo##*:}
-  IFS=', ' read -r -a array <<< "$presentVolumes"
-  for element in "${array[@]}";
-  do
-    elementProperties=$(ubinfo -d "$pnor" -n "$element")
-    # Get ubi volume name by getting rid of additional properties
-    name=${elementProperties#*Name:}
-    name="${name%Character*}"
-    name="$(echo -e "${name}" | tr -d '[:space:]')"
-
-    if [[ ${name} == pnor-prsv ]] || [[ ${name} == pnor-rw* ]] || [[ ${name} == pnor-ro* ]]; then
-      mountdir="/media/${name}"
-      if [ ! -d "${mountdir}" ]; then
-        mkdir -p "${mountdir}"
-      fi
-
-      if [[ ${name} == pnor-ro* ]]
-      then
-        ubiblock --create "/dev/ubi${pnor}_${element}"
-        mount -t squashfs -o ro "/dev/ubiblock${pnor}_${element}" "${mountdir}"
-      else
-        mount -t ubifs "ubi${pnor}:${name}" "${mountdir}"
-      fi
+    rc=$?
+    if [ ${rc} -ne 0 ]; then
+        # Check the pnor mtd device is formatted as ubi by reading the first 3 byes,
+        # which should be the ascii chars 'UBI'
+        magic="$(hexdump -C -n 3 "${pnordev}")"
+        if [[ "${magic}" =~ "UBI" ]]; then
+            # Device already formatted as ubi, ubiattach failed for some other reason
+            return ${rc}
+        else
+            # Format device as ubi
+            echo "Starting ubiformat ${pnordev}"
+            ubiformat "${pnordev}" -y -q
+            # Retry the ubiattach
+            ubiattach /dev/ubi_ctrl -m "${pnor}" -d "${pnor}"
+        fi
     fi
-  done
 }
 
-ubi_cleanup() {
+function mount_squashfs() {
+    pnormtd="$(findmtd pnor)"
+    ubidev="/dev/ubi${pnormtd#mtd}"
+    mountdir="/media/${name}"
+    vol="$(findubi "${name}")"
+    img="/tmp/images/${version}/pnor.xz.squashfs"
+    # shellcheck disable=SC2012 # ls provides the size in human-readable form
+    filesize="$(ls -sh "$img" | awk -F " " '{print $1}')"
+
+    if is_mounted "${name}"; then
+        echo "${name} is already mounted."
+        return 0
+    fi
+
+    if [ -n "${vol}" ]; then
+        ubirmvol "${ubidev}" -N "${name}"
+    fi
+
+    if [ ! -d "${mountdir}" ]; then
+        mkdir "${mountdir}"
+    fi
+
+    # Set size of read-only partition equal to pnor.xz.squashfs
+    ubimkvol "${ubidev}" -N "${name}" -s "${filesize}"KiB --type=static
+    if ! vol="$(findubi "${name}")"; then
+        echo "Unable to create RO volume!"
+        return 1
+    fi
+
+    ubidevid="${vol#ubi}"
+    if ! ubiupdatevol "/dev/ubi${ubidevid}" "${img}"; then
+        echo "Unable to update RO volume!"
+        return 1
+    fi
+
+    if ! ubiblock --create "/dev/ubi${ubidevid}"; then
+        echo "Unable to create UBI block for RO volume!"
+        return 1
+    fi
+
+    if ! mount -t squashfs -o ro "/dev/ubiblock${ubidevid}" "${mountdir}"; then
+        echo "Unable to mount RO volume!"
+        return 1
+    fi
+}
+
+function mount_ubi() {
+    pnormtd="$(findmtd pnor)"
+    pnor="${pnormtd#mtd}"
+    ubidev="/dev/ubi${pnor}"
+    pnordev="/dev/mtd${pnor}"
+
+    if [[ "${name}" == "pnor-patch" ]]; then
+        if [[ "$(fw_printenv fieldmode 2>/dev/null)" == "fieldmode=true" ]]; then
+            return 0
+        fi
+        if [[ ! "$(hexdump -C -n 3 "${pnordev}")" =~ "UBI" ]]; then
+            return 0
+        fi
+        mountdir="/usr/local/share/pnor"
+    else
+        mountdir="/media/${name}"
+    fi
+
+    if [[ "${name}" == "pnor-prsv" ]]; then
+        size="2MiB"
+    else
+        size="16MiB"
+    fi
+
+    if [ ! -d "${mountdir}" ]; then
+        mkdir -p "${mountdir}"
+    fi
+
+    vol="$(findubi "${name}")"
+    if [ -z "${vol}" ]; then
+        ubimkvol "${ubidev}" -N "${name}" -s "${size}"
+    fi
+
+    if ! is_mounted "${name}"; then
+        mountdev="ubi${pnor}:${name}"
+        mount -t ubifs "${mountdev}" "${mountdir}"
+    fi
+}
+
+function umount_ubi() {
+    pnormtd="$(findmtd pnor)"
+    pnor="${pnormtd#mtd}"
+    ubidev="/dev/ubi${pnor}"
+    mountdir="/media/${name}"
+
+    if is_mounted "${name}"; then
+        umount "${mountdir}"
+    fi
+
+    vol="$(findubi "${name}")"
+    id="${vol##*_}"
+    if [ -n "${id}" ]; then
+        ubirmvol "${ubidev}" -n "${id}"
+    fi
+
+    if [ -d "${mountdir}" ]; then
+        rm -r "${mountdir}"
+    fi
+}
+
+function remount_ubi() {
+    pnormtd="$(findmtd pnor)"
+    pnor="${pnormtd#mtd}"
+    pnordev="/dev/mtd${pnor}"
+
+    # Re-Attach the pnor mtd device to ubi
+    if [[ $(hexdump -C -n 3 "${pnordev}") =~ "UBI" ]]; then
+        ubiattach /dev/ubi_ctrl -m "${pnor}" -d "${pnor}"
+    else
+        # Device not formatted as ubi.
+        return 0
+    fi
+
+    # Get information on all ubi volumes
+    ubinfo=$(ubinfo -d "${pnor}")
+    presentVolumes=${ubinfo##*:}
+    IFS=', ' read -r -a array <<< "$presentVolumes"
+    for element in "${array[@]}";
+    do
+        elementProperties=$(ubinfo -d "$pnor" -n "$element")
+        # Get ubi volume name by getting rid of additional properties
+        name=${elementProperties#*Name:}
+        name="${name%Character*}"
+        name="$(echo -e "${name}" | tr -d '[:space:]')"
+
+        if [[ ${name} == pnor-prsv ]] || [[ ${name} == pnor-rw* ]] || [[ ${name} == pnor-ro* ]]; then
+            mountdir="/media/${name}"
+            if [ ! -d "${mountdir}" ]; then
+                mkdir -p "${mountdir}"
+            fi
+
+            if [[ ${name} == pnor-ro* ]]
+            then
+                ubiblock --create "/dev/ubi${pnor}_${element}"
+                mount -t squashfs -o ro "/dev/ubiblock${pnor}_${element}" "${mountdir}"
+            else
+                mount -t ubifs "ubi${pnor}:${name}" "${mountdir}"
+            fi
+        fi
+    done
+}
+
+function ubi_cleanup() {
     # When ubi_cleanup is run, it expects one or no active version.
     activeVersion=$(busctl --list --no-pager tree \
             org.open_power.Software.Host.Updater | \
-            grep /xyz/openbmc_project/software/ | tail -c 9)
+        grep /xyz/openbmc_project/software/ | tail -c 9)
 
     if [[ -z "$activeVersion" ]]; then
         vols=$(ubinfo -a | grep -e "pnor-ro-" -e "pnor-rw-" | cut -c 14-)
         mapfile -t array <<< "${vols}"
     else
         vols=$(ubinfo -a | grep -e "pnor-ro-" -e "pnor-rw-" | \
-                grep -v "$activeVersion" | cut -c 14-)
+            grep -v "$activeVersion" | cut -c 14-)
         mapfile -t array <<< "${vols}"
     fi
 
     for (( index=0; index<${#array[@]}; index++ )); do
-         name=${array[index]}
-         umount_ubi
+        name=${array[index]}
+        umount_ubi
     done
 }
 
 case "$1" in
-  ubiattach)
-    attach_ubi
-    ;;
-  squashfsmount)
-    name="$2"
-    version="$3"
-    mount_squashfs
-    ;;
-  ubimount)
-    name="$2"
-    mount_ubi
-    ;;
-  ubiumount)
-    name="$2"
-    umount_ubi
-    ;;
-  ubiremount)
-    remount_ubi
-    ;;
-  ubicleanup)
-    ubi_cleanup
-    ;;
-  *)
-    echo "Invalid argument"
-    exit 1
-    ;;
+    ubiattach)
+        attach_ubi
+        ;;
+    squashfsmount)
+        name="$2"
+        version="$3"
+        mount_squashfs
+        ;;
+    ubimount)
+        name="$2"
+        mount_ubi
+        ;;
+    ubiumount)
+        name="$2"
+        umount_ubi
+        ;;
+    ubiremount)
+        remount_ubi
+        ;;
+    ubicleanup)
+        ubi_cleanup
+        ;;
+    *)
+        echo "Invalid argument"
+        exit 1
+        ;;
 esac
 rc=$?
 if [ ${rc} -ne 0 ]; then
-  echo "$0: error ${rc}"
-  exit ${rc}
+    echo "$0: error ${rc}"
+    exit ${rc}
 fi
diff --git a/vpnor/obmc-vpnor-util b/vpnor/obmc-vpnor-util
index 54ba590..7c4500e 100644
--- a/vpnor/obmc-vpnor-util
+++ b/vpnor/obmc-vpnor-util
@@ -1,160 +1,160 @@
 #!/bin/bash
 
-clear_volatile() {
-  service=$(mapper get-service /org/open_power/control/volatile)
-  clearVolatileEnabled=$(busctl get-property "$service" /org/open_power/control/volatile xyz.openbmc_project.Object.Enable Enabled)
-  if [[ "$clearVolatileEnabled" != "b true" ]]; then
-    return 0
-  fi
-
-  PNOR_TOC_FILE="pnor.toc"
-  PNOR_RO_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/ro/"
-  PNOR_RW_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/rw/"
-  PNOR_PRSV_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/prsv/"
-
-  # toc partition string format:
-  # partition27=HB_VOLATILE,0x02ba9000,0x02bae000,00,ECC,VOLATILE,READWRITE
-  tocFilePath="${PNOR_RO_ACTIVE_PATH}${PNOR_TOC_FILE}"
-  if [ ! -f "${tocFilePath}" ]; then
-    tocFilePath="${PNOR_RW_ACTIVE_PATH}${PNOR_TOC_FILE}"
-  fi
-  mapfile -t volatiles < <(grep VOLATILE "${tocFilePath}" | grep -Eo '^partition([0-9]+)=([A-Za-z0-9_]+)')
-  for (( index=0; index<${#volatiles[@]}; index++ )); do
-    volatileName="$(echo "${volatiles[${index}]}" | awk -F '=' '{print $2}')"
-
-    rwVolatile="${PNOR_RW_ACTIVE_PATH}${volatileName}"
-    if [ -f "${rwVolatile}" ]; then
-      echo "Clear $rwVolatile"
-      rm "${rwVolatile}"
-    fi
-    prsvVolatile="${PNOR_PRSV_ACTIVE_PATH}${volatileName}"
-    if [ -f "${prsvVolatile}" ]; then
-      echo "Clear $prsvVolatile"
-      rm "${prsvVolatile}"
+function clear_volatile() {
+    service=$(mapper get-service /org/open_power/control/volatile)
+    clearVolatileEnabled=$(busctl get-property "$service" /org/open_power/control/volatile xyz.openbmc_project.Object.Enable Enabled)
+    if [[ "$clearVolatileEnabled" != "b true" ]]; then
+        return 0
     fi
 
-    if [ ! -f "${PNOR_RO_ACTIVE_PATH}${volatileName}" ]; then
-      cp -a "${PNOR_RO_ACTIVE_PATH}81e0066f.lid" "${PNOR_PRSV_ACTIVE_PATH}"
-      ln -s "81e0066f.lid" "${PNOR_PRSV_ACTIVE_PATH}${volatileName}"
+    PNOR_TOC_FILE="pnor.toc"
+    PNOR_RO_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/ro/"
+    PNOR_RW_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/rw/"
+    PNOR_PRSV_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/prsv/"
+
+    # toc partition string format:
+    # partition27=HB_VOLATILE,0x02ba9000,0x02bae000,00,ECC,VOLATILE,READWRITE
+    tocFilePath="${PNOR_RO_ACTIVE_PATH}${PNOR_TOC_FILE}"
+    if [ ! -f "${tocFilePath}" ]; then
+        tocFilePath="${PNOR_RW_ACTIVE_PATH}${PNOR_TOC_FILE}"
     fi
-  done
-  # Always reset the sensor after clearing
-  busctl set-property "$service" /org/open_power/control/volatile xyz.openbmc_project.Object.Enable Enabled b false
+    mapfile -t volatiles < <(grep VOLATILE "${tocFilePath}" | grep -Eo '^partition([0-9]+)=([A-Za-z0-9_]+)')
+    for (( index=0; index<${#volatiles[@]}; index++ )); do
+        volatileName="$(echo "${volatiles[${index}]}" | awk -F '=' '{print $2}')"
+
+        rwVolatile="${PNOR_RW_ACTIVE_PATH}${volatileName}"
+        if [ -f "${rwVolatile}" ]; then
+            echo "Clear $rwVolatile"
+            rm "${rwVolatile}"
+        fi
+        prsvVolatile="${PNOR_PRSV_ACTIVE_PATH}${volatileName}"
+        if [ -f "${prsvVolatile}" ]; then
+            echo "Clear $prsvVolatile"
+            rm "${prsvVolatile}"
+        fi
+
+        if [ ! -f "${PNOR_RO_ACTIVE_PATH}${volatileName}" ]; then
+            cp -a "${PNOR_RO_ACTIVE_PATH}81e0066f.lid" "${PNOR_PRSV_ACTIVE_PATH}"
+            ln -s "81e0066f.lid" "${PNOR_PRSV_ACTIVE_PATH}${volatileName}"
+        fi
+    done
+    # Always reset the sensor after clearing
+    busctl set-property "$service" /org/open_power/control/volatile xyz.openbmc_project.Object.Enable Enabled b false
 }
 
-update_symlinks() {
-  PNOR_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/"
-  HOSTFW_ACTIVE_PATH="/var/lib/phosphor-software-manager/hostfw/"
-  PNOR_RO_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/ro"
-  PNOR_RO_PREFIX="/media/pnor-ro-"
-  PNOR_RW_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/rw"
-  PNOR_RW_PREFIX="/media/pnor-rw-"
-  PNOR_PRSV_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/prsv"
-  PNOR_PRSV="/media/pnor-prsv"
-  PERSISTENCE_PATH="/var/lib/obmc/openpower-pnor-code-mgmt/"
-  PNOR_PATCH_LOCATION="/usr/local/share/pnor/"
-  MMC_BASE_PATH="/media/hostfw"
-  MMC_RO_PATH="${MMC_BASE_PATH}/running-ro"
-  MMC_RUNNING_PATH="${MMC_BASE_PATH}/running"
-  MMC_ALTERNATE_PATH="${MMC_BASE_PATH}/alternate"
-  MMC_STAGING_PATH="${MMC_BASE_PATH}/staging"
-  MMC_NVRAM_PATH="${MMC_BASE_PATH}/nvram"
-  HOSTFW_RUNNING_PATH="${HOSTFW_ACTIVE_PATH}/running"
-  HOSTFW_ALTERNATE_PATH="${HOSTFW_ACTIVE_PATH}/alternate"
-  HOSTFW_STAGING_PATH="${HOSTFW_ACTIVE_PATH}/staging"
-  HOSTFW_NVRAM_PATH="${HOSTFW_ACTIVE_PATH}/nvram"
+function update_symlinks() {
+    PNOR_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/"
+    HOSTFW_ACTIVE_PATH="/var/lib/phosphor-software-manager/hostfw/"
+    PNOR_RO_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/ro"
+    PNOR_RO_PREFIX="/media/pnor-ro-"
+    PNOR_RW_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/rw"
+    PNOR_RW_PREFIX="/media/pnor-rw-"
+    PNOR_PRSV_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/prsv"
+    PNOR_PRSV="/media/pnor-prsv"
+    PERSISTENCE_PATH="/var/lib/obmc/openpower-pnor-code-mgmt/"
+    PNOR_PATCH_LOCATION="/usr/local/share/pnor/"
+    MMC_BASE_PATH="/media/hostfw"
+    MMC_RO_PATH="${MMC_BASE_PATH}/running-ro"
+    MMC_RUNNING_PATH="${MMC_BASE_PATH}/running"
+    MMC_ALTERNATE_PATH="${MMC_BASE_PATH}/alternate"
+    MMC_STAGING_PATH="${MMC_BASE_PATH}/staging"
+    MMC_NVRAM_PATH="${MMC_BASE_PATH}/nvram"
+    HOSTFW_RUNNING_PATH="${HOSTFW_ACTIVE_PATH}/running"
+    HOSTFW_ALTERNATE_PATH="${HOSTFW_ACTIVE_PATH}/alternate"
+    HOSTFW_STAGING_PATH="${HOSTFW_ACTIVE_PATH}/staging"
+    HOSTFW_NVRAM_PATH="${HOSTFW_ACTIVE_PATH}/nvram"
 
-  # Get a list of all active PNOR versions
-  data="$(ls -d ${PNOR_RO_PREFIX}* 2>/dev/null)"
-  mapfile -t array <<< "${data}"
+    # Get a list of all active PNOR versions
+    data="$(ls -d ${PNOR_RO_PREFIX}* 2>/dev/null)"
+    mapfile -t array <<< "${data}"
 
-  currentVersion=""
-  lowestPriority=255
-  for element in "${array[@]}"; do
-    #Remove the PNOR_RO_PREFIX from the path to get version ID.
-    versionId="${element#"${PNOR_RO_PREFIX}"}"
+    currentVersion=""
+    lowestPriority=255
+    for element in "${array[@]}"; do
+        #Remove the PNOR_RO_PREFIX from the path to get version ID.
+        versionId="${element#"${PNOR_RO_PREFIX}"}"
 
-    # Get the priority of active versions from persistence files.
-    if [[ -f "${PERSISTENCE_PATH}${versionId}" ]]; then
-      data="$(grep -r "priority" "${PERSISTENCE_PATH}${versionId}")"
-      priority="${data: -1}"
-      if [[ priority -le lowestPriority ]]; then
-        lowestPriority=${priority}
-        currentVersion=${versionId}
-      fi
+        # Get the priority of active versions from persistence files.
+        if [[ -f "${PERSISTENCE_PATH}${versionId}" ]]; then
+            data="$(grep -r "priority" "${PERSISTENCE_PATH}${versionId}")"
+            priority="${data: -1}"
+            if [[ priority -le lowestPriority ]]; then
+                lowestPriority=${priority}
+                currentVersion=${versionId}
+            fi
+        fi
+    done
+
+    if [ -n "$currentVersion" ]; then
+        # Use active version
+        roTarget="${PNOR_RO_PREFIX}${currentVersion}"
+        rwTarget="${PNOR_RW_PREFIX}${currentVersion}"
+        prsvTarget="${PNOR_PRSV}"
+    elif [ -d "${MMC_BASE_PATH}" ]; then
+        # Use eMMC
+        roTarget="${MMC_RO_PATH}"
+        rwTarget="${MMC_RUNNING_PATH}"
+        prsvTarget="${MMC_RUNNING_PATH}"
+
+        if [ ! -d "${HOSTFW_ACTIVE_PATH}" ]; then
+            mkdir -p "${HOSTFW_ACTIVE_PATH}"
+        fi
+        # Symlinks used by PLDM
+        if [[ $(readlink -f "${HOSTFW_RUNNING_PATH}") != "${MMC_RUNNING_PATH}" ]]; then
+            rm -f ${HOSTFW_RUNNING_PATH}
+            ln -sfv ${MMC_RUNNING_PATH} ${HOSTFW_RUNNING_PATH}
+        fi
+        if [[ $(readlink -f "${HOSTFW_ALTERNATE_PATH}") != "${MMC_ALTERNATE_PATH}" ]]; then
+            rm -f ${HOSTFW_ALTERNATE_PATH}
+            ln -sfv ${MMC_ALTERNATE_PATH} ${HOSTFW_ALTERNATE_PATH}
+        fi
+        if [[ $(readlink -f "${HOSTFW_STAGING_PATH}") != "${MMC_STAGING_PATH}" ]]; then
+            rm -f ${HOSTFW_STAGING_PATH}
+            ln -sfv ${MMC_STAGING_PATH} ${HOSTFW_STAGING_PATH}
+        fi
+        if [[ $(readlink -f "${HOSTFW_NVRAM_PATH}") != "${MMC_NVRAM_PATH}" ]]; then
+            rm -f ${HOSTFW_NVRAM_PATH}
+            ln -sfv ${MMC_NVRAM_PATH} ${HOSTFW_NVRAM_PATH}
+        fi
     fi
-  done
 
-  if [ -n "$currentVersion" ]; then
-      # Use active version
-      roTarget="${PNOR_RO_PREFIX}${currentVersion}"
-      rwTarget="${PNOR_RW_PREFIX}${currentVersion}"
-      prsvTarget="${PNOR_PRSV}"
-  elif [ -d "${MMC_BASE_PATH}" ]; then
-      # Use eMMC
-      roTarget="${MMC_RO_PATH}"
-      rwTarget="${MMC_RUNNING_PATH}"
-      prsvTarget="${MMC_RUNNING_PATH}"
-
-      if [ ! -d "${HOSTFW_ACTIVE_PATH}" ]; then
-          mkdir -p "${HOSTFW_ACTIVE_PATH}"
-      fi
-      # Symlinks used by PLDM
-      if [[ $(readlink -f "${HOSTFW_RUNNING_PATH}") != "${MMC_RUNNING_PATH}" ]]; then
-          rm -f ${HOSTFW_RUNNING_PATH}
-          ln -sfv ${MMC_RUNNING_PATH} ${HOSTFW_RUNNING_PATH}
-      fi
-      if [[ $(readlink -f "${HOSTFW_ALTERNATE_PATH}") != "${MMC_ALTERNATE_PATH}" ]]; then
-          rm -f ${HOSTFW_ALTERNATE_PATH}
-          ln -sfv ${MMC_ALTERNATE_PATH} ${HOSTFW_ALTERNATE_PATH}
-      fi
-      if [[ $(readlink -f "${HOSTFW_STAGING_PATH}") != "${MMC_STAGING_PATH}" ]]; then
-          rm -f ${HOSTFW_STAGING_PATH}
-          ln -sfv ${MMC_STAGING_PATH} ${HOSTFW_STAGING_PATH}
-      fi
-      if [[ $(readlink -f "${HOSTFW_NVRAM_PATH}") != "${MMC_NVRAM_PATH}" ]]; then
-          rm -f ${HOSTFW_NVRAM_PATH}
-          ln -sfv ${MMC_NVRAM_PATH} ${HOSTFW_NVRAM_PATH}
-      fi
-  fi
-
-  if [ ! -d "${PNOR_ACTIVE_PATH}" ]; then
+    if [ ! -d "${PNOR_ACTIVE_PATH}" ]; then
         mkdir -p "${PNOR_ACTIVE_PATH}"
-  fi
+    fi
 
-  # If the RW or RO active links doesn't point to the version with
-  # lowest priority, then remove the symlink and create new ones.
-  if [[ $(readlink -f "${PNOR_RO_ACTIVE_PATH}") != "${roTarget}" ]]; then
-    rm -f ${PNOR_RO_ACTIVE_PATH}
-    rm -rf ${PNOR_PATCH_LOCATION}*
-    ln -sfv ${roTarget} ${PNOR_RO_ACTIVE_PATH}
-  fi
+    # If the RW or RO active links doesn't point to the version with
+    # lowest priority, then remove the symlink and create new ones.
+    if [[ $(readlink -f "${PNOR_RO_ACTIVE_PATH}") != "${roTarget}" ]]; then
+        rm -f ${PNOR_RO_ACTIVE_PATH}
+        rm -rf ${PNOR_PATCH_LOCATION}*
+        ln -sfv ${roTarget} ${PNOR_RO_ACTIVE_PATH}
+    fi
 
-  if [[ $(readlink -f "${PNOR_RW_ACTIVE_PATH}") != "${rwTarget}" ]]; then
-    rm -f ${PNOR_RW_ACTIVE_PATH}
-    ln -sfv ${rwTarget} ${PNOR_RW_ACTIVE_PATH}
-  fi
+    if [[ $(readlink -f "${PNOR_RW_ACTIVE_PATH}") != "${rwTarget}" ]]; then
+        rm -f ${PNOR_RW_ACTIVE_PATH}
+        ln -sfv ${rwTarget} ${PNOR_RW_ACTIVE_PATH}
+    fi
 
-  if [[ $(readlink -f "${PNOR_PRSV_ACTIVE_PATH}") != "${prsvTarget}" ]]; then
-    rm -f ${PNOR_PRSV_ACTIVE_PATH}
-    ln -sfv ${prsvTarget} ${PNOR_PRSV_ACTIVE_PATH}
-  fi
+    if [[ $(readlink -f "${PNOR_PRSV_ACTIVE_PATH}") != "${prsvTarget}" ]]; then
+        rm -f ${PNOR_PRSV_ACTIVE_PATH}
+        ln -sfv ${prsvTarget} ${PNOR_PRSV_ACTIVE_PATH}
+    fi
 }
 
 case "$1" in
-  clearvolatile)
-    clear_volatile
-    ;;
-  updatesymlinks)
-    update_symlinks
-    ;;
-  *)
-    echo "Invalid argument"
-    exit 1
-    ;;
+    clearvolatile)
+        clear_volatile
+        ;;
+    updatesymlinks)
+        update_symlinks
+        ;;
+    *)
+        echo "Invalid argument"
+        exit 1
+        ;;
 esac
 rc=$?
 if [ ${rc} -ne 0 ]; then
-  echo "$0: error ${rc}"
-  exit ${rc}
+    echo "$0: error ${rc}"
+    exit ${rc}
 fi