summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPaul Fagerburg <pfagerburg@chromium.org>2019-08-23 11:22:14 -0600
committerPatrick Georgi <pgeorgi@google.com>2019-09-19 09:37:12 +0000
commitb4eb02aa8b9e7c479e8cb104197afd326c36f974 (patch)
treed539bc7cb26cf28ecd0e1c7b5a06525526464dcf /util
parentdb7906a57902e4a2a582308f0e2834d335c85805 (diff)
hatch: automate creating a new variant in coreboot
To create a new variant of the hatch baseboard, we need to add the variant's GBB_HWID and other information to Kconfig and Kconfig.name, and set up a skeletal build based on the hatch baseboard. BUG=b:140261109 BRANCH=none TEST=``./create_coreboot_variant.sh sushi && git show`` Kconfig will have three new lines for the SUSHI variant, and Kconfig.name will have an entirely new section. New files created are: variants/sushi/Makefile.inc variants/sushi/overridetree.cb variants/sushi/include/ec.h variants/sushi/include/gpio.h variants/sushi/include/variant/acpi/dptf.asl Also run the script with an existing board name to verify that you can't create a variant that already exists. Change-Id: I1a5b9c8735faafebb2e4e384cb3346867d64c556 Signed-off-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/35239 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'util')
-rwxr-xr-xutil/mainboard/google/hatch/create_coreboot_variant.sh78
-rwxr-xr-xutil/mainboard/google/hatch/kconfig.py156
-rw-r--r--util/mainboard/google/hatch/template/Makefile.inc13
-rw-r--r--util/mainboard/google/hatch/template/include/variant/acpi/dptf.asl14
-rw-r--r--util/mainboard/google/hatch/template/include/variant/ec.h19
-rw-r--r--util/mainboard/google/hatch/template/include/variant/gpio.h19
-rw-r--r--util/mainboard/google/hatch/template/overridetree.cb6
7 files changed, 305 insertions, 0 deletions
diff --git a/util/mainboard/google/hatch/create_coreboot_variant.sh b/util/mainboard/google/hatch/create_coreboot_variant.sh
new file mode 100755
index 0000000000..32720ca54e
--- /dev/null
+++ b/util/mainboard/google/hatch/create_coreboot_variant.sh
@@ -0,0 +1,78 @@
+#!/bin/bash
+#
+# This file is part of the coreboot project.
+#
+# Copyright 2019 Google LLC.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+if [[ "$#" -ne 1 ]]; then
+ echo "Usage: $0 variant_name"
+ echo "e.g. $0 kohaku"
+ echo "Adds a new variant of Hatch to Kconfig and Kconfig.name, creates the"
+ echo "skeleton files for acpi, ec, and gpio, copies the makefile for"
+ echo "SPD sources, and sets up a basic overridetree"
+ exit 1
+fi
+
+# Note that this script is specific to Hatch, and so it does not allow
+# you to specify the baseboard as one of the cmdline arguments.
+#
+# This is the name of the base board that we're cloning to make the variant.
+base="hatch"
+# This is the name of the variant that is being cloned
+# ${var,,} converts to all lowercase
+variant="${1,,}"
+
+# This script and the templates live in util/mainboard/google/hatch
+# We need to create files in src/mainboard/google/hatch
+pushd "${BASH_SOURCE%/*}" || exit
+SRC=$(pwd)
+popd || exit
+pushd "${SRC}/../../../../src/mainboard/google/${base}" || {
+ echo "The baseboard directory for ${base} does not exist.";
+ exit; }
+
+# 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?"
+ popd || exit
+ exit 2
+fi
+
+# Start a branch. Use YMD timestamp to avoid collisions.
+DATE=$(date +%Y%m%d)
+git checkout -b "create_${variant}_${DATE}"
+
+# Copy the template tree to the target
+cp -r "${SRC}/template/*" "variants/${variant}/"
+git add "variants/${variant}/"
+
+# Now add the new variant to Kconfig and Kconfig.name
+# These files are in the current directory, e.g. src/mainboard/google/hatch
+"${SRC}/kconfig.py" --name "${variant}"
+
+mv Kconfig.new Kconfig
+mv Kconfig.name.new Kconfig.name
+
+git add Kconfig Kconfig.name
+
+# Now commit the files
+git commit -sm "${base}: Create ${variant} variant
+
+BUG=none
+TEST=util/abuild/abuild -p none -t google/${base} -x -a
+make sure the build includes GOOGLE_${variant^^}"
+
+popd || exit
+
+echo "Please check all the files (git show), make any changes you want,"
+echo "and then push to coreboot HEAD:refs/for/master"
diff --git a/util/mainboard/google/hatch/kconfig.py b/util/mainboard/google/hatch/kconfig.py
new file mode 100755
index 0000000000..8b54b75c51
--- /dev/null
+++ b/util/mainboard/google/hatch/kconfig.py
@@ -0,0 +1,156 @@
+#!/usr/bin/python3
+"""Add a new variant to the Kconfig and Kconfig.name for the baseboard
+
+To start a new variant of an existing baseboard, we need to add
+the variant into the Kconfig and Kconfig.name files for the
+baseboard. In Kconfig, we have three sections that need additional
+entries, GBB_HWID, MAINBOARD_PART_NUMBER, and VARIANT_DIR.
+
+In GBB_HWID, we need to add a HWID that includes a numeric suffix.
+The numeric suffix is the CRC-32 of the all-caps ASCII name,
+modulo 10000.
+For example, if the board name is "Fizz", we calculate the CRC of
+"FIZZ TEST", which is 0x598C492D. In decimal, the value is 1502365997,
+modulo 10000 is 5997. So the HWID string is "FIZZ TEST 5997"
+In the past, we have used an online CRC-32 calculator such as
+https://www.lammertbies.nl/comm/info/crc-calculation.html, and then
+used the calculator app to convert to decimal and take the last
+4 digits.
+
+The MAINBOARD_PART_NUMBER and VARIANT_DIR are simpler, just using
+various capitalizations of the variant name to create the strings.
+
+Kconfig.name adds an entire section for the new variant, and all
+of these use various capitalizations of the variant name. The strings
+in this section are SOC-specific, so we'll need versions for each
+SOC that we support.
+
+Copyright 2019 Google LLC.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; version 2 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+"""
+
+import argparse
+import zlib
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Add strings to coreboot Kconfig for a new board variant")
+ parser.add_argument('--name', type=str, required=True,
+ help='Name of the board variant')
+ args = parser.parse_args()
+
+ add_to_Kconfig(args.name)
+ add_to_Kconfig_name(args.name)
+
+
+def get_gbb_hwid(variant_name):
+ """Create the GBB_HWID for a variant
+
+ variant_name The name of the board variant, e.g. 'kohaku'
+
+ Returns:
+ GBB_HWID string for the board variant, e.g. 'KOHAKU TEST 1953'
+
+ Note that the case of the variant name does not matter; it gets
+ converted to all uppercase as part of this function."""
+ hwid = variant_name + ' test'
+ upperhwid = hwid.upper()
+ suffix = zlib.crc32(upperhwid.encode('UTF-8')) % 10000
+ gbb_hwid = upperhwid + ' ' + str(suffix).zfill(4)
+ return gbb_hwid
+
+
+def add_to_Kconfig(variant_name):
+ """Add options for the variant to the Kconfig
+
+ Open the Kconfig file and read it line-by-line. When we detect that we're
+ in one of the sections of interest, wait until we get a blank line
+ (signalling the end of that section), and then add our new line before
+ the blank line. The updated lines are written out to Kconfig.new in the
+ same directory as Kconfig.
+
+ variant_name The name of the board variant, e.g. 'kohaku'"""
+ # These are the part of the strings that we'll add to the sections
+ BOARD = 'BOARD_GOOGLE_' + variant_name.upper()
+ gbb_hwid = get_gbb_hwid(variant_name)
+ lowercase = variant_name.lower()
+ capitalized = lowercase.capitalize()
+
+ # These flags track whether we're in a section where we need to add an option
+ in_gbb_hwid = False
+ in_mainboard_part_number = False
+ in_variant_dir = False
+
+ inputname = 'Kconfig'
+ outputname = 'Kconfig.new'
+ with open(outputname, 'w') as outfile:
+ with open(inputname, 'r') as infile:
+ for rawline in infile:
+ line = rawline.rstrip('\r\n')
+
+ # Are we in one of the sections of interest?
+ if line == 'config GBB_HWID':
+ in_gbb_hwid = True
+ if line == 'config MAINBOARD_PART_NUMBER':
+ in_mainboard_part_number = True
+ if line == 'config VARIANT_DIR':
+ in_variant_dir = True
+
+ # Are we at the end of a section, and if so, is it one of the
+ # sections of interest?
+ if line == '':
+ if in_gbb_hwid:
+ print('\tdefault "' + gbb_hwid + '" if ' + BOARD, file=outfile)
+ in_gbb_hwid = False
+ if in_mainboard_part_number:
+ print('\tdefault "' + capitalized + '" if ' + BOARD, file=outfile)
+ in_mainboard_part_number = False
+ if in_variant_dir:
+ print('\tdefault "' + lowercase + '" if ' + BOARD, file=outfile)
+ in_variant_dir = False
+
+ print(line, file=outfile)
+
+
+def add_to_Kconfig_name(variant_name):
+ """Add a config section for the variant to the Kconfig.name
+
+ Kconfig.name is easier to modify than Kconfig; it only has a block at
+ the end with the new variant's details.
+
+ config BOARD_GOOGLE_${VARIANT}
+
+ variant_name The name of the board variant, e.g. 'kohaku'"""
+ # Board name for the config section
+ uppercase = variant_name.upper()
+ BOARD = 'BOARD_GOOGLE_' + uppercase
+ capitalized = variant_name.lower().capitalize()
+
+ inputname = 'Kconfig.name'
+ outputname = 'Kconfig.name.new'
+ with open(outputname, 'w') as outfile:
+ with open(inputname, 'r') as infile:
+ # Copy all input lines to output
+ for rawline in infile:
+ line = rawline.rstrip('\r\n')
+ print(line, file=outfile)
+
+ # Now add the new section
+ print('\nconfig ' + BOARD, file=outfile)
+ print('\tbool "-> ' + capitalized + '"', file=outfile)
+ print('\tselect BOARD_GOOGLE_BASEBOARD_HATCH', file=outfile)
+ print('\tselect BOARD_ROMSIZE_KB_16384', file=outfile)
+ print('\tselect SOC_INTEL_COMETLAKE', file=outfile)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/util/mainboard/google/hatch/template/Makefile.inc b/util/mainboard/google/hatch/template/Makefile.inc
new file mode 100644
index 0000000000..38cf728d8f
--- /dev/null
+++ b/util/mainboard/google/hatch/template/Makefile.inc
@@ -0,0 +1,13 @@
+## This file is part of the coreboot project.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; version 2 of the License.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+
+SPD_SOURCES =
diff --git a/util/mainboard/google/hatch/template/include/variant/acpi/dptf.asl b/util/mainboard/google/hatch/template/include/variant/acpi/dptf.asl
new file mode 100644
index 0000000000..496334daab
--- /dev/null
+++ b/util/mainboard/google/hatch/template/include/variant/acpi/dptf.asl
@@ -0,0 +1,14 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <baseboard/acpi/dptf.asl>
diff --git a/util/mainboard/google/hatch/template/include/variant/ec.h b/util/mainboard/google/hatch/template/include/variant/ec.h
new file mode 100644
index 0000000000..25269627bd
--- /dev/null
+++ b/util/mainboard/google/hatch/template/include/variant/ec.h
@@ -0,0 +1,19 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef VARIANT_EC_H
+#define VARIANT_EC_H
+
+#include <baseboard/ec.h>
+
+#endif
diff --git a/util/mainboard/google/hatch/template/include/variant/gpio.h b/util/mainboard/google/hatch/template/include/variant/gpio.h
new file mode 100644
index 0000000000..1322233ad0
--- /dev/null
+++ b/util/mainboard/google/hatch/template/include/variant/gpio.h
@@ -0,0 +1,19 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef VARIANT_GPIO_H
+#define VARIANT_GPIO_H
+
+#include <baseboard/gpio.h>
+
+#endif
diff --git a/util/mainboard/google/hatch/template/overridetree.cb b/util/mainboard/google/hatch/template/overridetree.cb
new file mode 100644
index 0000000000..abbcaaa08c
--- /dev/null
+++ b/util/mainboard/google/hatch/template/overridetree.cb
@@ -0,0 +1,6 @@
+chip soc/intel/cannonlake
+
+ device domain 0 on
+ end
+
+end