gooftool: add argument '--expect_zero_touch' for testing

When testing zero touch flow, we would provide commands for partners to
try.  If partners run `gooftool cr50_write_flash_info` directly, and
USE flag zero_touch is not set, the subcommand will skip setting SN
bits, and set board ID directly.  This will forbid the board to set SN
bits in the future, which is a bad thing when we are "trying" zero touch
feature.

Now, if we invoke the command by
  gooftool cr50_write_flash_info --expect_zero_touch
The command will first check if the required scripts are available, if
not, the command will fail immediately, without setting anything.

BUG=b:153242400
TEST=gooftool cr50_write_flash_info --expect_zero_touch

Change-Id: I356c869bdcda84c329fcafe8cd8f83ac9df8df91
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/factory/+/2139833
Tested-by: Stimim Chen <stimim@chromium.org>
Reviewed-by: Yves Arrouye <drcrash@chromium.org>
Reviewed-by: Cheng-Han Yang <chenghan@chromium.org>
Commit-Queue: Stimim Chen <stimim@chromium.org>
diff --git a/py/gooftool/commands.py b/py/gooftool/commands.py
index ec04a90..856477f 100755
--- a/py/gooftool/commands.py
+++ b/py/gooftool/commands.py
@@ -461,10 +461,18 @@
   Cr50WriteFlashInfo(options)
 
 
-@Command('cr50_write_flash_info')
+@Command('cr50_write_flash_info',
+         CmdArg('--expect_zero_touch', action='store_true',
+                help='zero touch feature is expected, the command will fail '
+                     'immediately if required dependencies are not found.'))
 def Cr50WriteFlashInfo(options):
   """Set the serial number bits, board id and flags on the Cr50 chip."""
-  GetGooftool(options).Cr50WriteFlashInfo()
+  # The '--expect_zero_touch' argument is for testing purpose, therefore, the
+  # argument can only be specified by directly using `cr50_write_flash_info`
+  # subcommand.  And the `expect_zero_touch` attribute won't exist when this
+  # function is invoked by other subcommands, e.g. `finalize`.
+  expect_zero_touch = getattr(options, 'expect_zero_touch', False)
+  GetGooftool(options).Cr50WriteFlashInfo(expect_zero_touch)
   event_log.Log('cr50_write_flash_info')