blob: 62dc88c0ad79c4a2779afa0ea32230549d9aab0c [file] [log] [blame]
# 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:
# 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(os.path.join(base, 'lib'))
from fdt import Fdt
from pack_firmware import PackFirmware
import write_firmware
from bundle_firmware import Bundle
import cros_output
from tools import Tools
from tools import CmdError
def _CheckTools(tools, options):
"""Check that all required tools are present.
This just does a simple presence test on the external tools we thing we
might need.
tools: Tools object to use to check tools.
Options: Command line options provided.
CmdError if a required tool is not found.
tools.CheckTool('fdtput', 'dtc')
tools.CheckTool('fdtget', 'dtc')
def _DoBundle(options, output, tools):
"""The main part of the cros_bundle_firmware code.
This takes the supplied options and performs the firmware bundling.
options: Parser options.
output: cros_output object to use.
tools: Tools object to use.
_CheckTools(tools, options)
tools.PrepareOutputDir(options.outdir, options.preserve)
if options.includedirs:
tools.search_paths += options.includedirs
bundle = Bundle(tools, output)
bundle.SetFiles(board=options.board, uboot=options.uboot, bct=options.bct,
bmpblk=options.bmpblk, coreboot=options.coreboot,
postload=options.postload, seabios=options.seabios,
exynos_bl1=options.exynos_bl1, exynos_bl2=options.exynos_bl2,
# Set up the fdt and options that we want.
fdt = bundle.SelectFdt(options.fdt)
bundle.SetBootcmd(options.bootcmd, options.bootsecure)
bundle.AddConfigList(options.add_config_int, use_int=True)
bundle.spl_source = options.spl_source
out_fname, props = bundle.Start(options.hardware_id, options.output,
# Write it to the board if required.
if options.write:
flasher = options.uboot_flasher
if not flasher:
flasher = bundle.uboot_fname
file_list = bundle.GetFiles()
write_firmware.DoWriteFirmware(output, tools, fdt, flasher,
file_list, out_fname, bundle, dest=options.write,
flash_dest=options.flash_dest, props=props)
except (CmdError, ValueError) as err:
# For verbosity 4 we want to display all possible information
if options.verbosity >= 4:
def main():
"""Main function for cros_bundle_firmware."""
parser = optparse.OptionParser()
parser.add_option('--add-config-str', dest='add_config_str', type='string',
nargs=2, action='append', help='Add a /config string to the U-Boot fdt')
parser.add_option('--add-config-int', dest='add_config_int', type='string',
nargs=2, action='append', help='Add a /config integer to the U-Boot fdt')
parser.add_option('-b', '--board', dest='board', type='string',
action='store', help='Board name to use (e.g. tegra2_kaen)',
parser.add_option('-B', '--boot', dest='spl_source', type='string',
action='store', help='Device for SPL to boot from (straps, spi, emmc)',
parser.add_option('--bootcmd', dest='bootcmd', type='string',
help='Set U-Boot boot command')
parser.add_option('--bootsecure', dest='bootsecure',
default=False, action='store_true',
help='Boot command is simple (no arguments) and not interruptible')
# TODO(sjg): Support multiple BCT files
# TODO(sjg): Support source BCT files
parser.add_option('-c', '--bct', dest='bct', type='string', action='store',
help='Path to BCT source file: only one can be given')
# TODO(sjg): Support source FDT files
parser.add_option('-d', '--dt', dest='fdt', type='string', action='store',
help='Path to fdt binary blob .dtb file to use')
parser.add_option('--bl1', dest='exynos_bl1', type='string',
action='store', help='Exynos preboot (BL1) file')
parser.add_option('--bl2', dest='exynos_bl2', type='string',
action='store', help='Exynos Secondary Program Loader (SPL / BL2) file')
parser.add_option('--add-node-enable', dest='add_node_enable',
type='string', nargs=2, action='append',
help='''Set a node to status = "ok" / "disabled".
You can refer to the node with /aliases/... also.
'--set-node-enable /uart@3f8 1' to enable the uart;
'--set-node-enable console 1' to enable the node pointed to by
parser.add_option('--hwid', dest='hardware_id', type='string',
action='store', help='Hardware ID string to use')
parser.add_option('--bmpblk', dest='bmpblk', type='string',
action='store', help='Bitmap block to use')
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)',
parser.add_option('-K', '--skeleton', dest='skeleton', type='string',
action='store', help='Coreboot skeleton file')
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('-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')
parser.add_option('-P', '--postload', dest='postload', type='string',
action='store', help='Path to post-load portion of U-Boot '
parser.add_option('-s', '--small', dest='small', action='store_true',
help='Create/write only the signed U-Boot binary (not the full image)')
parser.add_option('-S', '--seabios', dest='seabios', type='string',
action='store', help='Legacy BIOS (SeaBIOS)')
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('-C', '--coreboot', dest='coreboot', type='string',
action='store', help='Executable lowlevel init file (coreboot)')
parser.add_option('-v', '--verbosity', dest='verbosity', default=1,
type='int', help='Control verbosity: 0=silent, 1=progress, 3=full, '
parser.add_option('-w', '--write', dest='write', type='string',
action='store', help='Write firmware to device (usb, sd)')
(options, args) = parser.parse_args(sys.argv)
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
if __name__ == '__main__':
# If first argument is --test, run testing code.
if sys.argv[1:2] == ["--test"]: