blob: 7fa95733d34e4d648fad3ea61d156cfe62ba9e30 [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
Simon Glass02741682013-05-26 07:07:58 -0700126logging.basicConfig(format='%(message)s')
127kwargs = {'print_cmd': False, 'error_code_ok': True,
Ralph Nathan23a12212015-03-25 10:27:54 -0700128 'debug_level': logging.getLogger().getEffectiveLevel()}
Simon Glass02741682013-05-26 07:07:58 -0700129
130outdir = ''
131
132 # If you have multiple boards connected on different servo ports, put lines
133# like 'SERVO_PORT{"peach_pit"} = 7777' in your ~/.crosfwrc
134SERVO_PORT = {}
135
136smdk = None
137src_root = os.path.join(constants.SOURCE_ROOT, 'src')
138in_chroot = cros_build_lib.IsInsideChroot()
139
140uboard = ''
141
142default_board = 'peach_pit'
143use_ccache = False
144vendor = None
145verbose = False
146
147# Special cases for the U-Boot board config, the SOCs and default device tree
148# since the naming is not always consistent.
149# x86 has a lot of boards, but to U-Boot they are all the same
150UBOARDS = {
151 'daisy': 'smdk5250',
152 'peach': 'smdk5420',
153}
154for b in ['alex', 'butterfly', 'emeraldlake2', 'link', 'lumpy', 'parrot',
155 'stout', 'stumpy']:
156 UBOARDS[b] = 'coreboot-x86'
157 UBOARDS['chromeos_%s' % b] = 'chromeos_coreboot'
158
159SOCS = {
160 'coreboot-x86': '',
161 'chromeos_coreboot': '',
162 'daisy': 'exynos5250-',
163 'peach': 'exynos5420-',
164}
165
166DEFAULT_DTS = {
167 'daisy': 'snow',
168 'daisy_spring': 'spring',
169 'peach_pit': 'peach-pit',
170}
171
Simon Glassb89ae892013-07-18 15:23:35 -0600172OUT_DIR = '/tmp/crosfw'
173
Simon Glass02741682013-05-26 07:07:58 -0700174rc_file = os.path.expanduser('~/.crosfwrc')
175if os.path.exists(rc_file):
176 execfile(rc_file)
177
178
179def Log(msg):
180 """Print out a message if we are in verbose mode.
181
182 Args:
183 msg: Message to print
184 """
185 if verbose:
Ralph Nathan03047282015-03-23 11:09:32 -0700186 logging.info(msg)
Simon Glass02741682013-05-26 07:07:58 -0700187
188
189def Dumper(flag, infile, outfile):
190 """Run objdump on an input file.
191
192 Args:
193 flag: Flag to pass objdump (e.g. '-d').
194 infile: Input file to process.
195 outfile: Output file to write to.
196 """
197 result = cros_build_lib.RunCommand(
198 [CompilerTool('objdump'), flag, infile],
199 log_stdout_to_file=outfile, **kwargs)
200 if result.returncode:
201 sys.exit()
202
203
204def CompilerTool(tool):
205 """Returns the cross-compiler tool filename.
206
207 Args:
208 tool: Tool name to return, e.g. 'size'.
209
210 Returns:
211 Filename of requested tool.
212 """
213 return '%s%s' % (compiler, tool)
214
215
216def ParseCmdline(argv):
217 """Parse all command line options.
218
219 Args:
220 argv: Arguments to parse.
221
222 Returns:
223 Tuple containing:
224 options: Command line options from optpase
225 args: List of command line arguments
226 """
227 parser = commandline.OptionParser(__doc__)
228 parser.add_option('-a', '--cbfargs', action='append',
229 help='Pass extra arguments to cros_bundle_firmware')
230 parser.add_option('-b', '--board', type='string', default=default_board,
231 help='Select board to build (daisy/peach_pit/link)')
232 parser.add_option('-B', '--build', action='store_false', default=True,
233 help="Don't build U-Boot, just configure device tree")
234 parser.add_option('-C', '--console', action='store_false', default=True,
235 help='Permit console output')
236 parser.add_option('-d', '--dt', default='seaboard',
237 help='Select name of device tree file to use')
238 parser.add_option('-D', '--nodefaults', dest='use_defaults',
239 action='store_false', default=True,
240 help="Don't select default filenames for those not given")
241 parser.add_option('-F', '--flash', action='store_true', default=False,
Michael Prattc88035d2013-07-31 16:27:29 -0700242 help='Create magic flasher for SPI flash')
243 parser.add_option('-M', '--mmc', action='store_true', default=False,
244 help='Create magic flasher for eMMC')
Simon Glass02741682013-05-26 07:07:58 -0700245 parser.add_option('-i', '--incremental', action='store_true', default=False,
246 help="Don't reconfigure and clean")
247 parser.add_option('-k', '--kernel', action='store_true', default=False,
248 help='Send kernel to board also')
249 parser.add_option('-O', '--objdump', action='store_true', default=False,
250 help='Write disassembly output')
251 parser.add_option('-r', '--run', action='store_false', default=True,
252 help='Run the boot command')
253 parser.add_option('--ro', action='store_true', default=False,
254 help='Create Chrome OS read-only image')
255 parser.add_option('--rw', action='store_true', default=False,
256 help='Create Chrome OS read-write image')
257 parser.add_option('-s', '--separate', action='store_false', default=True,
258 help='Link device tree into U-Boot, instead of separate')
259 parser.add_option('-S', '--secure', action='store_true', default=False,
260 help='Use vboot_twostop secure boot')
261 parser.add_option('--small', action='store_true', default=False,
262 help='Create Chrome OS small image')
263 parser.add_option('-t', '--trace', action='store_true', default=False,
264 help='Enable trace support')
265 parser.add_option('-v', '--verbose', type='int', default=0,
266 help='Make cros_bundle_firmware verbose')
267 parser.add_option('-V', '--verified', action='store_true', default=False,
268 help='Include Chrome OS verified boot components')
269 parser.add_option('-w', '--write', action='store_false', default=True,
270 help="Don't write image to board using usb/em100")
271 parser.add_option('-x', '--sdcard', action='store_true', default=False,
272 help='Write to SD card instead of USB/em100')
273 parser.add_option('-z', '--size', action='store_true', default=False,
274 help='Display U-Boot image size')
275 return parser.parse_args(argv)
276
277
278def SetupBuild(options):
279 """Set up parameters needed for the build.
280
281 This checks the current environment and options and sets up various things
282 needed for the build, including 'base' which holds the base flags for
283 passing to the U-Boot Makefile.
284
285 Args:
286 options: Command line options
287
288 Returns:
289 Base flags to use for U-Boot, as a list.
290 """
Don Garrett25f309a2014-03-19 14:02:12 -0700291 # pylint: disable=W0603
Simon Glass02741682013-05-26 07:07:58 -0700292 global arch, board, compiler, family, outdir, smdk, uboard, vendor, verbose
293
294 if not verbose:
295 verbose = options.verbose != 0
296
Ralph Nathan23a12212015-03-25 10:27:54 -0700297 logging.getLogger().setLevel(options.verbose)
Simon Glass02741682013-05-26 07:07:58 -0700298
299 Log('Building for %s' % options.board)
300
Simon Glass9d9bf942013-07-10 16:32:42 -0700301 # Separate out board_variant string: "peach_pit" becomes "peach", "pit".
302 # But don't mess up upstream boards which use _ in their name.
Simon Glass02741682013-05-26 07:07:58 -0700303 parts = options.board.split('_')
Simon Glass9d9bf942013-07-10 16:32:42 -0700304 if parts[0] in ['daisy', 'peach']:
305 board = parts[0]
306 else:
307 board = options.board
Simon Glass02741682013-05-26 07:07:58 -0700308
309 # To allow this to be run from 'cros_sdk'
310 if in_chroot:
311 os.chdir(os.path.join(src_root, 'third_party', 'u-boot', 'files'))
312
313 base_board = board
314
315 if options.verified:
316 base_board = 'chromeos_%s' % base_board
317
318 uboard = UBOARDS.get(base_board, base_board)
319 Log('U-Boot board is %s' % uboard)
320
321 # Pull out some information from the U-Boot boards config file
322 family = None
323 with open('boards.cfg') as f:
324 for line in f:
325 if uboard in line:
326 if line[0] == '#':
327 continue
328 fields = line.split()
329 if not fields:
330 continue
331 arch = fields[1]
332 fields += [None, None, None]
333 smdk = fields[3]
334 vendor = fields[4]
335 family = fields[5]
336 break
337 if not arch:
338 cros_build_lib.Die("Selected board '%s' not found in boards.cfg." % board)
339
340 vboot = os.path.join('build', board, 'usr')
341 if arch == 'x86':
342 family = 'em100'
343 if in_chroot:
344 compiler = 'i686-pc-linux-gnu-'
345 else:
346 compiler = '/opt/i686/bin/i686-unknown-elf-'
347 elif arch == 'arm':
348 if in_chroot:
349 # Use the Chrome OS toolchain
350 compiler = 'armv7a-cros-linux-gnueabi-'
351 else:
352 compiler = glob.glob('/opt/linaro/gcc-linaro-arm-linux-*/bin/*gcc')
353 if not compiler:
354 cros_build_lib.Die("""Please install an ARM toolchain for your machine.
355'Install a Linaro toolchain from:'
356'https://launchpad.net/linaro-toolchain-binaries'
357'or see cros/commands/cros_chrome_sdk.py.""")
358 compiler = compiler[0]
359 compiler = re.sub('gcc$', '', compiler)
360 elif arch == 'sandbox':
361 compiler = ''
362 else:
363 cros_build_lib.Die("Selected arch '%s' not supported." % arch)
364
365 if not options.build:
366 options.incremental = True
367
368 cpus = multiprocessing.cpu_count()
369
Simon Glassb89ae892013-07-18 15:23:35 -0600370 outdir = os.path.join(OUT_DIR, uboard)
Simon Glass02741682013-05-26 07:07:58 -0700371 base = [
372 'make',
373 '-j%d' % cpus,
374 'O=%s' % outdir,
375 'ARCH=%s' % arch,
376 'CROSS_COMPILE=%s' % compiler,
377 '--no-print-directory',
378 'HOSTSTRIP=true',
379 'DEV_TREE_SRC=%s-%s' % (family, options.dt),
380 'QEMU_ARCH=']
381
382 if options.verbose < 2:
383 base.append('-s')
384
385 if options.ro and options.rw:
386 cros_build_lib.Die('Cannot specify both --ro and --rw options')
387 if options.ro:
388 base.append('CROS_RO=1')
389 options.small = True
390
391 if options.rw:
392 base.append('CROS_RW=1')
393 options.small = True
394
395 if options.small:
396 base.append('CROS_SMALL=1')
397 else:
398 base.append('CROS_FULL=1')
399
400 if options.verified:
401 base += [
402 'VBOOT=%s' % vboot,
403 'MAKEFLAGS_VBOOT=DEBUG=1',
404 'QUIET=1',
405 'CFLAGS_EXTRA_VBOOT=-DUNROLL_LOOPS',
406 'VBOOT_SOURCE=%s/platform/vboot_reference' % src_root]
Simon Glass9d9bf942013-07-10 16:32:42 -0700407 base.append('VBOOT_DEBUG=1')
Simon Glass02741682013-05-26 07:07:58 -0700408
409 # Handle the Chrome OS USE_STDINT workaround. Vboot needs <stdint.h> due
410 # to a recent change, the need for which I didn't fully understand. But
411 # U-Boot doesn't normally use this. We have added an option to U-Boot to
412 # enable use of <stdint.h> and without it vboot will fail to build. So we
413 # need to enable it where ww can. We can't just enable it always since
414 # that would prevent this script from building other non-Chrome OS boards
415 # with a different (older) toolchain, or Chrome OS boards without vboot.
416 # So use USE_STDINT if the toolchain supports it, and not if not. This
417 # file was originally part of glibc but has recently migrated to the
418 # compiler so it is reasonable to use it with a stand-alone program like
419 # U-Boot. At this point the comment has got long enough that we may as
420 # well include some poetry which seems to be sorely lacking the code base,
421 # so this is from Ogden Nash:
422 # To keep your marriage brimming
423 # With love in the loving cup,
424 # Whenever you're wrong, admit it;
425 # Whenever you're right, shut up.
426 cmd = [CompilerTool('gcc'), '-ffreestanding', '-x', 'c', '-c', '-']
Yu-Ju Hong3add4432014-01-30 11:46:15 -0800427 result = cros_build_lib.RunCommand(cmd,
428 input='#include <stdint.h>',
429 capture_output=True,
430 **kwargs)
Simon Glass02741682013-05-26 07:07:58 -0700431 if result.returncode == 0:
432 base.append('USE_STDINT=1')
433
434 if options.trace:
435 base.append('FTRACE=1')
436 if options.separate:
437 base.append('DEV_TREE_SEPARATE=1')
438
439 if options.incremental:
440 # Get the correct board for cros_write_firmware
441 config_mk = '%s/include/config.mk' % outdir
442 if not os.path.exists(config_mk):
Ralph Nathan446aee92015-03-23 14:44:56 -0700443 logging.warning('No build found for %s - dropping -i' % board)
Simon Glass02741682013-05-26 07:07:58 -0700444 options.incremental = False
445
446 config_mk = 'include/config.mk'
447 if os.path.exists(config_mk):
Ralph Nathan446aee92015-03-23 14:44:56 -0700448 logging.warning("Warning: '%s' exists, try 'make distclean'" % config_mk)
Simon Glass02741682013-05-26 07:07:58 -0700449
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:
Ralph Nathan446aee92015-03-23 14:44:56 -0700566 logging.warning('Using standard U-Boot as flasher')
Simon Glass46411592013-07-22 22:35:01 -0600567 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':
Ralph Nathan446aee92015-03-23 14:44:56 -0700593 logging.warning('Image cannot be written to board')
Simon Glass02741682013-05-26 07:07:58 -0700594 dest = ''
595 servo = []
596 elif dest == 'em100':
Ralph Nathan446aee92015-03-23 14:44:56 -0700597 logging.warning('Please reset the board manually to boot firmware')
Simon Glass02741682013-05-26 07:07:58 -0700598 servo = []
599
600 if not servo:
Ralph Nathan446aee92015-03-23 14:44:56 -0700601 logging.warning('(sadly dut-control does not work outside chroot)')
Simon Glass02741682013-05-26 07:07:58 -0700602
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.
Ralph Nathan446aee92015-03-23 14:44:56 -0700625 logging.warning('Using standard U-Boot for RW')
Simon Glass46411592013-07-22 22:35:01 -0600626 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:
Ralph Nathan03047282015-03-23 11:09:32 -0700651 logging.info('Image is available at %s/out/image.bin' % outdir)
Simon Glass02741682013-05-26 07:07:58 -0700652 else:
653 if result.returncode:
654 cros_build_lib.Die('Failed to write image to board')
655 else:
Ralph Nathan03047282015-03-23 11:09:32 -0700656 logging.info('Image written to board with %s' % ' '.join(dest + servo))
Simon Glass02741682013-05-26 07:07:58 -0700657
658
659def main(argv):
660 """Main function for script to build/write firmware.
661
662 Args:
663 argv: Program arguments.
664 """
665 options, args = ParseCmdline(argv)
666 base = SetupBuild(options)
667
668 with parallel.BackgroundTaskRunner(Dumper) as queue:
669 target = args[0] if args else 'all'
670 RunBuild(options, base, target, queue)
671
672 if options.write:
673 WriteFirmware(options)
674
675 if options.objdump:
676 Log('Writing diasssembly files')