servo: Add shared fw support to program_firmware

Octopus devices share firmware across multiple models (but not across
all Octopus devices). This breaks expectations made by the
program_firmware() call.

This commit adds the EC firmare image (as reported by the EC "ver"
command) as one of the images to attempt flashing onto the DUT.

BUG=chromium:1009841
TEST=None

Change-Id: I289dfe3a96d3c61b8a5339a24e4841ed816c7bc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/1967773
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
Tested-by: Justin TerAvest <teravest@chromium.org>
Commit-Queue: Kirtika Ruchandani <kirtika@chromium.org>
diff --git a/server/cros/servo/servo.py b/server/cros/servo/servo.py
index 1be3fed..bc7b4d4 100644
--- a/server/cros/servo/servo.py
+++ b/server/cros/servo/servo.py
@@ -1188,8 +1188,20 @@
         """
         ap_image_candidates = ('image.bin', 'image-%s.bin' % model,
                                'image-%s.bin' % board)
-        ec_image_candidates = ('ec.bin', '%s/ec.bin' % model,
-                               '%s/ec.bin' % board)
+
+        # Best effort; try to retrieve the EC board from the version as
+        # reported by the EC.
+        ec_board = None
+        try:
+          ec_board = self.get('ec_board')
+        except Exception as err:
+          logging.info('Failed to get ec_board value; ignoring')
+          pass
+
+        ec_image_candidates = ['ec.bin', '%s/ec.bin' % model,
+                               '%s/ec.bin' % board]
+        if ec_board:
+          ec_image_candidates.append('%s/ec.bin' % ec_board)
 
         self._reprogram(tarball_path, 'EC', ec_image_candidates, rw_only)
         self._reprogram(tarball_path, 'BIOS', ap_image_candidates, rw_only)