new_variant: update for volteer fitimage changes

- Add new variables to allow the fitimage binary and versions files
to be in different directories, but the default is that they're in
the same directory.
- Add new files that volteer's commit_fitimage.sh expects to find

BUG=b:179939074
TEST=run new_variant_fulltest.sh for each supported reference board.
Pay special attention to volteer and volteer2.

Change-Id: I0999871b97cccac8cd7506aa1dfe3852ba86cbc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2806830
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Nick Vaccaro <nvaccaro@google.com>
Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
diff --git a/contrib/variant/ambassador.py b/contrib/variant/ambassador.py
index 04e376d..a532aa0 100644
--- a/contrib/variant/ambassador.py
+++ b/contrib/variant/ambassador.py
@@ -53,8 +53,8 @@
 # Ambassador firmware is comingled with Puff's, so fitimage goes there.
 fitimage_dir = 'private-overlays/baseboard-puff-private/sys-boot/coreboot-private-files-puff'
 
-# Directory under fitimage_dir where gen_fit_image.sh leaves its outputs
-fitimage_outputs_dir = 'asset_generation/outputs'
+# Directory under fitimage_dir where the fitimage binary will be
+fitimage_bin_dir = 'asset_generation/outputs'
 
 # Explanation of gen_fit_image command
 fitimage_cmd = './gen_fit_image.sh %s <path_to_fit_kit> -b'
diff --git a/contrib/variant/hatch.py b/contrib/variant/hatch.py
index 80a6203..9288f05 100644
--- a/contrib/variant/hatch.py
+++ b/contrib/variant/hatch.py
@@ -47,8 +47,8 @@
 fitimage_dir = ('private-overlays/baseboard-hatch-private/'
     'sys-boot/coreboot-private-files-hatch')
 
-# Directory under fitimage_dir where gen_fit_image.sh leaves its outputs
-fitimage_outputs_dir = 'asset_generation/outputs'
+# Directory under fitimage_dir where the fitimage binary will be
+fitimage_bin_dir = 'asset_generation/outputs'
 
 # Explanation of gen_fit_image command
 fitimage_cmd = './gen_fit_image.sh %s <path_to_fit_kit> -b'
diff --git a/contrib/variant/new_variant.py b/contrib/variant/new_variant.py
index bc1db6c..4a9426a 100755
--- a/contrib/variant/new_variant.py
+++ b/contrib/variant/new_variant.py
@@ -239,10 +239,15 @@
     * fsp - package name for FSP. This may be None, depending on the
         processor on the reference board
     * fitimage_pkg - package name for the fitimage
-    * fitimage_dir - directory for fitimage; prepend '/mnt/host/source/src/'
-        in chroot, prepend '~/chromiumos/src' outside the chroot
-    * fitimage_outputs_dir - directory under fitimage_dir where gen_fit_image.sh
-        leaves its outputs
+    * fitimage_dir - base directory for fitimage; prepend
+        '/mnt/host/source/src/' in chroot, prepend '~/chromiumos/src' outside
+        the chroot
+    * fitimage_bin_dir - directory under fitimage_dir where the fitimage
+        binary will be
+    * fitimage_versions_dir - directory under fitimage_dir where the fitimage
+        versions file will be, defaults to the value of fitimage_bin_dir
+    * fitimage_bin - name of the fitimage binary to format with the variant
+        name, default of `fitimage-%s.bin`
     * 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
@@ -369,8 +374,12 @@
     status.cb_config_dir        = getattr(module, 'cb_config_dir', None)
     status.emerge_cmd           = module.emerge_cmd
     status.emerge_pkgs          = module.emerge_pkgs
+    status.fitimage_bin         = getattr(module, 'fitimage_bin',
+                                          'fitimage-%s.bin')
     status.fitimage_dir         = getattr(module, 'fitimage_dir', None)
