Dynamically set size of pnor read-only partition

- The pnor read-only partition contains the contents
  of the squashfs image. Therefore the corresponding
  ubi volume should only be as big in size.
- This would allow us to increase the number of active
  pnor version we can possibly store on pnor chip.

Resolves openbmc/openbmc#1840

Change-Id: I5e35a0fcd62e947919f4c9489642188ae2fe49bb
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios
index 6e4aa78..d92fad5 100644
--- a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios
+++ b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios
@@ -57,6 +57,8 @@
   ubidev="/dev/ubi${pnormtd#mtd}"
   mountdir="/media/${name}"
   vol="$(findubi "${name}")"
+  img="/tmp/images/${version}/pnor.xz.squashfs"
+  filesize="$(ls -sh $img | awk -F " " {'print $1'})"
 
   if is_mounted "${name}"; then
     echo "${name} is already mounted."
@@ -71,10 +73,8 @@
     mkdir "${mountdir}"
   fi
 
-  # Create a static ubi volume of arbitrary size 24MB,
-  # the current pnor image is ~19MB
-  # TODO Set size based on file size openbmc/openbmc#1840
-  ubimkvol "${ubidev}" -N "${name}" -s 24MiB --type=static
+  # Set size of read-only partition equal to pnor.xz.squashfs
+  ubimkvol "${ubidev}" -N "${name}" -s "${filesize}"KiB --type=static
   vol="$(findubi "${name}")"
 
   if [ $? != 0 ]; then
@@ -83,7 +83,6 @@
   fi
 
   ubidevid="${vol#ubi}"
-  img="/tmp/images/${version}/pnor.xz.squashfs"
   ubiupdatevol "/dev/ubi${ubidevid}" "${img}"
 
   if [ $? != 0 ]; then