Merge lp:~milo/linaro-image-tools/android-hwpack into lp:linaro-image-tools/11.11

Proposed by Данило Шеган
Status: Rejected
Rejected by: Milo Casagrande
Proposed branch: lp:~milo/linaro-image-tools/android-hwpack
Merge into: lp:linaro-image-tools/11.11
Diff against target: 5512 lines (+1928/-1614)
12 files modified
linaro-android-media-create (+15/-9)
linaro-media-create (+3/-3)
linaro_image_tools/hwpack/handler.py (+292/-0)
linaro_image_tools/hwpack/hwpack_fields.py (+7/-3)
linaro_image_tools/hwpack/hwpack_reader.py (+1/-1)
linaro_image_tools/media_create/__init__.py (+4/-3)
linaro_image_tools/media_create/android_boards.py (+219/-157)
linaro_image_tools/media_create/boards.py (+787/-1017)
linaro_image_tools/media_create/chroot_utils.py (+1/-1)
linaro_image_tools/media_create/tests/__init__.py (+4/-2)
linaro_image_tools/media_create/tests/test_android_boards.py (+249/-0)
linaro_image_tools/media_create/tests/test_media_create.py (+346/-418)
To merge this branch: bzr merge lp:~milo/linaro-image-tools/android-hwpack
Reviewer Review Type Date Requested Status
Данило Шеган (community) Disapprove
Review via email: mp+135109@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) wrote :

A few things on this branch:

 * it needs to be split up into more manageable branches (I said this a few times already)—take the "mechanical" changes out and put them into a branch of it's own (moving code around and enabling use of instances instead of classes all belongs in either one or two separate branches).
 * land bits and pieces that can land asap.
 * extracted configs contain only the 'final' class elements, not anything out of parent classes.

review: Disapprove
Revision history for this message
Данило Шеган (danilo) wrote :

Oh, and we should keep all the android_boards.py settings in: when no hwpack-like files are used, we should still be able to build older android images and similar.

Revision history for this message
Milo Casagrande (milo) wrote :

On Thu, Nov 22, 2012 at 2:44 PM, Данило Шеган <email address hidden> wrote:
> Review: Disapprove
>
> A few things on this branch:
>
> * it needs to be split up into more manageable branches (I said this a few times already)—take the "mechanical" changes out and put them into a branch of it's own (moving code around and enabling use of instances instead of classes all belongs in either one or two separate branches).
> * land bits and pieces that can land asap.

Indeed, it was not my intention to propose that branch for review, I
wanted to have a place where to store all for the moment, since I
wouldn't be able to complete it all in time.
I will split out the changes and start with the ones that should not
introduce errors or problems to other parts.

> * extracted configs contain only the 'final' class elements, not anything out of parent classes.

Yes, I'm not sure about this point though. I need to pick-up again
disucssions with Vishal if they want to have the full blown
configuration, or just a small subset and rely on the other
"defaults".
Ciao.

--
Milo Casagrande
Infrastructure Engineer
Linaro.org <www.linaro.org> │ Open source software for ARM SoCs

Unmerged revisions

617. By Milo Casagrande

Added new tests.

616. By Milo Casagrande

Fixed more tests.

615. By Milo Casagrande

Fixed more tests, 50 to go.

614. By Milo Casagrande

Fixed even more tests.

613. By Milo Casagrande

Fixed more tests.

612. By Milo Casagrande

Added fields.

611. By Milo Casagrande

Continued refactoring.

610. By Milo Casagrande

Started to fix tests.

609. By Milo Casagrande

Continue refactoring.

608. By Milo Casagrande

