faft: Support SPACE key to trigger TO_NORM screen

We changed the key for triggering TO_NORM screen from ENTER to SPACE.
This change adds:
 - the logic of supporting the alternative of space (ctrl+f3) on servo;
 - custromized space command instead of using servo;
 - sending both SPACE and ENTER to trigger TO_NORM screen.

BUG=chrome-os-partner:12057
TEST=Run firmware_DevMode on Snow passed.

Change-Id: Ied9242c2484e0172e3cbe83ed7f6659a3afce0fe
Reviewed-on: https://gerrit.chromium.org/gerrit/28929
Reviewed-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Tom Wai-Hong Tam <waihong@chromium.org>
Tested-by: Tom Wai-Hong Tam <waihong@chromium.org>
diff --git a/server/cros/faftsequence.py b/server/cros/faftsequence.py
index 1b7f59e..d3b8026 100644
--- a/server/cros/faftsequence.py
+++ b/server/cros/faftsequence.py
@@ -72,6 +72,8 @@
             instead of sending key via servo board.
         _customized_enter_key_command: The customized Enter key command instead
             of sending key via servo board.
+        _customized_space_key_command: The customized Space key command instead
+            of sending key via servo board.
         _customized_rec_reboot_command: The customized recovery reboot command
             instead of sending key combination of Power + Esc + F3 for
             triggering recovery reboot.
@@ -202,6 +204,7 @@
 
     _customized_ctrl_d_key_command = None
     _customized_enter_key_command = None
+    _customized_space_key_command = None
     _customized_rec_reboot_command = None
     _install_image_path = None
     _firmware_update = False
@@ -224,6 +227,10 @@
             self._customized_enter_key_command = args['enter_cmd']
             logging.info('Customized Enter key command: %s' %
                     self._customized_enter_key_command)
+        if 'space_cmd' in args:
+            self._customized_space_key_command = args['space_cmd']
+            logging.info('Customized Space key command: %s' %
+                    self._customized_space_key_command)
         if 'rec_reboot_cmd' in args:
             self._customized_rec_reboot_command = args['rec_reboot_cmd']
             logging.info('Customized recovery reboot command: %s' %
@@ -672,6 +679,16 @@
             self.servo.enter_key()
 
 
+    def send_space_to_dut(self):
+        """Send Space key to DUT."""
+        if self._customized_space_key_command:
+            logging.info('running the customized Space key command')
+            os.system(self._customized_space_key_command)
+        else:
+            # Send the alternative key combinaton of space key to servo.
+            self.servo.ctrl_refresh_key()
+
+
     def wait_fw_screen_and_ctrl_d(self):
         """Wait for firmware warning screen and press Ctrl-D."""
         time.sleep(self.FIRMWARE_SCREEN_DELAY)
@@ -792,6 +809,12 @@
         if dev:
             self.send_ctrl_d_to_dut()
         else:
+            # Only SPACE can trigger TO_NORM screen officially.
+            # We send both SPACE and ENTER in order to make the old and new
+            # firmware still work. It won't trigger twice since only one of
+            # them takes effect.
+            # TODO Remove to ENTER when all devices use new firmware.
+            self.send_space_to_dut()
             self.send_enter_to_dut()
         time.sleep(self.FIRMWARE_SCREEN_DELAY)
         self.send_enter_to_dut()
diff --git a/server/cros/servo.py b/server/cros/servo.py
index 53d2a06..3205cec 100644
--- a/server/cros/servo.py
+++ b/server/cros/servo.py
@@ -243,6 +243,14 @@
         self._press_and_release_keys('none', 'refresh')
 
 
+    def ctrl_refresh_key(self):
+        """Simulate Ctrl and Refresh (F3) simultaneous press.
+
+        This key combination is an alternative of Space key.
+        """
+        self._press_and_release_keys('ctrl_r', 'refresh')
+
+
     def imaginary_key(self):
         """Simulate imaginary key button press.