faft: Adjust chip_utils methods for consistency.

This change adjusts several places where EC image hashes were used
inconsistently, and returned in ways that would cause xmlrpc failure.
Now the hash methods in chip_utils all return bytearrays, and the
three chip classes have the same methods and are exposed in the dict.

BUG=b:165442321
TEST=Run firmware_FAFTRPC.updater, see that get_ec_hash() passes

Change-Id: Ic8a5be3d9b57c6e55344d1d20c3f74830020d205
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2399655
Tested-by: Dana Goyette <dgoyette@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Dana Goyette <dgoyette@chromium.org>
diff --git a/client/common_lib/cros/chip_utils.py b/client/common_lib/cros/chip_utils.py
index a641a70..93a0229 100644
--- a/client/common_lib/cros/chip_utils.py
+++ b/client/common_lib/cros/chip_utils.py
@@ -90,8 +90,7 @@
     cbfs_hash_name = fw_name + '.hash'
 
     def fw_ver_from_hash(self, blob):
-        """Return the firmware version encoded in the firmware hash."""
-
+        """Return the firmware version encoded in the passed-in hash content."""
         return blob[0]
 
     def compute_hash_bytes(self):
@@ -125,10 +124,12 @@
 
         # openssl outputs the result to stdout
         cmd = 'openssl dgst -sha256 -binary %s' % self.fw_file_name
-        return subprocess.check_output(cmd, shell=True)
+        result = subprocess.check_output(cmd, shell=True)
+        return bytearray(result)
 
 
 chip_id_map = {
-    '0x8751': ps8751,
-    '0x3429': anx3429,
+        'ecrw': ecrw,
+        '0x8751': ps8751,
+        '0x3429': anx3429,
 }
diff --git a/client/cros/faft/rpc_functions.py b/client/cros/faft/rpc_functions.py
index a488e04..a9dfcce 100644
--- a/client/cros/faft/rpc_functions.py
+++ b/client/cros/faft/rpc_functions.py
@@ -7,6 +7,7 @@
 
 @note: When adding categories, please also update server/cros/faft/rpc_proxy.pyi
 """
+import binascii
 import httplib
 import logging
 import os
@@ -1061,7 +1062,7 @@
         """Return the hex string of the EC hash."""
         blob = self._updater.get_ec_hash()
         # Format it to a hex string
-        return ''.join('%02x' % ord(c) for c in blob)
+        return binascii.hexlify(blob)
 
     def resign_firmware(self, version):
         """Resign firmware with version.
@@ -1170,6 +1171,9 @@
     def cbfs_get_chip_hash(self, fw_name):
         """Gets the chip firmware hash blob.
 
+        The hash data is returned as a list of stringified two-byte pieces:
+        \x12\x34...\xab\xcd\xef -> ['0x12', '0x34', ..., '0xab', '0xcd', '0xef']
+
         @param fw_name: Name of chip firmware whose hash blob to return.
         @return: Hex string of hash blob.
         """
diff --git a/client/cros/faft/utils/firmware_updater.py b/client/cros/faft/utils/firmware_updater.py
index 4886515..0548876 100644
--- a/client/cros/faft/utils/firmware_updater.py
+++ b/client/cros/faft/utils/firmware_updater.py
@@ -317,7 +317,7 @@
         # Replace ecrw.hash to the new one
         ecrw_hash_path = os.path.join(self._cbfs_work_path,
                                       chip_utils.ecrw.cbfs_hash_name)
-        with open(ecrw_hash_path, 'w') as f:
+        with open(ecrw_hash_path, 'wb') as f:
             f.write(self.get_ec_hash())
 
         # Store the modified ecrw and its hash to cbfs
@@ -620,7 +620,8 @@
         For a given chip type, returns the chip firmware hash blob.
         Before making this request, the chip blobs must have been
         extracted from cbfs using cbfs_extract_chip().
-        The hash data is returned as hexadecimal string.
+        The hash data is returned as a list of stringified two-byte pieces:
+        \x12\x34...\xab\xcd\xef -> ['0x12', '0x34', ..., '0xab', '0xcd', '0xef']
 
         @param fw_name: Chip firmware name whose hash blob to get.
         @return: Boolean success status.
diff --git a/server/site_tests/firmware_FAFTRPC/firmware_FAFTRPC.py b/server/site_tests/firmware_FAFTRPC/firmware_FAFTRPC.py
index 57f29ad..82dc948 100644
--- a/server/site_tests/firmware_FAFTRPC/firmware_FAFTRPC.py
+++ b/server/site_tests/firmware_FAFTRPC/firmware_FAFTRPC.py
@@ -936,7 +936,8 @@
                     "get_keys_path",
                     "get_work_path",
                     "get_bios_relative_path",
-                    "get_ec_relative_path"
+                    "get_ec_relative_path",
+                    "get_ec_hash"
                 ],
                 "passing_args": [
                     NO_ARGS,