new_variant: add support for reference board name
A baseboard can have a reference board whose name differs from the
project name, e.g. Zork has the Trembyle reference board.
All of the cros_workon and emerge commands, plus the usage in the
commit messages are 'zork' but the coreboot config file to use is
config.trembyle, not config.zork. Add the reference board as a
variable in the modules we load for supported boards, and as a
parameter to create_coreboot_config.sh.
Add a new step for copying the coreboot config from third_party
to overlays, which is required only for Zork at this time.
Add -j to create_initial_ec_image.sh so that the test build
is a lot faster.
BUG=b:148161697
TEST=Call create_coreboot_config.sh directly and verify that
it creates the correct config files.
$ create_coreboot_config.sh zork trembyle frobozz
$ diff config.trembyle config.frobozz
5c5
< CONFIG_BOARD_GOOGLE_TREMBYLE=y
---
> CONFIG_BOARD_GOOGLE_FROBOZZ=y
$ create_coreboot_config.sh hatch hatch sushi
$ diff config.hatch config.sushi
2c2
< CONFIG_BOARD_GOOGLE_HATCH=y
---
> CONFIG_BOARD_GOOGLE_SUSHI=y
19c19
< CONFIG_IFD_BIN_PATH="3rdparty/blobs/baseboard/hatch/descriptor-hatch.bin"
---
> CONFIG_IFD_BIN_PATH="3rdparty/blobs/baseboard/hatch/descriptor-sushi.bin"
39c39
< CONFIG_ME_BIN_PATH="3rdparty/blobs/baseboard/hatch/me-hatch.bin"
---
> CONFIG_ME_BIN_PATH="3rdparty/blobs/baseboard/hatch/me-sushi.bin"
Run the new_variant program to test creating a variant of hatch and a
variant of zork:
$ new_variant.py --board=hatch --variant=sushi
Verify that the CL in
third_party/chromiumos-overlay/sys-boot/coreboot/files/configs
is correct for the sushi variant of hatch
$ new_variant.py --board=trembyle --variant=frobozz
It will fail with an error because coreboot support isn't present yet.
Edit ~/.new_variant.yaml and change "step" to "cb_config".
Run new_variant.py --continue
Verify that the CL in
third_party/chromiumos-overlay/sys-boot/coreboot/files/configs
is correct for the frobozz variant of trembyle, but the commit messages
refer to zork in the title and the TEST= line, and the reference board
in the text.
Change-Id: I65a96b31dd52b3e5b9ddd240f53c215b19d2b84e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2016085
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Martin Roth <martinroth@google.com>
diff --git a/contrib/variant/copy_coreboot_config.sh b/contrib/variant/copy_coreboot_config.sh
new file mode 100755
index 0000000..30e9287
--- /dev/null
+++ b/contrib/variant/copy_coreboot_config.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+# 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.
+
+VERSION="1.0.0"
+SCRIPT=$(basename -- "${0}")
+
+export LC_ALL=C
+
+if [[ ! -e /etc/cros_chroot_version ]]; then
+ echo "This script must be run inside the chroot."
+ exit 1
+fi
+
+if [[ "$#" -lt 3 ]]; then
+ echo "Usage: ${SCRIPT} base_name reference_name variant_name [bug_number]"
+ echo "e.g. ${SCRIPT} hatch hatch kohaku b:140261109"
+ echo "e.g. ${SCRIPT} zork trembyle frobozz b:148161697"
+ echo "Copies the new coreboot configuation for the variant from"
+ echo "third_party/chromiumos-overlay to overlays"
+ exit 1
+fi
+
+# This is the name of the base board.
+# ${var,,} converts to all lowercase.
+BASE="${1,,}"
+# This is the name of the reference board that we're using to make the variant.
+# ${var,,} converts to all lowercase.
+REFERENCE="${2,,}"
+# This is the name of the variant that is being cloned.
+VARIANT="${3,,}"
+
+# Assign BUG= text, or "None" if that parameter wasn't specified.
+BUG=${4:-None}
+
+# For Zork, the new config file that is in
+# third_party/chromiumos-overlay/sys-boot/coreboot/files/configs
+# must also be copied to
+# src/overlays/overlay-zork/sys-boot/coreboot-zork/files/configs
+# and committed there as well.
+
+# Work in src/overlays/overlay-zork/sys-boot/coreboot-zork/files/configs
+cd "${HOME}/trunk/src/overlays/overlay-${BASE}/sys-boot/coreboot-${BASE}/files/configs" || exit 1
+
+# Start a branch. Use YMD timestamp to avoid collisions.
+DATE=$(date +%Y%m%d)
+repo start "create_${VARIANT}_${DATE}" . || exit 1
+# add_variant_to_yaml.sh will start a repo of the same name in this dir,
+# but it will just harmlessly exit, so this is OK.
+
+cp "${HOME}/trunk/src/third_party/chromiumos-overlay/sys-boot/coreboot/files/configs/config.${VARIANT}" .
+git add "config.${VARIANT}"
+git commit -sm "${BASE}: Add ${VARIANT} coreboot configuration
+
+Create a new coreboot configuration for the ${VARIANT} variant
+of the ${REFERENCE} reference board. The new configuration file is
+a copy of the reference board, but the name of the baseboard is
+replaced by the name of the variant where applicable.
+
+(Auto-Generated by ${SCRIPT} version ${VERSION}).
+
+BUG=${BUG}
+BRANCH=none
+TEST=FW_NAME=${VARIANT} emerge-${BASE} coreboot chromeos-bootimage
+Ensure that image-${VARIANT}.*.bin are created"
+
diff --git a/contrib/variant/create_coreboot_config.sh b/contrib/variant/create_coreboot_config.sh
index 9d17366..9846fa2 100755
--- a/contrib/variant/create_coreboot_config.sh
+++ b/contrib/variant/create_coreboot_config.sh
@@ -3,7 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-VERSION="1.0.2"
+VERSION="2.0.0"
SCRIPT=$(basename -- "${0}")
export LC_ALL=C
@@ -13,25 +13,30 @@
exit 1
fi
-if [[ "$#" -lt 2 ]]; then
- echo "Usage: ${SCRIPT} base_name variant_name [bug_number]"
- echo "e.g. ${SCRIPT} hatch kohaku b:140261109"
+if [[ "$#" -lt 3 ]]; then
+ echo "Usage: ${SCRIPT} base_name reference_name variant_name [bug_number]"
+ echo "e.g. ${SCRIPT} hatch hatch kohaku b:140261109"
+ echo "e.g. ${SCRIPT} zork trembyle frobozz b:148161697"
echo "Adds a new coreboot configuation for the variant by copying the"
echo "baseboard config file and replaces the names in the config file."
exit 1
fi
-# This is the name of the base board that we're using to make the variant.
+# This is the name of the base board.
# ${var,,} converts to all lowercase.
BASE="${1,,}"
+# This is the name of the reference board that we're using to make the variant.
+# ${var,,} converts to all lowercase.
+REFERENCE="${2,,}"
# This is the name of the variant that is being cloned.
-VARIANT="${2,,}"
+VARIANT="${3,,}"
# We need all uppercase version, too, so ${var^^}
BASE_UPPER="${BASE^^}"
+REFERENCE_UPPER="${REFERENCE^^}"
VARIANT_UPPER="${VARIANT^^}"
# Assign BUG= text, or "None" if that parameter wasn't specified.
-BUG=${3:-None}
+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
@@ -47,13 +52,14 @@
DATE=$(date +%Y%m%d)
repo start "create_${VARIANT}_${DATE}" . || exit 1
-# There are two usages of the baseboard name that we want to change, using
-# the Hatch baseboard and the Kohaku variant in this example.
+# There are multiple usages of the reference board name that we want to change,
+# using the Hatch reference board and the Kohaku variant in this example.
# CONFIG_BOARD_GOOGLE_HATCH=y
# ---
# CONFIG_BOARD_GOOGLE_KOHAKU=y
-# That one is easy; replace all-uppercase of the baseboard with all-uppercase
-# of the variant. The second one is
+# That one is easy; replace all-uppercase of the reference board with
+# all-uppercase of the variant.
+# Some baseboards have additional usages, such as
# CONFIG_IFD_BIN_PATH="3rdparty/blobs/baseboard/hatch/descriptor-hatch.bin"
# ---
# CONFIG_IFD_BIN_PATH="3rdparty/blobs/baseboard/hatch/descriptor-kohaku.bin"
@@ -68,20 +74,20 @@
# CONFIG_ME_BIN_PATH="3rdparty/blobs/baseboard/hatch/me-hatch.bin"
# ---
# CONFIG_ME_BIN_PATH="3rdparty/blobs/baseboard/hatch/me-kohaku.bin"
-sed -e "s/${BASE_UPPER}/${VARIANT_UPPER}/" \
+sed -e "s/${REFERENCE_UPPER}/${VARIANT_UPPER}/" \
-e "s/descriptor-${BASE}\.bin/descriptor-${VARIANT}.bin/" \
-e "s/descriptor\.bin/descriptor-${VARIANT}.bin/" \
-e "s/me-${BASE}\.bin/me-${VARIANT}.bin/" \
- "config.${BASE}" > "config.${VARIANT}"
+ "config.${REFERENCE}" > "config.${VARIANT}"
git add "config.${VARIANT}"
# Now commit the files.
git commit -sm "${BASE}: Add ${VARIANT} coreboot configuration
Create a new coreboot configuration for the ${VARIANT} variant
-of the ${BASE} baseboard. The new configuration file is a copy of
-the baseboard, but the name of the baseboard is replaced by the
-name of the variant where applicable.
+of the ${REFERENCE} reference board. The new configuration file is
+a copy of the reference board, but the name of the baseboard is
+replaced by the name of the variant where applicable.
(Auto-Generated by ${SCRIPT} version ${VERSION}).
diff --git a/contrib/variant/create_initial_ec_image.sh b/contrib/variant/create_initial_ec_image.sh
index ecb5005..bdca524 100755
--- a/contrib/variant/create_initial_ec_image.sh
+++ b/contrib/variant/create_initial_ec_image.sh
@@ -55,7 +55,7 @@
# Build the code; exit if it fails.
pushd .. || exit 1
-make BOARD="${VARIANT}" || exit 1
+make -j BOARD="${VARIANT}" || exit 1
popd || exit 1
git add "${VARIANT}"/*
diff --git a/contrib/variant/hatch.py b/contrib/variant/hatch.py
index 3c2dd1e..6902944 100644
--- a/contrib/variant/hatch.py
+++ b/contrib/variant/hatch.py
@@ -9,6 +9,9 @@
from __future__ import print_function
import step_names
+# Name of the baseboard
+base = 'hatch'
+
# List of steps (named in step_names.py) to run in sequence to create
# the new variant of the baseboard
step_list = [
diff --git a/contrib/variant/new_variant.py b/contrib/variant/new_variant.py
index 2945dac..8b63c36 100755
--- a/contrib/variant/new_variant.py
+++ b/contrib/variant/new_variant.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-"""Create a new variant of an existing base board
+"""Create a new variant of an existing reference board
This program will call all of the scripts that create the various pieces
of a new variant. For example to create a new variant of the hatch base
@@ -26,8 +26,8 @@
* private-overlays/overlay-hatch-private
* overlays
-The program has support for multiple baseboards, so the repos, directories,
-and scripts above can change depending on what the baseboard is.
+The program has support for multiple reference boards, so the repos, directories,
+and scripts above can change depending on what the reference board is.
Copyright 2020 The Chromium OS Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
@@ -48,11 +48,11 @@
def main():
- """Create a new variant of an existing base board
+ """Create a new variant of an existing reference board
This program automates the creation of a new variant of an existing
- base board by calling various scripts that copy the base board, modify
- files for the new variant, stage commits, and upload to gerrit.
+ reference board by calling various scripts that copy the reference board,
+ modify files for the new variant, stage commits, and upload to gerrit.
Note that one of the following is required:
* --continue
@@ -89,7 +89,7 @@
to check if there is an illegal combination of arguments.
Returns a list of:
- board Name of the base board
+ board Name of the reference board
variant Name of the variant being created
bug Text for bug number, if any ('None' otherwise)
continue_flag Flag if --continue was specified
@@ -97,7 +97,7 @@
parser = argparse.ArgumentParser(
description=main.__doc__,
formatter_class=argparse.RawTextHelpFormatter)
- parser.add_argument('--board', type=str, help='Name of the base board')
+ parser.add_argument('--board', type=str, help='Name of the reference board')
parser.add_argument(
'--variant', type=str, help='Name of the new variant to create')
parser.add_argument(
@@ -141,7 +141,7 @@
argument, so we have to use this function to do the checking.
Params:
- board Name of the base board
+ board Name of the reference board
variant Name of the variant being created
bug Text for bug number, if any ('None' otherwise)
continue_flag Flag if --continue was specified
@@ -202,17 +202,20 @@
the board, variant, and (optional) bug details.
To decouple the list of boards supported from this main program, we
- try to import a module with the same name as the baseboard,
+ try to import a module with the same name as the reference board,
so --board=hatch means that we import hatch.py. If we can't import
- the file, then we don't support that baseboard.
+ the file, then we don't support that reference board.
The board-specific module will set several variables, which we will
copy into the object that we return.
+ * 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.
* step_list - list of steps (named in step_names.py) to run in sequence
- to create the new variant of the baseboard
- * fsp - package name for FSP. This may be empty, depending on the
- processor on the baseboard
+ to create the new variant of the reference board
+ * 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 '~/trunk/src/' in chroot,
prepend '~/chromiumos/src' outside the chroot
@@ -224,7 +227,7 @@
Additionally, the following fields will be set:
- * board - the name of the baseboard, e.g. 'hatch'
+ * board - the name of the reference board, e.g. 'hatch'
* 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
@@ -239,7 +242,7 @@
it did not already exist).
Params:
- board Name of the base board
+ board Name of the reference board
variant Name of the variant being created
bug Text for bug number, if any ('None' otherwise)
continue_flag Flag if --continue was specified
@@ -268,11 +271,12 @@
try:
module = importlib.import_module(board)
except ImportError:
- print('Unsupported baseboard "' + board + '"')
+ print('Unsupported board "' + board + '"')
sys.exit(1)
# pylint: disable=bad-whitespace
# Allow extra spaces around = so that we can line things up nicely
+ status.base = module.base
status.emerge_cmd = module.emerge_cmd
status.emerge_pkgs = module.emerge_pkgs
status.fitimage_dir = module.fitimage_dir
@@ -305,6 +309,7 @@
dispatch = {
step_names.CB_VARIANT: create_coreboot_variant,
step_names.CB_CONFIG: create_coreboot_config,
+ step_names.COPY_CONFIG: copy_coreboot_config,
step_names.ADD_FIT: add_fitimage,
step_names.GEN_FIT: gen_fit_image_outside_chroot,
step_names.COMMIT_FIT: commit_fitimage,
@@ -404,15 +409,15 @@
"""
# Build up the command from all the packages in the list
- workon_cmd = ['cros_workon', '--board=' + status.board, action] + status.workon_pkgs
+ workon_cmd = ['cros_workon', '--board=' + status.base, action] + status.workon_pkgs
return bool(run_process(workon_cmd))
def create_coreboot_variant(status):
- """Create source files for a new variant of the base board in coreboot
+ """Create source files for a new variant of the reference board in coreboot
This function calls create_coreboot_variant.sh to set up a new variant
- of the base board.
+ of the reference board.
Params:
status variant_status object tracking our board, variant, etc.
@@ -426,7 +431,7 @@
'util/mainboard/google/create_coreboot_variant.sh')
return bool(run_process(
[create_coreboot_variant_sh,
- status.board,
+ status.base,
status.variant,
status.bug]))
@@ -448,6 +453,34 @@
'~/trunk/src/platform/dev/contrib/variant/create_coreboot_config.sh')
return bool(run_process(
[create_coreboot_config_sh,
+ status.base,
+ status.board,
+ status.variant,
+ status.bug]))
+
+
+def copy_coreboot_config(status):
+ """Copy the coreboot configuration for a new variant
+
+ This is only necessary for the Zork baseboard right now.
+ This function calls copy_coreboot_config.sh, which will copy
+ coreboot.${VARIANT} from
+ third_party/chromiumos-overlay/sys-boot/coreboot/files/configs
+ to
+ src/overlays/overlay-${BASE}/sys-boot/coreboot-${BASE}/files/configs
+
+ Params:
+ status variant_status object tracking our board, variant, etc.
+
+ Returns:
+ True if the script and test build succeeded, False if something failed
+ """
+ logging.info('Running step copy_coreboot_config')
+ copy_coreboot_config_sh = os.path.expanduser(
+ '~/trunk/src/platform/dev/contrib/variant/copy_coreboot_config.sh')
+ return bool(run_process(
+ [copy_coreboot_config_sh,
+ status.base,
status.board,
status.variant,
status.bug]))
@@ -457,8 +490,8 @@
"""Add the source files for a fitimage for the new variant
This function calls add_fitimage.sh to create a new XSL file for the
- variant's fitimage, which can override settings from the base board's XSL.
- When this is done, the user will have to build the fitimage by running
+ variant's fitimage, which can override settings from the reference board's
+ XSL. When this is done, the user will have to build the fitimage by running
gen_fit_image.sh outside of the chroot (and outside of this program's
control) because gen_fit_image.sh uses WINE, which is not installed in
the chroot. (There is a linux version of FIT, but it requires Open GL,
@@ -620,10 +653,10 @@
def create_initial_ec_image(status):
- """Create an EC image for the variant as a clone of the base board
+ """Create an EC image for the variant as a clone of the reference board
This function calls create_initial_ec_image.sh, which will clone the
- base board to create the variant. The shell script will build the
+ reference board to create the variant. The shell script will build the
EC code for the variant, but the repo upload hook insists that we
have done a `make buildall` before it will allow an upload, so this
function does the buildall.
@@ -691,7 +724,7 @@
'~/trunk/src/platform/dev/contrib/variant/add_variant_to_yaml.sh')
if not bool(run_process(
[add_variant_to_yaml_sh,
- status.board,
+ status.base,
status.variant,
status.bug])):
return False
@@ -732,20 +765,21 @@
# If the variant name doesn't show up in the file, then the count
# will be 0, so we would see, e.g.
# config.json:0
+ # Note that we leave out yaml/model.yaml (the public one) because for
+ # some boards, there is nothing in the public yaml file.
# We gather the output from grep, then look for any of the strings
# ending in :0. If none of them match, then we're good, but if even
# one of them ends with :0 then there was a problem with generating
# the files from the yaml.
- chromeos_config = '/build/' + status.board + '/usr/share/chromeos-config'
+ chromeos_config = '/build/' + status.base + '/usr/share/chromeos-config'
logging.debug('chromeos_config = "%s"', chromeos_config)
grep = run_process(
['grep',
- '-c',
+ '-ci',
status.variant,
'config.json',
'yaml/config.c',
'yaml/config.yaml',
- 'yaml/model.yaml',
'yaml/private-model.yaml'], cwd=chromeos_config, capture_output=True)
if grep is None:
@@ -773,7 +807,7 @@
return False
cros_workon(status, 'stop')
- build_path = '/build/' + status.board + '/firmware'
+ build_path = '/build/' + status.base + '/firmware'
logging.debug('build_path = "%s"', build_path)
if not file_exists(build_path, 'image-' + status.variant + '.bin'):
logging.error('emerge failed because image-%s.bin does not exist',
diff --git a/contrib/variant/step_names.py b/contrib/variant/step_names.py
index 944d83e..9847835 100644
--- a/contrib/variant/step_names.py
+++ b/contrib/variant/step_names.py
@@ -12,6 +12,7 @@
# Allow extra spaces around = so that we can line things up nicely
CB_VARIANT = 'cb_variant'
CB_CONFIG = 'cb_config'
+COPY_CONFIG = 'copy_config'
ADD_FIT = 'add_fit'
GEN_FIT = 'gen_fit'
COMMIT_FIT = 'commit_fit'
diff --git a/contrib/variant/trembyle.py b/contrib/variant/trembyle.py
new file mode 100644
index 0000000..46c6c48
--- /dev/null
+++ b/contrib/variant/trembyle.py
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+"""Define steps, package names, and directories for creating a Trembyle variant
+
+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 = 'zork'
+
+# List of steps (named in step_names.py) to run in sequence to create
+# the new variant of the baseboard
+step_list = [
+ step_names.CB_VARIANT,
+ step_names.CB_CONFIG,
+ step_names.COPY_CONFIG,
+ step_names.EC_IMAGE,
+ step_names.EC_BUILDALL,
+ step_names.ADD_YAML,
+ step_names.BUILD_YAML,
+ step_names.EMERGE,
+ step_names.PUSH,
+ step_names.UPLOAD,
+ step_names.FIND,
+ step_names.CQ_DEPEND,
+ step_names.CLEAN_UP]
+
+# Package name for FSP
+fsp = None
+
+# Package name for the fitimage (None, because Zork doesn't use FIT)
+fitimage_pkg = None
+
+# Directory for fitimage (None, because Zork doesn't use FIT)
+fitimage_dir = None
+
+# List of packages to cros_workon
+workon_pkgs = ['coreboot-zork', 'libpayload', 'vboot_reference', 'depthcharge',
+ 'chromeos-ec', 'chromeos-config-bsp-zork-private']
+
+# The emerge command
+emerge_cmd = 'emerge-zork'
+
+# List of packages to emerge
+emerge_pkgs = ['coreboot-zork', 'libpayload', 'vboot_reference', 'depthcharge',
+ 'chromeos-ec', 'chromeos-config-bsp-zork-private',
+ 'chromeos-config', 'chromeos-config-bsp', 'chromeos-config-bsp-zork',
+ 'coreboot-private-files', 'chromeos-bootimage']
+
+# List of packages to emerge just to build the yaml
+yaml_emerge_pkgs = ['chromeos-config-bsp', 'chromeos-config',
+ 'chromeos-config-bsp-zork', 'chromeos-config-bsp-zork-private']
+
+# Directory for the private yaml file
+private_yaml_dir = '~/trunk/src/private-overlays/overlay-zork-private/'\
+ 'chromeos-base/chromeos-config-bsp-zork-private'
diff --git a/contrib/variant/volteer.py b/contrib/variant/volteer.py
index 6744c80..68498b8 100644
--- a/contrib/variant/volteer.py
+++ b/contrib/variant/volteer.py
@@ -9,6 +9,9 @@
from __future__ import print_function
import step_names
+# Name of the baseboard
+base = 'volteer'
+
# List of steps (named in step_names.py) to run in sequence to create
# the new variant of the baseboard
step_list = [