Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 1 | # Copyright (c) 2011 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 | """This module builds a firmware image for a tegra-based board. |
| 6 | |
| 7 | This modules uses a few rudimentary other libraries for its activity. |
| 8 | |
| 9 | Here are the names we give to the various files we deal with. It is important |
| 10 | to keep these consistent! |
| 11 | |
| 12 | uboot u-boot.bin (with no device tree) |
| 13 | fdt the fdt blob |
| 14 | bct the BCT file |
| 15 | bootstub uboot + fdt |
| 16 | signed (uboot + fdt + bct) signed blob |
| 17 | """ |
| 18 | |
Simon Glass | ceff3ff | 2012-04-04 11:23:45 -0700 | [diff] [blame] | 19 | import glob |
Gabe Black | cdbdfe1 | 2013-02-06 05:37:52 -0800 | [diff] [blame] | 20 | import hashlib |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 21 | import os |
| 22 | import re |
| 23 | |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 24 | from fdt import Fdt |
| 25 | from pack_firmware import PackFirmware |
| 26 | import shutil |
Simon Glass | 7c2d557 | 2011-11-15 14:47:08 -0800 | [diff] [blame] | 27 | import struct |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 28 | from tools import CmdError |
Vadim Bendebury | b12e335 | 2013-06-08 17:25:19 -0700 | [diff] [blame] | 29 | from exynos import ExynosBl2 |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 30 | |
| 31 | # This data is required by bmpblk_utility. Does it ever change? |
| 32 | # It was stored with the chromeos-bootimage ebuild, but we want |
| 33 | # this utility to work outside the chroot. |
| 34 | yaml_data = ''' |
| 35 | bmpblock: 1.0 |
| 36 | |
| 37 | images: |
| 38 | devmode: DeveloperBmp/DeveloperBmp.bmp |
| 39 | recovery: RecoveryBmp/RecoveryBmp.bmp |
| 40 | rec_yuck: RecoveryNoOSBmp/RecoveryNoOSBmp.bmp |
| 41 | rec_insert: RecoveryMissingOSBmp/RecoveryMissingOSBmp.bmp |
| 42 | |
| 43 | screens: |
| 44 | dev_en: |
| 45 | - [0, 0, devmode] |
| 46 | rec_en: |
| 47 | - [0, 0, recovery] |
| 48 | yuck_en: |
| 49 | - [0, 0, rec_yuck] |
| 50 | ins_en: |
| 51 | - [0, 0, rec_insert] |
| 52 | |
| 53 | localizations: |
| 54 | - [ dev_en, rec_en, yuck_en, ins_en ] |
| 55 | ''' |
| 56 | |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 57 | # Default flash maps for various boards we support. |
| 58 | # These are used when no fdt is provided (e.g. upstream U-Boot with no |
| 59 | # fdt. Each is a list of nodes. |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 60 | # Note: Use 'reg' instead of 'size' to fully specify the start and end of |
| 61 | # each area, since there is no guarantee what order the nodes will appear |
| 62 | # in the fdt, and if they are out of order the image will not boot. |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 63 | default_flashmaps = { |
Simon Glass | 7695870 | 2012-11-08 13:07:53 -0800 | [diff] [blame] | 64 | 'tegra' : [ |
| 65 | { |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 66 | 'path' : '/flash', |
| 67 | 'reg' : [0, 0x400000], |
| 68 | }, { |
| 69 | 'path' : '/flash/ro-boot', |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 70 | 'label' : 'boot-stub', |
| 71 | 'size' : 512 << 10, |
| 72 | 'read-only' : True, |
| 73 | 'type' : 'blob signed', |
| 74 | 'required' : True |
| 75 | } |
| 76 | ], |
| 77 | 'daisy' : [ |
| 78 | { |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 79 | 'path' : '/flash', |
| 80 | 'reg' : [0, 0x400000], |
| 81 | }, { |
| 82 | 'path' : '/flash/pre-boot', |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 83 | 'label' : "bl1 pre-boot", |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 84 | 'reg' : [0, 0x2000], |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 85 | 'read-only' : True, |
| 86 | 'filename' : "e5250.nbl1.bin", |
| 87 | 'type' : "blob exynos-bl1", |
| 88 | 'required' : True, |
| 89 | }, { |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 90 | 'path' : '/flash/spl', |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 91 | 'label' : "bl2 spl", |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 92 | 'reg' : [0x2000, 0x4000], |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 93 | 'read-only' : True, |
| 94 | 'filename' : "bl2.bin", |
| 95 | 'type' : "blob exynos-bl2 boot,dtb", |
| 96 | 'required' : True, |
| 97 | }, { |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 98 | 'path' : '/flash/ro-boot', |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 99 | 'label' : "u-boot", |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 100 | 'reg' : [0x6000, 0x9a000], |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 101 | 'read-only' : True, |
| 102 | 'type' : "blob boot,dtb", |
| 103 | 'required' : True, |
| 104 | } |
Simon Glass | 7695870 | 2012-11-08 13:07:53 -0800 | [diff] [blame] | 105 | ], |
| 106 | 'link' : [ |
| 107 | { |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 108 | 'path' : '/flash', |
| 109 | 'reg' : [0, 0x800000], |
| 110 | }, { |
| 111 | 'path' : '/flash/si-all', |
Simon Glass | 7695870 | 2012-11-08 13:07:53 -0800 | [diff] [blame] | 112 | 'label' : 'si-all', |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 113 | 'reg' : [0x00000000, 0x00200000], |
Simon Glass | 7695870 | 2012-11-08 13:07:53 -0800 | [diff] [blame] | 114 | 'type' : 'ifd', |
| 115 | 'required' : True, |
| 116 | }, { |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 117 | 'path' : '/flash/ro-boot', |
Simon Glass | 7695870 | 2012-11-08 13:07:53 -0800 | [diff] [blame] | 118 | 'label' : 'boot-stub', |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 119 | 'reg' : [0x00700000, 0x00100000], |
Simon Glass | 7695870 | 2012-11-08 13:07:53 -0800 | [diff] [blame] | 120 | 'read-only' : True, |
| 121 | 'type' : 'blob coreboot', |
| 122 | 'required' : True, |
| 123 | } |
Simon Glass | f253422 | 2013-03-20 15:42:02 -0700 | [diff] [blame] | 124 | ], |
| 125 | 'peach' : [ |
| 126 | { |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 127 | 'path' : '/flash', |
| 128 | 'reg' : [0, 0x400000], |
| 129 | }, { |
| 130 | 'path' : '/flash/pre-boot', |
Simon Glass | f253422 | 2013-03-20 15:42:02 -0700 | [diff] [blame] | 131 | 'label' : "bl1 pre-boot", |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 132 | 'reg' : [0, 0x2000], |
Simon Glass | f253422 | 2013-03-20 15:42:02 -0700 | [diff] [blame] | 133 | 'read-only' : True, |
| 134 | 'filename' : "e5420.nbl1.bin", |
| 135 | 'type' : "blob exynos-bl1", |
| 136 | 'required' : True, |
| 137 | }, { |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 138 | 'path' : '/flash/spl', |
Simon Glass | f253422 | 2013-03-20 15:42:02 -0700 | [diff] [blame] | 139 | 'label' : "bl2 spl", |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 140 | 'reg' : [0x2000, 0x8000], |
Simon Glass | f253422 | 2013-03-20 15:42:02 -0700 | [diff] [blame] | 141 | 'read-only' : True, |
| 142 | 'filename' : "bl2.bin", |
| 143 | 'type' : "blob exynos-bl2 boot,dtb", |
| 144 | 'required' : True, |
| 145 | }, { |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 146 | 'path' : '/flash/ro-boot', |
Simon Glass | f253422 | 2013-03-20 15:42:02 -0700 | [diff] [blame] | 147 | 'label' : "u-boot", |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 148 | 'reg' : [0xa000, 0x9a000], |
Simon Glass | f253422 | 2013-03-20 15:42:02 -0700 | [diff] [blame] | 149 | 'read-only' : True, |
| 150 | 'type' : "blob boot,dtb", |
| 151 | 'required' : True, |
| 152 | } |
| 153 | ], |
Simon Glass | 0c54ba5 | 2012-11-06 12:36:43 -0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | |
Simon Glass | 4a887b1 | 2012-10-23 16:29:03 -0700 | [diff] [blame] | 157 | # Build GBB flags. |
| 158 | # (src/platform/vboot_reference/firmware/include/gbb_header.h) |
| 159 | gbb_flag_properties = { |
| 160 | 'dev-screen-short-delay': 0x00000001, |
| 161 | 'load-option-roms': 0x00000002, |
| 162 | 'enable-alternate-os': 0x00000004, |
| 163 | 'force-dev-switch-on': 0x00000008, |
| 164 | 'force-dev-boot-usb': 0x00000010, |
| 165 | 'disable-fw-rollback-check': 0x00000020, |
| 166 | 'enter-triggers-tonorm': 0x00000040, |
| 167 | 'force-dev-boot-legacy': 0x00000080, |
| 168 | } |
| 169 | |
Simon Glass | 49b026b | 2013-04-26 16:38:42 -0700 | [diff] [blame] | 170 | # Maps board name to Exynos product number |
| 171 | type_to_model = { |
| 172 | 'peach' : '5420', |
| 173 | 'daisy' : '5250' |
| 174 | } |
| 175 | |
Simon Glass | 5076a7f | 2012-10-23 16:31:54 -0700 | [diff] [blame] | 176 | def ListGoogleBinaryBlockFlags(): |
| 177 | """Print out a list of GBB flags.""" |
| 178 | print ' %-30s %s' % ('Available GBB flags:', 'Hex') |
| 179 | for name, value in gbb_flag_properties.iteritems(): |
| 180 | print ' %-30s %02x' % (name, value) |
| 181 | |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 182 | class Bundle: |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 183 | """This class encapsulates the entire bundle firmware logic. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 184 | |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 185 | Sequence of events: |
| 186 | bundle = Bundle(tools.Tools(), cros_output.Output()) |
| 187 | bundle.SetDirs(...) |
| 188 | bundle.SetFiles(...) |
| 189 | bundle.SetOptions(...) |
| 190 | bundle.SelectFdt(fdt.Fdt('filename.dtb') |
Simon Glass | a4934b7 | 2012-05-09 13:35:02 -0700 | [diff] [blame] | 191 | .. can call bundle.AddConfigList(), AddEnableList() if required |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 192 | bundle.Start(...) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 193 | |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 194 | Public properties: |
| 195 | fdt: The fdt object that we use for building our image. This wil be the |
| 196 | one specified by the user, except that we might add config options |
| 197 | to it. This is set up by SelectFdt() which must be called before |
| 198 | bundling starts. |
| 199 | uboot_fname: Full filename of the U-Boot binary we use. |
| 200 | bct_fname: Full filename of the BCT file we use. |
Simon Glass | 559b661 | 2012-05-23 13:28:45 -0700 | [diff] [blame] | 201 | spl_source: Source device to load U-Boot from, in SPL: |
| 202 | straps: Select device according to CPU strap pins |
| 203 | spi: Boot from SPI |
| 204 | emmc: Boot from eMMC |
Simon Glass | 23988ae | 2012-03-23 16:55:22 -0700 | [diff] [blame] | 205 | |
| 206 | Private attributes: |
| 207 | _small: True to create a 'small' signed U-Boot, False to produce a |
| 208 | full image. The small U-Boot is enough to boot but will not have |
| 209 | access to GBB, RW U-Boot, etc. |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 210 | """ |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 211 | |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 212 | def __init__(self, tools, output): |
| 213 | """Set up a new Bundle object. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 214 | |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 215 | Args: |
| 216 | tools: A tools.Tools object to use for external tools. |
| 217 | output: A cros_output.Output object to use for program output. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 218 | """ |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 219 | self._tools = tools |
| 220 | self._out = output |
| 221 | |
| 222 | # Set up the things we need to know in order to operate. |
| 223 | self._board = None # Board name, e.g. tegra2_seaboard. |
| 224 | self._fdt_fname = None # Filename of our FDT. |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 225 | self._force_rw = None |
Simon Glass | 00d027e | 2013-07-20 14:51:12 -0600 | [diff] [blame] | 226 | self._force_efs = None |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 227 | self._gbb_flags = None |
| 228 | self._keydir = None |
| 229 | self._small = False |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 230 | self.bct_fname = None # Filename of our BCT file. |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 231 | self.blobs = {} # Table of (type, filename) of arbitrary blobs |
Hung-Te Lin | 5b64938 | 2011-08-03 15:01:16 +0800 | [diff] [blame] | 232 | self.bmpblk_fname = None # Filename of our Bitmap Block |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 233 | self.coreboot_elf = None |
Stefan Reinauer | 8d79d36 | 2011-08-16 14:20:43 -0700 | [diff] [blame] | 234 | self.coreboot_fname = None # Filename of our coreboot binary. |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 235 | self.ecro_fname = None # Filename of EC read-only file |
| 236 | self.ecrw_fname = None # Filename of EC file |
Simon Glass | 7e19922 | 2012-03-13 15:51:18 -0700 | [diff] [blame] | 237 | self.exynos_bl1 = None # Filename of Exynos BL1 (pre-boot) |
| 238 | self.exynos_bl2 = None # Filename of Exynos BL2 (SPL) |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 239 | self.fdt = None # Our Fdt object. |
| 240 | self.kernel_fname = None |
| 241 | self.postload_fname = None |
| 242 | self.seabios_fname = None # Filename of our SeaBIOS payload. |
Simon Glass | 0726795 | 2012-06-08 12:45:13 -0700 | [diff] [blame] | 243 | self.skeleton_fname = None # Filename of Coreboot skeleton file |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 244 | self.uboot_fname = None # Filename of our U-Boot binary. |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 245 | |
| 246 | def SetDirs(self, keydir): |
| 247 | """Set up directories required for Bundle. |
| 248 | |
| 249 | Args: |
| 250 | keydir: Directory containing keys to use for signing firmware. |
| 251 | """ |
| 252 | self._keydir = keydir |
| 253 | |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 254 | def SetFiles(self, board, bct, uboot=None, bmpblk=None, coreboot=None, |
Simon Glass | a10282a | 2013-01-08 17:06:41 -0800 | [diff] [blame] | 255 | coreboot_elf=None, |
Simon Glass | 0726795 | 2012-06-08 12:45:13 -0700 | [diff] [blame] | 256 | postload=None, seabios=None, exynos_bl1=None, exynos_bl2=None, |
Che-Liang Chiou | 3bc344c | 2013-02-21 15:18:03 -0800 | [diff] [blame] | 257 | skeleton=None, ecrw=None, ecro=None, kernel=None, blobs=None): |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 258 | """Set up files required for Bundle. |
| 259 | |
| 260 | Args: |
| 261 | board: The name of the board to target (e.g. tegra2_seaboard). |
| 262 | uboot: The filename of the u-boot.bin image to use. |
| 263 | bct: The filename of the binary BCT file to use. |
Hung-Te Lin | 5b64938 | 2011-08-03 15:01:16 +0800 | [diff] [blame] | 264 | bmpblk: The filename of bitmap block file to use. |
Simon Glass | a10282a | 2013-01-08 17:06:41 -0800 | [diff] [blame] | 265 | coreboot: The filename of the coreboot image to use (on x86). |
| 266 | coreboot_elf: If not none, the ELF file to add as a Coreboot payload. |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 267 | postload: The filename of the u-boot-post.bin image to use. |
Vincent Palatin | f728677 | 2011-10-12 14:31:53 -0700 | [diff] [blame] | 268 | seabios: The filename of the SeaBIOS payload to use if any. |
Simon Glass | 0726795 | 2012-06-08 12:45:13 -0700 | [diff] [blame] | 269 | exynos_bl1: The filename of the exynos BL1 file |
| 270 | exynos_bl2: The filename of the exynos BL2 file (U-Boot spl) |
| 271 | skeleton: The filename of the coreboot skeleton file. |
Simon Glass | be0bc00 | 2012-08-16 12:50:48 -0700 | [diff] [blame] | 272 | ecrw: The filename of the EC (Embedded Controller) read-write file. |
| 273 | ecro: The filename of the EC (Embedded Controller) read-only file. |
Simon Glass | de9c807 | 2012-07-02 22:29:02 -0700 | [diff] [blame] | 274 | kernel: The filename of the kernel file if any. |
Che-Liang Chiou | 3bc344c | 2013-02-21 15:18:03 -0800 | [diff] [blame] | 275 | blobs: List of (type, filename) of arbitrary blobs. |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 276 | """ |
| 277 | self._board = board |
| 278 | self.uboot_fname = uboot |
| 279 | self.bct_fname = bct |
Hung-Te Lin | 5b64938 | 2011-08-03 15:01:16 +0800 | [diff] [blame] | 280 | self.bmpblk_fname = bmpblk |
Stefan Reinauer | 8d79d36 | 2011-08-16 14:20:43 -0700 | [diff] [blame] | 281 | self.coreboot_fname = coreboot |
Simon Glass | a10282a | 2013-01-08 17:06:41 -0800 | [diff] [blame] | 282 | self.coreboot_elf = coreboot_elf |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 283 | self.postload_fname = postload |
Vincent Palatin | f728677 | 2011-10-12 14:31:53 -0700 | [diff] [blame] | 284 | self.seabios_fname = seabios |
Simon Glass | 7e19922 | 2012-03-13 15:51:18 -0700 | [diff] [blame] | 285 | self.exynos_bl1 = exynos_bl1 |
| 286 | self.exynos_bl2 = exynos_bl2 |
Simon Glass | 0726795 | 2012-06-08 12:45:13 -0700 | [diff] [blame] | 287 | self.skeleton_fname = skeleton |
Simon Glass | be0bc00 | 2012-08-16 12:50:48 -0700 | [diff] [blame] | 288 | self.ecrw_fname = ecrw |
| 289 | self.ecro_fname = ecro |
Simon Glass | de9c807 | 2012-07-02 22:29:02 -0700 | [diff] [blame] | 290 | self.kernel_fname = kernel |
Che-Liang Chiou | 3bc344c | 2013-02-21 15:18:03 -0800 | [diff] [blame] | 291 | self.blobs = dict(blobs or ()) |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 292 | |
Simon Glass | 00d027e | 2013-07-20 14:51:12 -0600 | [diff] [blame] | 293 | def SetOptions(self, small, gbb_flags, force_rw=False, force_efs=False): |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 294 | """Set up options supported by Bundle. |
| 295 | |
| 296 | Args: |
| 297 | small: Only create a signed U-Boot - don't produce the full packed |
| 298 | firmware image. This is useful for devs who want to replace just the |
| 299 | U-Boot part while keeping the keys, gbb, etc. the same. |
Simon Glass | 6e486c2 | 2012-10-26 15:43:42 -0700 | [diff] [blame] | 300 | gbb_flags: Specification for string containing adjustments to make. |
| 301 | force_rw: Force firmware into RW mode. |
Simon Glass | 00d027e | 2013-07-20 14:51:12 -0600 | [diff] [blame] | 302 | force_efs: Force firmware to use 'early firmware selection' feature, |
| 303 | where RW firmware is selected before SDRAM is initialized. |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 304 | """ |
| 305 | self._small = small |
Simon Glass | 157c066 | 2012-10-23 13:52:42 -0700 | [diff] [blame] | 306 | self._gbb_flags = gbb_flags |
Simon Glass | 6e486c2 | 2012-10-26 15:43:42 -0700 | [diff] [blame] | 307 | self._force_rw = force_rw |
Simon Glass | 00d027e | 2013-07-20 14:51:12 -0600 | [diff] [blame] | 308 | self._force_efs = force_efs |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 309 | |
Simon Glass | 22f39fb | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 310 | def _GetBuildRoot(self): |
| 311 | """Get the path to this board's 'firmware' directory. |
| 312 | |
| 313 | Returns: |
| 314 | Path to firmware directory, with ## representing the path to the |
| 315 | chroot. |
| 316 | """ |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 317 | if not self._board: |
| 318 | raise ValueError('No board defined - please define a board to use') |
Simon Glass | 22f39fb | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 319 | return os.path.join('##', 'build', self._board, 'firmware') |
| 320 | |
| 321 | def _CheckFdtFilename(self, fname): |
| 322 | """Check provided FDT filename and return the correct name if needed. |
| 323 | |
| 324 | Where the filename lacks a path, add a default path for this board. |
| 325 | Where no FDT filename is provided, select a default one for this board. |
| 326 | |
| 327 | Args: |
| 328 | fname: Proposed FDT filename. |
| 329 | |
| 330 | Returns: |
| 331 | Selected FDT filename, after validation. |
| 332 | """ |
| 333 | build_root = self._GetBuildRoot() |
Simon Glass | 881964d | 2012-04-04 11:34:09 -0700 | [diff] [blame] | 334 | dir_name = os.path.join(build_root, 'dts') |
Simon Glass | 22f39fb | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 335 | if not fname: |
Simon Glass | ceff3ff | 2012-04-04 11:23:45 -0700 | [diff] [blame] | 336 | # Figure out where the file should be, and the name we expect. |
Simon Glass | ceff3ff | 2012-04-04 11:23:45 -0700 | [diff] [blame] | 337 | base_name = re.sub('_', '-', self._board) |
| 338 | |
| 339 | # In case the name exists with a prefix or suffix, find it. |
| 340 | wildcard = os.path.join(dir_name, '*%s*.dts' % base_name) |
| 341 | found_list = glob.glob(self._tools.Filename(wildcard)) |
| 342 | if len(found_list) == 1: |
Simon Glass | 22f39fb | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 343 | fname = found_list[0] |
Simon Glass | ceff3ff | 2012-04-04 11:23:45 -0700 | [diff] [blame] | 344 | else: |
| 345 | # We didn't find anything definite, so set up our expected name. |
Simon Glass | 22f39fb | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 346 | fname = os.path.join(dir_name, '%s.dts' % base_name) |
Simon Glass | ceff3ff | 2012-04-04 11:23:45 -0700 | [diff] [blame] | 347 | |
Simon Glass | 881964d | 2012-04-04 11:34:09 -0700 | [diff] [blame] | 348 | # Convert things like 'exynos5250-daisy' into a full path. |
Simon Glass | 22f39fb | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 349 | root, ext = os.path.splitext(fname) |
Simon Glass | 881964d | 2012-04-04 11:34:09 -0700 | [diff] [blame] | 350 | if not ext and not os.path.dirname(root): |
Simon Glass | 22f39fb | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 351 | fname = os.path.join(dir_name, '%s.dts' % root) |
| 352 | return fname |
| 353 | |
| 354 | def CheckOptions(self): |
| 355 | """Check provided options and select defaults.""" |
| 356 | build_root = self._GetBuildRoot() |
Simon Glass | 881964d | 2012-04-04 11:34:09 -0700 | [diff] [blame] | 357 | |
Simon Glass | 49b026b | 2013-04-26 16:38:42 -0700 | [diff] [blame] | 358 | board_type = self._board.split('_')[0] |
| 359 | model = type_to_model.get(board_type) |
| 360 | |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 361 | if not self.uboot_fname: |
| 362 | self.uboot_fname = os.path.join(build_root, 'u-boot.bin') |
| 363 | if not self.bct_fname: |
| 364 | self.bct_fname = os.path.join(build_root, 'bct', 'board.bct') |
Simon Glass | 2a7f0b3 | 2011-08-26 11:25:17 -0700 | [diff] [blame] | 365 | if not self.bmpblk_fname: |
David Hendricks | bdecc54 | 2012-08-21 13:53:58 -0700 | [diff] [blame] | 366 | self.bmpblk_fname = os.path.join(build_root, 'bmpblk.bin') |
Simon Glass | 49b026b | 2013-04-26 16:38:42 -0700 | [diff] [blame] | 367 | if model: |
| 368 | if not self.exynos_bl1: |
Simon Glass | d05696e | 2013-06-13 20:14:00 -0700 | [diff] [blame] | 369 | self.exynos_bl1 = os.path.join(build_root, 'u-boot.bl1.bin') |
Simon Glass | 49b026b | 2013-04-26 16:38:42 -0700 | [diff] [blame] | 370 | if not self.exynos_bl2: |
Simon Glass | d05696e | 2013-06-13 20:14:00 -0700 | [diff] [blame] | 371 | self.exynos_bl2 = os.path.join(build_root, 'u-boot-spl-wrapped.bin') |
Simon Glass | 0726795 | 2012-06-08 12:45:13 -0700 | [diff] [blame] | 372 | if not self.coreboot_fname: |
| 373 | self.coreboot_fname = os.path.join(build_root, 'coreboot.rom') |
| 374 | if not self.skeleton_fname: |
Stefan Reinauer | 728be82 | 2012-10-02 16:54:09 -0700 | [diff] [blame] | 375 | self.skeleton_fname = os.path.join(build_root, 'coreboot.rom') |
Stefan Reinauer | 9ad5484 | 2012-10-10 12:25:23 -0700 | [diff] [blame] | 376 | if not self.seabios_fname: |
| 377 | self.seabios_fname = 'seabios.cbfs' |
Simon Glass | be0bc00 | 2012-08-16 12:50:48 -0700 | [diff] [blame] | 378 | if not self.ecrw_fname: |
| 379 | self.ecrw_fname = os.path.join(build_root, 'ec.RW.bin') |
| 380 | if not self.ecro_fname: |
| 381 | self.ecro_fname = os.path.join(build_root, 'ec.RO.bin') |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 382 | |
Simon Glass | 7575930 | 2012-03-15 20:26:53 -0700 | [diff] [blame] | 383 | def GetFiles(self): |
| 384 | """Get a list of files that we know about. |
| 385 | |
| 386 | This is the opposite of SetFiles except that we may have put in some |
| 387 | default names. It returns a dictionary containing the filename for |
| 388 | each of a number of pre-defined files. |
| 389 | |
| 390 | Returns: |
| 391 | Dictionary, with one entry for each file. |
| 392 | """ |
| 393 | file_list = { |
| 394 | 'bct' : self.bct_fname, |
| 395 | 'exynos-bl1' : self.exynos_bl1, |
| 396 | 'exynos-bl2' : self.exynos_bl2, |
| 397 | } |
| 398 | return file_list |
| 399 | |
Simon Glass | 4a887b1 | 2012-10-23 16:29:03 -0700 | [diff] [blame] | 400 | def DecodeGBBFlagsFromFdt(self): |
| 401 | """Get Google Binary Block flags from the FDT. |
| 402 | |
| 403 | These should be in the chromeos-config node, like this: |
| 404 | |
| 405 | chromeos-config { |
| 406 | gbb-flag-dev-screen-short-delay; |
| 407 | gbb-flag-force-dev-switch-on; |
| 408 | gbb-flag-force-dev-boot-usb; |
| 409 | gbb-flag-disable-fw-rollback-check; |
| 410 | }; |
| 411 | |
| 412 | Returns: |
| 413 | GBB flags value from FDT. |
| 414 | """ |
| 415 | chromeos_config = self.fdt.GetProps("/chromeos-config") |
| 416 | gbb_flags = 0 |
| 417 | for name in chromeos_config: |
| 418 | if name.startswith('gbb-flag-'): |
| 419 | flag_value = gbb_flag_properties.get(name[9:]) |
| 420 | if flag_value: |
| 421 | gbb_flags |= flag_value |
| 422 | self._out.Notice("FDT: Enabling %s." % name) |
| 423 | else: |
| 424 | raise ValueError("FDT contains invalid GBB flags '%s'" % name) |
| 425 | return gbb_flags |
| 426 | |
Simon Glass | 157c066 | 2012-10-23 13:52:42 -0700 | [diff] [blame] | 427 | def DecodeGBBFlagsFromOptions(self, gbb_flags, adjustments): |
| 428 | """Decode ajustments to the provided GBB flags. |
| 429 | |
| 430 | We support three options: |
| 431 | |
| 432 | hex value: c2 |
| 433 | defined value: force-dev-boot-usb,load-option-roms |
| 434 | adjust default value: -load-option-roms,+force-dev-boot-usb |
| 435 | |
| 436 | The last option starts from the passed-in GBB flags and adds or removes |
| 437 | flags. |
| 438 | |
| 439 | Args: |
| 440 | gbb_flags: Base (default) FDT flags. |
| 441 | adjustments: String containing adjustments to make. |
| 442 | |
| 443 | Returns: |
| 444 | Updated FDT flags. |
| 445 | """ |
| 446 | use_base_value = True |
| 447 | if adjustments: |
| 448 | try: |
| 449 | return int(adjustments, base=16) |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 450 | except (ValueError, TypeError): |
Simon Glass | 157c066 | 2012-10-23 13:52:42 -0700 | [diff] [blame] | 451 | pass |
| 452 | for flag in adjustments.split(','): |
| 453 | oper = None |
| 454 | if flag[0] in ['-', '+']: |
| 455 | oper = flag[0] |
| 456 | flag = flag[1:] |
| 457 | value = gbb_flag_properties.get(flag) |
| 458 | if not value: |
| 459 | raise ValueError("Invalid GBB flag '%s'" % flag) |
| 460 | if oper == '+': |
| 461 | gbb_flags |= value |
Simon Glass | 8481658 | 2012-11-20 10:53:10 -0800 | [diff] [blame] | 462 | self._out.Notice("Cmdline: Enabling %s." % flag) |
Simon Glass | 157c066 | 2012-10-23 13:52:42 -0700 | [diff] [blame] | 463 | elif oper == '-': |
| 464 | gbb_flags &= ~value |
Simon Glass | 8481658 | 2012-11-20 10:53:10 -0800 | [diff] [blame] | 465 | self._out.Notice("Cmdline: Disabling %s." % flag) |
Simon Glass | 157c066 | 2012-10-23 13:52:42 -0700 | [diff] [blame] | 466 | else: |
| 467 | if use_base_value: |
| 468 | gbb_flags = 0 |
| 469 | use_base_value = False |
Simon Glass | 8481658 | 2012-11-20 10:53:10 -0800 | [diff] [blame] | 470 | self._out.Notice('Cmdline: Resetting flags to 0') |
Simon Glass | 157c066 | 2012-10-23 13:52:42 -0700 | [diff] [blame] | 471 | gbb_flags |= value |
Simon Glass | 8481658 | 2012-11-20 10:53:10 -0800 | [diff] [blame] | 472 | self._out.Notice("Cmdline: Enabling %s." % flag) |
Simon Glass | 157c066 | 2012-10-23 13:52:42 -0700 | [diff] [blame] | 473 | |
| 474 | return gbb_flags |
| 475 | |
Simon Glass | 5657757 | 2011-07-19 11:08:06 +1200 | [diff] [blame] | 476 | def _CreateGoogleBinaryBlock(self, hardware_id): |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 477 | """Create a GBB for the image. |
| 478 | |
Simon Glass | 5657757 | 2011-07-19 11:08:06 +1200 | [diff] [blame] | 479 | Args: |
| 480 | hardware_id: Hardware ID to use for this board. If None, then the |
| 481 | default from the Fdt will be used |
| 482 | |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 483 | Returns: |
| 484 | Path of the created GBB file. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 485 | """ |
Simon Glass | 5657757 | 2011-07-19 11:08:06 +1200 | [diff] [blame] | 486 | if not hardware_id: |
Simon Glass | 02d124a | 2012-03-02 14:47:20 -0800 | [diff] [blame] | 487 | hardware_id = self.fdt.GetString('/config', 'hwid') |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 488 | gbb_size = self.fdt.GetFlashPartSize('ro', 'gbb') |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 489 | odir = self._tools.outdir |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 490 | |
Simon Glass | 4a887b1 | 2012-10-23 16:29:03 -0700 | [diff] [blame] | 491 | gbb_flags = self.DecodeGBBFlagsFromFdt() |
Stefan Reinauer | 975e68f | 2012-02-27 13:27:08 -0800 | [diff] [blame] | 492 | |
Simon Glass | 157c066 | 2012-10-23 13:52:42 -0700 | [diff] [blame] | 493 | # Allow command line to override flags |
| 494 | gbb_flags = self.DecodeGBBFlagsFromOptions(gbb_flags, self._gbb_flags) |
| 495 | |
Simon Glass | 4a887b1 | 2012-10-23 16:29:03 -0700 | [diff] [blame] | 496 | self._out.Notice("GBB flags value %#x" % gbb_flags) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 497 | self._out.Progress('Creating GBB') |
| 498 | sizes = [0x100, 0x1000, gbb_size - 0x2180, 0x1000] |
| 499 | sizes = ['%#x' % size for size in sizes] |
| 500 | gbb = 'gbb.bin' |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 501 | keydir = self._tools.Filename(self._keydir) |
| 502 | self._tools.Run('gbb_utility', ['-c', ','.join(sizes), gbb], cwd=odir) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 503 | self._tools.Run('gbb_utility', ['-s', |
Simon Glass | 5657757 | 2011-07-19 11:08:06 +1200 | [diff] [blame] | 504 | '--hwid=%s' % hardware_id, |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 505 | '--rootkey=%s/root_key.vbpubk' % keydir, |
| 506 | '--recoverykey=%s/recovery_key.vbpubk' % keydir, |
Simon Glass | 2a7f0b3 | 2011-08-26 11:25:17 -0700 | [diff] [blame] | 507 | '--bmpfv=%s' % self._tools.Filename(self.bmpblk_fname), |
Stefan Reinauer | 975e68f | 2012-02-27 13:27:08 -0800 | [diff] [blame] | 508 | '--flags=%d' % gbb_flags, |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 509 | gbb], |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 510 | cwd=odir) |
| 511 | return os.path.join(odir, gbb) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 512 | |
Simon Glass | e13ee2c | 2011-07-28 08:12:28 +1200 | [diff] [blame] | 513 | def _SignBootstub(self, bct, bootstub, text_base): |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 514 | """Sign an image so that the Tegra SOC will boot it. |
| 515 | |
| 516 | Args: |
| 517 | bct: BCT file to use. |
| 518 | bootstub: Boot stub (U-Boot + fdt) file to sign. |
| 519 | text_base: Address of text base for image. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 520 | |
| 521 | Returns: |
| 522 | filename of signed image. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 523 | """ |
| 524 | # First create a config file - this is how we instruct cbootimage |
Simon Glass | e13ee2c | 2011-07-28 08:12:28 +1200 | [diff] [blame] | 525 | signed = os.path.join(self._tools.outdir, 'signed.bin') |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 526 | self._out.Progress('Signing Bootstub') |
Simon Glass | e13ee2c | 2011-07-28 08:12:28 +1200 | [diff] [blame] | 527 | config = os.path.join(self._tools.outdir, 'boot.cfg') |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 528 | fd = open(config, 'w') |
| 529 | fd.write('Version = 1;\n') |
| 530 | fd.write('Redundancy = 1;\n') |
| 531 | fd.write('Bctfile = %s;\n' % bct) |
Doug Anderson | 0eeb074 | 2011-09-15 18:11:40 -0700 | [diff] [blame] | 532 | |
| 533 | # TODO(dianders): Right now, we don't have enough space in our flash map |
| 534 | # for two copies of the BCT when we're using NAND, so hack it to 1. Not |
| 535 | # sure what this does for reliability, but at least things will fit... |
| 536 | is_nand = "NvBootDevType_Nand" in self._tools.Run('bct_dump', [bct]) |
| 537 | if is_nand: |
| 538 | fd.write('Bctcopy = 1;\n') |
| 539 | |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 540 | fd.write('BootLoader = %s,%#x,%#x,Complete;\n' % (bootstub, text_base, |
| 541 | text_base)) |
Doug Anderson | 0eeb074 | 2011-09-15 18:11:40 -0700 | [diff] [blame] | 542 | |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 543 | fd.close() |
| 544 | |
| 545 | self._tools.Run('cbootimage', [config, signed]) |
| 546 | self._tools.OutputSize('BCT', bct) |
| 547 | self._tools.OutputSize('Signed image', signed) |
| 548 | return signed |
| 549 | |
Doug Anderson | 86ce5f4 | 2011-07-27 10:40:18 -0700 | [diff] [blame] | 550 | def SetBootcmd(self, bootcmd, bootsecure): |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 551 | """Set the boot command for U-Boot. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 552 | |
| 553 | Args: |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 554 | bootcmd: Boot command to use, as a string (if None this this is a nop). |
Doug Anderson | 86ce5f4 | 2011-07-27 10:40:18 -0700 | [diff] [blame] | 555 | bootsecure: We'll set '/config/bootsecure' to 1 if True and 0 if False. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 556 | """ |
Simon Glass | 468d875 | 2012-09-19 16:36:19 -0700 | [diff] [blame] | 557 | if bootcmd is not None: |
| 558 | if bootcmd == 'none': |
| 559 | bootcmd = '' |
Simon Glass | 02d124a | 2012-03-02 14:47:20 -0800 | [diff] [blame] | 560 | self.fdt.PutString('/config', 'bootcmd', bootcmd) |
| 561 | self.fdt.PutInteger('/config', 'bootsecure', int(bootsecure)) |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 562 | self._out.Info('Boot command: %s' % bootcmd) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 563 | |
Simon Glass | a4934b7 | 2012-05-09 13:35:02 -0700 | [diff] [blame] | 564 | def SetNodeEnabled(self, node_name, enabled): |
| 565 | """Set whether an node is enabled or disabled. |
| 566 | |
| 567 | This simply sets the 'status' property of a node to "ok", or "disabled". |
| 568 | |
| 569 | The node should either be a full path to the node (like '/uart@10200000') |
| 570 | or an alias property. |
| 571 | |
| 572 | Aliases are supported like this: |
| 573 | |
| 574 | aliases { |
| 575 | console = "/uart@10200000"; |
| 576 | }; |
| 577 | |
| 578 | pointing to a node: |
| 579 | |
| 580 | uart@10200000 { |
Simon Glass | 4c5066f | 2012-06-20 16:51:19 -0700 | [diff] [blame] | 581 | status = "okay"; |
Simon Glass | a4934b7 | 2012-05-09 13:35:02 -0700 | [diff] [blame] | 582 | }; |
| 583 | |
| 584 | In this case, this function takes the name of the alias ('console' in |
| 585 | this case) and updates the status of the node that is pointed to, to |
| 586 | either ok or disabled. If the alias does not exist, a warning is |
| 587 | displayed. |
| 588 | |
| 589 | Args: |
| 590 | node_name: Name of node (e.g. '/uart@10200000') or alias alias |
| 591 | (e.g. 'console') to adjust |
| 592 | enabled: True to enable, False to disable |
| 593 | """ |
| 594 | # Look up the alias if this is an alias reference |
| 595 | if not node_name.startswith('/'): |
| 596 | lookup = self.fdt.GetString('/aliases', node_name, '') |
| 597 | if not lookup: |
| 598 | self._out.Warning("Cannot find alias '%s' - ignoring" % node_name) |
| 599 | return |
| 600 | node_name = lookup |
| 601 | if enabled: |
Simon Glass | 4c5066f | 2012-06-20 16:51:19 -0700 | [diff] [blame] | 602 | status = 'okay' |
Simon Glass | a4934b7 | 2012-05-09 13:35:02 -0700 | [diff] [blame] | 603 | else: |
| 604 | status = 'disabled' |
| 605 | self.fdt.PutString(node_name, 'status', status) |
| 606 | |
| 607 | def AddEnableList(self, enable_list): |
| 608 | """Process a list of nodes to enable/disable. |
| 609 | |
| 610 | Args: |
| 611 | config_list: List of (node, value) tuples to add to the fdt. For each |
| 612 | tuple: |
| 613 | node: The fdt node to write to will be <node> or pointed to by |
| 614 | /aliases/<node>. We can tell which |
| 615 | value: 0 to disable the node, 1 to enable it |
Vadim Bendebury | 507c001 | 2013-06-09 12:49:25 -0700 | [diff] [blame] | 616 | Raises: |
| 617 | CmdError if a command fails. |
Simon Glass | a4934b7 | 2012-05-09 13:35:02 -0700 | [diff] [blame] | 618 | """ |
| 619 | if enable_list: |
| 620 | for node_name, enabled in enable_list: |
| 621 | try: |
| 622 | enabled = int(enabled) |
| 623 | if enabled not in (0, 1): |
| 624 | raise ValueError |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 625 | except ValueError: |
Simon Glass | a4934b7 | 2012-05-09 13:35:02 -0700 | [diff] [blame] | 626 | raise CmdError("Invalid enable option value '%s' " |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 627 | "(should be 0 or 1)" % str(enabled)) |
Simon Glass | a4934b7 | 2012-05-09 13:35:02 -0700 | [diff] [blame] | 628 | self.SetNodeEnabled(node_name, enabled) |
| 629 | |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 630 | def AddConfigList(self, config_list, use_int=False): |
| 631 | """Add a list of config items to the fdt. |
| 632 | |
| 633 | Normally these values are written to the fdt as strings, but integers |
| 634 | are also supported, in which case the values will be converted to integers |
| 635 | (if necessary) before being stored. |
| 636 | |
| 637 | Args: |
| 638 | config_list: List of (config, value) tuples to add to the fdt. For each |
| 639 | tuple: |
| 640 | config: The fdt node to write to will be /config/<config>. |
| 641 | value: An integer or string value to write. |
| 642 | use_int: True to only write integer values. |
| 643 | |
| 644 | Raises: |
| 645 | CmdError: if a value is required to be converted to integer but can't be. |
| 646 | """ |
| 647 | if config_list: |
| 648 | for config in config_list: |
| 649 | value = config[1] |
| 650 | if use_int: |
| 651 | try: |
| 652 | value = int(value) |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 653 | except ValueError: |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 654 | raise CmdError("Cannot convert config option '%s' to integer" % |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 655 | str(value)) |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 656 | if type(value) == type(1): |
Simon Glass | 02d124a | 2012-03-02 14:47:20 -0800 | [diff] [blame] | 657 | self.fdt.PutInteger('/config', '%s' % config[0], value) |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 658 | else: |
Simon Glass | 02d124a | 2012-03-02 14:47:20 -0800 | [diff] [blame] | 659 | self.fdt.PutString('/config', '%s' % config[0], value) |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 660 | |
Simon Glass | 7c2d557 | 2011-11-15 14:47:08 -0800 | [diff] [blame] | 661 | def DecodeTextBase(self, data): |
| 662 | """Look at a U-Boot image and try to decode its TEXT_BASE. |
| 663 | |
| 664 | This works because U-Boot has a header with the value 0x12345678 |
| 665 | immediately followed by the TEXT_BASE value. We can therefore read this |
| 666 | from the image with some certainty. We check only the first 40 words |
| 667 | since the header should be within that region. |
| 668 | |
Simon Glass | 96b5030 | 2012-07-20 06:55:28 +0100 | [diff] [blame] | 669 | Since upstream Tegra has moved to having a 16KB SPL region at the start, |
| 670 | and currently this does holds the U-Boot text base (e.g. 0x10c000) instead |
| 671 | of the SPL one (e.g. 0x108000), we search in the U-Boot part as well. |
| 672 | |
Simon Glass | 7c2d557 | 2011-11-15 14:47:08 -0800 | [diff] [blame] | 673 | Args: |
| 674 | data: U-Boot binary data |
| 675 | |
| 676 | Returns: |
| 677 | Text base (integer) or None if none was found |
| 678 | """ |
| 679 | found = False |
Simon Glass | 96b5030 | 2012-07-20 06:55:28 +0100 | [diff] [blame] | 680 | for start in (0, 0x4000): |
| 681 | for i in range(start, start + 160, 4): |
| 682 | word = data[i:i + 4] |
Simon Glass | 7c2d557 | 2011-11-15 14:47:08 -0800 | [diff] [blame] | 683 | |
Simon Glass | 96b5030 | 2012-07-20 06:55:28 +0100 | [diff] [blame] | 684 | # TODO(sjg): This does not cope with a big-endian target |
| 685 | value = struct.unpack('<I', word)[0] |
| 686 | if found: |
| 687 | return value - start |
| 688 | if value == 0x12345678: |
| 689 | found = True |
Simon Glass | 7c2d557 | 2011-11-15 14:47:08 -0800 | [diff] [blame] | 690 | |
| 691 | return None |
| 692 | |
| 693 | def CalcTextBase(self, name, fdt, fname): |
| 694 | """Calculate the TEXT_BASE to use for U-Boot. |
| 695 | |
| 696 | Normally this value is in the fdt, so we just read it from there. But as |
| 697 | a second check we look at the image itself in case this is different, and |
| 698 | switch to that if it is. |
| 699 | |
| 700 | This allows us to flash any U-Boot even if its TEXT_BASE is different. |
| 701 | This is particularly useful with upstream U-Boot which uses a different |
| 702 | value (which we will move to). |
| 703 | """ |
| 704 | data = self._tools.ReadFile(fname) |
Andrew Chew | aa09254 | 2013-01-09 16:30:52 -0800 | [diff] [blame] | 705 | # The value that comes back from fdt.GetInt is signed, which makes no |
| 706 | # sense for an address base. Force it to unsigned. |
| 707 | fdt_text_base = fdt.GetInt('/chromeos-config', 'textbase', 0) & 0xffffffff |
Simon Glass | 7c2d557 | 2011-11-15 14:47:08 -0800 | [diff] [blame] | 708 | text_base = self.DecodeTextBase(data) |
Simon Glass | 96b5030 | 2012-07-20 06:55:28 +0100 | [diff] [blame] | 709 | text_base_str = '%#x' % text_base if text_base else 'None' |
| 710 | self._out.Info('TEXT_BASE: fdt says %#x, %s says %s' % (fdt_text_base, |
| 711 | fname, text_base_str)) |
Simon Glass | 7c2d557 | 2011-11-15 14:47:08 -0800 | [diff] [blame] | 712 | |
| 713 | # If they are different, issue a warning and switch over. |
| 714 | if text_base and text_base != fdt_text_base: |
| 715 | self._out.Warning("TEXT_BASE %x in %sU-Boot doesn't match " |
| 716 | "fdt value of %x. Using %x" % (text_base, name, |
| 717 | fdt_text_base, text_base)) |
| 718 | fdt_text_base = text_base |
| 719 | return fdt_text_base |
| 720 | |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 721 | def _CreateBootStub(self, uboot, base_fdt, postload): |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 722 | """Create a boot stub and a signed boot stub. |
| 723 | |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 724 | For postload: |
| 725 | We add a /config/postload-text-offset entry to the signed bootstub's |
| 726 | fdt so that U-Boot can find the postload code. |
| 727 | |
| 728 | The raw (unsigned) bootstub will have a value of -1 for this since we will |
| 729 | simply append the postload code to the bootstub and it can find it there. |
| 730 | This will be used for RW A/B firmware. |
| 731 | |
| 732 | For the signed case this value will specify where in the flash to find |
| 733 | the postload code. This will be used for RO firmware. |
| 734 | |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 735 | Args: |
| 736 | uboot: Path to u-boot.bin (may be chroot-relative) |
Simon Glass | 29b96ad | 2012-03-09 15:34:33 -0800 | [diff] [blame] | 737 | base_fdt: Fdt object containing the flat device tree. |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 738 | postload: Path to u-boot-post.bin, or None if none. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 739 | |
| 740 | Returns: |
| 741 | Tuple containing: |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 742 | Full path to bootstub (uboot + fdt(-1) + postload). |
| 743 | Full path to signed (uboot + fdt(flash pos) + bct) + postload. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 744 | |
| 745 | Raises: |
| 746 | CmdError if a command fails. |
| 747 | """ |
Simon Glass | e13ee2c | 2011-07-28 08:12:28 +1200 | [diff] [blame] | 748 | bootstub = os.path.join(self._tools.outdir, 'u-boot-fdt.bin') |
Simon Glass | 7c2d557 | 2011-11-15 14:47:08 -0800 | [diff] [blame] | 749 | text_base = self.CalcTextBase('', self.fdt, uboot) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 750 | uboot_data = self._tools.ReadFile(uboot) |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 751 | |
| 752 | # Make a copy of the fdt for the bootstub |
| 753 | fdt = base_fdt.Copy(os.path.join(self._tools.outdir, 'bootstub.dtb')) |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 754 | fdt.PutInteger('/config', 'postload-text-offset', 0xffffffff) |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 755 | fdt_data = self._tools.ReadFile(fdt.fname) |
Simon Glass | e13ee2c | 2011-07-28 08:12:28 +1200 | [diff] [blame] | 756 | |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 757 | self._tools.WriteFile(bootstub, uboot_data + fdt_data) |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 758 | self._tools.OutputSize('U-Boot binary', self.uboot_fname) |
| 759 | self._tools.OutputSize('U-Boot fdt', self._fdt_fname) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 760 | self._tools.OutputSize('Combined binary', bootstub) |
| 761 | |
Simon Glass | e13ee2c | 2011-07-28 08:12:28 +1200 | [diff] [blame] | 762 | # Sign the bootstub; this is a combination of the board specific |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 763 | # bct and the stub u-boot image. |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 764 | signed = self._SignBootstub(self._tools.Filename(self.bct_fname), |
Simon Glass | e13ee2c | 2011-07-28 08:12:28 +1200 | [diff] [blame] | 765 | bootstub, text_base) |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 766 | |
| 767 | signed_postload = os.path.join(self._tools.outdir, 'signed-postload.bin') |
| 768 | data = self._tools.ReadFile(signed) |
| 769 | |
| 770 | if postload: |
| 771 | # We must add postload to the bootstub since A and B will need to |
| 772 | # be able to find it without the /config/postload-text-offset mechanism. |
| 773 | bs_data = self._tools.ReadFile(bootstub) |
| 774 | bs_data += self._tools.ReadFile(postload) |
| 775 | bootstub = os.path.join(self._tools.outdir, 'u-boot-fdt-postload.bin') |
| 776 | self._tools.WriteFile(bootstub, bs_data) |
| 777 | self._tools.OutputSize('Combined binary with postload', bootstub) |
| 778 | |
| 779 | # Now that we know the file size, adjust the fdt and re-sign |
| 780 | postload_bootstub = os.path.join(self._tools.outdir, 'postload.bin') |
Simon Glass | 02d124a | 2012-03-02 14:47:20 -0800 | [diff] [blame] | 781 | fdt.PutInteger('/config', 'postload-text-offset', len(data)) |
Simon Glass | 6dcc2f2 | 2011-07-28 15:26:49 +1200 | [diff] [blame] | 782 | fdt_data = self._tools.ReadFile(fdt.fname) |
| 783 | self._tools.WriteFile(postload_bootstub, uboot_data + fdt_data) |
| 784 | signed = self._SignBootstub(self._tools.Filename(self.bct_fname), |
| 785 | postload_bootstub, text_base) |
| 786 | if len(data) != os.path.getsize(signed): |
| 787 | raise CmdError('Signed file size changed from %d to %d after updating ' |
| 788 | 'fdt' % (len(data), os.path.getsize(signed))) |
| 789 | |
| 790 | # Re-read the signed image, and add the post-load binary. |
| 791 | data = self._tools.ReadFile(signed) |
| 792 | data += self._tools.ReadFile(postload) |
| 793 | self._tools.OutputSize('Post-load binary', postload) |
| 794 | |
| 795 | self._tools.WriteFile(signed_postload, data) |
| 796 | self._tools.OutputSize('Final bootstub with postload', signed_postload) |
| 797 | |
| 798 | return bootstub, signed_postload |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 799 | |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 800 | def _CreateCorebootStub(self, coreboot): |
Stefan Reinauer | c2e1e4d | 2011-08-23 14:50:59 -0700 | [diff] [blame] | 801 | """Create a coreboot boot stub. |
| 802 | |
| 803 | Args: |
Stefan Reinauer | c2e1e4d | 2011-08-23 14:50:59 -0700 | [diff] [blame] | 804 | coreboot: Path to coreboot.rom |
Stefan Reinauer | c2e1e4d | 2011-08-23 14:50:59 -0700 | [diff] [blame] | 805 | |
| 806 | Returns: |
Simon Glass | cbc8355 | 2012-07-23 15:26:22 +0100 | [diff] [blame] | 807 | Full path to bootstub (coreboot + uboot). |
Stefan Reinauer | c2e1e4d | 2011-08-23 14:50:59 -0700 | [diff] [blame] | 808 | """ |
| 809 | bootstub = os.path.join(self._tools.outdir, 'coreboot-full.rom') |
Simon Glass | f2b3a5c | 2012-06-07 14:02:36 -0700 | [diff] [blame] | 810 | shutil.copyfile(self._tools.Filename(coreboot), bootstub) |
Simon Glass | cbc8355 | 2012-07-23 15:26:22 +0100 | [diff] [blame] | 811 | |
| 812 | # Don't add the fdt yet since it is not in final form |
Stefan Reinauer | c2e1e4d | 2011-08-23 14:50:59 -0700 | [diff] [blame] | 813 | return bootstub |
| 814 | |
Simon Glass | 7e19922 | 2012-03-13 15:51:18 -0700 | [diff] [blame] | 815 | |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 816 | def _PackOutput(self, msg): |
| 817 | """Helper function to write output from PackFirmware (verbose level 2). |
| 818 | |
| 819 | This is passed to PackFirmware for it to use to write output. |
| 820 | |
| 821 | Args: |
| 822 | msg: Message to display. |
| 823 | """ |
| 824 | self._out.Notice(msg) |
| 825 | |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 826 | def _BuildBlob(self, pack, fdt, blob_type): |
| 827 | """Build the blob data for a particular blob type. |
| 828 | |
| 829 | Args: |
| 830 | blob_type: The type of blob to create data for. Supported types are: |
| 831 | coreboot A coreboot image (ROM plus U-boot and .dtb payloads). |
| 832 | signed Nvidia T20/T30 signed image (BCT, U-Boot, .dtb). |
Vadim Bendebury | 507c001 | 2013-06-09 12:49:25 -0700 | [diff] [blame] | 833 | |
| 834 | Raises: |
| 835 | CmdError if a command fails. |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 836 | """ |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 837 | # stupid pylint insists that sha256 is not in hashlib. |
| 838 | # pylint: disable=E1101 |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 839 | if blob_type == 'coreboot': |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 840 | coreboot = self._CreateCorebootStub(self.coreboot_fname) |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 841 | pack.AddProperty('coreboot', coreboot) |
| 842 | pack.AddProperty('image', coreboot) |
Stefan Reinauer | 9ad5484 | 2012-10-10 12:25:23 -0700 | [diff] [blame] | 843 | elif blob_type == 'legacy': |
| 844 | pack.AddProperty('legacy', self.seabios_fname) |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 845 | elif blob_type == 'signed': |
| 846 | bootstub, signed = self._CreateBootStub(self.uboot_fname, fdt, |
| 847 | self.postload_fname) |
| 848 | pack.AddProperty('bootstub', bootstub) |
| 849 | pack.AddProperty('signed', signed) |
| 850 | pack.AddProperty('image', signed) |
Simon Glass | 7e19922 | 2012-03-13 15:51:18 -0700 | [diff] [blame] | 851 | elif blob_type == 'exynos-bl1': |
| 852 | pack.AddProperty(blob_type, self.exynos_bl1) |
Simon Glass | be0bc00 | 2012-08-16 12:50:48 -0700 | [diff] [blame] | 853 | |
| 854 | # TODO(sjg@chromium.org): Deprecate ecbin |
| 855 | elif blob_type in ['ecrw', 'ecbin']: |
| 856 | pack.AddProperty('ecrw', self.ecrw_fname) |
| 857 | pack.AddProperty('ecbin', self.ecrw_fname) |
Gabe Black | cdbdfe1 | 2013-02-06 05:37:52 -0800 | [diff] [blame] | 858 | elif blob_type == 'ecrwhash': |
| 859 | ec_hash_file = os.path.join(self._tools.outdir, 'ec_hash.bin') |
| 860 | ecrw = self._tools.ReadFile(self.ecrw_fname) |
| 861 | hasher = hashlib.sha256() |
| 862 | hasher.update(ecrw) |
| 863 | self._tools.WriteFile(ec_hash_file, hasher.digest()) |
| 864 | pack.AddProperty(blob_type, ec_hash_file) |
Simon Glass | be0bc00 | 2012-08-16 12:50:48 -0700 | [diff] [blame] | 865 | elif blob_type == 'ecro': |
Simon Glass | 693b40f | 2012-08-28 10:51:05 -0700 | [diff] [blame] | 866 | # crosbug.com/p/13143 |
| 867 | # We cannot have an fmap in the EC image since there can be only one, |
| 868 | # which is the main fmap describing the whole image. |
| 869 | # Ultimately the EC will not have an fmap, since with software sync |
| 870 | # there is no flashrom involvement in updating the EC flash, and thus |
| 871 | # no need for the fmap. |
| 872 | # For now, mangle the fmap name to avoid problems. |
| 873 | updated_ecro = os.path.join(self._tools.outdir, 'updated-ecro.bin') |
| 874 | data = self._tools.ReadFile(self.ecro_fname) |
| 875 | data = re.sub('__FMAP__', '__fMAP__', data) |
| 876 | self._tools.WriteFile(updated_ecro, data) |
| 877 | pack.AddProperty(blob_type, updated_ecro) |
Simon Glass | 0a047bc | 2013-07-19 15:44:43 -0600 | [diff] [blame] | 878 | elif blob_type.startswith('exynos-bl2'): |
| 879 | # We need to configure this per node, so do it later |
| 880 | pass |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 881 | elif pack.GetProperty(blob_type): |
| 882 | pass |
Che-Liang Chiou | 3bc344c | 2013-02-21 15:18:03 -0800 | [diff] [blame] | 883 | elif blob_type in self.blobs: |
| 884 | pack.AddProperty(blob_type, self.blobs[blob_type]) |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 885 | else: |
| 886 | raise CmdError("Unknown blob type '%s' required in flash map" % |
| 887 | blob_type) |
| 888 | |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 889 | def _CreateImage(self, gbb, fdt): |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 890 | """Create a full firmware image, along with various by-products. |
| 891 | |
| 892 | This uses the provided u-boot.bin, fdt and bct to create a firmware |
| 893 | image containing all the required parts. If the GBB is not supplied |
| 894 | then this will just return a signed U-Boot as the image. |
| 895 | |
| 896 | Args: |
Simon Glass | e13ee2c | 2011-07-28 08:12:28 +1200 | [diff] [blame] | 897 | gbb: Full path to the GBB file, or empty if a GBB is not required. |
| 898 | fdt: Fdt object containing required information. |
| 899 | |
| 900 | Returns: |
| 901 | Path to image file |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 902 | """ |
Simon Glass | 02d124a | 2012-03-02 14:47:20 -0800 | [diff] [blame] | 903 | self._out.Notice("Model: %s" % fdt.GetString('/', 'model')) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 904 | |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 905 | pack = PackFirmware(self._tools, self._out) |
Vadim Bendebury | 238f644 | 2013-03-27 11:23:25 -0700 | [diff] [blame] | 906 | # Get the flashmap so we know what to build. For board variants use the |
| 907 | # main board name as the key (drop the _<variant> suffix). |
| 908 | default_flashmap = default_flashmaps.get(self._board.split('_')[0]) |
Simon Glass | b8c6d95 | 2012-12-01 06:14:35 -0800 | [diff] [blame] | 909 | if self._force_rw: |
Vadim Bendebury | 7bfdb37 | 2013-03-27 11:52:58 -0700 | [diff] [blame] | 910 | fdt.PutInteger('/flash/rw-a-vblock', 'preamble-flags', 0) |
| 911 | fdt.PutInteger('/flash/rw-b-vblock', 'preamble-flags', 0) |
Simon Glass | 00d027e | 2013-07-20 14:51:12 -0600 | [diff] [blame] | 912 | if self._force_efs: |
| 913 | fdt.PutInteger('/chromeos-config', 'early-firmware-selection', 1) |
Simon Glass | b8c6d95 | 2012-12-01 06:14:35 -0800 | [diff] [blame] | 914 | |
Simon Glass | 4f31891 | 2013-07-20 16:13:06 -0600 | [diff] [blame] | 915 | if not fdt.GetProp('/flash', 'reg', ''): |
| 916 | fdt.InsertNodes(default_flashmap) |
| 917 | |
| 918 | pack.SelectFdt(fdt, self._board) |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 919 | |
| 920 | # Get all our blobs ready |
| 921 | pack.AddProperty('boot', self.uboot_fname) |
Simon Glass | 284cb89 | 2013-02-09 13:38:03 -0800 | [diff] [blame] | 922 | if self.skeleton_fname: |
| 923 | pack.AddProperty('skeleton', self.skeleton_fname) |
Simon Glass | 3b85f71 | 2012-06-21 07:06:46 -0700 | [diff] [blame] | 924 | pack.AddProperty('dtb', fdt.fname) |
Simon Glass | 50f7460 | 2012-03-15 21:04:25 -0700 | [diff] [blame] | 925 | |
Simon Glass | de9c807 | 2012-07-02 22:29:02 -0700 | [diff] [blame] | 926 | # If we are writing a kernel, add its offset from TEXT_BASE to the fdt. |
| 927 | if self.kernel_fname: |
| 928 | fdt.PutInteger('/config', 'kernel-offset', pack.image_size) |
| 929 | |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 930 | pack.AddProperty('gbb', self.uboot_fname) |
Simon Glass | 9d088d9 | 2012-07-16 16:27:11 +0100 | [diff] [blame] | 931 | blob_list = pack.GetBlobList() |
| 932 | self._out.Info('Building blobs %s\n' % blob_list) |
Simon Glass | 0726795 | 2012-06-08 12:45:13 -0700 | [diff] [blame] | 933 | for blob_type in pack.GetBlobList(): |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 934 | self._BuildBlob(pack, fdt, blob_type) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 935 | |
Simon Glass | 7306b90 | 2012-12-17 15:06:21 -0800 | [diff] [blame] | 936 | self._out.Progress('Packing image') |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 937 | if gbb: |
Simon Glass | e76bf7b | 2012-03-13 15:34:41 -0700 | [diff] [blame] | 938 | pack.RequireAllEntries() |
Hung-Te Lin | a7462e7 | 2011-07-27 19:17:10 +0800 | [diff] [blame] | 939 | fwid = '.'.join([ |
Simon Glass | 02d124a | 2012-03-02 14:47:20 -0800 | [diff] [blame] | 940 | re.sub('[ ,]+', '_', fdt.GetString('/', 'model')), |
Hung-Te Lin | a7462e7 | 2011-07-27 19:17:10 +0800 | [diff] [blame] | 941 | self._tools.GetChromeosVersion()]) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 942 | self._out.Notice('Firmware ID: %s' % fwid) |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 943 | pack.AddProperty('fwid', fwid) |
| 944 | pack.AddProperty('gbb', gbb) |
| 945 | pack.AddProperty('keydir', self._keydir) |
Simon Glass | c90cf58 | 2012-03-13 15:40:47 -0700 | [diff] [blame] | 946 | |
Simon Glass | 0a047bc | 2013-07-19 15:44:43 -0600 | [diff] [blame] | 947 | # Some blobs need to be configured according to the node they are in. |
Simon Glass | 4c24f66 | 2013-07-19 15:53:02 -0600 | [diff] [blame] | 948 | todo = pack.GetMissingBlobs() |
| 949 | for blob in todo: |
Simon Glass | 0a047bc | 2013-07-19 15:44:43 -0600 | [diff] [blame] | 950 | if blob.key.startswith('exynos-bl2'): |
| 951 | bl2 = ExynosBl2(self._tools, self._out) |
| 952 | pack.AddProperty(blob.key, bl2.MakeSpl(pack, fdt, blob, |
| 953 | self.exynos_bl2)) |
| 954 | |
Simon Glass | c90cf58 | 2012-03-13 15:40:47 -0700 | [diff] [blame] | 955 | pack.CheckProperties() |
Simon Glass | 8884b98 | 2012-06-21 12:41:41 -0700 | [diff] [blame] | 956 | |
| 957 | # Record position and size of all blob members in the FDT |
Gabe Black | cc22d77 | 2013-02-04 23:12:02 -0800 | [diff] [blame] | 958 | pack.UpdateBlobPositionsAndHashes(fdt) |
Simon Glass | 8884b98 | 2012-06-21 12:41:41 -0700 | [diff] [blame] | 959 | |
Simon Glass | 4c24f66 | 2013-07-19 15:53:02 -0600 | [diff] [blame] | 960 | # Recalculate the Exynos BL2, since it may have a hash. The call to |
| 961 | # UpdateBlobPositionsAndHashes() may have updated the hash-target so we |
| 962 | # need to recalculate the hash. |
| 963 | for blob in todo: |
| 964 | if blob.key.startswith('exynos-bl2'): |
| 965 | bl2 = ExynosBl2(self._tools, self._out) |
| 966 | pack.AddProperty(blob.key, bl2.MakeSpl(pack, fdt, blob, |
| 967 | self.exynos_bl2)) |
| 968 | |
Simon Glass | 6207efe | 2012-12-17 15:04:36 -0800 | [diff] [blame] | 969 | # Make a copy of the fdt for the bootstub |
| 970 | fdt_data = self._tools.ReadFile(fdt.fname) |
| 971 | uboot_data = self._tools.ReadFile(self.uboot_fname) |
| 972 | uboot_copy = os.path.join(self._tools.outdir, 'u-boot.bin') |
| 973 | self._tools.WriteFile(uboot_copy, uboot_data) |
| 974 | |
| 975 | uboot_dtb = os.path.join(self._tools.outdir, 'u-boot-dtb.bin') |
| 976 | self._tools.WriteFile(uboot_dtb, uboot_data + fdt_data) |
| 977 | |
Simon Glass | a10282a | 2013-01-08 17:06:41 -0800 | [diff] [blame] | 978 | # Fix up the coreboot image here, since we can't do this until we have |
| 979 | # a final device tree binary. |
Simon Glass | cbc8355 | 2012-07-23 15:26:22 +0100 | [diff] [blame] | 980 | if 'coreboot' in blob_list: |
| 981 | bootstub = pack.GetProperty('coreboot') |
| 982 | fdt = fdt.Copy(os.path.join(self._tools.outdir, 'bootstub.dtb')) |
Simon Glass | a10282a | 2013-01-08 17:06:41 -0800 | [diff] [blame] | 983 | if self.coreboot_elf: |
| 984 | self._tools.Run('cbfstool', [bootstub, 'add-payload', '-f', |
| 985 | self.coreboot_elf, '-n', 'fallback/payload', '-c', 'lzma']) |
| 986 | else: |
Simon Glass | 0a7cf11 | 2013-05-21 23:08:21 -0700 | [diff] [blame] | 987 | text_base = 0x1110000 |
| 988 | |
| 989 | # This is the the 'movw $GD_FLG_COLD_BOOT, %bx' instruction |
| 990 | # 1110015: 66 bb 00 01 mov $0x100,%bx |
| 991 | marker = struct.pack('<L', 0x0100bb66) |
| 992 | pos = uboot_data.find(marker) |
| 993 | if pos == -1 or pos > 0x100: |
| 994 | raise ValueError('Cannot find U-Boot cold boot entry point') |
| 995 | entry = text_base + pos |
| 996 | self._out.Notice('U-Boot entry point %#08x' % entry) |
Simon Glass | a10282a | 2013-01-08 17:06:41 -0800 | [diff] [blame] | 997 | self._tools.Run('cbfstool', [bootstub, 'add-flat-binary', '-f', |
| 998 | uboot_dtb, '-n', 'fallback/payload', '-c', 'lzma', |
Simon Glass | 0a7cf11 | 2013-05-21 23:08:21 -0700 | [diff] [blame] | 999 | '-l', '%#x' % text_base, '-e', '%#x' % entry]) |
Stefan Reinauer | 1502ea6 | 2012-11-01 10:15:38 -0700 | [diff] [blame] | 1000 | self._tools.Run('cbfstool', [bootstub, 'add', '-f', fdt.fname, |
| 1001 | '-n', 'u-boot.dtb', '-t', '0xac']) |
Simon Glass | b8ea180 | 2012-12-17 15:08:00 -0800 | [diff] [blame] | 1002 | data = self._tools.ReadFile(bootstub) |
| 1003 | bootstub_copy = os.path.join(self._tools.outdir, 'coreboot-8mb.rom') |
| 1004 | self._tools.WriteFile(bootstub_copy, data) |
Gabe Black | 3df7525 | 2013-02-14 21:32:10 -0800 | [diff] [blame] | 1005 | self._tools.WriteFile(bootstub, data[-0x100000:]) |
Simon Glass | cbc8355 | 2012-07-23 15:26:22 +0100 | [diff] [blame] | 1006 | |
Simon Glass | 208ad95 | 2013-02-10 11:16:46 -0800 | [diff] [blame] | 1007 | pack.AddProperty('fdtmap', fdt.fname) |
Simon Glass | c90cf58 | 2012-03-13 15:40:47 -0700 | [diff] [blame] | 1008 | image = os.path.join(self._tools.outdir, 'image.bin') |
| 1009 | pack.PackImage(self._tools.outdir, image) |
| 1010 | pack.AddProperty('image', image) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 1011 | |
Simon Glass | 439fe7a | 2012-03-09 16:19:34 -0800 | [diff] [blame] | 1012 | image = pack.GetProperty('image') |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 1013 | self._tools.OutputSize('Final image', image) |
Simon Glass | c90cf58 | 2012-03-13 15:40:47 -0700 | [diff] [blame] | 1014 | return image, pack |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 1015 | |
Simon Glass | dedda6f | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 1016 | def SelectFdt(self, fdt_fname, use_defaults): |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1017 | """Select an FDT to control the firmware bundling |
| 1018 | |
Simon Glass | dedda6f | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 1019 | We make a copy of this which will include any on-the-fly changes we want |
| 1020 | to make. |
| 1021 | |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1022 | Args: |
| 1023 | fdt_fname: The filename of the fdt to use. |
Simon Glass | dedda6f | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 1024 | use_defaults: True to use a default FDT name if available, and to add |
| 1025 | a full path to the provided filename if necessary. |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1026 | |
Simon Glass | c0f3dc6 | 2011-08-09 14:19:05 -0700 | [diff] [blame] | 1027 | Returns: |
| 1028 | The Fdt object of the original fdt file, which we will not modify. |
| 1029 | |
Simon Glass | dedda6f | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 1030 | Raises: |
| 1031 | ValueError if no FDT is provided (fdt_fname is None and use_defaults is |
| 1032 | False). |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1033 | """ |
Simon Glass | dedda6f | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 1034 | if use_defaults: |
| 1035 | fdt_fname = self._CheckFdtFilename(fdt_fname) |
Simon Glass | 22f39fb | 2013-02-09 13:44:14 -0800 | [diff] [blame] | 1036 | if not fdt_fname: |
| 1037 | raise ValueError('Please provide an FDT filename') |
| 1038 | fdt = Fdt(self._tools, fdt_fname) |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1039 | self._fdt_fname = fdt_fname |
Simon Glass | c3e42c3 | 2012-12-17 15:00:04 -0800 | [diff] [blame] | 1040 | |
| 1041 | # For upstream, select the correct architecture .dtsi manually. |
| 1042 | if self._board == 'link' or 'x86' in self._board: |
| 1043 | arch_dts = 'coreboot.dtsi' |
| 1044 | elif self._board == 'daisy': |
| 1045 | arch_dts = 'exynos5250.dtsi' |
| 1046 | else: |
| 1047 | arch_dts = 'tegra20.dtsi' |
| 1048 | |
| 1049 | fdt.Compile(arch_dts) |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1050 | self.fdt = fdt.Copy(os.path.join(self._tools.outdir, 'updated.dtb')) |
Simon Glass | 32abe2e | 2013-07-18 18:00:55 -0600 | [diff] [blame] | 1051 | return self.fdt |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1052 | |
Simon Glass | c90cf58 | 2012-03-13 15:40:47 -0700 | [diff] [blame] | 1053 | def Start(self, hardware_id, output_fname, show_map): |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1054 | """This creates a firmware bundle according to settings provided. |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 1055 | |
| 1056 | - Checks options, tools, output directory, fdt. |
| 1057 | - Creates GBB and image. |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1058 | |
| 1059 | Args: |
Simon Glass | 5657757 | 2011-07-19 11:08:06 +1200 | [diff] [blame] | 1060 | hardware_id: Hardware ID to use for this board. If None, then the |
| 1061 | default from the Fdt will be used |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1062 | output_fname: Output filename for the image. If this is not None, then |
| 1063 | the final image will be copied here. |
Simon Glass | c90cf58 | 2012-03-13 15:40:47 -0700 | [diff] [blame] | 1064 | show_map: Show a flash map, with each area's name and position |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1065 | |
| 1066 | Returns: |
| 1067 | Filename of the resulting image (not the output_fname copy). |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 1068 | """ |
Vadim Bendebury | 5baeec1 | 2013-04-02 13:01:22 -0700 | [diff] [blame] | 1069 | if self._small or self.fdt.GetProp('/config', 'nogbb', 'any') != 'any': |
| 1070 | gbb = '' # Building a small image or `nogbb' is requested in device tree. |
| 1071 | else: |
Simon Glass | 5657757 | 2011-07-19 11:08:06 +1200 | [diff] [blame] | 1072 | gbb = self._CreateGoogleBinaryBlock(hardware_id) |
Simon Glass | 89b86b8 | 2011-07-17 23:49:49 -0700 | [diff] [blame] | 1073 | |
| 1074 | # This creates the actual image. |
Simon Glass | c90cf58 | 2012-03-13 15:40:47 -0700 | [diff] [blame] | 1075 | image, pack = self._CreateImage(gbb, self.fdt) |
| 1076 | if show_map: |
| 1077 | pack.ShowMap() |
Simon Glass | 290a180 | 2011-07-17 13:54:32 -0700 | [diff] [blame] | 1078 | if output_fname: |
| 1079 | shutil.copyfile(image, output_fname) |
| 1080 | self._out.Notice("Output image '%s'" % output_fname) |
Simon Glass | 794217e | 2012-06-07 11:40:37 -0700 | [diff] [blame] | 1081 | return image, pack.props |