new_variant: support volteer and volteer2

The volteer reference board is based on ES2 silicon, while volteer2
is based on QS silicon. For the fitimage, we need to differentiate
between the two, while all the other steps for creating a new
variant are identical.
* Add support to call a different script to add the new fitimage
* Add a new reference board support file for volteer2
* Update new_variant_fulltest.sh to support volteer2

BUG=b:175247542
TEST=Test both the "volteer" and "volteer2" reference boards:
`testdata/new_variant_fulltest.sh volteer && echo PASS`
`testdata/new_variant_fulltest.sh volteer2 && echo PASS`

Cq-Depend: chrome-internal:3460226
Change-Id: I720b7689cbb88729717796232b0664ba2293c4bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2586215
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: YH Lin <yueherngl@chromium.org>
Commit-Queue: Nick Vaccaro <nvaccaro@google.com>
diff --git a/contrib/variant/new_variant.py b/contrib/variant/new_variant.py
index a0ca218..8d8ac77 100755
--- a/contrib/variant/new_variant.py
+++ b/contrib/variant/new_variant.py
@@ -243,6 +243,11 @@
         in chroot, prepend '~/chromiumos/src' outside the chroot
     * fitimage_outputs_dir - directory under fitimage_dir where gen_fit_image.sh
         leaves its outputs
+    * fitimage_cmd - explanation of gen_fit_image command, i.e. tell the user
+        how to run gen_fit_image.sh
+    * fitimage_script - script to add fitimage sources, defaults
+        to 'files/add_fitimage.sh' if not present. Only volteer and volteer2
+        currently need to use this.
     * workon_pkgs - list of packages to cros_workon
     * emerge_cmd - the emerge command, e.g. 'emerge-hatch'
     * emerge_pkgs - list of packages to emerge
@@ -263,7 +268,10 @@
 
     Additionally, the following fields will be set:
 
-    * board - the name of the reference board, e.g. 'hatch'
+    * board - the name of the reference board, e.g. 'hatch'. The --board
+        command line flag specifies this value, and new_variant derives the
+        the name of the python module to load from this value. However, in
+        certain cases (volteer2), the python module may override this value
     * variant - the name of the variant, e.g. 'sushi'
     * bug - optional text for a bug ID, used in the git commit messages.
         Could be 'None' (as text, not the python None), or something like
@@ -346,6 +354,13 @@
         print('Unsupported board "' + board + '"')
         sys.exit(1)
 
+    # Special case: allow the module to override the name of the reference
+    # board. Almost always, you want the module name (e.g. puff.py) and the
+    # name of the reference board (e.g. puff) to match. However, for some
+    # boards (volteer2), you want to have the reference board name still
+    # be 'volteer'.
+    status.board                = getattr(module, 'board', status.board)
+
     status.base                 = module.base
     status.coreboot_base        = getattr(module, 'coreboot_base', module.base)
     status.coreboot_dir         = module.coreboot_dir
@@ -358,6 +373,8 @@
     status.fitimage_outputs_dir = getattr(module, 'fitimage_outputs_dir', None)
     status.fitimage_pkg         = getattr(module, 'fitimage_pkg', None)
     status.fitimage_cmd         = getattr(module, 'fitimage_cmd', None)
+    status.fitimage_script      = getattr(module, 'fitimage_script',
+                                          'files/add_fitimage.sh')
     status.fsp                  = getattr(module, 'fsp', None)
     status.private_yaml_dir     = getattr(module, 'private_yaml_dir', None)
     status.step_list            = module.step_list
@@ -805,7 +822,7 @@
     """
     logging.info('Running step add_fitimage')
     add_fitimage_sh = os.path.expanduser(os.path.join(
-        '/mnt/host/source/src', status.fitimage_dir, 'files/add_fitimage.sh'))
+        '/mnt/host/source/src', status.fitimage_dir, status.fitimage_script))
     rc = run_process(
         [add_fitimage_sh,
         status.variant,
diff --git a/contrib/variant/testdata/new_variant_fulltest.sh b/contrib/variant/testdata/new_variant_fulltest.sh
index c5a10b8..38b483a 100755
--- a/contrib/variant/testdata/new_variant_fulltest.sh
+++ b/contrib/variant/testdata/new_variant_fulltest.sh
@@ -17,7 +17,7 @@
 
 if [[ "$#" -lt 1 ]]; then
   echo "Usage: ${SCRIPT} reference_name"
-  echo "e.g. ${SCRIPT} hatch | puff | volteer | waddledee | waddledoo | trembyle | dalboz"
+  echo "e.g. ${SCRIPT} hatch | puff | volteer | volteer2 | waddledee | waddledoo | trembyle | dalboz"
   echo "End-to-end test to create a new variant of a reference board"
   echo "Script version ${VERSION}"
   exit 1
@@ -87,6 +87,17 @@
     FITIMAGE_FILES_DIR=/mnt/host/source/src/private-overlays/baseboard-volteer-private/sys-boot/coreboot-private-files-baseboard-volteer/files
     ;;
 
+  volteer2)
+    BASE=volteer
+    NEW=gnastygnorc
+    CONFIG_DIR=/mnt/host/source/src/project/volteer
+    OVERLAY_DIR=/mnt/host/source/src/private-overlays/overlay-volteer-private/chromeos-base/chromeos-config-bsp-volteer-private
+    EBUILD=chromeos-config-bsp-volteer-private-9999.ebuild
+    FITIMAGE=volteer2
+    FITIMAGE_OUTPUTS_DIR=/mnt/host/source/src/private-overlays/baseboard-volteer-private/sys-boot/coreboot-private-files-baseboard-volteer/asset_generation/outputs
+    FITIMAGE_FILES_DIR=/mnt/host/source/src/private-overlays/baseboard-volteer-private/sys-boot/coreboot-private-files-baseboard-volteer/files
+    ;;
+
   waddledee|waddledoo)
     BASE=dedede
     NEW=kingitchy
@@ -151,7 +162,7 @@
     pushd "${FITIMAGE_OUTPUTS_DIR}"
     rm -f "fitimage-${NEW}.bin" "fitimage-${NEW}-versions.txt"
     # Clean up the extra Volteer fitimage files, too.
-    if [[ "${REFERENCE}" == "volteer" ]] ; then
+    if [[ "${REFERENCE}" == "volteer" || "${REFERENCE}" == "volteer2" ]] ; then
       rm -f "fit-${NEW}.log"
       popd
       pushd "${FITIMAGE_FILES_DIR}/blobs"
@@ -205,7 +216,7 @@
   # Volteer requires some extra files; the FIT log is named after the
   # variant, and there are two other blobs that are customized to the
   # variant and have names to reflect it.
-  if [[ "${REFERENCE}" == "volteer" ]] ; then
+  if [[ "${REFERENCE}" == "volteer" || "${REFERENCE}" == "volteer2" ]] ; then
     cp "fit-${FITIMAGE}.log" "fit-${NEW}.log"
     popd
     pushd "${FITIMAGE_FILES_DIR}/blobs"
diff --git a/contrib/variant/variant_status.py b/contrib/variant/variant_status.py
index 3c9f68a..964eeb5 100644
--- a/contrib/variant/variant_status.py
+++ b/contrib/variant/variant_status.py
@@ -26,26 +26,29 @@
     """
     yaml_loader = yaml.SafeLoader
     yaml_tag = u'!variant_status'
-    def __init__(self, yaml_name='.new_variant.yaml'):
+    def __init__(self, yaml_name='.new_variant.yaml', soc_type='qs'):
         """Initialize the class
 
         yaml_name will be the full path and name of the yaml file in the
         current user's home directory.
 
-        Params:
-            Name of the yaml file, defaults to 'new_variant.yaml'
+        Args:
+            yaml_name: Name of the yaml file, defaults to 'new_variant.yaml'
+            soc_type: SoC Type, defaults to "qs"
         """
         self.yaml_file = os.path.expanduser(os.path.join('~', yaml_name))
         self.board = None
         self.variant = None
+        self.soctype = soc_type
         self.bug = None
         self.step = None
 
 
     def __repr__(self):
-        return '{!s}(board={!r}, variant={!r}, bug={!r}, state={!r})'.format(
-            self.__class__.__name__, self.board, self.variant, self.bug,
-            self.step)
+        return '{!s}(board={!r}, variant={!r}, soctype={!r}, bug={!r}, ' \
+            'state={!r})'.format(self.__class__.__name__, self.board,
+                                 self.variant, self.soctype, self.bug,
+                                 self.step)
 
 
     def save(self):
diff --git a/contrib/variant/volteer.py b/contrib/variant/volteer.py
index 96ec7cc..55bbafc 100644
--- a/contrib/variant/volteer.py
+++ b/contrib/variant/volteer.py
@@ -52,6 +52,9 @@
 # Explanation of gen_fit_image command
 fitimage_cmd = './gen_fit_image.sh %s <path_to_fit_kit> -b'
 
+# Script to add fitimage sources
+fitimage_script = 'files/add_fitimage_es2.sh'
+
 # List of packages to cros_workon
 workon_pkgs = [
     'coreboot', 'libpayload', 'vboot_reference', 'depthcharge', fsp,
diff --git a/contrib/variant/volteer2.py b/contrib/variant/volteer2.py
new file mode 100644
index 0000000..3ace919
--- /dev/null
+++ b/contrib/variant/volteer2.py
@@ -0,0 +1,101 @@
+# -*- coding: utf-8 -*-
+"""Define steps, package names, and directories for creating a Volteer2 variant
+
+Volteer2 uses QS revision silicon, while Volteer uses ES2 revision. This
+matters when we generate a fitimage, but everywhere else, we just want to
+use the same stuff as Volteer.
+
+Copyright 2020 The Chromium OS Authors. All rights reserved.
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+"""
+
+from __future__ import print_function
+import step_names
+
+# Name of the baseboard
+base = 'volteer'
+
+# Name of the reference board
+board = 'volteer'
+
+# List of steps (named in step_names.py) to run in sequence to create
+# the new variant of the baseboard
+step_list = [
+    step_names.PROJECT_CONFIG,
+    step_names.FW_BUILD_CONFIG,
+    step_names.CB_VARIANT,
+    step_names.CB_CONFIG,
+    step_names.ADD_FIT,
+    step_names.GEN_FIT,
+    step_names.COMMIT_FIT,
+    step_names.EC_IMAGE,
+    step_names.EMERGE,
+    step_names.PUSH,
+    step_names.UPLOAD,
+    step_names.FIND,
+    step_names.CALC_CQ_DEPEND,
+    step_names.ADD_CQ_DEPEND,
+    step_names.RE_UPLOAD,
+    step_names.CLEAN_UP]
+
+# Base directory for coreboot
+coreboot_dir = 'third_party/coreboot'
+
+# Package name for FSP
+fsp = 'intel-tglfsp'
+
+# Package name for the fitimage
+fitimage_pkg = 'coreboot-private-files-baseboard-volteer'
+
+# Directory for fitimage; append '~/trunk/src/'' in chroot, '~/chromiumos/src'
+# outside
+fitimage_dir = 'private-overlays/baseboard-volteer-private/sys-boot/'\
+    'coreboot-private-files-baseboard-volteer'
+
+# Directory under fitimage_dir where gen_fit_image.sh leaves its outputs
+fitimage_outputs_dir = 'asset_generation/outputs'
+
+# Explanation of gen_fit_image command
+fitimage_cmd = './gen_fit_image.sh %s <path_to_fit_kit> -b'
+
+# Script to add fitimage sources
+fitimage_script = 'files/add_fitimage_qs.sh'
+
+# List of packages to cros_workon
+workon_pkgs = [
+    'coreboot', 'libpayload', 'vboot_reference', 'depthcharge', fsp,
+    fitimage_pkg, 'chromeos-ec', 'chromeos-config-bsp-volteer-private']
+
+# The emerge command
+emerge_cmd = 'emerge-volteer'
+
+# List of packages to emerge
+emerge_pkgs = [
+    'coreboot', 'libpayload', 'vboot_reference', 'depthcharge', fsp,
+    fitimage_pkg, 'chromeos-ec', 'chromeos-config-bsp-volteer-private',
+    'chromeos-config', 'chromeos-config-bsp', 'coreboot-private-files',
+    'chromeos-bootimage']
+
+# List of packages to cros_workon to build the project config
+config_workon_pkgs = ['chromeos-config-bsp-volteer-private']
+
+# List of packages to emerge to build the project config
+config_emerge_pkgs = ['chromeos-config-bsp-volteer-private']
+
+# List of commits that will be uploaded with `repo upload`
+repo_upload_list = [
+    step_names.CB_CONFIG, step_names.COMMIT_FIT,
+    step_names.EC_IMAGE, step_names.FW_BUILD_CONFIG]
+
+# List of commits that will be pushed to review.coreboot.org
+coreboot_push_list = [step_names.CB_VARIANT]
+
+# List of steps that depend on other steps, and what those are.
+# This list gets used for setting up Cq-Depend on the uploaded CLs.
+depends = {
+    step_names.CB_CONFIG: [step_names.FIND],
+    step_names.FW_BUILD_CONFIG: [
+        step_names.FIND, step_names.CB_CONFIG,
+        step_names.COMMIT_FIT, step_names.EC_IMAGE]
+}