| #!/usr/bin/python |
| |
| # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """This utility builds a firmware image for a tegra-based board. |
| |
| This utility uses a number of libraries for its activity. |
| |
| Hint: in order to run this outside the chroot you will need the following |
| from the chroot: |
| |
| /usr/bin: |
| gbb_utility |
| cbootimage |
| vbutil_firmware |
| |
| /usr/lib: |
| liblzma.so.0* |
| libyaml-0.so.1* |
| |
| """ |
| |
| # Python imports |
| import optparse |
| import os |
| import sys |
| |
| # Add the path to our own libraries |
| base = os.path.dirname(sys.argv[0]) |
| sys.path.append(base) |
| sys.path.append(os.path.join(base, 'lib')) |
| |
| import bundle_firmware |
| from bundle_firmware import Bundle |
| import cros_output |
| from tools import Tools |
| from tools import CmdError |
| |
| def _DoBundle(options, output, tools): |
| """The main part of the cros_bundle_firmware code. |
| |
| This takes the supplied options and performs the firmware bundling. |
| |
| Args: |
| options: Parser options. |
| output: cros_output object to use. |
| tools: Tools object to use. |
| """ |
| tools.PrepareOutputDir(options.outdir, options.preserve) |
| if options.includedirs: |
| tools.search_paths += options.includedirs |
| |
| bundle = Bundle(tools=tools, output=output, |
| keydir=options.key, |
| board=options.board, uboot=options.uboot, |
| coreboot=options.coreboot, |
| coreboot_elf=options.coreboot_elf, |
| seabios=options.seabios, |
| ecrw=options.ecrw, |
| ecro=options.ecro, pdrw=options.pdrw, kernel=options.kernel, |
| cbfs_files=options.cbfs_files, |
| rocbfs_files=options.rocbfs_files) |
| |
| try: |
| bundle.Start(options.output, options.show_map) |
| |
| except (CmdError, ValueError) as err: |
| # For verbosity 4 we want to display all possible information |
| if options.verbosity >= 4: |
| raise |
| else: |
| output.Error(str(err)) |
| sys.exit(1) |
| |
| def main(): |
| """Main function for cros_bundle_firmware.""" |
| parser = optparse.OptionParser() |
| parser.add_option('-b', '--board', dest='board', type='string', |
| action='store', help='Board name to use (e.g. tegra2_kaen)', |
| default='tegra2_seaboard') |
| parser.add_option('-C', '--coreboot', dest='coreboot', type='string', |
| action='store', help='Executable lowlevel init file (coreboot)') |
| parser.add_option('--coreboot-elf', type='string', |
| action='store', help='Elf file to use as Coreboot payload') |
| parser.add_option('--cbfs-files', dest='cbfs_files', type='string', |
| action='store', |
| help='Root directory of the files to be stored in RW and RO CBFS') |
| parser.add_option('--rocbfs-files', dest='rocbfs_files', type='string', |
| action='store', |
| help='Root directory of the files to be stored in RO CBFS') |
| parser.add_option('-e', '--ec', dest='ecrw', type='string', |
| action='store', help='EC binary file') |
| parser.add_option('--ecro', type='string', |
| action='store', help='EC read-only binary file') |
| parser.add_option('--force-efs', action='store_true', |
| help='Force early firmware selection') |
| parser.add_option('-F', '--flash', dest='flash_dest', type='string', |
| action='store', help='Create a flasher to flash the device (spi, mmc)') |
| parser.add_option('-k', '--key', dest='key', type='string', action='store', |
| help='Path to signing key directory (default to dev key)', |
| default='##/usr/share/vboot/devkeys') |
| parser.add_option('--kernel', dest='kernel', type='string', |
| action='store', help='Kernel file to ask U-Boot to boot') |
| parser.add_option('-I', '--includedir', dest='includedirs', type='string', |
| action='append', help='Include directory to search for files') |
| parser.add_option('-m', '--map', dest='show_map', action='store_true',\ |
| help='Output a flash map summary') |
| parser.add_option('-M', '--method', type='string', default='tegra', |
| action='store', help='Set USB flash method (tegra/exynos)' |
| 'output files') |
| parser.add_option('-o', '--output', dest='output', type='string', |
| action='store', help='Filename of final output image') |
| parser.add_option('-O', '--outdir', dest='outdir', type='string', |
| action='store', help='Path to directory to use for intermediate and ' |
| 'output files') |
| parser.add_option('-p', '--preserve', dest='preserve', action='store_true',\ |
| help='Preserve temporary output directory even if option -O is not given') |
| parser.add_option('--pd', dest='pdrw', type='string', |
| action='store', help='PD binary file') |
| parser.add_option('-S', '--seabios', dest='seabios', type='string', |
| action='store', help='Legacy BIOS (SeaBIOS)') |
| parser.add_option('--servo', type='string', default='any', |
| action='store', help='Servo to use (none, any, or port number)') |
| parser.add_option('-u', '--uboot', dest='uboot', type='string', |
| action='store', help='Executable bootloader file (U-Boot)') |
| parser.add_option('-U', '--uboot-flasher', dest='uboot_flasher', |
| type='string', action='store', help='Executable bootloader file ' |
| '(U-Boot) to use for flashing (defaults to the same as --uboot)') |
| parser.add_option('-v', '--verbosity', dest='verbosity', default=1, |
| type='int', help='Control verbosity: 0=silent, 1=progress, 3=full, ' |
| '4=debug') |
| (options, args) = parser.parse_args(sys.argv) |
| |
| if len(args) > 1: |
| parser.error("Unrecognized arguments '%s'" % ' '.join(args[1:])) |
| |
| with cros_output.Output(options.verbosity) as output: |
| with Tools(output) as tools: |
| _DoBundle(options, output, tools) |
| |
| |
| def _Test(): |
| """Run any built-in tests.""" |
| import doctest |
| assert doctest.testmod().failed == 0 |
| |
| if __name__ == '__main__': |
| # If first argument is --test, run testing code. |
| if sys.argv[1:2] == ["--test"]: |
| _Test(*sys.argv[2:]) |
| else: |
| main() |