Increase default size of UBI read-write volume

The default size of the UBI read-write volume is currently set to 4MB.
There are no plans to store more than one BMC rootfs image on the chip
so in a 32MB flash chip, accounting for the current rootfs image size
of ~15MB with plans to grow to ~20MB with the addition of redfish and
other packages, it is safe to increase the read-write volume size to
6MB since the current size is already almost completely taken up if
there are multiple error logs / dumps on the system.

In addition, make the size configurable from a recipe so that the
size can be changed in a per-system basis. And during code update,
check the current size and update it if it's different, this allows
systems to be able to be resized to a new size by performing factory
reset after a code update that sets the new size.

Tested:
- Booted on QEMU and verified non-ubi system (romulus) retains the
current 4MB read-write volume, and ubi system (witherspoon) has a
6MB volume.
- Code updated to an image that has these changes and verified the
rwfs_size env variable changes to 6MB, and that a subsequent factory
reset rebuilds the volume with size 6MB.

Change-Id: I995eb560c1bd87ee95712c731e3d6e55bc0b2735
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/common/recipes-bsp/u-boot/files/0004-config-ast-common-Add-conditional-factory-reset-comm.patch b/common/recipes-bsp/u-boot/files/0004-config-ast-common-Add-conditional-factory-reset-comm.patch
index 792cdb7..6bf9bb7 100644
--- a/common/recipes-bsp/u-boot/files/0004-config-ast-common-Add-conditional-factory-reset-comm.patch
+++ b/common/recipes-bsp/u-boot/files/0004-config-ast-common-Add-conditional-factory-reset-comm.patch
@@ -21,7 +21,7 @@
  #define CONFIG_ENV_SIZE			0x10000	/* Total Size of Environment Sector */
  #define CONFIG_ENV_SIZE_REDUND		0x10000
  
-+#define CONFIG_RWFS_SIZE		0x400000
++#define CONFIG_RWFS_SIZE		0x600000
 +
  #define CONFIG_BOOTCOMMAND		"run set_bootargs; run obmc_bootcmd"
  #define CONFIG_ENV_OVERWRITE
diff --git a/common/recipes-phosphor/flash/phosphor-software-manager.bb b/common/recipes-phosphor/flash/phosphor-software-manager.bb
index 5cd017e..725c835 100644
--- a/common/recipes-phosphor/flash/phosphor-software-manager.bb
+++ b/common/recipes-phosphor/flash/phosphor-software-manager.bb
@@ -86,9 +86,11 @@
 BMC_RW_MTD ??= "bmc"
 BMC_RO_MTD ??= "bmc"
 BMC_KERNEL_MTD ??= "bmc"
+BMC_RW_SIZE ??= "0x600000"
 SYSTEMD_SUBSTITUTIONS += "RW_MTD:${BMC_RW_MTD}:obmc-flash-bmc-ubirw.service"
 SYSTEMD_SUBSTITUTIONS += "RO_MTD:${BMC_RO_MTD}:obmc-flash-bmc-ubiro@.service"
 SYSTEMD_SUBSTITUTIONS += "KERNEL_MTD:${BMC_KERNEL_MTD}:obmc-flash-bmc-ubiro@.service"
+SYSTEMD_SUBSTITUTIONS += "RW_SIZE:${BMC_RW_SIZE}:obmc-flash-bmc-ubirw.service"
 
 SRC_URI += "file://obmc-flash-bmc"
 do_install_append() {
diff --git a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
index 12c6c76..d046516 100644
--- a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
+++ b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
@@ -108,10 +108,14 @@
   rw="${rwmtd#mtd}"
   ubidev="/dev/ubi${rw}"
 
-  # Create a ubi volume of size 4MB, that is the current size of the rwfs image
+  rwsize="$(fw_printenv -n rwfs_size)"
+  if [[ "${imgsize}" != "${rwsize}" ]]; then
+    fw_setenv rwfs_size "${imgsize}"
+  fi
+
   vol="$(findubi "${name}")"
   if [ -z "${vol}" ]; then
-    ubimkvol "${ubidev}" -N "${name}" -s 4MiB
+    ubimkvol "${ubidev}" -N "${name}" -s "${imgsize}"
   fi
 }
 
@@ -387,6 +391,7 @@
   ubirw)
     reqmtd="$2"
     name="$3"
+    imgsize="$4"
     ubi_rw
     ;;
   ubiro)
diff --git a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc-ubirw.service b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc-ubirw.service
index 4a955f2..79d0ea3 100644
--- a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc-ubirw.service
+++ b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc-ubirw.service
@@ -4,5 +4,5 @@
 [Service]
 Type=oneshot
 RemainAfterExit=no
-ExecStart=/usr/bin/env obmc-flash-bmc ubirw {RW_MTD} rwfs
+ExecStart=/usr/bin/env obmc-flash-bmc ubirw {RW_MTD} rwfs {RW_SIZE}
 SyslogIdentifier=obmc-flash-bmc