blob: 2bcd6533c6df3b1f713394d1cd7ad8a6701853df [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2013 The ChromiumOS Authors
Simon Glass02741682013-05-26 07:07:58 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""crosfw - Chrome OS Firmware build/flash script.
6
7Builds a firmware image for any board and writes it to the board. The image
8can be pure upstream or include Chrome OS components (-V). Some device
9tree parameters can be provided, including silent console (-C) and secure
10boot (-S). Use -i for a faster incremental build. The image is written to
11the board by default using USB/em100 (or sdcard with -x). Use -b to specify
12the board to build. Options can be added to ~/.crosfwrc - see the script for
13details.
14
15It can also flash SPI by writing a 'magic flasher' U-Boot with a payload
16to the board.
17
Simon Glass02741682013-05-26 07:07:58 -070018The script is normally run from within the U-Boot directory which is
19.../src/third_party/u-boot/files
20
21Example 1: Build upstream image for coreboot and write to a 'link':
22
23 crosfw -b link
24
25Example 2: Build verified boot image (V) for daisy/snow and boot in secure
26 mode (S) so that breaking in on boot is not possible.
27
28 crosfw -b daisy -VS
29 crosfw -b daisy -VSC (no console output)
30
31Example 3: Build a magic flasher (F) with full verified boot for peach_pit,
32 but with console enabled, write to SD card (x)
33
34 crosfw -b peach_pit -VSFx
35
36This sript does not use an ebuild. It does a similar thing to the
37chromeos-u-boot ebuild, and runs cros_bundle_firmware to produce various
38types of image, a little like the chromeos-bootimage ebuild.
39
40The purpose of this script is to make it easier and faster to perform
41common firmware build tasks without changing boards, manually updating
42device tree files or lots of USE flags and complexity in the ebuilds.
43
44This script has been tested with snow, link and peach_pit. It builds for
45peach_pit by default. Note that it will also build any upstream ARM
46board - e.g. "-b snapper9260" will build an image for that board.
47
48Mostly you can use the script inside and outside the chroot. The main
49limitation is that dut-control doesn't really work outside the chroot,
50so writing the image to the board over USB is not possible, nor can the
51board be automatically reset on x86 platforms.
52
53For an incremental build (faster), run with -i
54
55To get faster clean builds, install ccache, and create ~/.crosfwrc with
56this line:
57
Simon Glass6ddc7f12013-07-18 15:22:41 -060058 USE_CCACHE = True
Simon Glass02741682013-05-26 07:07:58 -070059
60(make sure ~/.ccache is not on NFS, or set CCACHE_DIR)
61
62Other options are the default board to build, and verbosity (0-4), e.g.:
63
Simon Glass6ddc7f12013-07-18 15:22:41 -060064 DEFAULT_BOARD = 'daisy'
65 VERBOSE = 1
Simon Glass02741682013-05-26 07:07:58 -070066
67It is possible to use multiple servo boards, each on its own port. Add
68these lines to your ~/.crosfwrc to set the servo port to use for each
69board:
70
71 SERVO_PORT['link'] = 8888
72 SERVO_PORT['daisy'] = 9999
73 SERVO_PORT['peach_pit'] = 7777
74
Simon Glassb89ae892013-07-18 15:23:35 -060075All builds appear in the <outdir>/<board> subdirectory and images are written
76to <outdir>/<uboard>/out, where <uboard> is the U-Boot name for the board (in
77the U-Boot boards.cfg file)
78
79The value for <outdir> defaults to /tmp/crosfw but can be configured in your
80~/.crosfwrc file, e.g.:"
81
82 OUT_DIR = '/tmp/u-boot'
Simon Glass02741682013-05-26 07:07:58 -070083
84For the -a option here are some useful options:
85
86--add-blob cros-splash /dev/null
87--gbb-flags -force-dev-switch-on
88--add-node-enable /spi@131b0000/cros-ecp@0 1
89--verify --full-erase
90--bootcmd "cros_test sha"
91--gbb-flags -force-dev-switch-on
Mike Frysinger0246c1f2021-12-14 01:17:17 -050092--bmpblk ~/chromiumos/src/third_party/u-boot/bmp.bin
Simon Glass02741682013-05-26 07:07:58 -070093
94For example: -a "--gbb-flags -force-dev-switch-on"
95
96Note the standard bmpblk is at:
Mike Frysinger0246c1f2021-12-14 01:17:17 -050097 ~/chromiumos/src/third_party/chromiumos-overlay/sys-boot/
98 chromeos-bootimage/files/bmpblk.bin
Simon Glass02741682013-05-26 07:07:58 -070099"""
100
101import glob
Chris McDonald59650c32021-07-20 15:29:28 -0600102import logging
Simon Glass02741682013-05-26 07:07:58 -0700103import multiprocessing
104import os
105import re
Mike Frysinger66d32cd2019-12-17 14:55:29 -0500106import subprocess
Simon Glass02741682013-05-26 07:07:58 -0700107import sys
108
Simon Glass02741682013-05-26 07:07:58 -0700109from chromite.lib import commandline
Chris McDonald59650c32021-07-20 15:29:28 -0600110from chromite.lib import constants
Simon Glass02741682013-05-26 07:07:58 -0700111from chromite.lib import cros_build_lib
112from chromite.lib import osutils
113from chromite.lib import parallel
114
115
116arch = None
117board = None
118compiler = None
119default_board = None
120family = None
121in_chroot = True
122
Alex Klein1699fab2022-09-08 08:46:06 -0600123kwargs = {
124 "print_cmd": False,
125 "check": False,
Simon Glassdee7d6b2023-02-10 11:35:18 -0700126 "encoding": "utf-8",
Alex Klein1699fab2022-09-08 08:46:06 -0600127}
Simon Glass02741682013-05-26 07:07:58 -0700128
Alex Klein1699fab2022-09-08 08:46:06 -0600129outdir = ""
Simon Glass02741682013-05-26 07:07:58 -0700130
Alex Klein1699fab2022-09-08 08:46:06 -0600131# If you have multiple boards connected on different servo ports, put lines
Simon Glass02741682013-05-26 07:07:58 -0700132# like 'SERVO_PORT{"peach_pit"} = 7777' in your ~/.crosfwrc
133SERVO_PORT = {}
134
135smdk = None
Alex Klein1699fab2022-09-08 08:46:06 -0600136src_root = os.path.join(constants.SOURCE_ROOT, "src")
Simon Glass02741682013-05-26 07:07:58 -0700137in_chroot = cros_build_lib.IsInsideChroot()
138
Alex Klein1699fab2022-09-08 08:46:06 -0600139uboard = ""
Simon Glass02741682013-05-26 07:07:58 -0700140
Alex Klein1699fab2022-09-08 08:46:06 -0600141default_board = "peach_pit"
Simon Glass02741682013-05-26 07:07:58 -0700142use_ccache = False
143vendor = None
Simon Glass02741682013-05-26 07:07:58 -0700144
145# Special cases for the U-Boot board config, the SOCs and default device tree
146# since the naming is not always consistent.
147# x86 has a lot of boards, but to U-Boot they are all the same
148UBOARDS = {
Alex Klein1699fab2022-09-08 08:46:06 -0600149 "daisy": "smdk5250",
150 "peach": "smdk5420",
Simon Glass02741682013-05-26 07:07:58 -0700151}
Alex Klein1699fab2022-09-08 08:46:06 -0600152for b in [
153 "alex",
154 "butterfly",
155 "emeraldlake2",
156 "link",
157 "lumpy",
158 "parrot",
159 "stout",
160 "stumpy",
161]:
162 UBOARDS[b] = "coreboot-x86"
163 UBOARDS["chromeos_%s" % b] = "chromeos_coreboot"
Simon Glass02741682013-05-26 07:07:58 -0700164
165SOCS = {
Alex Klein1699fab2022-09-08 08:46:06 -0600166 "coreboot-x86": "",
167 "chromeos_coreboot": "",
168 "daisy": "exynos5250-",
169 "peach": "exynos5420-",
Simon Glass02741682013-05-26 07:07:58 -0700170}
171
172DEFAULT_DTS = {
Alex Klein1699fab2022-09-08 08:46:06 -0600173 "daisy": "snow",
174 "daisy_spring": "spring",
175 "peach_pit": "peach-pit",
Simon Glass02741682013-05-26 07:07:58 -0700176}
177
Alex Klein1699fab2022-09-08 08:46:06 -0600178OUT_DIR = "/tmp/crosfw"
Simon Glassb89ae892013-07-18 15:23:35 -0600179
Alex Klein1699fab2022-09-08 08:46:06 -0600180rc_file = os.path.expanduser("~/.crosfwrc")
Simon Glass02741682013-05-26 07:07:58 -0700181if os.path.exists(rc_file):
Alex Klein1699fab2022-09-08 08:46:06 -0600182 with open(rc_file) as fp:
183 # pylint: disable=exec-used
184 exec(compile(fp.read(), rc_file, "exec"))
Simon Glass02741682013-05-26 07:07:58 -0700185
186
Simon Glass02741682013-05-26 07:07:58 -0700187def Dumper(flag, infile, outfile):
Alex Klein1699fab2022-09-08 08:46:06 -0600188 """Run objdump on an input file.
Simon Glass02741682013-05-26 07:07:58 -0700189
Alex Klein1699fab2022-09-08 08:46:06 -0600190 Args:
191 flag: Flag to pass objdump (e.g. '-d').
192 infile: Input file to process.
193 outfile: Output file to write to.
194 """
195 result = cros_build_lib.run(
196 [CompilerTool("objdump"), flag, infile], stdout=outfile, **kwargs
197 )
198 if result.returncode:
199 sys.exit()
Simon Glass02741682013-05-26 07:07:58 -0700200
201
202def CompilerTool(tool):
Alex Klein1699fab2022-09-08 08:46:06 -0600203 """Returns the cross-compiler tool filename.
Simon Glass02741682013-05-26 07:07:58 -0700204
Alex Klein1699fab2022-09-08 08:46:06 -0600205 Args:
206 tool: Tool name to return, e.g. 'size'.
Simon Glass02741682013-05-26 07:07:58 -0700207
Alex Klein1699fab2022-09-08 08:46:06 -0600208 Returns:
209 Filename of requested tool.
210 """
211 return "%s%s" % (compiler, tool)
Simon Glass02741682013-05-26 07:07:58 -0700212
213
214def ParseCmdline(argv):
Alex Klein1699fab2022-09-08 08:46:06 -0600215 """Parse all command line options.
Simon Glass02741682013-05-26 07:07:58 -0700216
Alex Klein1699fab2022-09-08 08:46:06 -0600217 Args:
218 argv: Arguments to parse.
Simon Glass02741682013-05-26 07:07:58 -0700219
Alex Klein1699fab2022-09-08 08:46:06 -0600220 Returns:
221 The parsed options object
222 """
Simon Glass95a316d2023-02-10 11:31:47 -0700223 parser = commandline.ArgumentParser(
224 description=__doc__, default_log_level="notice"
225 )
Alex Klein1699fab2022-09-08 08:46:06 -0600226 parser.add_argument(
Alex Klein1699fab2022-09-08 08:46:06 -0600227 "-B",
228 "--build",
229 action="store_false",
230 default=True,
231 help="Don't build U-Boot, just configure device tree",
232 )
233 parser.add_argument(
Alex Klein1699fab2022-09-08 08:46:06 -0600234 "-d",
235 "--dt",
236 default="seaboard",
237 help="Select name of device tree file to use",
238 )
239 parser.add_argument(
Alex Klein1699fab2022-09-08 08:46:06 -0600240 "-i",
241 "--incremental",
242 action="store_true",
243 default=False,
244 help="Don't reconfigure and clean",
245 )
246 parser.add_argument(
Alex Klein1699fab2022-09-08 08:46:06 -0600247 "-O",
248 "--objdump",
249 action="store_true",
250 default=False,
251 help="Write disassembly output",
252 )
253 parser.add_argument(
Alex Klein1699fab2022-09-08 08:46:06 -0600254 "-t",
255 "--trace",
256 action="store_true",
257 default=False,
258 help="Enable trace support",
259 )
260 parser.add_argument(
Simon Glassa68488c2023-02-09 16:53:47 -0700261 "-T",
262 "--target",
263 nargs="?",
264 default="all",
265 help="Select target to build",
266 )
267 parser.add_argument(
Alex Klein1699fab2022-09-08 08:46:06 -0600268 "-V",
269 "--verified",
270 action="store_true",
271 default=False,
272 help="Include Chrome OS verified boot components",
273 )
274 parser.add_argument(
Alex Klein1699fab2022-09-08 08:46:06 -0600275 "-z",
276 "--size",
277 action="store_true",
278 default=False,
279 help="Display U-Boot image size",
280 )
281 parser.add_argument(
Simon Glassa68488c2023-02-09 16:53:47 -0700282 "board",
283 type=str,
284 default=default_board,
285 help="Select board to build (daisy/peach_pit/link)",
Alex Klein1699fab2022-09-08 08:46:06 -0600286 )
287 return parser.parse_args(argv)
Simon Glass02741682013-05-26 07:07:58 -0700288
289
Simon Glassc1a323a2016-08-04 20:29:51 -0600290def FindCompiler(gcc, cros_prefix):
Alex Klein1699fab2022-09-08 08:46:06 -0600291 """Look up the compiler for an architecture.
Simon Glassc1a323a2016-08-04 20:29:51 -0600292
Alex Klein1699fab2022-09-08 08:46:06 -0600293 Args:
294 gcc: GCC architecture, either 'arm' or 'aarch64'
295 cros_prefix: Full Chromium OS toolchain prefix
296 """
297 if in_chroot:
298 # Use the Chromium OS toolchain.
299 prefix = cros_prefix
300 else:
301 prefix = glob.glob("/opt/linaro/gcc-linaro-%s-linux-*/bin/*gcc" % gcc)
302 if not prefix:
303 cros_build_lib.Die(
304 """Please install an %s toolchain for your machine.
Simon Glassc1a323a2016-08-04 20:29:51 -0600305Install a Linaro toolchain from:
306https://launchpad.net/linaro-toolchain-binaries
Alex Klein1699fab2022-09-08 08:46:06 -0600307or see cros/commands/cros_chrome_sdk.py."""
308 % gcc
309 )
310 prefix = re.sub("gcc$", "", prefix[0])
311 return prefix
Simon Glassc1a323a2016-08-04 20:29:51 -0600312
313
Simon Glass02741682013-05-26 07:07:58 -0700314def SetupBuild(options):
Alex Klein1699fab2022-09-08 08:46:06 -0600315 """Set up parameters needed for the build.
Simon Glass02741682013-05-26 07:07:58 -0700316
Alex Klein1699fab2022-09-08 08:46:06 -0600317 This checks the current environment and options and sets up various things
318 needed for the build, including 'base' which holds the base flags for
319 passing to the U-Boot Makefile.
Simon Glass02741682013-05-26 07:07:58 -0700320
Alex Klein1699fab2022-09-08 08:46:06 -0600321 Args:
322 options: Command line options
Simon Glass02741682013-05-26 07:07:58 -0700323
Alex Klein1699fab2022-09-08 08:46:06 -0600324 Returns:
325 Base flags to use for U-Boot, as a list.
326 """
327 # pylint: disable=global-statement
Simon Glass95a316d2023-02-10 11:31:47 -0700328 global arch, board, compiler, family, outdir, smdk, uboard, vendor
Simon Glass02741682013-05-26 07:07:58 -0700329
Simon Glass9674afc2023-02-10 11:21:30 -0700330 logging.info("Building for %s", options.board)
Simon Glass02741682013-05-26 07:07:58 -0700331
Alex Klein1699fab2022-09-08 08:46:06 -0600332 # Separate out board_variant string: "peach_pit" becomes "peach", "pit".
333 # But don't mess up upstream boards which use _ in their name.
334 parts = options.board.split("_")
335 if parts[0] in ["daisy", "peach"]:
336 board = parts[0]
Simon Glass02741682013-05-26 07:07:58 -0700337 else:
Alex Klein1699fab2022-09-08 08:46:06 -0600338 board = options.board
Simon Glass02741682013-05-26 07:07:58 -0700339
Alex Klein1699fab2022-09-08 08:46:06 -0600340 # To allow this to be run from 'cros_sdk'
341 if in_chroot:
342 os.chdir(os.path.join(src_root, "third_party", "u-boot", "files"))
Simon Glass02741682013-05-26 07:07:58 -0700343
Alex Klein1699fab2022-09-08 08:46:06 -0600344 base_board = board
Simon Glass02741682013-05-26 07:07:58 -0700345
Alex Klein1699fab2022-09-08 08:46:06 -0600346 if options.verified:
347 base_board = "chromeos_%s" % base_board
Simon Glass02741682013-05-26 07:07:58 -0700348
Alex Klein1699fab2022-09-08 08:46:06 -0600349 uboard = UBOARDS.get(base_board, base_board)
Simon Glass9674afc2023-02-10 11:21:30 -0700350 logging.info("U-Boot board is %s", uboard)
Simon Glass02741682013-05-26 07:07:58 -0700351
Alex Klein1699fab2022-09-08 08:46:06 -0600352 # Pull out some information from the U-Boot boards config file
353 family = None
354 (PRE_KBUILD, PRE_KCONFIG, KCONFIG) = range(3)
355 if os.path.exists("MAINTAINERS"):
356 board_format = PRE_KBUILD
357 else:
358 board_format = PRE_KCONFIG
359 with open("boards.cfg") as f:
360 for line in f:
361 if "genboardscfg" in line:
362 board_format = KCONFIG
363 if uboard in line:
364 if line[0] == "#":
365 continue
366 fields = line.split()
367 if not fields:
368 continue
Simon Glassa44a1f92023-02-09 16:31:34 -0700369 target = fields[6]
370 # Make sure this is the right target.
371 if target != uboard:
372 continue
Alex Klein1699fab2022-09-08 08:46:06 -0600373 arch = fields[1]
374 fields += [None, None, None]
375 if board_format == PRE_KBUILD:
376 smdk = fields[3]
377 vendor = fields[4]
378 family = fields[5]
Alex Klein1699fab2022-09-08 08:46:06 -0600379 elif board_format in (PRE_KCONFIG, KCONFIG):
380 smdk = fields[5]
381 vendor = fields[4]
382 family = fields[3]
383 target = fields[0]
Alex Klein1699fab2022-09-08 08:46:06 -0600384 if not arch:
385 cros_build_lib.Die(
386 "Selected board '%s' not found in boards.cfg." % board
387 )
Simon Glass02741682013-05-26 07:07:58 -0700388
Alex Klein1699fab2022-09-08 08:46:06 -0600389 vboot = os.path.join("build", board, "usr")
Simon Glassa44a1f92023-02-09 16:31:34 -0700390 if in_chroot:
391 if arch == "x86":
392 compiler = "i686-cros-linux-gnu-"
393 elif arch == "arm":
394 compiler = FindCompiler(arch, "armv7a-cros-linux-gnueabihf-")
395 elif arch == "aarch64":
396 compiler = FindCompiler(arch, "aarch64-cros-linux-gnu-")
Alex Klein1699fab2022-09-08 08:46:06 -0600397 elif arch == "sandbox":
398 compiler = ""
399 else:
Simon Glassa44a1f92023-02-09 16:31:34 -0700400 result = cros_build_lib.run(
401 ["buildman", "-A", "--boards", options.board],
402 capture_output=True,
Simon Glassa44a1f92023-02-09 16:31:34 -0700403 **kwargs,
404 )
405 compiler = result.stdout.strip()
406 if not compiler:
407 cros_build_lib.Die("Selected arch '%s' not supported.", arch)
Simon Glass02741682013-05-26 07:07:58 -0700408
Alex Klein1699fab2022-09-08 08:46:06 -0600409 if not options.build:
410 options.incremental = True
Simon Glass02741682013-05-26 07:07:58 -0700411
Alex Klein1699fab2022-09-08 08:46:06 -0600412 cpus = multiprocessing.cpu_count()
Simon Glass02741682013-05-26 07:07:58 -0700413
Alex Klein1699fab2022-09-08 08:46:06 -0600414 outdir = os.path.join(OUT_DIR, uboard)
415 base = [
416 "make",
417 "-j%d" % cpus,
418 "O=%s" % outdir,
419 "ARCH=%s" % arch,
420 "CROSS_COMPILE=%s" % compiler,
421 "--no-print-directory",
422 "HOSTSTRIP=true",
423 "DEV_TREE_SRC=%s-%s" % (family, options.dt),
424 "QEMU_ARCH=",
425 ]
Simon Glass02741682013-05-26 07:07:58 -0700426
Simon Glass95a316d2023-02-10 11:31:47 -0700427 # Enable quiet output at INFO level, everything at DEBUG level
428 if logging.getLogger().getEffectiveLevel() <= logging.DEBUG:
Alex Klein1699fab2022-09-08 08:46:06 -0600429 base.append("V=1")
Simon Glass95a316d2023-02-10 11:31:47 -0700430 elif logging.getLogger().getEffectiveLevel() >= logging.NOTICE:
431 base.append("-s")
Simon Glass02741682013-05-26 07:07:58 -0700432
Alex Klein1699fab2022-09-08 08:46:06 -0600433 if options.verified:
434 base += [
435 "VBOOT=%s" % vboot,
436 "MAKEFLAGS_VBOOT=DEBUG=1",
437 "QUIET=1",
438 "CFLAGS_EXTRA_VBOOT=-DUNROLL_LOOPS",
439 "VBOOT_SOURCE=%s/platform/vboot_reference" % src_root,
440 ]
441 base.append("VBOOT_DEBUG=1")
442
Alex Klein1699fab2022-09-08 08:46:06 -0600443 base.append("BUILD_ROM=1")
444 if options.trace:
445 base.append("FTRACE=1")
Alex Klein1699fab2022-09-08 08:46:06 -0600446
447 if options.incremental:
Alex Klein1699fab2022-09-08 08:46:06 -0600448 config_mk = "%s/include/autoconf.mk" % outdir
449 if not os.path.exists(config_mk):
450 logging.warning("No build found for %s - dropping -i", board)
451 options.incremental = False
452
453 config_mk = "include/autoconf.mk"
454 if os.path.exists(config_mk):
455 logging.warning("Warning: '%s' exists, try 'make distclean'", config_mk)
456
Alex Klein1699fab2022-09-08 08:46:06 -0600457 return base
Simon Glass02741682013-05-26 07:07:58 -0700458
459
460def RunBuild(options, base, target, queue):
Alex Klein1699fab2022-09-08 08:46:06 -0600461 """Run the U-Boot build.
Simon Glass02741682013-05-26 07:07:58 -0700462
Alex Klein1699fab2022-09-08 08:46:06 -0600463 Args:
464 options: Command line options.
465 base: Base U-Boot flags.
466 target: Target to build.
467 queue: A parallel queue to add jobs to.
468 """
Simon Glass9674afc2023-02-10 11:21:30 -0700469 logging.info("U-Boot build flags: %s", " ".join(base))
Simon Glass02741682013-05-26 07:07:58 -0700470
Alex Klein1699fab2022-09-08 08:46:06 -0600471 # Reconfigure U-Boot.
472 if not options.incremental:
473 # Ignore any error from this, some older U-Boots fail on this.
Simon Glassdee7d6b2023-02-10 11:35:18 -0700474 cros_build_lib.run(base + ["distclean"], capture_output=True, **kwargs)
Alex Klein1699fab2022-09-08 08:46:06 -0600475 if os.path.exists("tools/genboardscfg.py"):
476 mtarget = "defconfig"
477 else:
478 mtarget = "config"
479 cmd = base + ["%s_%s" % (uboard, mtarget)]
480 result = cros_build_lib.run(
481 cmd, stdout=True, stderr=subprocess.STDOUT, **kwargs
482 )
Simon Glassdee7d6b2023-02-10 11:35:18 -0700483 if (
484 result.returncode
485 or logging.getLogger().getEffectiveLevel() <= logging.DEBUG
486 ):
487 print(f"cmd: {result.cmdstr}")
488 print(result.stdout, file=sys.stderr)
489 if result.returncode:
490 sys.exit(result.returncode)
Simon Glass02741682013-05-26 07:07:58 -0700491
Alex Klein1699fab2022-09-08 08:46:06 -0600492 # Do the actual build.
493 if options.build:
494 result = cros_build_lib.run(
495 base + [target], stdout=True, stderr=subprocess.STDOUT, **kwargs
496 )
Simon Glassdee7d6b2023-02-10 11:35:18 -0700497 if (
498 result.returncode
499 or logging.getLogger().getEffectiveLevel() <= logging.INFO
500 ):
Alex Klein1699fab2022-09-08 08:46:06 -0600501 # The build failed, so output the results to stderr.
Simon Glassdee7d6b2023-02-10 11:35:18 -0700502 print(f"cmd: {result.cmdstr}")
503 print(result.stdout, file=sys.stderr)
504 if result.returncode:
505 sys.exit(result.returncode)
Simon Glass02741682013-05-26 07:07:58 -0700506
Alex Klein1699fab2022-09-08 08:46:06 -0600507 files = ["%s/u-boot" % outdir]
508 spl = glob.glob("%s/spl/u-boot-spl" % outdir)
509 if spl:
510 files += spl
511 if options.size:
512 result = cros_build_lib.run([CompilerTool("size")] + files, **kwargs)
513 if result.returncode:
514 sys.exit()
Simon Glass02741682013-05-26 07:07:58 -0700515
Alex Klein1699fab2022-09-08 08:46:06 -0600516 # Create disassembly files .dis and .Dis (full dump)
517 for f in files:
518 base = os.path.splitext(f)[0]
519 if options.objdump:
520 queue.put(("-d", f, base + ".dis"))
521 queue.put(("-D", f, base + ".Dis"))
522 else:
523 # Remove old files which otherwise might be confusing
524 osutils.SafeUnlink(base + ".dis")
525 osutils.SafeUnlink(base + ".Dis")
Simon Glass02741682013-05-26 07:07:58 -0700526
Simon Glass9674afc2023-02-10 11:21:30 -0700527 logging.info("Output directory %s", outdir)
Simon Glass02741682013-05-26 07:07:58 -0700528
529
Simon Glass02741682013-05-26 07:07:58 -0700530def main(argv):
Simon Glasse6201d72023-02-09 16:42:22 -0700531 """Main function for script to build firmware.
Simon Glass02741682013-05-26 07:07:58 -0700532
Alex Klein1699fab2022-09-08 08:46:06 -0600533 Args:
534 argv: Program arguments.
535 """
536 options = ParseCmdline(argv)
537 base = SetupBuild(options)
Simon Glass02741682013-05-26 07:07:58 -0700538
Alex Klein1699fab2022-09-08 08:46:06 -0600539 with parallel.BackgroundTaskRunner(Dumper) as queue:
540 RunBuild(options, base, options.target, queue)
Simon Glass02741682013-05-26 07:07:58 -0700541
Alex Klein1699fab2022-09-08 08:46:06 -0600542 if options.objdump:
Simon Glass9674afc2023-02-10 11:21:30 -0700543 logging.info("Writing diasssembly files")