new_variant: support private repos

Some reference designs do not yet have all of their code in public
repos, but we still need to be able to create new variant boards.
Add variables to reference board data for where coreboot source and
coreboot config are located. Use these variables to launch scripts
in the correct directory, or to point to those directories with
an environment variables that the launched script will use.

BUG=b:147483696
TEST=`./new_variant.py --board=hatch --variant=sushi`
Verify that the commit for config.sushi is in
third_party/chromiumos-overlay/sys-boot/coreboot/files/configs

`./new_variant.py --board=volteer --variant=ripto`
Verify that the commit for config.ripto is in
private-overlays/chipset-tgl-private/sys-boot/coreboot/files/configs

Change-Id: Ide00562ca7308f29c1732afbd234fc504b933ecd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2025291
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Jacob Rasmussen <jacobraz@google.com>
diff --git a/contrib/variant/create_coreboot_config.sh b/contrib/variant/create_coreboot_config.sh
index 9846fa2..d8ec54a 100755
--- a/contrib/variant/create_coreboot_config.sh
+++ b/contrib/variant/create_coreboot_config.sh
@@ -31,7 +31,6 @@
 # This is the name of the variant that is being cloned.
 VARIANT="${3,,}"
 # We need all uppercase version, too, so ${var^^}
-BASE_UPPER="${BASE^^}"
 REFERENCE_UPPER="${REFERENCE^^}"
 VARIANT_UPPER="${VARIANT^^}"
 
@@ -39,7 +38,9 @@
 BUG=${4:-None}
 
 # Work in third_party/chromiumos-overlay/sys-boot/coreboot/files/configs
-cd ~/trunk/src/third_party/chromiumos-overlay/sys-boot/coreboot/files/configs || exit 1
+# unless CB_CONFIG_DIR is set, in which case work in that dir
+DEFAULT_CB_CONFIG_DIR="third_party/chromiumos-overlay/sys-boot/coreboot/files/configs"
+cd "${HOME}/trunk/src/${CB_CONFIG_DIR:-${DEFAULT_CB_CONFIG_DIR}}" || exit 1
 
 # Make sure the variant doesn't already exist.
 if [[ -e "config.${VARIANT}" ]]; then
diff --git a/contrib/variant/hatch.py b/contrib/variant/hatch.py
index feb1228..1d9bb36 100644
--- a/contrib/variant/hatch.py
+++ b/contrib/variant/hatch.py
@@ -31,6 +31,12 @@
     step_names.CQ_DEPEND,
     step_names.CLEAN_UP]
 
+# Base directory for coreboot
+coreboot_dir = 'third_party/coreboot'
+
+# Base directory for coreboot configs (None=use default)
+cb_config_dir = None
+
 # Package name for FSP
 fsp = 'intel-cmlfsp'
 
diff --git a/contrib/variant/new_variant.py b/contrib/variant/new_variant.py
index 15bb4a4..084d2df 100755
--- a/contrib/variant/new_variant.py
+++ b/contrib/variant/new_variant.py
@@ -212,6 +212,11 @@
     * base - the name of the base board, such as Hatch, Volteer, or Zork.
         This can be different from the reference board, e.g. the Trembyle
         reference board in the Zork project.
+    * coreboot_dir - base directory for coreboot, usually third_party/coreboot
+        but could differ for processors that use a private repo
+    * cb_config_dir - base directory for coreboot configs, usually
+        third_party/chromiumos-overlay/sys-boot/coreboot/files/configs but
+        could differ for processors that use a private repo
     * step_list - list of steps (named in step_names.py) to run in sequence
         to create the new variant of the reference board
     * fsp - package name for FSP. This may be None, depending on the
@@ -277,6 +282,8 @@
         # pylint: disable=bad-whitespace
         # Allow extra spaces around = so that we can line things up nicely
         status.base                 = module.base
+        status.coreboot_dir         = module.coreboot_dir
+        status.cb_config_dir        = module.cb_config_dir
         status.emerge_cmd           = module.emerge_cmd
         status.emerge_pkgs          = module.emerge_pkgs
         status.fitimage_dir         = module.fitimage_dir
@@ -428,7 +435,8 @@
     """
     logging.info('Running step create_coreboot_variant')
     create_coreboot_variant_sh = os.path.join(
-        os.path.expanduser('~/trunk/src/third_party/coreboot'),
+        os.path.expanduser('~/trunk/src/'),
+        status.coreboot_dir,
         'util/mainboard/google/create_coreboot_variant.sh')
     return bool(run_process(
         [create_coreboot_variant_sh,
@@ -450,6 +458,9 @@
         True if the script and test build succeeded, False if something failed
     """
     logging.info('Running step create_coreboot_config')
+    environ = os.environ.copy()
+    if status.cb_config_dir is not None:
+        environ['CB_CONFIG_DIR'] = status.cb_config_dir
     create_coreboot_config_sh = os.path.expanduser(
         '~/trunk/src/platform/dev/contrib/variant/create_coreboot_config.sh')
     return bool(run_process(
@@ -457,7 +468,7 @@
         status.base,
         status.board,
         status.variant,
-        status.bug]))
+        status.bug], env=environ))
 
 
 def copy_coreboot_config(status):
diff --git a/contrib/variant/trembyle.py b/contrib/variant/trembyle.py
index 0a81d02..31fc24f 100644
--- a/contrib/variant/trembyle.py
+++ b/contrib/variant/trembyle.py
@@ -29,6 +29,12 @@
     step_names.CQ_DEPEND,
     step_names.CLEAN_UP]
 
+# Base directory for coreboot
+coreboot_dir = 'third_party/coreboot'
+
+# Base directory for coreboot configs (None=use default)
+cb_config_dir = None
+
 # Package name for FSP
 fsp = None
 
diff --git a/contrib/variant/volteer.py b/contrib/variant/volteer.py
index 76217fe..29fa728 100644
--- a/contrib/variant/volteer.py
+++ b/contrib/variant/volteer.py
@@ -16,8 +16,7 @@
 # the new variant of the baseboard
 step_list = [
     step_names.CB_VARIANT,
-    # TODO(b/147483696)
-    # step_names.CB_CONFIG,
+    step_names.CB_CONFIG,
     step_names.ADD_FIT,
     step_names.GEN_FIT,
     step_names.COMMIT_FIT,
@@ -32,6 +31,12 @@
     step_names.CQ_DEPEND,
     step_names.CLEAN_UP]
 
+# Base directory for coreboot
+coreboot_dir = 'third_party/coreboot-intel-private/jsl-tgl'
+
+# Base directory for coreboot configs (None=use default)
+cb_config_dir = 'private-overlays/chipset-tgl-private/sys-boot/coreboot/files/configs'
+
 # Package name for FSP
 fsp = 'intel-tglfsp'