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