Refactoring and cleaning up FW programming functions.

Moved and cleaned up the programmer.py functionality to
firmware_programmer.py.

1. Now using the flash_ec script for ec programming of
supported boards. This script is maintained by the
development teams.

2. Refactored flashrom programmer to support multiple boards
with the correct vref voltages supplied.

3. FW programmer objects are instantiated in the servo client
and can be changed based on the version of servo.

4. Exposed get_board and get_version in the servo client.

5. Smaller cleanup of functions calls, etc.

BUG=chromium:317911
TEST=Manually at desk

Change-Id: I0440fa0a7694ca53c7bbc944fbd906df94e1bd25
Reviewed-on: https://chromium-review.googlesource.com/177598
Reviewed-by: Yusuf Mohsinally <mohsinally@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Commit-Queue: Vic Yang <victoryang@chromium.org>
diff --git a/server/cros/servo/servo.py b/server/cros/servo/servo.py
index 20e6d4d..8e55d0f 100644
--- a/server/cros/servo/servo.py
+++ b/server/cros/servo/servo.py
@@ -12,7 +12,7 @@
 from autotest_lib.client.common_lib import error
 from autotest_lib.server import utils
 from autotest_lib.server.cros.servo import power_state_controller
-from autotest_lib.server.cros.servo import programmer
+from autotest_lib.server.cros.servo import firmware_programmer
 
 
 class Servo(object):
@@ -84,6 +84,13 @@
         self.set('usb_mux_oe1', 'on')
         self.switch_usbkey('off')
 
+        # Initialize firmware programmer
+        if self._server.get_version() == "servo_v2":
+            self._programmer = firmware_programmer.ProgrammerV2(self)
+        else:
+            logging.warn("No firmware programmer for servo version: %s" %
+                    self._version)
+
 
     def get_power_state_controller(self):
         """Return the power state controller for this Servo.
@@ -292,6 +299,20 @@
         time.sleep(Servo.BOOT_DELAY)
 
 
+    def get_version(self):
+        """Get the version of servod board.
+
+        """
+        return self._server.get_version()
+
+
+    def get_board(self):
+        """Get the board connected to servod.
+
+        """
+        return self._server.get_board()
+
+
     def _get_xmlrpclib_exception(self, xmlexc):
         """Get meaningful exception string from xmlrpc.
 
@@ -537,38 +558,28 @@
                                     args=args).stdout.strip()
 
 
-    def program_ec(self, board, image):
-        """Program EC on a given board using given image.
+    def program_bios(self, image):
+        """Program bios on DUT with given image.
 
-        @param board: a string, type of the DUT board
-        @param image: a string, file name of the EC image to program on the
-                      DUT
+        @param image: a string, file name of the BIOS image to program
+                      on the DUT.
+
         """
         if not self.is_localhost():
             image = self._scp_image(image)
-        programmer.program_ec(board, self, image)
+        self._programmer.program_bios(image)
 
 
-    def program_bootprom(self, board, image):
-        """Program bootprom on a given board using given image.
+    def program_ec(self, image):
+        """Program ec on DUT with given image.
 
-        In case servo is controlled by a remote host, the image needs to be
-        transferred to the host.
+        @param image: a string, file name of the EC image to program
+                      on the DUT.
 
-        If the device tree subdirectory is present along with the image, the
-        subdirectory is also copied to the remote host.
-
-        @param board: a string, type of the DUT board
-        @param image: a string, file name of the firmware image to program on
-                      the DUT. The device tree subdirectory, if present, is on
-                      the same level with the image file.
         """
         if not self.is_localhost():
-            dts_path = os.path.join(os.path.dirname(image), 'dts')
             image = self._scp_image(image)
-            if os.path.isdir(dts_path):
-                self._scp_image(dts_path)
-        programmer.program_bootprom(board, self, image)
+        self._programmer.program_ec(image)
 
 
     def _switch_usbkey_power(self, power_state, detection_delay=False):