blob: 8fd452e8ea5bdaae6ab13e00e4e8a410333c6634 [file] [log] [blame]
# 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.
set -e
SCRIPT="$(basename -- "$0")"
if [[ -z "${CB_SRC_DIR}" ]]; then
echo "CB_SRC_DIR must be set in the environment"
exit 1
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 dalboz"
echo "* Adds a new variant of the baseboard to Kconfig and"
echo "* Copies the template files for the baseboard to the new variant"
exit 1
to_lower() {
# Convert a string to lower case using ASCII translation rules.
LC_ALL=C LOWER="${1,,}"
echo "${LOWER}"
to_upper() {
# Convert a string to upper case using ASCII translation rules.
LC_ALL=C UPPER="${1^^}"
echo "${UPPER}"
# This is the name of the base board
BASE="$(to_lower "$1")"
# This is the name of the reference board that we're using to make the variant.
# TODO(b/149391804): fix the baseboard/reference board/variant terminology
REFERENCE="$(to_lower "$2")"
# This is the name of the variant that is being cloned.
VARIANT="$(to_lower "$3")"
VARIANT_UPPER="$(to_upper "${VARIANT}")"
# Assign BUG= text, or "None" if that parameter wasn't specified.
# Get the directory where this script is located; it is also where
# is located.
pushd "${BASH_SOURCE%/*}"
# The template files are in ${CB_SRC_DIR}/util/mainboard/google/${REFERENCE}/template
# We need to create files in ${CB_SRC_DIR}/src/mainboard/google/${BASE}/variants/${VARIANT}
if [[ ! -e "${CB_SRC_DIR}/src/mainboard/google/${BASE}" ]]; then
echo "The baseboard directory for ${BASE} does not exist."
exit 1
pushd "${CB_SRC_DIR}/src/mainboard/google/${BASE}"
# Make sure the variant doesn't already exist.
if [[ -e "variants/${VARIANT}" ]]; then
echo "variants/${VARIANT} already exists."
echo "Have you already created this variant?"
exit 1
# Start a branch. Use YMD timestamp to avoid collisions.
DATE="$(date +%Y%m%d)"
git checkout -b "coreboot_${VARIANT}_${DATE}"
# TODO(b/149701259): trap a function at exit that cleans this up
# Copy the template tree to the target.
mkdir -p "variants/${VARIANT}/"
cp -pr "${TEMPLATE}/." "variants/${VARIANT}/"
if [[ -e "variants/${VARIANT}/Kconfig" ]]; then
git add "variants/${VARIANT}/"
# Now add the new variant to Kconfig and
# These files are in the current directory, e.g. src/mainboard/google/hatch
"${SRC}/" --board "${REFERENCE}" --variant "${VARIANT}"
mv Kconfig
git add Kconfig
# TODO(b/149700012): Use fmt to wrap git commit messages0
# Now commit the files.
git commit -sm "${BASE}: Create ${VARIANT} variant
Create the ${VARIANT} variant of the ${REFERENCE} reference
board by copying the template files to a new directory named
for the variant.
(Auto-Generated by ${SCRIPT} version ${VERSION}).
TEST=util/abuild/abuild -p none -t google/${BASE} -x -a
make sure the build includes GOOGLE_${VARIANT_UPPER}"
# TODO(b/149702214): verify that it builds correctly