Disable beeps post reboots in crosperf.

Run gbb command before flashing to avoid post reboot beeps
if possible. It works only on machines with Write Protect Disabled.
Crosperf prints the erros messages and continues if this fails.

BUG=chromium:697609
TEST=Tested on kevin, daisy and jaq.

Change-Id: Ifb0c819281b3215655b7e3b02db605fa073d0e12
Reviewed-on: https://chromium-review.googlesource.com/508153
Commit-Ready: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Caroline Tice <cmtice@chromium.org>
diff --git a/image_chromeos.py b/image_chromeos.py
index 0ea6d39..f65ad4d 100755
--- a/image_chromeos.py
+++ b/image_chromeos.py
@@ -50,6 +50,20 @@
       'cros flash cannot work.'.format(remote))
 
 
+def DisableCrosBeeps(chromeos_root, remote, log_level):
+  """Disable annoying chromebooks beeps after reboots."""
+  cmd_executer = command_executer.GetCommandExecuter(log_level=log_level)
+
+  command = '/usr/share/vboot/bin/set_gbb_flags.sh 0x1'
+  logger.GetLogger().LogOutput('Trying to disable beeping.')
+
+  ret, o, _ = cmd_executer.CrosRunCommandWOutput(
+      command, chromeos_root=chromeos_root, machine=remote)
+  if ret != 0:
+    logger.GetLogger().LogOutput(o)
+    logger.GetLogger().LogOutput('Failed to disable beeps.')
+
+
 def DoImage(argv):
   """Image ChromeOS."""
 
@@ -199,9 +213,12 @@
       # Check to see if cros flash will work for the remote machine.
       CheckForCrosFlash(options.chromeos_root, options.remote, log_level)
 
+      # Disable the annoying chromebook beeps after reboot.
+      DisableCrosBeeps(options.chromeos_root, options.remote, log_level)
+
       cros_flash_args = [
-          'cros', 'flash', '--board=%s' % board, '--clobber-stateful',
-          options.remote
+          'cros', 'flash',
+          '--board=%s' % board, '--clobber-stateful', options.remote
       ]
       if local_image:
         cros_flash_args.append(chroot_image)