obmc-flash-bmc: Don't overwrite u-boot env vars if already set

The BMC requests to set various u-boot environment variables during
Activation like Priority and UBI volume information. Some of these
variables may already be set to the requested value, but u-boot writes
a new entry in the u-boot env mtd device. Prevent wearing off this mtd
by checking if the values are the same before writing.

Tested: Verified that without the change the /dev/mtd2 (u-boot env)
appends a new string every time a variable is set even if it's already
set. Verified with change that no new string is added to the mtd device.

Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
Change-Id: I8e3c379dc078d5b6ab593fe9cbeebbbd346f29e8
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 4bb7091..b8a33ae 100644
--- a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
+++ b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
@@ -309,8 +309,12 @@
     if [[ "$variable" == *"="* ]]; then
         varName="${variable%=*}"
         value="${variable##*=}"
-        fw_setenv "$varName" "$value"
-        fw_setenv "$varName" "$value"
+        # Write only if var is not set already to the requested value
+        currentValue="$(fw_printenv -n "${varName}")"
+        if [[ "${currenValue}" != "${value}" ]]; then
+          fw_setenv "$varName" "$value"
+          fw_setenv "$varName" "$value"
+        fi
     else
         fw_setenv "$variable"
         fw_setenv "$variable"