Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # -*- coding: utf-8 -*- |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 3 | """Create a new variant of an existing reference board |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 4 | |
| 5 | This program will call all of the scripts that create the various pieces |
| 6 | of a new variant. For example to create a new variant of the hatch base |
| 7 | board, the following scripts are called: |
| 8 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 9 | * third_party/coreboot/util/mainboard/google/create_coreboot_variant.sh |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 10 | * platform/dev/contrib/variant/create_coreboot_config.sh |
| 11 | * private-overlays/baseboard-hatch-private/sys-boot/ |
| 12 | * coreboot-private-files-hatch/files/add_fitimage.sh |
| 13 | * coreboot-private-files-hatch/asset_generation/gen_fit_image.sh |
| 14 | * Outside the chroot, because it uses WINE to run the FIT tools |
| 15 | * platform/dev/contrib/variant/create_initial_ec_image.sh |
| 16 | * platform/dev/contrib/variant/add_variant_to_yaml.sh |
| 17 | * private-overlays/overlay-hatch-private/chromeos-base/ |
| 18 | * chromeos-config-bsp-hatch-private/add_variant.sh |
| 19 | |
| 20 | Once the scripts are done, the following repos have changes |
| 21 | |
| 22 | * third_party/coreboot |
| 23 | * third_party/chromiumos-overlay |
| 24 | * private-overlays/baseboard-hatch-private |
| 25 | * platform/ec |
| 26 | * private-overlays/overlay-hatch-private |
| 27 | * overlays |
| 28 | |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 29 | The program has support for multiple reference boards, so the repos, directories, |
| 30 | and scripts above can change depending on what the reference board is. |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 31 | |
| 32 | Copyright 2020 The Chromium OS Authors. All rights reserved. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 33 | Use of this source code is governed by a BSD-style license that can be |
| 34 | found in the LICENSE file. |
| 35 | """ |
| 36 | |
| 37 | from __future__ import print_function |
| 38 | import argparse |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 39 | import importlib |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 40 | import logging |
| 41 | import os |
| 42 | import re |
| 43 | import shutil |
| 44 | import subprocess |
| 45 | import sys |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 46 | from chromite.lib import git |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 47 | import step_names |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 48 | import variant_status |
| 49 | |
| 50 | |
| 51 | def main(): |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 52 | """Create a new variant of an existing reference board |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 53 | |
| 54 | This program automates the creation of a new variant of an existing |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 55 | reference board by calling various scripts that copy the reference board, |
| 56 | modify files for the new variant, stage commits, and upload to gerrit. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 57 | |
| 58 | Note that one of the following is required: |
| 59 | * --continue |
| 60 | * --board=BOARD --variant=VARIANT [--bug=BUG] |
| 61 | """ |
| 62 | board, variant, bug, continue_flag = get_args() |
| 63 | |
| 64 | if not check_flags(board, variant, bug, continue_flag): |
| 65 | return False |
| 66 | |
| 67 | status = get_status(board, variant, bug, continue_flag) |
| 68 | if status is None: |
| 69 | return False |
| 70 | |
| 71 | status.load() |
| 72 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 73 | while status.step is not None: |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 74 | status.save() |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 75 | if not perform_step(status): |
| 76 | logging.debug('perform_step returned False; exiting ...') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 77 | return False |
| 78 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 79 | move_to_next_step(status) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 80 | |
| 81 | return True |
| 82 | |
| 83 | |
| 84 | def get_args(): |
| 85 | """Parse the command-line arguments |
| 86 | |
| 87 | There doesn't appear to be a way to specify that --continue is |
| 88 | mutually exclusive with --board, --variant, and --bug. As a result, |
| 89 | all arguments are optional, and another function will apply the logic |
| 90 | to check if there is an illegal combination of arguments. |
| 91 | |
| 92 | Returns a list of: |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 93 | board Name of the reference board |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 94 | variant Name of the variant being created |
| 95 | bug Text for bug number, if any ('None' otherwise) |
| 96 | continue_flag Flag if --continue was specified |
| 97 | """ |
| 98 | parser = argparse.ArgumentParser( |
| 99 | description=main.__doc__, |
| 100 | formatter_class=argparse.RawTextHelpFormatter) |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 101 | parser.add_argument('--board', type=str, help='Name of the reference board') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 102 | parser.add_argument( |
| 103 | '--variant', type=str, help='Name of the new variant to create') |
| 104 | parser.add_argument( |
| 105 | '--bug', type=str, help='Bug number to reference in commits') |
| 106 | parser.add_argument( |
| 107 | '--continue', action='store_true', |
| 108 | dest='continue_flag', help='Continue the process from where it paused') |
| 109 | parser.add_argument( |
| 110 | '--verbose', action='store_true', |
| 111 | dest='verbose_flag', help='Enable verbose output of progress') |
| 112 | args = parser.parse_args() |
| 113 | |
| 114 | if args.verbose_flag: |
| 115 | logging.basicConfig(level=logging.DEBUG) |
| 116 | else: |
| 117 | logging.basicConfig(level=logging.INFO) |
| 118 | |
| 119 | board = args.board |
| 120 | if board is not None: |
| 121 | board = board.lower() |
| 122 | |
| 123 | variant = args.variant |
| 124 | if variant is not None: |
| 125 | variant = variant.lower() |
| 126 | |
| 127 | bug = args.bug or 'None' |
| 128 | |
| 129 | return (board, variant, bug, args.continue_flag) |
| 130 | |
| 131 | |
| 132 | def check_flags(board, variant, bug, continue_flag): |
| 133 | """Check the flags to ensure no invalid combinations |
| 134 | |
| 135 | We allow any of the following: |
| 136 | --continue |
| 137 | --board=board_name --variant=variant_name |
| 138 | --board=board_name --variant=variant_name --bug=bug_text |
| 139 | |
| 140 | The argument parser does have the functionality to represent the |
| 141 | combination of --board and --variant as a single mutually-exclusive |
| 142 | argument, so we have to use this function to do the checking. |
| 143 | |
| 144 | Params: |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 145 | board Name of the reference board |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 146 | variant Name of the variant being created |
| 147 | bug Text for bug number, if any ('None' otherwise) |
| 148 | continue_flag Flag if --continue was specified |
| 149 | |
| 150 | Returns: |
| 151 | True if the arguments are acceptable, False otherwise |
| 152 | """ |
| 153 | if continue_flag: |
| 154 | if board is not None or variant is not None: |
| 155 | logging.error('--continue cannot have other options') |
| 156 | return False |
| 157 | |
| 158 | if bug != 'None': |
| 159 | logging.error('--continue cannot have other options') |
| 160 | return False |
| 161 | else: |
| 162 | if board is None: |
| 163 | logging.error('--board must be specified') |
| 164 | return False |
| 165 | |
| 166 | if variant is None: |
| 167 | logging.error('--variant must be specified') |
| 168 | return False |
| 169 | |
| 170 | return True |
| 171 | |
| 172 | |
| 173 | def file_exists(filepath, filename): |
| 174 | """Determine if a path and file exists |
| 175 | |
| 176 | Params: |
| 177 | filepath Path where build outputs should be found, e.g. |
| 178 | /build/hatch/firmware |
| 179 | filename File that should exist in that path, e.g. |
| 180 | image-sushi.bin |
| 181 | |
| 182 | Returns: |
| 183 | True if file exists in that path, False otherwise |
| 184 | """ |
| 185 | fullname = os.path.join(filepath, filename) |
| 186 | return os.path.exists(fullname) and os.path.isfile(fullname) |
| 187 | |
| 188 | |
| 189 | def get_status(board, variant, bug, continue_flag): |
| 190 | """Create the status file or get the previous status |
| 191 | |
| 192 | This program can stop at several places as we have to wait for CLs |
| 193 | to work through CQ or be upstreamed into the chromiumos tree, so just |
| 194 | like a git cherry-pick, there is a --continue option to pick up where |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 195 | you left off by reading a specially-named status file. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 196 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 197 | If --continue is specified, the status file must exist. |
| 198 | If the status file exists, then --continue must be specified. |
| 199 | When --continue is specified, we read the status file and return |
| 200 | with the contents. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 201 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 202 | If the status file does not exist, we will create the state file with |
| 203 | the board, variant, and (optional) bug details. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 204 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 205 | To decouple the list of boards supported from this main program, we |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 206 | try to import a module with the same name as the reference board, |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 207 | so --board=hatch means that we import hatch.py. If we can't import |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 208 | the file, then we don't support that reference board. |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 209 | |
| 210 | The board-specific module will set several variables, which we will |
| 211 | copy into the object that we return. |
| 212 | |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 213 | * base - the name of the base board, such as Hatch, Volteer, or Zork. |
| 214 | This can be different from the reference board, e.g. the Trembyle |
| 215 | reference board in the Zork project. |
Paul Fagerburg | 4d34345 | 2020-01-24 15:23:53 -0700 | [diff] [blame] | 216 | * coreboot_dir - base directory for coreboot, usually third_party/coreboot |
| 217 | but could differ for processors that use a private repo |
| 218 | * cb_config_dir - base directory for coreboot configs, usually |
| 219 | third_party/chromiumos-overlay/sys-boot/coreboot/files/configs but |
| 220 | could differ for processors that use a private repo |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 221 | * step_list - list of steps (named in step_names.py) to run in sequence |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 222 | to create the new variant of the reference board |
| 223 | * fsp - package name for FSP. This may be None, depending on the |
| 224 | processor on the reference board |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 225 | * fitimage_pkg - package name for the fitimage |
| 226 | * fitimage_dir - directory for fitimage; prepend '~/trunk/src/' in chroot, |
| 227 | prepend '~/chromiumos/src' outside the chroot |
| 228 | * workon_pkgs - list of packages to cros_workon |
| 229 | * emerge_cmd - the emerge command, e.g. 'emerge-hatch' |
| 230 | * emerge_pkgs - list of packages to emerge |
| 231 | * yaml_emerge_pkgs - list of packages to emerge just to build the yaml |
| 232 | * private_yaml_dir - directory for the private yaml file |
| 233 | |
| 234 | Additionally, the following fields will be set: |
| 235 | |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 236 | * board - the name of the reference board, e.g. 'hatch' |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 237 | * variant - the name of the variant, e.g. 'sushi' |
| 238 | * bug - optional text for a bug ID, used in the git commit messages. |
| 239 | Could be 'None' (as text, not the python None), or something like |
| 240 | 'b:12345' for buganizer, or 'chromium:12345' |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 241 | * step - internal state tracking, what step of the variant creation |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 242 | we are at. |
| 243 | * yaml_file - internal, just the name of the file where all this data |
| 244 | gets saved. |
| 245 | |
| 246 | These data might come from the status file (because we read it), or |
| 247 | they might be the initial values after we created the file (because |
| 248 | it did not already exist). |
| 249 | |
| 250 | Params: |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 251 | board Name of the reference board |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 252 | variant Name of the variant being created |
| 253 | bug Text for bug number, if any ('None' otherwise) |
| 254 | continue_flag Flag if --continue was specified |
| 255 | |
| 256 | Returns: |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 257 | variant_status object with all the data mentioned above |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 258 | """ |
| 259 | status = variant_status.variant_status() |
| 260 | if continue_flag: |
| 261 | if not status.yaml_file_exists(): |
| 262 | logging.error( |
| 263 | 'new_variant is not in progress; nothing to --continue') |
| 264 | return None |
| 265 | else: |
| 266 | if status.yaml_file_exists(): |
| 267 | logging.error( |
| 268 | 'new_variant already in progress; did you forget --continue?') |
| 269 | return None |
| 270 | |
| 271 | status.board = board |
| 272 | status.variant = variant |
| 273 | status.bug = bug |
Paul Fagerburg | dd3e9c3 | 2020-01-07 14:00:35 -0700 | [diff] [blame] | 274 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 275 | # We're just starting out, so load the appropriate module and copy |
| 276 | # all the data from it. |
| 277 | try: |
| 278 | module = importlib.import_module(board) |
| 279 | except ImportError: |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 280 | print('Unsupported board "' + board + '"') |
Paul Fagerburg | dd3e9c3 | 2020-01-07 14:00:35 -0700 | [diff] [blame] | 281 | sys.exit(1) |
| 282 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 283 | # pylint: disable=bad-whitespace |
| 284 | # Allow extra spaces around = so that we can line things up nicely |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 285 | status.base = module.base |
Paul Fagerburg | 4d34345 | 2020-01-24 15:23:53 -0700 | [diff] [blame] | 286 | status.coreboot_dir = module.coreboot_dir |
| 287 | status.cb_config_dir = module.cb_config_dir |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 288 | status.emerge_cmd = module.emerge_cmd |
| 289 | status.emerge_pkgs = module.emerge_pkgs |
| 290 | status.fitimage_dir = module.fitimage_dir |
| 291 | status.fitimage_pkg = module.fitimage_pkg |
Paul Fagerburg | 55dabf4 | 2020-01-27 15:30:09 -0700 | [diff] [blame] | 292 | status.fitimage_cmd = module.fitimage_cmd |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 293 | status.fsp = module.fsp |
| 294 | status.private_yaml_dir = module.private_yaml_dir |
| 295 | status.step_list = module.step_list |
| 296 | status.workon_pkgs = module.workon_pkgs |
| 297 | status.yaml_emerge_pkgs = module.yaml_emerge_pkgs |
| 298 | # pylint: enable=bad-whitespace |
Paul Fagerburg | dd3e9c3 | 2020-01-07 14:00:35 -0700 | [diff] [blame] | 299 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 300 | # Start at the first entry in the step list |
| 301 | status.step = status.step_list[0] |
Paul Fagerburg | dd3e9c3 | 2020-01-07 14:00:35 -0700 | [diff] [blame] | 302 | |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 303 | # Start a blank map for tracking CL data |
| 304 | status.commits = {} |
| 305 | |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 306 | status.save() |
| 307 | |
| 308 | return status |
| 309 | |
| 310 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 311 | def perform_step(status): |
| 312 | """Call the appropriate function for the current step |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 313 | |
| 314 | Params: |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 315 | status variant_status object tracking our board, variant, etc. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 316 | |
| 317 | Returns: |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 318 | True if the step succeeded, False if it failed |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 319 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 320 | # Function to call based on the step |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 321 | dispatch = { |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 322 | step_names.CB_VARIANT: create_coreboot_variant, |
| 323 | step_names.CB_CONFIG: create_coreboot_config, |
Paul Fagerburg | 2fd23f4 | 2020-02-07 14:04:48 -0700 | [diff] [blame] | 324 | step_names.CRAS_CONFIG: copy_cras_config, |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 325 | step_names.ADD_FIT: add_fitimage, |
| 326 | step_names.GEN_FIT: gen_fit_image_outside_chroot, |
| 327 | step_names.COMMIT_FIT: commit_fitimage, |
| 328 | step_names.EC_IMAGE: create_initial_ec_image, |
| 329 | step_names.EC_BUILDALL: ec_buildall, |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 330 | step_names.ADD_PUB_YAML: add_variant_to_public_yaml, |
| 331 | step_names.ADD_PRIV_YAML: add_variant_to_private_yaml, |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 332 | step_names.BUILD_YAML: build_yaml, |
| 333 | step_names.EMERGE: emerge_all, |
| 334 | step_names.PUSH: push_coreboot, |
| 335 | step_names.UPLOAD: upload_CLs, |
| 336 | step_names.FIND: find_coreboot_upstream, |
| 337 | step_names.CQ_DEPEND: add_cq_depends, |
| 338 | step_names.CLEAN_UP: clean_up, |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 341 | if status.step not in dispatch: |
| 342 | logging.error('Unknown step "%s", aborting...', status.step) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 343 | sys.exit(1) |
| 344 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 345 | return dispatch[status.step](status) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 346 | |
| 347 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 348 | def move_to_next_step(status): |
| 349 | """Move to the next step in the list |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 350 | |
| 351 | Params: |
| 352 | status variant_status object tracking our board, variant, etc. |
| 353 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 354 | if status.step not in status.step_list: |
| 355 | logging.error('Unknown step "%s", aborting...', status.step) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 356 | sys.exit(1) |
| 357 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 358 | idx = status.step_list.index(status.step) |
| 359 | if idx == len(status.step_list)-1: |
| 360 | status.step = None |
Paul Fagerburg | dd3e9c3 | 2020-01-07 14:00:35 -0700 | [diff] [blame] | 361 | else: |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 362 | status.step = status.step_list[idx+1] |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 363 | |
| 364 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 365 | def run_process(args, cwd=None, env=None, capture_output=False): |
| 366 | """Run a process, log debug messages, return text output of process |
| 367 | |
| 368 | The capture_output parameter allows us to capture the output when we |
| 369 | care about it (and not sending it to the screen), or ignoring it when |
| 370 | we don't care, and letting the user see the output so they know that |
| 371 | the build is still running, etc. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 372 | |
| 373 | Params: |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 374 | args List of the command and its params |
| 375 | cwd If not None, cd to this directory before running |
| 376 | env Environment to use for execution; if needed, get |
| 377 | os.environ.copy() and add variables. If None, just |
| 378 | use the current environment |
| 379 | capture_output True if we should capture the stdout, false |
| 380 | if we just care about success or not. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 381 | |
| 382 | Returns: |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 383 | If capture_output == True, we return the text output from running |
| 384 | the subprocess as a list of lines, or None if the process failed. |
| 385 | If capture_output == False, we return a True if it successed, or |
| 386 | None if the process failed. |
| 387 | |
| 388 | The caller can evaluate as a bool, because bool(None) == False, and |
| 389 | bool() of a non-empty list is True, or the caller can use the returned |
| 390 | text for further processing. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 391 | """ |
| 392 | logging.debug('Run %s', str(args)) |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 393 | try: |
| 394 | if capture_output: |
| 395 | output = subprocess.check_output(args, cwd=cwd, env=env, |
| 396 | stderr=subprocess.STDOUT) |
| 397 | else: |
| 398 | subprocess.run(args, cwd=cwd, env=env, check=True) |
| 399 | # Just something to decode so we don't get an empty list |
| 400 | output = b'True' |
| 401 | |
| 402 | logging.debug('process returns 0') |
| 403 | # Convert from byte string to ASCII |
| 404 | decoded = output.decode('utf-8') |
| 405 | # Split into array of individual lines |
| 406 | lines = decoded.split('\n') |
| 407 | return lines |
| 408 | except subprocess.CalledProcessError as err: |
| 409 | logging.debug('process returns %s', str(err.returncode)) |
| 410 | return None |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 411 | |
| 412 | |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 413 | def get_git_commit_data(cwd): |
| 414 | """Get the branch name and change id of the current commit |
| 415 | |
| 416 | Params: |
| 417 | cwd The current working directory, where we want to get the |
| 418 | branch name and change id |
| 419 | |
| 420 | Returns: |
| 421 | Map with 'dir', 'branch_name' and 'change_id' keys. The 'dir' |
| 422 | key maps to the value of os.path.expanduser(cwd) |
| 423 | """ |
| 424 | cwd = os.path.expanduser(cwd) |
| 425 | logging.debug('get_git_commit_data(%s)', cwd) |
| 426 | |
| 427 | branch_name = git.GetCurrentBranch(cwd) |
| 428 | if branch_name is None: |
| 429 | logging.error('Cannot determine git branch name in %s; exiting', cwd) |
| 430 | sys.exit(1) |
| 431 | logging.debug('git current branch is %s', branch_name) |
| 432 | |
| 433 | change_id = git.GetChangeId(cwd) |
| 434 | if change_id is None: |
| 435 | logging.error('Cannot determine Change-Id in %s; exiting', cwd) |
| 436 | sys.exit(1) |
| 437 | logging.debug('git Change-Id is %s', change_id) |
| 438 | |
| 439 | return { |
| 440 | 'dir': cwd, |
| 441 | 'branch_name': branch_name, |
| 442 | 'change_id': change_id |
| 443 | } |
| 444 | |
| 445 | |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 446 | def cros_workon(status, action): |
| 447 | """Call cros_workon for all the 9999 ebuilds we'll be touching |
| 448 | |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 449 | Params: |
| 450 | status variant_status object tracking our board, variant, etc. |
| 451 | action 'start' or 'stop' |
| 452 | |
| 453 | Returns: |
| 454 | True if the call to cros_workon was successful, False if failed |
| 455 | """ |
| 456 | |
| 457 | # Build up the command from all the packages in the list |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 458 | workon_cmd = ['cros_workon', '--board=' + status.base, action] + status.workon_pkgs |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 459 | return bool(run_process(workon_cmd)) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 460 | |
| 461 | |
| 462 | def create_coreboot_variant(status): |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 463 | """Create source files for a new variant of the reference board in coreboot |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 464 | |
| 465 | This function calls create_coreboot_variant.sh to set up a new variant |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 466 | of the reference board. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 467 | |
| 468 | Params: |
| 469 | status variant_status object tracking our board, variant, etc. |
| 470 | |
| 471 | Returns: |
| 472 | True if everything succeeded, False if something failed |
| 473 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 474 | logging.info('Running step create_coreboot_variant') |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 475 | cb_src_dir = os.path.join(os.path.expanduser('~/trunk/src/'), |
| 476 | status.coreboot_dir) |
| 477 | create_coreboot_variant_sh = os.path.join(cb_src_dir, |
Paul Fagerburg | 7b516d7 | 2019-12-20 13:13:41 -0700 | [diff] [blame] | 478 | 'util/mainboard/google/create_coreboot_variant.sh') |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 479 | rc = bool(run_process( |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 480 | [create_coreboot_variant_sh, |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 481 | status.base, |
Paul Fagerburg | abb1562 | 2020-02-07 15:41:29 -0700 | [diff] [blame] | 482 | status.board, |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 483 | status.variant, |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 484 | status.bug])) |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 485 | if rc: |
| 486 | status.commits['cb_variant'] = get_git_commit_data(cb_src_dir) |
| 487 | return rc |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 488 | |
| 489 | |
| 490 | def create_coreboot_config(status): |
| 491 | """Create a coreboot configuration for a new variant |
| 492 | |
| 493 | This function calls create_coreboot_config.sh, which will make a copy |
| 494 | of coreboot.${BOARD} into coreboot.${VARIANT}. |
| 495 | |
| 496 | Params: |
| 497 | status variant_status object tracking our board, variant, etc. |
| 498 | |
| 499 | Returns: |
| 500 | True if the script and test build succeeded, False if something failed |
| 501 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 502 | logging.info('Running step create_coreboot_config') |
Paul Fagerburg | 4d34345 | 2020-01-24 15:23:53 -0700 | [diff] [blame] | 503 | environ = os.environ.copy() |
| 504 | if status.cb_config_dir is not None: |
| 505 | environ['CB_CONFIG_DIR'] = status.cb_config_dir |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 506 | create_coreboot_config_sh = os.path.expanduser( |
| 507 | '~/trunk/src/platform/dev/contrib/variant/create_coreboot_config.sh') |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 508 | rc = bool(run_process( |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 509 | [create_coreboot_config_sh, |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 510 | status.base, |
| 511 | status.board, |
| 512 | status.variant, |
Paul Fagerburg | 4d34345 | 2020-01-24 15:23:53 -0700 | [diff] [blame] | 513 | status.bug], env=environ)) |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 514 | if rc: |
| 515 | # Use status.cb_config_dir if defined, or if not, use |
| 516 | # '~/trunk/src/third_party/chromiumos-overlay' |
| 517 | if status.cb_config_dir is not None: |
| 518 | cb_config_dir = os.path.join('~/trunk/src/', status.cb_config_dir) |
| 519 | else: |
| 520 | cb_config_dir = '~/trunk/src/third_party/chromiumos-overlay' |
| 521 | status.commits['cb_config'] = get_git_commit_data(cb_config_dir) |
| 522 | return rc |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 523 | |
| 524 | |
Paul Fagerburg | 2fd23f4 | 2020-02-07 14:04:48 -0700 | [diff] [blame] | 525 | def copy_cras_config(status): |
| 526 | """Copy the cras config for a new variant |
| 527 | |
| 528 | This is only necessary for the Zork baseboard right now. |
| 529 | This function calls copy_cras_config.sh, which will copy the |
| 530 | cras config in |
| 531 | overlays/overlay-${BASE}/chromeos-base/chromeos-bsp-${BASE}/files/cras-config/${BASE} |
| 532 | to .../${VARIANT} |
| 533 | |
| 534 | Params: |
| 535 | status variant_status object tracking our board, variant, etc. |
| 536 | |
| 537 | Returns: |
| 538 | True if the script and test build succeeded, False if something failed |
| 539 | """ |
| 540 | logging.info('Running step copy_cras_config') |
| 541 | copy_cras_config_sh = os.path.expanduser( |
| 542 | '~/trunk/src/platform/dev/contrib/variant/copy_cras_config.sh') |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 543 | rc = bool(run_process( |
Paul Fagerburg | 2fd23f4 | 2020-02-07 14:04:48 -0700 | [diff] [blame] | 544 | [copy_cras_config_sh, |
| 545 | status.base, |
| 546 | status.board, |
| 547 | status.variant, |
| 548 | status.bug])) |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 549 | if rc: |
| 550 | status.commits['copy_cras_config'] = get_git_commit_data('~/trunk/src/overlays') |
| 551 | return rc |
Paul Fagerburg | 2fd23f4 | 2020-02-07 14:04:48 -0700 | [diff] [blame] | 552 | |
| 553 | |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 554 | def add_fitimage(status): |
| 555 | """Add the source files for a fitimage for the new variant |
| 556 | |
| 557 | This function calls add_fitimage.sh to create a new XSL file for the |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 558 | variant's fitimage, which can override settings from the reference board's |
| 559 | XSL. When this is done, the user will have to build the fitimage by running |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 560 | gen_fit_image.sh outside of the chroot (and outside of this program's |
| 561 | control) because gen_fit_image.sh uses WINE, which is not installed in |
| 562 | the chroot. (There is a linux version of FIT, but it requires Open GL, |
| 563 | which is also not installed in the chroot.) |
| 564 | |
| 565 | Params: |
| 566 | status variant_status object tracking our board, variant, etc. |
| 567 | |
| 568 | Returns: |
| 569 | True if the script succeeded, False otherwise |
| 570 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 571 | logging.info('Running step add_fitimage') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 572 | add_fitimage_sh = os.path.expanduser(os.path.join( |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 573 | '~/trunk/src', status.fitimage_dir, 'files/add_fitimage.sh')) |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 574 | rc = bool(run_process( |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 575 | [add_fitimage_sh, |
| 576 | status.variant, |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 577 | status.bug])) |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 578 | if rc: |
| 579 | fitimage_dir = os.path.join('~/trunk/src', status.fitimage_dir) |
| 580 | status.commits['fitimage'] = get_git_commit_data(fitimage_dir) |
| 581 | return rc |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 582 | |
| 583 | |
| 584 | def gen_fit_image_outside_chroot(status): |
| 585 | """Tell the user to run gen_fit_image.sh outside the chroot |
| 586 | |
| 587 | As noted for add_Fitimage(), gen_fit_image.sh cannot run inside the |
| 588 | chroot. This function tells the user to run gen_fit_image.sh in |
| 589 | their normal environment, and then come back (--continue) when that |
| 590 | is done. |
| 591 | |
| 592 | Params: |
| 593 | status variant_status object tracking our board, variant, etc. |
| 594 | |
| 595 | Returns: |
| 596 | True |
| 597 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 598 | logging.info('Running step gen_fit_image_outside_chroot') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 599 | fit_image_files = check_fit_image_files(status) |
| 600 | # If the list is empty, then `not` of the list is True, so the files |
| 601 | # we need are all present and we can continue. |
| 602 | if not fit_image_files: |
| 603 | return True |
| 604 | |
| 605 | logging.info('The following files need to be generated:') |
| 606 | for filename in fit_image_files: |
| 607 | logging.info('* %s', filename) |
| 608 | logging.info('The fitimage sources are ready for gen_fit_image.sh to process.') |
| 609 | logging.info('gen_fit_image.sh cannot run inside the chroot. Please open a new terminal') |
| 610 | logging.info('window, change to the directory where gen_fit_image.sh is located, and run') |
Paul Fagerburg | 55dabf4 | 2020-01-27 15:30:09 -0700 | [diff] [blame] | 611 | logging.info(status.fitimage_cmd, status.variant) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 612 | logging.info('Then re-start this program with --continue.') |
| 613 | logging.info('If your chroot is based in ~/chromiumos, then the folder you want is') |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 614 | logging.info('~/chromiumos/src/%s/asset_generation', status.fitimage_dir) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 615 | return False |
| 616 | |
| 617 | |
| 618 | def check_fit_image_files(status): |
| 619 | """Check if the fitimage has been generated |
| 620 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 621 | This function is not called directly as a step, and so it doesn't need |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 622 | to produce any error messages to the user (except with --verbose). |
| 623 | gen_fit_image_outside_chroot will call this function to see if the |
| 624 | fitimage files exist, and if not, then that function will print the |
| 625 | message about how the user needs to run gen_fit_image.sh outside the |
| 626 | chroot. |
| 627 | |
| 628 | Params: |
| 629 | status variant_status object tracking our board, variant, etc. |
| 630 | |
| 631 | Returns: |
| 632 | List of files that *DO NOT* exist and need to be created, [] if |
| 633 | all files are present. |
| 634 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 635 | outputs_dir = os.path.expanduser(os.path.join( |
| 636 | '~/trunk/src', status.fitimage_dir, 'asset_generation/outputs')) |
| 637 | logging.debug('outputs_dir = "%s"', outputs_dir) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 638 | |
| 639 | files = [] |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 640 | if not file_exists(outputs_dir, 'fitimage-' + status.variant + '.bin'): |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 641 | files.append('fitimage-' + status.variant + '.bin') |
| 642 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 643 | if not file_exists(outputs_dir, |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 644 | 'fitimage-' + status.variant + '-versions.txt'): |
| 645 | files.append('fitimage-' + status.variant + '-versions.txt') |
| 646 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 647 | if not file_exists(outputs_dir, 'fit.log'): |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 648 | files.append('fit.log') |
| 649 | |
| 650 | return files |
| 651 | |
| 652 | |
| 653 | def move_fitimage_file(fitimage_dir, filename): |
| 654 | """Move fitimage files from create-place to commit-place |
| 655 | |
| 656 | commit_fitimage needs to move the fitimage files from the place where |
| 657 | they were created to a different directory in the tree. This utility |
| 658 | function handles joining paths and calling a file move function. |
| 659 | |
| 660 | Params: |
| 661 | fitimage_dir Directory where the fitimage files are |
| 662 | filename Name of the file being moved |
| 663 | |
| 664 | Returns: |
| 665 | True if the move succeeded, False if it failed |
| 666 | """ |
| 667 | src_dir = os.path.join(fitimage_dir, 'asset_generation/outputs') |
| 668 | src = os.path.join(src_dir, filename) |
| 669 | dest_dir = os.path.join(fitimage_dir, 'files') |
| 670 | dest = os.path.join(dest_dir, filename) |
| 671 | # If src does not exist and dest does, the move is already done => success! |
| 672 | if not file_exists(src_dir, filename) and file_exists(dest_dir, filename): |
| 673 | logging.debug('move "%s", "%s" unnecessary because dest exists and' |
| 674 | ' src does not exist', src, dest) |
| 675 | return True |
| 676 | |
| 677 | logging.debug('move "%s", "%s"', src, dest) |
| 678 | return shutil.move(src, dest) |
| 679 | |
| 680 | |
| 681 | def commit_fitimage(status): |
| 682 | """Move the fitimage files and add them to a git commit |
| 683 | |
| 684 | This function moves the fitimage binary and -versions files from |
| 685 | asset_generation/outputs to files/ and then adds those files and |
| 686 | fit.log to the existing git commit. |
| 687 | |
| 688 | Params: |
| 689 | status variant_status object tracking our board, variant, etc. |
| 690 | |
| 691 | Returns: |
| 692 | True if the copy, git add, and git commit --amend all succeeded. |
| 693 | False if something failed. |
| 694 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 695 | logging.info('Running step commit_fitimage') |
| 696 | fitimage_dir = os.path.expanduser(os.path.join('~/trunk/src', status.fitimage_dir)) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 697 | logging.debug('fitimage_dir = "%s"', fitimage_dir) |
| 698 | |
| 699 | # The copy operation will check that the source file exists, so no |
| 700 | # need to check separately. |
| 701 | if not move_fitimage_file(fitimage_dir, |
| 702 | 'fitimage-' + status.variant + '.bin'): |
| 703 | logging.error('Moving fitimage binary failed') |
| 704 | return False |
| 705 | |
| 706 | if not move_fitimage_file(fitimage_dir, |
| 707 | 'fitimage-' + status.variant + '-versions.txt'): |
| 708 | logging.error('Moving fitimage versions.txt failed') |
| 709 | return False |
| 710 | |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 711 | # TODO(pfagerburg) volteer also needs files/blobs/descriptor-${VARIANT}.bin |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 712 | if not bool(run_process( |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 713 | ['git', 'add', |
| 714 | 'asset_generation/outputs/fit.log', |
| 715 | 'files/fitimage-' + status.variant + '.bin', |
| 716 | 'files/fitimage-' + status.variant + '-versions.txt' |
| 717 | ], |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 718 | cwd=fitimage_dir)): |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 719 | return False |
| 720 | |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 721 | return bool(run_process(['git', 'commit', '--amend', '--no-edit'], |
| 722 | cwd=fitimage_dir)) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 723 | |
| 724 | |
| 725 | def create_initial_ec_image(status): |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 726 | """Create an EC image for the variant as a clone of the reference board |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 727 | |
| 728 | This function calls create_initial_ec_image.sh, which will clone the |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 729 | reference board to create the variant. The shell script will build the |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 730 | EC code for the variant, but the repo upload hook insists that we |
| 731 | have done a `make buildall` before it will allow an upload, so this |
| 732 | function does the buildall. |
| 733 | |
| 734 | Params: |
| 735 | status variant_status object tracking our board, variant, etc. |
| 736 | |
| 737 | Returns: |
| 738 | True if the script and test build succeeded, False if something failed |
| 739 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 740 | logging.info('Running step create_initial_ec_image') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 741 | create_initial_ec_image_sh = os.path.expanduser( |
| 742 | '~/trunk/src/platform/dev/contrib/variant/create_initial_ec_image.sh') |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 743 | if not bool(run_process( |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 744 | [create_initial_ec_image_sh, |
| 745 | status.board, |
| 746 | status.variant, |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 747 | status.bug])): |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 748 | return False |
| 749 | |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 750 | ec_src_dir = os.path.expanduser('~/trunk/src/platform/ec/board') |
| 751 | # No need to `if rc:` because we already tested the run_process result above |
| 752 | status.commits['ec_image'] = get_git_commit_data(ec_src_dir) |
| 753 | |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 754 | # create_initial_ec_image.sh will build the ec.bin for this variant |
| 755 | # if successful. |
| 756 | ec = os.path.expanduser('~/trunk/src/platform/ec') |
| 757 | logging.debug('ec = "%s"', ec) |
| 758 | ec_bin = 'build/' + status.variant + '/ec.bin' |
| 759 | logging.debug('ec.bin = "%s"', ec_bin) |
| 760 | |
| 761 | return file_exists(ec, ec_bin) |
| 762 | |
| 763 | |
| 764 | def ec_buildall(status): |
| 765 | """Do a make buildall -j for the EC, which is required for repo upload |
| 766 | |
| 767 | The upload hook checks to ensure that the entire EC codebase builds |
| 768 | without error, so we have to run make buildall -j before uploading. |
| 769 | |
| 770 | Params: |
| 771 | status variant_status object tracking our board, variant, etc. |
| 772 | |
| 773 | Returns: |
| 774 | True if the script and test build succeeded, False if something failed |
| 775 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 776 | logging.info('Running step ec_buildall') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 777 | del status # unused parameter |
| 778 | ec = os.path.expanduser('~/trunk/src/platform/ec') |
| 779 | logging.debug('ec = "%s"', ec) |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 780 | return bool(run_process(['make', 'buildall', '-j'], cwd=ec)) |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 781 | |
| 782 | |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 783 | def add_variant_to_public_yaml(status): |
| 784 | """Add the new variant to the public model.yaml file |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 785 | |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 786 | This function calls add_variant_to_yaml.sh to add the new variant to |
| 787 | the public model.yaml file. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 788 | |
| 789 | Params: |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 790 | status variant_status object tracking our board, variant, etc. |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 791 | |
| 792 | Returns: |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 793 | True if the script succeeded, False is something failed |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 794 | """ |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 795 | logging.info('Running step add_variant_to_public_yaml') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 796 | add_variant_to_yaml_sh = os.path.expanduser( |
| 797 | '~/trunk/src/platform/dev/contrib/variant/add_variant_to_yaml.sh') |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 798 | rc = bool(run_process( |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 799 | [add_variant_to_yaml_sh, |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 800 | status.base, |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 801 | status.variant, |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 802 | status.bug])) |
| 803 | if rc: |
| 804 | status.commits['public_yaml'] = get_git_commit_data('~/trunk/src/overlays') |
| 805 | return rc |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 806 | |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 807 | |
| 808 | def add_variant_to_private_yaml(status): |
| 809 | """Add the new variant to the private model.yaml file |
| 810 | |
| 811 | This function calls add_variant.sh to add the new variant to |
| 812 | the private model.yaml file. |
| 813 | |
| 814 | Params: |
| 815 | status variant_status object tracking our board, variant, etc. |
| 816 | |
| 817 | Returns: |
| 818 | True if the script succeeded, False is something failed |
| 819 | """ |
| 820 | logging.info('Running step add_variant_to_private_yaml') |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 821 | add_variant_sh = os.path.expanduser(os.path.join(status.private_yaml_dir, 'add_variant.sh')) |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 822 | rc = bool(run_process( |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 823 | [add_variant_sh, |
| 824 | status.variant, |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 825 | status.bug])) |
Paul Fagerburg | 1d043c3 | 2020-02-03 08:57:08 -0700 | [diff] [blame^] | 826 | if rc: |
| 827 | status.commits['private_yaml'] = get_git_commit_data(status.private_yaml_dir) |
| 828 | return rc |
| 829 | |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 830 | |
| 831 | |
| 832 | def build_yaml(status): |
| 833 | """Build config files from the yaml files |
| 834 | |
| 835 | This function builds the yaml files into the JSON and C code that |
| 836 | mosys and other tools use, then verifies that the new variant's name |
| 837 | shows up in all of the output files. |
| 838 | |
| 839 | Params: |
| 840 | status variant_status object tracking our board, variant, etc. |
| 841 | |
| 842 | Returns: |
| 843 | True if the scripts and build succeeded, False is something failed |
| 844 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 845 | logging.info('Running step build_yaml') |
| 846 | if not bool(run_process([status.emerge_cmd] + status.yaml_emerge_pkgs)): |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 847 | return False |
| 848 | |
| 849 | # Check generated files for occurences of the variant name. |
| 850 | # Each file should have at least one occurence, so use `grep -c` to |
| 851 | # count the occurrences of the variant name in each file. |
| 852 | # The results will be something like this: |
| 853 | # config.json:10 |
| 854 | # yaml/config.c:6 |
| 855 | # yaml/config.yaml:27 |
| 856 | # yaml/model.yaml:6 |
| 857 | # yaml/private-model.yaml:10 |
| 858 | # If the variant name doesn't show up in the file, then the count |
| 859 | # will be 0, so we would see, e.g. |
| 860 | # config.json:0 |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 861 | # Note that we leave out yaml/model.yaml (the public one) because for |
| 862 | # some boards, there is nothing in the public yaml file. |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 863 | # We gather the output from grep, then look for any of the strings |
| 864 | # ending in :0. If none of them match, then we're good, but if even |
| 865 | # one of them ends with :0 then there was a problem with generating |
| 866 | # the files from the yaml. |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 867 | chromeos_config = '/build/' + status.base + '/usr/share/chromeos-config' |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 868 | logging.debug('chromeos_config = "%s"', chromeos_config) |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 869 | grep = run_process( |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 870 | ['grep', |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 871 | '-ci', |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 872 | status.variant, |
| 873 | 'config.json', |
| 874 | 'yaml/config.c', |
| 875 | 'yaml/config.yaml', |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 876 | 'yaml/private-model.yaml'], cwd=chromeos_config, capture_output=True) |
| 877 | |
| 878 | if grep is None: |
| 879 | return False |
| 880 | |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 881 | return not bool([s for s in grep if re.search(r':0$', s)]) |
| 882 | |
| 883 | |
| 884 | def emerge_all(status): |
| 885 | """Build the coreboot BIOS and EC code for the new variant |
| 886 | |
| 887 | Params: |
| 888 | status variant_status object tracking our board, variant, etc. |
| 889 | |
| 890 | Returns: |
| 891 | True if the build succeeded, False if something failed |
| 892 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 893 | logging.info('Running step emerge_all') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 894 | cros_workon(status, 'start') |
| 895 | environ = os.environ.copy() |
| 896 | environ['FW_NAME'] = status.variant |
| 897 | # Build up the command for emerge from all the packages in the list |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 898 | emerge_cmd_and_params = [status.emerge_cmd] + status.emerge_pkgs |
| 899 | if not bool(run_process(emerge_cmd_and_params, env=environ)): |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 900 | return False |
| 901 | |
| 902 | cros_workon(status, 'stop') |
Paul Fagerburg | e868e83 | 2020-01-22 17:14:04 -0700 | [diff] [blame] | 903 | build_path = '/build/' + status.base + '/firmware' |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 904 | logging.debug('build_path = "%s"', build_path) |
| 905 | if not file_exists(build_path, 'image-' + status.variant + '.bin'): |
| 906 | logging.error('emerge failed because image-%s.bin does not exist', |
| 907 | status.variant) |
| 908 | return False |
| 909 | |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 910 | if not file_exists(build_path, 'image-' + status.variant + '.serial.bin'): |
| 911 | logging.error('emerge failed because image-%s.serial.bin does not exist', |
| 912 | status.variant) |
| 913 | return False |
| 914 | |
| 915 | return True |
| 916 | |
| 917 | |
| 918 | def push_coreboot(status): |
| 919 | """Push the coreboot CL to coreboot.org |
| 920 | |
| 921 | Params: |
| 922 | status variant_status object tracking our board, variant, etc. |
| 923 | |
| 924 | Returns: |
| 925 | True if the build succeeded, False if something failed |
| 926 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 927 | logging.info('Running step push_coreboot') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 928 | del status # unused parameter |
| 929 | logging.error('TODO (pfagerburg): implement push_coreboot') |
| 930 | return True |
| 931 | |
| 932 | |
| 933 | def upload_CLs(status): |
| 934 | """Upload all CLs to chromiumos |
| 935 | |
| 936 | Params: |
| 937 | status variant_status object tracking our board, variant, etc. |
| 938 | |
| 939 | Returns: |
| 940 | True if the build succeeded, False if something failed |
| 941 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 942 | logging.info('Running step upload_CLs') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 943 | del status # unused parameter |
| 944 | logging.error('TODO (pfagerburg): implement upload_CLs') |
| 945 | return True |
| 946 | |
| 947 | |
| 948 | def find_coreboot_upstream(status): |
| 949 | """Find the coreboot CL after it has been upstreamed to chromiumos |
| 950 | |
| 951 | Params: |
| 952 | status variant_status object tracking our board, variant, etc. |
| 953 | |
| 954 | Returns: |
| 955 | True if the build succeeded, False if something failed |
| 956 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 957 | logging.info('Running step find_coreboot_upstream') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 958 | del status # unused parameter |
| 959 | logging.error('TODO (pfagerburg): implement find_coreboot_upstream') |
| 960 | return True |
| 961 | |
| 962 | |
| 963 | def add_cq_depends(status): |
| 964 | """Add Cq-Depends to all of the CLs in chromiumos |
| 965 | |
| 966 | The CL in coreboot needs to be pushed to coreboot.org, get merged, |
| 967 | and then get upstreamed into the chromiumos tree before the other |
| 968 | CLs can cq-depend on it and pass CQ. |
| 969 | |
| 970 | Params: |
| 971 | status variant_status object tracking our board, variant, etc. |
| 972 | |
| 973 | Returns: |
| 974 | True if the build succeeded, False if something failed |
| 975 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 976 | logging.info('Running step add_cq_depends') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 977 | del status # unused parameter |
| 978 | logging.error('TODO (pfagerburg): implement add_cq_depends') |
| 979 | return True |
| 980 | |
| 981 | |
| 982 | def clean_up(status): |
| 983 | """Final clean-up, including delete the status file |
| 984 | |
| 985 | Params: |
| 986 | status variant_status object tracking our board, variant, etc. |
| 987 | |
| 988 | Returns: |
| 989 | True |
| 990 | """ |
Paul Fagerburg | bab5dde | 2020-01-10 15:10:29 -0700 | [diff] [blame] | 991 | logging.info('Running step clean_up') |
Paul Fagerburg | 3b534f9 | 2019-11-07 15:05:22 -0700 | [diff] [blame] | 992 | status.rm() |
| 993 | return True |
| 994 | |
| 995 | |
| 996 | if __name__ == '__main__': |
| 997 | sys.exit(not int(main())) |