Continue refactoring, added TODOs.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro-android-media-create'
--- linaro-android-media-create 2012-07-26 08:48:15 +0000
+++ linaro-android-media-create 2012-11-20 10:49:03 +0000
@@ -26,7 +26,7 @@
26from linaro_image_tools import cmd_runner26from linaro_image_tools import cmd_runner
2727
28from linaro_image_tools.media_create.android_boards import (28from linaro_image_tools.media_create.android_boards import (
29 android_board_configs,29 get_board_config,
30 )30 )
31from linaro_image_tools.media_create.check_device import (31from linaro_image_tools.media_create.check_device import (
32 confirm_device_selection_and_ensure_it_is_ready)32 confirm_device_selection_and_ensure_it_is_ready)
@@ -40,8 +40,10 @@
40 unpack_android_binary_tarball40 unpack_android_binary_tarball
41 )41 )
42from linaro_image_tools.media_create import get_android_args_parser42from linaro_image_tools.media_create import get_android_args_parser
43from linaro_image_tools.utils import ensure_command43from linaro_image_tools.utils import (
4444 ensure_command,
45 get_logger
46 )
4547
4648
47# Just define the global variables49# Just define the global variables
@@ -89,6 +91,8 @@
89 parser = get_android_args_parser()91 parser = get_android_args_parser()
90 args = parser.parse_args()92 args = parser.parse_args()
9193
94 logger = get_logger(debug=args.debug)
95
92 # If --help was specified this won't execute.96 # If --help was specified this won't execute.
93 # Create temp dir and initialize rest of path vars.97 # Create temp dir and initialize rest of path vars.
94 TMP_DIR = tempfile.mkdtemp()98 TMP_DIR = tempfile.mkdtemp()
@@ -102,13 +106,15 @@
102 DATA_DISK = os.path.join(TMP_DIR, 'userdata-disc')106 DATA_DISK = os.path.join(TMP_DIR, 'userdata-disc')
103 SDCARD_DISK = os.path.join(TMP_DIR, 'sdcard-disc')107 SDCARD_DISK = os.path.join(TMP_DIR, 'sdcard-disc')
104108
105 board_config = android_board_configs[args.dev]109 board_config = get_board_config(args.dev)
110 board_config.from_file(args.hwpack)
106 board_config.add_boot_args(args.extra_boot_args)111 board_config.add_boot_args(args.extra_boot_args)
107 board_config.add_boot_args_from_file(args.extra_boot_args_file)112 board_config.add_boot_args_from_file(args.extra_boot_args_file)
108113
109 if args.dev == 'iMX53':114 if args.dev == 'iMX53':
110 # XXX: remove this and the corresponding entry in android_board_configs115 # XXX: remove this and the corresponding entry in android_board_configs
111 print "DEPRECATION WARNING: iMX53 is deprecated, please use mx53loco."116 logger.warning("DEPRECATION WARNING: iMX53 is deprecated, please "
117 "use mx53loco.")
112118
113 ensure_required_commands(args)119 ensure_required_commands(args)
114120
@@ -117,11 +123,11 @@
117 if not confirm_device_selection_and_ensure_it_is_ready(args.device):123 if not confirm_device_selection_and_ensure_it_is_ready(args.device):
118 sys.exit(1)124 sys.exit(1)
119 elif not args.should_create_partitions:125 elif not args.should_create_partitions:
120 print ("Do not use --no-part in conjunction with --image_file.")126 logger.error("Do not use --no-part in conjunction with --image_file.")
121 sys.exit(1)127 sys.exit(1)
122 else:128 # else:
123 # All good, move on.129 # # All good, move on.
124 pass130 # pass
125131
126 cmd_runner.run(['mkdir', '-p', BOOT_DIR]).wait()132 cmd_runner.run(['mkdir', '-p', BOOT_DIR]).wait()
127 cmd_runner.run(['mkdir', '-p', SYSTEM_DIR]).wait()133 cmd_runner.run(['mkdir', '-p', SYSTEM_DIR]).wait()
128134
=== modified file 'linaro-media-create'
--- linaro-media-create 2012-10-22 06:57:20 +0000
+++ linaro-media-create 2012-11-20 10:49:03 +0000
@@ -25,7 +25,7 @@
2525
26from linaro_image_tools import cmd_runner26from linaro_image_tools import cmd_runner
2727
28from linaro_image_tools.media_create.boards import board_configs28from linaro_image_tools.media_create.boards import get_board_config
29from linaro_image_tools.media_create.check_device import (29from linaro_image_tools.media_create.check_device import (
30 confirm_device_selection_and_ensure_it_is_ready)30 confirm_device_selection_and_ensure_it_is_ready)
31from linaro_image_tools.media_create.chroot_utils import (31from linaro_image_tools.media_create.chroot_utils import (
@@ -131,9 +131,9 @@
131 logger.error(e.value)131 logger.error(e.value)
132 sys.exit(1)132 sys.exit(1)
133133
134 board_config = board_configs[args.dev]134 board_config = get_board_config(args.dev)
135 board_config.set_metadata(args.hwpacks, args.bootloader, args.dev)135 board_config.set_metadata(args.hwpacks, args.bootloader, args.dev)
136 board_config.set_board(args.dev)136 board_config.board(args.dev)
137 board_config.add_boot_args(args.extra_boot_args)137 board_config.add_boot_args(args.extra_boot_args)
138 board_config.add_boot_args_from_file(args.extra_boot_args_file)138 board_config.add_boot_args_from_file(args.extra_boot_args_file)
139139
140140
=== added file 'linaro_image_tools/hwpack/handler.py'
--- linaro_image_tools/hwpack/handler.py 1970-01-01 00:00:00 +0000
+++ linaro_image_tools/hwpack/handler.py 2012-11-20 10:49:03 +0000
@@ -0,0 +1,292 @@
1# Copyright (C) 2010, 2011 Linaro
2#
3# Author: Guilherme Salgado <guilherme.salgado@linaro.org>
4#
5# This file is part of Linaro Image Tools.
6#
7# Linaro Image Tools is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# Linaro Image Tools is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>.
19
20from StringIO import StringIO
21import ConfigParser
22import logging
23import os
24import re
25import shutil
26import tarfile
27import tempfile
28
29from linaro_image_tools.hwpack.config import Config
30from linaro_image_tools.hwpack.builder import PackageUnpacker
31from linaro_image_tools.utils import DEFAULT_LOGGER_NAME
32
33
34logger = logging.getLogger(DEFAULT_LOGGER_NAME)
35
36
37class HardwarepackHandler(object):
38 FORMAT_1 = '1.0'
39 FORMAT_2 = '2.0'
40 FORMAT_3 = '3.0'
41 FORMAT_MIXED = '1.0and2.0'
42 metadata_filename = 'metadata'
43 format_filename = 'FORMAT'
44 main_section = 'main'
45 hwpack_tarfiles = []
46 tempdir = None
47
48 def __init__(self, hwpacks, bootloader=None, board=None):
49 self.hwpacks = hwpacks
50 self.hwpack_tarfiles = []
51 self.bootloader = bootloader
52 self.board = board
53 self.tempdirs = {}
54 # Used to store the config created from the metadata.
55 self.config = None
56
57 class FakeSecHead(object):
58 """ Add a fake section header to the metadata file.
59
60 This is done so we can use ConfigParser to parse the file.
61 """
62 def __init__(self, fp):
63 self.fp = fp
64 self.sechead = '[%s]\n' % HardwarepackHandler.main_section
65
66 def readline(self):
67 if self.sechead:
68 try:
69 return self.sechead
70 finally:
71 self.sechead = None
72 else:
73 return self.fp.readline()
74
75 def __enter__(self):
76 self.tempdir = tempfile.mkdtemp()
77 for hwpack in self.hwpacks:
78 hwpack_tarfile = tarfile.open(hwpack, mode='r:gz')
79 self.hwpack_tarfiles.append(hwpack_tarfile)
80 return self
81
82 def __exit__(self, type, value, traceback):
83 for hwpack_tarfile in self.hwpack_tarfiles:
84 if hwpack_tarfile is not None:
85 hwpack_tarfile.close()
86 self.hwpack_tarfiles = []
87 if self.tempdir is not None and os.path.exists(self.tempdir):
88 shutil.rmtree(self.tempdir)
89
90 for name in self.tempdirs:
91 tempdir = self.tempdirs[name]
92 if tempdir is not None and os.path.exists(tempdir):
93 shutil.rmtree(tempdir)
94
95 def _get_config_from_metadata(self, metadata):
96 """
97 Retrieves a Config object associated with the metadata.
98
99 :param metadata: The metadata to parse.
100 :return: A Config instance.
101 """
102 if not self.config:
103 lines = metadata.readlines()
104 if re.search("=", lines[0]) and not re.search(":", lines[0]):
105 # Probably V2 hardware pack without [hwpack] on the first line
106 lines = ["[hwpack]\n"] + lines
107 self.config = Config(StringIO("".join(lines)))
108 self.config.set_board(self.board)
109 self.config.set_bootloader(self.bootloader)
110 return self.config
111
112 def get_field(self, field, return_keys=False):
113 data = None
114 hwpack_with_data = None
115 keys = None
116 for hwpack_tarfile in self.hwpack_tarfiles:
117 metadata = hwpack_tarfile.extractfile(self.metadata_filename)
118 parser = self._get_config_from_metadata(metadata)
119 try:
120 new_data = parser.get_option(field)
121 if new_data is not None:
122 assert data is None, "The metadata field '%s' is set to " \
123 "'%s' and new value '%s' is found" % (field, data,
124 new_data)
125 data = new_data
126 hwpack_with_data = hwpack_tarfile
127 if return_keys:
128 keys = parser.get_last_used_keys()
129 except ConfigParser.NoOptionError:
130 continue
131
132 if return_keys:
133 return data, hwpack_with_data, keys
134 return data, hwpack_with_data
135
136 def get_format(self):
137 format = None
138 supported_formats = [self.FORMAT_1, self.FORMAT_2, self.FORMAT_3]
139 for hwpack_tarfile in self.hwpack_tarfiles:
140 format_file = hwpack_tarfile.extractfile(self.format_filename)
141 format_string = format_file.read().strip()
142 if not format_string in supported_formats:
143 raise AssertionError(
144 "Format version '%s' is not supported." % format_string)
145 if format is None:
146 format = format_string
147 elif format != format_string:
148 return self.FORMAT_MIXED
149 return format
150
151 def get_file(self, file_alias):
152 """Get file(s) from a hwpack.
153 :param file_alias: Property name (not field name) which contains
154 file reference(s)
155 :return: path to a file or list of paths to files
156 """
157 file_names, hwpack_tarfile, keys = self.get_field(file_alias,
158 return_keys=True)
159 if not file_names:
160 return file_names
161 single = False
162 if not isinstance(file_names, list):
163 single = True
164 file_names = [file_names]
165 out_files = []
166
167 # Depending on if board and/or bootloader were used to look up the
168 # file we are getting, we need to prepend those names to the path
169 # to get the correct extracted file from the hardware pack.
170 config_names = [("board", "boards"), ("bootloader", "bootloaders")]
171 base_path = ""
172 if keys:
173 # If keys is non-empty, we have a V3 config option that was
174 # modified by the bootloader and/or boot option...
175 for name, key in config_names:
176 if self.get_field(name):
177 value = self.get_field(name)[0]
178 if keys[0] == key:
179 base_path = os.path.join(base_path, value)
180 keys = keys[1:]
181
182 for f in file_names:
183 # Check that the base path is needed. If the file doesn't exist,
184 # try without it (this provides fallback to V2 style directory
185 # layouts with a V3 config).
186 path_inc_board_and_bootloader = os.path.join(base_path, f)
187 if path_inc_board_and_bootloader in hwpack_tarfile.getnames():
188 f = path_inc_board_and_bootloader
189 hwpack_tarfile.extract(f, self.tempdir)
190 f = os.path.join(self.tempdir, f)
191 out_files.append(f)
192 if single:
193 return out_files[0]
194 return out_files
195
196 def list_packages(self):
197 """Return list of (package names, TarFile object containing them)"""
198 packages = []
199 for tf in self.hwpack_tarfiles:
200 for name in tf.getnames():
201 if name.startswith("pkgs/") and name.endswith(".deb"):
202 packages.append((tf, name))
203 return packages
204
205 def find_package_for(self, name, version=None, revision=None,
206 architecture=None):
207 """Find a package that matches the name, version, rev and arch given.
208
209 Packages are named according to the debian specification:
210 http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html
211 <name>_<Version>-<DebianRevisionNumber>_<DebianArchitecture>.deb
212 DebianRevisionNumber seems to be optional.
213 Use this spec to return a package matching the requirements given.
214 """
215 for tar_file, package in self.list_packages():
216 file_name = os.path.basename(package)
217 dpkg_chunks = re.search("^(.+)_(.+)_(.+)\.deb$",
218 file_name)
219 assert dpkg_chunks, "Could not split package file name into"\
220 "<name>_<Version>_<DebianArchitecture>.deb"
221
222 pkg_name = dpkg_chunks.group(1)
223 pkg_version = dpkg_chunks.group(2)
224 pkg_architecture = dpkg_chunks.group(3)
225
226 ver_chunks = re.search("^(.+)-(.+)$", pkg_version)
227 if ver_chunks:
228 pkg_version = ver_chunks.group(1)
229 pkg_revision = ver_chunks.group(2)
230 else:
231 pkg_revision = None
232
233 if name != pkg_name:
234 continue
235 if version != None and str(version) != pkg_version:
236 continue
237 if revision != None and str(revision) != pkg_revision:
238 continue
239 if (architecture != None and
240 str(architecture) != pkg_architecture):
241 continue
242
243 # Got a matching package - return its path inside the tarball
244 return tar_file, package
245
246 # Failed to find a matching package - return None
247 return None
248
249 def get_file_from_package(self, file_path, package_name,
250 package_version=None, package_revision=None,
251 package_architecture=None):
252 """Extract named file from package specified by name, ver, rev, arch.
253
254 File is extracted from the package matching the given specification
255 to a temporary directory. The absolute path to the extracted file is
256 returned.
257 """
258
259 package_info = self.find_package_for(package_name,
260 package_version,
261 package_revision,
262 package_architecture)
263 if package_info is None:
264 return None
265 tar_file, package = package_info
266
267 # Avoid unpacking hardware pack more than once by assigning each one
268 # its own tempdir to unpack into.
269 # TODO: update logic that uses self.tempdir so we can get rid of this
270 # by sharing nicely.
271 if not package in self.tempdirs:
272 self.tempdirs[package] = tempfile.mkdtemp()
273 tempdir = self.tempdirs[package]
274
275 # We extract everything in the hardware pack so we don't have to worry
276 # about chasing links (extract a link, find where it points to, extract
277 # that...). This is slower, but more reliable.
278 tar_file.extractall(tempdir)
279 package_path = os.path.join(tempdir, package)
280
281 with PackageUnpacker() as self.package_unpacker:
282 extracted_file = self.package_unpacker.get_file(package_path,
283 file_path)
284 after_tmp = re.sub(self.package_unpacker.tempdir, "",
285 extracted_file).lstrip("/\\")
286 extract_dir = os.path.join(tempdir, "extracted",
287 os.path.dirname(after_tmp))
288 os.makedirs(extract_dir)
289 shutil.move(extracted_file, extract_dir)
290 extracted_file = os.path.join(extract_dir,
291 os.path.basename(extracted_file))
292 return extracted_file
0293
=== modified file 'linaro_image_tools/hwpack/hwpack_fields.py'
--- linaro_image_tools/hwpack/hwpack_fields.py 2012-10-02 14:53:56 +0000
+++ linaro_image_tools/hwpack/hwpack_fields.py 2012-11-20 10:49:03 +0000
@@ -86,10 +86,14 @@
86METADATA_VERSION_FIELD = 'version'86METADATA_VERSION_FIELD = 'version'
8787
88# The allowed partition layouts.88# The allowed partition layouts.
89BOOTFS16 = 'bootfs16_rootfs'
90BOOTFS = 'bootfs_rootfs'
91RESERVED_BOOTFS = 'reserved_bootfs_rootfs'
92
89DEFINED_PARTITION_LAYOUTS = [93DEFINED_PARTITION_LAYOUTS = [
90 'bootfs16_rootfs',94 BOOTFS16,
91 'bootfs_rootfs',95 BOOTFS,
92 'reserved_bootfs_rootfs', ]96 RESERVED_BOOTFS, ]
9397
94# Supported bootloaders98# Supported bootloaders
95U_BOOT = 'u_boot'99U_BOOT = 'u_boot'
96100
=== modified file 'linaro_image_tools/hwpack/hwpack_reader.py'
--- linaro_image_tools/hwpack/hwpack_reader.py 2012-07-25 13:05:16 +0000
+++ linaro_image_tools/hwpack/hwpack_reader.py 2012-11-20 10:49:03 +0000
@@ -17,7 +17,7 @@
17# You should have received a copy of the GNU General Public License17# You should have received a copy of the GNU General Public License
18# along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>.18# along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>.
1919
20from linaro_image_tools.media_create.boards import HardwarepackHandler20from linaro_image_tools.hwpack.handler import HardwarepackHandler
21from linaro_image_tools.hwpack.hwpack_fields import (21from linaro_image_tools.hwpack.hwpack_fields import (
22 FORMAT_FIELD,22 FORMAT_FIELD,
23 NAME_FIELD,23 NAME_FIELD,
2424
=== modified file 'linaro_image_tools/media_create/__init__.py'
--- linaro_image_tools/media_create/__init__.py 2012-10-22 06:57:20 +0000
+++ linaro_image_tools/media_create/__init__.py 2012-11-20 10:49:03 +0000
@@ -78,6 +78,7 @@
78 parser.add_argument(78 parser.add_argument(
79 '--extra-boot-args-file', dest='extra_boot_args_file',79 '--extra-boot-args-file', dest='extra_boot_args_file',
80 required=False, help=('File containing extra boot arguments.'))80 required=False, help=('File containing extra boot arguments.'))
81 parser.add_argument("--debug", action="store_true")
8182
8283
83def get_args_parser():84def get_args_parser():
@@ -173,7 +174,6 @@
173 help="Select a bootloader from a hardware pack that contains more "174 help="Select a bootloader from a hardware pack that contains more "
174 "than one. If not specified, it will default to '%s'." %175 "than one. If not specified, it will default to '%s'." %
175 DEFAULT_BOOTLOADER)176 DEFAULT_BOOTLOADER)
176 parser.add_argument("--debug", action="store_true")
177177
178 add_common_options(parser)178 add_common_options(parser)
179 return parser179 return parser
@@ -189,6 +189,9 @@
189 '--image-file', '--image_file', dest='device',189 '--image-file', '--image_file', dest='device',
190 help='File where we should write the image file.')190 help='File where we should write the image file.')
191 parser.add_argument(191 parser.add_argument(
192 '--hwpack', required=True,
193 help=('An Android hardware pack file with the board configuration.'))
194 parser.add_argument(
192 '--image-size', '--image_size', default='2G',195 '--image-size', '--image_size', default='2G',
193 help=('The image size, specified in mega/giga bytes (e.g. 3000M or '196 help=('The image size, specified in mega/giga bytes (e.g. 3000M or '
194 '3G); use with --image_file only'))197 '3G); use with --image_file only'))
@@ -202,7 +205,6 @@
202 '--console', action='append', dest='consoles', default=[],205 '--console', action='append', dest='consoles', default=[],
203 help=('Add a console to kernel boot parameter; this parameter can be '206 help=('Add a console to kernel boot parameter; this parameter can be '
204 'defined multiple times.'))207 'defined multiple times.'))
205
206 parser.add_argument(208 parser.add_argument(
207 '--system', default='system.tar.bz2', required=True,209 '--system', default='system.tar.bz2', required=True,
208 help=('The tarball containing the Android system paritition'))210 help=('The tarball containing the Android system paritition'))
@@ -212,7 +214,6 @@
212 parser.add_argument(214 parser.add_argument(
213 '--boot', default='boot.tar.bz2', required=True,215 '--boot', default='boot.tar.bz2', required=True,
214 help=('The tarball containing the Android root partition'))216 help=('The tarball containing the Android root partition'))
215
216 parser.add_argument(217 parser.add_argument(
217 '--no-part', dest='should_create_partitions', action='store_false',218 '--no-part', dest='should_create_partitions', action='store_false',
218 help='Reuse existing partitions on the given media.')219 help='Reuse existing partitions on the given media.')
219220
=== modified file 'linaro_image_tools/media_create/android_boards.py'
--- linaro_image_tools/media_create/android_boards.py 2012-10-17 10:48:49 +0000
+++ linaro_image_tools/media_create/android_boards.py 2012-11-20 10:49:03 +0000
@@ -20,44 +20,131 @@
20"""Configuration for boards supported by linaro-android-media-create.20"""Configuration for boards supported by linaro-android-media-create.
2121
22To add support for a new board, you need to create a subclass of22To add support for a new board, you need to create a subclass of
23AndroidBoardConfig, set appropriate values for its variables and add it to23AndroidBoardConfig, create an Android hwpack as explained here:
24android_board_configs at the bottom of this file.24
25https://wiki.linaro.org/AndroidHardwarePacksV3
26
27and add the board to 'android_board_configs' at the end of this file.
25"""28"""
2629
30import os
31import yaml
32import logging
33
34from linaro_image_tools import cmd_runner
27from linaro_image_tools.media_create.partitions import SECTOR_SIZE35from linaro_image_tools.media_create.partitions import SECTOR_SIZE
28from linaro_image_tools.media_create.boards import PART_ALIGN_S
29from linaro_image_tools.media_create.boards import BeagleConfig
30from linaro_image_tools.media_create.boards import PandaConfig
31from linaro_image_tools.media_create.boards import Mx53LoCoConfig
32from linaro_image_tools.media_create.boards import SnowballSdConfig
33from linaro_image_tools.media_create.boards import SnowballEmmcConfig
34from linaro_image_tools.media_create.boards import SMDKV310Config
35from linaro_image_tools.media_create.boards import OrigenConfig
36from linaro_image_tools.media_create.boards import VexpressConfig
37from linaro_image_tools.media_create.boards import (36from linaro_image_tools.media_create.boards import (
37 BeagleConfig,
38 BoardConfig,
39 BoardConfigException,
40 Mx53LoCoConfig,
41 OrigenConfig,
42 PART_ALIGN_S,
43 PandaConfig,
44 SMDKV310Config,
45 SnowballEmmcConfig,
46 SnowballSdConfig,
47 VexpressConfig,
48 align_partition,
38 align_up,49 align_up,
39 align_partition,50 install_mx5_boot_loader,
40 classproperty,
41 make_boot_script,51 make_boot_script,
42 install_mx5_boot_loader,
43 )52 )
4453from linaro_image_tools.utils import DEFAULT_LOGGER_NAME
45from linaro_image_tools import cmd_runner54
46import os55logger = logging.getLogger(DEFAULT_LOGGER_NAME)
4756
4857BOOT_MIN_SIZE_S = align_up(128 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
49class AndroidBoardConfig(object):58SYSTEM_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
50 @classmethod59CACHE_MIN_SIZE_S = align_up(256 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
51 def _get_bootargs(cls, consoles):60USERDATA_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
61SDCARD_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
62LOADER_MIN_SIZE_S = align_up(1 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
63
64
65class AndroidBoardConfig(BoardConfig):
66
67 def __init__(self):
68 super(AndroidBoardConfig, self).__init__()
69 self._dtb_name = None
70 self._extra_serial_options = []
71 self._android_specific_args = []
72 self._extra_boot_args_options = []
73
74 def _get_android_specific_args(self):
75 return ' '.join(self._android_specific_args)
76
77 def _set_android_specific_args(self, value):
78 self._android_specific_args = value
79
80 android_specific_args = property(_get_android_specific_args,
81 _set_android_specific_args)
82
83 def _get_extra_boot_args_options(self):
84 return ' '.join(self._extra_boot_args_options)
85
86 def _set_extra_boot_args_options(self, value):
87 self._extra_boot_args_options = value
88
89 extra_boot_args_options = property(_get_extra_boot_args_options,
90 _set_extra_boot_args_options)
91
92 def _get_extra_serial_options(self):
93 return ' '.join(self._extra_serial_options)
94
95 def _set_extra_serial_options(self, value):
96 self._extra_serial_options = value
97
98 extra_serial_options = property(_get_extra_serial_options,
99 _set_extra_serial_options)
100
101 def _get_dtb_name(self):
102 return self._dtb_name
103
104 def _set_dtb_name(self, value):
105 self._dtb_name = value
106
107 dtb_name = property(_get_dtb_name, _set_dtb_name)
108
109 def from_file(self, hwpack):
110 """Loads the Android board configuration from an Android hardware pack
111 configuration file and sets the config attributes with their values.
112
113 :param hwpack: The Android hwpack configuration file.
114 :return The configuration read from the file as a dictionary.
115 """
116 try:
117 config = yaml.safe_load(hwpack)
118 self._set_attributes(config)
119 return config
120 except yaml.YAMLError, ex:
121 logger.debug("Error loading YAML file %s" % hwpack, ex)
122 raise BoardConfigException("Error reading Android hwpack %s"
123 % hwpack)
124
125 def _set_attributes(self, config):
126 """Initialize the class attributes with the values read from the
127 Android hardware pack configuration file.
128
129 :param config: The config read from the Android hwpack.
130 """
131 for name, value in config.iteritems():
132 if hasattr(self, name):
133 setattr(self, name, value)
134 else:
135 logger.warning("Attribute '%s' does not belong to this "
136 "instance of '%s'." % (name, self.__class__))
137
138 def _get_bootargs(self, consoles):
52 """Get the bootargs for this board.139 """Get the bootargs for this board.
53140
54 In general subclasses should not have to override this.141 In general subclasses should not have to override this.
55 """142 """
56 boot_args_options = 'rootwait ro'143 boot_args_options = 'rootwait ro'
57 if cls.extra_boot_args_options is not None:144 if self.extra_boot_args_options:
58 boot_args_options += ' %s' % cls.extra_boot_args_options145 boot_args_options += ' %s' % self.extra_boot_args_options
59 boot_args_options += ' %s' % cls.android_specific_args146 boot_args_options += ' %s' % self.android_specific_args
60 serial_opts = cls._extra_serial_opts147 serial_opts = self.extra_serial_options
61 for console in consoles:148 for console in consoles:
62 serial_opts += ' console=%s' % console149 serial_opts += ' console=%s' % console
63150
@@ -69,34 +156,32 @@
69 "%(boot_args_options)s"156 "%(boot_args_options)s"
70 % replacements)157 % replacements)
71158
72 @classmethod159 def _get_boot_env(self, consoles):
73 def _get_boot_env(cls, consoles):
74 """Get the boot environment for this board.160 """Get the boot environment for this board.
75161
76 In general subclasses should not have to override this.162 In general subclasses should not have to override this.
77 """163 """
78 boot_env = {}164 boot_env = {}
79 boot_env["bootargs"] = cls._get_bootargs(consoles)165 boot_env["bootargs"] = self._get_bootargs(consoles)
80 initrd = False166 initrd = False
81 if cls.initrd_addr:167 if self.initrd_addr:
82 initrd = True168 initrd = True
83 # On Android, the DTB file is always built as part of the kernel it169 # On Android, the DTB file is always built as part of the kernel it
84 # comes from - and lives in the same directory in the boot tarball, so170 # comes from - and lives in the same directory in the boot tarball, so
85 # here we don't need to pass the whole path to it.171 # here we don't need to pass the whole path to it.
86 boot_env["bootcmd"] = cls._get_bootcmd(initrd, cls.dtb_name)172 boot_env["bootcmd"] = self._get_bootcmd(initrd, self.dtb_name)
87 boot_env["initrd_high"] = cls.initrd_high173 boot_env["initrd_high"] = self.initrd_high
88 boot_env["fdt_high"] = cls.fdt_high174 boot_env["fdt_high"] = self.fdt_high
89 return boot_env175 return boot_env
90176
91 @classmethod177 def populate_boot_script(self, boot_partition, boot_disk, consoles):
92 def populate_boot_script(cls, boot_partition, boot_disk, consoles):
93 cmd_runner.run(['mkdir', '-p', boot_disk]).wait()178 cmd_runner.run(['mkdir', '-p', boot_disk]).wait()
94 # TODO: Use partition_mounted() here to make sure the partition is179 # TODO: Use partition_mounted() here to make sure the partition is
95 # always umounted after we're done.180 # always umounted after we're done.
96 cmd_runner.run(['mount', boot_partition, boot_disk],181 cmd_runner.run(['mount', boot_partition, boot_disk],
97 as_root=True).wait()182 as_root=True).wait()
98183
99 boot_env = cls._get_boot_env(consoles)184 boot_env = self._get_boot_env(consoles)
100 cmdline_filepath = os.path.join(boot_disk, "cmdline")185 cmdline_filepath = os.path.join(boot_disk, "cmdline")
101 cmdline_file = open(cmdline_filepath, 'r')186 cmdline_file = open(cmdline_filepath, 'r')
102 android_kernel_cmdline = cmdline_file.read()187 android_kernel_cmdline = cmdline_file.read()
@@ -105,7 +190,7 @@
105 cmdline_file.close()190 cmdline_file.close()
106191
107 boot_dir = boot_disk192 boot_dir = boot_disk
108 boot_script_path = os.path.join(boot_dir, cls.boot_script)193 boot_script_path = os.path.join(boot_dir, self.boot_script)
109 make_boot_script(boot_env, boot_script_path)194 make_boot_script(boot_env, boot_script_path)
110195
111 cmd_runner.run(['sync']).wait()196 cmd_runner.run(['sync']).wait()
@@ -114,25 +199,13 @@
114 except cmd_runner.SubcommandNonZeroReturnValue:199 except cmd_runner.SubcommandNonZeroReturnValue:
115 pass200 pass
116201
117 @classmethod202 def get_sfdisk_cmd(self, should_align_boot_part=False,
118 def get_sfdisk_cmd(cls, should_align_boot_part=False,
119 start_addr=0, extra_part=False):203 start_addr=0, extra_part=False):
120 if cls.fat_size == 32:204 if self.fat_size == 32:
121 partition_type = '0x0C'205 partition_type = '0x0C'
122 else:206 else:
123 partition_type = '0x0E'207 partition_type = '0x0E'
124208
125 BOOT_MIN_SIZE_S = align_up(
126 128 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
127 SYSTEM_MIN_SIZE_S = align_up(
128 512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
129 CACHE_MIN_SIZE_S = align_up(
130 256 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
131 USERDATA_MIN_SIZE_S = align_up(
132 512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
133 SDCARD_MIN_SIZE_S = align_up(
134 512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
135
136 # align on sector 63 for compatibility with broken versions of x-loader209 # align on sector 63 for compatibility with broken versions of x-loader
137 # unless align_boot_part is set210 # unless align_boot_part is set
138 boot_align = 63211 boot_align = 63
@@ -174,86 +247,48 @@
174 cache_start, _cache_len, userdata_start, userdata_start,247 cache_start, _cache_len, userdata_start, userdata_start,
175 _userdata_len, sdcard_start)248 _userdata_len, sdcard_start)
176249
177 @classmethod250 def populate_raw_partition(self, media, boot_dir):
178 def populate_raw_partition(cls, media, boot_dir):251 super(AndroidBoardConfig, self).populate_raw_partition(media, boot_dir)
179 super(AndroidBoardConfig, cls).populate_raw_partition(media, boot_dir)
180252
181 @classmethod253 def install_boot_loader(self, boot_partition, boot_device_or_file):
182 def install_boot_loader(cls, boot_partition, boot_device_or_file):
183 pass254 pass
184255
185256
186class AndroidOmapConfig(AndroidBoardConfig):257class AndroidOmapConfig(AndroidBoardConfig):
187 dtb_name = None258 """Placeholder class for OMAP configuration inheritance."""
188259
189260
190class AndroidBeagleConfig(AndroidOmapConfig, BeagleConfig):261class AndroidBeagleConfig(AndroidBoardConfig, BeagleConfig):
191 _extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'262 """Placeholder class for Beagle configuration inheritance."""
192 android_specific_args = 'init=/init androidboot.console=ttyO2'263
193 dtb_name = None264
194265class AndroidPandaConfig(AndroidBoardConfig, PandaConfig):
195266 """Placeholder class for Panda configuration inheritance."""
196class AndroidPandaConfig(AndroidOmapConfig, PandaConfig):
197 bootloader_flavor = 'omap4_panda'
198 dtb_addr = '0x815f0000'
199 dtb_name = 'board.dtb'
200 _extra_serial_opts = 'console=ttyO2,115200n8'
201 extra_boot_args_options = (
202 'earlyprintk fixrtc nocompcache vram=48M '
203 'omapfb.vram=0:24M,1:24M mem=456M@0x80000000 mem=512M@0xA0000000')
204 android_specific_args = 'init=/init androidboot.console=ttyO2'
205267
206268
207class AndroidSnowballSdConfig(AndroidBoardConfig, SnowballSdConfig):269class AndroidSnowballSdConfig(AndroidBoardConfig, SnowballSdConfig):
208 boot_script = 'boot.scr'270 """Placeholder class for Snowball SD configuration inheritance."""
209 fdt_high = '0x05000000'
210 initrd_addr = '0x05000000'
211 initrd_high = '0x06000000'
212 extra_boot_args_options = (
213 'earlyprintk mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
214 'mem=22M@360M mem_issw=1M@383M mem=640M@384M vmalloc=500M')
215 _extra_serial_opts = 'console=ttyAMA2,115200n8'
216 android_specific_args = 'init=/init androidboot.console=ttyAMA2'
217 dtb_name = 'board.dtb'
218 dtb_addr = '0x8000000'
219271
220272
221class AndroidSnowballEmmcConfig(AndroidBoardConfig, SnowballEmmcConfig):273class AndroidSnowballEmmcConfig(AndroidBoardConfig, SnowballEmmcConfig):
222 boot_script = 'boot.scr'274 """Snowball EMMC configuration inheritance."""
223 fdt_high = '0x05000000'275
224 initrd_addr = '0x05000000'276 def get_sfdisk_cmd(self, should_align_boot_part=False):
225 initrd_high = '0x06000000'
226 extra_boot_args_options = (
227 'earlyprintk mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
228 'mem=22M@360M mem_issw=1M@383M mem=640M@384M vmalloc=500M')
229 _extra_serial_opts = 'console=ttyAMA2,115200n8'
230 android_specific_args = 'init=/init androidboot.console=ttyAMA2'
231 mmc_option = '0:2'
232 dtb_name = 'board.dtb'
233 dtb_addr = '0x8000000'
234
235 @classmethod
236 def get_sfdisk_cmd(cls, should_align_boot_part=False):
237
238 LOADER_MIN_SIZE_S = align_up(
239 1 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
240
241 loader_start, loader_end, loader_len = align_partition(277 loader_start, loader_end, loader_len = align_partition(
242 SnowballEmmcConfig.SNOWBALL_LOADER_START_S,278 SnowballEmmcConfig.SNOWBALL_LOADER_START_S,
243 LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)279 LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
244280
245 command = super(AndroidSnowballEmmcConfig, cls).get_sfdisk_cmd(281 command = super(AndroidSnowballEmmcConfig, self).get_sfdisk_cmd(
246 should_align_boot_part=True, start_addr=loader_end,282 should_align_boot_part=True, start_addr=loader_end,
247 extra_part=True)283 extra_part=True)
248284
249 return '%s,%s,0xDA\n%s' % (285 return '%s,%s,0xDA\n%s' % (
250 loader_start, loader_len, command)286 loader_start, loader_len, command)
251287
252 @classmethod288 def populate_raw_partition(self, media, boot_dir):
253 def populate_raw_partition(cls, media, boot_dir):
254 # To avoid adding a Snowball specific command line option, we assume289 # To avoid adding a Snowball specific command line option, we assume
255 # that the user already has unpacked the startfiles to ./startupfiles290 # that the user already has unpacked the startfiles to ./startupfiles
256 config_files_dir = cls.snowball_config(boot_dir)291 config_files_dir = self.snowball_config(boot_dir)
257 assert os.path.exists(config_files_dir), (292 assert os.path.exists(config_files_dir), (
258 "You need to unpack the Snowball startupfiles to the directory "293 "You need to unpack the Snowball startupfiles to the directory "
259 "'startupfiles' in your current working directory. See "294 "'startupfiles' in your current working directory. See "
@@ -264,72 +299,85 @@
264 for boot_file in boot_files:299 for boot_file in boot_files:
265 cmd_runner.run(['cp', os.path.join(boot_dir, 'boot', boot_file),300 cmd_runner.run(['cp', os.path.join(boot_dir, 'boot', boot_file),
266 config_files_dir], as_root=True).wait()301 config_files_dir], as_root=True).wait()
267 super(AndroidSnowballEmmcConfig, cls).populate_raw_partition(302 super(AndroidSnowballEmmcConfig, self).populate_raw_partition(
268 media, boot_dir)303 media, boot_dir)
269304
270 @classmethod305 def snowball_config(self, chroot_dir):
271 def snowball_config(cls, chroot_dir):
272 # The user is expected to have unpacked the startupfiles to this subdir306 # The user is expected to have unpacked the startupfiles to this subdir
273 # of their working dir.307 # of their working dir.
274 return os.path.join('.', 'startupfiles')308 return os.path.join('.', 'startupfiles')
275309
276 @classproperty310 @property
277 def delete_startupfiles(cls):311 def delete_startupfiles(self):
278 # The startupfiles will have been unpacked to the user's working dir312 # The startupfiles will have been unpacked to the user's working dir
279 # and should not be deleted after they have been installed.313 # and should not be deleted after they have been installed.
280 return False314 return False
281315
282316
283class AndroidMx53LoCoConfig(AndroidBoardConfig, Mx53LoCoConfig):317class AndroidMx53LoCoConfig(AndroidBoardConfig, Mx53LoCoConfig):
284 extra_boot_args_options = (318 """Mx53LoCo configuration inheritance."""
285 'earlyprintk rootdelay=1 fixrtc nocompcache di1_primary tve')319
286 _extra_serial_opts = 'console=%s,115200n8' % (320 def _get_extra_serial_options(self):
287 Mx53LoCoConfig.serial_tty)321 serial_opts = self._extra_serial_options
288 android_specific_args = 'init=/init androidboot.console=%s' % (322 if serial_opts:
289 Mx53LoCoConfig.serial_tty)323 if isinstance(serial_opts, list):
290 dtb_name = None324 serial_opts = ' '.join(serial_opts)
291325 if self._check_placeholder_presence(serial_opts, '%s'):
292 @classmethod326 serial_opts = serial_opts % self.serial_tty
293 def get_sfdisk_cmd(cls, should_align_boot_part=False):327 return serial_opts
328
329 def _set_extra_serial_options(self, value):
330 self._extra_serial_options = value
331
332 extra_serial_options = property(_get_extra_serial_options,
333 _set_extra_serial_options)
334
335 def _get_android_specific_args(self):
336 android_args = self._android_specific_args
337 if android_args:
338 if isinstance(android_args, list):
339 android_args = ' '.join(android_args)
340 if self._check_placeholder_presence(android_args, '%s'):
341 android_args = android_args % self.serial_tty
342 return android_args
343
344 def _set_android_specific_args(self, value):
345 self._android_specific_args = value
346
347 android_specific_args = property(_get_android_specific_args,
348 _set_android_specific_args)
349
350 def get_sfdisk_cmd(self, should_align_boot_part=False):
294 loader_start, loader_end, loader_len = align_partition(351 loader_start, loader_end, loader_len = align_partition(
295 1, cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)352 1, self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
296353
297 command = super(AndroidMx53LoCoConfig, cls).get_sfdisk_cmd(354 command = super(AndroidMx53LoCoConfig, self).get_sfdisk_cmd(
298 should_align_boot_part=True, start_addr=loader_end,355 should_align_boot_part=True, start_addr=loader_end,
299 extra_part=True)356 extra_part=True)
300357
301 return '%s,%s,0xDA\n%s' % (358 return '%s,%s,0xDA\n%s' % (
302 loader_start, loader_len, command)359 loader_start, loader_len, command)
303360
304 @classmethod361 def install_boot_loader(self, boot_partition, boot_device_or_file):
305 def install_boot_loader(cls, boot_partition, boot_device_or_file):
306 install_mx5_boot_loader(362 install_mx5_boot_loader(
307 os.path.join(boot_device_or_file, "u-boot.imx"),363 os.path.join(boot_device_or_file, "u-boot.imx"),
308 boot_partition, cls.LOADER_MIN_SIZE_S)364 boot_partition, self.LOADER_MIN_SIZE_S)
309365
310366
311class AndroidMx6QSabreliteConfig(AndroidMx53LoCoConfig):367class AndroidMx6QSabreliteConfig(AndroidMx53LoCoConfig):
312 bootloader_flavor = 'mx6qsabrelite'368 """Placeholder class for Mx6Q Sabrelite configuration inheritance."""
313 kernel_addr = '0x10000000'
314 initrd_addr = '0x12000000'
315 load_addr = '0x10008000'
316 dtb_addr = '0x11ff0000'
317 dtb_name = 'board.dtb'
318369
319370
320class AndroidSamsungConfig(AndroidBoardConfig):371class AndroidSamsungConfig(AndroidBoardConfig):
321 dtb_name = None372 def get_sfdisk_cmd(self, should_align_boot_part=False):
322
323 @classmethod
324 def get_sfdisk_cmd(cls, should_align_boot_part=False):
325 loaders_min_len = (373 loaders_min_len = (
326 cls.SAMSUNG_V310_BL2_START + cls.SAMSUNG_V310_BL2_LEN -374 self.samsung_v310_bl2_start + self.samsung_v310_bl2_len -
327 cls.SAMSUNG_V310_BL1_START)375 self.samsung_v310_bl1_start)
328376
329 loader_start, loader_end, loader_len = align_partition(377 loader_start, loader_end, loader_len = align_partition(
330 1, loaders_min_len, 1, PART_ALIGN_S)378 1, loaders_min_len, 1, PART_ALIGN_S)
331379
332 command = super(AndroidSamsungConfig, cls).get_sfdisk_cmd(380 command = super(AndroidSamsungConfig, self).get_sfdisk_cmd(
333 should_align_boot_part=False, start_addr=loader_end,381 should_align_boot_part=False, start_addr=loader_end,
334 extra_part=True)382 extra_part=True)
335383
@@ -338,33 +386,47 @@
338386
339387
340class AndroidSMDKV310Config(AndroidSamsungConfig, SMDKV310Config):388class AndroidSMDKV310Config(AndroidSamsungConfig, SMDKV310Config):
341 _extra_serial_opts = 'console=tty0 console=ttySAC1,115200n8'389 """Placeholder class for SMDKV310 configuration inheritance."""
342 android_specific_args = 'init=/init androidboot.console=ttySAC1'
343 dtb_name = None
344390
345391
346class AndroidOrigenConfig(AndroidSamsungConfig, OrigenConfig):392class AndroidOrigenConfig(AndroidSamsungConfig, OrigenConfig):
347 _extra_serial_opts = 'console=tty0 console=ttySAC2,115200n8'393 """Placeholder class for Origen configuration inheritance."""
348 android_specific_args = 'init=/init androidboot.console=ttySAC2'
349 dtb_name = None
350394
351395
352class AndroidVexpressConfig(AndroidBoardConfig, VexpressConfig):396class AndroidVexpressConfig(AndroidBoardConfig, VexpressConfig):
353 _extra_serial_opts = 'console=tty0 console=ttyAMA0,38400n8'397 """Placeholder class for Vexpress configuration inheritance."""
354 android_specific_args = 'init=/init androidboot.console=ttyAMA0'398
355 dtb_name = None399
356400# This dictionary is composed as follows:
357401# <device_name>: <class>
402# The <device_name> is the command line argument passed to l-a-m-c, the
403# <class> is the corresponding config class in this file (not the instance).
404# If a new device does not have special needs, it is possible to use the
405# general AndroidBoardConfig class.
358android_board_configs = {406android_board_configs = {
359 'beagle': AndroidBeagleConfig,407 'beagle': AndroidBeagleConfig,
360 'panda': AndroidPandaConfig,408 'iMX53': AndroidMx53LoCoConfig,
361 'snowball_sd': AndroidSnowballSdConfig,
362 'snowball_emmc': AndroidSnowballEmmcConfig,
363 'smdkv310': AndroidSMDKV310Config,
364 'mx53loco': AndroidMx53LoCoConfig,409 'mx53loco': AndroidMx53LoCoConfig,
365 'iMX53': AndroidMx53LoCoConfig,
366 'mx6qsabrelite': AndroidMx6QSabreliteConfig,410 'mx6qsabrelite': AndroidMx6QSabreliteConfig,
367 'origen': AndroidOrigenConfig,411 'origen': AndroidOrigenConfig,
412 'panda': AndroidPandaConfig,
413 'smdkv310': AndroidSMDKV310Config,
414 'snowball_emmc': AndroidSnowballEmmcConfig,
415 'snowball_sd': AndroidSnowballSdConfig,
368 'vexpress': AndroidVexpressConfig,416 'vexpress': AndroidVexpressConfig,
369 'vexpress-a9': AndroidVexpressConfig,417 'vexpress-a9': AndroidVexpressConfig,
370 }418 }
419
420
421def get_board_config(board):
422 """Get the board configuration for the specified board.
423
424 :param board: The name of the board to get the configuration of.
425 :type board: str
426 """
427 clazz = android_board_configs.get(board, None)
428 if clazz:
429 return clazz()
430 else:
431 raise BoardConfigException("Board name '%s' has no configuration "
432 "available." % board)
371433
=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py 2012-10-22 06:57:20 +0000
+++ linaro_image_tools/media_create/boards.py 2012-11-20 10:49:03 +0000
@@ -24,28 +24,58 @@
24board_configs at the bottom of this file.24board_configs at the bottom of this file.
25"""25"""
2626
27from binascii import crc32
28from parted import Device
27import atexit29import atexit
28import glob30import glob
31import logging
29import os32import os
30import re33import re
34import string
35import struct
31import tempfile36import tempfile
32import struct
33from binascii import crc32
34import tarfile
35import ConfigParser
36import shutil
37import string
38import logging
39from linaro_image_tools.hwpack.config import Config
40from linaro_image_tools.hwpack.builder import PackageUnpacker
41
42from parted import Device
4337
44from linaro_image_tools import cmd_runner38from linaro_image_tools import cmd_runner
4539
46from linaro_image_tools.media_create.partitions import (40from linaro_image_tools.media_create.partitions import (
47 partition_mounted, SECTOR_SIZE, register_loopback)41 SECTOR_SIZE,
48from StringIO import StringIO42 partition_mounted,
43 register_loopback,
44 )
45
46from linaro_image_tools.hwpack.handler import HardwarepackHandler
47
48from linaro_image_tools.hwpack.hwpack_fields import (
49 BOOTFS,
50 BOOTFS16,
51 BOOT_MIN_SIZE_FIELD,
52 BOOT_SCRIPT_FIELD,
53 DTB_ADDR_FIELD,
54 DTB_FILES_FIELD,
55 DTB_FILE_FIELD,
56 ENV_DD_FIELD,
57 EXTRA_BOOT_OPTIONS_FIELD,
58 EXTRA_SERIAL_OPTIONS_FIELD,
59 INITRD_ADDR_FIELD,
60 KERNEL_ADDR_FIELD,
61 LOADER_MIN_SIZE_FIELD,
62 LOADER_START_FIELD,
63 LOAD_ADDR_FIELD,
64 MMC_ID_FIELD,
65 PARTITION_LAYOUT_FIELD,
66 RESERVED_BOOTFS,
67 ROOT_MIN_SIZE_FIELD,
68 SAMSUNG_BL1_LEN_FIELD,
69 SAMSUNG_BL1_START_FIELD,
70 SAMSUNG_BL2_LEN_FIELD,
71 SAMSUNG_ENV_LEN_FIELD,
72 SERIAL_TTY_FIELD,
73 SNOWBALL_STARTUP_FILES_CONFIG_FIELD,
74 SPL_DD_FIELD,
75 SPL_IN_BOOT_PART_FIELD,
76 WIRED_INTERFACES_FIELD,
77 WIRELESS_INTERFACES_FIELD,
78 )
4979
50logger = logging.getLogger(__name__)80logger = logging.getLogger(__name__)
5181
@@ -106,580 +136,336 @@
106 cmd_runner.run(cmd, as_root=True).wait()136 cmd_runner.run(cmd, as_root=True).wait()
107137
108138
109class classproperty(object):
110 """A descriptor that provides @property behavior on class methods."""
111 def __init__(self, getter):
112 self.getter = getter
113
114 def __get__(self, instance, cls):
115 return self.getter(cls)
116
117
118class HardwarepackHandler(object):
119 FORMAT_1 = '1.0'
120 FORMAT_2 = '2.0'
121 FORMAT_3 = '3.0'
122 FORMAT_MIXED = '1.0and2.0'
123 metadata_filename = 'metadata'
124 format_filename = 'FORMAT'
125 main_section = 'main'
126 hwpack_tarfiles = []
127 tempdir = None
128
129 def __init__(self, hwpacks, bootloader=None, board=None):
130 self.hwpacks = hwpacks
131 self.hwpack_tarfiles = []
132 self.bootloader = bootloader
133 self.board = board
134 self.tempdirs = {}
135 # Used to store the config created from the metadata.
136 self.config = None
137
138 class FakeSecHead(object):
139 """ Add a fake section header to the metadata file.
140
141 This is done so we can use ConfigParser to parse the file.
142 """
143 def __init__(self, fp):
144 self.fp = fp
145 self.sechead = '[%s]\n' % HardwarepackHandler.main_section
146
147 def readline(self):
148 if self.sechead:
149 try:
150 return self.sechead
151 finally:
152 self.sechead = None
153 else:
154 return self.fp.readline()
155
156 def __enter__(self):
157 self.tempdir = tempfile.mkdtemp()
158 for hwpack in self.hwpacks:
159 hwpack_tarfile = tarfile.open(hwpack, mode='r:gz')
160 self.hwpack_tarfiles.append(hwpack_tarfile)
161 return self
162
163 def __exit__(self, type, value, traceback):
164 for hwpack_tarfile in self.hwpack_tarfiles:
165 if hwpack_tarfile is not None:
166 hwpack_tarfile.close()
167 self.hwpack_tarfiles = []
168 if self.tempdir is not None and os.path.exists(self.tempdir):
169 shutil.rmtree(self.tempdir)
170
171 for name in self.tempdirs:
172 tempdir = self.tempdirs[name]
173 if tempdir is not None and os.path.exists(tempdir):
174 shutil.rmtree(tempdir)
175
176 def _get_config_from_metadata(self, metadata):
177 """
178 Retrieves a Config object associated with the metadata.
179
180 :param metadata: The metadata to parse.
181 :return: A Config instance.
182 """
183 if not self.config:
184 lines = metadata.readlines()
185 if re.search("=", lines[0]) and not re.search(":", lines[0]):
186 # Probably V2 hardware pack without [hwpack] on the first line
187 lines = ["[hwpack]\n"] + lines
188 self.config = Config(StringIO("".join(lines)))
189 self.config.set_board(self.board)
190 self.config.set_bootloader(self.bootloader)
191 return self.config
192
193 def get_field(self, field, return_keys=False):
194 data = None
195 hwpack_with_data = None
196 keys = None
197 for hwpack_tarfile in self.hwpack_tarfiles:
198 metadata = hwpack_tarfile.extractfile(self.metadata_filename)
199 parser = self._get_config_from_metadata(metadata)
200 try:
201 new_data = parser.get_option(field)
202 if new_data is not None:
203 assert data is None, "The metadata field '%s' is set to " \
204 "'%s' and new value '%s' is found" % (field, data,
205 new_data)
206 data = new_data
207 hwpack_with_data = hwpack_tarfile
208 if return_keys:
209 keys = parser.get_last_used_keys()
210 except ConfigParser.NoOptionError:
211 continue
212
213 if return_keys:
214 return data, hwpack_with_data, keys
215 return data, hwpack_with_data
216
217 def get_format(self):
218 format = None
219 supported_formats = [self.FORMAT_1, self.FORMAT_2, self.FORMAT_3]
220 for hwpack_tarfile in self.hwpack_tarfiles:
221 format_file = hwpack_tarfile.extractfile(self.format_filename)
222 format_string = format_file.read().strip()
223 if not format_string in supported_formats:
224 raise AssertionError(
225 "Format version '%s' is not supported." % format_string)
226 if format is None:
227 format = format_string
228 elif format != format_string:
229 return self.FORMAT_MIXED
230 return format
231
232 def get_file(self, file_alias):
233 """Get file(s) from a hwpack.
234 :param file_alias: Property name (not field name) which contains
235 file reference(s)
236 :return: path to a file or list of paths to files
237 """
238 file_names, hwpack_tarfile, keys = self.get_field(file_alias,
239 return_keys=True)
240 if not file_names:
241 return file_names
242 single = False
243 if not isinstance(file_names, list):
244 single = True
245 file_names = [file_names]
246 out_files = []
247
248 # Depending on if board and/or bootloader were used to look up the
249 # file we are getting, we need to prepend those names to the path
250 # to get the correct extracted file from the hardware pack.
251 config_names = [("board", "boards"), ("bootloader", "bootloaders")]
252 base_path = ""
253 if keys:
254 # If keys is non-empty, we have a V3 config option that was
255 # modified by the bootloader and/or boot option...
256 for name, key in config_names:
257 if self.get_field(name):
258 value = self.get_field(name)[0]
259 if keys[0] == key:
260 base_path = os.path.join(base_path, value)
261 keys = keys[1:]
262
263 for f in file_names:
264 # Check that the base path is needed. If the file doesn't exist,
265 # try without it (this provides fallback to V2 style directory
266 # layouts with a V3 config).
267 path_inc_board_and_bootloader = os.path.join(base_path, f)
268 if path_inc_board_and_bootloader in hwpack_tarfile.getnames():
269 f = path_inc_board_and_bootloader
270 hwpack_tarfile.extract(f, self.tempdir)
271 f = os.path.join(self.tempdir, f)
272 out_files.append(f)
273 if single:
274 return out_files[0]
275 return out_files
276
277 def list_packages(self):
278 """Return list of (package names, TarFile object containing them)"""
279 packages = []
280 for tf in self.hwpack_tarfiles:
281 for name in tf.getnames():
282 if name.startswith("pkgs/") and name.endswith(".deb"):
283 packages.append((tf, name))
284 return packages
285
286 def find_package_for(self, name, version=None, revision=None,
287 architecture=None):
288 """Find a package that matches the name, version, rev and arch given.
289
290 Packages are named according to the debian specification:
291 http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html
292 <name>_<Version>-<DebianRevisionNumber>_<DebianArchitecture>.deb
293 DebianRevisionNumber seems to be optional.
294 Use this spec to return a package matching the requirements given.
295 """
296 for tar_file, package in self.list_packages():
297 file_name = os.path.basename(package)
298 dpkg_chunks = re.search("^(.+)_(.+)_(.+)\.deb$",
299 file_name)
300 assert dpkg_chunks, "Could not split package file name into"\
301 "<name>_<Version>_<DebianArchitecture>.deb"
302
303 pkg_name = dpkg_chunks.group(1)
304 pkg_version = dpkg_chunks.group(2)
305 pkg_architecture = dpkg_chunks.group(3)
306
307 ver_chunks = re.search("^(.+)-(.+)$", pkg_version)
308 if ver_chunks:
309 pkg_version = ver_chunks.group(1)
310 pkg_revision = ver_chunks.group(2)
311 else:
312 pkg_revision = None
313
314 if name != pkg_name:
315 continue
316 if version != None and str(version) != pkg_version:
317 continue
318 if revision != None and str(revision) != pkg_revision:
319 continue
320 if (architecture != None and
321 str(architecture) != pkg_architecture):
322 continue
323
324 # Got a matching package - return its path inside the tarball
325 return tar_file, package
326
327 # Failed to find a matching package - return None
328 return None
329
330 def get_file_from_package(self, file_path, package_name,
331 package_version=None, package_revision=None,
332 package_architecture=None):
333 """Extract named file from package specified by name, ver, rev, arch.
334
335 File is extracted from the package matching the given specification
336 to a temporary directory. The absolute path to the extracted file is
337 returned.
338 """
339
340 package_info = self.find_package_for(package_name,
341 package_version,
342 package_revision,
343 package_architecture)
344 if package_info is None:
345 return None
346 tar_file, package = package_info
347
348 # Avoid unpacking hardware pack more than once by assigning each one
349 # its own tempdir to unpack into.
350 # TODO: update logic that uses self.tempdir so we can get rid of this
351 # by sharing nicely.
352 if not package in self.tempdirs:
353 self.tempdirs[package] = tempfile.mkdtemp()
354 tempdir = self.tempdirs[package]
355
356 # We extract everything in the hardware pack so we don't have to worry
357 # about chasing links (extract a link, find where it points to, extract
358 # that...). This is slower, but more reliable.
359 tar_file.extractall(tempdir)
360 package_path = os.path.join(tempdir, package)
361
362 with PackageUnpacker() as self.package_unpacker:
363 extracted_file = self.package_unpacker.get_file(package_path,
364 file_path)
365 after_tmp = re.sub(self.package_unpacker.tempdir, "",
366 extracted_file).lstrip("/\\")
367 extract_dir = os.path.join(tempdir, "extracted",
368 os.path.dirname(after_tmp))
369 os.makedirs(extract_dir)
370 shutil.move(extracted_file, extract_dir)
371 extracted_file = os.path.join(extract_dir,
372 os.path.basename(extracted_file))
373 return extracted_file
374
375
376class BoardConfig(object):139class BoardConfig(object):
377 board = None
378 """The configuration used when building an image for a board."""140 """The configuration used when building an image for a board."""
379 hwpack_format = None141
380 # These attributes may not need to be redefined on some subclasses.
381 bootloader_flavor = None
382 # whether to copy u-boot to the boot partition
383 bootloader_file_in_boot_part = False
384 bootloader_dd = False
385 spl_in_boot_part = False
386 spl_dd = False
387 env_dd = False
388 fatload_command = 'fatload'
389 mmc_option = '0:1'
390 mmc_device_id = 0
391 mmc_part_offset = 0
392 uimage_path = ''
393 fat_size = 32
394 extra_serial_opts = ''
395 _extra_serial_opts = ''
396 _live_serial_opts = ''
397 extra_boot_args_options = None
398 supports_writing_to_mmc = True
399 LOADER_MIN_SIZE_S = align_up(1 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE142 LOADER_MIN_SIZE_S = align_up(1 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE
400 BOOT_MIN_SIZE_S = align_up(50 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE143 BOOT_MIN_SIZE_S = align_up(50 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE
401 ROOT_MIN_SIZE_S = align_up(50 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE144 ROOT_MIN_SIZE_S = align_up(50 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE
402145
403 # These attributes must be defined on all subclasses for backwards146 def __init__(self):
404 # compatibility with hwpacks v1 format. Hwpacks v2 format allows these to147 super(BoardConfig, self).__init__()
405 # be specified in the hwpack metadata.148 # XXX: when killing v1 hwpack, we might rename these two without the
406 kernel_addr = None149 # leading underscore. It is done in this way since sublcasses use
407 initrd_addr = None150 # placeholders in the string for dinamically change values. But this
408 initrd_high = '0xffffffff'151 # is done only for hwpack v1.
409 load_addr = None152 self._extra_serial_opts = ''
410 dtb_addr = None153 self._live_serial_opts = ''
411 dtb_name = None154 self.board = None
412 dtb_file = None155 self.boot_script = None
413 fdt_high = '0xffffffff'156 self.bootloader_dd = False
414 kernel_flavors = None157 self.bootloader_file_in_boot_part = False
415 boot_script = None158 self.bootloader_flavor = None
416 serial_tty = None159 self.dtb_addr = None
417 wired_interfaces = None160 self.dtb_file = None
418 wireless_interfaces = None161 self.dtb_files = None
419 mmc_id = None162 self.dtb_name = None
420 vmlinuz = None163 self.env_dd = False
421 initrd = None164 self.extra_boot_args_options = None
422 partition_layout = None165 self.fat_size = 32
423 LOADER_START_S = 1166 self.fatload_command = 'fatload'
424167 self.fdt_high = '0xffffffff'
425 # Support for dtb_files as per hwpack v3 format.168 self.hardwarepack_handler = None
426 dtb_files = None169 self.hwpack_format = None
427170 self.initrd_addr = None
428 # Samsung v310 implementation notes and terminology171 self.initrd_high = '0xffffffff'
429 #172 self.kernel_addr = None
430 # * BL0, BL1 etc. are the various bootloaders in order of execution173 self.kernel_flavors = None
431 # * BL0 is the first stage bootloader, located in ROM; it loads a 32s174 self.load_addr = None
432 # long BL1 from MMC offset +1s and runs it175 self.loader_start_s = 1
433 # * BL1 is the secondary program loader (SPL), a small (< 14k) version176 self.mmc_device_id = 0
434 # of U-Boot with a checksum; it inits DRAM and loads a 1024s long BL2177 self.mmc_id = None
435 # to DRAM from MMC offset +65s178 self.mmc_option = '0:1'
436 # * BL2 is U-Boot; it loads its 32s (16 KiB) long environment from MMC179 self.mmc_part_offset = 0
437 # offset +33s which tells it to load a boot.scr from the first FAT180 self.partition_layout = None
438 # partition of the MMC181 self.serial_tty = None
439 #182 self.spl_dd = False
440 # Layout:183 self.spl_in_boot_part = False
441 # +0s: part table / MBR, 1s long184 self.supports_writing_to_mmc = True
442 # +1s: BL1/SPL, 32s long185 self.uimage_path = ''
443 # +33s: U-Boot environment, 32s long186 self.wired_interfaces = None
444 # +65s: U-Boot, 1024s long187 self.wireless_interfaces = None
445 # >= +1089s: FAT partition with boot script (boot.scr), kernel (uImage)188 # Samsung v310 implementation notes and terminology
446 # and initrd (uInitrd)189 #
447 SAMSUNG_V310_BL1_START = 1190 # * BL0, BL1 etc. are the various bootloaders in order of execution
448 SAMSUNG_V310_BL1_LEN = 32191 # * BL0 is the first stage bootloader, located in ROM; it loads a 32s
449 SAMSUNG_V310_ENV_START = SAMSUNG_V310_BL1_START + SAMSUNG_V310_BL1_LEN192 # long BL1 from MMC offset +1s and runs it
450 SAMSUNG_V310_ENV_LEN = 32193 # * BL1 is the secondary program loader (SPL), a small (< 14k) version
451 assert SAMSUNG_V310_ENV_START == 33, (194 # of U-Boot with a checksum; it inits DRAM and loads a 1024s long BL2
452 "BL1 expects u-boot environment at +33s")195 # to DRAM from MMC offset +65s
453 assert SAMSUNG_V310_ENV_LEN * SECTOR_SIZE == 16 * 1024, (196 # * BL2 is U-Boot; it loads its 32s (16 KiB) long environment from MMC
454 "BL1 expects u-boot environment to be 16 KiB")197 # offset +33s which tells it to load a boot.scr from the first FAT
455 SAMSUNG_V310_BL2_START = SAMSUNG_V310_ENV_START + SAMSUNG_V310_ENV_LEN198 # partition of the MMC
456 SAMSUNG_V310_BL2_LEN = 1024199 #
457 assert SAMSUNG_V310_BL2_LEN * SECTOR_SIZE == 512 * 1024, (200 # Layout:
458 "BL1 expects BL2 (u-boot) to be 512 KiB")201 # +0s: part table / MBR, 1s long
459202 # +1s: BL1/SPL, 32s long
460 hardwarepack_handler = None203 # +33s: U-Boot environment, 32s long
461204 # +65s: U-Boot, 1024s long
462 @classmethod205 # >= +1089s: FAT partition with boot script (boot.scr), kernel (uImage)
463 def get_metadata_field(cls, field_name):206 # and initrd (uInitrd)
207 self.samsung_v310_bl1_start = 1
208 self.samsung_v310_bl1_len = 32
209 self._samsung_v310_env_start = (self.samsung_v310_bl1_start +
210 self.samsung_v310_bl1_len)
211 self._samsung_v310_env_len = 32
212 self._samsung_v310_bl2_start = (self.samsung_v310_env_start +
213 self.samsung_v310_env_len)
214 self._samsung_v310_bl2_len = 1024
215 # XXX: attributes that are not listed in hwpackV3, should be removed?
216 self.vmlinuz = None
217 self.initrd = None
218
219 def _get_samsung_v310_env_start(self):
220 return self._samsung_v310_env_start
221
222 def _set_samsung_v310_env_start(self, value):
223 assert value == 33, ("BL1 expects u-boot environment at +33s.")
224 self._samsung_v310_env_start = value
225
226 samsung_v310_env_start = property(_get_samsung_v310_env_start,
227 _set_samsung_v310_env_start)
228
229 def _get_samsung_v310_env_len(self):
230 return self._samsung_v310_env_len
231
232 def _set_samsung_v310_env_len(self, value):
233 assert value * SECTOR_SIZE == 16 * 1024, ("BL1 expects u-boot "
234 "environment to be 16 KiB.")
235 self._samsung_v310_env_len = value
236
237 samsung_v310_env_len = property(_get_samsung_v310_env_len,
238 _set_samsung_v310_env_len)
239
240 def _get_samsung_v310_bl2_start(self):
241 return self._samsung_v310_bl2_start
242
243 def _set_samsung_v310_bl2_start(self, value):
244 self._samsung_v310_bl2_start = value
245
246 samsung_v310_bl2_start = property(_get_samsung_v310_bl2_start,
247 _set_samsung_v310_bl2_start)
248
249 def _get_samsung_v310_bl2_len(self):
250 return self._samsung_v310_bl2_len
251
252 def _set_samsung_v310_bl2_len(self, value):
253 assert value * SECTOR_SIZE == 512 * 1024, ("BL1 expects BL2 (u-boot) "
254 "to be 512 KiB.")
255 self._samsung_v310_bl2_len = value
256
257 samsung_v310_bl2_len = property(_get_samsung_v310_bl2_len,
258 _set_samsung_v310_bl2_len)
259
260 # XXX: can be removed when killing v1 hwpack.
261 def _get_live_serial_opts(self):
262 return_value = self._live_serial_opts
263 if self._check_placeholder_presence(return_value, r'%s'):
264 return_value = self._live_serial_opts % self.serial_tty
265 return return_value
266
267 def _set_live_serial_opts(self, value):
268 self._live_serial_opts = value
269
270 live_serial_opts = property(_get_live_serial_opts, _set_live_serial_opts)
271
272 # XXX: can be removed when killing v1 hwpack.
273 def _get_extra_serial_opts(self):
274 return_value = self._extra_serial_opts
275 if self._check_placeholder_presence(return_value, r'%s'):
276 return_value = return_value % self.serial_tty
277 return return_value
278
279 def _set_extra_serial_opts(self, value):
280 self._extra_serial_opts = value
281
282 extra_serial_opts = property(_get_extra_serial_opts,
283 _set_extra_serial_opts)
284
285 def get_metadata_field(self, field_name):
464 """ Return the metadata value for field_name if it can be found.286 """ Return the metadata value for field_name if it can be found.
465 """287 """
466 data, _ = cls.hardwarepack_handler.get_field(field_name)288 data, _ = self.hardwarepack_handler.get_field(field_name)
467 return data289 return data
468290
469 @classmethod291 def set_metadata(self, hwpacks, bootloader=None, board=None):
470 def set_board(cls, board):292 self.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
471 cls.board = board
472
473 @classmethod
474 def set_metadata(cls, hwpacks, bootloader=None, board=None):
475 cls.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
476 board)293 board)
477 with cls.hardwarepack_handler:294 with self.hardwarepack_handler:
478 cls.hwpack_format = cls.hardwarepack_handler.get_format()295 self.hwpack_format = self.hardwarepack_handler.get_format()
479 if (cls.hwpack_format == cls.hardwarepack_handler.FORMAT_1):296 if (self.hwpack_format == self.hardwarepack_handler.FORMAT_1):
480 return297 return
481298
482 if (cls.hwpack_format != cls.hardwarepack_handler.FORMAT_1):299 if (self.hwpack_format != self.hardwarepack_handler.FORMAT_1):
483 # Clear V1 defaults.300 # Clear V1 defaults.
484 cls.kernel_addr = None301 # TODO When removing v1 support, remove also default values
485 cls.initrd_addr = None302 # in the constructor and avoid all this.
486 cls.load_addr = None303 self.kernel_addr = None
487 cls.serial_tty = None304 self.initrd_addr = None
488 cls.fat_size = None305 self.load_addr = None
489 cls.dtb_name = None306 self.serial_tty = None
490 cls.dtb_addr = None307 self.fat_size = None
491 cls.extra_boot_args_options = None308 self.dtb_name = None
492 cls.boot_script = None309 self.dtb_addr = None
493 cls.kernel_flavors = None310 self.extra_boot_args_options = None
494 cls.mmc_option = None311 self.boot_script = None
495 cls.mmc_part_offset = None312 self.kernel_flavors = None
496 cls.SAMSUNG_V310_BL1_START = None313 self.mmc_option = None
497 cls.SAMSUNG_V310_BL1_LEN = None314 self.mmc_part_offset = None
498 cls.SAMSUNG_V310_ENV_START = None315 self.samsung_v310_bl1_start = None
499 cls.SAMSUNG_V310_ENV_LEN = None316 self.samsung_v310_bl1_len = None
500 cls.SAMSUNG_V310_BL2_START = None317 self._samsung_v310_env_start = None
501 cls.SAMSUNG_V310_BL2_LEN = None318 self._samsung_v310_env_len = None
319 self.samsung_v310_bl2_start = None
320 self._samsung_v310_bl2_len = None
502321
322 self.board = board
503 # Set new values from metadata.323 # Set new values from metadata.
504 cls.kernel_addr = cls.get_metadata_field('kernel_addr')324 self.kernel_addr = self.get_metadata_field(KERNEL_ADDR_FIELD)
505 cls.initrd_addr = cls.get_metadata_field('initrd_addr')325 self.initrd_addr = self.get_metadata_field(INITRD_ADDR_FIELD)
506 cls.load_addr = cls.get_metadata_field('load_addr')326 self.load_addr = self.get_metadata_field(LOAD_ADDR_FIELD)
507 cls.dtb_addr = cls.get_metadata_field('dtb_addr')327 self.dtb_addr = self.get_metadata_field(DTB_ADDR_FIELD)
508 cls.serial_tty = cls.get_metadata_field('serial_tty')328 self.serial_tty = self.get_metadata_field(SERIAL_TTY_FIELD)
509 wired_interfaces = cls.get_metadata_field('wired_interfaces')329 wired_interfaces = self.get_metadata_field(WIRED_INTERFACES_FIELD)
510 if wired_interfaces is not None:330 if wired_interfaces:
511 cls.wired_interfaces = wired_interfaces331 self.wired_interfaces = wired_interfaces
512 wireless_interfaces = cls.get_metadata_field(332 wireless_interfaces = self.get_metadata_field(
513 'wireless_interfaces')333 WIRELESS_INTERFACES_FIELD)
514 if wireless_interfaces is not None:334 if wireless_interfaces:
515 cls.wireless_interfaces = wireless_interfaces335 self.wireless_interfaces = wireless_interfaces
516 cls.vmlinuz = cls.get_metadata_field('vmlinuz')336 self.dtb_file = self.get_metadata_field(DTB_FILE_FIELD)
517 cls.initrd = cls.get_metadata_field('initrd')337 # XXX: need to deprecate dtb_file field and use only dtb_files
518 cls.dtb_file = cls.get_metadata_field('dtb_file')338 # for multiple entries.
519 cls.dtb_files = cls.get_metadata_field('dtb_files')339 if self.dtb_file:
520 cls.extra_boot_args_options = cls.get_metadata_field(340 logger.warn("Deprecation warning: use the 'dtb_files' field "
521 'extra_boot_options')341 "instead of 'dtb_file'.")
522 cls.boot_script = cls.get_metadata_field('boot_script')342 self.dtb_files = self.get_metadata_field(DTB_FILES_FIELD)
523 cls.extra_serial_opts = cls.get_metadata_field(343 self.extra_boot_args_options = self.get_metadata_field(
524 'extra_serial_opts')344 EXTRA_BOOT_OPTIONS_FIELD)
525 cls.snowball_startup_files_config = cls.get_metadata_field(345 self.boot_script = self.get_metadata_field(BOOT_SCRIPT_FIELD)
526 'snowball_startup_files_config')346 self.extra_serial_opts = self.get_metadata_field(
527347 EXTRA_SERIAL_OPTIONS_FIELD)
528 cls.partition_layout = cls.get_metadata_field('partition_layout')348 self.snowball_startup_files_config = self.get_metadata_field(
529 if cls.partition_layout in [349 SNOWBALL_STARTUP_FILES_CONFIG_FIELD)
530 'bootfs_rootfs', 'reserved_bootfs_rootfs', None]:350 self.partition_layout = self.get_metadata_field(
531 cls.fat_size = 32351 PARTITION_LAYOUT_FIELD)
532 elif cls.partition_layout == 'bootfs16_rootfs':352 if self.partition_layout in [BOOTFS, RESERVED_BOOTFS, None]:
533 cls.fat_size = 16353 self.fat_size = 32
354 elif self.partition_layout == BOOTFS16:
355 self.fat_size = 16
534 else:356 else:
535 raise AssertionError("Unknown partition layout '%s'." % \357 raise AssertionError("Unknown partition layout '%s'." % \
536 cls.partition_layout)358 self.partition_layout)
537359
538 cls.mmc_option = cls.get_metadata_field('mmc_id')360 self.mmc_option = self.get_metadata_field(MMC_ID_FIELD)
539 if cls.mmc_option is not None:361 if self.mmc_option:
540 cls.mmc_device_id = int(cls.mmc_option.split(':')[0])362 self.mmc_device_id = int(self.mmc_option.split(':')[0])
541 cls.mmc_part_offset = int(cls.mmc_option.split(':')[1]) - 1363 self.mmc_part_offset = int(self.mmc_option.split(':')[1]) - 1
542364
543 boot_min_size = cls.get_metadata_field('boot_min_size')365 # XXX: need to fix these values.
544 if boot_min_size is not None:366 boot_min_size = self.get_metadata_field(BOOT_MIN_SIZE_FIELD)
545 cls.BOOT_MIN_SIZE_S = align_up(int(boot_min_size) * 1024 ** 2,367 if boot_min_size:
546 SECTOR_SIZE) / SECTOR_SIZE368 self.BOOT_MIN_SIZE_S = align_up(int(boot_min_size) * 1024 ** 2,
547 root_min_size = cls.get_metadata_field('root_min_size')369 SECTOR_SIZE) / SECTOR_SIZE
548 if root_min_size is not None:370 root_min_size = self.get_metadata_field(ROOT_MIN_SIZE_FIELD)
549 cls.ROOT_MIN_SIZE_S = align_up(int(root_min_size) * 1024 ** 2,371 if root_min_size:
550 SECTOR_SIZE) / SECTOR_SIZE372 self.ROOT_MIN_SIZE_S = align_up(int(root_min_size) * 1024 ** 2,
551 loader_min_size = cls.get_metadata_field('loader_min_size')373 SECTOR_SIZE) / SECTOR_SIZE
552 if loader_min_size is not None:374 loader_min_size = self.get_metadata_field(LOADER_MIN_SIZE_FIELD)
553 cls.LOADER_MIN_SIZE_S = (375 if loader_min_size:
376 self.LOADER_MIN_SIZE_S = (
554 align_up(int(loader_min_size) * 1024 ** 2,377 align_up(int(loader_min_size) * 1024 ** 2,
555 SECTOR_SIZE) / SECTOR_SIZE)378 SECTOR_SIZE) / SECTOR_SIZE)
556379
557 bootloader_file_in_boot_part = cls.get_metadata_field(380 spl_in_boot_part = self.get_metadata_field(SPL_IN_BOOT_PART_FIELD)
558 'bootloader_file_in_boot_part')
559 if bootloader_file_in_boot_part is None:
560 cls.bootloader_file_in_boot_part = False
561 elif string.lower(bootloader_file_in_boot_part) == 'yes':
562 cls.bootloader_file_in_boot_part = True
563 elif string.lower(bootloader_file_in_boot_part) == 'no':
564 cls.bootloader_file_in_boot_part = False
565 spl_in_boot_part = cls.get_metadata_field('spl_in_boot_part')
566 if spl_in_boot_part is None:381 if spl_in_boot_part is None:
567 cls.spl_in_boot_part = False382 self.spl_in_boot_part = False
568 elif string.lower(spl_in_boot_part) == 'yes':383 elif string.lower(spl_in_boot_part) == 'yes':
569 cls.spl_in_boot_part = True384 self.spl_in_boot_part = True
570 elif string.lower(spl_in_boot_part) == 'no':385 elif string.lower(spl_in_boot_part) == 'no':
571 cls.spl_in_boot_part = False386 self.spl_in_boot_part = False
572 env_dd = cls.get_metadata_field('env_dd')387
388 env_dd = self.get_metadata_field(ENV_DD_FIELD)
573 if env_dd is None:389 if env_dd is None:
574 cls.env_dd = False390 self.env_dd = False
575 elif string.lower(env_dd) == 'yes':391 elif string.lower(env_dd) == 'yes':
576 cls.env_dd = True392 self.env_dd = True
577 elif string.lower(env_dd) == 'no':393 elif string.lower(env_dd) == 'no':
578 cls.env_dd = False394 self.env_dd = False
579395
580 bootloader_dd = cls.get_metadata_field('bootloader_dd')396 # XXX: in hwpack v3 this field is just called 'dd'.
397 # Need to check its use.
398 bootloader_dd = self.get_metadata_field('bootloader_dd')
581 # Either bootloader_dd is not specified, or it contains the dd399 # Either bootloader_dd is not specified, or it contains the dd
582 # offset.400 # offset.
583 if bootloader_dd is None:401 if bootloader_dd is None:
584 cls.bootloader_dd = False402 self.bootloader_dd = False
585 else:403 else:
586 cls.bootloader_dd = int(bootloader_dd)404 self.bootloader_dd = int(bootloader_dd)
587 spl_dd = cls.get_metadata_field('spl_dd')405 spl_dd = self.get_metadata_field(SPL_DD_FIELD)
588 # Either spl_dd is not specified, or it contains the dd offset.406 # Either spl_dd is not specified, or it contains the dd offset.
589 if spl_dd is None:407 if spl_dd is None:
590 cls.spl_dd = False408 self.spl_dd = False
591 else:409 else:
592 cls.spl_dd = int(spl_dd)410 self.spl_dd = int(spl_dd)
593411
594 loader_start = cls.get_metadata_field('loader_start')412 loader_start = self.get_metadata_field(LOADER_START_FIELD)
595 if loader_start is not None:413 if loader_start:
596 cls.LOADER_START_S = int(loader_start)414 self.loader_start_s = int(loader_start)
597 samsung_bl1_start = cls.get_metadata_field('samsung_bl1_start')415 samsung_bl1_start = self.get_metadata_field(
598 if samsung_bl1_start is not None:416 SAMSUNG_BL1_START_FIELD)
599 cls.SAMSUNG_V310_BL1_START = int(samsung_bl1_start)417 if samsung_bl1_start:
600 samsung_bl1_len = cls.get_metadata_field('samsung_bl1_len')418 self.samsung_v310_bl1_start = int(samsung_bl1_start)
601 if samsung_bl1_len is not None:419 samsung_bl1_len = self.get_metadata_field(SAMSUNG_BL1_LEN_FIELD)
602 cls.SAMSUNG_V310_BL1_LEN = int(samsung_bl1_len)420 if samsung_bl1_len:
603 samsung_env_len = cls.get_metadata_field('samsung_env_len')421 self.samsung_v310_bl1_len = int(samsung_bl1_len)
604 if samsung_env_len is not None:422 samsung_env_len = self.get_metadata_field(SAMSUNG_ENV_LEN_FIELD)
605 cls.SAMSUNG_V310_ENV_LEN = int(samsung_env_len)423 if samsung_env_len:
606 assert cls.SAMSUNG_V310_ENV_LEN * SECTOR_SIZE == 16 * 1024, (424 self.samsung_v310_env_len = int(samsung_env_len)
607 "BL1 expects u-boot environment to be 16 KiB")425 samsung_bl2_len = self.get_metadata_field(SAMSUNG_BL2_LEN_FIELD)
608 samsung_bl2_len = cls.get_metadata_field('samsung_bl2_len')426 if samsung_bl2_len:
609 if samsung_bl2_len is not None:427 self.samsung_v310_bl2_len = int(samsung_bl2_len)
610 cls.SAMSUNG_V310_BL2_LEN = int(samsung_bl2_len)428
611 assert cls.SAMSUNG_V310_BL2_LEN * SECTOR_SIZE == 512 * 1024, (429 if (self.samsung_v310_bl1_start and self.samsung_v310_bl1_len):
612 "BL1 expects BL2 (u-boot) to be 512 KiB")430 self.samsung_v310_env_start = (self.samsung_v310_bl1_start +
613431 self.samsung_v310_bl1_len)
614 if (cls.SAMSUNG_V310_BL1_START and cls.SAMSUNG_V310_BL1_LEN):432 if (self.samsung_v310_env_start and self.samsung_v310_env_len):
615 cls.SAMSUNG_V310_ENV_START = (cls.SAMSUNG_V310_BL1_START +433 self.samsung_v310_bl2_start = (self.samsung_v310_env_start +
616 cls.SAMSUNG_V310_BL1_LEN)434 self.samsung_v310_env_len)
617 assert cls.SAMSUNG_V310_ENV_START == 33, (435
618 "BL1 expects u-boot environment at +33s")436 self.bootloader_copy_files = self.hardwarepack_handler.get_field(
619 if (cls.SAMSUNG_V310_ENV_START and cls.SAMSUNG_V310_ENV_LEN):
620 cls.SAMSUNG_V310_BL2_START = (cls.SAMSUNG_V310_ENV_START +
621 cls.SAMSUNG_V310_ENV_LEN)
622
623 cls.bootloader_copy_files = cls.hardwarepack_handler.get_field(
624 "bootloader_copy_files")[0]437 "bootloader_copy_files")[0]
625438
626 cls.bootloader = cls.hardwarepack_handler.get_field(439 # XXX: no reference in hwpackV3 format of these fields, double
627 "bootloader")440 # check if they can be dropped when killing v1.
628 cls.board = board441 self.bootloader = self.hardwarepack_handler.get_field(
442 "bootloader")
443 self.vmlinuz = self.get_metadata_field('vmlinuz')
444 self.initrd = self.get_metadata_field('initrd')
445 bootloader_file_in_boot_part = self.get_metadata_field(
446 'bootloader_file_in_boot_part')
447 if bootloader_file_in_boot_part is None:
448 self.bootloader_file_in_boot_part = False
449 elif string.lower(bootloader_file_in_boot_part) == 'yes':
450 self.bootloader_file_in_boot_part = True
451 elif string.lower(bootloader_file_in_boot_part) == 'no':
452 self.bootloader_file_in_boot_part = False
629453
630 @classmethod454 def get_file(self, file_alias, default=None):
631 def get_file(cls, file_alias, default=None):
632 # XXX remove the 'default' parameter when V1 support is removed!455 # XXX remove the 'default' parameter when V1 support is removed!
633 file_in_hwpack = cls.hardwarepack_handler.get_file(file_alias)456 file_in_hwpack = self.hardwarepack_handler.get_file(file_alias)
634 if file_in_hwpack is not None:457 if file_in_hwpack is not None:
635 return file_in_hwpack458 return file_in_hwpack
636 else:459 else:
637 return default460 return default
638461
639 @classmethod462 def get_v1_sfdisk_cmd(self, should_align_boot_part=False):
640 def get_v1_sfdisk_cmd(cls, should_align_boot_part=False):463 # XXX: This default implementation and all overrides are left for V1
641 """Return the sfdisk command to partition the media.464 # compatibility only. They should be removed as part of the work to
642465 # kill off hwpacks V1.
643 :param should_align_boot_part: Whether to align the boot partition too.466 return self.get_normal_sfdisk_cmd(should_align_boot_part)
644467
645 This default implementation returns a boot vfat partition of type468 def get_normal_sfdisk_cmd(self, should_align_boot_part=False):
646 FAT16 or FAT32, followed by a root partition.
647
648 XXX: This default implementation and all overrides are left for V1
649 compatibility only. They should be removed as part of the work to
650 kill off hwpacks V1.
651 """
652 if cls.fat_size == 32:
653 partition_type = '0x0C'
654 else:
655 partition_type = '0x0E'
656
657 # align on sector 63 for compatibility with broken versions of x-loader
658 # unless align_boot_part is set
659 boot_align = 63
660 if should_align_boot_part:
661 boot_align = PART_ALIGN_S
662
663 # can only start on sector 1 (sector 0 is MBR / partition table)
664 boot_start, boot_end, boot_len = align_partition(
665 1, cls.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
666 # apparently OMAP3 ROMs require the vfat length to be an even number
667 # of sectors (multiple of 1 KiB); decrease the length if it's odd,
668 # there should still be enough room
669 boot_len = boot_len - boot_len % 2
670 boot_end = boot_start + boot_len - 1
671
672 # we ignore _root_end / _root_len and return a sfdisk command to
673 # instruct the use of all remaining space; XXX if we had some root size
674 # config, we could do something more sensible
675 root_start, _root_end, _root_len = align_partition(
676 boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
677
678 return '%s,%s,%s,*\n%s,,,-' % (
679 boot_start, boot_len, partition_type, root_start)
680
681 @classmethod
682 def get_normal_sfdisk_cmd(cls, should_align_boot_part=False):
683 """Return the sfdisk command to partition the media.469 """Return the sfdisk command to partition the media.
684470
685 :param should_align_boot_part: Whether to align the boot partition too.471 :param should_align_boot_part: Whether to align the boot partition too.
@@ -687,7 +473,7 @@
687 This returns a boot vfat partition of type FAT16473 This returns a boot vfat partition of type FAT16
688 or FAT32, followed by a root partition.474 or FAT32, followed by a root partition.
689 """475 """
690 if cls.fat_size == 32:476 if self.fat_size == 32:
691 partition_type = '0x0C'477 partition_type = '0x0C'
692 else:478 else:
693 partition_type = '0x0E'479 partition_type = '0x0E'
@@ -701,7 +487,7 @@
701487
702 # can only start on sector 1 (sector 0 is MBR / partition table)488 # can only start on sector 1 (sector 0 is MBR / partition table)
703 boot_start, boot_end, boot_len = align_partition(489 boot_start, boot_end, boot_len = align_partition(
704 1, cls.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)490 1, self.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
705 # apparently OMAP3 ROMs require the vfat length to be an even number491 # apparently OMAP3 ROMs require the vfat length to be an even number
706 # of sectors (multiple of 1 KiB); decrease the length if it's odd,492 # of sectors (multiple of 1 KiB); decrease the length if it's odd,
707 # there should still be enough room493 # there should still be enough room
@@ -713,13 +499,12 @@
713 # instruct the use of all remaining space; XXX we now have root size499 # instruct the use of all remaining space; XXX we now have root size
714 # config, so we can do something more sensible500 # config, so we can do something more sensible
715 root_start, _root_end, _root_len = align_partition(501 root_start, _root_end, _root_len = align_partition(
716 boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)502 boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
717503
718 return '%s,%s,%s,*\n%s,,,-' % (504 return '%s,%s,%s,*\n%s,,,-' % (
719 boot_start, boot_len, partition_type, root_start)505 boot_start, boot_len, partition_type, root_start)
720506
721 @classmethod507 def get_reserved_sfdisk_cmd(self, should_align_boot_part=None):
722 def get_reserved_sfdisk_cmd(cls, should_align_boot_part=None):
723 """Return the sfdisk command to partition the media.508 """Return the sfdisk command to partition the media.
724509
725 :param should_align_boot_part: Ignored.510 :param should_align_boot_part: Ignored.
@@ -728,40 +513,38 @@
728 FAT16 or FAT32, followed by a root partition.513 FAT16 or FAT32, followed by a root partition.
729 """514 """
730 loader_start, loader_end, loader_len = align_partition(515 loader_start, loader_end, loader_len = align_partition(
731 cls.LOADER_START_S, cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)516 self.loader_start_s, self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
732517
733 boot_start, boot_end, boot_len = align_partition(518 boot_start, boot_end, boot_len = align_partition(
734 loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)519 loader_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
735520
736 root_start, _root_end, _root_len = align_partition(521 root_start, _root_end, _root_len = align_partition(
737 boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)522 boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
738523
739 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (524 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
740 loader_start, loader_len, boot_start, boot_len, root_start)525 loader_start, loader_len, boot_start, boot_len, root_start)
741526
742 @classmethod527 def get_sfdisk_cmd(self, should_align_boot_part=False):
743 def get_sfdisk_cmd(cls, should_align_boot_part=False):528 if (self.partition_layout in ['bootfs_rootfs', 'bootfs16_rootfs'] or
744 if (cls.partition_layout in ['bootfs_rootfs', 'bootfs16_rootfs'] or529 self.board == 'snowball_sd'):
745 cls.board == 'snowball_sd'):530 return self.get_normal_sfdisk_cmd(should_align_boot_part)
746 return cls.get_normal_sfdisk_cmd(should_align_boot_part)531 elif self.partition_layout in ['reserved_bootfs_rootfs']:
747 elif cls.partition_layout in ['reserved_bootfs_rootfs']:532 return self.get_reserved_sfdisk_cmd(should_align_boot_part)
748 return cls.get_reserved_sfdisk_cmd(should_align_boot_part)
749 else:533 else:
750 assert (cls.hwpack_format == HardwarepackHandler.FORMAT_1), (534 assert (self.hwpack_format == HardwarepackHandler.FORMAT_1), (
751 "Hwpack format is not 1.0 but "535 "Hwpack format is not 1.0 but "
752 "partition_layout is unspecified.")536 "partition_layout is unspecified.")
753 return cls.get_v1_sfdisk_cmd(should_align_boot_part)537 return self.get_v1_sfdisk_cmd(should_align_boot_part)
754538
755 @classmethod539 def _get_bootcmd(self, i_img_data, d_img_data):
756 def _get_bootcmd(cls, i_img_data, d_img_data):
757 """Get the bootcmd for this board.540 """Get the bootcmd for this board.
758541
759 In general subclasses should not have to override this.542 In general subclasses should not have to override this.
760 """543 """
761 replacements = dict(544 replacements = dict(
762 fatload_command=cls.fatload_command, uimage_path=cls.uimage_path,545 fatload_command=self.fatload_command, uimage_path=self.uimage_path,
763 mmc_option=cls.mmc_option, kernel_addr=cls.kernel_addr,546 mmc_option=self.mmc_option, kernel_addr=self.kernel_addr,
764 initrd_addr=cls.initrd_addr, dtb_addr=cls.dtb_addr)547 initrd_addr=self.initrd_addr, dtb_addr=self.dtb_addr)
765 boot_script = (548 boot_script = (
766 ("%(fatload_command)s mmc %(mmc_option)s %(kernel_addr)s " +549 ("%(fatload_command)s mmc %(mmc_option)s %(kernel_addr)s " +
767 "%(uimage_path)suImage; ")) % replacements550 "%(uimage_path)suImage; ")) % replacements
@@ -770,7 +553,7 @@
770 ("%(fatload_command)s mmc %(mmc_option)s %(initrd_addr)s " +553 ("%(fatload_command)s mmc %(mmc_option)s %(initrd_addr)s " +
771 "%(uimage_path)suInitrd; ")) % replacements554 "%(uimage_path)suInitrd; ")) % replacements
772 if d_img_data is not None:555 if d_img_data is not None:
773 assert cls.dtb_addr is not None, (556 assert self.dtb_addr is not None, (
774 "Need a dtb_addr when passing d_img_data")557 "Need a dtb_addr when passing d_img_data")
775 boot_script += (558 boot_script += (
776 ("%(fatload_command)s mmc %(mmc_option)s %(dtb_addr)s " +559 ("%(fatload_command)s mmc %(mmc_option)s %(dtb_addr)s " +
@@ -782,37 +565,34 @@
782 boot_script += ((" %(dtb_addr)s")) % replacements565 boot_script += ((" %(dtb_addr)s")) % replacements
783 return boot_script566 return boot_script
784567
785 @classmethod568 def add_boot_args(self, extra_args):
786 def add_boot_args(cls, extra_args):
787 if extra_args is not None:569 if extra_args is not None:
788 if cls.extra_boot_args_options is None:570 if self.extra_boot_args_options is None:
789 cls.extra_boot_args_options = extra_args571 self.extra_boot_args_options = extra_args
790 else:572 else:
791 cls.extra_boot_args_options += ' %s' % extra_args573 self.extra_boot_args_options += ' %s' % extra_args
792574
793 @classmethod575 def add_boot_args_from_file(self, path):
794 def add_boot_args_from_file(cls, path):
795 if path is not None:576 if path is not None:
796 with open(path, 'r') as boot_args_file:577 with open(path, 'r') as boot_args_file:
797 cls.add_boot_args(boot_args_file.read().strip())578 self.add_boot_args(boot_args_file.read().strip())
798579
799 @classmethod580 def _get_bootargs(self, is_live, is_lowmem, consoles, rootfs_id):
800 def _get_bootargs(cls, is_live, is_lowmem, consoles, rootfs_id):
801 """Get the bootargs for this board.581 """Get the bootargs for this board.
802582
803 In general subclasses should not have to override this.583 In general subclasses should not have to override this.
804 """584 """
805 boot_args_options = 'rootwait ro'585 boot_args_options = 'rootwait ro'
806 if cls.extra_boot_args_options is not None:586 if self.extra_boot_args_options:
807 boot_args_options += ' %s' % cls.extra_boot_args_options587 boot_args_options += ' %s' % self.extra_boot_args_options
808 serial_opts = cls.extra_serial_opts588 serial_opts = self.extra_serial_opts
809 for console in consoles:589 for console in consoles:
810 serial_opts += ' console=%s' % console590 serial_opts += ' console=%s' % console
811591
812 lowmem_opt = ''592 lowmem_opt = ''
813 boot_snippet = 'root=%s' % rootfs_id593 boot_snippet = 'root=%s' % rootfs_id
814 if is_live:594 if is_live:
815 serial_opts += ' %s' % cls.live_serial_opts595 serial_opts += ' %s' % self.live_serial_opts
816 boot_snippet = 'boot=casper'596 boot_snippet = 'boot=casper'
817 if is_lowmem:597 if is_lowmem:
818 lowmem_opt = 'only-ubiquity'598 lowmem_opt = 'only-ubiquity'
@@ -826,45 +606,42 @@
826 "%(boot_snippet)s %(boot_args_options)s"606 "%(boot_snippet)s %(boot_args_options)s"
827 % replacements)607 % replacements)
828608
829 @classmethod609 def _get_boot_env(self, is_live, is_lowmem, consoles, rootfs_id,
830 def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
831 i_img_data, d_img_data):610 i_img_data, d_img_data):
832 """Get the boot environment for this board.611 """Get the boot environment for this board.
833612
834 In general subclasses should not have to override this.613 In general subclasses should not have to override this.
835 """614 """
836 boot_env = {}615 boot_env = {}
837 boot_env["bootargs"] = cls._get_bootargs(616 boot_env["bootargs"] = self._get_bootargs(
838 is_live, is_lowmem, consoles, rootfs_id)617 is_live, is_lowmem, consoles, rootfs_id)
839 boot_env["bootcmd"] = cls._get_bootcmd(i_img_data, d_img_data)618 boot_env["bootcmd"] = self._get_bootcmd(i_img_data, d_img_data)
840 boot_env["initrd_high"] = cls.initrd_high619 boot_env["initrd_high"] = self.initrd_high
841 boot_env["fdt_high"] = cls.fdt_high620 boot_env["fdt_high"] = self.fdt_high
842 return boot_env621 return boot_env
843622
844 @classmethod623 def make_boot_files(self, bootloader_parts_dir, is_live, is_lowmem,
845 def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
846 consoles, chroot_dir, rootfs_id, boot_dir,624 consoles, chroot_dir, rootfs_id, boot_dir,
847 boot_device_or_file):625 boot_device_or_file):
848 if cls.hwpack_format == HardwarepackHandler.FORMAT_1:626 if self.hwpack_format == HardwarepackHandler.FORMAT_1:
849 parts_dir = bootloader_parts_dir627 parts_dir = bootloader_parts_dir
850 else:628 else:
851 parts_dir = chroot_dir629 parts_dir = chroot_dir
852 (k_img_data, i_img_data, d_img_data) = cls._get_kflavor_files(630 (k_img_data, i_img_data, d_img_data) = self._get_kflavor_files(
853 parts_dir)631 parts_dir)
854 boot_env = cls._get_boot_env(is_live, is_lowmem, consoles, rootfs_id,632 boot_env = self._get_boot_env(is_live, is_lowmem, consoles, rootfs_id,
855 i_img_data, d_img_data)633 i_img_data, d_img_data)
856634
857 if cls.hwpack_format == HardwarepackHandler.FORMAT_1:635 if self.hwpack_format == HardwarepackHandler.FORMAT_1:
858 cls._make_boot_files(636 self._make_boot_files(
859 boot_env, chroot_dir, boot_dir,637 boot_env, chroot_dir, boot_dir,
860 boot_device_or_file, k_img_data, i_img_data, d_img_data)638 boot_device_or_file, k_img_data, i_img_data, d_img_data)
861 else:639 else:
862 cls._make_boot_files_v2(640 self._make_boot_files_v2(
863 boot_env, chroot_dir, boot_dir,641 boot_env, chroot_dir, boot_dir,
864 boot_device_or_file, k_img_data, i_img_data, d_img_data)642 boot_device_or_file, k_img_data, i_img_data, d_img_data)
865643
866 @classmethod644 def _copy_dtb_files(self, dtb_files, dest_dir, search_dir):
867 def _copy_dtb_files(cls, dtb_files, dest_dir, search_dir):
868 """Copy the files defined in dtb_files into the boot directory.645 """Copy the files defined in dtb_files into the boot directory.
869646
870 :param dtb_files: The list of dtb files647 :param dtb_files: The list of dtb files
@@ -904,13 +681,12 @@
904 else:681 else:
905 # Hopefully we should never get here.682 # Hopefully we should never get here.
906 # This should only happen if the hwpack config YAML file is683 # This should only happen if the hwpack config YAML file is
907 # wrong684 # wrong.
908 logger.warn('WARNING: Wrong syntax in metadata file. '685 logger.warn('WARNING: Wrong syntax in metadata file. '
909 'Check the hwpack configuration file used to '686 'Check the hwpack configuration file used to '
910 'generate the hwpack archive.')687 'generate the hwpack archive.')
911688
912 @classmethod689 def _dd_file(self, from_file, to_file, seek, max_size=None):
913 def _dd_file(cls, from_file, to_file, seek, max_size=None):
914 assert from_file is not None, "No source file name given."690 assert from_file is not None, "No source file name given."
915 if max_size is not None:691 if max_size is not None:
916 assert os.path.getsize(from_file) <= max_size, (692 assert os.path.getsize(from_file) <= max_size, (
@@ -918,23 +694,21 @@
918 logger.info("Writing '%s' to '%s' at %s." % (from_file, to_file, seek))694 logger.info("Writing '%s' to '%s' at %s." % (from_file, to_file, seek))
919 _dd(from_file, to_file, seek=seek)695 _dd(from_file, to_file, seek=seek)
920696
921 @classmethod697 def install_samsung_boot_loader(self, samsung_spl_file, bootloader_file,
922 def install_samsung_boot_loader(cls, samsung_spl_file, bootloader_file,
923 boot_device_or_file):698 boot_device_or_file):
924 cls._dd_file(samsung_spl_file, boot_device_or_file,699 self._dd_file(samsung_spl_file, boot_device_or_file,
925 cls.SAMSUNG_V310_BL1_START,700 self.samsung_v310_bl1_start,
926 cls.SAMSUNG_V310_BL1_LEN * SECTOR_SIZE)701 self.samsung_v310_bl1_len * SECTOR_SIZE)
927 cls._dd_file(bootloader_file, boot_device_or_file,702 self._dd_file(bootloader_file, boot_device_or_file,
928 cls.SAMSUNG_V310_BL2_START,703 self.samsung_v310_bl2_start,
929 cls.SAMSUNG_V310_BL2_LEN * SECTOR_SIZE)704 self.samsung_v310_bl2_len * SECTOR_SIZE)
930705
931 @classmethod706 def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
932 def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir,
933 boot_device_or_file, k_img_data, i_img_data,707 boot_device_or_file, k_img_data, i_img_data,
934 d_img_data):708 d_img_data):
935 with cls.hardwarepack_handler:709 with self.hardwarepack_handler:
936 spl_file = cls.get_file('spl_file')710 spl_file = self.get_file('spl_file')
937 if cls.spl_in_boot_part:711 if self.spl_in_boot_part:
938 assert spl_file is not None, (712 assert spl_file is not None, (
939 "SPL binary could not be found")713 "SPL binary could not be found")
940 logger.info(714 logger.info(
@@ -944,15 +718,15 @@
944 # XXX: Is this really needed?718 # XXX: Is this really needed?
945 cmd_runner.run(["sync"]).wait()719 cmd_runner.run(["sync"]).wait()
946720
947 if cls.spl_dd:721 if self.spl_dd:
948 cls._dd_file(spl_file, boot_device_or_file, cls.spl_dd)722 self._dd_file(spl_file, boot_device_or_file, self.spl_dd)
949723
950 bootloader_file = cls.get_file('bootloader_file')724 bootloader_file = self.get_file('bootloader_file')
951 if cls.bootloader_dd:725 if self.bootloader_dd:
952 cls._dd_file(bootloader_file, boot_device_or_file,726 self._dd_file(bootloader_file, boot_device_or_file,
953 cls.bootloader_dd)727 self.bootloader_dd)
954728
955 make_uImage(cls.load_addr, k_img_data, boot_dir)729 make_uImage(self.load_addr, k_img_data, boot_dir)
956730
957 if i_img_data is not None:731 if i_img_data is not None:
958 make_uInitrd(i_img_data, boot_dir)732 make_uInitrd(i_img_data, boot_dir)
@@ -960,29 +734,28 @@
960 if d_img_data is not None:734 if d_img_data is not None:
961 make_dtb(d_img_data, boot_dir)735 make_dtb(d_img_data, boot_dir)
962736
963 if cls.boot_script is not None:737 if self.boot_script is not None:
964 boot_script_path = os.path.join(boot_dir, cls.boot_script)738 boot_script_path = os.path.join(boot_dir, self.boot_script)
965 make_boot_script(boot_env, boot_script_path)739 make_boot_script(boot_env, boot_script_path)
966740
967 # Only used for Omap, will this be bad for the other boards?741 # Only used for Omap, will this be bad for the other boards?
968 make_boot_ini(boot_script_path, boot_dir)742 make_boot_ini(boot_script_path, boot_dir)
969743
970 if (cls.snowball_startup_files_config is not None and744 if (self.snowball_startup_files_config is not None and
971 cls.board != 'snowball_sd'):745 self.board != 'snowball_sd'):
972 cls.populate_raw_partition(boot_device_or_file, chroot_dir)746 self.populate_raw_partition(boot_device_or_file, chroot_dir)
973747
974 if cls.env_dd:748 if self.env_dd:
975 # Do we need to zero out the env before flashing it?749 # Do we need to zero out the env before flashing it?
976 _dd("/dev/zero", boot_device_or_file,750 _dd("/dev/zero", boot_device_or_file,
977 count=cls.SAMSUNG_V310_ENV_LEN,751 count=self.samsung_v310_env_len,
978 seek=cls.SAMSUNG_V310_ENV_START)752 seek=self.samsung_v310_env_start)
979 env_size = cls.SAMSUNG_V310_ENV_LEN * SECTOR_SIZE753 env_size = self.samsung_v310_env_len * SECTOR_SIZE
980 env_file = make_flashable_env(boot_env, env_size)754 env_file = make_flashable_env(boot_env, env_size)
981 cls._dd_file(env_file, boot_device_or_file,755 self._dd_file(env_file, boot_device_or_file,
982 cls.SAMSUNG_V310_ENV_START)756 self.samsung_v310_env_start)
983757
984 @classmethod758 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
985 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
986 boot_device_or_file, k_img_data, i_img_data,759 boot_device_or_file, k_img_data, i_img_data,
987 d_img_data):760 d_img_data):
988 """Make the necessary boot files for this board.761 """Make the necessary boot files for this board.
@@ -992,8 +765,7 @@
992 """765 """
993 raise NotImplementedError()766 raise NotImplementedError()
994767
995 @classmethod768 def populate_boot(self, chroot_dir, rootfs_id, boot_partition, boot_disk,
996 def populate_boot(cls, chroot_dir, rootfs_id, boot_partition, boot_disk,
997 boot_device_or_file, is_live, is_lowmem, consoles):769 boot_device_or_file, is_live, is_lowmem, consoles):
998 parts_dir = 'boot'770 parts_dir = 'boot'
999 if is_live:771 if is_live:
@@ -1001,21 +773,21 @@
1001 bootloader_parts_dir = os.path.join(chroot_dir, parts_dir)773 bootloader_parts_dir = os.path.join(chroot_dir, parts_dir)
1002 cmd_runner.run(['mkdir', '-p', boot_disk]).wait()774 cmd_runner.run(['mkdir', '-p', boot_disk]).wait()
1003 with partition_mounted(boot_partition, boot_disk):775 with partition_mounted(boot_partition, boot_disk):
1004 with cls.hardwarepack_handler:776 with self.hardwarepack_handler:
1005 if cls.bootloader_file_in_boot_part:777 if self.bootloader_file_in_boot_part:
1006 # <legacy v1 support>778 # <legacy v1 support>
1007 if cls.bootloader_flavor is not None:779 if self.bootloader_flavor is not None:
1008 default = os.path.join(780 default = os.path.join(
1009 chroot_dir, 'usr', 'lib', 'u-boot',781 chroot_dir, 'usr', 'lib', 'u-boot',
1010 cls.bootloader_flavor, 'u-boot.img')782 self.bootloader_flavor, 'u-boot.img')
1011 if not os.path.exists(default):783 if not os.path.exists(default):
1012 default = os.path.join(784 default = os.path.join(
1013 chroot_dir, 'usr', 'lib', 'u-boot',785 chroot_dir, 'usr', 'lib', 'u-boot',
1014 cls.bootloader_flavor, 'u-boot.bin')786 self.bootloader_flavor, 'u-boot.bin')
1015 else:787 else:
1016 default = None788 default = None
1017 # </legacy v1 support>789 # </legacy v1 support>
1018 bootloader_bin = cls.get_file('bootloader_file',790 bootloader_bin = self.get_file('bootloader_file',
1019 default=default)791 default=default)
1020 assert bootloader_bin is not None, (792 assert bootloader_bin is not None, (
1021 "bootloader binary could not be found")793 "bootloader binary could not be found")
@@ -1025,18 +797,17 @@
1025 proc.wait()797 proc.wait()
1026798
1027 # Handle copy_files field.799 # Handle copy_files field.
1028 cls.copy_files(boot_disk)800 self.copy_files(boot_disk)
1029801
1030 # Handle dtb_files field.802 # Handle dtb_files field.
1031 if cls.dtb_files:803 if self.dtb_files:
1032 cls._copy_dtb_files(cls.dtb_files, boot_disk, chroot_dir)804 self._copy_dtb_files(self.dtb_files, boot_disk, chroot_dir)
1033805
1034 cls.make_boot_files(806 self.make_boot_files(
1035 bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,807 bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
1036 rootfs_id, boot_disk, boot_device_or_file)808 rootfs_id, boot_disk, boot_device_or_file)
1037809
1038 @classmethod810 def copy_files(self, boot_disk):
1039 def copy_files(cls, boot_disk):
1040 """Handle the copy_files metadata field."""811 """Handle the copy_files metadata field."""
1041812
1042 # Extract anything specified by copy_files sections813 # Extract anything specified by copy_files sections
@@ -1046,13 +817,14 @@
1046 # {'source_path': 'dest_path'}817 # {'source_path': 'dest_path'}
1047 # ]818 # ]
1048 # }819 # }
1049 if cls.bootloader_copy_files is None:820 if self.bootloader_copy_files is None:
1050 return821 return
1051822
1052 for source_package, file_list in cls.bootloader_copy_files.iteritems():823 for source_package, file_list in \
824 self.bootloader_copy_files.iteritems():
1053 for file_info in file_list:825 for file_info in file_list:
1054 for source_path, dest_path in file_info.iteritems():826 for source_path, dest_path in file_info.iteritems():
1055 source = cls.hardwarepack_handler.get_file_from_package(827 source = self.hardwarepack_handler.get_file_from_package(
1056 source_path, source_package)828 source_path, source_package)
1057 dest_path = dest_path.lstrip("/\\")829 dest_path = dest_path.lstrip("/\\")
1058 dirname = os.path.dirname(dest_path)830 dirname = os.path.dirname(dest_path)
@@ -1065,25 +837,24 @@
1065 os.path.join(boot_disk, dest_path)], as_root=True)837 os.path.join(boot_disk, dest_path)], as_root=True)
1066 proc.wait()838 proc.wait()
1067839
1068 @classmethod840 def _get_kflavor_files(self, path):
1069 def _get_kflavor_files(cls, path):
1070 """Search for kernel, initrd and optional dtb in path."""841 """Search for kernel, initrd and optional dtb in path."""
1071 if cls.kernel_flavors is None:842 if self.kernel_flavors is None:
1072 # V2 metadata specifies each glob, not flavors.843 # V2 metadata specifies each glob, not flavors.
1073 # XXX This duplication is temporary until V1 dies.844 # XXX This duplication is temporary until V1 dies.
1074 return cls._get_kflavor_files_v2(path)845 return self._get_kflavor_files_v2(path)
1075846
1076 for flavor in cls.kernel_flavors:847 for flavor in self.kernel_flavors:
1077 kregex = KERNEL_GLOB % {'kernel_flavor': flavor}848 kregex = KERNEL_GLOB % {'kernel_flavor': flavor}
1078 iregex = INITRD_GLOB % {'kernel_flavor': flavor}849 iregex = INITRD_GLOB % {'kernel_flavor': flavor}
1079 dregex = DTB_GLOB % {'kernel_flavor': flavor,850 dregex = DTB_GLOB % {'kernel_flavor': flavor,
1080 'dtb_name': cls.dtb_name}851 'dtb_name': self.dtb_name}
1081 kernel = _get_file_matching(os.path.join(path, kregex))852 kernel = _get_file_matching(os.path.join(path, kregex))
1082 if kernel is not None:853 if kernel is not None:
1083 initrd = _get_file_matching(os.path.join(path, iregex))854 initrd = _get_file_matching(os.path.join(path, iregex))
1084 if initrd is not None:855 if initrd is not None:
1085 dtb = None856 dtb = None
1086 if cls.dtb_name is not None:857 if self.dtb_name is not None:
1087 dtb = _get_file_matching(os.path.join(path, dregex))858 dtb = _get_file_matching(os.path.join(path, dregex))
1088 return (kernel, initrd, dtb)859 return (kernel, initrd, dtb)
1089 raise ValueError(860 raise ValueError(
@@ -1091,83 +862,83 @@
1091 flavor, iregex))862 flavor, iregex))
1092 raise ValueError(863 raise ValueError(
1093 "No kernel found matching %s for flavors %s" % (864 "No kernel found matching %s for flavors %s" % (
1094 KERNEL_GLOB, " ".join(cls.kernel_flavors)))865 KERNEL_GLOB, " ".join(self.kernel_flavors)))
1095866
1096 @classmethod867 def _get_kflavor_files_v2(self, path):
1097 def _get_kflavor_files_v2(cls, path):
1098 kernel = initrd = dtb = None868 kernel = initrd = dtb = None
1099869
1100 if cls.vmlinuz:870 if self.vmlinuz:
1101 kernel = _get_file_matching(os.path.join(path, cls.vmlinuz))871 kernel = _get_file_matching(os.path.join(path, self.vmlinuz))
1102 if not cls.vmlinuz or not kernel:872 if not self.vmlinuz or not kernel:
1103 raise ValueError("Unable to find a valid kernel image.")873 raise ValueError("Unable to find a valid kernel image.")
1104874
1105 if cls.initrd:875 if self.initrd:
1106 initrd = _get_file_matching(os.path.join(path, cls.initrd))876 initrd = _get_file_matching(os.path.join(path, self.initrd))
1107 if not cls.initrd or not initrd:877 if not self.initrd or not initrd:
1108 logger.warn("Could not find a valid initrd, skipping uInitd.")878 logger.warn("Could not find a valid initrd, skipping uInitd.")
1109879
1110 if cls.dtb_file:880 if self.dtb_file:
1111 dtb = _get_file_matching(os.path.join(path, cls.dtb_file))881 dtb = _get_file_matching(os.path.join(path, self.dtb_file))
1112 if not cls.dtb_file or not dtb:882 if not self.dtb_file or not dtb:
1113 logger.warn("Could not find a valid dtb file, skipping it.")883 logger.warn("Could not find a valid dtb file, skipping it.")
1114884
1115 logger.info("Will use kernel=%s, initrd=%s, dtb=%s." % \885 logger.info("Will use kernel=%s, initrd=%s, dtb=%s." % \
1116 (kernel, initrd, dtb))886 (kernel, initrd, dtb))
1117 return (kernel, initrd, dtb)887 return (kernel, initrd, dtb)
1118888
1119 @classmethod889 def populate_raw_partition(self, media, boot_dir):
1120 def populate_raw_partition(cls, media, boot_dir):
1121 # Override in subclass if needed890 # Override in subclass if needed
1122 pass891 pass
1123892
1124 @classmethod893 def snowball_config(self, chroot_dir):
1125 def snowball_config(cls, chroot_dir):
1126 # Override in subclasses where applicable894 # Override in subclasses where applicable
1127 raise NotImplementedError(895 raise NotImplementedError(
1128 "snowball_config() must only be called on BoardConfigs that "896 "snowball_config() must only be called on BoardConfigs that "
1129 "use the Snowball startupfiles.")897 "use the Snowball startupfiles.")
1130898
899 # XXX: can be removed when killing v1 hwpack and updating the attributes
900 # that use it.
901 @staticmethod
902 def _check_placeholder_presence(string, placeholder):
903 """Checks if the passed string contains the particular placeholder."""
904 # Very simple way of achieving that.
905 presence = False
906 if placeholder in string:
907 presence = True
908 return presence
909
1131910
1132class OmapConfig(BoardConfig):911class OmapConfig(BoardConfig):
1133 kernel_flavors = ['linaro-omap4', 'linaro-lt-omap', 'linaro-omap', 'omap4']912
1134 bootloader_file_in_boot_part = True913 def __init__(self):
1135914 super(OmapConfig, self).__init__()
1136 # XXX: Here we define these things as dynamic properties because our915 self.kernel_flavors = ['linaro-omap4', 'linaro-lt-omap',
1137 # temporary hack to fix bug 697824 relies on changing the board's916 'linaro-omap', 'omap4']
1138 # serial_tty at run time.917 self.bootloader_file_in_boot_part = True
1139 _extra_serial_opts = None918 # XXX: Here we define these things as dynamic properties because our
1140 _live_serial_opts = None919 # temporary hack to fix bug 697824 relies on changing the board's
1141 _serial_tty = None920 # serial_tty at run time.
1142921 self._serial_tty = None
1143 @classproperty922
1144 def serial_tty(cls):923 # XXX: when killing v1 hwpack this should be safely removed.
1145 # This is just to make sure no callsites use .serial_tty before924 def _get_serial_tty(self):
1146 # calling set_appropriate_serial_tty(). If we had this in the first925 return self._serial_tty
1147 # place we'd have uncovered bug 710971 before releasing.926
1148 raise AttributeError(927 def _set_serial_tty(self, value):
1149 "You must not use this attribute before calling "928 self._serial_tty = value
1150 "set_appropriate_serial_tty")929
1151930 serial_tty = property(_get_serial_tty, _set_serial_tty)
1152 @classproperty931
1153 def live_serial_opts(cls):932 def set_appropriate_serial_tty(self, chroot_dir):
1154 return cls._live_serial_opts % cls.serial_tty
1155
1156 @classproperty
1157 def extra_serial_opts(cls):
1158 return cls._extra_serial_opts % cls.serial_tty
1159
1160 @classmethod
1161 def set_appropriate_serial_tty(cls, chroot_dir):
1162 """Set the appropriate serial_tty depending on the kernel used.933 """Set the appropriate serial_tty depending on the kernel used.
1163934
1164 If the kernel found in the chroot dir is << 2.6.36 we use tyyS2, else935 If the kernel found in the chroot dir is << 2.6.36 we use tyyS2, else
1165 we use the default value (_serial_tty).936 we use the default value (_serial_tty).
1166 """937 """
1167 # XXX: delete this method when hwpacks V1 can die938 # XXX: delete this method when hwpacks V1 can die
1168 assert cls.hwpack_format == HardwarepackHandler.FORMAT_1939 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1169 # XXX: This is also part of our temporary hack to fix bug 697824.940 # XXX: This is also part of our temporary hack to fix bug 697824.
1170 cls.serial_tty = classproperty(lambda cls: cls._serial_tty)941 # cls.serial_tty = classproperty(lambda cls: cls._serial_tty)
1171 vmlinuz = _get_file_matching(942 vmlinuz = _get_file_matching(
1172 os.path.join(chroot_dir, 'boot', 'vmlinuz*'))943 os.path.join(chroot_dir, 'boot', 'vmlinuz*'))
1173 basename = os.path.basename(vmlinuz)944 basename = os.path.basename(vmlinuz)
@@ -1176,135 +947,134 @@
1176 if match is not None:947 if match is not None:
1177 minor_version = match.group(1)948 minor_version = match.group(1)
1178 if int(minor_version) < 36:949 if int(minor_version) < 36:
1179 cls.serial_tty = classproperty(lambda cls: 'ttyS2')950 self.serial_tty = 'ttyS2'
1180951
1181 @classmethod952 def make_boot_files(self, bootloader_parts_dir, is_live, is_lowmem,
1182 def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
1183 consoles, chroot_dir, rootfs_id, boot_dir,953 consoles, chroot_dir, rootfs_id, boot_dir,
1184 boot_device_or_file):954 boot_device_or_file):
1185 # XXX: This is also part of our temporary hack to fix bug 697824; we955 # XXX: This is also part of our temporary hack to fix bug 697824; we
1186 # need to call set_appropriate_serial_tty() before doing anything that956 # need to call set_appropriate_serial_tty() before doing anything that
1187 # may use cls.serial_tty.957 # may use self.serial_tty.
1188 if cls.hwpack_format == HardwarepackHandler.FORMAT_1:958 if self.hwpack_format == HardwarepackHandler.FORMAT_1:
1189 cls.set_appropriate_serial_tty(chroot_dir)959 self.set_appropriate_serial_tty(chroot_dir)
1190 super(OmapConfig, cls).make_boot_files(960 super(OmapConfig, self).make_boot_files(
1191 bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,961 bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
1192 rootfs_id, boot_dir, boot_device_or_file)962 rootfs_id, boot_dir, boot_device_or_file)
1193963
1194 @classmethod964 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1195 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1196 boot_device_or_file, k_img_data, i_img_data,965 boot_device_or_file, k_img_data, i_img_data,
1197 d_img_data):966 d_img_data):
1198 # XXX: delete this method when hwpacks V1 can die967 # XXX: delete this method when hwpacks V1 can die
1199 assert cls.hwpack_format == HardwarepackHandler.FORMAT_1968 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1200 install_omap_boot_loader(chroot_dir, boot_dir, cls)969 install_omap_boot_loader(chroot_dir, boot_dir, self)
1201 make_uImage(cls.load_addr, k_img_data, boot_dir)970 make_uImage(self.load_addr, k_img_data, boot_dir)
1202 make_uInitrd(i_img_data, boot_dir)971 make_uInitrd(i_img_data, boot_dir)
1203 make_dtb(d_img_data, boot_dir)972 make_dtb(d_img_data, boot_dir)
1204 boot_script_path = os.path.join(boot_dir, cls.boot_script)973 boot_script_path = os.path.join(boot_dir, self.boot_script)
1205 make_boot_script(boot_env, boot_script_path)974 make_boot_script(boot_env, boot_script_path)
1206 make_boot_ini(boot_script_path, boot_dir)975 make_boot_ini(boot_script_path, boot_dir)
1207976
1208977
1209class BeagleConfig(OmapConfig):978class BeagleConfig(OmapConfig):
1210 bootloader_flavor = 'omap3_beagle'979
1211 dtb_name = 'omap3-beagle.dtb'980 def __init__(self):
1212 _serial_tty = 'ttyO2'981 super(BeagleConfig, self).__init__()
1213 _extra_serial_opts = 'console=tty0 console=%s,115200n8'982 self.boot_script = 'boot.scr'
1214 _live_serial_opts = 'serialtty=%s'983 self.bootloader_flavor = 'omap3_beagle'
1215 kernel_addr = '0x80000000'984 self.dtb_addr = '0x815f0000'
1216 dtb_addr = '0x815f0000'985 self.dtb_name = 'omap3-beagle.dtb'
1217 initrd_addr = '0x81600000'986 self.extra_boot_args_options = (
1218 load_addr = '0x80008000'987 'earlyprintk fixrtc nocompcache vram=12M '
1219 boot_script = 'boot.scr'988 'omapfb.mode=dvi:1280x720MR-16@60 mpurate=${mpurate}')
1220 extra_boot_args_options = (989 self.initrd_addr = '0x81600000'
1221 'earlyprintk fixrtc nocompcache vram=12M '990 self.kernel_addr = '0x80000000'
1222 'omapfb.mode=dvi:1280x720MR-16@60 mpurate=${mpurate}')991 self.load_addr = '0x80008000'
992 self._serial_tty = 'ttyO2'
993 self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
994 self._live_serial_opts = 'serialtty=%s'
1223995
1224996
1225class OveroConfig(OmapConfig):997class OveroConfig(OmapConfig):
1226 bootloader_flavor = 'omap3_overo'998 def __init__(self):
1227 dtb_name = 'omap3-overo.dtb'999 super(OveroConfig, self).__init__()
1228 _serial_tty = 'ttyO2'1000 self.boot_script = 'boot.scr'
1229 _extra_serial_opts = 'console=tty0 console=%s,115200n8'1001 self.bootloader_flavor = 'omap3_overo'
1230 kernel_addr = '0x80000000'1002 self.dtb_addr = '0x815f0000'
1231 dtb_addr = '0x815f0000'1003 self.dtb_name = 'omap3-overo.dtb'
1232 initrd_addr = '0x81600000'1004 self.extra_boot_args_options = (
1233 load_addr = '0x80008000'1005 'earlyprintk mpurate=${mpurate} vram=12M '
1234 boot_script = 'boot.scr'1006 'omapdss.def_disp=${defaultdisplay} omapfb.mode=dvi:${dvimode}')
1235 extra_boot_args_options = (1007 self.initrd_addr = '0x81600000'
1236 'earlyprintk mpurate=${mpurate} vram=12M '1008 self.kernel_addr = '0x80000000'
1237 'omapdss.def_disp=${defaultdisplay} omapfb.mode=dvi:${dvimode}')1009 self.load_addr = '0x80008000'
1010 self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1011 self._serial_tty = 'ttyO2'
12381012
12391013
1240class PandaConfig(OmapConfig):1014class PandaConfig(OmapConfig):
1241 bootloader_flavor = 'omap4_panda'1015 def __init__(self):
1242 dtb_name = 'omap4-panda.dtb'1016 super(PandaConfig, self).__init__()
1243 _serial_tty = 'ttyO2'1017 self._serial_tty = 'ttyO2'
1244 _extra_serial_opts = 'console=tty0 console=%s,115200n8'1018 self.boot_script = 'boot.scr'
1245 _live_serial_opts = 'serialtty=%s'1019 self.bootloader_flavor = 'omap4_panda'
1246 kernel_addr = '0x80200000'1020 self.dtb_addr = '0x815f0000'
1247 dtb_addr = '0x815f0000'1021 self.dtb_name = 'omap4-panda.dtb'
1248 initrd_addr = '0x81600000'1022 self.extra_boot_args_options = (
1249 load_addr = '0x80008000'1023 'earlyprintk fixrtc nocompcache vram=48M '
1250 boot_script = 'boot.scr'1024 'omapfb.vram=0:24M mem=456M@0x80000000 mem=512M@0xA0000000')
1251 extra_boot_args_options = (1025 self.initrd_addr = '0x81600000'
1252 'earlyprintk fixrtc nocompcache vram=48M '1026 self.kernel_addr = '0x80200000'
1253 'omapfb.vram=0:24M mem=456M@0x80000000 mem=512M@0xA0000000')1027 self.load_addr = '0x80008000'
1028 self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1029 self._live_serial_opts = 'serialtty=%s'
12541030
12551031
1256class IgepConfig(BeagleConfig):1032class IgepConfig(BeagleConfig):
1257 bootloader_file_in_boot_part = False1033 def __init__(self):
1258 bootloader_flavor = None1034 super(IgepConfig, self).__init__()
1259 dtb_name = 'isee-igep-v2.dtb'1035 self.bootloader_file_in_boot_part = False
1036 self.bootloader_flavor = None
1037 self.dtb_name = 'isee-igep-v2.dtb'
12601038
1261 @classmethod1039 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1262 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1263 boot_device_or_file, k_img_data, i_img_data,1040 boot_device_or_file, k_img_data, i_img_data,
1264 d_img_data):1041 d_img_data):
1265 # XXX: delete this method when hwpacks V1 can die1042 # XXX: delete this method when hwpacks V1 can die
1266 assert cls.hwpack_format == HardwarepackHandler.FORMAT_11043 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1267 make_uImage(cls.load_addr, k_img_data, boot_dir)1044 make_uImage(self.load_addr, k_img_data, boot_dir)
1268 make_uInitrd(i_img_data, boot_dir)1045 make_uInitrd(i_img_data, boot_dir)
1269 make_dtb(d_img_data, boot_dir)1046 make_dtb(d_img_data, boot_dir)
1270 boot_script_path = os.path.join(boot_dir, cls.boot_script)1047 boot_script_path = os.path.join(boot_dir, self.boot_script)
1271 make_boot_script(boot_env, boot_script_path)1048 make_boot_script(boot_env, boot_script_path)
1272 make_boot_ini(boot_script_path, boot_dir)1049 make_boot_ini(boot_script_path, boot_dir)
12731050
12741051
1275class Ux500Config(BoardConfig):1052class Ux500Config(BoardConfig):
1276 serial_tty = 'ttyAMA2'1053 def __init__(self):
1277 _extra_serial_opts = 'console=tty0 console=%s,115200n8'1054 super(Ux500Config, self).__init__()
1278 _live_serial_opts = 'serialtty=%s'1055 self.boot_script = 'flash.scr'
1279 kernel_addr = '0x00100000'1056 self.extra_boot_args_options = (
1280 initrd_addr = '0x08000000'1057 'earlyprintk rootdelay=1 fixrtc nocompcache '
1281 load_addr = '0x00008000'1058 'mem=96M@0 mem_modem=32M@96M mem=44M@128M pmem=22M@172M '
1282 kernel_flavors = ['u8500', 'ux500']1059 'mem=30M@194M mem_mali=32M@224M pmem_hwb=54M@256M '
1283 boot_script = 'flash.scr'1060 'hwmem=48M@302M mem=152M@360M')
1284 extra_boot_args_options = (1061 self.initrd_addr = '0x08000000'
1285 'earlyprintk rootdelay=1 fixrtc nocompcache '1062 self.kernel_addr = '0x00100000'
1286 'mem=96M@0 mem_modem=32M@96M mem=44M@128M pmem=22M@172M '1063 self.kernel_flavors = ['u8500', 'ux500']
1287 'mem=30M@194M mem_mali=32M@224M pmem_hwb=54M@256M '1064 self.load_addr = '0x00008000'
1288 'hwmem=48M@302M mem=152M@360M')1065 self.mmc_option = '1:1'
1289 mmc_option = '1:1'1066 self.serial_tty = 'ttyAMA2'
12901067 self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1291 @classproperty1068 self._live_serial_opts = 'serialtty=%s'
1292 def live_serial_opts(cls):1069
1293 return cls._live_serial_opts % cls.serial_tty1070 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1294
1295 @classproperty
1296 def extra_serial_opts(cls):
1297 return cls._extra_serial_opts % cls.serial_tty
1298
1299 @classmethod
1300 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1301 boot_device_or_file, k_img_data, i_img_data,1071 boot_device_or_file, k_img_data, i_img_data,
1302 d_img_data):1072 d_img_data):
1303 # XXX: delete this method when hwpacks V1 can die1073 # XXX: delete this method when hwpacks V1 can die
1304 assert cls.hwpack_format == HardwarepackHandler.FORMAT_11074 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1305 make_uImage(cls.load_addr, k_img_data, boot_dir)1075 make_uImage(self.load_addr, k_img_data, boot_dir)
1306 make_uInitrd(i_img_data, boot_dir)1076 make_uInitrd(i_img_data, boot_dir)
1307 boot_script_path = os.path.join(boot_dir, cls.boot_script)1077 boot_script_path = os.path.join(boot_dir, self.boot_script)
1308 make_boot_script(boot_env, boot_script_path)1078 make_boot_script(boot_env, boot_script_path)
13091079
13101080
@@ -1314,15 +1084,16 @@
1314 Note that the Snowball board needs a loader partition on the1084 Note that the Snowball board needs a loader partition on the
1315 internal eMMC flash to boot. That partition is created with1085 internal eMMC flash to boot. That partition is created with
1316 the SnowballConfigImage configuration.'''1086 the SnowballConfigImage configuration.'''
1087 def __init__(self):
1088 super(SnowballSdConfig, self).__init__()
13171089
1318 @classmethod1090 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1319 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1320 boot_device_or_file, k_img_data, i_img_data,1091 boot_device_or_file, k_img_data, i_img_data,
1321 d_img_data):1092 d_img_data):
1322 # XXX: delete this method when hwpacks V1 can die1093 # XXX: delete this method when hwpacks V1 can die
1323 assert cls.hwpack_format == HardwarepackHandler.FORMAT_11094 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1324 make_uImage(cls.load_addr, k_img_data, boot_dir)1095 make_uImage(self.load_addr, k_img_data, boot_dir)
1325 boot_script_path = os.path.join(boot_dir, cls.boot_script)1096 boot_script_path = os.path.join(boot_dir, self.boot_script)
1326 make_boot_script(boot_env, boot_script_path)1097 make_boot_script(boot_env, boot_script_path)
13271098
13281099
@@ -1330,16 +1101,18 @@
1330 '''Use only with --image option. Creates a raw image which contains an1101 '''Use only with --image option. Creates a raw image which contains an
1331 additional (raw) loader partition, containing some boot stages1102 additional (raw) loader partition, containing some boot stages
1332 and u-boot.'''1103 and u-boot.'''
1333 # Boot ROM looks for a boot table of contents (TOC) at 0x20000
1334 # Actually, it first looks at address 0, but that's where l-m-c
1335 # puts the MBR, so the boot loader skips that address.
1336 supports_writing_to_mmc = False
1337 SNOWBALL_LOADER_START_S = (128 * 1024) / SECTOR_SIZE1104 SNOWBALL_LOADER_START_S = (128 * 1024) / SECTOR_SIZE
1338 snowball_startup_files_config = 'startfiles.cfg'
1339 TOC_SIZE = 5121105 TOC_SIZE = 512
13401106
1341 @classmethod1107 def __init__(self):
1342 def get_v1_sfdisk_cmd(cls, should_align_boot_part=None):1108 super(SnowballEmmcConfig, self).__init__()
1109 # Boot ROM looks for a boot table of contents (TOC) at 0x20000
1110 # Actually, it first looks at address 0, but that's where l-m-c
1111 # puts the MBR, so the boot loader skips that address.
1112 self.supports_writing_to_mmc = False
1113 self.snowball_startup_files_config = 'startfiles.cfg'
1114
1115 def get_v1_sfdisk_cmd(self, should_align_boot_part=None):
1343 """Return the sfdisk command to partition the media.1116 """Return the sfdisk command to partition the media.
13441117
1345 :param should_align_boot_part: Ignored.1118 :param should_align_boot_part: Ignored.
@@ -1357,68 +1130,64 @@
1357 # with the usual SECTOR_SIZE of 0x200.1130 # with the usual SECTOR_SIZE of 0x200.
1358 # (sector 0 is MBR / partition table)1131 # (sector 0 is MBR / partition table)
1359 loader_start, loader_end, loader_len = align_partition(1132 loader_start, loader_end, loader_len = align_partition(
1360 SnowballEmmcConfig.SNOWBALL_LOADER_START_S,1133 self.SNOWBALL_LOADER_START_S,
1361 cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)1134 self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
13621135
1363 boot_start, boot_end, boot_len = align_partition(1136 boot_start, boot_end, boot_len = align_partition(
1364 loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)1137 loader_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1365 # we ignore _root_end / _root_len and return an sfdisk command to1138 # we ignore _root_end / _root_len and return an sfdisk command to
1366 # instruct the use of all remaining space; XXX if we had some root size1139 # instruct the use of all remaining space; XXX if we had some root size
1367 # config, we could do something more sensible1140 # config, we could do something more sensible
1368 root_start, _root_end, _root_len = align_partition(1141 root_start, _root_end, _root_len = align_partition(
1369 boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)1142 boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
13701143
1371 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (1144 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
1372 loader_start, loader_len, boot_start, boot_len, root_start)1145 loader_start, loader_len, boot_start, boot_len, root_start)
13731146
1374 @classmethod1147 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1375 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1376 boot_device_or_file, k_img_data, i_img_data,1148 boot_device_or_file, k_img_data, i_img_data,
1377 d_img_data):1149 d_img_data):
1378 # XXX: delete this method when hwpacks V1 can die1150 # XXX: delete this method when hwpacks V1 can die
1379 assert cls.hwpack_format == HardwarepackHandler.FORMAT_11151 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1380 make_uImage(cls.load_addr, k_img_data, boot_dir)1152 make_uImage(self.load_addr, k_img_data, boot_dir)
1381 boot_script_path = os.path.join(boot_dir, cls.boot_script)1153 boot_script_path = os.path.join(boot_dir, self.boot_script)
1382 make_boot_script(boot_env, boot_script_path)1154 make_boot_script(boot_env, boot_script_path)
1383 cls.populate_raw_partition(boot_device_or_file, chroot_dir)1155 self.populate_raw_partition(boot_device_or_file, chroot_dir)
13841156
1385 @classmethod1157 def populate_raw_partition(self, boot_device_or_file, chroot_dir):
1386 def populate_raw_partition(cls, boot_device_or_file, chroot_dir):
1387 # Populate created raw partition with TOC and startup files.1158 # Populate created raw partition with TOC and startup files.
1388 _, toc_filename = tempfile.mkstemp()1159 _, toc_filename = tempfile.mkstemp()
1389 config_files_dir = cls.snowball_config(chroot_dir)1160 config_files_dir = self.snowball_config(chroot_dir)
1390 new_files = cls.get_file_info(chroot_dir, config_files_dir)1161 new_files = self.get_file_info(chroot_dir, config_files_dir)
1391 with open(toc_filename, 'wb') as toc:1162 with open(toc_filename, 'wb') as toc:
1392 cls.create_toc(toc, new_files)1163 self.create_toc(toc, new_files)
1393 cls.install_snowball_boot_loader(toc_filename, new_files,1164 self.install_snowball_boot_loader(toc_filename, new_files,
1394 boot_device_or_file,1165 boot_device_or_file,
1395 cls.SNOWBALL_LOADER_START_S,1166 self.SNOWBALL_LOADER_START_S,
1396 cls.delete_startupfiles)1167 self.delete_startupfiles)
1397 cls.delete_file(toc_filename)1168 self.delete_file(toc_filename)
1398 if cls.delete_startupfiles:1169 if self.delete_startupfiles:
1399 cls.delete_file(os.path.join(config_files_dir,1170 self.delete_file(os.path.join(config_files_dir,
1400 cls.snowball_startup_files_config))1171 self.snowball_startup_files_config))
14011172
1402 @classmethod1173 def snowball_config(self, chroot_dir):
1403 def snowball_config(cls, chroot_dir):
1404 # We will find the startupfiles in the target boot partition.1174 # We will find the startupfiles in the target boot partition.
1405 return os.path.join(chroot_dir, 'boot')1175 return os.path.join(chroot_dir, 'boot')
14061176
1407 @classproperty1177 @property
1408 def delete_startupfiles(cls):1178 def delete_startupfiles(self):
1409 # The startupfiles will have been installed to the target boot1179 # The startupfiles will have been installed to the target boot
1410 # partition by the hwpack, and should be deleted so we don't leave1180 # partition by the hwpack, and should be deleted so we don't leave
1411 # them on the target system.1181 # them on the target system.
1412 return True1182 return True
14131183
1414 @classmethod1184 def install_snowball_boot_loader(self, toc_file_name, files,
1415 def install_snowball_boot_loader(cls, toc_file_name, files,
1416 boot_device_or_file, start_sector,1185 boot_device_or_file, start_sector,
1417 delete_startupfiles=False):1186 delete_startupfiles=False):
1418 ''' Copies TOC and boot files into the boot partition.1187 ''' Copies TOC and boot files into the boot partition.
1419 A sector size of 1 is used for some files, as they do not1188 A sector size of 1 is used for some files, as they do not
1420 necessarily start on an even address. '''1189 necessarily start on an even address. '''
1421 assert os.path.getsize(toc_file_name) <= cls.TOC_SIZE1190 assert os.path.getsize(toc_file_name) <= self.TOC_SIZE
1422 _dd(toc_file_name, boot_device_or_file, seek=start_sector)1191 _dd(toc_file_name, boot_device_or_file, seek=start_sector)
14231192
1424 for file in files:1193 for file in files:
@@ -1433,16 +1202,14 @@
1433 seek_sectors = start_sector + file['offset'] / SECTOR_SIZE1202 seek_sectors = start_sector + file['offset'] / SECTOR_SIZE
1434 _dd(filename, boot_device_or_file, seek=seek_sectors)1203 _dd(filename, boot_device_or_file, seek=seek_sectors)
1435 if delete_startupfiles:1204 if delete_startupfiles:
1436 cls.delete_file(filename)1205 self.delete_file(filename)
14371206
1438 @classmethod1207 def delete_file(self, file_path):
1439 def delete_file(cls, file_path):
1440 cmd = ["rm", "%s" % file_path]1208 cmd = ["rm", "%s" % file_path]
1441 proc = cmd_runner.run(cmd, as_root=True)1209 proc = cmd_runner.run(cmd, as_root=True)
1442 proc.wait()1210 proc.wait()
14431211
1444 @classmethod1212 def create_toc(self, f, files):
1445 def create_toc(cls, f, files):
1446 ''' Writes a table of contents of the boot binaries.1213 ''' Writes a table of contents of the boot binaries.
1447 Boot rom searches this table to find the binaries.'''1214 Boot rom searches this table to find the binaries.'''
1448 # Format string means: < little endian,1215 # Format string means: < little endian,
@@ -1464,15 +1231,14 @@
1464 file['section_name'])1231 file['section_name'])
1465 f.write(data)1232 f.write(data)
14661233
1467 @classmethod1234 def get_file_info(self, chroot_dir, config_files_dir):
1468 def get_file_info(cls, chroot_dir, config_files_dir):
1469 ''' Fills in the offsets of files that are located in1235 ''' Fills in the offsets of files that are located in
1470 non-absolute memory locations depending on their sizes.'1236 non-absolute memory locations depending on their sizes.'
1471 Also fills in file sizes'''1237 Also fills in file sizes'''
1472 ofs = cls.TOC_SIZE1238 ofs = self.TOC_SIZE
1473 files = []1239 files = []
1474 with open(os.path.join(config_files_dir,1240 with open(os.path.join(config_files_dir,
1475 cls.snowball_startup_files_config),1241 self.snowball_startup_files_config),
1476 'r') as info_file:1242 'r') as info_file:
1477 for line in info_file:1243 for line in info_file:
1478 file_data = line.split()1244 file_data = line.split()
@@ -1503,23 +1269,16 @@
15031269
15041270
1505class Mx5Config(BoardConfig):1271class Mx5Config(BoardConfig):
1506 serial_tty = 'ttymxc0'1272 def __init__(self):
1507 _extra_serial_opts = 'console=tty0 console=%s,115200n8'1273 super(Mx5Config, self).__init__()
1508 _live_serial_opts = 'serialtty=%s'1274 self.boot_script = 'boot.scr'
1509 boot_script = 'boot.scr'1275 self.mmc_option = '0:2'
1510 mmc_part_offset = 11276 self.mmc_part_offset = 1
1511 mmc_option = '0:2'1277 self.serial_tty = 'ttymxc0'
15121278 self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1513 @classproperty1279 self._live_serial_opts = 'serialtty=%s'
1514 def live_serial_opts(cls):1280
1515 return cls._live_serial_opts % cls.serial_tty1281 def get_v1_sfdisk_cmd(self, should_align_boot_part=None):
1516
1517 @classproperty
1518 def extra_serial_opts(cls):
1519 return cls._extra_serial_opts % cls.serial_tty
1520
1521 @classmethod
1522 def get_v1_sfdisk_cmd(cls, should_align_boot_part=None):
1523 """Return the sfdisk command to partition the media.1282 """Return the sfdisk command to partition the media.
15241283
1525 :param should_align_boot_part: Ignored.1284 :param should_align_boot_part: Ignored.
@@ -1533,103 +1292,107 @@
1533 # onwards, so it's safer to just start at the first sector, sector 11292 # onwards, so it's safer to just start at the first sector, sector 1
1534 # (sector 0 is MBR / partition table)1293 # (sector 0 is MBR / partition table)
1535 loader_start, loader_end, loader_len = align_partition(1294 loader_start, loader_end, loader_len = align_partition(
1536 1, cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)1295 1, self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
15371296
1538 boot_start, boot_end, boot_len = align_partition(1297 boot_start, boot_end, boot_len = align_partition(
1539 loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)1298 loader_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1540 # we ignore _root_end / _root_len and return a sfdisk command to1299 # we ignore _root_end / _root_len and return a sfdisk command to
1541 # instruct the use of all remaining space; XXX if we had some root size1300 # instruct the use of all remaining space; XXX if we had some root size
1542 # config, we could do something more sensible1301 # config, we could do something more sensible
1543 root_start, _root_end, _root_len = align_partition(1302 root_start, _root_end, _root_len = align_partition(
1544 boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)1303 boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
15451304
1546 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (1305 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
1547 loader_start, loader_len, boot_start, boot_len, root_start)1306 loader_start, loader_len, boot_start, boot_len, root_start)
15481307
1549 @classmethod1308 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1550 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1551 boot_device_or_file, k_img_data, i_img_data,1309 boot_device_or_file, k_img_data, i_img_data,
1552 d_img_data):1310 d_img_data):
1553 # XXX: delete this method when hwpacks V1 can die1311 # XXX: delete this method when hwpacks V1 can die
1554 assert cls.hwpack_format == HardwarepackHandler.FORMAT_11312 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1555 with cls.hardwarepack_handler:1313 with self.hardwarepack_handler:
1556 bootloader_file = cls.get_file('bootloader_file',1314 bootloader_file = self.get_file('bootloader_file',
1557 default=os.path.join(1315 default=os.path.join(
1558 chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor,1316 chroot_dir, 'usr', 'lib', 'u-boot', self.bootloader_flavor,
1559 'u-boot.imx'))1317 'u-boot.imx'))
1560 install_mx5_boot_loader(bootloader_file, boot_device_or_file,1318 install_mx5_boot_loader(bootloader_file, boot_device_or_file,
1561 cls.LOADER_MIN_SIZE_S)1319 self.LOADER_MIN_SIZE_S)
1562 make_uImage(cls.load_addr, k_img_data, boot_dir)1320 make_uImage(self.load_addr, k_img_data, boot_dir)
1563 make_uInitrd(i_img_data, boot_dir)1321 make_uInitrd(i_img_data, boot_dir)
1564 make_dtb(d_img_data, boot_dir)1322 make_dtb(d_img_data, boot_dir)
1565 boot_script_path = os.path.join(boot_dir, cls.boot_script)1323 boot_script_path = os.path.join(boot_dir, self.boot_script)
1566 make_boot_script(boot_env, boot_script_path)1324 make_boot_script(boot_env, boot_script_path)
15671325
15681326
1569class Mx51Config(Mx5Config):1327class Mx51Config(Mx5Config):
1570 kernel_addr = '0x90000000'1328 def __init__(self):
1571 dtb_addr = '0x91ff0000'1329 super(Mx51Config, self).__init__()
1572 initrd_addr = '0x92000000'1330 self.dtb_addr = '0x91ff0000'
1573 load_addr = '0x90008000'1331 self.initrd_addr = '0x92000000'
1574 kernel_flavors = ['linaro-mx51', 'linaro-lt-mx5']1332 self.kernel_addr = '0x90000000'
1333 self.kernel_flavors = ['linaro-mx51', 'linaro-lt-mx5']
1334 self.load_addr = '0x90008000'
15751335
15761336
1577class Mx53Config(Mx5Config):1337class Mx53Config(Mx5Config):
1578 kernel_addr = '0x70000000'1338 def __init__(self):
1579 dtb_addr = '0x71ff0000'1339 super(Mx53Config, self).__init__()
1580 initrd_addr = '0x72000000'1340 self.dtb_addr = '0x71ff0000'
1581 load_addr = '0x70008000'1341 self.initrd_addr = '0x72000000'
1582 kernel_flavors = ['linaro-lt-mx53', 'linaro-lt-mx5']1342 self.kernel_addr = '0x70000000'
1343 self.kernel_flavors = ['linaro-lt-mx53', 'linaro-lt-mx5']
1344 self.load_addr = '0x70008000'
15831345
15841346
1585class EfikamxConfig(Mx51Config):1347class EfikamxConfig(Mx51Config):
1586 bootloader_flavor = 'efikamx'1348 def __init__(self):
1587 dtb_name = 'genesi-efikamx.dtb'1349 super(EfikamxConfig, self).__init__()
1350 self.bootloader_flavor = 'efikamx'
1351 self.dtb_name = 'genesi-efikamx.dtb'
15881352
15891353
1590class EfikasbConfig(Mx51Config):1354class EfikasbConfig(Mx51Config):
1591 bootloader_flavor = 'efikasb'1355 def __init__(self):
1592 dtb_name = 'genesi-efikasb.dtb'1356 super(EfikasbConfig, self).__init__()
1357 self.bootloader_flavor = 'efikasb'
1358 self.dtb_name = 'genesi-efikasb.dtb'
15931359
15941360
1595class Mx51evkConfig(Mx51Config):1361class Mx51evkConfig(Mx51Config):
1596 bootloader_flavor = 'mx51evk'1362 def __init__(self):
1597 dtb_name = 'mx51-babbage.dtb'1363 super(Mx51evkConfig, self).__init__()
1364 self.bootloader_flavor = 'mx51evk'
1365 self.dtb_name = 'mx51-babbage.dtb'
15981366
15991367
1600class Mx53LoCoConfig(Mx53Config):1368class Mx53LoCoConfig(Mx53Config):
1601 bootloader_flavor = 'mx53loco'1369 def __init__(self):
1602 dtb_name = 'mx53-loco.dtb'1370 super(Mx53LoCoConfig, self).__init__()
1371 self.bootloader_flavor = 'mx53loco'
1372 self.dtb_name = 'mx53-loco.dtb'
16031373
16041374
1605class VexpressConfig(BoardConfig):1375class VexpressConfig(BoardConfig):
1606 bootloader_flavor = 'ca9x4_ct_vxp'1376 def __init__(self):
1607 bootloader_file_in_boot_part = True1377 super(VexpressConfig, self).__init__()
1608 serial_tty = 'ttyAMA0'1378 self.boot_script = 'boot.scr'
1609 _extra_serial_opts = 'console=tty0 console=%s,38400n8'1379 self.bootloader_file_in_boot_part = True
1610 _live_serial_opts = 'serialtty=%s'1380 self.bootloader_flavor = 'ca9x4_ct_vxp'
1611 kernel_addr = '0x60000000'1381 # ARM Boot Monitor is used to load u-boot, uImage etc. into flash and
1612 initrd_addr = '0x62000000'1382 # only allows for FAT16
1613 load_addr = '0x60008000'1383 self.fat_size = 16
1614 kernel_flavors = ['linaro-vexpress']1384 self.initrd_addr = '0x62000000'
1615 boot_script = 'boot.scr'1385 self.kernel_addr = '0x60000000'
1616 # ARM Boot Monitor is used to load u-boot, uImage etc. into flash and1386 self.kernel_flavors = ['linaro-vexpress']
1617 # only allows for FAT161387 self.load_addr = '0x60008000'
1618 fat_size = 161388 self.serial_tty = 'ttyAMA0'
16191389 self._extra_serial_opts = 'console=tty0 console=%s,38400n8'
1620 @classproperty1390 self._live_serial_opts = 'serialtty=%s'
1621 def live_serial_opts(cls):1391
1622 return cls._live_serial_opts % cls.serial_tty1392 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1623
1624 @classproperty
1625 def extra_serial_opts(cls):
1626 return cls._extra_serial_opts % cls.serial_tty
1627
1628 @classmethod
1629 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1630 boot_device_or_file, k_img_data, i_img_data,1393 boot_device_or_file, k_img_data, i_img_data,
1631 d_img_data):1394 d_img_data):
1632 make_uImage(cls.load_addr, k_img_data, boot_dir)1395 make_uImage(self.load_addr, k_img_data, boot_dir)
1633 make_uInitrd(i_img_data, boot_dir)1396 make_uInitrd(i_img_data, boot_dir)
16341397
16351398
@@ -1637,22 +1400,23 @@
1637 # For now, this is a duplicate of VexpressConfig.1400 # For now, this is a duplicate of VexpressConfig.
1638 # In future, there will also be A5 and A15 variants.1401 # In future, there will also be A5 and A15 variants.
1639 # For all of these, there should never be any V1 hardware packs.1402 # For all of these, there should never be any V1 hardware packs.
1640 pass1403 def __init__(self):
1404 super(VexpressA9Config, self).__init__()
16411405
16421406
1643class FastModelConfig(BoardConfig):1407class FastModelConfig(BoardConfig):
1644 supports_writing_to_mmc = False1408 def __init__(self):
1409 super(FastModelConfig, self).__init__()
1410 self.supports_writing_to_mmc = False
16451411
1646 @classmethod1412 def _get_bootcmd(self, i_img_data, d_img_data):
1647 def _get_bootcmd(cls, i_img_data, d_img_data):
1648 """Get the bootcmd for FastModel.1413 """Get the bootcmd for FastModel.
16491414
1650 We override this as we don't do uboot.1415 We override this as we don't do uboot.
1651 """1416 """
1652 return ""1417 return ""
16531418
1654 @classmethod1419 def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
1655 def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir,
1656 boot_device_or_file, k_img_data, i_img_data,1420 boot_device_or_file, k_img_data, i_img_data,
1657 d_img_data):1421 d_img_data):
1658 output_dir = os.path.dirname(boot_device_or_file)1422 output_dir = os.path.dirname(boot_device_or_file)
@@ -1669,16 +1433,15 @@
16691433
16701434
1671class SamsungConfig(BoardConfig):1435class SamsungConfig(BoardConfig):
1672 @classproperty1436 def __init__(self):
1673 def extra_serial_opts(cls):1437 super(SamsungConfig, self).__init__()
1674 return cls._extra_serial_opts % cls.serial_tty1438 self._extra_serial_opts = None
16751439
1676 @classmethod1440 def get_v1_sfdisk_cmd(self, should_align_boot_part=False):
1677 def get_v1_sfdisk_cmd(cls, should_align_boot_part=False):
1678 # bootloaders partition needs to hold BL1, U-Boot environment, and BL21441 # bootloaders partition needs to hold BL1, U-Boot environment, and BL2
1679 loaders_min_len = (1442 loaders_min_len = (
1680 cls.SAMSUNG_V310_BL2_START + cls.SAMSUNG_V310_BL2_LEN -1443 self.samsung_v310_bl2_start + self.samsung_v310_bl2_len -
1681 cls.SAMSUNG_V310_BL1_START)1444 self.samsung_v310_bl1_start)
16821445
1683 # bootloaders partition1446 # bootloaders partition
1684 loaders_start, loaders_end, loaders_len = align_partition(1447 loaders_start, loaders_end, loaders_len = align_partition(
@@ -1686,44 +1449,42 @@
16861449
1687 # FAT boot partition1450 # FAT boot partition
1688 boot_start, boot_end, boot_len = align_partition(1451 boot_start, boot_end, boot_len = align_partition(
1689 loaders_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)1452 loaders_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
16901453
1691 # root partition1454 # root partition
1692 # we ignore _root_end / _root_len and return a sfdisk command to1455 # we ignore _root_end / _root_len and return a sfdisk command to
1693 # instruct the use of all remaining space; XXX if we had some root size1456 # instruct the use of all remaining space; XXX if we had some root size
1694 # config, we could do something more sensible1457 # config, we could do something more sensible
1695 root_start, _root_end, _root_len = align_partition(1458 root_start, _root_end, _root_len = align_partition(
1696 boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)1459 boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
16971460
1698 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (1461 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
1699 loaders_start, loaders_len, boot_start, boot_len, root_start)1462 loaders_start, loaders_len, boot_start, boot_len, root_start)
17001463
1701 @classmethod1464 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1702 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1703 boot_device_or_file, k_img_data, i_img_data,1465 boot_device_or_file, k_img_data, i_img_data,
1704 d_img_data):1466 d_img_data):
1705 # XXX: delete this method when hwpacks V1 can die1467 # XXX: delete this method when hwpacks V1 can die
1706 assert cls.hwpack_format == HardwarepackHandler.FORMAT_11468 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1707 cls.install_samsung_boot_loader(cls._get_samsung_spl(chroot_dir),1469 self.install_samsung_boot_loader(self._get_samsung_spl(chroot_dir),
1708 cls._get_samsung_bootloader(chroot_dir), boot_device_or_file)1470 self._get_samsung_bootloader(chroot_dir), boot_device_or_file)
1709 env_size = cls.SAMSUNG_V310_ENV_LEN * SECTOR_SIZE1471 env_size = self.samsung_v310_env_len * SECTOR_SIZE
1710 env_file = make_flashable_env(boot_env, env_size)1472 env_file = make_flashable_env(boot_env, env_size)
1711 _dd(env_file, boot_device_or_file, seek=cls.SAMSUNG_V310_ENV_START)1473 _dd(env_file, boot_device_or_file, seek=self.samsung_v310_env_start)
17121474
1713 make_uImage(cls.load_addr, k_img_data, boot_dir)1475 make_uImage(self.load_addr, k_img_data, boot_dir)
1714 make_uInitrd(i_img_data, boot_dir)1476 make_uInitrd(i_img_data, boot_dir)
17151477
1716 # unused at the moment once FAT support enabled for the1478 # unused at the moment once FAT support enabled for the
1717 # Samsung u-boot this can be used bug 7279781479 # Samsung u-boot this can be used bug 727978
1718 boot_script_path = os.path.join(boot_dir, cls.boot_script)1480 boot_script_path = os.path.join(boot_dir, self.boot_script)
1719 make_boot_script(boot_env, boot_script_path)1481 make_boot_script(boot_env, boot_script_path)
17201482
1721 @classmethod1483 def _get_samsung_spl(self, chroot_dir):
1722 def _get_samsung_spl(cls, chroot_dir):
1723 # XXX: delete this method when hwpacks V1 can die1484 # XXX: delete this method when hwpacks V1 can die
1724 assert cls.hwpack_format == HardwarepackHandler.FORMAT_11485 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1725 spl_dir = os.path.join(1486 spl_dir = os.path.join(
1726 chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor)1487 chroot_dir, 'usr', 'lib', 'u-boot', self.bootloader_flavor)
1727 old_spl_path = os.path.join(spl_dir, 'v310_mmc_spl.bin')1488 old_spl_path = os.path.join(spl_dir, 'v310_mmc_spl.bin')
1728 new_spl_path = os.path.join(spl_dir, 'u-boot-mmc-spl.bin')1489 new_spl_path = os.path.join(spl_dir, 'u-boot-mmc-spl.bin')
1729 new_new_spl_path = os.path.join(spl_dir, 'origen-spl.bin')1490 new_new_spl_path = os.path.join(spl_dir, 'origen-spl.bin')
@@ -1743,49 +1504,48 @@
1743 % (old_spl_path, new_spl_path))1504 % (old_spl_path, new_spl_path))
1744 return spl_file1505 return spl_file
17451506
1746 @classmethod1507 def _get_samsung_bootloader(self, chroot_dir):
1747 def _get_samsung_bootloader(cls, chroot_dir):
1748 # XXX: delete this method when hwpacks V1 can die1508 # XXX: delete this method when hwpacks V1 can die
1749 assert cls.hwpack_format == HardwarepackHandler.FORMAT_11509 assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1750 bootloader_file = os.path.join(1510 bootloader_file = os.path.join(
1751 chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor,1511 chroot_dir, 'usr', 'lib', 'u-boot', self.bootloader_flavor,
1752 'u-boot.bin')1512 'u-boot.bin')
1753 return bootloader_file1513 return bootloader_file
17541514
1755 @classmethod1515 def populate_raw_partition(self, boot_device_or_file, chroot_dir):
1756 def populate_raw_partition(cls, boot_device_or_file, chroot_dir):
1757 # Zero the env so that the boot_script will get loaded1516 # Zero the env so that the boot_script will get loaded
1758 _dd("/dev/zero", boot_device_or_file, count=cls.SAMSUNG_V310_ENV_LEN,1517 _dd("/dev/zero", boot_device_or_file, count=self.samsung_v310_env_len,
1759 seek=cls.SAMSUNG_V310_ENV_START)1518 seek=self.samsung_v310_env_start)
1760 # Populate created raw partition with BL1 and u-boot1519 # Populate created raw partition with BL1 and u-boot
1761 spl_file = os.path.join(chroot_dir, 'boot', 'u-boot-mmc-spl.bin')1520 spl_file = os.path.join(chroot_dir, 'boot', 'u-boot-mmc-spl.bin')
1762 assert os.path.getsize(spl_file) <= (1521 assert os.path.getsize(spl_file) <= (
1763 cls.SAMSUNG_V310_BL1_LEN * SECTOR_SIZE), (1522 self.samsung_v310_bl1_len * SECTOR_SIZE), (
1764 "%s is larger than SAMSUNG_V310_BL1_LEN" % spl_file)1523 "%s is larger than samsung_v310_bl1_len" % spl_file)
1765 _dd(spl_file, boot_device_or_file, seek=cls.SAMSUNG_V310_BL1_START)1524 _dd(spl_file, boot_device_or_file, seek=self.samsung_v310_bl1_start)
1766 uboot_file = os.path.join(chroot_dir, 'boot', 'u-boot.bin')1525 uboot_file = os.path.join(chroot_dir, 'boot', 'u-boot.bin')
1767 assert os.path.getsize(uboot_file) <= (1526 assert os.path.getsize(uboot_file) <= (
1768 cls.SAMSUNG_V310_BL2_LEN * SECTOR_SIZE), (1527 self.samsung_v310_bl2_len * SECTOR_SIZE), (
1769 "%s is larger than SAMSUNG_V310_BL2_LEN" % uboot_file)1528 "%s is larger than samsung_v310_bl2_len" % uboot_file)
1770 _dd(uboot_file, boot_device_or_file, seek=cls.SAMSUNG_V310_BL2_START)1529 _dd(uboot_file, boot_device_or_file, seek=self.samsung_v310_bl2_start)
17711530
17721531
1773class SMDKV310Config(SamsungConfig):1532class SMDKV310Config(SamsungConfig):
1774 bootloader_flavor = 'smdkv310'1533 def __init__(self):
1775 serial_tty = 'ttySAC1'1534 super(SMDKV310Config, self).__init__()
1776 _extra_serial_opts = 'console=%s,115200n8'1535 self.boot_script = 'boot.scr'
1777 kernel_addr = '0x40007000'1536 self.bootloader_flavor = 'smdkv310'
1778 initrd_addr = '0x42000000'1537 self.initrd_addr = '0x42000000'
1779 load_addr = '0x40008000'1538 self.kernel_addr = '0x40007000'
1780 kernel_flavors = ['s5pv310']1539 self.kernel_flavors = ['s5pv310']
1781 boot_script = 'boot.scr'1540 self.load_addr = '0x40008000'
1782 mmc_part_offset = 11541 self.mmc_option = '0:2'
1783 mmc_option = '0:2'1542 self.mmc_part_offset = 1
1543 self.serial_tty = 'ttySAC1'
1544 self._extra_serial_opts = 'console=%s,115200n8'
17841545
1785 @classmethod1546 def _get_boot_env(self, is_live, is_lowmem, consoles, rootfs_id,
1786 def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
1787 i_img_data, d_img_data):1547 i_img_data, d_img_data):
1788 boot_env = super(SamsungConfig, cls)._get_boot_env(1548 boot_env = super(SamsungConfig, self)._get_boot_env(
1789 is_live, is_lowmem, consoles, rootfs_id, i_img_data, d_img_data)1549 is_live, is_lowmem, consoles, rootfs_id, i_img_data, d_img_data)
17901550
1791 boot_env["ethact"] = "smc911x-0"1551 boot_env["ethact"] = "smc911x-0"
@@ -1795,27 +1555,22 @@
17951555
17961556
1797class OrigenConfig(SamsungConfig):1557class OrigenConfig(SamsungConfig):
1798 bootloader_flavor = 'origen'1558 # TODO test
1799 serial_tty = 'ttySAC2'1559 def __init__(self):
1800 _extra_serial_opts = 'console=%s,115200n8'1560 super(OrigenConfig, self).__init__()
1801 kernel_addr = '0x40007000'1561 self.boot_script = 'boot.scr'
1802 initrd_addr = '0x42000000'1562 self.bootloader_flavor = 'origen'
1803 load_addr = '0x40008000'1563 self.initrd_addr = '0x42000000'
1804 kernel_flavors = ['origen']1564 self.kernel_addr = '0x40007000'
1805 boot_script = 'boot.scr'1565 self.kernel_flavors = ['origen']
1806 mmc_part_offset = 11566 self.load_addr = '0x40008000'
1807 mmc_option = '0:2'1567 self.mmc_option = '0:2'
1568 self.mmc_part_offset = 1
1569 self.serial_tty = 'ttySAC2'
1570 self._extra_serial_opts = 'console=%s,115200n8'
18081571
18091572
1810class I386Config(BoardConfig):1573class I386Config(BoardConfig):
1811 # define serial
1812 serial_tty = 'ttyS0'
1813 _extra_serial_opts = 'console=tty0 console=%s,115200n8'
1814 _live_serial_opts = 'serialtty=%s'
1815
1816 # define kernel image
1817 kernel_flavors = ['generic', 'pae']
1818
1819 # define bootloader1574 # define bootloader
1820 BOOTLOADER_CMD = 'grub-install'1575 BOOTLOADER_CMD = 'grub-install'
1821 BOOTLOADER_CFG_FILE = 'grub/grub.cfg'1576 BOOTLOADER_CFG_FILE = 'grub/grub.cfg'
@@ -1827,16 +1582,14 @@
1827 initrd /%s1582 initrd /%s
1828 }"""1583 }"""
18291584
1830 @classproperty1585 def __init__(self):
1831 def live_serial_opts(cls):1586 super(I386Config, self).__init__()
1832 return cls._live_serial_opts % cls.serial_tty1587 self.kernel_flavors = ['generic', 'pae']
18331588 self.serial_tty = 'ttyS0'
1834 @classproperty1589 self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1835 def extra_serial_opts(cls):1590 self._live_serial_opts = 'serialtty=%s'
1836 return cls._extra_serial_opts % cls.serial_tty1591
18371592 def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1838 @classmethod
1839 def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1840 boot_device_or_file, k_img_data, i_img_data,1593 boot_device_or_file, k_img_data, i_img_data,
1841 d_img_data):1594 d_img_data):
1842 # copy image and init into boot partition1595 # copy image and init into boot partition
@@ -1849,13 +1602,13 @@
1849 img_loop = register_loopback(boot_device_or_file, 0, img_size)1602 img_loop = register_loopback(boot_device_or_file, 0, img_size)
18501603
1851 # install bootloader1604 # install bootloader
1852 cmd_runner.run([cls.BOOTLOADER_CMD, '--boot-directory=%s' % boot_dir,1605 cmd_runner.run([self.BOOTLOADER_CMD, '--boot-directory=%s' % boot_dir,
1853 '--modules', 'part_msdos', img_loop],1606 '--modules', 'part_msdos', img_loop],
1854 as_root=True).wait()1607 as_root=True).wait()
18551608
1856 # generate loader config file1609 # generate loader config file
1857 loader_config = cls.BOOTLOADER_CFG % (os.path.basename(k_img_data),1610 loader_config = self.BOOTLOADER_CFG % (os.path.basename(k_img_data),
1858 cls.extra_serial_opts, os.path.basename(i_img_data))1611 self.extra_serial_opts, os.path.basename(i_img_data))
18591612
1860 _, tmpfile = tempfile.mkstemp()1613 _, tmpfile = tempfile.mkstemp()
1861 atexit.register(os.unlink, tmpfile)1614 atexit.register(os.unlink, tmpfile)
@@ -1863,40 +1616,57 @@
1863 fd.write(loader_config)1616 fd.write(loader_config)
18641617
1865 cmd_runner.run(['cp', tmpfile, os.path.join(boot_dir,1618 cmd_runner.run(['cp', tmpfile, os.path.join(boot_dir,
1866 cls.BOOTLOADER_CFG_FILE)], as_root=True).wait()1619 self.BOOTLOADER_CFG_FILE)], as_root=True).wait()
18671620
1868 @classmethod1621 def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
1869 def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir,
1870 boot_device_or_file, k_img_data, i_img_data,1622 boot_device_or_file, k_img_data, i_img_data,
1871 d_img_data):1623 d_img_data):
1872 # reuse hwpack v1 function1624 # reuse hwpack v1 function
1873 cls._make_boot_files(boot_env, chroot_dir, boot_dir,1625 self._make_boot_files(boot_env, chroot_dir, boot_dir,
1874 boot_device_or_file, k_img_data, i_img_data,1626 boot_device_or_file, k_img_data, i_img_data,
1875 d_img_data)1627 d_img_data)
1628
1629
1630class BoardConfigException(Exception):
1631 """General board config exception."""
18761632
18771633
1878board_configs = {1634board_configs = {
1879 'beagle': BeagleConfig,1635 'beagle': BeagleConfig,
1880 'igep': IgepConfig,
1881 'panda': PandaConfig,
1882 'vexpress': VexpressConfig,
1883 'vexpress-a9': VexpressA9Config,
1884 'fastmodel': FastModelConfig,
1885 'ux500': Ux500Config,
1886 'snowball_sd': SnowballSdConfig,
1887 'snowball_emmc': SnowballEmmcConfig,
1888 'efikamx': EfikamxConfig,1636 'efikamx': EfikamxConfig,
1889 'efikasb': EfikasbConfig,1637 'efikasb': EfikasbConfig,
1638 'fastmodel': FastModelConfig,
1639 'i386': I386Config,
1640 'igep': IgepConfig,
1890 'mx51evk': Mx51evkConfig,1641 'mx51evk': Mx51evkConfig,
1891 'mx53loco': Mx53LoCoConfig,1642 'mx53loco': Mx53LoCoConfig,
1643 'mx6qsabrelite': BoardConfig,
1644 'origen': OrigenConfig,
1892 'overo': OveroConfig,1645 'overo': OveroConfig,
1646 'panda': PandaConfig,
1893 'smdkv310': SMDKV310Config,1647 'smdkv310': SMDKV310Config,
1894 'origen': OrigenConfig,1648 'snowball_emmc': SnowballEmmcConfig,
1895 'mx6qsabrelite': BoardConfig,1649 'snowball_sd': SnowballSdConfig,
1896 'i386': I386Config,1650 'ux500': Ux500Config,
1651 'vexpress': VexpressConfig,
1652 'vexpress-a9': VexpressA9Config,
1897 }1653 }
18981654
18991655
1656def get_board_config(board):
1657 """Get the board configuration for the specified board.
1658
1659 :param board: The name of the board to get the configuration of.
1660 :type board: str
1661 """
1662 clazz = board_configs.get(board, None)
1663 if clazz:
1664 return clazz()
1665 else:
1666 raise BoardConfigException("Board name '%s' has no configuration "
1667 "available." % board)
1668
1669
1900def _dd(input_file, output_file, block_size=SECTOR_SIZE, count=None, seek=None,1670def _dd(input_file, output_file, block_size=SECTOR_SIZE, count=None, seek=None,
1901 skip=None):1671 skip=None):
1902 """Wrapper around the dd command"""1672 """Wrapper around the dd command"""
19031673
=== modified file 'linaro_image_tools/media_create/chroot_utils.py'
--- linaro_image_tools/media_create/chroot_utils.py 2012-10-04 09:12:57 +0000
+++ linaro_image_tools/media_create/chroot_utils.py 2012-11-20 10:49:03 +0000
@@ -25,7 +25,7 @@
25 is_arm_host,25 is_arm_host,
26 find_command,26 find_command,
27 )27 )
28from linaro_image_tools.media_create.boards import HardwarepackHandler28from linaro_image_tools.hwpack.handler import HardwarepackHandler
2929
30# It'd be nice if we could use atexit here, but all the things we need to undo30# It'd be nice if we could use atexit here, but all the things we need to undo
31# have to happen right after install_hwpacks completes and the atexit31# have to happen right after install_hwpacks completes and the atexit
3232
=== modified file 'linaro_image_tools/media_create/tests/__init__.py'
--- linaro_image_tools/media_create/tests/__init__.py 2012-06-07 13:12:42 +0000
+++ linaro_image_tools/media_create/tests/__init__.py 2012-11-20 10:49:03 +0000
@@ -2,8 +2,10 @@
22
33
4def test_suite():4def test_suite():
5 module_names = ['linaro_image_tools.media_create.tests.test_media_create',5 module_names = [
6 ]6 'linaro_image_tools.media_create.tests.test_media_create',
7 'linaro_image_tools.media_create.tests.test_android_boards',
8 ]
7 loader = unittest.TestLoader()9 loader = unittest.TestLoader()
8 suite = loader.loadTestsFromNames(module_names)10 suite = loader.loadTestsFromNames(module_names)
9 return suite11 return suite
1012
=== added file 'linaro_image_tools/media_create/tests/test_android_boards.py'
--- linaro_image_tools/media_create/tests/test_android_boards.py 1970-01-01 00:00:00 +0000
+++ linaro_image_tools/media_create/tests/test_android_boards.py 2012-11-20 10:49:03 +0000
@@ -0,0 +1,249 @@
1# Copyright (C) 2010, 2011 Linaro
2#
3# Author: Milo Casagrande <milo.casagrande@linaro.org>
4#
5# This file is part of Linaro Image Tools.
6#
7# Linaro Image Tools is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# Linaro Image Tools is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20from StringIO import StringIO
21from testtools import TestCase
22
23from linaro_image_tools.media_create.boards import (
24 BoardConfigException,
25 )
26
27from linaro_image_tools.media_create.android_boards import (
28 AndroidBeagleConfig,
29 get_board_config,
30 )
31
32
33class TestAndroidBoards(TestCase):
34 """Class to test small things in android_boards."""
35
36 def test_get_board_config(self):
37 instance = get_board_config('beagle')
38 self.assertIsInstance(instance, AndroidBeagleConfig)
39
40 def test_get_board_config_wrong(self):
41 self.assertRaises(BoardConfigException, get_board_config, 'notadevice')
42
43
44class TestAndroidBoardsHwpack(TestCase):
45 """Class to test the new Android hwpack configuration file."""
46
47 def setUp(self):
48 super(TestAndroidBoardsHwpack, self).setUp()
49 # Pick a default board.
50 self.config = get_board_config('beagle')
51 self.hwpack_base = "format: 3.0\n"
52 self.fake_hwpack = (self.hwpack_base + "dtb_name: a_name\n"
53 "fdt_high: '0xFFFFFFFF'\nfat_size: 16\n")
54
55 def test_read_from_file(self):
56 conf = self.config.from_file(StringIO(self.fake_hwpack))
57 expected = {'format': 3.0, 'dtb_name': 'a_name',
58 'fdt_high': '0xFFFFFFFF', 'fat_size': 16}
59 self.assertEqual(expected, conf)
60
61 def test_android_specific_args(self):
62 """The field android_specific_args should be a concatenated string."""
63 specific_args = ("android_specific_args:\n - init=/init\n "
64 "- androidboot.console=ttyO2")
65 hwpack_config = self.hwpack_base + specific_args
66 self.config.from_file(StringIO(hwpack_config))
67 expected = 'init=/init androidboot.console=ttyO2'
68 self.assertEqual(expected, self.config.android_specific_args)
69
70 def test_extra_serial_options(self):
71 """The field extra_serial_options should be a concatenated string."""
72 extra_serial_opts = ("extra_serial_options:\n - console=tty0\n "
73 "- console=ttyO2,115200n8")
74 hwpack_config = self.hwpack_base + extra_serial_opts
75 self.config.from_file(StringIO(hwpack_config))
76 expected = 'console=tty0 console=ttyO2,115200n8'
77 self.assertEqual(expected, self.config.extra_serial_options)
78
79 def test_extra_boot_args_options(self):
80 """The field extra_boot_args_options should be a concatenated string.
81 Testing presence of a field defined in the parent class."""
82 extra_boot_args_options = ("extra_boot_args_options:\n "
83 "- earlyprintk\n - mem=128M@0\n "
84 "- mali.mali_mem=64M@128M\n")
85 hwpack_config = self.hwpack_base + extra_boot_args_options
86 self.config.from_file(StringIO(hwpack_config))
87 expected = 'earlyprintk mem=128M@0 mali.mali_mem=64M@128M'
88 self.assertEqual(expected, self.config.extra_boot_args_options)
89
90 def test_android_mx6(self):
91 android_mx6_config = (self.hwpack_base + "bootloader_flavor: "
92 "mx6qsabrelite\nextra_boot_args_options:\n - earlyprintk\n"
93 " - rootdelay=1\n - fixrtc\n - nocompcache\n - di1_primary\n"
94 " - tve\nextra_serial_options:\n - console=%s,115200n8\n"
95 "android_specific_args:\n - init=/init\n - "
96 "androidboot.console=%s\nkernel_addr: '0x10000000'\n"
97 "initrd_addr: '0x12000000'\nload_addr: '0x10008000'\ndtb_addr:"
98 " '0x11ff0000'\ndtb_name: board.dtb")
99 expected = {
100 'bootargs': 'console=ttymxc0,115200n8 '
101 'rootwait ro earlyprintk rootdelay=1 fixrtc '
102 'nocompcache di1_primary tve init=/init '
103 'androidboot.console=ttymxc0',
104 'bootcmd': 'fatload mmc 0:2 0x10000000 uImage; '
105 'fatload mmc 0:2 0x12000000 uInitrd; '
106 'fatload mmc 0:2 0x11ff0000 board.dtb; '
107 'bootm 0x10000000 0x12000000 0x11ff0000',
108 'fdt_high': '0xffffffff',
109 'initrd_high': '0xffffffff'}
110 config = get_board_config('mx6qsabrelite')
111 config.from_file(StringIO(android_mx6_config))
112 self.assertBootEnv(config, expected)
113
114 def test_panda(self):
115 panda_config = (self.hwpack_base + "bootloader_flavor: omap4_panda\n"
116 "dtb_addr: '0x815f0000'\ndtb_name: board.dtb\n"
117 "extra_serial_options:\n - console=ttyO2,115200n8\n"
118 "extra_boot_args_options:\n - earlyprintk\n"
119 " - fixrtc\n - nocompcache\n - vram=48M\n"
120 " - omapfb.vram=0:24M,1:24M\n - mem=456M@0x80000000\n"
121 " - mem=512M@0xA0000000\nandroid_specific_args:\n"
122 " - init=/init\n - androidboot.console=ttyO2")
123 # XXX: To fix bug 697824 we have to change class attributes of our
124 # OMAP board configs, and some tests do that so to make sure they
125 # don't interfere with us we'll reset that before doing anything.
126 config = get_board_config('panda')
127 config.from_file(StringIO(panda_config))
128 expected = {
129 'bootargs': 'console=ttyO2,115200n8 '
130 'rootwait ro earlyprintk fixrtc '
131 'nocompcache vram=48M omapfb.vram=0:24M,1:24M '
132 'mem=456M@0x80000000 mem=512M@0xA0000000 '
133 'init=/init androidboot.console=ttyO2',
134 'bootcmd': 'fatload mmc 0:1 0x80200000 uImage; '
135 'fatload mmc 0:1 0x81600000 uInitrd; '
136 'fatload mmc 0:1 0x815f0000 board.dtb; '
137 'bootm 0x80200000 0x81600000 0x815f0000',
138 'fdt_high': '0xffffffff',
139 'initrd_high': '0xffffffff'}
140 self.assertBootEnv(config, expected)
141
142 def test_android_snowball_sd(self):
143 snowball_config = (self.hwpack_base + "boot_script: boot.scr\n"
144 "fdt_high: '0x05000000'\ninitrd_addr: '0x05000000'\n"
145 "initrd_high: '0x06000000'\nextra_boot_args_options:\n "
146 "- earlyprintk\n - mem=128M@0\n - mali.mali_mem=64M@128M\n "
147 "- hwmem=168M@192M\n - mem=22M@360M\n - mem_issw=1M@383M\n "
148 "- mem=640M@384M\n - vmalloc=500M\nextra_serial_options:\n"
149 " - console=ttyAMA2,115200n8\nandroid_specific_args:\n "
150 "- init=/init\n - androidboot.console=ttyAMA2\n"
151 "dtb_name: board.dtb\ndtb_addr: '0x8000000'")
152 config = get_board_config('snowball_sd')
153 config.from_file(StringIO(snowball_config))
154 expected = {
155 'bootargs': 'console=ttyAMA2,115200n8 '
156 'rootwait ro earlyprintk '
157 'mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
158 'mem=22M@360M mem_issw=1M@383M mem=640M@384M '
159 'vmalloc=500M init=/init androidboot.console=ttyAMA2',
160 'bootcmd': 'fatload mmc 1:1 0x00100000 uImage; '
161 'fatload mmc 1:1 0x05000000 uInitrd; '
162 'fatload mmc 1:1 0x8000000 board.dtb; '
163 'bootm 0x00100000 0x05000000 0x8000000',
164 'fdt_high': '0x05000000',
165 'initrd_high': '0x06000000'}
166 self.assertBootEnv(config, expected)
167
168 def test_android_snowball_emmc(self):
169 snowball_config = (self.hwpack_base + "boot_script: boot.scr\n"
170 "fdt_high: '0x05000000'\ninitrd_addr: '0x05000000'\n"
171 "initrd_high: '0x06000000'\nextra_boot_args_options:\n "
172 "- earlyprintk\n - mem=128M@0\n - mali.mali_mem=64M@128M\n "
173 "- hwmem=168M@192M\n - mem=22M@360M\n - mem_issw=1M@383M\n "
174 "- mem=640M@384M\n - vmalloc=500M\nextra_serial_options:\n"
175 " - console=ttyAMA2,115200n8\nandroid_specific_args:\n "
176 "- init=/init\n - androidboot.console=ttyAMA2\n"
177 "dtb_name: board.dtb\ndtb_addr: '0x8000000'\nmmc_option: '0:2'")
178 config = get_board_config('snowball_emmc')
179 config.from_file(StringIO(snowball_config))
180 expected = {
181 'bootargs': 'console=ttyAMA2,115200n8 '
182 'rootwait ro earlyprintk '
183 'mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
184 'mem=22M@360M mem_issw=1M@383M mem=640M@384M '
185 'vmalloc=500M init=/init androidboot.console=ttyAMA2',
186 'bootcmd': 'fatload mmc 0:2 0x00100000 uImage; '
187 'fatload mmc 0:2 0x05000000 uInitrd; '
188 'fatload mmc 0:2 0x8000000 board.dtb; '
189 'bootm 0x00100000 0x05000000 0x8000000',
190 'fdt_high': '0x05000000',
191 'initrd_high': '0x06000000'}
192 self.assertBootEnv(config, expected)
193
194 def test_android_origen(self):
195 origen_config = (self.hwpack_base + "extra_serial_options:\n "
196 "- console=tty0\n - console=ttySAC2,115200n8\n"
197 "android_specific_args:\n - init=/init\n "
198 "- androidboot.console=ttySAC2")
199 config = get_board_config('origen')
200 config.from_file(StringIO(origen_config))
201 expected = {
202 'bootargs': 'console=tty0 console=ttySAC2,115200n8 '
203 'rootwait ro init=/init androidboot.console=ttySAC2',
204 'bootcmd': 'fatload mmc 0:2 0x40007000 uImage; '
205 'fatload mmc 0:2 0x42000000 uInitrd; '
206 'bootm 0x40007000 0x42000000',
207 'fdt_high': '0xffffffff',
208 'initrd_high': '0xffffffff'}
209 self.assertBootEnv(config, expected)
210
211 def test_android_vexpress(self):
212 vexpress_config = (self.hwpack_base + "extra_serial_options:\n "
213 "- console=tty0\n - console=ttyAMA0,38400n8\n"
214 "android_specific_args:\n - init=/init\n "
215 "- androidboot.console=ttyAMA0")
216 config = get_board_config('vexpress')
217 config.from_file(StringIO(vexpress_config))
218 expected = {
219 'bootargs': 'console=tty0 console=ttyAMA0,38400n8 '
220 'rootwait ro init=/init androidboot.console=ttyAMA0',
221 'bootcmd': 'fatload mmc 0:1 0x60000000 uImage; '
222 'fatload mmc 0:1 0x62000000 uInitrd; '
223 'bootm 0x60000000 0x62000000',
224 'fdt_high': '0xffffffff',
225 'initrd_high': '0xffffffff'}
226 self.assertBootEnv(config, expected)
227
228 def test_android_mx5(self):
229 mx5_config = (self.hwpack_base + "extra_boot_args_options:\n "
230 "- earlyprintk\n - rootdelay=1\n - fixrtc\n - nocompcache\n "
231 "- di1_primary\n - tve\nextra_serial_options:\n"
232 " - console=%s,115200n8\nandroid_specific_args:\n "
233 "- init=/init\n - androidboot.console=%s")
234 config = get_board_config('mx53loco')
235 config.from_file(mx5_config)
236 expected = {
237 'bootargs': 'console=ttymxc0,115200n8 '
238 'rootwait ro earlyprintk rootdelay=1 fixrtc '
239 'nocompcache di1_primary tve init=/init '
240 'androidboot.console=ttymxc0',
241 'bootcmd': 'fatload mmc 0:2 0x70000000 uImage; '
242 'fatload mmc 0:2 0x72000000 uInitrd; '
243 'bootm 0x70000000 0x72000000',
244 'fdt_high': '0xffffffff',
245 'initrd_high': '0xffffffff'}
246 self.assertBootEnv(config, expected)
247
248 def assertBootEnv(self, config, expected):
249 self.assertEqual(expected, config._get_boot_env(consoles=[]))
0250
=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
--- linaro_image_tools/media_create/tests/test_media_create.py 2012-10-17 08:59:25 +0000
+++ linaro_image_tools/media_create/tests/test_media_create.py 2012-11-20 10:49:03 +0000
@@ -36,6 +36,7 @@
36from testtools import TestCase36from testtools import TestCase
3737
38from linaro_image_tools import cmd_runner38from linaro_image_tools import cmd_runner
39from linaro_image_tools.hwpack.handler import HardwarepackHandler
39from linaro_image_tools.hwpack.packages import PackageMaker40from linaro_image_tools.hwpack.packages import PackageMaker
40import linaro_image_tools.media_create41import linaro_image_tools.media_create
41from linaro_image_tools.media_create import (42from linaro_image_tools.media_create import (
@@ -49,7 +50,6 @@
49 SECTOR_SIZE,50 SECTOR_SIZE,
50 align_up,51 align_up,
51 align_partition,52 align_partition,
52 board_configs,
53 get_plain_boot_script_contents,53 get_plain_boot_script_contents,
54 make_flashable_env,54 make_flashable_env,
55 install_mx5_boot_loader,55 install_mx5_boot_loader,
@@ -61,12 +61,11 @@
61 _get_file_matching,61 _get_file_matching,
62 _get_mlo_file,62 _get_mlo_file,
63 _run_mkimage,63 _run_mkimage,
64 HardwarepackHandler,
65 BoardConfig,64 BoardConfig,
65 get_board_config,
66 )66 )
67from linaro_image_tools.media_create.android_boards import (67from linaro_image_tools.media_create.android_boards import (
68 AndroidSnowballEmmcConfig,68 AndroidSnowballEmmcConfig,
69 android_board_configs,
70 )69 )
71from linaro_image_tools.media_create.chroot_utils import (70from linaro_image_tools.media_create.chroot_utils import (
72 copy_file,71 copy_file,
@@ -427,10 +426,9 @@
427 linaro_image_tools.media_create.boards, 'HardwarepackHandler',426 linaro_image_tools.media_create.boards, 'HardwarepackHandler',
428 self.MockHardwarepackHandler))427 self.MockHardwarepackHandler))
429428
430 class config(BoardConfig):429 board_conf = BoardConfig()
431 pass430 board_conf.set_metadata('ahwpack.tar.gz')
432 config.set_metadata('ahwpack.tar.gz')431 self.assertEquals(None, board_conf.kernel_addr)
433 self.assertEquals(None, config.kernel_addr)
434432
435 def test_sets_kernel_addr(self):433 def test_sets_kernel_addr(self):
436 self.useFixture(MockSomethingFixture(434 self.useFixture(MockSomethingFixture(
@@ -442,10 +440,9 @@
442 field_to_test: data_to_set,440 field_to_test: data_to_set,
443 }441 }
444442
445 class config(BoardConfig):443 board_conf = BoardConfig()
446 pass444 board_conf.set_metadata('ahwpack.tar.gz')
447 config.set_metadata('ahwpack.tar.gz')445 self.assertEquals(data_to_set, board_conf.kernel_addr)
448 self.assertEquals(data_to_set, config.kernel_addr)
449446
450 def test_sets_initrd_addr(self):447 def test_sets_initrd_addr(self):
451 self.useFixture(MockSomethingFixture(448 self.useFixture(MockSomethingFixture(
@@ -457,10 +454,9 @@
457 field_to_test: data_to_set,454 field_to_test: data_to_set,
458 }455 }
459456
460 class config(BoardConfig):457 board_conf = BoardConfig()
461 pass458 board_conf.set_metadata('ahwpack.tar.gz')
462 config.set_metadata('ahwpack.tar.gz')459 self.assertEquals(data_to_set, board_conf.initrd_addr)
463 self.assertEquals(data_to_set, config.initrd_addr)
464460
465 def test_sets_load_addr(self):461 def test_sets_load_addr(self):
466 self.useFixture(MockSomethingFixture(462 self.useFixture(MockSomethingFixture(
@@ -472,10 +468,9 @@
472 field_to_test: data_to_set,468 field_to_test: data_to_set,
473 }469 }
474470
475 class config(BoardConfig):471 board_conf = BoardConfig()
476 pass472 board_conf.set_metadata('ahwpack.tar.gz')
477 config.set_metadata('ahwpack.tar.gz')473 self.assertEquals(data_to_set, board_conf.load_addr)
478 self.assertEquals(data_to_set, config.load_addr)
479474
480 def test_sets_serial_tty(self):475 def test_sets_serial_tty(self):
481 self.useFixture(MockSomethingFixture(476 self.useFixture(MockSomethingFixture(
@@ -487,10 +482,9 @@
487 field_to_test: data_to_set,482 field_to_test: data_to_set,
488 }483 }
489484
490 class config(BoardConfig):485 board_conf = BoardConfig()
491 pass486 board_conf.set_metadata('ahwpack.tar.gz')
492 config.set_metadata('ahwpack.tar.gz')487 self.assertEquals(data_to_set, board_conf.serial_tty)
493 self.assertEquals(data_to_set, config.serial_tty)
494488
495 def test_sets_wired_interfaces(self):489 def test_sets_wired_interfaces(self):
496 self.useFixture(MockSomethingFixture(490 self.useFixture(MockSomethingFixture(
@@ -502,10 +496,9 @@
502 field_to_test: data_to_set,496 field_to_test: data_to_set,
503 }497 }
504498
505 class config(BoardConfig):499 board_conf = BoardConfig()
506 pass500 board_conf.set_metadata('ahwpack.tar.gz')
507 config.set_metadata('ahwpack.tar.gz')501 self.assertEquals(data_to_set, board_conf.wired_interfaces)
508 self.assertEquals(data_to_set, config.wired_interfaces)
509502
510 def test_sets_wireless_interfaces(self):503 def test_sets_wireless_interfaces(self):
511 self.useFixture(MockSomethingFixture(504 self.useFixture(MockSomethingFixture(
@@ -517,10 +510,9 @@
517 field_to_test: data_to_set,510 field_to_test: data_to_set,
518 }511 }
519512
520 class config(BoardConfig):513 board_conf = BoardConfig()
521 pass514 board_conf.set_metadata('ahwpack.tar.gz')
522 config.set_metadata('ahwpack.tar.gz')515 self.assertEquals(data_to_set, board_conf.wireless_interfaces)
523 self.assertEquals(data_to_set, config.wireless_interfaces)
524516
525 def test_sets_mmc_id(self):517 def test_sets_mmc_id(self):
526 self.useFixture(MockSomethingFixture(518 self.useFixture(MockSomethingFixture(
@@ -532,12 +524,11 @@
532 field_to_test: data_to_set,524 field_to_test: data_to_set,
533 }525 }
534526
535 class config(BoardConfig):527 board_conf = BoardConfig()
536 pass528 board_conf.set_metadata('ahwpack.tar.gz')
537 config.set_metadata('ahwpack.tar.gz')529 self.assertEquals(data_to_set, board_conf.mmc_option)
538 self.assertEquals(data_to_set, config.mmc_option)530 self.assertEquals(0, board_conf.mmc_device_id)
539 self.assertEquals(0, config.mmc_device_id)531 self.assertEquals(0, board_conf.mmc_part_offset)
540 self.assertEquals(0, config.mmc_part_offset)
541532
542 def test_sets_boot_min_size(self):533 def test_sets_boot_min_size(self):
543 self.useFixture(MockSomethingFixture(534 self.useFixture(MockSomethingFixture(
@@ -551,10 +542,9 @@
551 field_to_test: data_to_set,542 field_to_test: data_to_set,
552 }543 }
553544
554 class config(BoardConfig):545 board_conf = BoardConfig()
555 pass546 board_conf.set_metadata('ahwpack.tar.gz')
556 config.set_metadata('ahwpack.tar.gz')547 self.assertEquals(expected, board_conf.BOOT_MIN_SIZE_S)
557 self.assertEquals(expected, config.BOOT_MIN_SIZE_S)
558548
559 def test_sets_root_min_size(self):549 def test_sets_root_min_size(self):
560 self.useFixture(MockSomethingFixture(550 self.useFixture(MockSomethingFixture(
@@ -568,10 +558,9 @@
568 field_to_test: data_to_set,558 field_to_test: data_to_set,
569 }559 }
570560
571 class config(BoardConfig):561 board_conf = BoardConfig()
572 pass562 board_conf.set_metadata('ahwpack.tar.gz')
573 config.set_metadata('ahwpack.tar.gz')563 self.assertEquals(expected, board_conf.ROOT_MIN_SIZE_S)
574 self.assertEquals(expected, config.ROOT_MIN_SIZE_S)
575564
576 def test_sets_loader_min_size(self):565 def test_sets_loader_min_size(self):
577 self.useFixture(MockSomethingFixture(566 self.useFixture(MockSomethingFixture(
@@ -585,10 +574,9 @@
585 field_to_test: data_to_set,574 field_to_test: data_to_set,
586 }575 }
587576
588 class config(BoardConfig):577 board_conf = BoardConfig()
589 pass578 board_conf.set_metadata('ahwpack.tar.gz')
590 config.set_metadata('ahwpack.tar.gz')579 self.assertEquals(expected, board_conf.LOADER_MIN_SIZE_S)
591 self.assertEquals(expected, config.LOADER_MIN_SIZE_S)
592580
593 def test_sets_partition_layout_32(self):581 def test_sets_partition_layout_32(self):
594 self.useFixture(MockSomethingFixture(582 self.useFixture(MockSomethingFixture(
@@ -600,10 +588,9 @@
600 field_to_test: data_to_set,588 field_to_test: data_to_set,
601 }589 }
602590
603 class config(BoardConfig):591 board_conf = BoardConfig()
604 pass592 board_conf.set_metadata('ahwpack.tar.gz')
605 config.set_metadata('ahwpack.tar.gz')593 self.assertEquals(32, board_conf.fat_size)
606 self.assertEquals(32, config.fat_size)
607594
608 def test_sets_partition_layout_16(self):595 def test_sets_partition_layout_16(self):
609 self.useFixture(MockSomethingFixture(596 self.useFixture(MockSomethingFixture(
@@ -615,10 +602,9 @@
615 field_to_test: data_to_set,602 field_to_test: data_to_set,
616 }603 }
617604
618 class config(BoardConfig):605 board_conf = BoardConfig()
619 pass606 board_conf.set_metadata('ahwpack.tar.gz')
620 config.set_metadata('ahwpack.tar.gz')607 self.assertEquals(16, board_conf.fat_size)
621 self.assertEquals(16, config.fat_size)
622608
623 def test_sets_partition_layout_raises(self):609 def test_sets_partition_layout_raises(self):
624 self.useFixture(MockSomethingFixture(610 self.useFixture(MockSomethingFixture(
@@ -630,10 +616,9 @@
630 field_to_test: data_to_set,616 field_to_test: data_to_set,
631 }617 }
632618
633 class config(BoardConfig):619 board_conf = BoardConfig()
634 pass
635 self.assertRaises(620 self.assertRaises(
636 AssertionError, config.set_metadata, 'ahwpack.tar.gz')621 AssertionError, board_conf.set_metadata, 'ahwpack.tar.gz')
637622
638 def test_sets_copy_files(self):623 def test_sets_copy_files(self):
639 self.useFixture(MockSomethingFixture(624 self.useFixture(MockSomethingFixture(
@@ -647,10 +632,9 @@
647 field_to_test: data_to_set,632 field_to_test: data_to_set,
648 }633 }
649634
650 class config(BoardConfig):635 board_conf = BoardConfig()
651 pass636 board_conf.set_metadata('ahwpack.tar.gz')
652 config.set_metadata('ahwpack.tar.gz')637 self.assertEquals(data_to_set, board_conf.bootloader_copy_files)
653 self.assertEquals(data_to_set, config.bootloader_copy_files)
654638
655639
656class TestGetMLOFile(TestCaseWithFixtures):640class TestGetMLOFile(TestCaseWithFixtures):
@@ -697,7 +681,10 @@
697681
698682
699class TestGetSMDKSPL(TestCaseWithFixtures):683class TestGetSMDKSPL(TestCaseWithFixtures):
700 config = boards.SMDKV310Config684 def setUp(self):
685 super(TestGetSMDKSPL, self).setUp()
686 self.config = boards.SMDKV310Config()
687 self.config.hwpack_format = '1.0'
701688
702 def test_no_file_present(self):689 def test_no_file_present(self):
703 tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()690 tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
@@ -729,7 +716,10 @@
729716
730717
731class TestGetSMDKUboot(TestCaseWithFixtures):718class TestGetSMDKUboot(TestCaseWithFixtures):
732 config = boards.SMDKV310Config719 def setUp(self):
720 super(TestGetSMDKUboot, self).setUp()
721 self.config = boards.SMDKV310Config()
722 self.config.hwpack_format = '1.0'
733723
734 def test_uses_uboot_flavour(self):724 def test_uses_uboot_flavour(self):
735 chroot_dir = "chroot"725 chroot_dir = "chroot"
@@ -740,7 +730,10 @@
740730
741731
742class TestGetOrigenSPL(TestCaseWithFixtures):732class TestGetOrigenSPL(TestCaseWithFixtures):
743 config = boards.OrigenConfig733 def setUp(self):
734 super(TestGetOrigenSPL, self).setUp()
735 self.config = boards.OrigenConfig()
736 self.config.hwpack_format = '1.0'
744737
745 def test_no_file_present(self):738 def test_no_file_present(self):
746 tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()739 tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
@@ -756,7 +749,7 @@
756749
757750
758class TestGetOrigenUboot(TestGetSMDKUboot):751class TestGetOrigenUboot(TestGetSMDKUboot):
759 config = boards.OrigenConfig752 config = boards.OrigenConfig()
760753
761754
762class TestCreateToc(TestCaseWithFixtures):755class TestCreateToc(TestCaseWithFixtures):
@@ -778,6 +771,7 @@
778 '\x05\x00\x00\x00' '\x05\x00\x00\x00' \771 '\x05\x00\x00\x00' '\x05\x00\x00\x00' \
779 'hello' + zero + '\x00\x00\x00'772 'hello' + zero + '\x00\x00\x00'
780 self.expected = line1 + line2 + line3773 self.expected = line1 + line2 + line3
774 self.board_conf = boards.SnowballEmmcConfig()
781775
782 def create_files_structure(self, src_data):776 def create_files_structure(self, src_data):
783 ''' Creates the data structure that the tested function777 ''' Creates the data structure that the tested function
@@ -801,7 +795,7 @@
801 files = self.create_files_structure(correct_data)795 files = self.create_files_structure(correct_data)
802 filename = os.path.join(self.tempdir, 'toc')796 filename = os.path.join(self.tempdir, 'toc')
803 with open(filename, 'w') as f:797 with open(filename, 'w') as f:
804 boards.SnowballEmmcConfig.create_toc(f, files)798 self.board_conf.create_toc(f, files)
805 with open(filename, 'r') as f:799 with open(filename, 'r') as f:
806 actual = f.read()800 actual = f.read()
807 self.assertEquals(96, len(actual))801 self.assertEquals(96, len(actual))
@@ -816,7 +810,7 @@
816 files = self.create_files_structure(illegal_name_data)810 files = self.create_files_structure(illegal_name_data)
817 with open(os.path.join(self.tempdir, 'toc'), 'w') as f:811 with open(os.path.join(self.tempdir, 'toc'), 'w') as f:
818 self.assertRaises(AssertionError,812 self.assertRaises(AssertionError,
819 boards.SnowballEmmcConfig.create_toc,813 self.board_conf.create_toc,
820 f, files)814 f, files)
821815
822 def test_create_toc_error_negative_unsigned(self):816 def test_create_toc_error_negative_unsigned(self):
@@ -826,7 +820,7 @@
826 files = self.create_files_structure(illegal_unsigned_data)820 files = self.create_files_structure(illegal_unsigned_data)
827 with open(os.path.join(self.tempdir, 'toc'), 'w') as f:821 with open(os.path.join(self.tempdir, 'toc'), 'w') as f:
828 self.assertRaises(struct.error,822 self.assertRaises(struct.error,
829 boards.SnowballEmmcConfig.create_toc,823 self.board_conf.create_toc,
830 f, files)824 f, files)
831825
832826
@@ -845,6 +839,8 @@
845 os.makedirs(self.temp_bootdir_path)839 os.makedirs(self.temp_bootdir_path)
846 if not os.path.exists(self.temp_configdir_path):840 if not os.path.exists(self.temp_configdir_path):
847 os.makedirs(self.temp_configdir_path)841 os.makedirs(self.temp_configdir_path)
842 self.snowball_config = get_board_config('snowball_emmc')
843 self.snowball_config.hwpack_format = HardwarepackHandler.FORMAT_1
848844
849 def setupFiles(self):845 def setupFiles(self):
850 return self.create_test_files(self.temp_bootdir_path)846 return self.create_test_files(self.temp_bootdir_path)
@@ -870,7 +866,7 @@
870 ('UBOOT_ENV', 'u-boot-env.bin', 0, 0x00C1F000, '10')]866 ('UBOOT_ENV', 'u-boot-env.bin', 0, 0x00C1F000, '10')]
871 # Create a config file867 # Create a config file
872 cfg_file = os.path.join(868 cfg_file = os.path.join(
873 path, boards.SnowballEmmcConfig.snowball_startup_files_config)869 path, self.snowball_config.snowball_startup_files_config)
874 with open(cfg_file, 'w') as f:870 with open(cfg_file, 'w') as f:
875 for line in src_data:871 for line in src_data:
876 # Write comments, so we test that the parser can read them872 # Write comments, so we test that the parser can read them
@@ -886,8 +882,8 @@
886 f.write(line[0])882 f.write(line[0])
887 #define the expected values read from the config file883 #define the expected values read from the config file
888 expected = []884 expected = []
889 ofs = [boards.SnowballEmmcConfig.TOC_SIZE,885 ofs = [self.snowball_config.TOC_SIZE,
890 boards.SnowballEmmcConfig.TOC_SIZE + len('ISSW'), 0x160000,886 self.snowball_config.TOC_SIZE + len('ISSW'), 0x160000,
891 0x170000, 0xBA0000, 0xC1F000]887 0x170000, 0xBA0000, 0xC1F000]
892 size = [len('ISSW'), len('X-LOADER'), len('MEM_INIT'), \888 size = [len('ISSW'), len('X-LOADER'), len('MEM_INIT'), \
893 len('PWR_MGT'), len('NORMAL'), len('UBOOT_ENV')]889 len('PWR_MGT'), len('NORMAL'), len('UBOOT_ENV')]
@@ -906,13 +902,13 @@
906 def test_get_file_info_relative_path(self):902 def test_get_file_info_relative_path(self):
907 # Create a config file903 # Create a config file
908 cfg_file = os.path.join(self.temp_bootdir_path,904 cfg_file = os.path.join(self.temp_bootdir_path,
909 boards.SnowballEmmcConfig.snowball_startup_files_config)905 self.snowball_config.snowball_startup_files_config)
910 uboot_file = 'u-boot.bin'906 uboot_file = 'u-boot.bin'
911 with open(cfg_file, 'w') as f:907 with open(cfg_file, 'w') as f:
912 f.write('%s %s %i %#x %s\n' % ('NORMAL', uboot_file, 0,908 f.write('%s %s %i %#x %s\n' % ('NORMAL', uboot_file, 0,
913 0xBA0000, '9'))909 0xBA0000, '9'))
914 with open(os.path.join(self.temp_bootdir_path, uboot_file), 'w') as f:910 with open(os.path.join(self.temp_bootdir_path, uboot_file), 'w') as f:
915 file_info = boards.SnowballEmmcConfig.get_file_info(911 file_info = self.snowball_config.get_file_info(
916 self.tempdir, self.temp_bootdir_path)912 self.tempdir, self.temp_bootdir_path)
917 self.assertEquals(file_info[0]['filename'],913 self.assertEquals(file_info[0]['filename'],
918 os.path.join(self.temp_bootdir_path, uboot_file))914 os.path.join(self.temp_bootdir_path, uboot_file))
@@ -920,7 +916,7 @@
920 def test_get_file_info_abs_path(self):916 def test_get_file_info_abs_path(self):
921 # Create a config file917 # Create a config file
922 cfg_file = os.path.join(self.temp_bootdir_path,918 cfg_file = os.path.join(self.temp_bootdir_path,
923 boards.SnowballEmmcConfig.snowball_startup_files_config)919 self.snowball_config.snowball_startup_files_config)
924 uboot_dir = tempfile.mkdtemp(dir=self.tempdir)920 uboot_dir = tempfile.mkdtemp(dir=self.tempdir)
925 uboot_file = os.path.join(uboot_dir, 'u-boot.bin')921 uboot_file = os.path.join(uboot_dir, 'u-boot.bin')
926 uboot_relative_file = uboot_file.replace(self.tempdir, '')922 uboot_relative_file = uboot_file.replace(self.tempdir, '')
@@ -928,19 +924,19 @@
928 f.write('%s %s %i %#x %s\n' % (924 f.write('%s %s %i %#x %s\n' % (
929 'NORMAL', uboot_relative_file, 0, 0xBA0000, '9'))925 'NORMAL', uboot_relative_file, 0, 0xBA0000, '9'))
930 with open(uboot_file, 'w') as f:926 with open(uboot_file, 'w') as f:
931 file_info = boards.SnowballEmmcConfig.get_file_info(927 file_info = self.snowball_config.get_file_info(
932 self.tempdir, self.temp_bootdir_path)928 self.tempdir, self.temp_bootdir_path)
933 self.assertEquals(file_info[0]['filename'], uboot_file)929 self.assertEquals(file_info[0]['filename'], uboot_file)
934930
935 def test_get_file_info_raises(self):931 def test_get_file_info_raises(self):
936 # Create a config file932 # Create a config file
937 cfg_file = os.path.join(self.temp_bootdir_path,933 cfg_file = os.path.join(self.temp_bootdir_path,
938 boards.SnowballEmmcConfig.snowball_startup_files_config)934 self.snowball_config.snowball_startup_files_config)
939 with open(cfg_file, 'w') as f:935 with open(cfg_file, 'w') as f:
940 f.write('%s %s %i %#x %s\n' % ('NORMAL', 'u-boot.bin', 0,936 f.write('%s %s %i %#x %s\n' % ('NORMAL', 'u-boot.bin', 0,
941 0xBA0000, '9'))937 0xBA0000, '9'))
942 self.assertRaises(938 self.assertRaises(
943 AssertionError, boards.SnowballEmmcConfig.get_file_info,939 AssertionError, self.snowball_config.get_file_info,
944 self.tempdir, self.temp_bootdir_path)940 self.tempdir, self.temp_bootdir_path)
945941
946 def test_file_name_size(self):942 def test_file_name_size(self):
@@ -948,28 +944,28 @@
948 _, toc_filename = tempfile.mkstemp()944 _, toc_filename = tempfile.mkstemp()
949 atexit.register(os.unlink, toc_filename)945 atexit.register(os.unlink, toc_filename)
950 filedata = 'X'946 filedata = 'X'
951 bytes = boards.SnowballEmmcConfig.TOC_SIZE + 1947 bytes = self.snowball_config.TOC_SIZE + 1
952 tmpfile = open(toc_filename, 'wb')948 tmpfile = open(toc_filename, 'wb')
953 for n in xrange(bytes):949 for n in xrange(bytes):
954 tmpfile.write(filedata)950 tmpfile.write(filedata)
955 tmpfile.close()951 tmpfile.close()
956 files = self.setupFiles()952 files = self.setupFiles()
957 self.assertRaises(AssertionError,953 self.assertRaises(AssertionError,
958 boards.SnowballEmmcConfig.install_snowball_boot_loader,954 self.snowball_config.install_snowball_boot_loader,
959 toc_filename, files, "boot_device_or_file",955 toc_filename, files, "boot_device_or_file",
960 boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S)956 self.snowball_config.SNOWBALL_LOADER_START_S)
961957
962 def test_install_snowball_boot_loader_toc_dont_delete(self):958 def test_install_snowball_boot_loader_toc_dont_delete(self):
963 fixture = self.useFixture(MockCmdRunnerPopenFixture())959 fixture = self.useFixture(MockCmdRunnerPopenFixture())
964 toc_filename = self.createTempFileAsFixture()960 toc_filename = self.createTempFileAsFixture()
965 files = self.setupFiles()961 files = self.setupFiles()
966 boards.SnowballEmmcConfig.install_snowball_boot_loader(toc_filename,962 self.snowball_config.install_snowball_boot_loader(toc_filename,
967 files, "boot_device_or_file",963 files, "boot_device_or_file",
968 boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S)964 self.snowball_config.SNOWBALL_LOADER_START_S)
969 expected = [965 expected = [
970 '%s dd if=%s of=boot_device_or_file bs=512 conv=notrunc' \966 '%s dd if=%s of=boot_device_or_file bs=512 conv=notrunc' \
971 ' seek=%s' % (sudo_args, toc_filename,967 ' seek=%s' % (sudo_args, toc_filename,
972 boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S),968 self.snowball_config.SNOWBALL_LOADER_START_S),
973 '%s dd if=%s/boot_image_issw.bin of=boot_device_or_file bs=512' \969 '%s dd if=%s/boot_image_issw.bin of=boot_device_or_file bs=512' \
974 ' conv=notrunc seek=257' % (sudo_args, self.temp_bootdir_path),970 ' conv=notrunc seek=257' % (sudo_args, self.temp_bootdir_path),
975 '%s dd if=%s/boot_image_x-loader.bin of=boot_device_or_file' \971 '%s dd if=%s/boot_image_x-loader.bin of=boot_device_or_file' \
@@ -990,13 +986,13 @@
990 fixture = self.useFixture(MockCmdRunnerPopenFixture())986 fixture = self.useFixture(MockCmdRunnerPopenFixture())
991 toc_filename = self.createTempFileAsFixture()987 toc_filename = self.createTempFileAsFixture()
992 files = self.setupFiles()988 files = self.setupFiles()
993 boards.SnowballEmmcConfig.install_snowball_boot_loader(toc_filename,989 self.snowball_config.install_snowball_boot_loader(toc_filename,
994 files, "boot_device_or_file",990 files, "boot_device_or_file",
995 boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S, True)991 self.snowball_config.SNOWBALL_LOADER_START_S, True)
996 expected = [992 expected = [
997 '%s dd if=%s of=boot_device_or_file bs=512 conv=notrunc' \993 '%s dd if=%s of=boot_device_or_file bs=512 conv=notrunc' \
998 ' seek=%s' % (sudo_args, toc_filename,994 ' seek=%s' % (sudo_args, toc_filename,
999 boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S),995 self.snowball_config.SNOWBALL_LOADER_START_S),
1000 '%s dd if=%s/boot_image_issw.bin of=boot_device_or_file bs=512' \996 '%s dd if=%s/boot_image_issw.bin of=boot_device_or_file bs=512' \
1001 ' conv=notrunc seek=257' % (sudo_args, self.temp_bootdir_path),997 ' conv=notrunc seek=257' % (sudo_args, self.temp_bootdir_path),
1002 '%s rm %s/boot_image_issw.bin' % (sudo_args,998 '%s rm %s/boot_image_issw.bin' % (sudo_args,
@@ -1026,13 +1022,14 @@
1026 fixture = self.useFixture(MockCmdRunnerPopenFixture())1022 fixture = self.useFixture(MockCmdRunnerPopenFixture())
1027 toc_filename = self.createTempFileAsFixture()1023 toc_filename = self.createTempFileAsFixture()
1028 files = self.setupFiles()1024 files = self.setupFiles()
1029 AndroidSnowballEmmcConfig.install_snowball_boot_loader(1025 board_conf = AndroidSnowballEmmcConfig()
1026 board_conf.install_snowball_boot_loader(
1030 toc_filename, files, "boot_device_or_file",1027 toc_filename, files, "boot_device_or_file",
1031 AndroidSnowballEmmcConfig.SNOWBALL_LOADER_START_S)1028 board_conf.SNOWBALL_LOADER_START_S)
1032 expected = [1029 expected = [
1033 '%s dd if=%s of=boot_device_or_file bs=512 conv=notrunc' \1030 '%s dd if=%s of=boot_device_or_file bs=512 conv=notrunc' \
1034 ' seek=%s' % (sudo_args, toc_filename,1031 ' seek=%s' % (sudo_args, toc_filename,
1035 AndroidSnowballEmmcConfig.SNOWBALL_LOADER_START_S),1032 board_conf.SNOWBALL_LOADER_START_S),
1036 '%s dd if=%s/boot_image_issw.bin of=boot_device_or_file bs=512' \1033 '%s dd if=%s/boot_image_issw.bin of=boot_device_or_file bs=512' \
1037 ' conv=notrunc seek=257' % (sudo_args, self.temp_bootdir_path),1034 ' conv=notrunc seek=257' % (sudo_args, self.temp_bootdir_path),
1038 '%s dd if=%s/boot_image_x-loader.bin of=boot_device_or_file' \1035 '%s dd if=%s/boot_image_x-loader.bin of=boot_device_or_file' \
@@ -1057,11 +1054,11 @@
1057 k_img_file = os.path.join(self.tempdir, 'vmlinuz-1-ux500')1054 k_img_file = os.path.join(self.tempdir, 'vmlinuz-1-ux500')
1058 i_img_file = os.path.join(self.tempdir, 'initrd.img-1-ux500')1055 i_img_file = os.path.join(self.tempdir, 'initrd.img-1-ux500')
10591056
1060 boot_env = board_configs['snowball_emmc']._get_boot_env(1057 boot_env = self.snowball_config._get_boot_env(
1061 is_live=False, is_lowmem=False, consoles=[],1058 is_live=False, is_lowmem=False, consoles=[],
1062 rootfs_id="UUID=test_boot_env_uuid",1059 rootfs_id="UUID=test_boot_env_uuid",
1063 i_img_data=None, d_img_data=None)1060 i_img_data=None, d_img_data=None)
1064 boards.SnowballEmmcConfig._make_boot_files(boot_env, self.tempdir,1061 self.snowball_config._make_boot_files(boot_env, self.tempdir,
1065 self.temp_bootdir_path, 'boot_device_or_file', k_img_file,1062 self.temp_bootdir_path, 'boot_device_or_file', k_img_file,
1066 i_img_file, None)1063 i_img_file, None)
1067 expected = [1064 expected = [
@@ -1105,12 +1102,12 @@
1105 def test_missing_files(self):1102 def test_missing_files(self):
1106 '''When the files cannot be read, an IOError should be raised'''1103 '''When the files cannot be read, an IOError should be raised'''
1107 self.assertRaises(IOError,1104 self.assertRaises(IOError,
1108 boards.SnowballEmmcConfig.get_file_info,1105 self.snowball_config.get_file_info,
1109 self.tempdir, self.temp_bootdir_path)1106 self.tempdir, self.temp_bootdir_path)
11101107
1111 def test_normal_case(self):1108 def test_normal_case(self):
1112 expected = self.setupFiles()1109 expected = self.setupFiles()
1113 actual = boards.SnowballEmmcConfig.get_file_info(1110 actual = self.snowball_config.get_file_info(
1114 self.tempdir, self.temp_bootdir_path)1111 self.tempdir, self.temp_bootdir_path)
1115 self.assertEquals(expected, actual)1112 self.assertEquals(expected, actual)
11161113
@@ -1147,8 +1144,8 @@
1147 classmethod(set_appropriate_serial_tty_mock)))1144 classmethod(set_appropriate_serial_tty_mock)))
11481145
1149 def make_boot_files(self, config):1146 def make_boot_files(self, config):
1150 def _get_kflavor_files_mock(cls, path):1147 def _get_kflavor_files_mock(self, path):
1151 if cls.dtb_name is None:1148 if self.dtb_name is None:
1152 return (path, path, None)1149 return (path, path, None)
1153 return (path, path, path)1150 return (path, path, path)
11541151
@@ -1159,23 +1156,25 @@
1159 config.make_boot_files('', False, False, [], '', '', '', '')1156 config.make_boot_files('', False, False, [], '', '', '', '')
11601157
1161 def test_vexpress_steps(self):1158 def test_vexpress_steps(self):
1162 self.make_boot_files(boards.VexpressConfig)1159 board_conf = boards.VexpressConfig()
1160 self.make_boot_files(board_conf)
1163 expected = ['make_uImage', 'make_uInitrd']1161 expected = ['make_uImage', 'make_uInitrd']
1164 self.assertEqual(expected, self.funcs_calls)1162 self.assertEqual(expected, self.funcs_calls)
11651163
1166 def test_vexpress_a9_steps(self):1164 def test_vexpress_a9_steps(self):
1167 self.make_boot_files(boards.VexpressA9Config)1165 board_conf = boards.VexpressA9Config()
1166 self.make_boot_files(board_conf)
1168 expected = ['make_uImage', 'make_uInitrd']1167 expected = ['make_uImage', 'make_uInitrd']
1169 self.assertEqual(expected, self.funcs_calls)1168 self.assertEqual(expected, self.funcs_calls)
11701169
1171 def test_mx5_steps(self):1170 def test_mx5_steps(self):
1172 class SomeMx5Config(boards.Mx5Config):1171 board_conf = boards.Mx5Config()
1173 bootloader_flavor = 'bootloader_flavor'1172 board_conf.bootloader_flavor = 'bootloader_flavor'
1174 SomeMx5Config.hardwarepack_handler = (1173 board_conf.hardwarepack_handler = (
1175 TestSetMetadata.MockHardwarepackHandler('ahwpack.tar.gz'))1174 TestSetMetadata.MockHardwarepackHandler('ahwpack.tar.gz'))
1176 SomeMx5Config.hardwarepack_handler.get_format = (1175 board_conf.hardwarepack_handler.get_format = (
1177 lambda: '1.0')1176 lambda: '1.0')
1178 self.make_boot_files(SomeMx5Config)1177 self.make_boot_files(board_conf)
1179 expected = [1178 expected = [
1180 'install_mx5_boot_loader', 'make_uImage', 'make_uInitrd',1179 'install_mx5_boot_loader', 'make_uImage', 'make_uInitrd',
1181 'make_dtb', 'make_boot_script']1180 'make_dtb', 'make_boot_script']
@@ -1224,42 +1223,46 @@
1224 self.assertEqual(expected, self.funcs_calls)1223 self.assertEqual(expected, self.funcs_calls)
12251224
1226 def test_ux500_steps(self):1225 def test_ux500_steps(self):
1227 self.make_boot_files(boards.Ux500Config)1226 self.make_boot_files(boards.Ux500Config())
1228 expected = ['make_uImage', 'make_uInitrd', 'make_boot_script']1227 expected = ['make_uImage', 'make_uInitrd', 'make_boot_script']
1229 self.assertEqual(expected, self.funcs_calls)1228 self.assertEqual(expected, self.funcs_calls)
12301229
1231 def test_snowball_sd_steps(self):1230 def test_snowball_sd_steps(self):
1232 self.make_boot_files(boards.SnowballSdConfig)1231 self.make_boot_files(boards.SnowballSdConfig())
1233 expected = ['make_uImage', 'make_boot_script']1232 expected = ['make_uImage', 'make_boot_script']
1234 self.assertEqual(expected, self.funcs_calls)1233 self.assertEqual(expected, self.funcs_calls)
12351234
1236 def test_panda_steps(self):1235 def test_panda_steps(self):
1237 self.mock_set_appropriate_serial_tty(boards.PandaConfig)1236 board_conf = boards.PandaConfig()
1238 self.make_boot_files(boards.PandaConfig)1237 self.mock_set_appropriate_serial_tty(board_conf)
1238 self.make_boot_files(board_conf)
1239 expected = [1239 expected = [
1240 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd',1240 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd',
1241 'make_dtb', 'make_boot_script', 'make_boot_ini']1241 'make_dtb', 'make_boot_script', 'make_boot_ini']
1242 self.assertEqual(expected, self.funcs_calls)1242 self.assertEqual(expected, self.funcs_calls)
12431243
1244 def test_beagle_steps(self):1244 def test_beagle_steps(self):
1245 self.mock_set_appropriate_serial_tty(boards.BeagleConfig)1245 board_conf = boards.BeagleConfig()
1246 self.make_boot_files(boards.BeagleConfig)1246 self.mock_set_appropriate_serial_tty(board_conf)
1247 self.make_boot_files(board_conf)
1247 expected = [1248 expected = [
1248 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd',1249 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd',
1249 'make_dtb', 'make_boot_script', 'make_boot_ini']1250 'make_dtb', 'make_boot_script', 'make_boot_ini']
1250 self.assertEqual(expected, self.funcs_calls)1251 self.assertEqual(expected, self.funcs_calls)
12511252
1252 def test_igep_steps(self):1253 def test_igep_steps(self):
1253 self.mock_set_appropriate_serial_tty(boards.IgepConfig)1254 board_conf = boards.IgepConfig()
1254 self.make_boot_files(boards.IgepConfig)1255 self.mock_set_appropriate_serial_tty(board_conf)
1256 self.make_boot_files(board_conf)
1255 expected = [1257 expected = [
1256 'make_uImage', 'make_uInitrd', 'make_dtb', 'make_boot_script',1258 'make_uImage', 'make_uInitrd', 'make_dtb', 'make_boot_script',
1257 'make_boot_ini']1259 'make_boot_ini']
1258 self.assertEqual(expected, self.funcs_calls)1260 self.assertEqual(expected, self.funcs_calls)
12591261
1260 def test_overo_steps(self):1262 def test_overo_steps(self):
1261 self.mock_set_appropriate_serial_tty(boards.OveroConfig)1263 board_conf = boards.OveroConfig()
1262 self.make_boot_files(boards.OveroConfig)1264 self.mock_set_appropriate_serial_tty(board_conf)
1265 self.make_boot_files(board_conf)
1263 expected = [1266 expected = [
1264 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd',1267 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd',
1265 'make_dtb', 'make_boot_script', 'make_boot_ini']1268 'make_dtb', 'make_boot_script', 'make_boot_ini']
@@ -1291,20 +1294,20 @@
12911294
1292 def test_snowball_config_raises(self):1295 def test_snowball_config_raises(self):
1293 self.assertRaises(NotImplementedError,1296 self.assertRaises(NotImplementedError,
1294 boards.SnowballSdConfig.snowball_config, '')1297 boards.SnowballSdConfig().snowball_config, '')
12951298
1296 def test_beagle_raw(self):1299 def test_beagle_raw(self):
1297 self.populate_raw_partition(android_boards.AndroidBeagleConfig)1300 self.populate_raw_partition(android_boards.AndroidBeagleConfig())
1298 expected = []1301 expected = []
1299 self.assertEqual(expected, self.funcs_calls)1302 self.assertEqual(expected, self.funcs_calls)
13001303
1301 def test_panda_raw(self):1304 def test_panda_raw(self):
1302 self.populate_raw_partition(android_boards.AndroidPandaConfig)1305 self.populate_raw_partition(android_boards.AndroidPandaConfig())
1303 expected = []1306 expected = []
1304 self.assertEqual(expected, self.funcs_calls)1307 self.assertEqual(expected, self.funcs_calls)
13051308
1306 def test_snowball_sd_raw(self):1309 def test_snowball_sd_raw(self):
1307 self.populate_raw_partition(boards.SnowballSdConfig)1310 self.populate_raw_partition(boards.SnowballSdConfig())
1308 expected = []1311 expected = []
1309 self.assertEqual(expected, self.funcs_calls)1312 self.assertEqual(expected, self.funcs_calls)
13101313
@@ -1329,7 +1332,7 @@
1329 linaro_image_tools.media_create.boards.SnowballEmmcConfig,1332 linaro_image_tools.media_create.boards.SnowballEmmcConfig,
1330 'delete_file',1333 'delete_file',
1331 mock_func_creator('delete_file')))1334 mock_func_creator('delete_file')))
1332 self.populate_raw_partition(boards.SnowballEmmcConfig)1335 self.populate_raw_partition(boards.SnowballEmmcConfig())
1333 expected = ['get_file_info', 'create_toc',1336 expected = ['get_file_info', 'create_toc',
1334 'install_snowball_boot_loader', 'delete_file',1337 'install_snowball_boot_loader', 'delete_file',
1335 'delete_file']1338 'delete_file']
@@ -1341,12 +1344,12 @@
1341 self.useFixture(MockSomethingFixture(os.path, 'getsize',1344 self.useFixture(MockSomethingFixture(os.path, 'getsize',
1342 lambda file: 1))1345 lambda file: 1))
13431346
1344 self.populate_raw_partition(boards.SMDKV310Config)1347 self.populate_raw_partition(boards.SMDKV310Config())
1345 expected = ['_dd', '_dd', '_dd']1348 expected = ['_dd', '_dd', '_dd']
1346 self.assertEqual(expected, self.funcs_calls)1349 self.assertEqual(expected, self.funcs_calls)
13471350
1348 def test_mx53loco_raw(self):1351 def test_mx53loco_raw(self):
1349 self.populate_raw_partition(boards.Mx53LoCoConfig)1352 self.populate_raw_partition(boards.Mx53LoCoConfig())
1350 expected = []1353 expected = []
1351 self.assertEqual(expected, self.funcs_calls)1354 self.assertEqual(expected, self.funcs_calls)
13521355
@@ -1354,12 +1357,12 @@
1354 self.useFixture(MockSomethingFixture(os.path, 'getsize',1357 self.useFixture(MockSomethingFixture(os.path, 'getsize',
1355 lambda file: 1))1358 lambda file: 1))
13561359
1357 self.populate_raw_partition(boards.OrigenConfig)1360 self.populate_raw_partition(boards.OrigenConfig())
1358 expected = ['_dd', '_dd', '_dd']1361 expected = ['_dd', '_dd', '_dd']
1359 self.assertEqual(expected, self.funcs_calls)1362 self.assertEqual(expected, self.funcs_calls)
13601363
1361 def test_vexpress_a9_raw(self):1364 def test_vexpress_a9_raw(self):
1362 self.populate_raw_partition(boards.VexpressA9Config)1365 self.populate_raw_partition(boards.VexpressA9Config())
1363 expected = []1366 expected = []
1364 self.assertEqual(expected, self.funcs_calls)1367 self.assertEqual(expected, self.funcs_calls)
13651368
@@ -1374,17 +1377,17 @@
1374 config.populate_raw_partition('', '')1377 config.populate_raw_partition('', '')
13751378
1376 def test_beagle_raw(self):1379 def test_beagle_raw(self):
1377 self.populate_raw_partition(android_boards.AndroidBeagleConfig)1380 self.populate_raw_partition(android_boards.AndroidBeagleConfig())
1378 expected = []1381 expected = []
1379 self.assertEqual(expected, self.funcs_calls)1382 self.assertEqual(expected, self.funcs_calls)
13801383
1381 def test_panda_raw(self):1384 def test_panda_raw(self):
1382 self.populate_raw_partition(android_boards.AndroidPandaConfig)1385 self.populate_raw_partition(android_boards.AndroidPandaConfig())
1383 expected = []1386 expected = []
1384 self.assertEqual(expected, self.funcs_calls)1387 self.assertEqual(expected, self.funcs_calls)
13851388
1386 def test_snowball_sd_raw(self):1389 def test_snowball_sd_raw(self):
1387 self.populate_raw_partition(android_boards.AndroidSnowballSdConfig)1390 self.populate_raw_partition(android_boards.AndroidSnowballSdConfig())
1388 expected = []1391 expected = []
1389 self.assertEqual(expected, self.funcs_calls)1392 self.assertEqual(expected, self.funcs_calls)
13901393
@@ -1415,7 +1418,7 @@
1415 android_boards.AndroidSnowballEmmcConfig,1418 android_boards.AndroidSnowballEmmcConfig,
1416 'delete_file',1419 'delete_file',
1417 mock_func_creator('delete_file')))1420 mock_func_creator('delete_file')))
1418 self.populate_raw_partition(android_boards.AndroidSnowballEmmcConfig)1421 self.populate_raw_partition(android_boards.AndroidSnowballEmmcConfig())
1419 expected_calls = ['get_file_info', 'create_toc',1422 expected_calls = ['get_file_info', 'create_toc',
1420 'install_snowball_boot_loader', 'delete_file']1423 'install_snowball_boot_loader', 'delete_file']
1421 # Test that we copy the u-boot files to the local startupfiles dir.1424 # Test that we copy the u-boot files to the local startupfiles dir.
@@ -1435,14 +1438,14 @@
1435 self.useFixture(MockSomethingFixture(os.path, 'getsize',1438 self.useFixture(MockSomethingFixture(os.path, 'getsize',
1436 lambda file: 1))1439 lambda file: 1))
14371440
1438 self.populate_raw_partition(android_boards.AndroidSMDKV310Config)1441 self.populate_raw_partition(android_boards.AndroidSMDKV310Config())
1439 expected_calls = []1442 expected_calls = []
1440 # Test that we dd the files1443 # Test that we dd the files
1441 self.assertEqual(expected_commands, fixture.mock.commands_executed)1444 self.assertEqual(expected_commands, fixture.mock.commands_executed)
1442 self.assertEqual(expected_calls, self.funcs_calls)1445 self.assertEqual(expected_calls, self.funcs_calls)
14431446
1444 def test_mx53loco_raw(self):1447 def test_mx53loco_raw(self):
1445 self.populate_raw_partition(android_boards.AndroidMx53LoCoConfig)1448 self.populate_raw_partition(android_boards.AndroidMx53LoCoConfig())
1446 expected = []1449 expected = []
1447 self.assertEqual(expected, self.funcs_calls)1450 self.assertEqual(expected, self.funcs_calls)
14481451
@@ -1457,14 +1460,14 @@
1457 self.useFixture(MockSomethingFixture(os.path, 'getsize',1460 self.useFixture(MockSomethingFixture(os.path, 'getsize',
1458 lambda file: 1))1461 lambda file: 1))
14591462
1460 self.populate_raw_partition(android_boards.AndroidOrigenConfig)1463 self.populate_raw_partition(android_boards.AndroidOrigenConfig())
1461 expected = []1464 expected = []
1462 # Test that we dd the files1465 # Test that we dd the files
1463 self.assertEqual(expected_commands, fixture.mock.commands_executed)1466 self.assertEqual(expected_commands, fixture.mock.commands_executed)
1464 self.assertEqual(expected, self.funcs_calls)1467 self.assertEqual(expected, self.funcs_calls)
14651468
1466 def test_vexpress_raw(self):1469 def test_vexpress_raw(self):
1467 self.populate_raw_partition(android_boards.AndroidVexpressConfig)1470 self.populate_raw_partition(android_boards.AndroidVexpressConfig())
1468 expected = []1471 expected = []
1469 self.assertEqual(expected, self.funcs_calls)1472 self.assertEqual(expected, self.funcs_calls)
14701473
@@ -1505,15 +1508,16 @@
15051508
1506 def test_omap_make_boot_files(self):1509 def test_omap_make_boot_files(self):
1507 self.set_appropriate_serial_tty_called = False1510 self.set_appropriate_serial_tty_called = False
1508 self.mock_set_appropriate_serial_tty(board_configs['beagle'])1511 board_conf = get_board_config('beagle')
1512 self.mock_set_appropriate_serial_tty(board_conf)
1509 self.useFixture(MockSomethingFixture(1513 self.useFixture(MockSomethingFixture(
1510 boards.BoardConfig, 'make_boot_files',1514 board_conf, 'make_boot_files',
1511 classmethod(lambda *args: None)))1515 classmethod(lambda *args: None)))
1512 # We don't need to worry about what's passed to make_boot_files()1516 # We don't need to worry about what's passed to make_boot_files()
1513 # because we mock the method which does the real work above and here1517 # because we mock the method which does the real work above and here
1514 # we're only interested in ensuring that OmapConfig.make_boot_files()1518 # we're only interested in ensuring that OmapConfig.make_boot_files()
1515 # calls set_appropriate_serial_tty().1519 # calls set_appropriate_serial_tty().
1516 board_configs['beagle'].make_boot_files(1520 board_conf.make_boot_files(
1517 None, None, None, None, None, None, None, None)1521 None, None, None, None, None, None, None, None)
1518 self.assertTrue(1522 self.assertTrue(
1519 self.set_appropriate_serial_tty_called,1523 self.set_appropriate_serial_tty_called,
@@ -1522,17 +1526,17 @@
1522 def test_omap_make_boot_files_v2(self):1526 def test_omap_make_boot_files_v2(self):
1523 self.set_appropriate_serial_tty_called = False1527 self.set_appropriate_serial_tty_called = False
15241528
1525 class config(boards.BeagleConfig):1529 board_conf = boards.BeagleConfig()
1526 hwpack_format = HardwarepackHandler.FORMAT_21530 board_conf.hwpack_format = HardwarepackHandler.FORMAT_2
1527 self.mock_set_appropriate_serial_tty(config)1531 self.mock_set_appropriate_serial_tty(board_conf)
1528 self.useFixture(MockSomethingFixture(1532 self.useFixture(MockSomethingFixture(
1529 boards.BoardConfig, 'make_boot_files',1533 board_conf, 'make_boot_files',
1530 classmethod(lambda *args: None)))1534 classmethod(lambda *args: None)))
1531 # We don't need to worry about what's passed to make_boot_files()1535 # We don't need to worry about what's passed to make_boot_files()
1532 # because we mock the method which does the real work above and here1536 # because we mock the method which does the real work above and here
1533 # we're only interested in ensuring that OmapConfig.make_boot_files()1537 # we're only interested in ensuring that OmapConfig.make_boot_files()
1534 # does not call set_appropriate_serial_tty().1538 # does not call set_appropriate_serial_tty().
1535 config.make_boot_files(1539 board_conf.make_boot_files(
1536 None, None, None, None, None, None, None, None)1540 None, None, None, None, None, None, None, None)
1537 self.assertFalse(1541 self.assertFalse(
1538 self.set_appropriate_serial_tty_called,1542 self.set_appropriate_serial_tty_called,
@@ -1543,149 +1547,173 @@
1543 boot_dir = os.path.join(tempdir, 'boot')1547 boot_dir = os.path.join(tempdir, 'boot')
1544 os.makedirs(boot_dir)1548 os.makedirs(boot_dir)
1545 open(os.path.join(boot_dir, 'vmlinuz-2.6.35-23-foo'), 'w').close()1549 open(os.path.join(boot_dir, 'vmlinuz-2.6.35-23-foo'), 'w').close()
1546 boards.BeagleConfig.set_appropriate_serial_tty(tempdir)1550 board_conf = boards.BeagleConfig()
1547 self.assertEquals('ttyS2', boards.BeagleConfig.serial_tty)1551 board_conf.hwpack_format = '1.0'
1552 board_conf.set_appropriate_serial_tty(tempdir)
1553 self.assertEquals('ttyS2', board_conf.serial_tty)
15481554
1549 def test_set_appropriate_serial_tty_new_kernel(self):1555 def test_set_appropriate_serial_tty_new_kernel(self):
1550 tempdir = self.useFixture(CreateTempDirFixture()).tempdir1556 tempdir = self.useFixture(CreateTempDirFixture()).tempdir
1551 boot_dir = os.path.join(tempdir, 'boot')1557 boot_dir = os.path.join(tempdir, 'boot')
1552 os.makedirs(boot_dir)1558 os.makedirs(boot_dir)
1553 open(os.path.join(boot_dir, 'vmlinuz-2.6.36-13-foo'), 'w').close()1559 open(os.path.join(boot_dir, 'vmlinuz-2.6.36-13-foo'), 'w').close()
1554 boards.BeagleConfig.set_appropriate_serial_tty(tempdir)1560 board_conf = boards.BeagleConfig()
1555 self.assertEquals('ttyO2', boards.BeagleConfig.serial_tty)1561 board_conf.hwpack_format = '1.0'
1562 board_conf.set_appropriate_serial_tty(tempdir)
1563 self.assertEquals('ttyO2', board_conf.serial_tty)
15561564
1557 def test_set_appropriate_serial_tty_three_dot_oh_kernel(self):1565 def test_set_appropriate_serial_tty_three_dot_oh_kernel(self):
1558 tempdir = self.useFixture(CreateTempDirFixture()).tempdir1566 tempdir = self.useFixture(CreateTempDirFixture()).tempdir
1559 boot_dir = os.path.join(tempdir, 'boot')1567 boot_dir = os.path.join(tempdir, 'boot')
1560 os.makedirs(boot_dir)1568 os.makedirs(boot_dir)
1561 open(os.path.join(boot_dir, 'vmlinuz-3.0-13-foo'), 'w').close()1569 open(os.path.join(boot_dir, 'vmlinuz-3.0-13-foo'), 'w').close()
1562 boards.BeagleConfig.set_appropriate_serial_tty(tempdir)1570 board_conf = boards.BeagleConfig()
1563 self.assertEquals('ttyO2', boards.BeagleConfig.serial_tty)1571 board_conf.hwpack_format = '1.0'
1572 board_conf.set_appropriate_serial_tty(tempdir)
1573 self.assertEquals('ttyO2', board_conf.serial_tty)
15641574
15651575
1566class TestGetSfdiskCmd(TestCase):1576class TestGetSfdiskCmd(TestCase):
15671577
1578 def set_up_config(self, config):
1579 config.hwpack_format = '1.0'
1580
1568 def test_default(self):1581 def test_default(self):
1582 board_conf = BoardConfig()
1583 self.set_up_config(board_conf)
1569 self.assertEqual(1584 self.assertEqual(
1570 '63,106432,0x0C,*\n106496,,,-',1585 '63,106432,0x0C,*\n106496,,,-', board_conf.get_sfdisk_cmd())
1571 boards.BoardConfig.get_sfdisk_cmd())
15721586
1573 def test_default_aligned(self):1587 def test_default_aligned(self):
1588 board_conf = BoardConfig()
1589 self.set_up_config(board_conf)
1574 self.assertEqual(1590 self.assertEqual(
1575 '8192,106496,0x0C,*\n114688,,,-',1591 '8192,106496,0x0C,*\n114688,,,-',
1576 boards.BoardConfig.get_sfdisk_cmd(should_align_boot_part=True))1592 board_conf.get_sfdisk_cmd(should_align_boot_part=True))
15771593
1578 def test_mx5(self):1594 def test_mx5(self):
1595 board_conf = boards.Mx5Config()
1596 board_conf.hwpack_format = '1.0'
1579 self.assertEqual(1597 self.assertEqual(
1580 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',1598 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
1581 boards.Mx5Config.get_sfdisk_cmd())1599 board_conf.get_sfdisk_cmd())
15821600
1583 def test_snowball_sd(self):1601 def test_snowball_sd(self):
1602 board_conf = boards.SnowballSdConfig()
1603 self.set_up_config(board_conf)
1584 self.assertEqual(1604 self.assertEqual(
1585 '63,106432,0x0C,*\n106496,,,-',1605 '63,106432,0x0C,*\n106496,,,-', board_conf.get_sfdisk_cmd())
1586 boards.SnowballSdConfig.get_sfdisk_cmd())
15871606
1588 def test_snowball_emmc(self):1607 def test_snowball_emmc(self):
1608 board_conf = boards.SnowballEmmcConfig()
1609 self.set_up_config(board_conf)
1589 self.assertEqual(1610 self.assertEqual(
1590 '256,7936,0xDA\n8192,106496,0x0C,*\n114688,,,-',1611 '256,7936,0xDA\n8192,106496,0x0C,*\n114688,,,-',
1591 boards.SnowballEmmcConfig.get_sfdisk_cmd())1612 board_conf.get_sfdisk_cmd())
15921613
1593 def test_smdkv310(self):1614 def test_smdkv310(self):
1615 board_conf = get_board_config('smdkv310')
1616 self.set_up_config(board_conf)
1594 self.assertEquals(1617 self.assertEquals(
1595 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',1618 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
1596 board_configs['smdkv310'].get_sfdisk_cmd())1619 board_conf.get_sfdisk_cmd())
15971620
1598 def test_origen(self):1621 def test_origen(self):
1622 board_conf = get_board_config('origen')
1623 self.set_up_config(board_conf)
1599 self.assertEquals(1624 self.assertEquals(
1600 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',1625 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
1601 board_configs['origen'].get_sfdisk_cmd())1626 board_conf.get_sfdisk_cmd())
16021627
1603 def test_panda_android(self):1628 def test_panda_android(self):
1604 self.assertEqual(1629 self.assertEqual(
1605 '63,270272,0x0C,*\n270336,1048576,L\n1318912,524288,L\n'1630 '63,270272,0x0C,*\n270336,1048576,L\n1318912,524288,L\n'
1606 '1843200,-,E\n1843200,1048576,L\n2891776,,,-',1631 '1843200,-,E\n1843200,1048576,L\n2891776,,,-',
1607 android_boards.AndroidPandaConfig.get_sfdisk_cmd())1632 android_boards.AndroidPandaConfig().get_sfdisk_cmd())
16081633
1609 def test_origen_android(self):1634 def test_origen_android(self):
1610 self.assertEqual(1635 self.assertEqual(
1611 '1,8191,0xDA\n8253,270274,0x0C,*\n278528,1048576,L\n'1636 '1,8191,0xDA\n8253,270274,0x0C,*\n278528,1048576,L\n'
1612 '1327104,-,E\n1327104,524288,L\n1851392,1048576,L\n2899968,,,-',1637 '1327104,-,E\n1327104,524288,L\n1851392,1048576,L\n2899968,,,-',
1613 android_boards.AndroidOrigenConfig.get_sfdisk_cmd())1638 android_boards.AndroidOrigenConfig().get_sfdisk_cmd())
16141639
1615 def test_snowball_emmc_android(self):1640 def test_snowball_emmc_android(self):
1616 self.assertEqual(1641 self.assertEqual(
1617 '256,7936,0xDA\n8192,262144,0x0C,*\n270336,1048576,L\n'1642 '256,7936,0xDA\n8192,262144,0x0C,*\n270336,1048576,L\n'
1618 '1318912,-,E\n1318912,524288,L\n1843200,1048576,L\n2891776,,,-',1643 '1318912,-,E\n1318912,524288,L\n1843200,1048576,L\n2891776,,,-',
1619 android_boards.AndroidSnowballEmmcConfig.get_sfdisk_cmd())1644 android_boards.AndroidSnowballEmmcConfig().get_sfdisk_cmd())
16201645
1621 def test_vexpress_android(self):1646 def test_vexpress_android(self):
1622 self.assertEqual(1647 self.assertEqual(
1623 '63,270272,0x0E,*\n270336,1048576,L\n1318912,524288,L\n'1648 '63,270272,0x0E,*\n270336,1048576,L\n1318912,524288,L\n'
1624 '1843200,-,E\n1843200,1048576,L\n2891776,,,-',1649 '1843200,-,E\n1843200,1048576,L\n2891776,,,-',
1625 android_boards.AndroidVexpressConfig.get_sfdisk_cmd())1650 android_boards.AndroidVexpressConfig().get_sfdisk_cmd())
16261651
1627 def test_mx5_android(self):1652 def test_mx5_android(self):
1628 self.assertEqual(1653 self.assertEqual(
1629 '1,8191,0xDA\n8192,262144,0x0C,*\n270336,1048576,L\n'1654 '1,8191,0xDA\n8192,262144,0x0C,*\n270336,1048576,L\n'
1630 '1318912,-,E\n1318912,524288,L\n1843200,1048576,L\n2891776,,,-',1655 '1318912,-,E\n1318912,524288,L\n1843200,1048576,L\n2891776,,,-',
1631 android_boards.AndroidMx53LoCoConfig.get_sfdisk_cmd())1656 android_boards.AndroidMx53LoCoConfig().get_sfdisk_cmd())
16321657
1633 def test_mx6_android(self):1658 def test_mx6_android(self):
1634 self.assertEqual(1659 self.assertEqual(
1635 '1,8191,0xDA\n8192,262144,0x0C,*\n270336,1048576,L\n'1660 '1,8191,0xDA\n8192,262144,0x0C,*\n270336,1048576,L\n'
1636 '1318912,-,E\n1318912,524288,L\n1843200,1048576,L\n2891776,,,-',1661 '1318912,-,E\n1318912,524288,L\n1843200,1048576,L\n2891776,,,-',
1637 android_boards.AndroidMx6QSabreliteConfig.get_sfdisk_cmd())1662 android_boards.AndroidMx6QSabreliteConfig().get_sfdisk_cmd())
16381663
16391664
1640class TestGetSfdiskCmdV2(TestCase):1665class TestGetSfdiskCmdV2(TestCase):
16411666
1642 def test_mx5(self):1667 def test_mx5(self):
1643 class config(boards.Mx5Config):1668 board_conf = boards.Mx5Config()
1644 partition_layout = 'reserved_bootfs_rootfs'1669 board_conf.partition_layout = 'reserved_bootfs_rootfs'
1645 self.assertEqual(1670 self.assertEqual(
1646 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',1671 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
1647 config.get_sfdisk_cmd())1672 board_conf.get_sfdisk_cmd())
16481673
1649 def test_snowball_sd(self):1674 def test_snowball_sd(self):
1650 class config(boards.SnowballSdConfig):1675 board_conf = boards.SnowballSdConfig()
1651 partition_layout = 'bootfs_rootfs'1676 board_conf.partition_layout = 'bootfs_rootfs'
1652 self.assertEqual(1677 self.assertEqual(
1653 '63,106432,0x0C,*\n106496,,,-',1678 '63,106432,0x0C,*\n106496,,,-',
1654 config.get_sfdisk_cmd())1679 board_conf.get_sfdisk_cmd())
16551680
1656 def test_snowball_emmc(self):1681 def test_snowball_emmc(self):
1657 class config(boards.SnowballEmmcConfig):1682 board_conf = boards.SnowballEmmcConfig()
1658 partition_layout = 'reserved_bootfs_rootfs'1683 board_conf.partition_layout = 'reserved_bootfs_rootfs'
1659 LOADER_START_S = (128 * 1024) / SECTOR_SIZE1684 board_conf.loader_start_s = (128 * 1024) / SECTOR_SIZE
1660 self.assertEqual(1685 self.assertEqual(
1661 '256,7936,0xDA\n8192,106496,0x0C,*\n114688,,,-',1686 '256,7936,0xDA\n8192,106496,0x0C,*\n114688,,,-',
1662 config.get_sfdisk_cmd())1687 board_conf.get_sfdisk_cmd())
16631688
1664 def test_smdkv310(self):1689 def test_smdkv310(self):
1665 class config(board_configs['smdkv310']):1690 board_conf = get_board_config('smdkv310')
1666 partition_layout = 'reserved_bootfs_rootfs'1691 board_conf.partition_layout = 'reserved_bootfs_rootfs'
1667 LOADER_MIN_SIZE_S = (boards.BoardConfig.SAMSUNG_V310_BL2_START +1692 board_conf.LOADER_MIN_SIZE_S = (
1668 boards.BoardConfig.SAMSUNG_V310_BL2_LEN -1693 board_conf.samsung_v310_bl2_start +
1669 boards.BoardConfig.SAMSUNG_V310_BL1_START)1694 board_conf.samsung_v310_bl2_len -
1695 board_conf.samsung_v310_bl1_start)
1670 self.assertEquals(1696 self.assertEquals(
1671 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',1697 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
1672 config.get_sfdisk_cmd())1698 board_conf.get_sfdisk_cmd())
16731699
1674 def test_origen(self):1700 def test_origen(self):
1675 class config(board_configs['origen']):1701 board_conf = get_board_config('origen')
1676 partition_layout = 'reserved_bootfs_rootfs'1702 board_conf.partition_layout = 'reserved_bootfs_rootfs'
1677 LOADER_MIN_SIZE_S = (boards.BoardConfig.SAMSUNG_V310_BL2_START +1703 board_conf.LOADER_MIN_SIZE_S = (
1678 boards.BoardConfig.SAMSUNG_V310_BL2_LEN -1704 board_conf.samsung_v310_bl2_start +
1679 boards.BoardConfig.SAMSUNG_V310_BL1_START)1705 board_conf.samsung_v310_bl2_len -
1706 board_conf.samsung_v310_bl1_start)
1680 self.assertEquals(1707 self.assertEquals(
1681 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',1708 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
1682 config.get_sfdisk_cmd())1709 board_conf.get_sfdisk_cmd())
16831710
16841711
1685class TestGetBootCmd(TestCase):1712class TestGetBootCmd(TestCase):
16861713
1687 def test_vexpress(self):1714 def test_vexpress(self):
1688 boot_commands = board_configs['vexpress']._get_boot_env(1715 board_conf = get_board_config('vexpress')
1716 boot_commands = board_conf._get_boot_env(
1689 is_live=False, is_lowmem=False, consoles=['ttyXXX'],1717 is_live=False, is_lowmem=False, consoles=['ttyXXX'],
1690 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)1718 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
1691 expected = {1719 expected = {
@@ -1699,7 +1727,8 @@
1699 self.assertEqual(expected, boot_commands)1727 self.assertEqual(expected, boot_commands)
17001728
1701 def test_vexpress_a9(self):1729 def test_vexpress_a9(self):
1702 boot_commands = board_configs['vexpress-a9']._get_boot_env(1730 board_conf = get_board_config('vexpress-a9')
1731 boot_commands = board_conf._get_boot_env(
1703 is_live=False, is_lowmem=False, consoles=['ttyXXX'],1732 is_live=False, is_lowmem=False, consoles=['ttyXXX'],
1704 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)1733 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
1705 expected = {1734 expected = {
@@ -1713,7 +1742,8 @@
1713 self.assertEqual(expected, boot_commands)1742 self.assertEqual(expected, boot_commands)
17141743
1715 def test_mx51(self):1744 def test_mx51(self):
1716 boot_commands = boards.Mx51Config._get_boot_env(1745 board_conf = boards.Mx51Config()
1746 boot_commands = board_conf._get_boot_env(
1717 is_live=False, is_lowmem=False, consoles=[],1747 is_live=False, is_lowmem=False, consoles=[],
1718 rootfs_id="UUID=deadbeef", i_img_data="initrd",1748 rootfs_id="UUID=deadbeef", i_img_data="initrd",
1719 d_img_data="mx51.dtb")1749 d_img_data="mx51.dtb")
@@ -1729,7 +1759,8 @@
1729 self.assertEqual(expected, boot_commands)1759 self.assertEqual(expected, boot_commands)
17301760
1731 def test_smdkv310(self):1761 def test_smdkv310(self):
1732 boot_commands = board_configs['smdkv310']._get_boot_env(1762 board_conf = get_board_config('smdkv310')
1763 boot_commands = board_conf._get_boot_env(
1733 is_live=False, is_lowmem=False, consoles=[],1764 is_live=False, is_lowmem=False, consoles=[],
1734 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)1765 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
1735 expected = {1766 expected = {
@@ -1745,7 +1776,8 @@
1745 self.assertEqual(expected, boot_commands)1776 self.assertEqual(expected, boot_commands)
17461777
1747 def test_origen(self):1778 def test_origen(self):
1748 boot_commands = board_configs['origen']._get_boot_env(1779 board_conf = get_board_config('origen')
1780 boot_commands = board_conf._get_boot_env(
1749 is_live=False, is_lowmem=False, consoles=[],1781 is_live=False, is_lowmem=False, consoles=[],
1750 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)1782 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
1751 expected = {1783 expected = {
@@ -1759,7 +1791,8 @@
1759 self.assertEqual(expected, boot_commands)1791 self.assertEqual(expected, boot_commands)
17601792
1761 def test_ux500(self):1793 def test_ux500(self):
1762 boot_commands = board_configs['ux500']._get_boot_env(1794 board_conf = get_board_config('ux500')
1795 boot_commands = board_conf._get_boot_env(
1763 is_live=False, is_lowmem=False, consoles=[],1796 is_live=False, is_lowmem=False, consoles=[],
1764 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)1797 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
1765 expected = {1798 expected = {
@@ -1777,7 +1810,8 @@
1777 self.assertEqual(expected, boot_commands)1810 self.assertEqual(expected, boot_commands)
17781811
1779 def test_snowball_emmc(self):1812 def test_snowball_emmc(self):
1780 boot_commands = board_configs['snowball_emmc']._get_boot_env(1813 board_conf = get_board_config('snowball_emmc')
1814 boot_commands = board_conf._get_boot_env(
1781 is_live=False, is_lowmem=False, consoles=[],1815 is_live=False, is_lowmem=False, consoles=[],
1782 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)1816 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
1783 expected = {1817 expected = {
@@ -1798,7 +1832,7 @@
1798 # XXX: To fix bug 697824 we have to change class attributes of our1832 # XXX: To fix bug 697824 we have to change class attributes of our
1799 # OMAP board configs, and some tests do that so to make sure they1833 # OMAP board configs, and some tests do that so to make sure they
1800 # don't interfere with us we'll reset that before doing anything.1834 # don't interfere with us we'll reset that before doing anything.
1801 config = board_configs['panda']1835 config = get_board_config('panda')
1802 config.serial_tty = config._serial_tty1836 config.serial_tty = config._serial_tty
1803 boot_commands = config._get_boot_env(1837 boot_commands = config._get_boot_env(
1804 is_live=False, is_lowmem=False, consoles=[],1838 is_live=False, is_lowmem=False, consoles=[],
@@ -1821,7 +1855,7 @@
1821 # XXX: To fix bug 697824 we have to change class attributes of our1855 # XXX: To fix bug 697824 we have to change class attributes of our
1822 # OMAP board configs, and some tests do that so to make sure they1856 # OMAP board configs, and some tests do that so to make sure they
1823 # don't interfere with us we'll reset that before doing anything.1857 # don't interfere with us we'll reset that before doing anything.
1824 config = board_configs['beagle']1858 config = get_board_config('beagle')
1825 config.serial_tty = config._serial_tty1859 config.serial_tty = config._serial_tty
1826 boot_commands = config._get_boot_env(1860 boot_commands = config._get_boot_env(
1827 is_live=False, is_lowmem=False, consoles=[],1861 is_live=False, is_lowmem=False, consoles=[],
@@ -1844,7 +1878,7 @@
1844 # XXX: To fix bug 697824 we have to change class attributes of our1878 # XXX: To fix bug 697824 we have to change class attributes of our
1845 # OMAP board configs, and some tests do that so to make sure they1879 # OMAP board configs, and some tests do that so to make sure they
1846 # don't interfere with us we'll reset that before doing anything.1880 # don't interfere with us we'll reset that before doing anything.
1847 config = boards.IgepConfig1881 config = boards.IgepConfig()
1848 config.serial_tty = config._serial_tty1882 config.serial_tty = config._serial_tty
1849 boot_cmd = config._get_boot_env(1883 boot_cmd = config._get_boot_env(
1850 is_live=False, is_lowmem=False, consoles=[],1884 is_live=False, is_lowmem=False, consoles=[],
@@ -1867,7 +1901,7 @@
1867 # XXX: To fix bug 697824 we have to change class attributes of our1901 # XXX: To fix bug 697824 we have to change class attributes of our
1868 # OMAP board configs, and some tests do that so to make sure they1902 # OMAP board configs, and some tests do that so to make sure they
1869 # don't interfere with us we'll reset that before doing anything.1903 # don't interfere with us we'll reset that before doing anything.
1870 config = board_configs['overo']1904 config = get_board_config('overo')
1871 config.serial_tty = config._serial_tty1905 config.serial_tty = config._serial_tty
1872 boot_commands = config._get_boot_env(1906 boot_commands = config._get_boot_env(
1873 is_live=False, is_lowmem=False, consoles=[],1907 is_live=False, is_lowmem=False, consoles=[],
@@ -1890,12 +1924,15 @@
18901924
1891class TestExtraBootCmd(TestCaseWithFixtures):1925class TestExtraBootCmd(TestCaseWithFixtures):
18921926
1927 def setUp(self):
1928 super(TestExtraBootCmd, self).setUp()
1929 self.board_conf = BoardConfig()
1930
1893 def test_extra_boot_args_options_is_picked_by_get_boot_env(self):1931 def test_extra_boot_args_options_is_picked_by_get_boot_env(self):
1894 boot_args = 'whatever'1932 boot_args = 'whatever'
18951933
1896 class config(BoardConfig):1934 self.board_conf.extra_boot_args_options = boot_args
1897 extra_boot_args_options = boot_args1935 boot_commands = self.board_conf._get_boot_env(
1898 boot_commands = config._get_boot_env(
1899 is_live=False, is_lowmem=False, consoles=['ttyXXX'],1936 is_live=False, is_lowmem=False, consoles=['ttyXXX'],
1900 rootfs_id="UUID=deadbeef", i_img_data=None, d_img_data=None)1937 rootfs_id="UUID=deadbeef", i_img_data=None, d_img_data=None)
1901 expected = (1938 expected = (
@@ -1905,28 +1942,25 @@
1905 def test_passing_None_to_add_boot_args(self):1942 def test_passing_None_to_add_boot_args(self):
1906 boot_args = 'extra-args'1943 boot_args = 'extra-args'
19071944
1908 class config(BoardConfig):1945 self.board_conf.extra_boot_args_options = boot_args
1909 extra_boot_args_options = boot_args1946 self.board_conf.add_boot_args(None)
1910 config.add_boot_args(None)1947 self.assertEqual(boot_args, self.board_conf.extra_boot_args_options)
1911 self.assertEqual(boot_args, config.extra_boot_args_options)
19121948
1913 def test_passing_string_to_add_boot_args(self):1949 def test_passing_string_to_add_boot_args(self):
1914 boot_args = 'extra-args'1950 boot_args = 'extra-args'
1915 extra_args = 'user-args'1951 extra_args = 'user-args'
19161952
1917 class config(BoardConfig):1953 self.board_conf.extra_boot_args_options = boot_args
1918 extra_boot_args_options = boot_args1954 self.board_conf.add_boot_args(extra_args)
1919 config.add_boot_args(extra_args)
1920 self.assertEqual(1955 self.assertEqual(
1921 "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)1956 "%s %s" % (boot_args, extra_args),
1957 self.board_conf.extra_boot_args_options)
19221958
1923 def test_passing_string_to_add_boot_args_with_no_default_extra_args(self):1959 def test_passing_string_to_add_boot_args_with_no_default_extra_args(self):
1924 extra_args = 'user-args'1960 extra_args = 'user-args'
19251961
1926 class config(BoardConfig):1962 self.board_conf.add_boot_args(extra_args)
1927 extra_boot_args_options = None1963 self.assertEqual(extra_args, self.board_conf.extra_boot_args_options)
1928 config.add_boot_args(extra_args)
1929 self.assertEqual(extra_args, config.extra_boot_args_options)
19301964
1931 def test_add_boot_args_from_file(self):1965 def test_add_boot_args_from_file(self):
1932 boot_args = 'extra-args'1966 boot_args = 'extra-args'
@@ -1935,19 +1969,18 @@
1935 with open(boot_arg_path, 'w') as boot_arg_file:1969 with open(boot_arg_path, 'w') as boot_arg_file:
1936 boot_arg_file.write(extra_args)1970 boot_arg_file.write(extra_args)
19371971
1938 class config(BoardConfig):1972 self.board_conf.extra_boot_args_options = boot_args
1939 extra_boot_args_options = boot_args1973 self.board_conf.add_boot_args_from_file(boot_arg_path)
1940 config.add_boot_args_from_file(boot_arg_path)
1941 self.assertEqual(1974 self.assertEqual(
1942 "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)1975 "%s %s" % (boot_args, extra_args),
1976 self.board_conf.extra_boot_args_options)
19431977
1944 def test_passing_None_to_add_boot_args_from_file(self):1978 def test_passing_None_to_add_boot_args_from_file(self):
1945 boot_args = 'extra-args'1979 boot_args = 'extra-args'
19461980
1947 class config(BoardConfig):1981 self.board_conf.extra_boot_args_options = boot_args
1948 extra_boot_args_options = boot_args1982 self.board_conf.add_boot_args_from_file(None)
1949 config.add_boot_args_from_file(None)1983 self.assertEqual(boot_args, self.board_conf.extra_boot_args_options)
1950 self.assertEqual(boot_args, config.extra_boot_args_options)
19511984
1952 def test_add_boot_args_from_file_strips_whitespace_from_file(self):1985 def test_add_boot_args_from_file_strips_whitespace_from_file(self):
1953 boot_args = 'extra-args'1986 boot_args = 'extra-args'
@@ -1956,122 +1989,11 @@
1956 with open(boot_arg_path, 'w') as boot_arg_file:1989 with open(boot_arg_path, 'w') as boot_arg_file:
1957 boot_arg_file.write('\n\n \t ' + extra_args + ' \n\n')1990 boot_arg_file.write('\n\n \t ' + extra_args + ' \n\n')
19581991
1959 class config(BoardConfig):1992 self.board_conf.extra_boot_args_options = boot_args
1960 extra_boot_args_options = boot_args1993 self.board_conf.add_boot_args_from_file(boot_arg_path)
1961 config.add_boot_args_from_file(boot_arg_path)
1962 self.assertEqual(1994 self.assertEqual(
1963 "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
1964
1965
1966class TestGetBootCmdAndroid(TestCase):
1967
1968 def test_panda(self):
1969 # XXX: To fix bug 697824 we have to change class attributes of our
1970 # OMAP board configs, and some tests do that so to make sure they
1971 # don't interfere with us we'll reset that before doing anything.
1972 config = android_board_configs['panda']
1973 config.serial_tty = config._serial_tty
1974 expected = {
1975 'bootargs': 'console=ttyO2,115200n8 '
1976 'rootwait ro earlyprintk fixrtc '
1977 'nocompcache vram=48M omapfb.vram=0:24M,1:24M '
1978 'mem=456M@0x80000000 mem=512M@0xA0000000 '
1979 'init=/init androidboot.console=ttyO2',
1980 'bootcmd': 'fatload mmc 0:1 0x80200000 uImage; '
1981 'fatload mmc 0:1 0x81600000 uInitrd; '
1982 'fatload mmc 0:1 0x815f0000 board.dtb; '
1983 'bootm 0x80200000 0x81600000 0x815f0000',
1984 'fdt_high': '0xffffffff',
1985 'initrd_high': '0xffffffff'}
1986 self.assertBootEnv(config, expected)
1987
1988 def test_android_snowball_sd(self):
1989 expected = {
1990 'bootargs': 'console=ttyAMA2,115200n8 '
1991 'rootwait ro earlyprintk '
1992 'mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
1993 'mem=22M@360M mem_issw=1M@383M mem=640M@384M '
1994 'vmalloc=500M init=/init androidboot.console=ttyAMA2',
1995 'bootcmd': 'fatload mmc 1:1 0x00100000 uImage; '
1996 'fatload mmc 1:1 0x05000000 uInitrd; '
1997 'fatload mmc 1:1 0x8000000 board.dtb; '
1998 'bootm 0x00100000 0x05000000 0x8000000',
1999 'fdt_high': '0x05000000',
2000 'initrd_high': '0x06000000'}
2001 self.assertBootEnv(
2002 android_boards.AndroidSnowballSdConfig, expected)
2003
2004 def test_android_snowball_emmc(self):
2005 expected = {
2006 'bootargs': 'console=ttyAMA2,115200n8 '
2007 'rootwait ro earlyprintk '
2008 'mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
2009 'mem=22M@360M mem_issw=1M@383M mem=640M@384M '
2010 'vmalloc=500M init=/init androidboot.console=ttyAMA2',
2011 'bootcmd': 'fatload mmc 0:2 0x00100000 uImage; '
2012 'fatload mmc 0:2 0x05000000 uInitrd; '
2013 'fatload mmc 0:2 0x8000000 board.dtb; '
2014 'bootm 0x00100000 0x05000000 0x8000000',
2015 'fdt_high': '0x05000000',
2016 'initrd_high': '0x06000000'}
2017 self.assertBootEnv(
2018 android_boards.AndroidSnowballEmmcConfig, expected)
2019
2020 def test_android_origen(self):
2021 expected = {
2022 'bootargs': 'console=tty0 console=ttySAC2,115200n8 '
2023 'rootwait ro init=/init androidboot.console=ttySAC2',
2024 'bootcmd': 'fatload mmc 0:2 0x40007000 uImage; '
2025 'fatload mmc 0:2 0x42000000 uInitrd; '
2026 'bootm 0x40007000 0x42000000',
2027 'fdt_high': '0xffffffff',
2028 'initrd_high': '0xffffffff'}
2029 self.assertBootEnv(
2030 android_boards.AndroidOrigenConfig, expected)
2031
2032 def test_android_vexpress(self):
2033 expected = {
2034 'bootargs': 'console=tty0 console=ttyAMA0,38400n8 '
2035 'rootwait ro init=/init androidboot.console=ttyAMA0',
2036 'bootcmd': 'fatload mmc 0:1 0x60000000 uImage; '
2037 'fatload mmc 0:1 0x62000000 uInitrd; '
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches