blob: d9cd1209a07aaddbade5b842b2a6c83201fedf0e [file] [log] [blame]
Simon Glass02741682013-05-26 07:07:58 -07001# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2# 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
18Usage: crosfw [options]
19
20The script is normally run from within the U-Boot directory which is
21.../src/third_party/u-boot/files
22
23Example 1: Build upstream image for coreboot and write to a 'link':
24
25 crosfw -b link
26
27Example 2: Build verified boot image (V) for daisy/snow and boot in secure
28 mode (S) so that breaking in on boot is not possible.
29
30 crosfw -b daisy -VS
31 crosfw -b daisy -VSC (no console output)
32
33Example 3: Build a magic flasher (F) with full verified boot for peach_pit,
34 but with console enabled, write to SD card (x)
35
36 crosfw -b peach_pit -VSFx
37
38This sript does not use an ebuild. It does a similar thing to the
39chromeos-u-boot ebuild, and runs cros_bundle_firmware to produce various
40types of image, a little like the chromeos-bootimage ebuild.
41
42The purpose of this script is to make it easier and faster to perform
43common firmware build tasks without changing boards, manually updating
44device tree files or lots of USE flags and complexity in the ebuilds.
45
46This script has been tested with snow, link and peach_pit. It builds for
47peach_pit by default. Note that it will also build any upstream ARM
48board - e.g. "-b snapper9260" will build an image for that board.
49
50Mostly you can use the script inside and outside the chroot. The main
51limitation is that dut-control doesn't really work outside the chroot,
52so writing the image to the board over USB is not possible, nor can the
53board be automatically reset on x86 platforms.
54
55For an incremental build (faster), run with -i
56
57To get faster clean builds, install ccache, and create ~/.crosfwrc with
58this line:
59
Simon Glass6ddc7f12013-07-18 15:22:41 -060060 USE_CCACHE = True
Simon Glass02741682013-05-26 07:07:58 -070061
62(make sure ~/.ccache is not on NFS, or set CCACHE_DIR)
63
64Other options are the default board to build, and verbosity (0-4), e.g.:
65
Simon Glass6ddc7f12013-07-18 15:22:41 -060066 DEFAULT_BOARD = 'daisy'
67 VERBOSE = 1
Simon Glass02741682013-05-26 07:07:58 -070068
69It is possible to use multiple servo boards, each on its own port. Add
70these lines to your ~/.crosfwrc to set the servo port to use for each
71board:
72
73 SERVO_PORT['link'] = 8888
74 SERVO_PORT['daisy'] = 9999
75 SERVO_PORT['peach_pit'] = 7777
76
Simon Glassb89ae892013-07-18 15:23:35 -060077All builds appear in the <outdir>/<board> subdirectory and images are written
78to <outdir>/<uboard>/out, where <uboard> is the U-Boot name for the board (in
79the U-Boot boards.cfg file)
80
81The value for <outdir> defaults to /tmp/crosfw but can be configured in your
82~/.crosfwrc file, e.g.:"
83
84 OUT_DIR = '/tmp/u-boot'
Simon Glass02741682013-05-26 07:07:58 -070085
86For the -a option here are some useful options:
87
88--add-blob cros-splash /dev/null
89--gbb-flags -force-dev-switch-on
90--add-node-enable /spi@131b0000/cros-ecp@0 1
91--verify --full-erase
92--bootcmd "cros_test sha"
93--gbb-flags -force-dev-switch-on
94--bmpblk ~/trunk/src/third_party/u-boot/bmp.bin
95
96For example: -a "--gbb-flags -force-dev-switch-on"
97
98Note the standard bmpblk is at:
99 /home/$USER/trunk/src/third_party/chromiumos-overlay/sys-boot/
100 chromeos-bootimage/files/bmpblk.bin"
101"""
102
103import glob
104import logging
105import multiprocessing
106import os
107import re
108import sys
109
Don Garrett88b8d782014-05-13 17:30:55 -0700110from chromite.cbuildbot import constants
Simon Glass02741682013-05-26 07:07:58 -0700111from chromite.lib import commandline
112from chromite.lib import cros_build_lib
113from chromite.lib import osutils
114from chromite.lib import parallel
115
116
117arch = None
118board = None
119compiler = None
120default_board = None
121family = None
122in_chroot = True
123
124logger = logging.getLogger('chromite')
125logging.basicConfig(format='%(message)s')
126kwargs = {'print_cmd': False, 'error_code_ok': True,
127 'debug_level': logger.getEffectiveLevel()}
128
129outdir = ''
130
131 # If you have multiple boards connected on different servo ports, put lines
132# like 'SERVO_PORT{"peach_pit"} = 7777' in your ~/.crosfwrc
133SERVO_PORT = {}
134
135smdk = None
136src_root = os.path.join(constants.SOURCE_ROOT, 'src')
137in_chroot = cros_build_lib.IsInsideChroot()
138
139uboard = ''
140
141default_board = 'peach_pit'
142use_ccache = False
143vendor = None
144verbose = False
145
146# Special cases for the U-Boot board config, the SOCs and default device tree
147# since the naming is not always consistent.
148# x86 has a lot of boards, but to U-Boot they are all the same
149UBOARDS = {
150 'daisy': 'smdk5250',
151 'peach': 'smdk5420',
152}
153for b in ['alex', 'butterfly', 'emeraldlake2', 'link', 'lumpy', 'parrot',
154 'stout', 'stumpy']:
155 UBOARDS[b] = 'coreboot-x86'
156 UBOARDS['chromeos_%s' % b] = 'chromeos_coreboot'
157
158SOCS = {
159 'coreboot-x86': '',
160 'chromeos_coreboot': '',
161 'daisy': 'exynos5250-',
162 'peach': 'exynos5420-',
163}
164
165DEFAULT_DTS = {
166 'daisy': 'snow',
167 'daisy_spring': 'spring',
168 'peach_pit': 'peach-pit',
169}
170
Simon Glassb89ae892013-07-18 15:23:35 -0600171OUT_DIR = '/tmp/crosfw'
172
Simon Glass02741682013-05-26 07:07:58 -0700173rc_file = os.path.expanduser('~/.crosfwrc')
174if os.path.exists(rc_file):
175 execfile(rc_file)
176
177
178def Log(msg):
179 """Print out a message if we are in verbose mode.
180
181 Args:
182 msg: Message to print
183 """
184 if verbose:
185 cros_build_lib.Info(msg)
186
187
188def Dumper(flag, infile, outfile):
189 """Run objdump on an input file.
190
191 Args:
192 flag: Flag to pass objdump (e.g. '-d').
193 infile: Input file to process.
194 outfile: Output file to write to.
195 """
196 result = cros_build_lib.RunCommand(
197 [CompilerTool('objdump'), flag, infile],
198 log_stdout_to_file=outfile, **kwargs)
199 if result.returncode:
200 sys.exit()
201
202
203def CompilerTool(tool):
204 """Returns the cross-compiler tool filename.
205
206 Args:
207 tool: Tool name to return, e.g. 'size'.
208
209 Returns:
210 Filename of requested tool.
211 """
212 return '%s%s' % (compiler, tool)
213
214
215def ParseCmdline(argv):
216 """Parse all command line options.
217
218 Args:
219 argv: Arguments to parse.
220
221 Returns:
222 Tuple containing:
223 options: Command line options from optpase
224 args: List of command line arguments
225 """
226 parser = commandline.OptionParser(__doc__)
227 parser.add_option('-a', '--cbfargs', action='append',
228 help='Pass extra arguments to cros_bundle_firmware')
229 parser.add_option('-b', '--board', type='string', default=default_board,
230 help='Select board to build (daisy/peach_pit/link)')
231 parser.add_option('-B', '--build', action='store_false', default=True,
232 help="Don't build U-Boot, just configure device tree")
233 parser.add_option('-C', '--console', action='store_false', default=True,
234 help='Permit console output')
235 parser.add_option('-d', '--dt', default='seaboard',
236 help='Select name of device tree file to use')
237 parser.add_option('-D', '--nodefaults', dest='use_defaults',
238 action='store_false', default=True,
239 help="Don't select default filenames for those not given")
240 parser.add_option('-F', '--flash', action='store_true', default=False,
Michael Prattc88035d2013-07-31 16:27:29 -0700241 help='Create magic flasher for SPI flash')
242 parser.add_option('-M', '--mmc', action='store_true', default=False,
243 help='Create magic flasher for eMMC')
Simon Glass02741682013-05-26 07:07:58 -0700244 parser.add_option('-i', '--incremental', action='store_true', default=False,
245 help="Don't reconfigure and clean")
246 parser.add_option('-k', '--kernel', action='store_true', default=False,
247 help='Send kernel to board also')
248 parser.add_option('-O', '--objdump', action='store_true', default=False,
249 help='Write disassembly output')
250 parser.add_option('-r', '--run', action='store_false', default=True,
251 help='Run the boot command')
252 parser.add_option('--ro', action='store_true', default=False,
253 help='Create Chrome OS read-only image')
254 parser.add_option('--rw', action='store_true', default=False,
255 help='Create Chrome OS read-write image')
256 parser.add_option('-s', '--separate', action='store_false', default=True,
257 help='Link device tree into U-Boot, instead of separate')
258 parser.add_option('-S', '--secure', action='store_true', default=False,
259 help='Use vboot_twostop secure boot')
260 parser.add_option('--small', action='store_true', default=False,
261 help='Create Chrome OS small image')
262 parser.add_option('-t', '--trace', action='store_true', default=False,
263 help='Enable trace support')
264 parser.add_option('-v', '--verbose', type='int', default=0,
265 help='Make cros_bundle_firmware verbose')
266 parser.add_option('-V', '--verified', action='store_true', default=False,
267 help='Include Chrome OS verified boot components')
268 parser.add_option('-w', '--write', action='store_false', default=True,
269 help="Don't write image to board using usb/em100")
270 parser.add_option('-x', '--sdcard', action='store_true', default=False,
271 help='Write to SD card instead of USB/em100')
272 parser.add_option('-z', '--size', action='store_true', default=False,
273 help='Display U-Boot image size')
274 return parser.parse_args(argv)
275
276
277def SetupBuild(options):
278 """Set up parameters needed for the build.
279
280 This checks the current environment and options and sets up various things
281 needed for the build, including 'base' which holds the base flags for
282 passing to the U-Boot Makefile.
283
284 Args:
285 options: Command line options
286
287 Returns:
288 Base flags to use for U-Boot, as a list.
289 """
Don Garrett25f309a2014-03-19 14:02:12 -0700290 # pylint: disable=W0603
Simon Glass02741682013-05-26 07:07:58 -0700291 global arch, board, compiler, family, outdir, smdk, uboard, vendor, verbose
292
293 if not verbose:
294 verbose = options.verbose != 0
295
296 logger.setLevel(options.verbose)
297
298 Log('Building for %s' % options.board)
299
Simon Glass9d9bf942013-07-10 16:32:42 -0700300 # Separate out board_variant string: "peach_pit" becomes "peach", "pit".
301 # But don't mess up upstream boards which use _ in their name.
Simon Glass02741682013-05-26 07:07:58 -0700302 parts = options.board.split('_')
Simon Glass9d9bf942013-07-10 16:32:42 -0700303 if parts[0] in ['daisy', 'peach']:
304 board = parts[0]
305 else:
306 board = options.board
Simon Glass02741682013-05-26 07:07:58 -0700307
308 # To allow this to be run from 'cros_sdk'
309 if in_chroot:
310 os.chdir(os.path.join(src_root, 'third_party', 'u-boot', 'files'))
311
312 base_board = board
313
314 if options.verified:
315 base_board = 'chromeos_%s' % base_board
316
317 uboard = UBOARDS.get(base_board, base_board)
318 Log('U-Boot board is %s' % uboard)
319
320 # Pull out some information from the U-Boot boards config file
321 family = None
322 with open('boards.cfg') as f:
323 for line in f:
324 if uboard in line:
325 if line[0] == '#':
326 continue
327 fields = line.split()
328 if not fields:
329 continue
330 arch = fields[1]
331 fields += [None, None, None]
332 smdk = fields[3]
333 vendor = fields[4]
334 family = fields[5]
335 break
336 if not arch:
337 cros_build_lib.Die("Selected board '%s' not found in boards.cfg." % board)
338
339 vboot = os.path.join('build', board, 'usr')
340 if arch == 'x86':
341 family = 'em100'
342 if in_chroot:
343 compiler = 'i686-pc-linux-gnu-'
344 else:
345 compiler = '/opt/i686/bin/i686-unknown-elf-'
346 elif arch == 'arm':
347 if in_chroot:
348 # Use the Chrome OS toolchain
349 compiler = 'armv7a-cros-linux-gnueabi-'
350 else:
351 compiler = glob.glob('/opt/linaro/gcc-linaro-arm-linux-*/bin/*gcc')
352 if not compiler:
353 cros_build_lib.Die("""Please install an ARM toolchain for your machine.
354'Install a Linaro toolchain from:'
355'https://launchpad.net/linaro-toolchain-binaries'
356'or see cros/commands/cros_chrome_sdk.py.""")
357 compiler = compiler[0]
358 compiler = re.sub('gcc$', '', compiler)
359 elif arch == 'sandbox':
360 compiler = ''
361 else:
362 cros_build_lib.Die("Selected arch '%s' not supported." % arch)
363
364 if not options.build:
365 options.incremental = True
366
367 cpus = multiprocessing.cpu_count()
368
Simon Glassb89ae892013-07-18 15:23:35 -0600369 outdir = os.path.join(OUT_DIR, uboard)
Simon Glass02741682013-05-26 07:07:58 -0700370 base = [
371 'make',
372 '-j%d' % cpus,
373 'O=%s' % outdir,
374 'ARCH=%s' % arch,
375 'CROSS_COMPILE=%s' % compiler,
376 '--no-print-directory',
377 'HOSTSTRIP=true',
378 'DEV_TREE_SRC=%s-%s' % (family, options.dt),
379 'QEMU_ARCH=']
380
381 if options.verbose < 2:
382 base.append('-s')
383
384 if options.ro and options.rw:
385 cros_build_lib.Die('Cannot specify both --ro and --rw options')
386 if options.ro:
387 base.append('CROS_RO=1')
388 options.small = True
389
390 if options.rw:
391 base.append('CROS_RW=1')
392 options.small = True
393
394 if options.small:
395 base.append('CROS_SMALL=1')
396 else:
397 base.append('CROS_FULL=1')
398
399 if options.verified:
400 base += [
401 'VBOOT=%s' % vboot,
402 'MAKEFLAGS_VBOOT=DEBUG=1',
403 'QUIET=1',
404 'CFLAGS_EXTRA_VBOOT=-DUNROLL_LOOPS',
405 'VBOOT_SOURCE=%s/platform/vboot_reference' % src_root]
Simon Glass9d9bf942013-07-10 16:32:42 -0700406 base.append('VBOOT_DEBUG=1')
Simon Glass02741682013-05-26 07:07:58 -0700407
408 # Handle the Chrome OS USE_STDINT workaround. Vboot needs <stdint.h> due
409 # to a recent change, the need for which I didn't fully understand. But
410 # U-Boot doesn't normally use this. We have added an option to U-Boot to
411 # enable use of <stdint.h> and without it vboot will fail to build. So we
412 # need to enable it where ww can. We can't just enable it always since
413 # that would prevent this script from building other non-Chrome OS boards
414 # with a different (older) toolchain, or Chrome OS boards without vboot.
415 # So use USE_STDINT if the toolchain supports it, and not if not. This
416 # file was originally part of glibc but has recently migrated to the
417 # compiler so it is reasonable to use it with a stand-alone program like
418 # U-Boot. At this point the comment has got long enough that we may as
419 # well include some poetry which seems to be sorely lacking the code base,
420 # so this is from Ogden Nash:
421 # To keep your marriage brimming
422 # With love in the loving cup,
423 # Whenever you're wrong, admit it;
424 # Whenever you're right, shut up.
425 cmd = [CompilerTool('gcc'), '-ffreestanding', '-x', 'c', '-c', '-']
Yu-Ju Hong3add4432014-01-30 11:46:15 -0800426 result = cros_build_lib.RunCommand(cmd,
427 input='#include <stdint.h>',
428 capture_output=True,
429 **kwargs)
Simon Glass02741682013-05-26 07:07:58 -0700430 if result.returncode == 0:
431 base.append('USE_STDINT=1')
432
433 if options.trace:
434 base.append('FTRACE=1')
435 if options.separate:
436 base.append('DEV_TREE_SEPARATE=1')
437
438 if options.incremental:
439 # Get the correct board for cros_write_firmware
440 config_mk = '%s/include/config.mk' % outdir
441 if not os.path.exists(config_mk):
442 cros_build_lib.Warning('No build found for %s - dropping -i' % board)
443 options.incremental = False
444
445 config_mk = 'include/config.mk'
446 if os.path.exists(config_mk):
447 cros_build_lib.Warning("Warning: '%s' exists, try 'make distclean'"
448 % config_mk)
449
450 # For when U-Boot supports ccache
451 # See http://patchwork.ozlabs.org/patch/245079/
452 if use_ccache:
453 os.environ['CCACHE'] = 'ccache'
454
455 return base
456
457
458def RunBuild(options, base, target, queue):
459 """Run the U-Boot build.
460
461 Args:
462 options: Command line options.
463 base: Base U-Boot flags.
464 target: Target to build.
465 queue: A parallel queue to add jobs to.
466 """
467 Log('U-Boot build flags: %s' % ' '.join(base))
468
469 # Reconfigure U-Boot.
470 if not options.incremental:
471 # Ignore any error from this, some older U-Boots fail on this.
472 cros_build_lib.RunCommand(base + ['distclean'], **kwargs)
473 result = cros_build_lib.RunCommand(base + ['%s_config' % uboard], **kwargs)
474 if result.returncode:
475 sys.exit()
476
477 # Do the actual build.
478 if options.build:
479 result = cros_build_lib.RunCommand(base + [target], **kwargs)
480 if result.returncode:
481 sys.exit()
482
483 files = ['%s/u-boot' % outdir]
484 spl = glob.glob('%s/spl/u-boot-spl' % outdir)
485 if spl:
486 files += spl
487 if options.size:
Simon Glassc7d266d2013-07-18 15:15:57 -0600488 result = cros_build_lib.RunCommand([CompilerTool('size')] + files,
489 **kwargs)
Simon Glass02741682013-05-26 07:07:58 -0700490 if result.returncode:
491 sys.exit()
492
493 # Create disassembly files .dis and .Dis (full dump)
494 for f in files:
495 base = os.path.splitext(f)[0]
496 if options.objdump:
497 queue.put(('-d', f, base + '.dis'))
498 queue.put(('-D', f, base + '.Dis'))
499 else:
500 # Remove old files which otherwise might be confusing
501 osutils.SafeUnlink(base + '.dis')
502 osutils.SafeUnlink(base + '.Dis')
503
504 Log('Output directory %s' % outdir)
505
506
507def WriteFirmware(options):
508 """Write firmware to the board.
509
510 This uses cros_bundle_firmware to create a firmware image and write it to
511 the board.
512
513 Args:
514 options: Command line options
515 """
516 flash = []
517 kernel = []
518 run = []
519 secure = []
520 servo = []
521 silent = []
522 verbose_arg = []
Simon Glass46411592013-07-22 22:35:01 -0600523 ro_uboot = []
Simon Glass02741682013-05-26 07:07:58 -0700524
525 bl2 = ['--bl2', '%s/spl/%s-spl.bin' % (outdir, smdk)]
526
527 if options.use_defaults:
528 bl1 = []
529 bmpblk = []
530 ecro = []
531 ecrw = []
532 defaults = []
533 else:
534 bl1 = ['--bl1', '##/build/%s/firmware/u-boot.bl1.bin' % options.board]
535 bmpblk = ['--bmpblk', '##/build/%s/firmware/bmpblk.bin' % options.board]
536 ecro = ['--ecro', '##/build/%s/firmware/ec.RO.bin' % options.board]
537 ecrw = ['--ec', '##/build/%s/firmware/ec.RW.bin' % options.board]
538 defaults = ['-D']
539
540 if arch == 'x86':
541 seabios = ['--seabios',
542 '##/build/%s/firmware/seabios.cbfs' % options.board]
543 else:
544 seabios = []
545
546 if options.sdcard:
547 dest = 'sd:.'
548 elif arch == 'x86':
549 dest = 'em100'
550 elif arch == 'sandbox':
551 dest = ''
552 else:
553 dest = 'usb'
554
555 port = SERVO_PORT.get(options.board, '')
556 if port:
557 servo = ['--servo', '%d' % port]
558
559 if options.flash:
560 flash = ['-F', 'spi']
561
Simon Glass46411592013-07-22 22:35:01 -0600562 # The small builds don't have the command line interpreter so cannot
563 # run the magic flasher script. So use the standard U-Boot in this
564 # case.
565 if options.small:
566 cros_build_lib.Warning('Using standard U-Boot as flasher')
567 flash += ['-U', '##/build/%s/firmware/u-boot.bin' % options.board]
568
Michael Prattc88035d2013-07-31 16:27:29 -0700569 if options.mmc:
570 flash = ['-F', 'sdmmc']
571
Simon Glass02741682013-05-26 07:07:58 -0700572 if options.verbose:
573 verbose_arg = ['-v', '%s' % options.verbose]
574
575 if options.secure:
576 secure += ['--bootsecure', '--bootcmd', 'vboot_twostop']
577
578 if not options.verified:
579 # Make a small image, without GBB, etc.
580 secure.append('-s')
581
582 if options.kernel:
583 kernel = ['--kernel', '##/build/%s/boot/vmlinux.uimg' % options.board]
584
585 if not options.console:
586 silent = ['--add-config-int', 'silent-console', '1']
587
588 if not options.run:
589 run = ['--bootcmd', 'none']
590
591 if arch != 'sandbox' and not in_chroot and servo:
592 if dest == 'usb':
593 cros_build_lib.Warning('Image cannot be written to board')
594 dest = ''
595 servo = []
596 elif dest == 'em100':
597 cros_build_lib.Warning('Please reset the board manually to boot firmware')
598 servo = []
599
600 if not servo:
601 cros_build_lib.Warning('(sadly dut-control does not work outside chroot)')
602
603 if dest:
604 dest = ['-w', dest]
605 else:
606 dest = []
607
608 soc = SOCS.get(board)
609 if not soc:
610 soc = SOCS.get(uboard, '')
611 dt_name = DEFAULT_DTS.get(options.board, options.board)
612 dts_file = 'board/%s/dts/%s%s.dts' % (vendor, soc, dt_name)
613 Log('Device tree: %s' % dts_file)
614
615 if arch == 'sandbox':
616 uboot_fname = '%s/u-boot' % outdir
617 else:
618 uboot_fname = '%s/u-boot.bin' % outdir
619
Simon Glass46411592013-07-22 22:35:01 -0600620 if options.ro:
621 # RO U-Boot is passed through as blob 'ro-boot'. We use the standard
622 # ebuild one as RW.
623 # TODO(sjg@chromium.org): Option to build U-Boot a second time to get
624 # a fresh RW U-Boot.
625 cros_build_lib.Warning('Using standard U-Boot for RW')
626 ro_uboot = ['--add-blob', 'ro-boot', uboot_fname]
627 uboot_fname = '##/build/%s/firmware/u-boot.bin' % options.board
Simon Glass02741682013-05-26 07:07:58 -0700628 cbf = ['%s/platform/dev/host/cros_bundle_firmware' % src_root,
629 '-b', options.board,
630 '-d', dts_file,
631 '-I', 'arch/%s/dts' % arch, '-I', 'cros/dts',
632 '-u', uboot_fname,
633 '-O', '%s/out' % outdir,
634 '-M', family]
635
636 for other in [bl1, bl2, bmpblk, defaults, dest, ecro, ecrw, flash, kernel,
Simon Glass46411592013-07-22 22:35:01 -0600637 run, seabios, secure, servo, silent, verbose_arg, ro_uboot]:
Simon Glass02741682013-05-26 07:07:58 -0700638 if other:
639 cbf += other
640 if options.cbfargs:
641 for item in options.cbfargs:
642 cbf += item.split(' ')
643 os.environ['PYTHONPATH'] = ('%s/platform/dev/host/lib:%s/..' %
644 (src_root, src_root))
645 Log(' '.join(cbf))
646 result = cros_build_lib.RunCommand(cbf, **kwargs)
647 if result.returncode:
648 cros_build_lib.Die('cros_bundle_firmware failed')
649
650 if not dest or not result.returncode:
651 cros_build_lib.Info('Image is available at %s/out/image.bin' % outdir)
652 else:
653 if result.returncode:
654 cros_build_lib.Die('Failed to write image to board')
655 else:
656 cros_build_lib.Info('Image written to board with %s' %
657 ' '.join(dest + servo))
658
659
660def main(argv):
661 """Main function for script to build/write firmware.
662
663 Args:
664 argv: Program arguments.
665 """
666 options, args = ParseCmdline(argv)
667 base = SetupBuild(options)
668
669 with parallel.BackgroundTaskRunner(Dumper) as queue:
670 target = args[0] if args else 'all'
671 RunBuild(options, base, target, queue)
672
673 if options.write:
674 WriteFirmware(options)
675
676 if options.objdump:
677 Log('Writing diasssembly files')