blob: f86de1f72633c548ec67ae1274b48a61f293b4b5 [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
Mike Frysinger383367e2014-09-16 15:06:17 -0400103from __future__ import print_function
104
Simon Glass02741682013-05-26 07:07:58 -0700105import glob
Simon Glass02741682013-05-26 07:07:58 -0700106import multiprocessing
107import os
108import re
109import sys
110
Don Garrett88b8d782014-05-13 17:30:55 -0700111from chromite.cbuildbot import constants
Simon Glass02741682013-05-26 07:07:58 -0700112from chromite.lib import commandline
113from chromite.lib import cros_build_lib
Ralph Nathan91874ca2015-03-19 13:29:41 -0700114from chromite.lib import cros_logging as logging
Simon Glass02741682013-05-26 07:07:58 -0700115from chromite.lib import osutils
116from chromite.lib import parallel
117
118
119arch = None
120board = None
121compiler = None
122default_board = None
123family = None
124in_chroot = True
125
126logger = logging.getLogger('chromite')
127logging.basicConfig(format='%(message)s')
128kwargs = {'print_cmd': False, 'error_code_ok': True,
129 'debug_level': logger.getEffectiveLevel()}
130
131outdir = ''
132
133 # If you have multiple boards connected on different servo ports, put lines
134# like 'SERVO_PORT{"peach_pit"} = 7777' in your ~/.crosfwrc
135SERVO_PORT = {}
136
137smdk = None
138src_root = os.path.join(constants.SOURCE_ROOT, 'src')
139in_chroot = cros_build_lib.IsInsideChroot()
140
141uboard = ''
142
143default_board = 'peach_pit'
144use_ccache = False
145vendor = None
146verbose = False
147
148# Special cases for the U-Boot board config, the SOCs and default device tree
149# since the naming is not always consistent.
150# x86 has a lot of boards, but to U-Boot they are all the same
151UBOARDS = {
152 'daisy': 'smdk5250',
153 'peach': 'smdk5420',
154}
155for b in ['alex', 'butterfly', 'emeraldlake2', 'link', 'lumpy', 'parrot',
156 'stout', 'stumpy']:
157 UBOARDS[b] = 'coreboot-x86'
158 UBOARDS['chromeos_%s' % b] = 'chromeos_coreboot'
159
160SOCS = {
161 'coreboot-x86': '',
162 'chromeos_coreboot': '',
163 'daisy': 'exynos5250-',
164 'peach': 'exynos5420-',
165}
166
167DEFAULT_DTS = {
168 'daisy': 'snow',
169 'daisy_spring': 'spring',
170 'peach_pit': 'peach-pit',
171}
172
Simon Glassb89ae892013-07-18 15:23:35 -0600173OUT_DIR = '/tmp/crosfw'
174
Simon Glass02741682013-05-26 07:07:58 -0700175rc_file = os.path.expanduser('~/.crosfwrc')
176if os.path.exists(rc_file):
177 execfile(rc_file)
178
179
180def Log(msg):
181 """Print out a message if we are in verbose mode.
182
183 Args:
184 msg: Message to print
185 """
186 if verbose:
Ralph Nathan03047282015-03-23 11:09:32 -0700187 logging.info(msg)
Simon Glass02741682013-05-26 07:07:58 -0700188
189
190def Dumper(flag, infile, outfile):
191 """Run objdump on an input file.
192
193 Args:
194 flag: Flag to pass objdump (e.g. '-d').
195 infile: Input file to process.
196 outfile: Output file to write to.
197 """
198 result = cros_build_lib.RunCommand(
199 [CompilerTool('objdump'), flag, infile],
200 log_stdout_to_file=outfile, **kwargs)
201 if result.returncode:
202 sys.exit()
203
204
205def CompilerTool(tool):
206 """Returns the cross-compiler tool filename.
207
208 Args:
209 tool: Tool name to return, e.g. 'size'.
210
211 Returns:
212 Filename of requested tool.
213 """
214 return '%s%s' % (compiler, tool)
215
216
217def ParseCmdline(argv):
218 """Parse all command line options.
219
220 Args:
221 argv: Arguments to parse.
222
223 Returns:
224 Tuple containing:
225 options: Command line options from optpase
226 args: List of command line arguments
227 """
228 parser = commandline.OptionParser(__doc__)
229 parser.add_option('-a', '--cbfargs', action='append',
230 help='Pass extra arguments to cros_bundle_firmware')
231 parser.add_option('-b', '--board', type='string', default=default_board,
232 help='Select board to build (daisy/peach_pit/link)')
233 parser.add_option('-B', '--build', action='store_false', default=True,
234 help="Don't build U-Boot, just configure device tree")
235 parser.add_option('-C', '--console', action='store_false', default=True,
236 help='Permit console output')
237 parser.add_option('-d', '--dt', default='seaboard',
238 help='Select name of device tree file to use')
239 parser.add_option('-D', '--nodefaults', dest='use_defaults',
240 action='store_false', default=True,
241 help="Don't select default filenames for those not given")
242 parser.add_option('-F', '--flash', action='store_true', default=False,
Michael Prattc88035d2013-07-31 16:27:29 -0700243 help='Create magic flasher for SPI flash')
244 parser.add_option('-M', '--mmc', action='store_true', default=False,
245 help='Create magic flasher for eMMC')
Simon Glass02741682013-05-26 07:07:58 -0700246 parser.add_option('-i', '--incremental', action='store_true', default=False,
247 help="Don't reconfigure and clean")
248 parser.add_option('-k', '--kernel', action='store_true', default=False,
249 help='Send kernel to board also')
250 parser.add_option('-O', '--objdump', action='store_true', default=False,
251 help='Write disassembly output')
252 parser.add_option('-r', '--run', action='store_false', default=True,
253 help='Run the boot command')
254 parser.add_option('--ro', action='store_true', default=False,
255 help='Create Chrome OS read-only image')
256 parser.add_option('--rw', action='store_true', default=False,
257 help='Create Chrome OS read-write image')
258 parser.add_option('-s', '--separate', action='store_false', default=True,
259 help='Link device tree into U-Boot, instead of separate')
260 parser.add_option('-S', '--secure', action='store_true', default=False,
261 help='Use vboot_twostop secure boot')
262 parser.add_option('--small', action='store_true', default=False,
263 help='Create Chrome OS small image')
264 parser.add_option('-t', '--trace', action='store_true', default=False,
265 help='Enable trace support')
266 parser.add_option('-v', '--verbose', type='int', default=0,
267 help='Make cros_bundle_firmware verbose')
268 parser.add_option('-V', '--verified', action='store_true', default=False,
269 help='Include Chrome OS verified boot components')
270 parser.add_option('-w', '--write', action='store_false', default=True,
271 help="Don't write image to board using usb/em100")
272 parser.add_option('-x', '--sdcard', action='store_true', default=False,
273 help='Write to SD card instead of USB/em100')
274 parser.add_option('-z', '--size', action='store_true', default=False,
275 help='Display U-Boot image size')
276 return parser.parse_args(argv)
277
278
279def SetupBuild(options):
280 """Set up parameters needed for the build.
281
282 This checks the current environment and options and sets up various things
283 needed for the build, including 'base' which holds the base flags for
284 passing to the U-Boot Makefile.
285
286 Args:
287 options: Command line options
288
289 Returns:
290 Base flags to use for U-Boot, as a list.
291 """
Don Garrett25f309a2014-03-19 14:02:12 -0700292 # pylint: disable=W0603
Simon Glass02741682013-05-26 07:07:58 -0700293 global arch, board, compiler, family, outdir, smdk, uboard, vendor, verbose
294
295 if not verbose:
296 verbose = options.verbose != 0
297
298 logger.setLevel(options.verbose)
299
300 Log('Building for %s' % options.board)
301
Simon Glass9d9bf942013-07-10 16:32:42 -0700302 # Separate out board_variant string: "peach_pit" becomes "peach", "pit".
303 # But don't mess up upstream boards which use _ in their name.
Simon Glass02741682013-05-26 07:07:58 -0700304 parts = options.board.split('_')
Simon Glass9d9bf942013-07-10 16:32:42 -0700305 if parts[0] in ['daisy', 'peach']:
306 board = parts[0]
307 else:
308 board = options.board
Simon Glass02741682013-05-26 07:07:58 -0700309
310 # To allow this to be run from 'cros_sdk'
311 if in_chroot:
312 os.chdir(os.path.join(src_root, 'third_party', 'u-boot', 'files'))
313
314 base_board = board
315
316 if options.verified:
317 base_board = 'chromeos_%s' % base_board
318
319 uboard = UBOARDS.get(base_board, base_board)
320 Log('U-Boot board is %s' % uboard)
321
322 # Pull out some information from the U-Boot boards config file
323 family = None
324 with open('boards.cfg') as f:
325 for line in f:
326 if uboard in line:
327 if line[0] == '#':
328 continue
329 fields = line.split()
330 if not fields:
331 continue
332 arch = fields[1]
333 fields += [None, None, None]
334 smdk = fields[3]
335 vendor = fields[4]
336 family = fields[5]
337 break
338 if not arch:
339 cros_build_lib.Die("Selected board '%s' not found in boards.cfg." % board)
340
341 vboot = os.path.join('build', board, 'usr')
342 if arch == 'x86':
343 family = 'em100'
344 if in_chroot:
345 compiler = 'i686-pc-linux-gnu-'
346 else:
347 compiler = '/opt/i686/bin/i686-unknown-elf-'
348 elif arch == 'arm':
349 if in_chroot:
350 # Use the Chrome OS toolchain
351 compiler = 'armv7a-cros-linux-gnueabi-'
352 else:
353 compiler = glob.glob('/opt/linaro/gcc-linaro-arm-linux-*/bin/*gcc')
354 if not compiler:
355 cros_build_lib.Die("""Please install an ARM toolchain for your machine.
356'Install a Linaro toolchain from:'
357'https://launchpad.net/linaro-toolchain-binaries'
358'or see cros/commands/cros_chrome_sdk.py.""")
359 compiler = compiler[0]
360 compiler = re.sub('gcc$', '', compiler)
361 elif arch == 'sandbox':
362 compiler = ''
363 else:
364 cros_build_lib.Die("Selected arch '%s' not supported." % arch)
365
366 if not options.build:
367 options.incremental = True
368
369 cpus = multiprocessing.cpu_count()
370
Simon Glassb89ae892013-07-18 15:23:35 -0600371 outdir = os.path.join(OUT_DIR, uboard)
Simon Glass02741682013-05-26 07:07:58 -0700372 base = [
373 'make',
374 '-j%d' % cpus,
375 'O=%s' % outdir,
376 'ARCH=%s' % arch,
377 'CROSS_COMPILE=%s' % compiler,
378 '--no-print-directory',
379 'HOSTSTRIP=true',
380 'DEV_TREE_SRC=%s-%s' % (family, options.dt),
381 'QEMU_ARCH=']
382
383 if options.verbose < 2:
384 base.append('-s')
385
386 if options.ro and options.rw:
387 cros_build_lib.Die('Cannot specify both --ro and --rw options')
388 if options.ro:
389 base.append('CROS_RO=1')
390 options.small = True
391
392 if options.rw:
393 base.append('CROS_RW=1')
394 options.small = True
395
396 if options.small:
397 base.append('CROS_SMALL=1')
398 else:
399 base.append('CROS_FULL=1')
400
401 if options.verified:
402 base += [
403 'VBOOT=%s' % vboot,
404 'MAKEFLAGS_VBOOT=DEBUG=1',
405 'QUIET=1',
406 'CFLAGS_EXTRA_VBOOT=-DUNROLL_LOOPS',
407 'VBOOT_SOURCE=%s/platform/vboot_reference' % src_root]
Simon Glass9d9bf942013-07-10 16:32:42 -0700408 base.append('VBOOT_DEBUG=1')
Simon Glass02741682013-05-26 07:07:58 -0700409
410 # Handle the Chrome OS USE_STDINT workaround. Vboot needs <stdint.h> due
411 # to a recent change, the need for which I didn't fully understand. But
412 # U-Boot doesn't normally use this. We have added an option to U-Boot to
413 # enable use of <stdint.h> and without it vboot will fail to build. So we
414 # need to enable it where ww can. We can't just enable it always since
415 # that would prevent this script from building other non-Chrome OS boards
416 # with a different (older) toolchain, or Chrome OS boards without vboot.
417 # So use USE_STDINT if the toolchain supports it, and not if not. This
418 # file was originally part of glibc but has recently migrated to the
419 # compiler so it is reasonable to use it with a stand-alone program like
420 # U-Boot. At this point the comment has got long enough that we may as
421 # well include some poetry which seems to be sorely lacking the code base,
422 # so this is from Ogden Nash:
423 # To keep your marriage brimming
424 # With love in the loving cup,
425 # Whenever you're wrong, admit it;
426 # Whenever you're right, shut up.
427 cmd = [CompilerTool('gcc'), '-ffreestanding', '-x', 'c', '-c', '-']
Yu-Ju Hong3add4432014-01-30 11:46:15 -0800428 result = cros_build_lib.RunCommand(cmd,
429 input='#include <stdint.h>',
430 capture_output=True,
431 **kwargs)
Simon Glass02741682013-05-26 07:07:58 -0700432 if result.returncode == 0:
433 base.append('USE_STDINT=1')
434
435 if options.trace:
436 base.append('FTRACE=1')
437 if options.separate:
438 base.append('DEV_TREE_SEPARATE=1')
439
440 if options.incremental:
441 # Get the correct board for cros_write_firmware
442 config_mk = '%s/include/config.mk' % outdir
443 if not os.path.exists(config_mk):
Ralph Nathan446aee92015-03-23 14:44:56 -0700444 logging.warning('No build found for %s - dropping -i' % board)
Simon Glass02741682013-05-26 07:07:58 -0700445 options.incremental = False
446
447 config_mk = 'include/config.mk'
448 if os.path.exists(config_mk):
Ralph Nathan446aee92015-03-23 14:44:56 -0700449 logging.warning("Warning: '%s' exists, try 'make distclean'" % config_mk)
Simon Glass02741682013-05-26 07:07:58 -0700450
451 # For when U-Boot supports ccache
452 # See http://patchwork.ozlabs.org/patch/245079/
453 if use_ccache:
454 os.environ['CCACHE'] = 'ccache'
455
456 return base
457
458
459def RunBuild(options, base, target, queue):
460 """Run the U-Boot build.
461
462 Args:
463 options: Command line options.
464 base: Base U-Boot flags.
465 target: Target to build.
466 queue: A parallel queue to add jobs to.
467 """
468 Log('U-Boot build flags: %s' % ' '.join(base))
469
470 # Reconfigure U-Boot.
471 if not options.incremental:
472 # Ignore any error from this, some older U-Boots fail on this.
473 cros_build_lib.RunCommand(base + ['distclean'], **kwargs)
474 result = cros_build_lib.RunCommand(base + ['%s_config' % uboard], **kwargs)
475 if result.returncode:
476 sys.exit()
477
478 # Do the actual build.
479 if options.build:
480 result = cros_build_lib.RunCommand(base + [target], **kwargs)
481 if result.returncode:
482 sys.exit()
483
484 files = ['%s/u-boot' % outdir]
485 spl = glob.glob('%s/spl/u-boot-spl' % outdir)
486 if spl:
487 files += spl
488 if options.size:
Simon Glassc7d266d2013-07-18 15:15:57 -0600489 result = cros_build_lib.RunCommand([CompilerTool('size')] + files,
490 **kwargs)
Simon Glass02741682013-05-26 07:07:58 -0700491 if result.returncode:
492 sys.exit()
493
494 # Create disassembly files .dis and .Dis (full dump)
495 for f in files:
496 base = os.path.splitext(f)[0]
497 if options.objdump:
498 queue.put(('-d', f, base + '.dis'))
499 queue.put(('-D', f, base + '.Dis'))
500 else:
501 # Remove old files which otherwise might be confusing
502 osutils.SafeUnlink(base + '.dis')
503 osutils.SafeUnlink(base + '.Dis')
504
505 Log('Output directory %s' % outdir)
506
507
508def WriteFirmware(options):
509 """Write firmware to the board.
510
511 This uses cros_bundle_firmware to create a firmware image and write it to
512 the board.
513
514 Args:
515 options: Command line options
516 """
517 flash = []
518 kernel = []
519 run = []
520 secure = []
521 servo = []
522 silent = []
523 verbose_arg = []
Simon Glass46411592013-07-22 22:35:01 -0600524 ro_uboot = []
Simon Glass02741682013-05-26 07:07:58 -0700525
526 bl2 = ['--bl2', '%s/spl/%s-spl.bin' % (outdir, smdk)]
527
528 if options.use_defaults:
529 bl1 = []
530 bmpblk = []
531 ecro = []
532 ecrw = []
533 defaults = []
534 else:
535 bl1 = ['--bl1', '##/build/%s/firmware/u-boot.bl1.bin' % options.board]
536 bmpblk = ['--bmpblk', '##/build/%s/firmware/bmpblk.bin' % options.board]
537 ecro = ['--ecro', '##/build/%s/firmware/ec.RO.bin' % options.board]
538 ecrw = ['--ec', '##/build/%s/firmware/ec.RW.bin' % options.board]
539 defaults = ['-D']
540
541 if arch == 'x86':
542 seabios = ['--seabios',
543 '##/build/%s/firmware/seabios.cbfs' % options.board]
544 else:
545 seabios = []
546
547 if options.sdcard:
548 dest = 'sd:.'
549 elif arch == 'x86':
550 dest = 'em100'
551 elif arch == 'sandbox':
552 dest = ''
553 else:
554 dest = 'usb'
555
556 port = SERVO_PORT.get(options.board, '')
557 if port:
558 servo = ['--servo', '%d' % port]
559
560 if options.flash:
561 flash = ['-F', 'spi']
562
Simon Glass46411592013-07-22 22:35:01 -0600563 # The small builds don't have the command line interpreter so cannot
564 # run the magic flasher script. So use the standard U-Boot in this
565 # case.
566 if options.small:
Ralph Nathan446aee92015-03-23 14:44:56 -0700567 logging.warning('Using standard U-Boot as flasher')
Simon Glass46411592013-07-22 22:35:01 -0600568 flash += ['-U', '##/build/%s/firmware/u-boot.bin' % options.board]
569
Michael Prattc88035d2013-07-31 16:27:29 -0700570 if options.mmc:
571 flash = ['-F', 'sdmmc']
572
Simon Glass02741682013-05-26 07:07:58 -0700573 if options.verbose:
574 verbose_arg = ['-v', '%s' % options.verbose]
575
576 if options.secure:
577 secure += ['--bootsecure', '--bootcmd', 'vboot_twostop']
578
579 if not options.verified:
580 # Make a small image, without GBB, etc.
581 secure.append('-s')
582
583 if options.kernel:
584 kernel = ['--kernel', '##/build/%s/boot/vmlinux.uimg' % options.board]
585
586 if not options.console:
587 silent = ['--add-config-int', 'silent-console', '1']
588
589 if not options.run:
590 run = ['--bootcmd', 'none']
591
592 if arch != 'sandbox' and not in_chroot and servo:
593 if dest == 'usb':
Ralph Nathan446aee92015-03-23 14:44:56 -0700594 logging.warning('Image cannot be written to board')
Simon Glass02741682013-05-26 07:07:58 -0700595 dest = ''
596 servo = []
597 elif dest == 'em100':
Ralph Nathan446aee92015-03-23 14:44:56 -0700598 logging.warning('Please reset the board manually to boot firmware')
Simon Glass02741682013-05-26 07:07:58 -0700599 servo = []
600
601 if not servo:
Ralph Nathan446aee92015-03-23 14:44:56 -0700602 logging.warning('(sadly dut-control does not work outside chroot)')
Simon Glass02741682013-05-26 07:07:58 -0700603
604 if dest:
605 dest = ['-w', dest]
606 else:
607 dest = []
608
609 soc = SOCS.get(board)
610 if not soc:
611 soc = SOCS.get(uboard, '')
612 dt_name = DEFAULT_DTS.get(options.board, options.board)
613 dts_file = 'board/%s/dts/%s%s.dts' % (vendor, soc, dt_name)
614 Log('Device tree: %s' % dts_file)
615
616 if arch == 'sandbox':
617 uboot_fname = '%s/u-boot' % outdir
618 else:
619 uboot_fname = '%s/u-boot.bin' % outdir
620
Simon Glass46411592013-07-22 22:35:01 -0600621 if options.ro:
622 # RO U-Boot is passed through as blob 'ro-boot'. We use the standard
623 # ebuild one as RW.
624 # TODO(sjg@chromium.org): Option to build U-Boot a second time to get
625 # a fresh RW U-Boot.
Ralph Nathan446aee92015-03-23 14:44:56 -0700626 logging.warning('Using standard U-Boot for RW')
Simon Glass46411592013-07-22 22:35:01 -0600627 ro_uboot = ['--add-blob', 'ro-boot', uboot_fname]
628 uboot_fname = '##/build/%s/firmware/u-boot.bin' % options.board
Simon Glass02741682013-05-26 07:07:58 -0700629 cbf = ['%s/platform/dev/host/cros_bundle_firmware' % src_root,
630 '-b', options.board,
631 '-d', dts_file,
632 '-I', 'arch/%s/dts' % arch, '-I', 'cros/dts',
633 '-u', uboot_fname,
634 '-O', '%s/out' % outdir,
635 '-M', family]
636
637 for other in [bl1, bl2, bmpblk, defaults, dest, ecro, ecrw, flash, kernel,
Simon Glass46411592013-07-22 22:35:01 -0600638 run, seabios, secure, servo, silent, verbose_arg, ro_uboot]:
Simon Glass02741682013-05-26 07:07:58 -0700639 if other:
640 cbf += other
641 if options.cbfargs:
642 for item in options.cbfargs:
643 cbf += item.split(' ')
644 os.environ['PYTHONPATH'] = ('%s/platform/dev/host/lib:%s/..' %
645 (src_root, src_root))
646 Log(' '.join(cbf))
647 result = cros_build_lib.RunCommand(cbf, **kwargs)
648 if result.returncode:
649 cros_build_lib.Die('cros_bundle_firmware failed')
650
651 if not dest or not result.returncode:
Ralph Nathan03047282015-03-23 11:09:32 -0700652 logging.info('Image is available at %s/out/image.bin' % outdir)
Simon Glass02741682013-05-26 07:07:58 -0700653 else:
654 if result.returncode:
655 cros_build_lib.Die('Failed to write image to board')
656 else:
Ralph Nathan03047282015-03-23 11:09:32 -0700657 logging.info('Image written to board with %s' % ' '.join(dest + servo))
Simon Glass02741682013-05-26 07:07:58 -0700658
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')