-    status.fitimage_outputs_dir = getattr(module, 'fitimage_outputs_dir', None)
+    status.fitimage_bin_dir     = getattr(module, 'fitimage_bin_dir', None)
+    status.fitimage_versions_dir= getattr(module, 'fitimage_versions_dir',
+                                          status.fitimage_bin_dir)
     status.fitimage_pkg         = getattr(module, 'fitimage_pkg', None)
     status.fitimage_cmd         = getattr(module, 'fitimage_cmd', None)
     status.fitimage_script      = getattr(module, 'fitimage_script',
@@ -893,17 +902,21 @@
         List of files that *DO NOT* exist and need to be created, [] if
         all files are present.
     """
-    outputs_dir = os.path.join('/mnt/host/source/src', status.fitimage_dir,
-        status.fitimage_outputs_dir)
-    logging.debug('outputs_dir = "%s"', outputs_dir)
+    fitimage_bin_dir = os.path.join('/mnt/host/source/src',
+        status.fitimage_dir, status.fitimage_bin_dir)
+    logging.debug('fitimage_bin_dir = "%s"', fitimage_bin_dir)
+    fitimage_versions_dir = os.path.join('/mnt/host/source/src',
+        status.fitimage_dir, status.fitimage_versions_dir)
+    logging.debug('fitimage_versions_dir = "%s"', fitimage_versions_dir)
 
     files_not_found = []
-    fitimage_bin = 'fitimage-' + status.variant + '.bin'
-    if not os.path.isfile(os.path.join(outputs_dir, fitimage_bin)):
+    fitimage_bin = status.fitimage_bin % status.variant
+    if not os.path.isfile(os.path.join(fitimage_bin_dir, fitimage_bin)):
         files_not_found.append(fitimage_bin)
 
     fitimage_versions = 'fitimage-' + status.variant + '-versions.txt'
-    if not os.path.isfile(os.path.join(outputs_dir, fitimage_versions)):
+    if not os.path.isfile(os.path.join(fitimage_versions_dir,
+        fitimage_versions)):
         files_not_found.append(fitimage_versions)
 
     return files_not_found
diff --git a/contrib/variant/puff.py b/contrib/variant/puff.py
index 8069266..b378c57 100644
--- a/contrib/variant/puff.py
+++ b/contrib/variant/puff.py
@@ -49,8 +49,8 @@
 # Directory for fitimage; append '~/trunk/src/'' in chroot, '~/chromiumos/src' outside
 fitimage_dir = 'private-overlays/baseboard-puff-private/sys-boot/coreboot-private-files-puff'
 
-# Directory under fitimage_dir where gen_fit_image.sh leaves its outputs
-fitimage_outputs_dir = 'asset_generation/outputs'
+# Directory under fitimage_dir where the fitimage binary will be
+fitimage_bin_dir = 'asset_generation/outputs'
 
 # Explanation of gen_fit_image command
 fitimage_cmd = './gen_fit_image.sh %s <path_to_fit_kit> -b'
diff --git a/contrib/variant/testdata/new_variant_fulltest.sh b/contrib/variant/testdata/new_variant_fulltest.sh
index 7a0560a..9b4416b 100755
--- a/contrib/variant/testdata/new_variant_fulltest.sh
+++ b/contrib/variant/testdata/new_variant_fulltest.sh
@@ -83,7 +83,7 @@
     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=volteer
-    FITIMAGE_OUTPUTS_DIR=/mnt/host/source/src/private-overlays/baseboard-volteer-private/sys-boot/coreboot-private-files-baseboard-volteer/asset_generation/outputs
+    FITIMAGE_OUTPUTS_DIR=/mnt/host/source/src/private-overlays/baseboard-volteer-private/sys-boot/coreboot-private-files-baseboard-volteer/files/blobs
     FITIMAGE_FILES_DIR=/mnt/host/source/src/private-overlays/baseboard-volteer-private/sys-boot/coreboot-private-files-baseboard-volteer/files
     ;;
 
@@ -94,7 +94,7 @@
     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_OUTPUTS_DIR=/mnt/host/source/src/private-overlays/baseboard-volteer-private/sys-boot/coreboot-private-files-baseboard-volteer/files/blobs
     FITIMAGE_FILES_DIR=/mnt/host/source/src/private-overlays/baseboard-volteer-private/sys-boot/coreboot-private-files-baseboard-volteer/files
     ;;
 
@@ -167,6 +167,15 @@
       popd
       pushd "${FITIMAGE_FILES_DIR}/blobs"
       rm -f "csme-${NEW}.bin" "descriptor-${NEW}.bin" "me_rw-${NEW}.bin"
+      popd
+      pushd "${FITIMAGE_FILES_DIR}/versions"
+      rm -f "fitimage-${NEW}-versions.txt"
+      popd
+      pushd "${FITIMAGE_FILES_DIR}/logs"
+      rm -f "fit-${NEW}-ro.log" "fit-${NEW}-rw.log"
+      popd
+      pushd "${FITIMAGE_FILES_DIR}/maps"
+      rm "fitimage-${NEW}.map"
     fi
     popd
   fi
@@ -210,21 +219,32 @@
 # the new variant's name so that we don't have to generate the fitimage outside
 # the chroot.
 if [[ ! -z ${FITIMAGE_OUTPUTS_DIR+x} ]] ; then
-  pushd "${FITIMAGE_OUTPUTS_DIR}"
-  cp "${FITIMAGE_FILES_DIR}/fitimage-${FITIMAGE}.bin" "fitimage-${NEW}.bin"
-  cp "${FITIMAGE_FILES_DIR}/fitimage-${FITIMAGE}-versions.txt" "fitimage-${NEW}-versions.txt"
   # Volteer requires some extra files; the FIT log is named after the
   # variant, and there are other blobs that are customized to the
-  # variant and have names to reflect it.
+  # variant and have names to reflect it. Volteer also does not use
+  # fitimage-${VARIANT}.bin.
   if [[ "${REFERENCE}" == "volteer" || "${REFERENCE}" == "volteer2" ]] ; then
-    cp "fit-${FITIMAGE}.log" "fit-${NEW}.log"
-    popd
     pushd "${FITIMAGE_FILES_DIR}/blobs"
     cp "csme-${FITIMAGE}.bin" "csme-${NEW}.bin"
     cp "descriptor-${FITIMAGE}.bin" "descriptor-${NEW}.bin"
     # me_rw-volteer.bin does not exist, and since the fitmage isn't being used
     # on an actual board, it's OK to just use volteer2 for either reference.
     cp "me_rw-volteer2.bin" "me_rw-${NEW}.bin"
+    popd
+    pushd "${FITIMAGE_FILES_DIR}/versions"
+    cp "fitimage-${REFERENCE}-versions.txt" "fitimage-${NEW}-versions.txt"
+    popd
+    pushd "${FITIMAGE_FILES_DIR}/logs"
+    cp "fit-${REFERENCE}-ro.log" "fit-${NEW}-ro.log"
+    cp "fit-${REFERENCE}-rw.log" "fit-${NEW}-rw.log"
+    popd
+    pushd "${FITIMAGE_FILES_DIR}/maps"
+    cp "fitimage-${REFERENCE}.map" "fitimage-${NEW}.map"
+  else
+    pushd "${FITIMAGE_OUTPUTS_DIR}"
+    # All boards that have fitimages and are not volteer use a fitimage binary.
+    cp "${FITIMAGE_FILES_DIR}/fitimage-${FITIMAGE}.bin" "fitimage-${NEW}.bin"
+    cp "${FITIMAGE_FILES_DIR}/fitimage-${FITIMAGE}-versions.txt" "fitimage-${NEW}-versions.txt"
   fi
   popd
 fi
diff --git a/contrib/variant/variant_status.py b/contrib/variant/variant_status.py
index 964eeb5..052c190 100644
--- a/contrib/variant/variant_status.py
+++ b/contrib/variant/variant_status.py
@@ -26,7 +26,7 @@
     """
     yaml_loader = yaml.SafeLoader
     yaml_tag = u'!variant_status'
-    def __init__(self, yaml_name='.new_variant.yaml', soc_type='qs'):
+    def __init__(self, yaml_name='.new_variant.yaml'):
         """Initialize the class
 
         yaml_name will be the full path and name of the yaml file in the
@@ -34,21 +34,18 @@
 
         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}, soctype={!r}, bug={!r}, ' \
-            'state={!r})'.format(self.__class__.__name__, self.board,
-                                 self.variant, self.soctype, self.bug,
-                                 self.step)
+        return '{!s}(board={!r}, variant={!r}, bug={!r}, state={!r})'.format(
+            self.__class__.__name__, self.board, self.variant, self.bug,
+            self.step)
 
 
     def save(self):
diff --git a/contrib/variant/volteer.py b/contrib/variant/volteer.py
index 55bbafc..d8dbe26 100644
--- a/contrib/variant/volteer.py
+++ b/contrib/variant/volteer.py
@@ -46,11 +46,17 @@
 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'
+# Volteer fitimages use csme-${VARIANT}.bin, not fitimage-${VARIANT}.bin
+fitimage_bin = 'csme-%s.bin'
+
+# Directory under fitimage_dir where the fitimage binary will be
+fitimage_bin_dir = 'files/blobs'
+
+# Directory under fitimage_dir where the fitimage versions file will be
+fitimage_versions_dir = 'files/versions'
 
 # Explanation of gen_fit_image command
-fitimage_cmd = './gen_fit_image.sh %s <path_to_fit_kit> -b'
+fitimage_cmd = './gen_fit_image.sh %s <path_to_fit_kit> es2 -b'
 
 # Script to add fitimage sources
 fitimage_script = 'files/add_fitimage_es2.sh'
diff --git a/contrib/variant/volteer2.py b/contrib/variant/volteer2.py
index 3ace919..798e2a7 100644
--- a/contrib/variant/volteer2.py
+++ b/contrib/variant/volteer2.py
@@ -53,11 +53,14 @@
 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'
+# Volteer fitimages use csme-${VARIANT}.bin, not fitimage-${VARIANT}.bin
+fitimage_bin = 'csme-%s.bin'
 
-# Explanation of gen_fit_image command
-fitimage_cmd = './gen_fit_image.sh %s <path_to_fit_kit> -b'
+# Directory under fitimage_dir where the fitimage binary will be
+fitimage_bin_dir = 'files/blobs'
+
+# Directory under fitimage_dir where the fitimage versions file will be
+fitimage_versions_dir = 'files/versions'
 
 # Script to add fitimage sources
 fitimage_script = 'files/add_fitimage_qs.sh'
diff --git a/contrib/variant/waddledee.py b/contrib/variant/waddledee.py
index 557d801..2d64bef 100644
--- a/contrib/variant/waddledee.py
+++ b/contrib/variant/waddledee.py
@@ -46,8 +46,8 @@
 fitimage_dir = 'private-overlays/baseboard-dedede-private/sys-boot/'\
     'coreboot-private-files-baseboard-dedede'
 
-# Directory under fitimage_dir where gen_fit_image.sh leaves its outputs
-fitimage_outputs_dir = 'files/blobs'
+# Directory under fitimage_dir where the fitimage binary will be
+fitimage_bin_dir = 'files/blobs'
 
 # Explanation of gen_fit_image command
 fitimage_cmd = './gen_fit_image.sh %s <path_to_fit_kit> -b'