blob: a88118a3e00ed43fc4126f11b6aa4252506c8174 [file] [log] [blame]
Simon Glass89b86b82011-07-17 23:49:49 -07001# 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 Kleinc2df3ca2014-01-06 15:15:34 -05005"""This module builds a firmware image.
Simon Glass89b86b82011-07-17 23:49:49 -07006
7This modules uses a few rudimentary other libraries for its activity.
8
9Here are the names we give to the various files we deal with. It is important
10to 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 Glassceff3ff2012-04-04 11:23:45 -070019import glob
Gabe Blackcdbdfe12013-02-06 05:37:52 -080020import hashlib
Simon Glass89b86b82011-07-17 23:49:49 -070021import os
22import re
23
Simon Glass89b86b82011-07-17 23:49:49 -070024from fdt import Fdt
25from pack_firmware import PackFirmware
26import shutil
Simon Glass7c2d5572011-11-15 14:47:08 -080027import struct
Vadim Bendebury8c35e2e2014-05-06 12:55:50 -070028from flashmaps import default_flashmaps
Simon Glass439fe7a2012-03-09 16:19:34 -080029from tools import CmdError
Vadim Bendeburyb12e3352013-06-08 17:25:19 -070030from exynos import ExynosBl2
Simon Glass89b86b82011-07-17 23:49:49 -070031
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.
35yaml_data = '''
36bmpblock: 1.0
37
38images:
39 devmode: DeveloperBmp/DeveloperBmp.bmp
40 recovery: RecoveryBmp/RecoveryBmp.bmp
41 rec_yuck: RecoveryNoOSBmp/RecoveryNoOSBmp.bmp
42 rec_insert: RecoveryMissingOSBmp/RecoveryMissingOSBmp.bmp
43
44screens:
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
54localizations:
55 - [ dev_en, rec_en, yuck_en, ins_en ]
56'''
57
Simon Glass4a887b12012-10-23 16:29:03 -070058# Build GBB flags.
59# (src/platform/vboot_reference/firmware/include/gbb_header.h)
60gbb_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 Nematbakhsh07c19882014-08-19 10:21:59 -070069 'faft-key-overide': 0x00000100,
70 'disable-ec-software-sync': 0x00000200,
71 'default-dev-boot-legacy': 0x00000400,
72 'disable-pd-software-sync': 0x00000800,
Furquan Shaikhd4eac3b2015-05-15 18:05:09 -070073 'force-dev-boot-fastboot-full-cap': 0x00002000,
Mary Ruthvena759c322015-11-16 08:23:26 -080074 'enable-serial': 0x00004000,
Simon Glass4a887b12012-10-23 16:29:03 -070075}
76
Simon Glass49b026b2013-04-26 16:38:42 -070077# Maps board name to Exynos product number
78type_to_model = {
79 'peach' : '5420',
80 'daisy' : '5250'
81}
82
Simon Glass5076a7f2012-10-23 16:31:54 -070083def 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 Durbin41c85b62015-12-17 17:40:29 -060089class BlobDeferral(Exception):
90 """An error indicating deferal of blob generation."""
91 pass
92
Simon Glass89b86b82011-07-17 23:49:49 -070093class Bundle:
Simon Glass290a1802011-07-17 13:54:32 -070094 """This class encapsulates the entire bundle firmware logic.
Simon Glass89b86b82011-07-17 23:49:49 -070095
Simon Glass290a1802011-07-17 13:54:32 -070096 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 Glassa4934b72012-05-09 13:35:02 -0700102 .. can call bundle.AddConfigList(), AddEnableList() if required
Simon Glass290a1802011-07-17 13:54:32 -0700103 bundle.Start(...)
Simon Glass89b86b82011-07-17 23:49:49 -0700104
Simon Glass290a1802011-07-17 13:54:32 -0700105 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 Glass559b6612012-05-23 13:28:45 -0700112 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 Glass23988ae2012-03-23 16:55:22 -0700116
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 Glass290a1802011-07-17 13:54:32 -0700121 """
Simon Glass89b86b82011-07-17 23:49:49 -0700122
Simon Glass290a1802011-07-17 13:54:32 -0700123 def __init__(self, tools, output):
124 """Set up a new Bundle object.
Simon Glass89b86b82011-07-17 23:49:49 -0700125
Simon Glass290a1802011-07-17 13:54:32 -0700126 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 Glass89b86b82011-07-17 23:49:49 -0700129 """
Simon Glass290a1802011-07-17 13:54:32 -0700130 self._tools = tools
131 self._out = output
132
133 # Set up the things we need to know in order to operate.
Rhyland Kleinc2df3ca2014-01-06 15:15:34 -0500134 self._board = None # Board name, e.g. nyan.
Simon Glass290a1802011-07-17 13:54:32 -0700135 self._fdt_fname = None # Filename of our FDT.
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700136 self._force_rw = None
Simon Glass00d027e2013-07-20 14:51:12 -0600137 self._force_efs = None
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700138 self._gbb_flags = None
139 self._keydir = None
140 self._small = False
Simon Glass290a1802011-07-17 13:54:32 -0700141 self.bct_fname = None # Filename of our BCT file.
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700142 self.blobs = {} # Table of (type, filename) of arbitrary blobs
Hung-Te Lin5b649382011-08-03 15:01:16 +0800143 self.bmpblk_fname = None # Filename of our Bitmap Block
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700144 self.coreboot_elf = None
Stefan Reinauer8d79d362011-08-16 14:20:43 -0700145 self.coreboot_fname = None # Filename of our coreboot binary.
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700146 self.ecro_fname = None # Filename of EC read-only file
147 self.ecrw_fname = None # Filename of EC file
Randall Spangler7307da92014-07-18 12:47:34 -0700148 self.pdrw_fname = None # Filename of PD file
Simon Glass7e199222012-03-13 15:51:18 -0700149 self.exynos_bl1 = None # Filename of Exynos BL1 (pre-boot)
150 self.exynos_bl2 = None # Filename of Exynos BL2 (SPL)
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700151 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 Glass07267952012-06-08 12:45:13 -0700155 self.skeleton_fname = None # Filename of Coreboot skeleton file
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700156 self.uboot_fname = None # Filename of our U-Boot binary.
Simon Glass290a1802011-07-17 13:54:32 -0700157
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 Glass6dcc2f22011-07-28 15:26:49 +1200166 def SetFiles(self, board, bct, uboot=None, bmpblk=None, coreboot=None,
Simon Glassa10282a2013-01-08 17:06:41 -0800167 coreboot_elf=None,
Simon Glass07267952012-06-08 12:45:13 -0700168 postload=None, seabios=None, exynos_bl1=None, exynos_bl2=None,
Randall Spangler7307da92014-07-18 12:47:34 -0700169 skeleton=None, ecrw=None, ecro=None, pdrw=None,
Daisuke Nojiri69662892015-09-25 15:24:04 -0700170 kernel=None, blobs=None, skip_bmpblk=False, cbfs_files=None):
Simon Glass290a1802011-07-17 13:54:32 -0700171 """Set up files required for Bundle.
172
173 Args:
Rhyland Kleinc2df3ca2014-01-06 15:15:34 -0500174 board: The name of the board to target (e.g. nyan).
Simon Glass290a1802011-07-17 13:54:32 -0700175 uboot: The filename of the u-boot.bin image to use.
176 bct: The filename of the binary BCT file to use.
Hung-Te Lin5b649382011-08-03 15:01:16 +0800177 bmpblk: The filename of bitmap block file to use.
Simon Glassa10282a2013-01-08 17:06:41 -0800178 coreboot: The filename of the coreboot image to use (on x86).
179 coreboot_elf: If not none, the ELF file to add as a Coreboot payload.
Simon Glass6dcc2f22011-07-28 15:26:49 +1200180 postload: The filename of the u-boot-post.bin image to use.
Vincent Palatinf7286772011-10-12 14:31:53 -0700181 seabios: The filename of the SeaBIOS payload to use if any.
Simon Glass07267952012-06-08 12:45:13 -0700182 exynos_bl1: The filename of the exynos BL1 file
183 exynos_bl2: The filename of the exynos BL2 file (U-Boot spl)
184 skeleton: The filename of the coreboot skeleton file.
Simon Glassbe0bc002012-08-16 12:50:48 -0700185 ecrw: The filename of the EC (Embedded Controller) read-write file.
186 ecro: The filename of the EC (Embedded Controller) read-only file.
Randall Spangler7307da92014-07-18 12:47:34 -0700187 pdrw: The filename of the PD (PD embedded controller) read-write file.
Simon Glassde9c8072012-07-02 22:29:02 -0700188 kernel: The filename of the kernel file if any.
Che-Liang Chiou3bc344c2013-02-21 15:18:03 -0800189 blobs: List of (type, filename) of arbitrary blobs.
Vadim Bendeburybfd227f2014-11-28 22:14:24 -0800190 skip_bmpblk: True if no bmpblk is required
Daisuke Nojiri69662892015-09-25 15:24:04 -0700191 cbfs_files: Root directory of files to be stored in CBFS
Simon Glass290a1802011-07-17 13:54:32 -0700192 """
193 self._board = board
194 self.uboot_fname = uboot
195 self.bct_fname = bct
Hung-Te Lin5b649382011-08-03 15:01:16 +0800196 self.bmpblk_fname = bmpblk
Stefan Reinauer8d79d362011-08-16 14:20:43 -0700197 self.coreboot_fname = coreboot
Simon Glassa10282a2013-01-08 17:06:41 -0800198 self.coreboot_elf = coreboot_elf
Simon Glass6dcc2f22011-07-28 15:26:49 +1200199 self.postload_fname = postload
Vincent Palatinf7286772011-10-12 14:31:53 -0700200 self.seabios_fname = seabios
Simon Glass7e199222012-03-13 15:51:18 -0700201 self.exynos_bl1 = exynos_bl1
202 self.exynos_bl2 = exynos_bl2
Simon Glass07267952012-06-08 12:45:13 -0700203 self.skeleton_fname = skeleton
Simon Glassbe0bc002012-08-16 12:50:48 -0700204 self.ecrw_fname = ecrw
205 self.ecro_fname = ecro
Randall Spangler7307da92014-07-18 12:47:34 -0700206 self.pdrw_fname = pdrw
Simon Glassde9c8072012-07-02 22:29:02 -0700207 self.kernel_fname = kernel
Che-Liang Chiou3bc344c2013-02-21 15:18:03 -0800208 self.blobs = dict(blobs or ())
Vadim Bendeburybfd227f2014-11-28 22:14:24 -0800209 self.skip_bmpblk = skip_bmpblk
Daisuke Nojiri69662892015-09-25 15:24:04 -0700210 self.cbfs_files = cbfs_files
Simon Glass290a1802011-07-17 13:54:32 -0700211
Simon Glass00d027e2013-07-20 14:51:12 -0600212 def SetOptions(self, small, gbb_flags, force_rw=False, force_efs=False):
Simon Glass290a1802011-07-17 13:54:32 -0700213 """Set up options supported by Bundle.
214
215 Args:
216 small: Only create a signed U-Boot - don't produce the full packed
217 firmware image. This is useful for devs who want to replace just the
218 U-Boot part while keeping the keys, gbb, etc. the same.
Simon Glass6e486c22012-10-26 15:43:42 -0700219 gbb_flags: Specification for string containing adjustments to make.
220 force_rw: Force firmware into RW mode.
Simon Glass00d027e2013-07-20 14:51:12 -0600221 force_efs: Force firmware to use 'early firmware selection' feature,
222 where RW firmware is selected before SDRAM is initialized.
Simon Glass290a1802011-07-17 13:54:32 -0700223 """
224 self._small = small
Simon Glass157c0662012-10-23 13:52:42 -0700225 self._gbb_flags = gbb_flags
Simon Glass6e486c22012-10-26 15:43:42 -0700226 self._force_rw = force_rw
Simon Glass00d027e2013-07-20 14:51:12 -0600227 self._force_efs = force_efs
Simon Glass290a1802011-07-17 13:54:32 -0700228
Simon Glass22f39fb2013-02-09 13:44:14 -0800229 def _GetBuildRoot(self):
230 """Get the path to this board's 'firmware' directory.
231
232 Returns:
233 Path to firmware directory, with ## representing the path to the
234 chroot.
235 """
Simon Glass290a1802011-07-17 13:54:32 -0700236 if not self._board:
237 raise ValueError('No board defined - please define a board to use')
Simon Glass22f39fb2013-02-09 13:44:14 -0800238 return os.path.join('##', 'build', self._board, 'firmware')
239
240 def _CheckFdtFilename(self, fname):
241 """Check provided FDT filename and return the correct name if needed.
242
243 Where the filename lacks a path, add a default path for this board.
244 Where no FDT filename is provided, select a default one for this board.
245
246 Args:
247 fname: Proposed FDT filename.
248
249 Returns:
250 Selected FDT filename, after validation.
251 """
252 build_root = self._GetBuildRoot()
Julius Wernerb4b14392013-08-09 14:41:40 -0700253 dir_name = os.path.join(build_root, 'dtb')
Simon Glass22f39fb2013-02-09 13:44:14 -0800254 if not fname:
Simon Glassceff3ff2012-04-04 11:23:45 -0700255 # Figure out where the file should be, and the name we expect.
Simon Glassceff3ff2012-04-04 11:23:45 -0700256 base_name = re.sub('_', '-', self._board)
257
258 # In case the name exists with a prefix or suffix, find it.
Julius Wernerb4b14392013-08-09 14:41:40 -0700259 wildcard = os.path.join(dir_name, '*%s.dtb' % base_name)
Simon Glassceff3ff2012-04-04 11:23:45 -0700260 found_list = glob.glob(self._tools.Filename(wildcard))
261 if len(found_list) == 1:
Simon Glass22f39fb2013-02-09 13:44:14 -0800262 fname = found_list[0]
Simon Glassceff3ff2012-04-04 11:23:45 -0700263 else:
264 # We didn't find anything definite, so set up our expected name.
Julius Wernerb4b14392013-08-09 14:41:40 -0700265 fname = os.path.join(dir_name, '%s.dtb' % base_name)
Simon Glassceff3ff2012-04-04 11:23:45 -0700266
Simon Glass881964d2012-04-04 11:34:09 -0700267 # Convert things like 'exynos5250-daisy' into a full path.
Simon Glass22f39fb2013-02-09 13:44:14 -0800268 root, ext = os.path.splitext(fname)
Simon Glass881964d2012-04-04 11:34:09 -0700269 if not ext and not os.path.dirname(root):
Julius Wernerb4b14392013-08-09 14:41:40 -0700270 fname = os.path.join(dir_name, '%s.dtb' % root)
Simon Glass22f39fb2013-02-09 13:44:14 -0800271 return fname
272
273 def CheckOptions(self):
274 """Check provided options and select defaults."""
275 build_root = self._GetBuildRoot()
Simon Glass881964d2012-04-04 11:34:09 -0700276
Simon Glass49b026b2013-04-26 16:38:42 -0700277 board_type = self._board.split('_')[0]
278 model = type_to_model.get(board_type)
279
Simon Glass290a1802011-07-17 13:54:32 -0700280 if not self.uboot_fname:
281 self.uboot_fname = os.path.join(build_root, 'u-boot.bin')
282 if not self.bct_fname:
283 self.bct_fname = os.path.join(build_root, 'bct', 'board.bct')
Simon Glass2a7f0b32011-08-26 11:25:17 -0700284 if not self.bmpblk_fname:
David Hendricksbdecc542012-08-21 13:53:58 -0700285 self.bmpblk_fname = os.path.join(build_root, 'bmpblk.bin')
Simon Glass49b026b2013-04-26 16:38:42 -0700286 if model:
287 if not self.exynos_bl1:
Simon Glassd05696e2013-06-13 20:14:00 -0700288 self.exynos_bl1 = os.path.join(build_root, 'u-boot.bl1.bin')
Simon Glass49b026b2013-04-26 16:38:42 -0700289 if not self.exynos_bl2:
Julius Wernerb12c0052013-08-14 13:57:04 -0700290 self.exynos_bl2 = os.path.join(build_root, 'u-boot-spl.wrapped.bin')
Simon Glass07267952012-06-08 12:45:13 -0700291 if not self.coreboot_fname:
292 self.coreboot_fname = os.path.join(build_root, 'coreboot.rom')
293 if not self.skeleton_fname:
Stefan Reinauer728be822012-10-02 16:54:09 -0700294 self.skeleton_fname = os.path.join(build_root, 'coreboot.rom')
Stefan Reinauer9ad54842012-10-10 12:25:23 -0700295 if not self.seabios_fname:
296 self.seabios_fname = 'seabios.cbfs'
Simon Glassbe0bc002012-08-16 12:50:48 -0700297 if not self.ecrw_fname:
298 self.ecrw_fname = os.path.join(build_root, 'ec.RW.bin')
Randall Spangler7307da92014-07-18 12:47:34 -0700299 if not self.pdrw_fname:
300 self.pdrw_fname = os.path.join(build_root, 'pd.RW.bin')
Simon Glassbe0bc002012-08-16 12:50:48 -0700301 if not self.ecro_fname:
302 self.ecro_fname = os.path.join(build_root, 'ec.RO.bin')
Simon Glass89b86b82011-07-17 23:49:49 -0700303
Simon Glass75759302012-03-15 20:26:53 -0700304 def GetFiles(self):
305 """Get a list of files that we know about.
306
307 This is the opposite of SetFiles except that we may have put in some
308 default names. It returns a dictionary containing the filename for
309 each of a number of pre-defined files.
310
311 Returns:
312 Dictionary, with one entry for each file.
313 """
314 file_list = {
315 'bct' : self.bct_fname,
316 'exynos-bl1' : self.exynos_bl1,
317 'exynos-bl2' : self.exynos_bl2,
318 }
319 return file_list
320
Simon Glass4a887b12012-10-23 16:29:03 -0700321 def DecodeGBBFlagsFromFdt(self):
322 """Get Google Binary Block flags from the FDT.
323
324 These should be in the chromeos-config node, like this:
325
326 chromeos-config {
327 gbb-flag-dev-screen-short-delay;
328 gbb-flag-force-dev-switch-on;
329 gbb-flag-force-dev-boot-usb;
330 gbb-flag-disable-fw-rollback-check;
331 };
332
333 Returns:
334 GBB flags value from FDT.
335 """
336 chromeos_config = self.fdt.GetProps("/chromeos-config")
337 gbb_flags = 0
338 for name in chromeos_config:
339 if name.startswith('gbb-flag-'):
340 flag_value = gbb_flag_properties.get(name[9:])
341 if flag_value:
342 gbb_flags |= flag_value
343 self._out.Notice("FDT: Enabling %s." % name)
344 else:
345 raise ValueError("FDT contains invalid GBB flags '%s'" % name)
346 return gbb_flags
347
Simon Glass157c0662012-10-23 13:52:42 -0700348 def DecodeGBBFlagsFromOptions(self, gbb_flags, adjustments):
349 """Decode ajustments to the provided GBB flags.
350
351 We support three options:
352
353 hex value: c2
354 defined value: force-dev-boot-usb,load-option-roms
355 adjust default value: -load-option-roms,+force-dev-boot-usb
356
357 The last option starts from the passed-in GBB flags and adds or removes
358 flags.
359
360 Args:
361 gbb_flags: Base (default) FDT flags.
362 adjustments: String containing adjustments to make.
363
364 Returns:
365 Updated FDT flags.
366 """
367 use_base_value = True
368 if adjustments:
369 try:
370 return int(adjustments, base=16)
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700371 except (ValueError, TypeError):
Simon Glass157c0662012-10-23 13:52:42 -0700372 pass
373 for flag in adjustments.split(','):
374 oper = None
375 if flag[0] in ['-', '+']:
376 oper = flag[0]
377 flag = flag[1:]
378 value = gbb_flag_properties.get(flag)
379 if not value:
380 raise ValueError("Invalid GBB flag '%s'" % flag)
381 if oper == '+':
382 gbb_flags |= value
Simon Glass84816582012-11-20 10:53:10 -0800383 self._out.Notice("Cmdline: Enabling %s." % flag)
Simon Glass157c0662012-10-23 13:52:42 -0700384 elif oper == '-':
385 gbb_flags &= ~value
Simon Glass84816582012-11-20 10:53:10 -0800386 self._out.Notice("Cmdline: Disabling %s." % flag)
Simon Glass157c0662012-10-23 13:52:42 -0700387 else:
388 if use_base_value:
389 gbb_flags = 0
390 use_base_value = False
Simon Glass84816582012-11-20 10:53:10 -0800391 self._out.Notice('Cmdline: Resetting flags to 0')
Simon Glass157c0662012-10-23 13:52:42 -0700392 gbb_flags |= value
Simon Glass84816582012-11-20 10:53:10 -0800393 self._out.Notice("Cmdline: Enabling %s." % flag)
Simon Glass157c0662012-10-23 13:52:42 -0700394
395 return gbb_flags
396
Simon Glass56577572011-07-19 11:08:06 +1200397 def _CreateGoogleBinaryBlock(self, hardware_id):
Simon Glass89b86b82011-07-17 23:49:49 -0700398 """Create a GBB for the image.
399
Simon Glass56577572011-07-19 11:08:06 +1200400 Args:
401 hardware_id: Hardware ID to use for this board. If None, then the
402 default from the Fdt will be used
403
Simon Glass89b86b82011-07-17 23:49:49 -0700404 Returns:
405 Path of the created GBB file.
Simon Glass89b86b82011-07-17 23:49:49 -0700406 """
Simon Glass56577572011-07-19 11:08:06 +1200407 if not hardware_id:
Simon Glass02d124a2012-03-02 14:47:20 -0800408 hardware_id = self.fdt.GetString('/config', 'hwid')
Simon Glass89b86b82011-07-17 23:49:49 -0700409 gbb_size = self.fdt.GetFlashPartSize('ro', 'gbb')
Simon Glass290a1802011-07-17 13:54:32 -0700410 odir = self._tools.outdir
Simon Glass89b86b82011-07-17 23:49:49 -0700411
Simon Glass4a887b12012-10-23 16:29:03 -0700412 gbb_flags = self.DecodeGBBFlagsFromFdt()
Stefan Reinauer975e68f2012-02-27 13:27:08 -0800413
Simon Glass157c0662012-10-23 13:52:42 -0700414 # Allow command line to override flags
415 gbb_flags = self.DecodeGBBFlagsFromOptions(gbb_flags, self._gbb_flags)
416
Simon Glass4a887b12012-10-23 16:29:03 -0700417 self._out.Notice("GBB flags value %#x" % gbb_flags)
Simon Glass89b86b82011-07-17 23:49:49 -0700418 self._out.Progress('Creating GBB')
419 sizes = [0x100, 0x1000, gbb_size - 0x2180, 0x1000]
420 sizes = ['%#x' % size for size in sizes]
421 gbb = 'gbb.bin'
Simon Glass290a1802011-07-17 13:54:32 -0700422 keydir = self._tools.Filename(self._keydir)
Vadim Bendeburybfd227f2014-11-28 22:14:24 -0800423
424 gbb_set_command = ['-s',
425 '--hwid=%s' % hardware_id,
426 '--rootkey=%s/root_key.vbpubk' % keydir,
427 '--recoverykey=%s/recovery_key.vbpubk' % keydir,
428 '--flags=%d' % gbb_flags,
429 gbb]
430 if not self.skip_bmpblk:
431 gbb_set_command[-1:-1] = ['--bmpfv=%s' % self._tools.Filename(
432 self.bmpblk_fname),]
433
Simon Glass290a1802011-07-17 13:54:32 -0700434 self._tools.Run('gbb_utility', ['-c', ','.join(sizes), gbb], cwd=odir)
Vadim Bendeburybfd227f2014-11-28 22:14:24 -0800435 self._tools.Run('gbb_utility', gbb_set_command, cwd=odir)
Simon Glass290a1802011-07-17 13:54:32 -0700436 return os.path.join(odir, gbb)
Simon Glass89b86b82011-07-17 23:49:49 -0700437
Simon Glasse13ee2c2011-07-28 08:12:28 +1200438 def _SignBootstub(self, bct, bootstub, text_base):
Simon Glass89b86b82011-07-17 23:49:49 -0700439 """Sign an image so that the Tegra SOC will boot it.
440
441 Args:
442 bct: BCT file to use.
443 bootstub: Boot stub (U-Boot + fdt) file to sign.
444 text_base: Address of text base for image.
Simon Glass89b86b82011-07-17 23:49:49 -0700445
446 Returns:
447 filename of signed image.
Simon Glass89b86b82011-07-17 23:49:49 -0700448 """
449 # First create a config file - this is how we instruct cbootimage
Simon Glasse13ee2c2011-07-28 08:12:28 +1200450 signed = os.path.join(self._tools.outdir, 'signed.bin')
Simon Glass89b86b82011-07-17 23:49:49 -0700451 self._out.Progress('Signing Bootstub')
Simon Glasse13ee2c2011-07-28 08:12:28 +1200452 config = os.path.join(self._tools.outdir, 'boot.cfg')
Simon Glass89b86b82011-07-17 23:49:49 -0700453 fd = open(config, 'w')
454 fd.write('Version = 1;\n')
455 fd.write('Redundancy = 1;\n')
456 fd.write('Bctfile = %s;\n' % bct)
Doug Anderson0eeb0742011-09-15 18:11:40 -0700457
458 # TODO(dianders): Right now, we don't have enough space in our flash map
459 # for two copies of the BCT when we're using NAND, so hack it to 1. Not
460 # sure what this does for reliability, but at least things will fit...
461 is_nand = "NvBootDevType_Nand" in self._tools.Run('bct_dump', [bct])
462 if is_nand:
463 fd.write('Bctcopy = 1;\n')
464
Simon Glass89b86b82011-07-17 23:49:49 -0700465 fd.write('BootLoader = %s,%#x,%#x,Complete;\n' % (bootstub, text_base,
466 text_base))
Doug Anderson0eeb0742011-09-15 18:11:40 -0700467
Simon Glass89b86b82011-07-17 23:49:49 -0700468 fd.close()
469
470 self._tools.Run('cbootimage', [config, signed])
471 self._tools.OutputSize('BCT', bct)
472 self._tools.OutputSize('Signed image', signed)
473 return signed
474
Doug Anderson86ce5f42011-07-27 10:40:18 -0700475 def SetBootcmd(self, bootcmd, bootsecure):
Simon Glass290a1802011-07-17 13:54:32 -0700476 """Set the boot command for U-Boot.
Simon Glass89b86b82011-07-17 23:49:49 -0700477
478 Args:
Simon Glass290a1802011-07-17 13:54:32 -0700479 bootcmd: Boot command to use, as a string (if None this this is a nop).
Doug Anderson86ce5f42011-07-27 10:40:18 -0700480 bootsecure: We'll set '/config/bootsecure' to 1 if True and 0 if False.
Simon Glass89b86b82011-07-17 23:49:49 -0700481 """
Simon Glass468d8752012-09-19 16:36:19 -0700482 if bootcmd is not None:
483 if bootcmd == 'none':
484 bootcmd = ''
Simon Glass02d124a2012-03-02 14:47:20 -0800485 self.fdt.PutString('/config', 'bootcmd', bootcmd)
486 self.fdt.PutInteger('/config', 'bootsecure', int(bootsecure))
Simon Glass290a1802011-07-17 13:54:32 -0700487 self._out.Info('Boot command: %s' % bootcmd)
Simon Glass89b86b82011-07-17 23:49:49 -0700488
Simon Glassa4934b72012-05-09 13:35:02 -0700489 def SetNodeEnabled(self, node_name, enabled):
490 """Set whether an node is enabled or disabled.
491
492 This simply sets the 'status' property of a node to "ok", or "disabled".
493
494 The node should either be a full path to the node (like '/uart@10200000')
495 or an alias property.
496
497 Aliases are supported like this:
498
499 aliases {
500 console = "/uart@10200000";
501 };
502
503 pointing to a node:
504
505 uart@10200000 {
Simon Glass4c5066f2012-06-20 16:51:19 -0700506 status = "okay";
Simon Glassa4934b72012-05-09 13:35:02 -0700507 };
508
509 In this case, this function takes the name of the alias ('console' in
510 this case) and updates the status of the node that is pointed to, to
511 either ok or disabled. If the alias does not exist, a warning is
512 displayed.
513
514 Args:
515 node_name: Name of node (e.g. '/uart@10200000') or alias alias
516 (e.g. 'console') to adjust
517 enabled: True to enable, False to disable
518 """
519 # Look up the alias if this is an alias reference
520 if not node_name.startswith('/'):
521 lookup = self.fdt.GetString('/aliases', node_name, '')
522 if not lookup:
523 self._out.Warning("Cannot find alias '%s' - ignoring" % node_name)
524 return
525 node_name = lookup
526 if enabled:
Simon Glass4c5066f2012-06-20 16:51:19 -0700527 status = 'okay'
Simon Glassa4934b72012-05-09 13:35:02 -0700528 else:
529 status = 'disabled'
530 self.fdt.PutString(node_name, 'status', status)
531
532 def AddEnableList(self, enable_list):
533 """Process a list of nodes to enable/disable.
534
535 Args:
Vadim Bendebury7dac18c2014-05-06 14:13:35 -0700536 enable_list: List of (node, value) tuples to add to the fdt. For each
Simon Glassa4934b72012-05-09 13:35:02 -0700537 tuple:
538 node: The fdt node to write to will be <node> or pointed to by
539 /aliases/<node>. We can tell which
540 value: 0 to disable the node, 1 to enable it
Vadim Bendebury7dac18c2014-05-06 14:13:35 -0700541
Vadim Bendebury507c0012013-06-09 12:49:25 -0700542 Raises:
543 CmdError if a command fails.
Simon Glassa4934b72012-05-09 13:35:02 -0700544 """
545 if enable_list:
546 for node_name, enabled in enable_list:
547 try:
548 enabled = int(enabled)
549 if enabled not in (0, 1):
550 raise ValueError
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700551 except ValueError:
Simon Glassa4934b72012-05-09 13:35:02 -0700552 raise CmdError("Invalid enable option value '%s' "
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700553 "(should be 0 or 1)" % str(enabled))
Simon Glassa4934b72012-05-09 13:35:02 -0700554 self.SetNodeEnabled(node_name, enabled)
555
Simon Glass290a1802011-07-17 13:54:32 -0700556 def AddConfigList(self, config_list, use_int=False):
557 """Add a list of config items to the fdt.
558
559 Normally these values are written to the fdt as strings, but integers
560 are also supported, in which case the values will be converted to integers
561 (if necessary) before being stored.
562
563 Args:
564 config_list: List of (config, value) tuples to add to the fdt. For each
565 tuple:
566 config: The fdt node to write to will be /config/<config>.
567 value: An integer or string value to write.
568 use_int: True to only write integer values.
569
570 Raises:
571 CmdError: if a value is required to be converted to integer but can't be.
572 """
573 if config_list:
574 for config in config_list:
575 value = config[1]
576 if use_int:
577 try:
578 value = int(value)
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700579 except ValueError:
Simon Glass290a1802011-07-17 13:54:32 -0700580 raise CmdError("Cannot convert config option '%s' to integer" %
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700581 str(value))
Simon Glass290a1802011-07-17 13:54:32 -0700582 if type(value) == type(1):
Simon Glass02d124a2012-03-02 14:47:20 -0800583 self.fdt.PutInteger('/config', '%s' % config[0], value)
Simon Glass290a1802011-07-17 13:54:32 -0700584 else:
Simon Glass02d124a2012-03-02 14:47:20 -0800585 self.fdt.PutString('/config', '%s' % config[0], value)
Simon Glass290a1802011-07-17 13:54:32 -0700586
Simon Glass7c2d5572011-11-15 14:47:08 -0800587 def DecodeTextBase(self, data):
588 """Look at a U-Boot image and try to decode its TEXT_BASE.
589
590 This works because U-Boot has a header with the value 0x12345678
591 immediately followed by the TEXT_BASE value. We can therefore read this
592 from the image with some certainty. We check only the first 40 words
593 since the header should be within that region.
594
Simon Glass96b50302012-07-20 06:55:28 +0100595 Since upstream Tegra has moved to having a 16KB SPL region at the start,
596 and currently this does holds the U-Boot text base (e.g. 0x10c000) instead
597 of the SPL one (e.g. 0x108000), we search in the U-Boot part as well.
598
Simon Glass7c2d5572011-11-15 14:47:08 -0800599 Args:
600 data: U-Boot binary data
601
602 Returns:
603 Text base (integer) or None if none was found
604 """
605 found = False
Simon Glass96b50302012-07-20 06:55:28 +0100606 for start in (0, 0x4000):
607 for i in range(start, start + 160, 4):
608 word = data[i:i + 4]
Simon Glass7c2d5572011-11-15 14:47:08 -0800609
Simon Glass96b50302012-07-20 06:55:28 +0100610 # TODO(sjg): This does not cope with a big-endian target
611 value = struct.unpack('<I', word)[0]
612 if found:
613 return value - start
614 if value == 0x12345678:
615 found = True
Simon Glass7c2d5572011-11-15 14:47:08 -0800616
617 return None
618
619 def CalcTextBase(self, name, fdt, fname):
620 """Calculate the TEXT_BASE to use for U-Boot.
621
622 Normally this value is in the fdt, so we just read it from there. But as
623 a second check we look at the image itself in case this is different, and
624 switch to that if it is.
625
626 This allows us to flash any U-Boot even if its TEXT_BASE is different.
627 This is particularly useful with upstream U-Boot which uses a different
628 value (which we will move to).
629 """
630 data = self._tools.ReadFile(fname)
Andrew Chewaa092542013-01-09 16:30:52 -0800631 # The value that comes back from fdt.GetInt is signed, which makes no
632 # sense for an address base. Force it to unsigned.
633 fdt_text_base = fdt.GetInt('/chromeos-config', 'textbase', 0) & 0xffffffff
Simon Glass7c2d5572011-11-15 14:47:08 -0800634 text_base = self.DecodeTextBase(data)
Simon Glass96b50302012-07-20 06:55:28 +0100635 text_base_str = '%#x' % text_base if text_base else 'None'
636 self._out.Info('TEXT_BASE: fdt says %#x, %s says %s' % (fdt_text_base,
637 fname, text_base_str))
Simon Glass7c2d5572011-11-15 14:47:08 -0800638
639 # If they are different, issue a warning and switch over.
640 if text_base and text_base != fdt_text_base:
641 self._out.Warning("TEXT_BASE %x in %sU-Boot doesn't match "
642 "fdt value of %x. Using %x" % (text_base, name,
643 fdt_text_base, text_base))
644 fdt_text_base = text_base
645 return fdt_text_base
646
Simon Glass6dcc2f22011-07-28 15:26:49 +1200647 def _CreateBootStub(self, uboot, base_fdt, postload):
Simon Glass89b86b82011-07-17 23:49:49 -0700648 """Create a boot stub and a signed boot stub.
649
Simon Glass6dcc2f22011-07-28 15:26:49 +1200650 For postload:
651 We add a /config/postload-text-offset entry to the signed bootstub's
652 fdt so that U-Boot can find the postload code.
653
654 The raw (unsigned) bootstub will have a value of -1 for this since we will
655 simply append the postload code to the bootstub and it can find it there.
656 This will be used for RW A/B firmware.
657
658 For the signed case this value will specify where in the flash to find
659 the postload code. This will be used for RO firmware.
660
Simon Glass89b86b82011-07-17 23:49:49 -0700661 Args:
662 uboot: Path to u-boot.bin (may be chroot-relative)
Simon Glass29b96ad2012-03-09 15:34:33 -0800663 base_fdt: Fdt object containing the flat device tree.
Simon Glass6dcc2f22011-07-28 15:26:49 +1200664 postload: Path to u-boot-post.bin, or None if none.
Simon Glass89b86b82011-07-17 23:49:49 -0700665
666 Returns:
667 Tuple containing:
Simon Glass6dcc2f22011-07-28 15:26:49 +1200668 Full path to bootstub (uboot + fdt(-1) + postload).
669 Full path to signed (uboot + fdt(flash pos) + bct) + postload.
Simon Glass89b86b82011-07-17 23:49:49 -0700670
671 Raises:
672 CmdError if a command fails.
673 """
Simon Glasse13ee2c2011-07-28 08:12:28 +1200674 bootstub = os.path.join(self._tools.outdir, 'u-boot-fdt.bin')
Simon Glass7c2d5572011-11-15 14:47:08 -0800675 text_base = self.CalcTextBase('', self.fdt, uboot)
Simon Glass89b86b82011-07-17 23:49:49 -0700676 uboot_data = self._tools.ReadFile(uboot)
Simon Glass6dcc2f22011-07-28 15:26:49 +1200677
678 # Make a copy of the fdt for the bootstub
679 fdt = base_fdt.Copy(os.path.join(self._tools.outdir, 'bootstub.dtb'))
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700680 fdt.PutInteger('/config', 'postload-text-offset', 0xffffffff)
Simon Glass290a1802011-07-17 13:54:32 -0700681 fdt_data = self._tools.ReadFile(fdt.fname)
Simon Glasse13ee2c2011-07-28 08:12:28 +1200682
Simon Glass89b86b82011-07-17 23:49:49 -0700683 self._tools.WriteFile(bootstub, uboot_data + fdt_data)
Simon Glass290a1802011-07-17 13:54:32 -0700684 self._tools.OutputSize('U-Boot binary', self.uboot_fname)
685 self._tools.OutputSize('U-Boot fdt', self._fdt_fname)
Simon Glass89b86b82011-07-17 23:49:49 -0700686 self._tools.OutputSize('Combined binary', bootstub)
687
Simon Glasse13ee2c2011-07-28 08:12:28 +1200688 # Sign the bootstub; this is a combination of the board specific
Simon Glass89b86b82011-07-17 23:49:49 -0700689 # bct and the stub u-boot image.
Simon Glass290a1802011-07-17 13:54:32 -0700690 signed = self._SignBootstub(self._tools.Filename(self.bct_fname),
Simon Glasse13ee2c2011-07-28 08:12:28 +1200691 bootstub, text_base)
Simon Glass6dcc2f22011-07-28 15:26:49 +1200692
693 signed_postload = os.path.join(self._tools.outdir, 'signed-postload.bin')
694 data = self._tools.ReadFile(signed)
695
696 if postload:
697 # We must add postload to the bootstub since A and B will need to
698 # be able to find it without the /config/postload-text-offset mechanism.
699 bs_data = self._tools.ReadFile(bootstub)
700 bs_data += self._tools.ReadFile(postload)
701 bootstub = os.path.join(self._tools.outdir, 'u-boot-fdt-postload.bin')
702 self._tools.WriteFile(bootstub, bs_data)
703 self._tools.OutputSize('Combined binary with postload', bootstub)
704
705 # Now that we know the file size, adjust the fdt and re-sign
706 postload_bootstub = os.path.join(self._tools.outdir, 'postload.bin')
Simon Glass02d124a2012-03-02 14:47:20 -0800707 fdt.PutInteger('/config', 'postload-text-offset', len(data))
Simon Glass6dcc2f22011-07-28 15:26:49 +1200708 fdt_data = self._tools.ReadFile(fdt.fname)
709 self._tools.WriteFile(postload_bootstub, uboot_data + fdt_data)
710 signed = self._SignBootstub(self._tools.Filename(self.bct_fname),
711 postload_bootstub, text_base)
712 if len(data) != os.path.getsize(signed):
713 raise CmdError('Signed file size changed from %d to %d after updating '
714 'fdt' % (len(data), os.path.getsize(signed)))
715
716 # Re-read the signed image, and add the post-load binary.
717 data = self._tools.ReadFile(signed)
718 data += self._tools.ReadFile(postload)
719 self._tools.OutputSize('Post-load binary', postload)
720
721 self._tools.WriteFile(signed_postload, data)
722 self._tools.OutputSize('Final bootstub with postload', signed_postload)
723
724 return bootstub, signed_postload
Simon Glass89b86b82011-07-17 23:49:49 -0700725
Aaron Durbin5751c3e2016-01-04 11:45:22 -0600726 def _AddCbfsFiles(self, bootstub):
727 for dir, subs, files in os.walk(self.cbfs_files):
728 for file in files:
729 file = os.path.join(dir, file)
730 cbfs_name = file.replace(self.cbfs_files, '', 1).strip('/')
731 self._tools.Run('cbfstool', [bootstub, 'add', '-f', file,
732 '-n', cbfs_name, '-t', 'raw', '-c', 'lzma'])
733
734 def _CreateCorebootStub(self, pack, coreboot):
735 """Create a coreboot boot stub and add pack properties.
Stefan Reinauerc2e1e4d2011-08-23 14:50:59 -0700736
737 Args:
Aaron Durbina113f522016-01-05 09:09:55 -0600738 pack: a PackFirmware object describing the firmware image to build.
Stefan Reinauerc2e1e4d2011-08-23 14:50:59 -0700739 coreboot: Path to coreboot.rom
Stefan Reinauerc2e1e4d2011-08-23 14:50:59 -0700740 """
741 bootstub = os.path.join(self._tools.outdir, 'coreboot-full.rom')
Simon Glassf2b3a5c2012-06-07 14:02:36 -0700742 shutil.copyfile(self._tools.Filename(coreboot), bootstub)
Simon Glasscbc83552012-07-23 15:26:22 +0100743
Aaron Durbin5751c3e2016-01-04 11:45:22 -0600744 pack.AddProperty('coreboot', bootstub)
745 pack.AddProperty('image', bootstub)
Stefan Reinauerc2e1e4d2011-08-23 14:50:59 -0700746
Aaron Durbin5751c3e2016-01-04 11:45:22 -0600747 # Add files to to RO CBFS if provided.
748 if self.cbfs_files:
749 self._AddCbfsFiles(bootstub)
Simon Glass7e199222012-03-13 15:51:18 -0700750
Aaron Durbina113f522016-01-05 09:09:55 -0600751 # Create a coreboot copy to use as a scratch pad. Order matters. The
752 # cbfs_files were added prior to this action. That's so the RW CBFS
753 # regions inherit the files from the RO CBFS region.
754 cb_copy = os.path.abspath(os.path.join(self._tools.outdir, 'cb_copy'))
755 self._tools.WriteFile(cb_copy, self._tools.ReadFile(bootstub))
756 pack.AddProperty('cb_copy', cb_copy)
757
758
Simon Glass89b86b82011-07-17 23:49:49 -0700759 def _PackOutput(self, msg):
760 """Helper function to write output from PackFirmware (verbose level 2).
761
762 This is passed to PackFirmware for it to use to write output.
763
764 Args:
765 msg: Message to display.
766 """
767 self._out.Notice(msg)
768
Vadim Bendeburyc9600c62014-12-22 16:31:13 -0800769 def _PrepareCbfs(self, pack, blob_name):
770 """Create CBFS blob in rw-boot-{a,b} FMAP sections.
771
772 When the blob name is defined as cbfs#<section>#<subsection>, fill the
773 <section>_<subsection> area in the flash map with a CBFS copy, putting the
774 CBFS header of the copy at the base of the section.
775
776 If --coreboot-elf parameter was specified during cros_bumdle_firmware
777 invocation, add the parameter of this option as the payload to the new
778 CBFS instance.
779
780 Args:
781 pack: a PackFirmware object describing the firmware image to build.
782 blob_name: a string, blob name describing what FMAP section this CBFS
783 copy is destined to
784 Raises:
785 CmdError if base coreboot image does not contain CBFS
Aaron Durbina113f522016-01-05 09:09:55 -0600786 BlobDeferral if coreboot image with fmap is not available yet.
Vadim Bendeburyc9600c62014-12-22 16:31:13 -0800787 """
788
Aaron Durbina113f522016-01-05 09:09:55 -0600789 cb_copy = pack.GetProperty('cb_copy')
790 if cb_copy is None:
791 raise BlobDeferral("Waiting for 'cb_copy' property.")
Vadim Bendeburyc9600c62014-12-22 16:31:13 -0800792
793 part_sections = blob_name.split('/')[1:]
794
795 # Base address and size of the desitnation partition
796 base, size = self.fdt.GetFlashPart(*part_sections)
797
Patrick Georgi10ea5ef2015-10-22 19:14:26 +0200798 # Check if there's an advanced CBFS configuration request
799 node = self.fdt.GetFlashNode(*part_sections)
800 try:
801 cbfs_config = self.fdt.GetProps(node + '/cbfs-files')
802 except CmdError:
803 cbfs_config = None
804
Vadim Bendeburyc9600c62014-12-22 16:31:13 -0800805 # Copy CBFS to the required offset
806 self._tools.Run('cbfstool', [cb_copy, 'copy', '-D',
807 '%d' % base, '-s', '%d' % size])
808
809 # Add coreboot payload if so requested. Note that the some images use
810 # different payload for the rw sections, which is passed in as the value
811 # of the --uboot option in the command line.
812 if self.uboot_fname:
813 payload_fname = self.uboot_fname
814 elif self.coreboot_elf:
815 payload_fname = self.coreboot_elf
816 else:
817 payload_fname = None
818
819 if payload_fname:
820 self._tools.Run('cbfstool', [
821 cb_copy, 'add-payload', '-f', payload_fname,
822 '-n', 'fallback/payload', '-c', 'lzma' , '-H', '%d' % base])
823
Patrick Georgi964fb542015-10-16 16:52:03 +0200824 if self.ecrw_fname:
825 self._tools.Run('cbfstool', [
826 cb_copy, 'add', '-f', self.ecrw_fname, '-t', 'raw',
827 '-n', 'ecrw', '-A', 'sha256', '-H', '%d' % base ])
828
829 if self.pdrw_fname:
830 self._tools.Run('cbfstool', [
831 cb_copy, 'add', '-f', self.pdrw_fname, '-t', 'raw',
832 '-n', 'pdrw', '-A', 'sha256', '-H', '%d' % base ])
833
Patrick Georgi10ea5ef2015-10-22 19:14:26 +0200834 # add files to CBFS in RW regions more flexibly:
835 # rw-a-boot {
836 # ...
837 # cbfs-files {
838 # ecfoo = "add -n ecrw-copy -f ec.RW.bin -t raw -A sha256";
839 # };
840 # };
841 # adds a file called "ecrw-copy" of raw type to FW_MAIN_A with the
842 # content of ec.RW.bin in the build root, with a SHA256 hash.
843 # The dts property name ("ecfoo") is ignored but should be unique,
844 # all cbfstool commands that start with "add" are allowed.
845 # The second and third argument need to be "-n <cbfs file name>".
846 if cbfs_config != None:
847 # remove all files slated for addition, in case they already exist
848 for val in cbfs_config.itervalues():
849 f = val.split(' ')
850 command = f[0]
851 if command[:3] != 'add':
852 raise CmdError("first argument in '%s' must start with 'add'", f)
853 if f[1] != '-n':
854 raise CmdError("second argument in '%s' must be '-n'", f)
855 cbfsname = f[2]
856 try:
Patrick Georgie920c2b2015-12-10 21:59:56 +0100857 # Calling through shell isn't strictly necessary here, but we still
858 # do it to keep operation more similar to the invocation in the next
859 # loop.
860 self._tools.Run('sh', [ '-c',
861 ' '.join(['cbfstool', cb_copy, 'remove', '-H', '%d' % base,
862 '-n', cbfsname]) ])
Patrick Georgi10ea5ef2015-10-22 19:14:26 +0200863 except CmdError:
864 pass # the most likely error is that the file doesn't already exist
865
866 # now add the files
867 for val in cbfs_config.itervalues():
868 f = val.split(' ')
869 command = f[0]
870 cbfsname = f[2]
871 args = f[3:]
Patrick Georgie920c2b2015-12-10 21:59:56 +0100872 # Call through shell so variable expansion can happen. With a change
873 # to the ebuild this enables specifying filename arguments to
874 # cbfstool as -f romstage.elf${COREBOOT_VARIANT} and have that be
875 # resolved to romstage.elf.serial when appropriate.
876 self._tools.Run('sh', [ '-c',
877 ' '.join(['cbfstool', cb_copy, command, '-H', '%d' % base,
878 '-n', cbfsname] + args)],
879 self._tools.Filename(self._GetBuildRoot()))
Patrick Georgi10ea5ef2015-10-22 19:14:26 +0200880
Vadim Bendeburyc9600c62014-12-22 16:31:13 -0800881 # And extract the blob for the FW section
882 rw_section = os.path.join(self._tools.outdir, '_'.join(part_sections))
883 self._tools.WriteFile(rw_section,
884 self._tools.ReadFile(cb_copy)[base:base+size])
885
886 pack.AddProperty(blob_name, rw_section)
887
888
Simon Glass439fe7a2012-03-09 16:19:34 -0800889 def _BuildBlob(self, pack, fdt, blob_type):
890 """Build the blob data for a particular blob type.
891
892 Args:
Vadim Bendebury7dac18c2014-05-06 14:13:35 -0700893 pack: a PackFirmware object describing the firmware image to build.
894 fdt: an fdt object including image layout information
Simon Glass439fe7a2012-03-09 16:19:34 -0800895 blob_type: The type of blob to create data for. Supported types are:
896 coreboot A coreboot image (ROM plus U-boot and .dtb payloads).
897 signed Nvidia T20/T30 signed image (BCT, U-Boot, .dtb).
Vadim Bendebury507c0012013-06-09 12:49:25 -0700898
899 Raises:
900 CmdError if a command fails.
Aaron Durbin41c85b62015-12-17 17:40:29 -0600901 BlobDeferral if a blob is waiting for a dependency.
Simon Glass439fe7a2012-03-09 16:19:34 -0800902 """
Vadim Bendebury7bfdb372013-03-27 11:52:58 -0700903 # stupid pylint insists that sha256 is not in hashlib.
904 # pylint: disable=E1101
Simon Glass439fe7a2012-03-09 16:19:34 -0800905 if blob_type == 'coreboot':
Aaron Durbin5751c3e2016-01-04 11:45:22 -0600906 self._CreateCorebootStub(pack, self.coreboot_fname)
Stefan Reinauer9ad54842012-10-10 12:25:23 -0700907 elif blob_type == 'legacy':
908 pack.AddProperty('legacy', self.seabios_fname)
Simon Glass439fe7a2012-03-09 16:19:34 -0800909 elif blob_type == 'signed':
910 bootstub, signed = self._CreateBootStub(self.uboot_fname, fdt,
911 self.postload_fname)
912 pack.AddProperty('bootstub', bootstub)
913 pack.AddProperty('signed', signed)
914 pack.AddProperty('image', signed)
Simon Glass7e199222012-03-13 15:51:18 -0700915 elif blob_type == 'exynos-bl1':
916 pack.AddProperty(blob_type, self.exynos_bl1)
Simon Glassbe0bc002012-08-16 12:50:48 -0700917
918 # TODO(sjg@chromium.org): Deprecate ecbin
919 elif blob_type in ['ecrw', 'ecbin']:
920 pack.AddProperty('ecrw', self.ecrw_fname)
921 pack.AddProperty('ecbin', self.ecrw_fname)
Randall Spangler7307da92014-07-18 12:47:34 -0700922 elif blob_type == 'pdrw':
923 pack.AddProperty('pdrw', self.pdrw_fname)
Gabe Blackcdbdfe12013-02-06 05:37:52 -0800924 elif blob_type == 'ecrwhash':
925 ec_hash_file = os.path.join(self._tools.outdir, 'ec_hash.bin')
926 ecrw = self._tools.ReadFile(self.ecrw_fname)
927 hasher = hashlib.sha256()
928 hasher.update(ecrw)
929 self._tools.WriteFile(ec_hash_file, hasher.digest())
930 pack.AddProperty(blob_type, ec_hash_file)
Randall Spangler7307da92014-07-18 12:47:34 -0700931 elif blob_type == 'pdrwhash':
932 pd_hash_file = os.path.join(self._tools.outdir, 'pd_hash.bin')
933 pdrw = self._tools.ReadFile(self.pdrw_fname)
934 hasher = hashlib.sha256()
935 hasher.update(pdrw)
936 self._tools.WriteFile(pd_hash_file, hasher.digest())
937 pack.AddProperty(blob_type, pd_hash_file)
Simon Glassbe0bc002012-08-16 12:50:48 -0700938 elif blob_type == 'ecro':
Simon Glass693b40f2012-08-28 10:51:05 -0700939 # crosbug.com/p/13143
940 # We cannot have an fmap in the EC image since there can be only one,
941 # which is the main fmap describing the whole image.
942 # Ultimately the EC will not have an fmap, since with software sync
943 # there is no flashrom involvement in updating the EC flash, and thus
944 # no need for the fmap.
945 # For now, mangle the fmap name to avoid problems.
946 updated_ecro = os.path.join(self._tools.outdir, 'updated-ecro.bin')
947 data = self._tools.ReadFile(self.ecro_fname)
948 data = re.sub('__FMAP__', '__fMAP__', data)
949 self._tools.WriteFile(updated_ecro, data)
950 pack.AddProperty(blob_type, updated_ecro)
Simon Glass0a047bc2013-07-19 15:44:43 -0600951 elif blob_type.startswith('exynos-bl2'):
952 # We need to configure this per node, so do it later
953 pass
Vadim Bendeburyc9600c62014-12-22 16:31:13 -0800954 elif blob_type.startswith('cbfs'):
955 self._PrepareCbfs(pack, blob_type)
Simon Glass439fe7a2012-03-09 16:19:34 -0800956 elif pack.GetProperty(blob_type):
957 pass
Che-Liang Chiou3bc344c2013-02-21 15:18:03 -0800958 elif blob_type in self.blobs:
959 pack.AddProperty(blob_type, self.blobs[blob_type])
Simon Glass439fe7a2012-03-09 16:19:34 -0800960 else:
961 raise CmdError("Unknown blob type '%s' required in flash map" %
962 blob_type)
963
Aaron Durbin41c85b62015-12-17 17:40:29 -0600964 def _BuildBlobs(self, pack, fdt):
965 """Build the blob data for the list of blobs in the pack.
966
967 Args:
968 pack: a PackFirmware object describing the firmware image to build.
969 fdt: an fdt object including image layout information
970
971 Raises:
972 CmdError if a command fails.
973 BlobDeferral if dependencies cannot be met because of cycles.
974 """
975 blob_list = pack.GetBlobList()
976 self._out.Info('Building blobs %s\n' % blob_list)
977
978 complete = False
979 deferred_list = []
980
981 # Build blobs allowing for dependencies between blobs. While this is
982 # an potential O(n^2) operation, in practice most blobs aren't dependent
983 # and should resolve in a few passes.
984 while not complete:
985 orig = set(blob_list)
986 for blob_type in blob_list:
987 try:
988 self._BuildBlob(pack, fdt, blob_type)
989 except (BlobDeferral):
990 deferred_list.append(blob_type)
991 if not deferred_list:
992 complete = True
993 # If deferred is the same as the original no progress is being made.
994 if not orig - set(deferred_list):
995 raise BlobDeferral("Blob cyle '%s'" % orig)
996 # Process the deferred blobs
997 blob_list = deferred_list[:]
998 deferred_list = []
999
Simon Glass290a1802011-07-17 13:54:32 -07001000 def _CreateImage(self, gbb, fdt):
Simon Glass89b86b82011-07-17 23:49:49 -07001001 """Create a full firmware image, along with various by-products.
1002
1003 This uses the provided u-boot.bin, fdt and bct to create a firmware
1004 image containing all the required parts. If the GBB is not supplied
1005 then this will just return a signed U-Boot as the image.
1006
1007 Args:
Vadim Bendebury7dac18c2014-05-06 14:13:35 -07001008 gbb: a string, full path to the GBB file, or empty if a GBB is not
1009 required.
1010 fdt: an fdt object containing required information.
Simon Glasse13ee2c2011-07-28 08:12:28 +12001011
1012 Returns:
1013 Path to image file
Simon Glass89b86b82011-07-17 23:49:49 -07001014 """
Simon Glass02d124a2012-03-02 14:47:20 -08001015 self._out.Notice("Model: %s" % fdt.GetString('/', 'model'))
Simon Glass89b86b82011-07-17 23:49:49 -07001016
Simon Glass439fe7a2012-03-09 16:19:34 -08001017 pack = PackFirmware(self._tools, self._out)
Simon Glassb8c6d952012-12-01 06:14:35 -08001018 if self._force_rw:
Vadim Bendebury7bfdb372013-03-27 11:52:58 -07001019 fdt.PutInteger('/flash/rw-a-vblock', 'preamble-flags', 0)
1020 fdt.PutInteger('/flash/rw-b-vblock', 'preamble-flags', 0)
Simon Glass00d027e2013-07-20 14:51:12 -06001021 if self._force_efs:
1022 fdt.PutInteger('/chromeos-config', 'early-firmware-selection', 1)
Simon Glassa7e66e22013-07-23 07:21:16 -06001023 pack.use_efs = fdt.GetInt('/chromeos-config', 'early-firmware-selection',
1024 0)
Simon Glassb8c6d952012-12-01 06:14:35 -08001025
Simon Glass4f318912013-07-20 16:13:06 -06001026 pack.SelectFdt(fdt, self._board)
Simon Glass439fe7a2012-03-09 16:19:34 -08001027
1028 # Get all our blobs ready
Vadim Bendebury466a7d82014-12-22 10:08:58 -08001029 if self.uboot_fname:
1030 pack.AddProperty('boot', self.uboot_fname)
Simon Glass284cb892013-02-09 13:38:03 -08001031 if self.skeleton_fname:
1032 pack.AddProperty('skeleton', self.skeleton_fname)
Simon Glass3b85f712012-06-21 07:06:46 -07001033 pack.AddProperty('dtb', fdt.fname)
Simon Glass50f74602012-03-15 21:04:25 -07001034
Simon Glassde9c8072012-07-02 22:29:02 -07001035 # If we are writing a kernel, add its offset from TEXT_BASE to the fdt.
1036 if self.kernel_fname:
1037 fdt.PutInteger('/config', 'kernel-offset', pack.image_size)
1038
Vadim Bendebury466a7d82014-12-22 10:08:58 -08001039 if gbb:
1040 pack.AddProperty('gbb', gbb)
Aaron Durbin41c85b62015-12-17 17:40:29 -06001041
1042 # Build the blobs out.
1043 self._BuildBlobs(pack, fdt)
Simon Glass89b86b82011-07-17 23:49:49 -07001044
Simon Glass7306b902012-12-17 15:06:21 -08001045 self._out.Progress('Packing image')
Simon Glass89b86b82011-07-17 23:49:49 -07001046 if gbb:
Simon Glasse76bf7b2012-03-13 15:34:41 -07001047 pack.RequireAllEntries()
Hung-Te Lina7462e72011-07-27 19:17:10 +08001048 fwid = '.'.join([
Simon Glass02d124a2012-03-02 14:47:20 -08001049 re.sub('[ ,]+', '_', fdt.GetString('/', 'model')),
Hung-Te Lina7462e72011-07-27 19:17:10 +08001050 self._tools.GetChromeosVersion()])
Simon Glass89b86b82011-07-17 23:49:49 -07001051 self._out.Notice('Firmware ID: %s' % fwid)
Simon Glass439fe7a2012-03-09 16:19:34 -08001052 pack.AddProperty('fwid', fwid)
Simon Glass439fe7a2012-03-09 16:19:34 -08001053 pack.AddProperty('keydir', self._keydir)
Simon Glassc90cf582012-03-13 15:40:47 -07001054
Simon Glass0a047bc2013-07-19 15:44:43 -06001055 # Some blobs need to be configured according to the node they are in.
Simon Glass4c24f662013-07-19 15:53:02 -06001056 todo = pack.GetMissingBlobs()
1057 for blob in todo:
Simon Glass0a047bc2013-07-19 15:44:43 -06001058 if blob.key.startswith('exynos-bl2'):
1059 bl2 = ExynosBl2(self._tools, self._out)
1060 pack.AddProperty(blob.key, bl2.MakeSpl(pack, fdt, blob,
1061 self.exynos_bl2))
1062
Simon Glassc90cf582012-03-13 15:40:47 -07001063 pack.CheckProperties()
Simon Glass8884b982012-06-21 12:41:41 -07001064
1065 # Record position and size of all blob members in the FDT
Gabe Blackcc22d772013-02-04 23:12:02 -08001066 pack.UpdateBlobPositionsAndHashes(fdt)
Simon Glass8884b982012-06-21 12:41:41 -07001067
Simon Glass4c24f662013-07-19 15:53:02 -06001068 # Recalculate the Exynos BL2, since it may have a hash. The call to
1069 # UpdateBlobPositionsAndHashes() may have updated the hash-target so we
1070 # need to recalculate the hash.
1071 for blob in todo:
1072 if blob.key.startswith('exynos-bl2'):
1073 bl2 = ExynosBl2(self._tools, self._out)
1074 pack.AddProperty(blob.key, bl2.MakeSpl(pack, fdt, blob,
1075 self.exynos_bl2))
1076
Simon Glass6207efe2012-12-17 15:04:36 -08001077 # Make a copy of the fdt for the bootstub
1078 fdt_data = self._tools.ReadFile(fdt.fname)
Vadim Bendebury466a7d82014-12-22 10:08:58 -08001079 if self.uboot_fname:
1080 uboot_data = self._tools.ReadFile(self.uboot_fname)
1081 uboot_copy = os.path.join(self._tools.outdir, 'u-boot.bin')
1082 self._tools.WriteFile(uboot_copy, uboot_data)
Simon Glass6207efe2012-12-17 15:04:36 -08001083
Vadim Bendebury466a7d82014-12-22 10:08:58 -08001084 uboot_dtb = os.path.join(self._tools.outdir, 'u-boot-dtb.bin')
1085 self._tools.WriteFile(uboot_dtb, uboot_data + fdt_data)
Simon Glass6207efe2012-12-17 15:04:36 -08001086
Simon Glassa10282a2013-01-08 17:06:41 -08001087 # Fix up the coreboot image here, since we can't do this until we have
1088 # a final device tree binary.
Aaron Durbin41c85b62015-12-17 17:40:29 -06001089 if 'coreboot' in pack.GetBlobList():
Simon Glasscbc83552012-07-23 15:26:22 +01001090 bootstub = pack.GetProperty('coreboot')
1091 fdt = fdt.Copy(os.path.join(self._tools.outdir, 'bootstub.dtb'))
Simon Glassa10282a2013-01-08 17:06:41 -08001092 if self.coreboot_elf:
1093 self._tools.Run('cbfstool', [bootstub, 'add-payload', '-f',
1094 self.coreboot_elf, '-n', 'fallback/payload', '-c', 'lzma'])
Vadim Bendebury466a7d82014-12-22 10:08:58 -08001095 elif self.uboot_fname:
Simon Glass0a7cf112013-05-21 23:08:21 -07001096 text_base = 0x1110000
1097
1098 # This is the the 'movw $GD_FLG_COLD_BOOT, %bx' instruction
1099 # 1110015: 66 bb 00 01 mov $0x100,%bx
1100 marker = struct.pack('<L', 0x0100bb66)
1101 pos = uboot_data.find(marker)
1102 if pos == -1 or pos > 0x100:
1103 raise ValueError('Cannot find U-Boot cold boot entry point')
1104 entry = text_base + pos
1105 self._out.Notice('U-Boot entry point %#08x' % entry)
Simon Glassa10282a2013-01-08 17:06:41 -08001106 self._tools.Run('cbfstool', [bootstub, 'add-flat-binary', '-f',
1107 uboot_dtb, '-n', 'fallback/payload', '-c', 'lzma',
Simon Glass0a7cf112013-05-21 23:08:21 -07001108 '-l', '%#x' % text_base, '-e', '%#x' % entry])
Stefan Reinauer1502ea62012-11-01 10:15:38 -07001109 self._tools.Run('cbfstool', [bootstub, 'add', '-f', fdt.fname,
1110 '-n', 'u-boot.dtb', '-t', '0xac'])
Simon Glassb8ea1802012-12-17 15:08:00 -08001111 data = self._tools.ReadFile(bootstub)
1112 bootstub_copy = os.path.join(self._tools.outdir, 'coreboot-8mb.rom')
1113 self._tools.WriteFile(bootstub_copy, data)
Vadim Bendebury9f36e712014-06-12 13:37:59 -07001114
Julius Werneraa1fe942014-11-21 17:16:11 -08001115 # Use offset and size from fmap.dts to extract CBFS area from coreboot.rom
1116 cbfs_offset, cbfs_size = fdt.GetFlashPart('ro', 'boot')
1117 self._tools.WriteFile(bootstub, data[cbfs_offset:cbfs_offset+cbfs_size])
Simon Glasscbc83552012-07-23 15:26:22 +01001118
Simon Glass208ad952013-02-10 11:16:46 -08001119 pack.AddProperty('fdtmap', fdt.fname)
Simon Glassc90cf582012-03-13 15:40:47 -07001120 image = os.path.join(self._tools.outdir, 'image.bin')
1121 pack.PackImage(self._tools.outdir, image)
1122 pack.AddProperty('image', image)
Simon Glass89b86b82011-07-17 23:49:49 -07001123
Simon Glass439fe7a2012-03-09 16:19:34 -08001124 image = pack.GetProperty('image')
Simon Glass89b86b82011-07-17 23:49:49 -07001125 self._tools.OutputSize('Final image', image)
Simon Glassc90cf582012-03-13 15:40:47 -07001126 return image, pack
Simon Glass89b86b82011-07-17 23:49:49 -07001127
Simon Glassdedda6f2013-02-09 13:44:14 -08001128 def SelectFdt(self, fdt_fname, use_defaults):
Simon Glass290a1802011-07-17 13:54:32 -07001129 """Select an FDT to control the firmware bundling
1130
Simon Glassdedda6f2013-02-09 13:44:14 -08001131 We make a copy of this which will include any on-the-fly changes we want
1132 to make.
1133
Simon Glass290a1802011-07-17 13:54:32 -07001134 Args:
1135 fdt_fname: The filename of the fdt to use.
Simon Glassdedda6f2013-02-09 13:44:14 -08001136 use_defaults: True to use a default FDT name if available, and to add
1137 a full path to the provided filename if necessary.
Simon Glass290a1802011-07-17 13:54:32 -07001138
Simon Glassc0f3dc62011-08-09 14:19:05 -07001139 Returns:
1140 The Fdt object of the original fdt file, which we will not modify.
1141
Simon Glassdedda6f2013-02-09 13:44:14 -08001142 Raises:
1143 ValueError if no FDT is provided (fdt_fname is None and use_defaults is
1144 False).
Simon Glass290a1802011-07-17 13:54:32 -07001145 """
Simon Glassdedda6f2013-02-09 13:44:14 -08001146 if use_defaults:
1147 fdt_fname = self._CheckFdtFilename(fdt_fname)
Simon Glass22f39fb2013-02-09 13:44:14 -08001148 if not fdt_fname:
1149 raise ValueError('Please provide an FDT filename')
1150 fdt = Fdt(self._tools, fdt_fname)
Simon Glass290a1802011-07-17 13:54:32 -07001151 self._fdt_fname = fdt_fname
Simon Glassc3e42c32012-12-17 15:00:04 -08001152
1153 # For upstream, select the correct architecture .dtsi manually.
1154 if self._board == 'link' or 'x86' in self._board:
1155 arch_dts = 'coreboot.dtsi'
1156 elif self._board == 'daisy':
1157 arch_dts = 'exynos5250.dtsi'
1158 else:
Rhyland Kleinc2df3ca2014-01-06 15:15:34 -05001159 arch_dts = 'tegra124.dtsi'
Simon Glassc3e42c32012-12-17 15:00:04 -08001160
1161 fdt.Compile(arch_dts)
Simon Glasse53abbc2013-08-21 22:29:55 -06001162 fdt = fdt.Copy(os.path.join(self._tools.outdir, 'updated.dtb'))
1163
1164 # Get the flashmap so we know what to build. For board variants use the
1165 # main board name as the key (drop the _<variant> suffix).
1166 default_flashmap = default_flashmaps.get(self._board.split('_')[0], [])
1167
1168 if not fdt.GetProp('/flash', 'reg', ''):
1169 fdt.InsertNodes(default_flashmap)
1170
Rhyland Kleinc2df3ca2014-01-06 15:15:34 -05001171 # Only check for /iram and /config nodes for boards that require it.
1172 if self._board in ('daisy', 'peach'):
1173 # Insert default values for any essential properties that are missing.
1174 # This should only happen for upstream U-Boot, until our changes are
1175 # upstreamed.
1176 if not fdt.GetProp('/iram', 'reg', ''):
1177 self._out.Warning('Cannot find /iram, using default')
1178 fdt.InsertNodes([i for i in default_flashmap if i['path'] == '/iram'])
Simon Glasse53abbc2013-08-21 22:29:55 -06001179
Rhyland Kleinc2df3ca2014-01-06 15:15:34 -05001180 # Sadly the pit branch has an invalid /memory node. Work around it
1181 # for now. crosbug.com/p/22184
1182 if (not fdt.GetProp('/memory', 'reg', '') or
1183 fdt.GetIntList('/memory', 'reg')[0] == 0):
1184 self._out.Warning('Cannot find /memory, using default')
1185 fdt.InsertNodes([i for i in default_flashmap if i['path'] == '/memory'])
Simon Glasse53abbc2013-08-21 22:29:55 -06001186
Rhyland Kleinc2df3ca2014-01-06 15:15:34 -05001187 if not fdt.GetProp('/config', 'samsung,bl1-offset', ''):
1188 self._out.Warning('Missing properties in /config, using defaults')
1189 fdt.InsertNodes([i for i in default_flashmap if i['path'] == '/config'])
Simon Glasse53abbc2013-08-21 22:29:55 -06001190
Simon Glass7df773b2013-08-25 18:02:29 -06001191 # Remember our board type.
1192 fdt.PutString('/chromeos-config', 'board', self._board)
1193
Simon Glasse53abbc2013-08-21 22:29:55 -06001194 self.fdt = fdt
1195 return fdt
Simon Glass290a1802011-07-17 13:54:32 -07001196
Simon Glassc90cf582012-03-13 15:40:47 -07001197 def Start(self, hardware_id, output_fname, show_map):
Simon Glass290a1802011-07-17 13:54:32 -07001198 """This creates a firmware bundle according to settings provided.
Simon Glass89b86b82011-07-17 23:49:49 -07001199
1200 - Checks options, tools, output directory, fdt.
1201 - Creates GBB and image.
Simon Glass290a1802011-07-17 13:54:32 -07001202
1203 Args:
Simon Glass56577572011-07-19 11:08:06 +12001204 hardware_id: Hardware ID to use for this board. If None, then the
1205 default from the Fdt will be used
Simon Glass290a1802011-07-17 13:54:32 -07001206 output_fname: Output filename for the image. If this is not None, then
1207 the final image will be copied here.
Simon Glassc90cf582012-03-13 15:40:47 -07001208 show_map: Show a flash map, with each area's name and position
Simon Glass290a1802011-07-17 13:54:32 -07001209
1210 Returns:
1211 Filename of the resulting image (not the output_fname copy).
Simon Glass89b86b82011-07-17 23:49:49 -07001212 """
Vadim Bendebury5baeec12013-04-02 13:01:22 -07001213 if self._small or self.fdt.GetProp('/config', 'nogbb', 'any') != 'any':
1214 gbb = '' # Building a small image or `nogbb' is requested in device tree.
1215 else:
Simon Glass56577572011-07-19 11:08:06 +12001216 gbb = self._CreateGoogleBinaryBlock(hardware_id)
Simon Glass89b86b82011-07-17 23:49:49 -07001217
1218 # This creates the actual image.
Simon Glassc90cf582012-03-13 15:40:47 -07001219 image, pack = self._CreateImage(gbb, self.fdt)
1220 if show_map:
1221 pack.ShowMap()
Simon Glass290a1802011-07-17 13:54:32 -07001222 if output_fname:
1223 shutil.copyfile(image, output_fname)
1224 self._out.Notice("Output image '%s'" % output_fname)
Simon Glass794217e2012-06-07 11:40:37 -07001225 return image, pack.props