flashmap: Add FMAP_AREA_PRESERVE in area flags

Many projects started their initial builds without knowing that some
sections must be preserved when being updated. This may be solved by
adding section name to 'preserved' list in firmware updater (for
instance, CL:1239797), or include that section as sub area of
{RO,RW}_PRESERVE.

However, there are problems in both solution. For example, installing an
older image will run old updater, which will not preserve the new names.
Also, if there are multiple sections must be preserved (and not
contiguous - see CL:1493629) there will be problems.
Additionally, changing FMAP layout usually causes more problems.

As a result, adding the description in FMAP area would be the better
idea. The new FMAP_AREA_PRESERVE is a suggestion for updater to preserve
this section if possible. Programs constructing FMAP must define its own
way to add such attribute.

BUG=b:126637087,chromium:936768
TEST=sudo emerge flashmap

Change-Id: I61e80aa13efe36177b76b5a9d8d3a4b8bcbd9bac
Reviewed-on: https://chromium-review.googlesource.com/1493767
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Duncan Laurie <dlaurie@google.com>
diff --git a/fmap.py b/fmap.py
index 830a64e..982d1a5 100644
--- a/fmap.py
+++ b/fmap.py
@@ -68,6 +68,8 @@
 FMAP_FLAGS = {
     'FMAP_AREA_STATIC': 1 << 0,
     'FMAP_AREA_COMPRESSED': 1 << 1,
+    'FMAP_AREA_RO': 1 << 2,
+    'FMAP_AREA_PRESERVE': 1 << 3,
 }
 
 FMAP_HEADER_NAMES = (
diff --git a/lib/fmap.c b/lib/fmap.c
index 8984697..c62735d 100644
--- a/lib/fmap.c
+++ b/lib/fmap.c
@@ -57,6 +57,7 @@
 	{ FMAP_AREA_STATIC, "static" },
 	{ FMAP_AREA_COMPRESSED, "compressed" },
 	{ FMAP_AREA_RO, "ro" },
+	{ FMAP_AREA_PRESERVE, "preserve" },
 };
 
 /* returns size of fmap data structure if successful, <0 to indicate error */
diff --git a/lib/fmap.h b/lib/fmap.h
index 51bd768..05993fd 100644
--- a/lib/fmap.h
+++ b/lib/fmap.h
@@ -54,6 +54,7 @@
 	FMAP_AREA_STATIC	= 1 << 0,
 	FMAP_AREA_COMPRESSED	= 1 << 1,
 	FMAP_AREA_RO		= 1 << 2,
+	FMAP_AREA_PRESERVE	= 1 << 3,  /* Should be preserved on update. */
 };
 
 /* Mapping of volatile and static regions in firmware binary */