bmc_update: explictly save firmware environment

Find the file to copy from the firmware environent config,
and assume the complete file should be saved as an image
to the u-boot-env mtd partition.

Preserve network settings has worked to save the u-boot-env
by copying the runtime copy of the env saved by the
initramfs init script to /run/fw_env.  That copy was
created as a workaround for a flash erase problem that
can not be created with the current driver.

Change-Id: Ie42ddbb4f821447349f70ab21d1333194aba08cf
Signed-off-by: Milton Miller <miltonm@us.ibm.com>
diff --git a/pyflashbmc/bmc_update.py b/pyflashbmc/bmc_update.py
index c1c04ec..56940fe 100644
--- a/pyflashbmc/bmc_update.py
+++ b/pyflashbmc/bmc_update.py
@@ -27,6 +27,25 @@
             yield tarinfo
 
 
+def save_fw_env():
+    fw_env = "/etc/fw_env.config"
+    lines = 0
+    files=[]
+    envcfg = open(fw_env, 'r')
+    try:
+        for line in envcfg.readlines():
+            # ignore lines that are blank or start with #
+            if (line.startswith("#")): continue
+            if (not len(line.strip())): continue
+            fn = line.partition("\t")[0];
+            files.append(fn)
+            lines += 1
+    finally:
+        envcfg.close()
+    if (lines < 1 or lines > 2 or (lines == 2 and files[0] != files[1])):
+            raise Exception("Error parsing %s\n" % fw_env)
+    shutil.copyfile(files[0], os.path.join(UPDATE_PATH, "image-u-boot-env"))
+
 class BmcFlashControl(DbusProperties, DbusObjectManager):
     def __init__(self, bus, name):
         super(BmcFlashControl, self).__init__(
@@ -138,7 +157,7 @@
 
             if self.Get(DBUS_NAME, "preserve_network_settings"):
                 print "Preserving network settings"
-                shutil.copy2("/run/fw_env", UPDATE_PATH+"/image-u-boot-env")
+                save_fw_env()
 
         except Exception as e:
             print e