Add verification support for RW_VPD.

Registration and group codes are in RW_VPD. We need to have verify these
codes are set before finalize.

BUG=chrome-os-partner:13396
TEST=manually run "gooftool verify_hwid"

Change-Id: If2a710dba7a14a018cabd256763f7d7ddd9adc2f
Reviewed-on: https://gerrit.chromium.org/gerrit/33411
Commit-Ready: Ricky Liang <jcliang@chromium.org>
Tested-by: Ricky Liang <jcliang@chromium.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
diff --git a/py/gooftool/gooftool.py b/py/gooftool/gooftool.py
index d1776d8..a84f913 100755
--- a/py/gooftool/gooftool.py
+++ b/py/gooftool/gooftool.py
@@ -381,16 +381,23 @@
   the necessary fields as specified by the board data, and when
   possible verify that values are legitimate.
   """
-  def VerifyVpd(ro_vpd_keys):
+  def VerifyVpd(ro_vpd_keys, rw_vpd_keys):
     ro_vpd = ReadRoVpd(main_fw_file)
     for key in ro_vpd_keys:
       if key not in ro_vpd:
-        sys.exit('Missing required VPD field: %s' % key)
+        sys.exit('Missing required RO VPD field: %s' % key)
       known_valid_values = KNOWN_VPD_FIELD_DATA.get(key, None)
       value = ro_vpd[key]
-      if known_valid_values is not None and value not in known_valid_values:
-        sys.exit('Invalid VPD entry : key %r, value %r' % (key, value))
+      if (known_valid_values is not None) and (value not in known_valid_values):
+        sys.exit('Invalid RO VPD entry : key %r, value %r' % (key, value))
     rw_vpd = ReadRwVpd(main_fw_file)
+    for key in rw_vpd_keys:
+      if key not in rw_vpd:
+        sys.exit('Missing required RW VPD field: %s' % key)
+      known_valid_values = KNOWN_VPD_FIELD_DATA.get(key, None)
+      value = rw_vpd[key]
+      if (known_valid_values is not None) and (value not in known_valid_values):
+        sys.exit('Invalid RW VPD entry : key %r, value %r' % (key, value))
     _event_log.Log('vpd', ro_vpd=ro_vpd, rw_vpd=rw_vpd)
   map(hwid_tool.Validate.Status, options.status)
   main_fw_file = crosfw.LoadMainFirmware().GetFileName()
@@ -459,7 +466,7 @@
                hwid.volatile)
     found_status = matched_volatiles.get(hwid.volatile, None)
     sys.exit(err_msg + ', but hwid status %r was unacceptable' % found_status)
-  VerifyVpd(device.vpd_ro_fields)
+  VerifyVpd(device.vpd_ro_fields, device.vpd_rw_fields)
   _event_log.Log('verified_hwid', hwid=hwid)
   print 'Verification SUCCESS!'
 
diff --git a/py/hwdb/hwid_tool.py b/py/hwdb/hwid_tool.py
index 8f0b07d..5e1e866 100755
--- a/py/hwdb/hwid_tool.py
+++ b/py/hwdb/hwid_tool.py
@@ -110,6 +110,7 @@
     'volatiles': (dict, (dict, str)),
     'volatile_values': (dict, str),
     'vpd_ro_fields': (list, str),
+    'vpd_rw_fields': (list, str),
     })
 
 MakeDatastoreClass('ProbeResults', {
@@ -1598,7 +1599,8 @@
                    if vol_code in target_volatiles),
     volatile_values=dict((vol_name, device.volatile_values[vol_name])
                          for vol_name in target_volatile_names),
-    vpd_ro_fields=device.vpd_ro_fields))
+    vpd_ro_fields=device.vpd_ro_fields,
+    vpd_rw_fields=device.vpd_rw_fields))
   filtered_comp_db.Write(config.dest_dir)
   filtered_hw_db = HardwareDb(config.dest_dir)
   filtered_hw_db.devices[config.board] = filtered_device