gooftool: add a flag to enable set sn bits

This is the the fundation of approach (1) and (2) listed in the issue.
We also removed CheckCr50SetSnBitsDependency() because the script is now
always included in the test image.

BUG=b:157210082
TEST=make test

Change-Id: I7d566e9a354cc881639fc3c87552a6f4b5a78c2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/factory/+/2212021
Reviewed-by: Stimim Chen <stimim@chromium.org>
Tested-by: Stimim Chen <stimim@chromium.org>
Commit-Queue: Stimim Chen <stimim@chromium.org>
diff --git a/py/gooftool/commands.py b/py/gooftool/commands.py
index c889d9b..cf97522 100755
--- a/py/gooftool/commands.py
+++ b/py/gooftool/commands.py
@@ -267,6 +267,10 @@
     '--no_generate_mfg_date', action='store_false', dest='generate_mfg_date',
     help='Do not generate manufacturing date nor write mfg_date into VPD.')
 
+_enable_zero_touch_cmd_arg = CmdArg(
+    '--enable_zero_touch', action='store_true',
+    help='Set attested_device_id for zero-touch feature.')
+
 
 @Command(
     'verify_ec_key',
@@ -364,9 +368,11 @@
   return GetGooftool(options).VerifyCrosConfig()
 
 
-@Command('verify-sn-bits')
+@Command('verify-sn-bits',
+         _enable_zero_touch_cmd_arg)
 def VerifySnBits(options):
-  GetGooftool(options).VerifySnBits()
+  if options.enable_zero_touch:
+    GetGooftool(options).VerifySnBits()
 
 
 @Command('write_protect')
@@ -466,17 +472,11 @@
 
 @Command('cr50_write_flash_info',
          _rma_mode_cmd_arg,
-         CmdArg('--expect_zero_touch', action='store_true',
-                help='zero touch feature is expected, the command will fail '
-                     'immediately if required dependencies are not found.'))
+         _enable_zero_touch_cmd_arg)
 def Cr50WriteFlashInfo(options):
   """Set the serial number bits, board id and flags on the Cr50 chip."""
-  # 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, options.rma_mode)
+  GetGooftool(options).Cr50WriteFlashInfo(
+      options.enable_zero_touch, options.rma_mode)
   event_log.Log('cr50_write_flash_info')
 
 
@@ -566,7 +566,8 @@
          _enforced_release_channels_cmd_arg,
          _waive_list_cmd_arg,
          _skip_list_cmd_arg,
-         _no_ectool_cmd_arg)
+         _no_ectool_cmd_arg,
+         _enable_zero_touch_cmd_arg)
 def Verify(options):
   """Verifies if whole factory process is ready for finalization.
 
@@ -812,7 +813,8 @@
          _rlz_embargo_end_date_offset_cmd_arg,
          _waive_list_cmd_arg,
          _skip_list_cmd_arg,
-         _no_generate_mfg_date_cmd_arg)
+         _no_generate_mfg_date_cmd_arg,
+         _enable_zero_touch_cmd_arg)
 def Finalize(options):
   """Verify system readiness and trigger transition into release state.