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
1=== modified file 'linaro-android-media-create'
2--- linaro-android-media-create 2012-07-26 08:48:15 +0000
3+++ linaro-android-media-create 2012-11-20 10:49:03 +0000
4@@ -26,7 +26,7 @@
5 from linaro_image_tools import cmd_runner
6
7 from linaro_image_tools.media_create.android_boards import (
8- android_board_configs,
9+ get_board_config,
10 )
11 from linaro_image_tools.media_create.check_device import (
12 confirm_device_selection_and_ensure_it_is_ready)
13@@ -40,8 +40,10 @@
14 unpack_android_binary_tarball
15 )
16 from linaro_image_tools.media_create import get_android_args_parser
17-from linaro_image_tools.utils import ensure_command
18-
19+from linaro_image_tools.utils import (
20+ ensure_command,
21+ get_logger
22+ )
23
24
25 # Just define the global variables
26@@ -89,6 +91,8 @@
27 parser = get_android_args_parser()
28 args = parser.parse_args()
29
30+ logger = get_logger(debug=args.debug)
31+
32 # If --help was specified this won't execute.
33 # Create temp dir and initialize rest of path vars.
34 TMP_DIR = tempfile.mkdtemp()
35@@ -102,13 +106,15 @@
36 DATA_DISK = os.path.join(TMP_DIR, 'userdata-disc')
37 SDCARD_DISK = os.path.join(TMP_DIR, 'sdcard-disc')
38
39- board_config = android_board_configs[args.dev]
40+ board_config = get_board_config(args.dev)
41+ board_config.from_file(args.hwpack)
42 board_config.add_boot_args(args.extra_boot_args)
43 board_config.add_boot_args_from_file(args.extra_boot_args_file)
44
45 if args.dev == 'iMX53':
46 # XXX: remove this and the corresponding entry in android_board_configs
47- print "DEPRECATION WARNING: iMX53 is deprecated, please use mx53loco."
48+ logger.warning("DEPRECATION WARNING: iMX53 is deprecated, please "
49+ "use mx53loco.")
50
51 ensure_required_commands(args)
52
53@@ -117,11 +123,11 @@
54 if not confirm_device_selection_and_ensure_it_is_ready(args.device):
55 sys.exit(1)
56 elif not args.should_create_partitions:
57- print ("Do not use --no-part in conjunction with --image_file.")
58+ logger.error("Do not use --no-part in conjunction with --image_file.")
59 sys.exit(1)
60- else:
61- # All good, move on.
62- pass
63+ # else:
64+ # # All good, move on.
65+ # pass
66
67 cmd_runner.run(['mkdir', '-p', BOOT_DIR]).wait()
68 cmd_runner.run(['mkdir', '-p', SYSTEM_DIR]).wait()
69
70=== modified file 'linaro-media-create'
71--- linaro-media-create 2012-10-22 06:57:20 +0000
72+++ linaro-media-create 2012-11-20 10:49:03 +0000
73@@ -25,7 +25,7 @@
74
75 from linaro_image_tools import cmd_runner
76
77-from linaro_image_tools.media_create.boards import board_configs
78+from linaro_image_tools.media_create.boards import get_board_config
79 from linaro_image_tools.media_create.check_device import (
80 confirm_device_selection_and_ensure_it_is_ready)
81 from linaro_image_tools.media_create.chroot_utils import (
82@@ -131,9 +131,9 @@
83 logger.error(e.value)
84 sys.exit(1)
85
86- board_config = board_configs[args.dev]
87+ board_config = get_board_config(args.dev)
88 board_config.set_metadata(args.hwpacks, args.bootloader, args.dev)
89- board_config.set_board(args.dev)
90+ board_config.board(args.dev)
91 board_config.add_boot_args(args.extra_boot_args)
92 board_config.add_boot_args_from_file(args.extra_boot_args_file)
93
94
95=== added file 'linaro_image_tools/hwpack/handler.py'
96--- linaro_image_tools/hwpack/handler.py 1970-01-01 00:00:00 +0000
97+++ linaro_image_tools/hwpack/handler.py 2012-11-20 10:49:03 +0000
98@@ -0,0 +1,292 @@
99+# Copyright (C) 2010, 2011 Linaro
100+#
101+# Author: Guilherme Salgado <guilherme.salgado@linaro.org>
102+#
103+# This file is part of Linaro Image Tools.
104+#
105+# Linaro Image Tools is free software: you can redistribute it and/or modify
106+# it under the terms of the GNU General Public License as published by
107+# the Free Software Foundation, either version 3 of the License, or
108+# (at your option) any later version.
109+#
110+# Linaro Image Tools is distributed in the hope that it will be useful,
111+# but WITHOUT ANY WARRANTY; without even the implied warranty of
112+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113+# GNU General Public License for more details.
114+#
115+# You should have received a copy of the GNU General Public License
116+# along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>.
117+
118+from StringIO import StringIO
119+import ConfigParser
120+import logging
121+import os
122+import re
123+import shutil
124+import tarfile
125+import tempfile
126+
127+from linaro_image_tools.hwpack.config import Config
128+from linaro_image_tools.hwpack.builder import PackageUnpacker
129+from linaro_image_tools.utils import DEFAULT_LOGGER_NAME
130+
131+
132+logger = logging.getLogger(DEFAULT_LOGGER_NAME)
133+
134+
135+class HardwarepackHandler(object):
136+ FORMAT_1 = '1.0'
137+ FORMAT_2 = '2.0'
138+ FORMAT_3 = '3.0'
139+ FORMAT_MIXED = '1.0and2.0'
140+ metadata_filename = 'metadata'
141+ format_filename = 'FORMAT'
142+ main_section = 'main'
143+ hwpack_tarfiles = []
144+ tempdir = None
145+
146+ def __init__(self, hwpacks, bootloader=None, board=None):
147+ self.hwpacks = hwpacks
148+ self.hwpack_tarfiles = []
149+ self.bootloader = bootloader
150+ self.board = board
151+ self.tempdirs = {}
152+ # Used to store the config created from the metadata.
153+ self.config = None
154+
155+ class FakeSecHead(object):
156+ """ Add a fake section header to the metadata file.
157+
158+ This is done so we can use ConfigParser to parse the file.
159+ """
160+ def __init__(self, fp):
161+ self.fp = fp
162+ self.sechead = '[%s]\n' % HardwarepackHandler.main_section
163+
164+ def readline(self):
165+ if self.sechead:
166+ try:
167+ return self.sechead
168+ finally:
169+ self.sechead = None
170+ else:
171+ return self.fp.readline()
172+
173+ def __enter__(self):
174+ self.tempdir = tempfile.mkdtemp()
175+ for hwpack in self.hwpacks:
176+ hwpack_tarfile = tarfile.open(hwpack, mode='r:gz')
177+ self.hwpack_tarfiles.append(hwpack_tarfile)
178+ return self
179+
180+ def __exit__(self, type, value, traceback):
181+ for hwpack_tarfile in self.hwpack_tarfiles:
182+ if hwpack_tarfile is not None:
183+ hwpack_tarfile.close()
184+ self.hwpack_tarfiles = []
185+ if self.tempdir is not None and os.path.exists(self.tempdir):
186+ shutil.rmtree(self.tempdir)
187+
188+ for name in self.tempdirs:
189+ tempdir = self.tempdirs[name]
190+ if tempdir is not None and os.path.exists(tempdir):
191+ shutil.rmtree(tempdir)
192+
193+ def _get_config_from_metadata(self, metadata):
194+ """
195+ Retrieves a Config object associated with the metadata.
196+
197+ :param metadata: The metadata to parse.
198+ :return: A Config instance.
199+ """
200+ if not self.config:
201+ lines = metadata.readlines()
202+ if re.search("=", lines[0]) and not re.search(":", lines[0]):
203+ # Probably V2 hardware pack without [hwpack] on the first line
204+ lines = ["[hwpack]\n"] + lines
205+ self.config = Config(StringIO("".join(lines)))
206+ self.config.set_board(self.board)
207+ self.config.set_bootloader(self.bootloader)
208+ return self.config
209+
210+ def get_field(self, field, return_keys=False):
211+ data = None
212+ hwpack_with_data = None
213+ keys = None
214+ for hwpack_tarfile in self.hwpack_tarfiles:
215+ metadata = hwpack_tarfile.extractfile(self.metadata_filename)
216+ parser = self._get_config_from_metadata(metadata)
217+ try:
218+ new_data = parser.get_option(field)
219+ if new_data is not None:
220+ assert data is None, "The metadata field '%s' is set to " \
221+ "'%s' and new value '%s' is found" % (field, data,
222+ new_data)
223+ data = new_data
224+ hwpack_with_data = hwpack_tarfile
225+ if return_keys:
226+ keys = parser.get_last_used_keys()
227+ except ConfigParser.NoOptionError:
228+ continue
229+
230+ if return_keys:
231+ return data, hwpack_with_data, keys
232+ return data, hwpack_with_data
233+
234+ def get_format(self):
235+ format = None
236+ supported_formats = [self.FORMAT_1, self.FORMAT_2, self.FORMAT_3]
237+ for hwpack_tarfile in self.hwpack_tarfiles:
238+ format_file = hwpack_tarfile.extractfile(self.format_filename)
239+ format_string = format_file.read().strip()
240+ if not format_string in supported_formats:
241+ raise AssertionError(
242+ "Format version '%s' is not supported." % format_string)
243+ if format is None:
244+ format = format_string
245+ elif format != format_string:
246+ return self.FORMAT_MIXED
247+ return format
248+
249+ def get_file(self, file_alias):
250+ """Get file(s) from a hwpack.
251+ :param file_alias: Property name (not field name) which contains
252+ file reference(s)
253+ :return: path to a file or list of paths to files
254+ """
255+ file_names, hwpack_tarfile, keys = self.get_field(file_alias,
256+ return_keys=True)
257+ if not file_names:
258+ return file_names
259+ single = False
260+ if not isinstance(file_names, list):
261+ single = True
262+ file_names = [file_names]
263+ out_files = []
264+
265+ # Depending on if board and/or bootloader were used to look up the
266+ # file we are getting, we need to prepend those names to the path
267+ # to get the correct extracted file from the hardware pack.
268+ config_names = [("board", "boards"), ("bootloader", "bootloaders")]
269+ base_path = ""
270+ if keys:
271+ # If keys is non-empty, we have a V3 config option that was
272+ # modified by the bootloader and/or boot option...
273+ for name, key in config_names:
274+ if self.get_field(name):
275+ value = self.get_field(name)[0]
276+ if keys[0] == key:
277+ base_path = os.path.join(base_path, value)
278+ keys = keys[1:]
279+
280+ for f in file_names:
281+ # Check that the base path is needed. If the file doesn't exist,
282+ # try without it (this provides fallback to V2 style directory
283+ # layouts with a V3 config).
284+ path_inc_board_and_bootloader = os.path.join(base_path, f)
285+ if path_inc_board_and_bootloader in hwpack_tarfile.getnames():
286+ f = path_inc_board_and_bootloader
287+ hwpack_tarfile.extract(f, self.tempdir)
288+ f = os.path.join(self.tempdir, f)
289+ out_files.append(f)
290+ if single:
291+ return out_files[0]
292+ return out_files
293+
294+ def list_packages(self):
295+ """Return list of (package names, TarFile object containing them)"""
296+ packages = []
297+ for tf in self.hwpack_tarfiles:
298+ for name in tf.getnames():
299+ if name.startswith("pkgs/") and name.endswith(".deb"):
300+ packages.append((tf, name))
301+ return packages
302+
303+ def find_package_for(self, name, version=None, revision=None,
304+ architecture=None):
305+ """Find a package that matches the name, version, rev and arch given.
306+
307+ Packages are named according to the debian specification:
308+ http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html
309+ <name>_<Version>-<DebianRevisionNumber>_<DebianArchitecture>.deb
310+ DebianRevisionNumber seems to be optional.
311+ Use this spec to return a package matching the requirements given.
312+ """
313+ for tar_file, package in self.list_packages():
314+ file_name = os.path.basename(package)
315+ dpkg_chunks = re.search("^(.+)_(.+)_(.+)\.deb$",
316+ file_name)
317+ assert dpkg_chunks, "Could not split package file name into"\
318+ "<name>_<Version>_<DebianArchitecture>.deb"
319+
320+ pkg_name = dpkg_chunks.group(1)
321+ pkg_version = dpkg_chunks.group(2)
322+ pkg_architecture = dpkg_chunks.group(3)
323+
324+ ver_chunks = re.search("^(.+)-(.+)$", pkg_version)
325+ if ver_chunks:
326+ pkg_version = ver_chunks.group(1)
327+ pkg_revision = ver_chunks.group(2)
328+ else:
329+ pkg_revision = None
330+
331+ if name != pkg_name:
332+ continue
333+ if version != None and str(version) != pkg_version:
334+ continue
335+ if revision != None and str(revision) != pkg_revision:
336+ continue
337+ if (architecture != None and
338+ str(architecture) != pkg_architecture):
339+ continue
340+
341+ # Got a matching package - return its path inside the tarball
342+ return tar_file, package
343+
344+ # Failed to find a matching package - return None
345+ return None
346+
347+ def get_file_from_package(self, file_path, package_name,
348+ package_version=None, package_revision=None,
349+ package_architecture=None):
350+ """Extract named file from package specified by name, ver, rev, arch.
351+
352+ File is extracted from the package matching the given specification
353+ to a temporary directory. The absolute path to the extracted file is
354+ returned.
355+ """
356+
357+ package_info = self.find_package_for(package_name,
358+ package_version,
359+ package_revision,
360+ package_architecture)
361+ if package_info is None:
362+ return None
363+ tar_file, package = package_info
364+
365+ # Avoid unpacking hardware pack more than once by assigning each one
366+ # its own tempdir to unpack into.
367+ # TODO: update logic that uses self.tempdir so we can get rid of this
368+ # by sharing nicely.
369+ if not package in self.tempdirs:
370+ self.tempdirs[package] = tempfile.mkdtemp()
371+ tempdir = self.tempdirs[package]
372+
373+ # We extract everything in the hardware pack so we don't have to worry
374+ # about chasing links (extract a link, find where it points to, extract
375+ # that...). This is slower, but more reliable.
376+ tar_file.extractall(tempdir)
377+ package_path = os.path.join(tempdir, package)
378+
379+ with PackageUnpacker() as self.package_unpacker:
380+ extracted_file = self.package_unpacker.get_file(package_path,
381+ file_path)
382+ after_tmp = re.sub(self.package_unpacker.tempdir, "",
383+ extracted_file).lstrip("/\\")
384+ extract_dir = os.path.join(tempdir, "extracted",
385+ os.path.dirname(after_tmp))
386+ os.makedirs(extract_dir)
387+ shutil.move(extracted_file, extract_dir)
388+ extracted_file = os.path.join(extract_dir,
389+ os.path.basename(extracted_file))
390+ return extracted_file
391
392=== modified file 'linaro_image_tools/hwpack/hwpack_fields.py'
393--- linaro_image_tools/hwpack/hwpack_fields.py 2012-10-02 14:53:56 +0000
394+++ linaro_image_tools/hwpack/hwpack_fields.py 2012-11-20 10:49:03 +0000
395@@ -86,10 +86,14 @@
396 METADATA_VERSION_FIELD = 'version'
397
398 # The allowed partition layouts.
399+BOOTFS16 = 'bootfs16_rootfs'
400+BOOTFS = 'bootfs_rootfs'
401+RESERVED_BOOTFS = 'reserved_bootfs_rootfs'
402+
403 DEFINED_PARTITION_LAYOUTS = [
404- 'bootfs16_rootfs',
405- 'bootfs_rootfs',
406- 'reserved_bootfs_rootfs', ]
407+ BOOTFS16,
408+ BOOTFS,
409+ RESERVED_BOOTFS, ]
410
411 # Supported bootloaders
412 U_BOOT = 'u_boot'
413
414=== modified file 'linaro_image_tools/hwpack/hwpack_reader.py'
415--- linaro_image_tools/hwpack/hwpack_reader.py 2012-07-25 13:05:16 +0000
416+++ linaro_image_tools/hwpack/hwpack_reader.py 2012-11-20 10:49:03 +0000
417@@ -17,7 +17,7 @@
418 # You should have received a copy of the GNU General Public License
419 # along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>.
420
421-from linaro_image_tools.media_create.boards import HardwarepackHandler
422+from linaro_image_tools.hwpack.handler import HardwarepackHandler
423 from linaro_image_tools.hwpack.hwpack_fields import (
424 FORMAT_FIELD,
425 NAME_FIELD,
426
427=== modified file 'linaro_image_tools/media_create/__init__.py'
428--- linaro_image_tools/media_create/__init__.py 2012-10-22 06:57:20 +0000
429+++ linaro_image_tools/media_create/__init__.py 2012-11-20 10:49:03 +0000
430@@ -78,6 +78,7 @@
431 parser.add_argument(
432 '--extra-boot-args-file', dest='extra_boot_args_file',
433 required=False, help=('File containing extra boot arguments.'))
434+ parser.add_argument("--debug", action="store_true")
435
436
437 def get_args_parser():
438@@ -173,7 +174,6 @@
439 help="Select a bootloader from a hardware pack that contains more "
440 "than one. If not specified, it will default to '%s'." %
441 DEFAULT_BOOTLOADER)
442- parser.add_argument("--debug", action="store_true")
443
444 add_common_options(parser)
445 return parser
446@@ -189,6 +189,9 @@
447 '--image-file', '--image_file', dest='device',
448 help='File where we should write the image file.')
449 parser.add_argument(
450+ '--hwpack', required=True,
451+ help=('An Android hardware pack file with the board configuration.'))
452+ parser.add_argument(
453 '--image-size', '--image_size', default='2G',
454 help=('The image size, specified in mega/giga bytes (e.g. 3000M or '
455 '3G); use with --image_file only'))
456@@ -202,7 +205,6 @@
457 '--console', action='append', dest='consoles', default=[],
458 help=('Add a console to kernel boot parameter; this parameter can be '
459 'defined multiple times.'))
460-
461 parser.add_argument(
462 '--system', default='system.tar.bz2', required=True,
463 help=('The tarball containing the Android system paritition'))
464@@ -212,7 +214,6 @@
465 parser.add_argument(
466 '--boot', default='boot.tar.bz2', required=True,
467 help=('The tarball containing the Android root partition'))
468-
469 parser.add_argument(
470 '--no-part', dest='should_create_partitions', action='store_false',
471 help='Reuse existing partitions on the given media.')
472
473=== modified file 'linaro_image_tools/media_create/android_boards.py'
474--- linaro_image_tools/media_create/android_boards.py 2012-10-17 10:48:49 +0000
475+++ linaro_image_tools/media_create/android_boards.py 2012-11-20 10:49:03 +0000
476@@ -20,44 +20,131 @@
477 """Configuration for boards supported by linaro-android-media-create.
478
479 To add support for a new board, you need to create a subclass of
480-AndroidBoardConfig, set appropriate values for its variables and add it to
481-android_board_configs at the bottom of this file.
482+AndroidBoardConfig, create an Android hwpack as explained here:
483+
484+https://wiki.linaro.org/AndroidHardwarePacksV3
485+
486+and add the board to 'android_board_configs' at the end of this file.
487 """
488
489+import os
490+import yaml
491+import logging
492+
493+from linaro_image_tools import cmd_runner
494 from linaro_image_tools.media_create.partitions import SECTOR_SIZE
495-from linaro_image_tools.media_create.boards import PART_ALIGN_S
496-from linaro_image_tools.media_create.boards import BeagleConfig
497-from linaro_image_tools.media_create.boards import PandaConfig
498-from linaro_image_tools.media_create.boards import Mx53LoCoConfig
499-from linaro_image_tools.media_create.boards import SnowballSdConfig
500-from linaro_image_tools.media_create.boards import SnowballEmmcConfig
501-from linaro_image_tools.media_create.boards import SMDKV310Config
502-from linaro_image_tools.media_create.boards import OrigenConfig
503-from linaro_image_tools.media_create.boards import VexpressConfig
504 from linaro_image_tools.media_create.boards import (
505+ BeagleConfig,
506+ BoardConfig,
507+ BoardConfigException,
508+ Mx53LoCoConfig,
509+ OrigenConfig,
510+ PART_ALIGN_S,
511+ PandaConfig,
512+ SMDKV310Config,
513+ SnowballEmmcConfig,
514+ SnowballSdConfig,
515+ VexpressConfig,
516+ align_partition,
517 align_up,
518- align_partition,
519- classproperty,
520+ install_mx5_boot_loader,
521 make_boot_script,
522- install_mx5_boot_loader,
523 )
524-
525-from linaro_image_tools import cmd_runner
526-import os
527-
528-
529-class AndroidBoardConfig(object):
530- @classmethod
531- def _get_bootargs(cls, consoles):
532+from linaro_image_tools.utils import DEFAULT_LOGGER_NAME
533+
534+logger = logging.getLogger(DEFAULT_LOGGER_NAME)
535+
536+BOOT_MIN_SIZE_S = align_up(128 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
537+SYSTEM_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
538+CACHE_MIN_SIZE_S = align_up(256 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
539+USERDATA_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
540+SDCARD_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
541+LOADER_MIN_SIZE_S = align_up(1 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
542+
543+
544+class AndroidBoardConfig(BoardConfig):
545+
546+ def __init__(self):
547+ super(AndroidBoardConfig, self).__init__()
548+ self._dtb_name = None
549+ self._extra_serial_options = []
550+ self._android_specific_args = []
551+ self._extra_boot_args_options = []
552+
553+ def _get_android_specific_args(self):
554+ return ' '.join(self._android_specific_args)
555+
556+ def _set_android_specific_args(self, value):
557+ self._android_specific_args = value
558+
559+ android_specific_args = property(_get_android_specific_args,
560+ _set_android_specific_args)
561+
562+ def _get_extra_boot_args_options(self):
563+ return ' '.join(self._extra_boot_args_options)
564+
565+ def _set_extra_boot_args_options(self, value):
566+ self._extra_boot_args_options = value
567+
568+ extra_boot_args_options = property(_get_extra_boot_args_options,
569+ _set_extra_boot_args_options)
570+
571+ def _get_extra_serial_options(self):
572+ return ' '.join(self._extra_serial_options)
573+
574+ def _set_extra_serial_options(self, value):
575+ self._extra_serial_options = value
576+
577+ extra_serial_options = property(_get_extra_serial_options,
578+ _set_extra_serial_options)
579+
580+ def _get_dtb_name(self):
581+ return self._dtb_name
582+
583+ def _set_dtb_name(self, value):
584+ self._dtb_name = value
585+
586+ dtb_name = property(_get_dtb_name, _set_dtb_name)
587+
588+ def from_file(self, hwpack):
589+ """Loads the Android board configuration from an Android hardware pack
590+ configuration file and sets the config attributes with their values.
591+
592+ :param hwpack: The Android hwpack configuration file.
593+ :return The configuration read from the file as a dictionary.
594+ """
595+ try:
596+ config = yaml.safe_load(hwpack)
597+ self._set_attributes(config)
598+ return config
599+ except yaml.YAMLError, ex:
600+ logger.debug("Error loading YAML file %s" % hwpack, ex)
601+ raise BoardConfigException("Error reading Android hwpack %s"
602+ % hwpack)
603+
604+ def _set_attributes(self, config):
605+ """Initialize the class attributes with the values read from the
606+ Android hardware pack configuration file.
607+
608+ :param config: The config read from the Android hwpack.
609+ """
610+ for name, value in config.iteritems():
611+ if hasattr(self, name):
612+ setattr(self, name, value)
613+ else:
614+ logger.warning("Attribute '%s' does not belong to this "
615+ "instance of '%s'." % (name, self.__class__))
616+
617+ def _get_bootargs(self, consoles):
618 """Get the bootargs for this board.
619
620 In general subclasses should not have to override this.
621 """
622 boot_args_options = 'rootwait ro'
623- if cls.extra_boot_args_options is not None:
624- boot_args_options += ' %s' % cls.extra_boot_args_options
625- boot_args_options += ' %s' % cls.android_specific_args
626- serial_opts = cls._extra_serial_opts
627+ if self.extra_boot_args_options:
628+ boot_args_options += ' %s' % self.extra_boot_args_options
629+ boot_args_options += ' %s' % self.android_specific_args
630+ serial_opts = self.extra_serial_options
631 for console in consoles:
632 serial_opts += ' console=%s' % console
633
634@@ -69,34 +156,32 @@
635 "%(boot_args_options)s"
636 % replacements)
637
638- @classmethod
639- def _get_boot_env(cls, consoles):
640+ def _get_boot_env(self, consoles):
641 """Get the boot environment for this board.
642
643 In general subclasses should not have to override this.
644 """
645 boot_env = {}
646- boot_env["bootargs"] = cls._get_bootargs(consoles)
647+ boot_env["bootargs"] = self._get_bootargs(consoles)
648 initrd = False
649- if cls.initrd_addr:
650+ if self.initrd_addr:
651 initrd = True
652 # On Android, the DTB file is always built as part of the kernel it
653 # comes from - and lives in the same directory in the boot tarball, so
654 # here we don't need to pass the whole path to it.
655- boot_env["bootcmd"] = cls._get_bootcmd(initrd, cls.dtb_name)
656- boot_env["initrd_high"] = cls.initrd_high
657- boot_env["fdt_high"] = cls.fdt_high
658+ boot_env["bootcmd"] = self._get_bootcmd(initrd, self.dtb_name)
659+ boot_env["initrd_high"] = self.initrd_high
660+ boot_env["fdt_high"] = self.fdt_high
661 return boot_env
662
663- @classmethod
664- def populate_boot_script(cls, boot_partition, boot_disk, consoles):
665+ def populate_boot_script(self, boot_partition, boot_disk, consoles):
666 cmd_runner.run(['mkdir', '-p', boot_disk]).wait()
667 # TODO: Use partition_mounted() here to make sure the partition is
668 # always umounted after we're done.
669 cmd_runner.run(['mount', boot_partition, boot_disk],
670 as_root=True).wait()
671
672- boot_env = cls._get_boot_env(consoles)
673+ boot_env = self._get_boot_env(consoles)
674 cmdline_filepath = os.path.join(boot_disk, "cmdline")
675 cmdline_file = open(cmdline_filepath, 'r')
676 android_kernel_cmdline = cmdline_file.read()
677@@ -105,7 +190,7 @@
678 cmdline_file.close()
679
680 boot_dir = boot_disk
681- boot_script_path = os.path.join(boot_dir, cls.boot_script)
682+ boot_script_path = os.path.join(boot_dir, self.boot_script)
683 make_boot_script(boot_env, boot_script_path)
684
685 cmd_runner.run(['sync']).wait()
686@@ -114,25 +199,13 @@
687 except cmd_runner.SubcommandNonZeroReturnValue:
688 pass
689
690- @classmethod
691- def get_sfdisk_cmd(cls, should_align_boot_part=False,
692+ def get_sfdisk_cmd(self, should_align_boot_part=False,
693 start_addr=0, extra_part=False):
694- if cls.fat_size == 32:
695+ if self.fat_size == 32:
696 partition_type = '0x0C'
697 else:
698 partition_type = '0x0E'
699
700- BOOT_MIN_SIZE_S = align_up(
701- 128 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
702- SYSTEM_MIN_SIZE_S = align_up(
703- 512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
704- CACHE_MIN_SIZE_S = align_up(
705- 256 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
706- USERDATA_MIN_SIZE_S = align_up(
707- 512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
708- SDCARD_MIN_SIZE_S = align_up(
709- 512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
710-
711 # align on sector 63 for compatibility with broken versions of x-loader
712 # unless align_boot_part is set
713 boot_align = 63
714@@ -174,86 +247,48 @@
715 cache_start, _cache_len, userdata_start, userdata_start,
716 _userdata_len, sdcard_start)
717
718- @classmethod
719- def populate_raw_partition(cls, media, boot_dir):
720- super(AndroidBoardConfig, cls).populate_raw_partition(media, boot_dir)
721+ def populate_raw_partition(self, media, boot_dir):
722+ super(AndroidBoardConfig, self).populate_raw_partition(media, boot_dir)
723
724- @classmethod
725- def install_boot_loader(cls, boot_partition, boot_device_or_file):
726+ def install_boot_loader(self, boot_partition, boot_device_or_file):
727 pass
728
729
730 class AndroidOmapConfig(AndroidBoardConfig):
731- dtb_name = None
732-
733-
734-class AndroidBeagleConfig(AndroidOmapConfig, BeagleConfig):
735- _extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'
736- android_specific_args = 'init=/init androidboot.console=ttyO2'
737- dtb_name = None
738-
739-
740-class AndroidPandaConfig(AndroidOmapConfig, PandaConfig):
741- bootloader_flavor = 'omap4_panda'
742- dtb_addr = '0x815f0000'
743- dtb_name = 'board.dtb'
744- _extra_serial_opts = 'console=ttyO2,115200n8'
745- extra_boot_args_options = (
746- 'earlyprintk fixrtc nocompcache vram=48M '
747- 'omapfb.vram=0:24M,1:24M mem=456M@0x80000000 mem=512M@0xA0000000')
748- android_specific_args = 'init=/init androidboot.console=ttyO2'
749+ """Placeholder class for OMAP configuration inheritance."""
750+
751+
752+class AndroidBeagleConfig(AndroidBoardConfig, BeagleConfig):
753+ """Placeholder class for Beagle configuration inheritance."""
754+
755+
756+class AndroidPandaConfig(AndroidBoardConfig, PandaConfig):
757+ """Placeholder class for Panda configuration inheritance."""
758
759
760 class AndroidSnowballSdConfig(AndroidBoardConfig, SnowballSdConfig):
761- boot_script = 'boot.scr'
762- fdt_high = '0x05000000'
763- initrd_addr = '0x05000000'
764- initrd_high = '0x06000000'
765- extra_boot_args_options = (
766- 'earlyprintk mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
767- 'mem=22M@360M mem_issw=1M@383M mem=640M@384M vmalloc=500M')
768- _extra_serial_opts = 'console=ttyAMA2,115200n8'
769- android_specific_args = 'init=/init androidboot.console=ttyAMA2'
770- dtb_name = 'board.dtb'
771- dtb_addr = '0x8000000'
772+ """Placeholder class for Snowball SD configuration inheritance."""
773
774
775 class AndroidSnowballEmmcConfig(AndroidBoardConfig, SnowballEmmcConfig):
776- boot_script = 'boot.scr'
777- fdt_high = '0x05000000'
778- initrd_addr = '0x05000000'
779- initrd_high = '0x06000000'
780- extra_boot_args_options = (
781- 'earlyprintk mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
782- 'mem=22M@360M mem_issw=1M@383M mem=640M@384M vmalloc=500M')
783- _extra_serial_opts = 'console=ttyAMA2,115200n8'
784- android_specific_args = 'init=/init androidboot.console=ttyAMA2'
785- mmc_option = '0:2'
786- dtb_name = 'board.dtb'
787- dtb_addr = '0x8000000'
788-
789- @classmethod
790- def get_sfdisk_cmd(cls, should_align_boot_part=False):
791-
792- LOADER_MIN_SIZE_S = align_up(
793- 1 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
794-
795+ """Snowball EMMC configuration inheritance."""
796+
797+ def get_sfdisk_cmd(self, should_align_boot_part=False):
798 loader_start, loader_end, loader_len = align_partition(
799 SnowballEmmcConfig.SNOWBALL_LOADER_START_S,
800 LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
801
802- command = super(AndroidSnowballEmmcConfig, cls).get_sfdisk_cmd(
803+ command = super(AndroidSnowballEmmcConfig, self).get_sfdisk_cmd(
804 should_align_boot_part=True, start_addr=loader_end,
805 extra_part=True)
806
807 return '%s,%s,0xDA\n%s' % (
808 loader_start, loader_len, command)
809
810- @classmethod
811- def populate_raw_partition(cls, media, boot_dir):
812+ def populate_raw_partition(self, media, boot_dir):
813 # To avoid adding a Snowball specific command line option, we assume
814 # that the user already has unpacked the startfiles to ./startupfiles
815- config_files_dir = cls.snowball_config(boot_dir)
816+ config_files_dir = self.snowball_config(boot_dir)
817 assert os.path.exists(config_files_dir), (
818 "You need to unpack the Snowball startupfiles to the directory "
819 "'startupfiles' in your current working directory. See "
820@@ -264,72 +299,85 @@
821 for boot_file in boot_files:
822 cmd_runner.run(['cp', os.path.join(boot_dir, 'boot', boot_file),
823 config_files_dir], as_root=True).wait()
824- super(AndroidSnowballEmmcConfig, cls).populate_raw_partition(
825+ super(AndroidSnowballEmmcConfig, self).populate_raw_partition(
826 media, boot_dir)
827
828- @classmethod
829- def snowball_config(cls, chroot_dir):
830+ def snowball_config(self, chroot_dir):
831 # The user is expected to have unpacked the startupfiles to this subdir
832 # of their working dir.
833 return os.path.join('.', 'startupfiles')
834
835- @classproperty
836- def delete_startupfiles(cls):
837+ @property
838+ def delete_startupfiles(self):
839 # The startupfiles will have been unpacked to the user's working dir
840 # and should not be deleted after they have been installed.
841 return False
842
843
844 class AndroidMx53LoCoConfig(AndroidBoardConfig, Mx53LoCoConfig):
845- extra_boot_args_options = (
846- 'earlyprintk rootdelay=1 fixrtc nocompcache di1_primary tve')
847- _extra_serial_opts = 'console=%s,115200n8' % (
848- Mx53LoCoConfig.serial_tty)
849- android_specific_args = 'init=/init androidboot.console=%s' % (
850- Mx53LoCoConfig.serial_tty)
851- dtb_name = None
852-
853- @classmethod
854- def get_sfdisk_cmd(cls, should_align_boot_part=False):
855+ """Mx53LoCo configuration inheritance."""
856+
857+ def _get_extra_serial_options(self):
858+ serial_opts = self._extra_serial_options
859+ if serial_opts:
860+ if isinstance(serial_opts, list):
861+ serial_opts = ' '.join(serial_opts)
862+ if self._check_placeholder_presence(serial_opts, '%s'):
863+ serial_opts = serial_opts % self.serial_tty
864+ return serial_opts
865+
866+ def _set_extra_serial_options(self, value):
867+ self._extra_serial_options = value
868+
869+ extra_serial_options = property(_get_extra_serial_options,
870+ _set_extra_serial_options)
871+
872+ def _get_android_specific_args(self):
873+ android_args = self._android_specific_args
874+ if android_args:
875+ if isinstance(android_args, list):
876+ android_args = ' '.join(android_args)
877+ if self._check_placeholder_presence(android_args, '%s'):
878+ android_args = android_args % self.serial_tty
879+ return android_args
880+
881+ def _set_android_specific_args(self, value):
882+ self._android_specific_args = value
883+
884+ android_specific_args = property(_get_android_specific_args,
885+ _set_android_specific_args)
886+
887+ def get_sfdisk_cmd(self, should_align_boot_part=False):
888 loader_start, loader_end, loader_len = align_partition(
889- 1, cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
890+ 1, self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
891
892- command = super(AndroidMx53LoCoConfig, cls).get_sfdisk_cmd(
893+ command = super(AndroidMx53LoCoConfig, self).get_sfdisk_cmd(
894 should_align_boot_part=True, start_addr=loader_end,
895 extra_part=True)
896
897 return '%s,%s,0xDA\n%s' % (
898 loader_start, loader_len, command)
899
900- @classmethod
901- def install_boot_loader(cls, boot_partition, boot_device_or_file):
902+ def install_boot_loader(self, boot_partition, boot_device_or_file):
903 install_mx5_boot_loader(
904 os.path.join(boot_device_or_file, "u-boot.imx"),
905- boot_partition, cls.LOADER_MIN_SIZE_S)
906+ boot_partition, self.LOADER_MIN_SIZE_S)
907
908
909 class AndroidMx6QSabreliteConfig(AndroidMx53LoCoConfig):
910- bootloader_flavor = 'mx6qsabrelite'
911- kernel_addr = '0x10000000'
912- initrd_addr = '0x12000000'
913- load_addr = '0x10008000'
914- dtb_addr = '0x11ff0000'
915- dtb_name = 'board.dtb'
916+ """Placeholder class for Mx6Q Sabrelite configuration inheritance."""
917
918
919 class AndroidSamsungConfig(AndroidBoardConfig):
920- dtb_name = None
921-
922- @classmethod
923- def get_sfdisk_cmd(cls, should_align_boot_part=False):
924+ def get_sfdisk_cmd(self, should_align_boot_part=False):
925 loaders_min_len = (
926- cls.SAMSUNG_V310_BL2_START + cls.SAMSUNG_V310_BL2_LEN -
927- cls.SAMSUNG_V310_BL1_START)
928+ self.samsung_v310_bl2_start + self.samsung_v310_bl2_len -
929+ self.samsung_v310_bl1_start)
930
931 loader_start, loader_end, loader_len = align_partition(
932 1, loaders_min_len, 1, PART_ALIGN_S)
933
934- command = super(AndroidSamsungConfig, cls).get_sfdisk_cmd(
935+ command = super(AndroidSamsungConfig, self).get_sfdisk_cmd(
936 should_align_boot_part=False, start_addr=loader_end,
937 extra_part=True)
938
939@@ -338,33 +386,47 @@
940
941
942 class AndroidSMDKV310Config(AndroidSamsungConfig, SMDKV310Config):
943- _extra_serial_opts = 'console=tty0 console=ttySAC1,115200n8'
944- android_specific_args = 'init=/init androidboot.console=ttySAC1'
945- dtb_name = None
946+ """Placeholder class for SMDKV310 configuration inheritance."""
947
948
949 class AndroidOrigenConfig(AndroidSamsungConfig, OrigenConfig):
950- _extra_serial_opts = 'console=tty0 console=ttySAC2,115200n8'
951- android_specific_args = 'init=/init androidboot.console=ttySAC2'
952- dtb_name = None
953+ """Placeholder class for Origen configuration inheritance."""
954
955
956 class AndroidVexpressConfig(AndroidBoardConfig, VexpressConfig):
957- _extra_serial_opts = 'console=tty0 console=ttyAMA0,38400n8'
958- android_specific_args = 'init=/init androidboot.console=ttyAMA0'
959- dtb_name = None
960-
961-
962+ """Placeholder class for Vexpress configuration inheritance."""
963+
964+
965+# This dictionary is composed as follows:
966+# <device_name>: <class>
967+# The <device_name> is the command line argument passed to l-a-m-c, the
968+# <class> is the corresponding config class in this file (not the instance).
969+# If a new device does not have special needs, it is possible to use the
970+# general AndroidBoardConfig class.
971 android_board_configs = {
972 'beagle': AndroidBeagleConfig,
973- 'panda': AndroidPandaConfig,
974- 'snowball_sd': AndroidSnowballSdConfig,
975- 'snowball_emmc': AndroidSnowballEmmcConfig,
976- 'smdkv310': AndroidSMDKV310Config,
977+ 'iMX53': AndroidMx53LoCoConfig,
978 'mx53loco': AndroidMx53LoCoConfig,
979- 'iMX53': AndroidMx53LoCoConfig,
980 'mx6qsabrelite': AndroidMx6QSabreliteConfig,
981 'origen': AndroidOrigenConfig,
982+ 'panda': AndroidPandaConfig,
983+ 'smdkv310': AndroidSMDKV310Config,
984+ 'snowball_emmc': AndroidSnowballEmmcConfig,
985+ 'snowball_sd': AndroidSnowballSdConfig,
986 'vexpress': AndroidVexpressConfig,
987 'vexpress-a9': AndroidVexpressConfig,
988 }
989+
990+
991+def get_board_config(board):
992+ """Get the board configuration for the specified board.
993+
994+ :param board: The name of the board to get the configuration of.
995+ :type board: str
996+ """
997+ clazz = android_board_configs.get(board, None)
998+ if clazz:
999+ return clazz()
1000+ else:
1001+ raise BoardConfigException("Board name '%s' has no configuration "
1002+ "available." % board)
1003
1004=== modified file 'linaro_image_tools/media_create/boards.py'
1005--- linaro_image_tools/media_create/boards.py 2012-10-22 06:57:20 +0000
1006+++ linaro_image_tools/media_create/boards.py 2012-11-20 10:49:03 +0000
1007@@ -24,28 +24,58 @@
1008 board_configs at the bottom of this file.
1009 """
1010
1011+from binascii import crc32
1012+from parted import Device
1013 import atexit
1014 import glob
1015+import logging
1016 import os
1017 import re
1018+import string
1019+import struct
1020 import tempfile
1021-import struct
1022-from binascii import crc32
1023-import tarfile
1024-import ConfigParser
1025-import shutil
1026-import string
1027-import logging
1028-from linaro_image_tools.hwpack.config import Config
1029-from linaro_image_tools.hwpack.builder import PackageUnpacker
1030-
1031-from parted import Device
1032
1033 from linaro_image_tools import cmd_runner
1034
1035 from linaro_image_tools.media_create.partitions import (
1036- partition_mounted, SECTOR_SIZE, register_loopback)
1037-from StringIO import StringIO
1038+ SECTOR_SIZE,
1039+ partition_mounted,
1040+ register_loopback,
1041+ )
1042+
1043+from linaro_image_tools.hwpack.handler import HardwarepackHandler
1044+
1045+from linaro_image_tools.hwpack.hwpack_fields import (
1046+ BOOTFS,
1047+ BOOTFS16,
1048+ BOOT_MIN_SIZE_FIELD,
1049+ BOOT_SCRIPT_FIELD,
1050+ DTB_ADDR_FIELD,
1051+ DTB_FILES_FIELD,
1052+ DTB_FILE_FIELD,
1053+ ENV_DD_FIELD,
1054+ EXTRA_BOOT_OPTIONS_FIELD,
1055+ EXTRA_SERIAL_OPTIONS_FIELD,
1056+ INITRD_ADDR_FIELD,
1057+ KERNEL_ADDR_FIELD,
1058+ LOADER_MIN_SIZE_FIELD,
1059+ LOADER_START_FIELD,
1060+ LOAD_ADDR_FIELD,
1061+ MMC_ID_FIELD,
1062+ PARTITION_LAYOUT_FIELD,
1063+ RESERVED_BOOTFS,
1064+ ROOT_MIN_SIZE_FIELD,
1065+ SAMSUNG_BL1_LEN_FIELD,
1066+ SAMSUNG_BL1_START_FIELD,
1067+ SAMSUNG_BL2_LEN_FIELD,
1068+ SAMSUNG_ENV_LEN_FIELD,
1069+ SERIAL_TTY_FIELD,
1070+ SNOWBALL_STARTUP_FILES_CONFIG_FIELD,
1071+ SPL_DD_FIELD,
1072+ SPL_IN_BOOT_PART_FIELD,
1073+ WIRED_INTERFACES_FIELD,
1074+ WIRELESS_INTERFACES_FIELD,
1075+ )
1076
1077 logger = logging.getLogger(__name__)
1078
1079@@ -106,580 +136,336 @@
1080 cmd_runner.run(cmd, as_root=True).wait()
1081
1082
1083-class classproperty(object):
1084- """A descriptor that provides @property behavior on class methods."""
1085- def __init__(self, getter):
1086- self.getter = getter
1087-
1088- def __get__(self, instance, cls):
1089- return self.getter(cls)
1090-
1091-
1092-class HardwarepackHandler(object):
1093- FORMAT_1 = '1.0'
1094- FORMAT_2 = '2.0'
1095- FORMAT_3 = '3.0'
1096- FORMAT_MIXED = '1.0and2.0'
1097- metadata_filename = 'metadata'
1098- format_filename = 'FORMAT'
1099- main_section = 'main'
1100- hwpack_tarfiles = []
1101- tempdir = None
1102-
1103- def __init__(self, hwpacks, bootloader=None, board=None):
1104- self.hwpacks = hwpacks
1105- self.hwpack_tarfiles = []
1106- self.bootloader = bootloader
1107- self.board = board
1108- self.tempdirs = {}
1109- # Used to store the config created from the metadata.
1110- self.config = None
1111-
1112- class FakeSecHead(object):
1113- """ Add a fake section header to the metadata file.
1114-
1115- This is done so we can use ConfigParser to parse the file.
1116- """
1117- def __init__(self, fp):
1118- self.fp = fp
1119- self.sechead = '[%s]\n' % HardwarepackHandler.main_section
1120-
1121- def readline(self):
1122- if self.sechead:
1123- try:
1124- return self.sechead
1125- finally:
1126- self.sechead = None
1127- else:
1128- return self.fp.readline()
1129-
1130- def __enter__(self):
1131- self.tempdir = tempfile.mkdtemp()
1132- for hwpack in self.hwpacks:
1133- hwpack_tarfile = tarfile.open(hwpack, mode='r:gz')
1134- self.hwpack_tarfiles.append(hwpack_tarfile)
1135- return self
1136-
1137- def __exit__(self, type, value, traceback):
1138- for hwpack_tarfile in self.hwpack_tarfiles:
1139- if hwpack_tarfile is not None:
1140- hwpack_tarfile.close()
1141- self.hwpack_tarfiles = []
1142- if self.tempdir is not None and os.path.exists(self.tempdir):
1143- shutil.rmtree(self.tempdir)
1144-
1145- for name in self.tempdirs:
1146- tempdir = self.tempdirs[name]
1147- if tempdir is not None and os.path.exists(tempdir):
1148- shutil.rmtree(tempdir)
1149-
1150- def _get_config_from_metadata(self, metadata):
1151- """
1152- Retrieves a Config object associated with the metadata.
1153-
1154- :param metadata: The metadata to parse.
1155- :return: A Config instance.
1156- """
1157- if not self.config:
1158- lines = metadata.readlines()
1159- if re.search("=", lines[0]) and not re.search(":", lines[0]):
1160- # Probably V2 hardware pack without [hwpack] on the first line
1161- lines = ["[hwpack]\n"] + lines
1162- self.config = Config(StringIO("".join(lines)))
1163- self.config.set_board(self.board)
1164- self.config.set_bootloader(self.bootloader)
1165- return self.config
1166-
1167- def get_field(self, field, return_keys=False):
1168- data = None
1169- hwpack_with_data = None
1170- keys = None
1171- for hwpack_tarfile in self.hwpack_tarfiles:
1172- metadata = hwpack_tarfile.extractfile(self.metadata_filename)
1173- parser = self._get_config_from_metadata(metadata)
1174- try:
1175- new_data = parser.get_option(field)
1176- if new_data is not None:
1177- assert data is None, "The metadata field '%s' is set to " \
1178- "'%s' and new value '%s' is found" % (field, data,
1179- new_data)
1180- data = new_data
1181- hwpack_with_data = hwpack_tarfile
1182- if return_keys:
1183- keys = parser.get_last_used_keys()
1184- except ConfigParser.NoOptionError:
1185- continue
1186-
1187- if return_keys:
1188- return data, hwpack_with_data, keys
1189- return data, hwpack_with_data
1190-
1191- def get_format(self):
1192- format = None
1193- supported_formats = [self.FORMAT_1, self.FORMAT_2, self.FORMAT_3]
1194- for hwpack_tarfile in self.hwpack_tarfiles:
1195- format_file = hwpack_tarfile.extractfile(self.format_filename)
1196- format_string = format_file.read().strip()
1197- if not format_string in supported_formats:
1198- raise AssertionError(
1199- "Format version '%s' is not supported." % format_string)
1200- if format is None:
1201- format = format_string
1202- elif format != format_string:
1203- return self.FORMAT_MIXED
1204- return format
1205-
1206- def get_file(self, file_alias):
1207- """Get file(s) from a hwpack.
1208- :param file_alias: Property name (not field name) which contains
1209- file reference(s)
1210- :return: path to a file or list of paths to files
1211- """
1212- file_names, hwpack_tarfile, keys = self.get_field(file_alias,
1213- return_keys=True)
1214- if not file_names:
1215- return file_names
1216- single = False
1217- if not isinstance(file_names, list):
1218- single = True
1219- file_names = [file_names]
1220- out_files = []
1221-
1222- # Depending on if board and/or bootloader were used to look up the
1223- # file we are getting, we need to prepend those names to the path
1224- # to get the correct extracted file from the hardware pack.
1225- config_names = [("board", "boards"), ("bootloader", "bootloaders")]
1226- base_path = ""
1227- if keys:
1228- # If keys is non-empty, we have a V3 config option that was
1229- # modified by the bootloader and/or boot option...
1230- for name, key in config_names:
1231- if self.get_field(name):
1232- value = self.get_field(name)[0]
1233- if keys[0] == key:
1234- base_path = os.path.join(base_path, value)
1235- keys = keys[1:]
1236-
1237- for f in file_names:
1238- # Check that the base path is needed. If the file doesn't exist,
1239- # try without it (this provides fallback to V2 style directory
1240- # layouts with a V3 config).
1241- path_inc_board_and_bootloader = os.path.join(base_path, f)
1242- if path_inc_board_and_bootloader in hwpack_tarfile.getnames():
1243- f = path_inc_board_and_bootloader
1244- hwpack_tarfile.extract(f, self.tempdir)
1245- f = os.path.join(self.tempdir, f)
1246- out_files.append(f)
1247- if single:
1248- return out_files[0]
1249- return out_files
1250-
1251- def list_packages(self):
1252- """Return list of (package names, TarFile object containing them)"""
1253- packages = []
1254- for tf in self.hwpack_tarfiles:
1255- for name in tf.getnames():
1256- if name.startswith("pkgs/") and name.endswith(".deb"):
1257- packages.append((tf, name))
1258- return packages
1259-
1260- def find_package_for(self, name, version=None, revision=None,
1261- architecture=None):
1262- """Find a package that matches the name, version, rev and arch given.
1263-
1264- Packages are named according to the debian specification:
1265- http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html
1266- <name>_<Version>-<DebianRevisionNumber>_<DebianArchitecture>.deb
1267- DebianRevisionNumber seems to be optional.
1268- Use this spec to return a package matching the requirements given.
1269- """
1270- for tar_file, package in self.list_packages():
1271- file_name = os.path.basename(package)
1272- dpkg_chunks = re.search("^(.+)_(.+)_(.+)\.deb$",
1273- file_name)
1274- assert dpkg_chunks, "Could not split package file name into"\
1275- "<name>_<Version>_<DebianArchitecture>.deb"
1276-
1277- pkg_name = dpkg_chunks.group(1)
1278- pkg_version = dpkg_chunks.group(2)
1279- pkg_architecture = dpkg_chunks.group(3)
1280-
1281- ver_chunks = re.search("^(.+)-(.+)$", pkg_version)
1282- if ver_chunks:
1283- pkg_version = ver_chunks.group(1)
1284- pkg_revision = ver_chunks.group(2)
1285- else:
1286- pkg_revision = None
1287-
1288- if name != pkg_name:
1289- continue
1290- if version != None and str(version) != pkg_version:
1291- continue
1292- if revision != None and str(revision) != pkg_revision:
1293- continue
1294- if (architecture != None and
1295- str(architecture) != pkg_architecture):
1296- continue
1297-
1298- # Got a matching package - return its path inside the tarball
1299- return tar_file, package
1300-
1301- # Failed to find a matching package - return None
1302- return None
1303-
1304- def get_file_from_package(self, file_path, package_name,
1305- package_version=None, package_revision=None,
1306- package_architecture=None):
1307- """Extract named file from package specified by name, ver, rev, arch.
1308-
1309- File is extracted from the package matching the given specification
1310- to a temporary directory. The absolute path to the extracted file is
1311- returned.
1312- """
1313-
1314- package_info = self.find_package_for(package_name,
1315- package_version,
1316- package_revision,
1317- package_architecture)
1318- if package_info is None:
1319- return None
1320- tar_file, package = package_info
1321-
1322- # Avoid unpacking hardware pack more than once by assigning each one
1323- # its own tempdir to unpack into.
1324- # TODO: update logic that uses self.tempdir so we can get rid of this
1325- # by sharing nicely.
1326- if not package in self.tempdirs:
1327- self.tempdirs[package] = tempfile.mkdtemp()
1328- tempdir = self.tempdirs[package]
1329-
1330- # We extract everything in the hardware pack so we don't have to worry
1331- # about chasing links (extract a link, find where it points to, extract
1332- # that...). This is slower, but more reliable.
1333- tar_file.extractall(tempdir)
1334- package_path = os.path.join(tempdir, package)
1335-
1336- with PackageUnpacker() as self.package_unpacker:
1337- extracted_file = self.package_unpacker.get_file(package_path,
1338- file_path)
1339- after_tmp = re.sub(self.package_unpacker.tempdir, "",
1340- extracted_file).lstrip("/\\")
1341- extract_dir = os.path.join(tempdir, "extracted",
1342- os.path.dirname(after_tmp))
1343- os.makedirs(extract_dir)
1344- shutil.move(extracted_file, extract_dir)
1345- extracted_file = os.path.join(extract_dir,
1346- os.path.basename(extracted_file))
1347- return extracted_file
1348-
1349-
1350 class BoardConfig(object):
1351- board = None
1352 """The configuration used when building an image for a board."""
1353- hwpack_format = None
1354- # These attributes may not need to be redefined on some subclasses.
1355- bootloader_flavor = None
1356- # whether to copy u-boot to the boot partition
1357- bootloader_file_in_boot_part = False
1358- bootloader_dd = False
1359- spl_in_boot_part = False
1360- spl_dd = False
1361- env_dd = False
1362- fatload_command = 'fatload'
1363- mmc_option = '0:1'
1364- mmc_device_id = 0
1365- mmc_part_offset = 0
1366- uimage_path = ''
1367- fat_size = 32
1368- extra_serial_opts = ''
1369- _extra_serial_opts = ''
1370- _live_serial_opts = ''
1371- extra_boot_args_options = None
1372- supports_writing_to_mmc = True
1373+
1374 LOADER_MIN_SIZE_S = align_up(1 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE
1375 BOOT_MIN_SIZE_S = align_up(50 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE
1376 ROOT_MIN_SIZE_S = align_up(50 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE
1377
1378- # These attributes must be defined on all subclasses for backwards
1379- # compatibility with hwpacks v1 format. Hwpacks v2 format allows these to
1380- # be specified in the hwpack metadata.
1381- kernel_addr = None
1382- initrd_addr = None
1383- initrd_high = '0xffffffff'
1384- load_addr = None
1385- dtb_addr = None
1386- dtb_name = None
1387- dtb_file = None
1388- fdt_high = '0xffffffff'
1389- kernel_flavors = None
1390- boot_script = None
1391- serial_tty = None
1392- wired_interfaces = None
1393- wireless_interfaces = None
1394- mmc_id = None
1395- vmlinuz = None
1396- initrd = None
1397- partition_layout = None
1398- LOADER_START_S = 1
1399-
1400- # Support for dtb_files as per hwpack v3 format.
1401- dtb_files = None
1402-
1403- # Samsung v310 implementation notes and terminology
1404- #
1405- # * BL0, BL1 etc. are the various bootloaders in order of execution
1406- # * BL0 is the first stage bootloader, located in ROM; it loads a 32s
1407- # long BL1 from MMC offset +1s and runs it
1408- # * BL1 is the secondary program loader (SPL), a small (< 14k) version
1409- # of U-Boot with a checksum; it inits DRAM and loads a 1024s long BL2
1410- # to DRAM from MMC offset +65s
1411- # * BL2 is U-Boot; it loads its 32s (16 KiB) long environment from MMC
1412- # offset +33s which tells it to load a boot.scr from the first FAT
1413- # partition of the MMC
1414- #
1415- # Layout:
1416- # +0s: part table / MBR, 1s long
1417- # +1s: BL1/SPL, 32s long
1418- # +33s: U-Boot environment, 32s long
1419- # +65s: U-Boot, 1024s long
1420- # >= +1089s: FAT partition with boot script (boot.scr), kernel (uImage)
1421- # and initrd (uInitrd)
1422- SAMSUNG_V310_BL1_START = 1
1423- SAMSUNG_V310_BL1_LEN = 32
1424- SAMSUNG_V310_ENV_START = SAMSUNG_V310_BL1_START + SAMSUNG_V310_BL1_LEN
1425- SAMSUNG_V310_ENV_LEN = 32
1426- assert SAMSUNG_V310_ENV_START == 33, (
1427- "BL1 expects u-boot environment at +33s")
1428- assert SAMSUNG_V310_ENV_LEN * SECTOR_SIZE == 16 * 1024, (
1429- "BL1 expects u-boot environment to be 16 KiB")
1430- SAMSUNG_V310_BL2_START = SAMSUNG_V310_ENV_START + SAMSUNG_V310_ENV_LEN
1431- SAMSUNG_V310_BL2_LEN = 1024
1432- assert SAMSUNG_V310_BL2_LEN * SECTOR_SIZE == 512 * 1024, (
1433- "BL1 expects BL2 (u-boot) to be 512 KiB")
1434-
1435- hardwarepack_handler = None
1436-
1437- @classmethod
1438- def get_metadata_field(cls, field_name):
1439+ def __init__(self):
1440+ super(BoardConfig, self).__init__()
1441+ # XXX: when killing v1 hwpack, we might rename these two without the
1442+ # leading underscore. It is done in this way since sublcasses use
1443+ # placeholders in the string for dinamically change values. But this
1444+ # is done only for hwpack v1.
1445+ self._extra_serial_opts = ''
1446+ self._live_serial_opts = ''
1447+ self.board = None
1448+ self.boot_script = None
1449+ self.bootloader_dd = False
1450+ self.bootloader_file_in_boot_part = False
1451+ self.bootloader_flavor = None
1452+ self.dtb_addr = None
1453+ self.dtb_file = None
1454+ self.dtb_files = None
1455+ self.dtb_name = None
1456+ self.env_dd = False
1457+ self.extra_boot_args_options = None
1458+ self.fat_size = 32
1459+ self.fatload_command = 'fatload'
1460+ self.fdt_high = '0xffffffff'
1461+ self.hardwarepack_handler = None
1462+ self.hwpack_format = None
1463+ self.initrd_addr = None
1464+ self.initrd_high = '0xffffffff'
1465+ self.kernel_addr = None
1466+ self.kernel_flavors = None
1467+ self.load_addr = None
1468+ self.loader_start_s = 1
1469+ self.mmc_device_id = 0
1470+ self.mmc_id = None
1471+ self.mmc_option = '0:1'
1472+ self.mmc_part_offset = 0
1473+ self.partition_layout = None
1474+ self.serial_tty = None
1475+ self.spl_dd = False
1476+ self.spl_in_boot_part = False
1477+ self.supports_writing_to_mmc = True
1478+ self.uimage_path = ''
1479+ self.wired_interfaces = None
1480+ self.wireless_interfaces = None
1481+ # Samsung v310 implementation notes and terminology
1482+ #
1483+ # * BL0, BL1 etc. are the various bootloaders in order of execution
1484+ # * BL0 is the first stage bootloader, located in ROM; it loads a 32s
1485+ # long BL1 from MMC offset +1s and runs it
1486+ # * BL1 is the secondary program loader (SPL), a small (< 14k) version
1487+ # of U-Boot with a checksum; it inits DRAM and loads a 1024s long BL2
1488+ # to DRAM from MMC offset +65s
1489+ # * BL2 is U-Boot; it loads its 32s (16 KiB) long environment from MMC
1490+ # offset +33s which tells it to load a boot.scr from the first FAT
1491+ # partition of the MMC
1492+ #
1493+ # Layout:
1494+ # +0s: part table / MBR, 1s long
1495+ # +1s: BL1/SPL, 32s long
1496+ # +33s: U-Boot environment, 32s long
1497+ # +65s: U-Boot, 1024s long
1498+ # >= +1089s: FAT partition with boot script (boot.scr), kernel (uImage)
1499+ # and initrd (uInitrd)
1500+ self.samsung_v310_bl1_start = 1
1501+ self.samsung_v310_bl1_len = 32
1502+ self._samsung_v310_env_start = (self.samsung_v310_bl1_start +
1503+ self.samsung_v310_bl1_len)
1504+ self._samsung_v310_env_len = 32
1505+ self._samsung_v310_bl2_start = (self.samsung_v310_env_start +
1506+ self.samsung_v310_env_len)
1507+ self._samsung_v310_bl2_len = 1024
1508+ # XXX: attributes that are not listed in hwpackV3, should be removed?
1509+ self.vmlinuz = None
1510+ self.initrd = None
1511+
1512+ def _get_samsung_v310_env_start(self):
1513+ return self._samsung_v310_env_start
1514+
1515+ def _set_samsung_v310_env_start(self, value):
1516+ assert value == 33, ("BL1 expects u-boot environment at +33s.")
1517+ self._samsung_v310_env_start = value
1518+
1519+ samsung_v310_env_start = property(_get_samsung_v310_env_start,
1520+ _set_samsung_v310_env_start)
1521+
1522+ def _get_samsung_v310_env_len(self):
1523+ return self._samsung_v310_env_len
1524+
1525+ def _set_samsung_v310_env_len(self, value):
1526+ assert value * SECTOR_SIZE == 16 * 1024, ("BL1 expects u-boot "
1527+ "environment to be 16 KiB.")
1528+ self._samsung_v310_env_len = value
1529+
1530+ samsung_v310_env_len = property(_get_samsung_v310_env_len,
1531+ _set_samsung_v310_env_len)
1532+
1533+ def _get_samsung_v310_bl2_start(self):
1534+ return self._samsung_v310_bl2_start
1535+
1536+ def _set_samsung_v310_bl2_start(self, value):
1537+ self._samsung_v310_bl2_start = value
1538+
1539+ samsung_v310_bl2_start = property(_get_samsung_v310_bl2_start,
1540+ _set_samsung_v310_bl2_start)
1541+
1542+ def _get_samsung_v310_bl2_len(self):
1543+ return self._samsung_v310_bl2_len
1544+
1545+ def _set_samsung_v310_bl2_len(self, value):
1546+ assert value * SECTOR_SIZE == 512 * 1024, ("BL1 expects BL2 (u-boot) "
1547+ "to be 512 KiB.")
1548+ self._samsung_v310_bl2_len = value
1549+
1550+ samsung_v310_bl2_len = property(_get_samsung_v310_bl2_len,
1551+ _set_samsung_v310_bl2_len)
1552+
1553+ # XXX: can be removed when killing v1 hwpack.
1554+ def _get_live_serial_opts(self):
1555+ return_value = self._live_serial_opts
1556+ if self._check_placeholder_presence(return_value, r'%s'):
1557+ return_value = self._live_serial_opts % self.serial_tty
1558+ return return_value
1559+
1560+ def _set_live_serial_opts(self, value):
1561+ self._live_serial_opts = value
1562+
1563+ live_serial_opts = property(_get_live_serial_opts, _set_live_serial_opts)
1564+
1565+ # XXX: can be removed when killing v1 hwpack.
1566+ def _get_extra_serial_opts(self):
1567+ return_value = self._extra_serial_opts
1568+ if self._check_placeholder_presence(return_value, r'%s'):
1569+ return_value = return_value % self.serial_tty
1570+ return return_value
1571+
1572+ def _set_extra_serial_opts(self, value):
1573+ self._extra_serial_opts = value
1574+
1575+ extra_serial_opts = property(_get_extra_serial_opts,
1576+ _set_extra_serial_opts)
1577+
1578+ def get_metadata_field(self, field_name):
1579 """ Return the metadata value for field_name if it can be found.
1580 """
1581- data, _ = cls.hardwarepack_handler.get_field(field_name)
1582+ data, _ = self.hardwarepack_handler.get_field(field_name)
1583 return data
1584
1585- @classmethod
1586- def set_board(cls, board):
1587- cls.board = board
1588-
1589- @classmethod
1590- def set_metadata(cls, hwpacks, bootloader=None, board=None):
1591- cls.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
1592+ def set_metadata(self, hwpacks, bootloader=None, board=None):
1593+ self.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
1594 board)
1595- with cls.hardwarepack_handler:
1596- cls.hwpack_format = cls.hardwarepack_handler.get_format()
1597- if (cls.hwpack_format == cls.hardwarepack_handler.FORMAT_1):
1598+ with self.hardwarepack_handler:
1599+ self.hwpack_format = self.hardwarepack_handler.get_format()
1600+ if (self.hwpack_format == self.hardwarepack_handler.FORMAT_1):
1601 return
1602
1603- if (cls.hwpack_format != cls.hardwarepack_handler.FORMAT_1):
1604+ if (self.hwpack_format != self.hardwarepack_handler.FORMAT_1):
1605 # Clear V1 defaults.
1606- cls.kernel_addr = None
1607- cls.initrd_addr = None
1608- cls.load_addr = None
1609- cls.serial_tty = None
1610- cls.fat_size = None
1611- cls.dtb_name = None
1612- cls.dtb_addr = None
1613- cls.extra_boot_args_options = None
1614- cls.boot_script = None
1615- cls.kernel_flavors = None
1616- cls.mmc_option = None
1617- cls.mmc_part_offset = None
1618- cls.SAMSUNG_V310_BL1_START = None
1619- cls.SAMSUNG_V310_BL1_LEN = None
1620- cls.SAMSUNG_V310_ENV_START = None
1621- cls.SAMSUNG_V310_ENV_LEN = None
1622- cls.SAMSUNG_V310_BL2_START = None
1623- cls.SAMSUNG_V310_BL2_LEN = None
1624+ # TODO When removing v1 support, remove also default values
1625+ # in the constructor and avoid all this.
1626+ self.kernel_addr = None
1627+ self.initrd_addr = None
1628+ self.load_addr = None
1629+ self.serial_tty = None
1630+ self.fat_size = None
1631+ self.dtb_name = None
1632+ self.dtb_addr = None
1633+ self.extra_boot_args_options = None
1634+ self.boot_script = None
1635+ self.kernel_flavors = None
1636+ self.mmc_option = None
1637+ self.mmc_part_offset = None
1638+ self.samsung_v310_bl1_start = None
1639+ self.samsung_v310_bl1_len = None
1640+ self._samsung_v310_env_start = None
1641+ self._samsung_v310_env_len = None
1642+ self.samsung_v310_bl2_start = None
1643+ self._samsung_v310_bl2_len = None
1644
1645+ self.board = board
1646 # Set new values from metadata.
1647- cls.kernel_addr = cls.get_metadata_field('kernel_addr')
1648- cls.initrd_addr = cls.get_metadata_field('initrd_addr')
1649- cls.load_addr = cls.get_metadata_field('load_addr')
1650- cls.dtb_addr = cls.get_metadata_field('dtb_addr')
1651- cls.serial_tty = cls.get_metadata_field('serial_tty')
1652- wired_interfaces = cls.get_metadata_field('wired_interfaces')
1653- if wired_interfaces is not None:
1654- cls.wired_interfaces = wired_interfaces
1655- wireless_interfaces = cls.get_metadata_field(
1656- 'wireless_interfaces')
1657- if wireless_interfaces is not None:
1658- cls.wireless_interfaces = wireless_interfaces
1659- cls.vmlinuz = cls.get_metadata_field('vmlinuz')
1660- cls.initrd = cls.get_metadata_field('initrd')
1661- cls.dtb_file = cls.get_metadata_field('dtb_file')
1662- cls.dtb_files = cls.get_metadata_field('dtb_files')
1663- cls.extra_boot_args_options = cls.get_metadata_field(
1664- 'extra_boot_options')
1665- cls.boot_script = cls.get_metadata_field('boot_script')
1666- cls.extra_serial_opts = cls.get_metadata_field(
1667- 'extra_serial_opts')
1668- cls.snowball_startup_files_config = cls.get_metadata_field(
1669- 'snowball_startup_files_config')
1670-
1671- cls.partition_layout = cls.get_metadata_field('partition_layout')
1672- if cls.partition_layout in [
1673- 'bootfs_rootfs', 'reserved_bootfs_rootfs', None]:
1674- cls.fat_size = 32
1675- elif cls.partition_layout == 'bootfs16_rootfs':
1676- cls.fat_size = 16
1677+ self.kernel_addr = self.get_metadata_field(KERNEL_ADDR_FIELD)
1678+ self.initrd_addr = self.get_metadata_field(INITRD_ADDR_FIELD)
1679+ self.load_addr = self.get_metadata_field(LOAD_ADDR_FIELD)
1680+ self.dtb_addr = self.get_metadata_field(DTB_ADDR_FIELD)
1681+ self.serial_tty = self.get_metadata_field(SERIAL_TTY_FIELD)
1682+ wired_interfaces = self.get_metadata_field(WIRED_INTERFACES_FIELD)
1683+ if wired_interfaces:
1684+ self.wired_interfaces = wired_interfaces
1685+ wireless_interfaces = self.get_metadata_field(
1686+ WIRELESS_INTERFACES_FIELD)
1687+ if wireless_interfaces:
1688+ self.wireless_interfaces = wireless_interfaces
1689+ self.dtb_file = self.get_metadata_field(DTB_FILE_FIELD)
1690+ # XXX: need to deprecate dtb_file field and use only dtb_files
1691+ # for multiple entries.
1692+ if self.dtb_file:
1693+ logger.warn("Deprecation warning: use the 'dtb_files' field "
1694+ "instead of 'dtb_file'.")
1695+ self.dtb_files = self.get_metadata_field(DTB_FILES_FIELD)
1696+ self.extra_boot_args_options = self.get_metadata_field(
1697+ EXTRA_BOOT_OPTIONS_FIELD)
1698+ self.boot_script = self.get_metadata_field(BOOT_SCRIPT_FIELD)
1699+ self.extra_serial_opts = self.get_metadata_field(
1700+ EXTRA_SERIAL_OPTIONS_FIELD)
1701+ self.snowball_startup_files_config = self.get_metadata_field(
1702+ SNOWBALL_STARTUP_FILES_CONFIG_FIELD)
1703+ self.partition_layout = self.get_metadata_field(
1704+ PARTITION_LAYOUT_FIELD)
1705+ if self.partition_layout in [BOOTFS, RESERVED_BOOTFS, None]:
1706+ self.fat_size = 32
1707+ elif self.partition_layout == BOOTFS16:
1708+ self.fat_size = 16
1709 else:
1710 raise AssertionError("Unknown partition layout '%s'." % \
1711- cls.partition_layout)
1712-
1713- cls.mmc_option = cls.get_metadata_field('mmc_id')
1714- if cls.mmc_option is not None:
1715- cls.mmc_device_id = int(cls.mmc_option.split(':')[0])
1716- cls.mmc_part_offset = int(cls.mmc_option.split(':')[1]) - 1
1717-
1718- boot_min_size = cls.get_metadata_field('boot_min_size')
1719- if boot_min_size is not None:
1720- cls.BOOT_MIN_SIZE_S = align_up(int(boot_min_size) * 1024 ** 2,
1721- SECTOR_SIZE) / SECTOR_SIZE
1722- root_min_size = cls.get_metadata_field('root_min_size')
1723- if root_min_size is not None:
1724- cls.ROOT_MIN_SIZE_S = align_up(int(root_min_size) * 1024 ** 2,
1725- SECTOR_SIZE) / SECTOR_SIZE
1726- loader_min_size = cls.get_metadata_field('loader_min_size')
1727- if loader_min_size is not None:
1728- cls.LOADER_MIN_SIZE_S = (
1729+ self.partition_layout)
1730+
1731+ self.mmc_option = self.get_metadata_field(MMC_ID_FIELD)
1732+ if self.mmc_option:
1733+ self.mmc_device_id = int(self.mmc_option.split(':')[0])
1734+ self.mmc_part_offset = int(self.mmc_option.split(':')[1]) - 1
1735+
1736+ # XXX: need to fix these values.
1737+ boot_min_size = self.get_metadata_field(BOOT_MIN_SIZE_FIELD)
1738+ if boot_min_size:
1739+ self.BOOT_MIN_SIZE_S = align_up(int(boot_min_size) * 1024 ** 2,
1740+ SECTOR_SIZE) / SECTOR_SIZE
1741+ root_min_size = self.get_metadata_field(ROOT_MIN_SIZE_FIELD)
1742+ if root_min_size:
1743+ self.ROOT_MIN_SIZE_S = align_up(int(root_min_size) * 1024 ** 2,
1744+ SECTOR_SIZE) / SECTOR_SIZE
1745+ loader_min_size = self.get_metadata_field(LOADER_MIN_SIZE_FIELD)
1746+ if loader_min_size:
1747+ self.LOADER_MIN_SIZE_S = (
1748 align_up(int(loader_min_size) * 1024 ** 2,
1749 SECTOR_SIZE) / SECTOR_SIZE)
1750
1751- bootloader_file_in_boot_part = cls.get_metadata_field(
1752- 'bootloader_file_in_boot_part')
1753- if bootloader_file_in_boot_part is None:
1754- cls.bootloader_file_in_boot_part = False
1755- elif string.lower(bootloader_file_in_boot_part) == 'yes':
1756- cls.bootloader_file_in_boot_part = True
1757- elif string.lower(bootloader_file_in_boot_part) == 'no':
1758- cls.bootloader_file_in_boot_part = False
1759- spl_in_boot_part = cls.get_metadata_field('spl_in_boot_part')
1760+ spl_in_boot_part = self.get_metadata_field(SPL_IN_BOOT_PART_FIELD)
1761 if spl_in_boot_part is None:
1762- cls.spl_in_boot_part = False
1763+ self.spl_in_boot_part = False
1764 elif string.lower(spl_in_boot_part) == 'yes':
1765- cls.spl_in_boot_part = True
1766+ self.spl_in_boot_part = True
1767 elif string.lower(spl_in_boot_part) == 'no':
1768- cls.spl_in_boot_part = False
1769- env_dd = cls.get_metadata_field('env_dd')
1770+ self.spl_in_boot_part = False
1771+
1772+ env_dd = self.get_metadata_field(ENV_DD_FIELD)
1773 if env_dd is None:
1774- cls.env_dd = False
1775+ self.env_dd = False
1776 elif string.lower(env_dd) == 'yes':
1777- cls.env_dd = True
1778+ self.env_dd = True
1779 elif string.lower(env_dd) == 'no':
1780- cls.env_dd = False
1781+ self.env_dd = False
1782
1783- bootloader_dd = cls.get_metadata_field('bootloader_dd')
1784+ # XXX: in hwpack v3 this field is just called 'dd'.
1785+ # Need to check its use.
1786+ bootloader_dd = self.get_metadata_field('bootloader_dd')
1787 # Either bootloader_dd is not specified, or it contains the dd
1788 # offset.
1789 if bootloader_dd is None:
1790- cls.bootloader_dd = False
1791+ self.bootloader_dd = False
1792 else:
1793- cls.bootloader_dd = int(bootloader_dd)
1794- spl_dd = cls.get_metadata_field('spl_dd')
1795+ self.bootloader_dd = int(bootloader_dd)
1796+ spl_dd = self.get_metadata_field(SPL_DD_FIELD)
1797 # Either spl_dd is not specified, or it contains the dd offset.
1798 if spl_dd is None:
1799- cls.spl_dd = False
1800+ self.spl_dd = False
1801 else:
1802- cls.spl_dd = int(spl_dd)
1803-
1804- loader_start = cls.get_metadata_field('loader_start')
1805- if loader_start is not None:
1806- cls.LOADER_START_S = int(loader_start)
1807- samsung_bl1_start = cls.get_metadata_field('samsung_bl1_start')
1808- if samsung_bl1_start is not None:
1809- cls.SAMSUNG_V310_BL1_START = int(samsung_bl1_start)
1810- samsung_bl1_len = cls.get_metadata_field('samsung_bl1_len')
1811- if samsung_bl1_len is not None:
1812- cls.SAMSUNG_V310_BL1_LEN = int(samsung_bl1_len)
1813- samsung_env_len = cls.get_metadata_field('samsung_env_len')
1814- if samsung_env_len is not None:
1815- cls.SAMSUNG_V310_ENV_LEN = int(samsung_env_len)
1816- assert cls.SAMSUNG_V310_ENV_LEN * SECTOR_SIZE == 16 * 1024, (
1817- "BL1 expects u-boot environment to be 16 KiB")
1818- samsung_bl2_len = cls.get_metadata_field('samsung_bl2_len')
1819- if samsung_bl2_len is not None:
1820- cls.SAMSUNG_V310_BL2_LEN = int(samsung_bl2_len)
1821- assert cls.SAMSUNG_V310_BL2_LEN * SECTOR_SIZE == 512 * 1024, (
1822- "BL1 expects BL2 (u-boot) to be 512 KiB")
1823-
1824- if (cls.SAMSUNG_V310_BL1_START and cls.SAMSUNG_V310_BL1_LEN):
1825- cls.SAMSUNG_V310_ENV_START = (cls.SAMSUNG_V310_BL1_START +
1826- cls.SAMSUNG_V310_BL1_LEN)
1827- assert cls.SAMSUNG_V310_ENV_START == 33, (
1828- "BL1 expects u-boot environment at +33s")
1829- if (cls.SAMSUNG_V310_ENV_START and cls.SAMSUNG_V310_ENV_LEN):
1830- cls.SAMSUNG_V310_BL2_START = (cls.SAMSUNG_V310_ENV_START +
1831- cls.SAMSUNG_V310_ENV_LEN)
1832-
1833- cls.bootloader_copy_files = cls.hardwarepack_handler.get_field(
1834+ self.spl_dd = int(spl_dd)
1835+
1836+ loader_start = self.get_metadata_field(LOADER_START_FIELD)
1837+ if loader_start:
1838+ self.loader_start_s = int(loader_start)
1839+ samsung_bl1_start = self.get_metadata_field(
1840+ SAMSUNG_BL1_START_FIELD)
1841+ if samsung_bl1_start:
1842+ self.samsung_v310_bl1_start = int(samsung_bl1_start)
1843+ samsung_bl1_len = self.get_metadata_field(SAMSUNG_BL1_LEN_FIELD)
1844+ if samsung_bl1_len:
1845+ self.samsung_v310_bl1_len = int(samsung_bl1_len)
1846+ samsung_env_len = self.get_metadata_field(SAMSUNG_ENV_LEN_FIELD)
1847+ if samsung_env_len:
1848+ self.samsung_v310_env_len = int(samsung_env_len)
1849+ samsung_bl2_len = self.get_metadata_field(SAMSUNG_BL2_LEN_FIELD)
1850+ if samsung_bl2_len:
1851+ self.samsung_v310_bl2_len = int(samsung_bl2_len)
1852+
1853+ if (self.samsung_v310_bl1_start and self.samsung_v310_bl1_len):
1854+ self.samsung_v310_env_start = (self.samsung_v310_bl1_start +
1855+ self.samsung_v310_bl1_len)
1856+ if (self.samsung_v310_env_start and self.samsung_v310_env_len):
1857+ self.samsung_v310_bl2_start = (self.samsung_v310_env_start +
1858+ self.samsung_v310_env_len)
1859+
1860+ self.bootloader_copy_files = self.hardwarepack_handler.get_field(
1861 "bootloader_copy_files")[0]
1862
1863- cls.bootloader = cls.hardwarepack_handler.get_field(
1864- "bootloader")
1865- cls.board = board
1866+ # XXX: no reference in hwpackV3 format of these fields, double
1867+ # check if they can be dropped when killing v1.
1868+ self.bootloader = self.hardwarepack_handler.get_field(
1869+ "bootloader")
1870+ self.vmlinuz = self.get_metadata_field('vmlinuz')
1871+ self.initrd = self.get_metadata_field('initrd')
1872+ bootloader_file_in_boot_part = self.get_metadata_field(
1873+ 'bootloader_file_in_boot_part')
1874+ if bootloader_file_in_boot_part is None:
1875+ self.bootloader_file_in_boot_part = False
1876+ elif string.lower(bootloader_file_in_boot_part) == 'yes':
1877+ self.bootloader_file_in_boot_part = True
1878+ elif string.lower(bootloader_file_in_boot_part) == 'no':
1879+ self.bootloader_file_in_boot_part = False
1880
1881- @classmethod
1882- def get_file(cls, file_alias, default=None):
1883+ def get_file(self, file_alias, default=None):
1884 # XXX remove the 'default' parameter when V1 support is removed!
1885- file_in_hwpack = cls.hardwarepack_handler.get_file(file_alias)
1886+ file_in_hwpack = self.hardwarepack_handler.get_file(file_alias)
1887 if file_in_hwpack is not None:
1888 return file_in_hwpack
1889 else:
1890 return default
1891
1892- @classmethod
1893- def get_v1_sfdisk_cmd(cls, should_align_boot_part=False):
1894- """Return the sfdisk command to partition the media.
1895-
1896- :param should_align_boot_part: Whether to align the boot partition too.
1897-
1898- This default implementation returns a boot vfat partition of type
1899- FAT16 or FAT32, followed by a root partition.
1900-
1901- XXX: This default implementation and all overrides are left for V1
1902- compatibility only. They should be removed as part of the work to
1903- kill off hwpacks V1.
1904- """
1905- if cls.fat_size == 32:
1906- partition_type = '0x0C'
1907- else:
1908- partition_type = '0x0E'
1909-
1910- # align on sector 63 for compatibility with broken versions of x-loader
1911- # unless align_boot_part is set
1912- boot_align = 63
1913- if should_align_boot_part:
1914- boot_align = PART_ALIGN_S
1915-
1916- # can only start on sector 1 (sector 0 is MBR / partition table)
1917- boot_start, boot_end, boot_len = align_partition(
1918- 1, cls.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
1919- # apparently OMAP3 ROMs require the vfat length to be an even number
1920- # of sectors (multiple of 1 KiB); decrease the length if it's odd,
1921- # there should still be enough room
1922- boot_len = boot_len - boot_len % 2
1923- boot_end = boot_start + boot_len - 1
1924-
1925- # we ignore _root_end / _root_len and return a sfdisk command to
1926- # instruct the use of all remaining space; XXX if we had some root size
1927- # config, we could do something more sensible
1928- root_start, _root_end, _root_len = align_partition(
1929- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1930-
1931- return '%s,%s,%s,*\n%s,,,-' % (
1932- boot_start, boot_len, partition_type, root_start)
1933-
1934- @classmethod
1935- def get_normal_sfdisk_cmd(cls, should_align_boot_part=False):
1936+ def get_v1_sfdisk_cmd(self, should_align_boot_part=False):
1937+ # XXX: This default implementation and all overrides are left for V1
1938+ # compatibility only. They should be removed as part of the work to
1939+ # kill off hwpacks V1.
1940+ return self.get_normal_sfdisk_cmd(should_align_boot_part)
1941+
1942+ def get_normal_sfdisk_cmd(self, should_align_boot_part=False):
1943 """Return the sfdisk command to partition the media.
1944
1945 :param should_align_boot_part: Whether to align the boot partition too.
1946@@ -687,7 +473,7 @@
1947 This returns a boot vfat partition of type FAT16
1948 or FAT32, followed by a root partition.
1949 """
1950- if cls.fat_size == 32:
1951+ if self.fat_size == 32:
1952 partition_type = '0x0C'
1953 else:
1954 partition_type = '0x0E'
1955@@ -701,7 +487,7 @@
1956
1957 # can only start on sector 1 (sector 0 is MBR / partition table)
1958 boot_start, boot_end, boot_len = align_partition(
1959- 1, cls.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
1960+ 1, self.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
1961 # apparently OMAP3 ROMs require the vfat length to be an even number
1962 # of sectors (multiple of 1 KiB); decrease the length if it's odd,
1963 # there should still be enough room
1964@@ -713,13 +499,12 @@
1965 # instruct the use of all remaining space; XXX we now have root size
1966 # config, so we can do something more sensible
1967 root_start, _root_end, _root_len = align_partition(
1968- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1969+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1970
1971 return '%s,%s,%s,*\n%s,,,-' % (
1972 boot_start, boot_len, partition_type, root_start)
1973
1974- @classmethod
1975- def get_reserved_sfdisk_cmd(cls, should_align_boot_part=None):
1976+ def get_reserved_sfdisk_cmd(self, should_align_boot_part=None):
1977 """Return the sfdisk command to partition the media.
1978
1979 :param should_align_boot_part: Ignored.
1980@@ -728,40 +513,38 @@
1981 FAT16 or FAT32, followed by a root partition.
1982 """
1983 loader_start, loader_end, loader_len = align_partition(
1984- cls.LOADER_START_S, cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
1985+ self.loader_start_s, self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
1986
1987 boot_start, boot_end, boot_len = align_partition(
1988- loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1989+ loader_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1990
1991 root_start, _root_end, _root_len = align_partition(
1992- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1993+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1994
1995 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
1996 loader_start, loader_len, boot_start, boot_len, root_start)
1997
1998- @classmethod
1999- def get_sfdisk_cmd(cls, should_align_boot_part=False):
2000- if (cls.partition_layout in ['bootfs_rootfs', 'bootfs16_rootfs'] or
2001- cls.board == 'snowball_sd'):
2002- return cls.get_normal_sfdisk_cmd(should_align_boot_part)
2003- elif cls.partition_layout in ['reserved_bootfs_rootfs']:
2004- return cls.get_reserved_sfdisk_cmd(should_align_boot_part)
2005+ def get_sfdisk_cmd(self, should_align_boot_part=False):
2006+ if (self.partition_layout in ['bootfs_rootfs', 'bootfs16_rootfs'] or
2007+ self.board == 'snowball_sd'):
2008+ return self.get_normal_sfdisk_cmd(should_align_boot_part)
2009+ elif self.partition_layout in ['reserved_bootfs_rootfs']:
2010+ return self.get_reserved_sfdisk_cmd(should_align_boot_part)
2011 else:
2012- assert (cls.hwpack_format == HardwarepackHandler.FORMAT_1), (
2013+ assert (self.hwpack_format == HardwarepackHandler.FORMAT_1), (
2014 "Hwpack format is not 1.0 but "
2015 "partition_layout is unspecified.")
2016- return cls.get_v1_sfdisk_cmd(should_align_boot_part)
2017+ return self.get_v1_sfdisk_cmd(should_align_boot_part)
2018
2019- @classmethod
2020- def _get_bootcmd(cls, i_img_data, d_img_data):
2021+ def _get_bootcmd(self, i_img_data, d_img_data):
2022 """Get the bootcmd for this board.
2023
2024 In general subclasses should not have to override this.
2025 """
2026 replacements = dict(
2027- fatload_command=cls.fatload_command, uimage_path=cls.uimage_path,
2028- mmc_option=cls.mmc_option, kernel_addr=cls.kernel_addr,
2029- initrd_addr=cls.initrd_addr, dtb_addr=cls.dtb_addr)
2030+ fatload_command=self.fatload_command, uimage_path=self.uimage_path,
2031+ mmc_option=self.mmc_option, kernel_addr=self.kernel_addr,
2032+ initrd_addr=self.initrd_addr, dtb_addr=self.dtb_addr)
2033 boot_script = (
2034 ("%(fatload_command)s mmc %(mmc_option)s %(kernel_addr)s " +
2035 "%(uimage_path)suImage; ")) % replacements
2036@@ -770,7 +553,7 @@
2037 ("%(fatload_command)s mmc %(mmc_option)s %(initrd_addr)s " +
2038 "%(uimage_path)suInitrd; ")) % replacements
2039 if d_img_data is not None:
2040- assert cls.dtb_addr is not None, (
2041+ assert self.dtb_addr is not None, (
2042 "Need a dtb_addr when passing d_img_data")
2043 boot_script += (
2044 ("%(fatload_command)s mmc %(mmc_option)s %(dtb_addr)s " +
2045@@ -782,37 +565,34 @@
2046 boot_script += ((" %(dtb_addr)s")) % replacements
2047 return boot_script
2048
2049- @classmethod
2050- def add_boot_args(cls, extra_args):
2051+ def add_boot_args(self, extra_args):
2052 if extra_args is not None:
2053- if cls.extra_boot_args_options is None:
2054- cls.extra_boot_args_options = extra_args
2055+ if self.extra_boot_args_options is None:
2056+ self.extra_boot_args_options = extra_args
2057 else:
2058- cls.extra_boot_args_options += ' %s' % extra_args
2059+ self.extra_boot_args_options += ' %s' % extra_args
2060
2061- @classmethod
2062- def add_boot_args_from_file(cls, path):
2063+ def add_boot_args_from_file(self, path):
2064 if path is not None:
2065 with open(path, 'r') as boot_args_file:
2066- cls.add_boot_args(boot_args_file.read().strip())
2067+ self.add_boot_args(boot_args_file.read().strip())
2068
2069- @classmethod
2070- def _get_bootargs(cls, is_live, is_lowmem, consoles, rootfs_id):
2071+ def _get_bootargs(self, is_live, is_lowmem, consoles, rootfs_id):
2072 """Get the bootargs for this board.
2073
2074 In general subclasses should not have to override this.
2075 """
2076 boot_args_options = 'rootwait ro'
2077- if cls.extra_boot_args_options is not None:
2078- boot_args_options += ' %s' % cls.extra_boot_args_options
2079- serial_opts = cls.extra_serial_opts
2080+ if self.extra_boot_args_options:
2081+ boot_args_options += ' %s' % self.extra_boot_args_options
2082+ serial_opts = self.extra_serial_opts
2083 for console in consoles:
2084 serial_opts += ' console=%s' % console
2085
2086 lowmem_opt = ''
2087 boot_snippet = 'root=%s' % rootfs_id
2088 if is_live:
2089- serial_opts += ' %s' % cls.live_serial_opts
2090+ serial_opts += ' %s' % self.live_serial_opts
2091 boot_snippet = 'boot=casper'
2092 if is_lowmem:
2093 lowmem_opt = 'only-ubiquity'
2094@@ -826,45 +606,42 @@
2095 "%(boot_snippet)s %(boot_args_options)s"
2096 % replacements)
2097
2098- @classmethod
2099- def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
2100+ def _get_boot_env(self, is_live, is_lowmem, consoles, rootfs_id,
2101 i_img_data, d_img_data):
2102 """Get the boot environment for this board.
2103
2104 In general subclasses should not have to override this.
2105 """
2106 boot_env = {}
2107- boot_env["bootargs"] = cls._get_bootargs(
2108+ boot_env["bootargs"] = self._get_bootargs(
2109 is_live, is_lowmem, consoles, rootfs_id)
2110- boot_env["bootcmd"] = cls._get_bootcmd(i_img_data, d_img_data)
2111- boot_env["initrd_high"] = cls.initrd_high
2112- boot_env["fdt_high"] = cls.fdt_high
2113+ boot_env["bootcmd"] = self._get_bootcmd(i_img_data, d_img_data)
2114+ boot_env["initrd_high"] = self.initrd_high
2115+ boot_env["fdt_high"] = self.fdt_high
2116 return boot_env
2117
2118- @classmethod
2119- def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
2120+ def make_boot_files(self, bootloader_parts_dir, is_live, is_lowmem,
2121 consoles, chroot_dir, rootfs_id, boot_dir,
2122 boot_device_or_file):
2123- if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
2124+ if self.hwpack_format == HardwarepackHandler.FORMAT_1:
2125 parts_dir = bootloader_parts_dir
2126 else:
2127 parts_dir = chroot_dir
2128- (k_img_data, i_img_data, d_img_data) = cls._get_kflavor_files(
2129+ (k_img_data, i_img_data, d_img_data) = self._get_kflavor_files(
2130 parts_dir)
2131- boot_env = cls._get_boot_env(is_live, is_lowmem, consoles, rootfs_id,
2132+ boot_env = self._get_boot_env(is_live, is_lowmem, consoles, rootfs_id,
2133 i_img_data, d_img_data)
2134
2135- if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
2136- cls._make_boot_files(
2137+ if self.hwpack_format == HardwarepackHandler.FORMAT_1:
2138+ self._make_boot_files(
2139 boot_env, chroot_dir, boot_dir,
2140 boot_device_or_file, k_img_data, i_img_data, d_img_data)
2141 else:
2142- cls._make_boot_files_v2(
2143+ self._make_boot_files_v2(
2144 boot_env, chroot_dir, boot_dir,
2145 boot_device_or_file, k_img_data, i_img_data, d_img_data)
2146
2147- @classmethod
2148- def _copy_dtb_files(cls, dtb_files, dest_dir, search_dir):
2149+ def _copy_dtb_files(self, dtb_files, dest_dir, search_dir):
2150 """Copy the files defined in dtb_files into the boot directory.
2151
2152 :param dtb_files: The list of dtb files
2153@@ -904,13 +681,12 @@
2154 else:
2155 # Hopefully we should never get here.
2156 # This should only happen if the hwpack config YAML file is
2157- # wrong
2158+ # wrong.
2159 logger.warn('WARNING: Wrong syntax in metadata file. '
2160 'Check the hwpack configuration file used to '
2161 'generate the hwpack archive.')
2162
2163- @classmethod
2164- def _dd_file(cls, from_file, to_file, seek, max_size=None):
2165+ def _dd_file(self, from_file, to_file, seek, max_size=None):
2166 assert from_file is not None, "No source file name given."
2167 if max_size is not None:
2168 assert os.path.getsize(from_file) <= max_size, (
2169@@ -918,23 +694,21 @@
2170 logger.info("Writing '%s' to '%s' at %s." % (from_file, to_file, seek))
2171 _dd(from_file, to_file, seek=seek)
2172
2173- @classmethod
2174- def install_samsung_boot_loader(cls, samsung_spl_file, bootloader_file,
2175+ def install_samsung_boot_loader(self, samsung_spl_file, bootloader_file,
2176 boot_device_or_file):
2177- cls._dd_file(samsung_spl_file, boot_device_or_file,
2178- cls.SAMSUNG_V310_BL1_START,
2179- cls.SAMSUNG_V310_BL1_LEN * SECTOR_SIZE)
2180- cls._dd_file(bootloader_file, boot_device_or_file,
2181- cls.SAMSUNG_V310_BL2_START,
2182- cls.SAMSUNG_V310_BL2_LEN * SECTOR_SIZE)
2183+ self._dd_file(samsung_spl_file, boot_device_or_file,
2184+ self.samsung_v310_bl1_start,
2185+ self.samsung_v310_bl1_len * SECTOR_SIZE)
2186+ self._dd_file(bootloader_file, boot_device_or_file,
2187+ self.samsung_v310_bl2_start,
2188+ self.samsung_v310_bl2_len * SECTOR_SIZE)
2189
2190- @classmethod
2191- def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir,
2192+ def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
2193 boot_device_or_file, k_img_data, i_img_data,
2194 d_img_data):
2195- with cls.hardwarepack_handler:
2196- spl_file = cls.get_file('spl_file')
2197- if cls.spl_in_boot_part:
2198+ with self.hardwarepack_handler:
2199+ spl_file = self.get_file('spl_file')
2200+ if self.spl_in_boot_part:
2201 assert spl_file is not None, (
2202 "SPL binary could not be found")
2203 logger.info(
2204@@ -944,15 +718,15 @@
2205 # XXX: Is this really needed?
2206 cmd_runner.run(["sync"]).wait()
2207
2208- if cls.spl_dd:
2209- cls._dd_file(spl_file, boot_device_or_file, cls.spl_dd)
2210-
2211- bootloader_file = cls.get_file('bootloader_file')
2212- if cls.bootloader_dd:
2213- cls._dd_file(bootloader_file, boot_device_or_file,
2214- cls.bootloader_dd)
2215-
2216- make_uImage(cls.load_addr, k_img_data, boot_dir)
2217+ if self.spl_dd:
2218+ self._dd_file(spl_file, boot_device_or_file, self.spl_dd)
2219+
2220+ bootloader_file = self.get_file('bootloader_file')
2221+ if self.bootloader_dd:
2222+ self._dd_file(bootloader_file, boot_device_or_file,
2223+ self.bootloader_dd)
2224+
2225+ make_uImage(self.load_addr, k_img_data, boot_dir)
2226
2227 if i_img_data is not None:
2228 make_uInitrd(i_img_data, boot_dir)
2229@@ -960,29 +734,28 @@
2230 if d_img_data is not None:
2231 make_dtb(d_img_data, boot_dir)
2232
2233- if cls.boot_script is not None:
2234- boot_script_path = os.path.join(boot_dir, cls.boot_script)
2235+ if self.boot_script is not None:
2236+ boot_script_path = os.path.join(boot_dir, self.boot_script)
2237 make_boot_script(boot_env, boot_script_path)
2238
2239 # Only used for Omap, will this be bad for the other boards?
2240 make_boot_ini(boot_script_path, boot_dir)
2241
2242- if (cls.snowball_startup_files_config is not None and
2243- cls.board != 'snowball_sd'):
2244- cls.populate_raw_partition(boot_device_or_file, chroot_dir)
2245+ if (self.snowball_startup_files_config is not None and
2246+ self.board != 'snowball_sd'):
2247+ self.populate_raw_partition(boot_device_or_file, chroot_dir)
2248
2249- if cls.env_dd:
2250+ if self.env_dd:
2251 # Do we need to zero out the env before flashing it?
2252 _dd("/dev/zero", boot_device_or_file,
2253- count=cls.SAMSUNG_V310_ENV_LEN,
2254- seek=cls.SAMSUNG_V310_ENV_START)
2255- env_size = cls.SAMSUNG_V310_ENV_LEN * SECTOR_SIZE
2256+ count=self.samsung_v310_env_len,
2257+ seek=self.samsung_v310_env_start)
2258+ env_size = self.samsung_v310_env_len * SECTOR_SIZE
2259 env_file = make_flashable_env(boot_env, env_size)
2260- cls._dd_file(env_file, boot_device_or_file,
2261- cls.SAMSUNG_V310_ENV_START)
2262+ self._dd_file(env_file, boot_device_or_file,
2263+ self.samsung_v310_env_start)
2264
2265- @classmethod
2266- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
2267+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
2268 boot_device_or_file, k_img_data, i_img_data,
2269 d_img_data):
2270 """Make the necessary boot files for this board.
2271@@ -992,8 +765,7 @@
2272 """
2273 raise NotImplementedError()
2274
2275- @classmethod
2276- def populate_boot(cls, chroot_dir, rootfs_id, boot_partition, boot_disk,
2277+ def populate_boot(self, chroot_dir, rootfs_id, boot_partition, boot_disk,
2278 boot_device_or_file, is_live, is_lowmem, consoles):
2279 parts_dir = 'boot'
2280 if is_live:
2281@@ -1001,21 +773,21 @@
2282 bootloader_parts_dir = os.path.join(chroot_dir, parts_dir)
2283 cmd_runner.run(['mkdir', '-p', boot_disk]).wait()
2284 with partition_mounted(boot_partition, boot_disk):
2285- with cls.hardwarepack_handler:
2286- if cls.bootloader_file_in_boot_part:
2287+ with self.hardwarepack_handler:
2288+ if self.bootloader_file_in_boot_part:
2289 # <legacy v1 support>
2290- if cls.bootloader_flavor is not None:
2291+ if self.bootloader_flavor is not None:
2292 default = os.path.join(
2293 chroot_dir, 'usr', 'lib', 'u-boot',
2294- cls.bootloader_flavor, 'u-boot.img')
2295+ self.bootloader_flavor, 'u-boot.img')
2296 if not os.path.exists(default):
2297 default = os.path.join(
2298 chroot_dir, 'usr', 'lib', 'u-boot',
2299- cls.bootloader_flavor, 'u-boot.bin')
2300+ self.bootloader_flavor, 'u-boot.bin')
2301 else:
2302 default = None
2303 # </legacy v1 support>
2304- bootloader_bin = cls.get_file('bootloader_file',
2305+ bootloader_bin = self.get_file('bootloader_file',
2306 default=default)
2307 assert bootloader_bin is not None, (
2308 "bootloader binary could not be found")
2309@@ -1025,18 +797,17 @@
2310 proc.wait()
2311
2312 # Handle copy_files field.
2313- cls.copy_files(boot_disk)
2314+ self.copy_files(boot_disk)
2315
2316 # Handle dtb_files field.
2317- if cls.dtb_files:
2318- cls._copy_dtb_files(cls.dtb_files, boot_disk, chroot_dir)
2319+ if self.dtb_files:
2320+ self._copy_dtb_files(self.dtb_files, boot_disk, chroot_dir)
2321
2322- cls.make_boot_files(
2323+ self.make_boot_files(
2324 bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
2325 rootfs_id, boot_disk, boot_device_or_file)
2326
2327- @classmethod
2328- def copy_files(cls, boot_disk):
2329+ def copy_files(self, boot_disk):
2330 """Handle the copy_files metadata field."""
2331
2332 # Extract anything specified by copy_files sections
2333@@ -1046,13 +817,14 @@
2334 # {'source_path': 'dest_path'}
2335 # ]
2336 # }
2337- if cls.bootloader_copy_files is None:
2338+ if self.bootloader_copy_files is None:
2339 return
2340
2341- for source_package, file_list in cls.bootloader_copy_files.iteritems():
2342+ for source_package, file_list in \
2343+ self.bootloader_copy_files.iteritems():
2344 for file_info in file_list:
2345 for source_path, dest_path in file_info.iteritems():
2346- source = cls.hardwarepack_handler.get_file_from_package(
2347+ source = self.hardwarepack_handler.get_file_from_package(
2348 source_path, source_package)
2349 dest_path = dest_path.lstrip("/\\")
2350 dirname = os.path.dirname(dest_path)
2351@@ -1065,25 +837,24 @@
2352 os.path.join(boot_disk, dest_path)], as_root=True)
2353 proc.wait()
2354
2355- @classmethod
2356- def _get_kflavor_files(cls, path):
2357+ def _get_kflavor_files(self, path):
2358 """Search for kernel, initrd and optional dtb in path."""
2359- if cls.kernel_flavors is None:
2360+ if self.kernel_flavors is None:
2361 # V2 metadata specifies each glob, not flavors.
2362 # XXX This duplication is temporary until V1 dies.
2363- return cls._get_kflavor_files_v2(path)
2364+ return self._get_kflavor_files_v2(path)
2365
2366- for flavor in cls.kernel_flavors:
2367+ for flavor in self.kernel_flavors:
2368 kregex = KERNEL_GLOB % {'kernel_flavor': flavor}
2369 iregex = INITRD_GLOB % {'kernel_flavor': flavor}
2370 dregex = DTB_GLOB % {'kernel_flavor': flavor,
2371- 'dtb_name': cls.dtb_name}
2372+ 'dtb_name': self.dtb_name}
2373 kernel = _get_file_matching(os.path.join(path, kregex))
2374 if kernel is not None:
2375 initrd = _get_file_matching(os.path.join(path, iregex))
2376 if initrd is not None:
2377 dtb = None
2378- if cls.dtb_name is not None:
2379+ if self.dtb_name is not None:
2380 dtb = _get_file_matching(os.path.join(path, dregex))
2381 return (kernel, initrd, dtb)
2382 raise ValueError(
2383@@ -1091,83 +862,83 @@
2384 flavor, iregex))
2385 raise ValueError(
2386 "No kernel found matching %s for flavors %s" % (
2387- KERNEL_GLOB, " ".join(cls.kernel_flavors)))
2388+ KERNEL_GLOB, " ".join(self.kernel_flavors)))
2389
2390- @classmethod
2391- def _get_kflavor_files_v2(cls, path):
2392+ def _get_kflavor_files_v2(self, path):
2393 kernel = initrd = dtb = None
2394
2395- if cls.vmlinuz:
2396- kernel = _get_file_matching(os.path.join(path, cls.vmlinuz))
2397- if not cls.vmlinuz or not kernel:
2398+ if self.vmlinuz:
2399+ kernel = _get_file_matching(os.path.join(path, self.vmlinuz))
2400+ if not self.vmlinuz or not kernel:
2401 raise ValueError("Unable to find a valid kernel image.")
2402
2403- if cls.initrd:
2404- initrd = _get_file_matching(os.path.join(path, cls.initrd))
2405- if not cls.initrd or not initrd:
2406+ if self.initrd:
2407+ initrd = _get_file_matching(os.path.join(path, self.initrd))
2408+ if not self.initrd or not initrd:
2409 logger.warn("Could not find a valid initrd, skipping uInitd.")
2410
2411- if cls.dtb_file:
2412- dtb = _get_file_matching(os.path.join(path, cls.dtb_file))
2413- if not cls.dtb_file or not dtb:
2414+ if self.dtb_file:
2415+ dtb = _get_file_matching(os.path.join(path, self.dtb_file))
2416+ if not self.dtb_file or not dtb:
2417 logger.warn("Could not find a valid dtb file, skipping it.")
2418
2419 logger.info("Will use kernel=%s, initrd=%s, dtb=%s." % \
2420 (kernel, initrd, dtb))
2421 return (kernel, initrd, dtb)
2422
2423- @classmethod
2424- def populate_raw_partition(cls, media, boot_dir):
2425+ def populate_raw_partition(self, media, boot_dir):
2426 # Override in subclass if needed
2427 pass
2428
2429- @classmethod
2430- def snowball_config(cls, chroot_dir):
2431+ def snowball_config(self, chroot_dir):
2432 # Override in subclasses where applicable
2433 raise NotImplementedError(
2434 "snowball_config() must only be called on BoardConfigs that "
2435 "use the Snowball startupfiles.")
2436
2437+ # XXX: can be removed when killing v1 hwpack and updating the attributes
2438+ # that use it.
2439+ @staticmethod
2440+ def _check_placeholder_presence(string, placeholder):
2441+ """Checks if the passed string contains the particular placeholder."""
2442+ # Very simple way of achieving that.
2443+ presence = False
2444+ if placeholder in string:
2445+ presence = True
2446+ return presence
2447+
2448
2449 class OmapConfig(BoardConfig):
2450- kernel_flavors = ['linaro-omap4', 'linaro-lt-omap', 'linaro-omap', 'omap4']
2451- bootloader_file_in_boot_part = True
2452-
2453- # XXX: Here we define these things as dynamic properties because our
2454- # temporary hack to fix bug 697824 relies on changing the board's
2455- # serial_tty at run time.
2456- _extra_serial_opts = None
2457- _live_serial_opts = None
2458- _serial_tty = None
2459-
2460- @classproperty
2461- def serial_tty(cls):
2462- # This is just to make sure no callsites use .serial_tty before
2463- # calling set_appropriate_serial_tty(). If we had this in the first
2464- # place we'd have uncovered bug 710971 before releasing.
2465- raise AttributeError(
2466- "You must not use this attribute before calling "
2467- "set_appropriate_serial_tty")
2468-
2469- @classproperty
2470- def live_serial_opts(cls):
2471- return cls._live_serial_opts % cls.serial_tty
2472-
2473- @classproperty
2474- def extra_serial_opts(cls):
2475- return cls._extra_serial_opts % cls.serial_tty
2476-
2477- @classmethod
2478- def set_appropriate_serial_tty(cls, chroot_dir):
2479+
2480+ def __init__(self):
2481+ super(OmapConfig, self).__init__()
2482+ self.kernel_flavors = ['linaro-omap4', 'linaro-lt-omap',
2483+ 'linaro-omap', 'omap4']
2484+ self.bootloader_file_in_boot_part = True
2485+ # XXX: Here we define these things as dynamic properties because our
2486+ # temporary hack to fix bug 697824 relies on changing the board's
2487+ # serial_tty at run time.
2488+ self._serial_tty = None
2489+
2490+ # XXX: when killing v1 hwpack this should be safely removed.
2491+ def _get_serial_tty(self):
2492+ return self._serial_tty
2493+
2494+ def _set_serial_tty(self, value):
2495+ self._serial_tty = value
2496+
2497+ serial_tty = property(_get_serial_tty, _set_serial_tty)
2498+
2499+ def set_appropriate_serial_tty(self, chroot_dir):
2500 """Set the appropriate serial_tty depending on the kernel used.
2501
2502 If the kernel found in the chroot dir is << 2.6.36 we use tyyS2, else
2503 we use the default value (_serial_tty).
2504 """
2505 # XXX: delete this method when hwpacks V1 can die
2506- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
2507+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
2508 # XXX: This is also part of our temporary hack to fix bug 697824.
2509- cls.serial_tty = classproperty(lambda cls: cls._serial_tty)
2510+ # cls.serial_tty = classproperty(lambda cls: cls._serial_tty)
2511 vmlinuz = _get_file_matching(
2512 os.path.join(chroot_dir, 'boot', 'vmlinuz*'))
2513 basename = os.path.basename(vmlinuz)
2514@@ -1176,135 +947,134 @@
2515 if match is not None:
2516 minor_version = match.group(1)
2517 if int(minor_version) < 36:
2518- cls.serial_tty = classproperty(lambda cls: 'ttyS2')
2519+ self.serial_tty = 'ttyS2'
2520
2521- @classmethod
2522- def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
2523+ def make_boot_files(self, bootloader_parts_dir, is_live, is_lowmem,
2524 consoles, chroot_dir, rootfs_id, boot_dir,
2525 boot_device_or_file):
2526 # XXX: This is also part of our temporary hack to fix bug 697824; we
2527 # need to call set_appropriate_serial_tty() before doing anything that
2528- # may use cls.serial_tty.
2529- if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
2530- cls.set_appropriate_serial_tty(chroot_dir)
2531- super(OmapConfig, cls).make_boot_files(
2532+ # may use self.serial_tty.
2533+ if self.hwpack_format == HardwarepackHandler.FORMAT_1:
2534+ self.set_appropriate_serial_tty(chroot_dir)
2535+ super(OmapConfig, self).make_boot_files(
2536 bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
2537 rootfs_id, boot_dir, boot_device_or_file)
2538
2539- @classmethod
2540- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
2541+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
2542 boot_device_or_file, k_img_data, i_img_data,
2543 d_img_data):
2544 # XXX: delete this method when hwpacks V1 can die
2545- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
2546- install_omap_boot_loader(chroot_dir, boot_dir, cls)
2547- make_uImage(cls.load_addr, k_img_data, boot_dir)
2548+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
2549+ install_omap_boot_loader(chroot_dir, boot_dir, self)
2550+ make_uImage(self.load_addr, k_img_data, boot_dir)
2551 make_uInitrd(i_img_data, boot_dir)
2552 make_dtb(d_img_data, boot_dir)
2553- boot_script_path = os.path.join(boot_dir, cls.boot_script)
2554+ boot_script_path = os.path.join(boot_dir, self.boot_script)
2555 make_boot_script(boot_env, boot_script_path)
2556 make_boot_ini(boot_script_path, boot_dir)
2557
2558
2559 class BeagleConfig(OmapConfig):
2560- bootloader_flavor = 'omap3_beagle'
2561- dtb_name = 'omap3-beagle.dtb'
2562- _serial_tty = 'ttyO2'
2563- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
2564- _live_serial_opts = 'serialtty=%s'
2565- kernel_addr = '0x80000000'
2566- dtb_addr = '0x815f0000'
2567- initrd_addr = '0x81600000'
2568- load_addr = '0x80008000'
2569- boot_script = 'boot.scr'
2570- extra_boot_args_options = (
2571- 'earlyprintk fixrtc nocompcache vram=12M '
2572- 'omapfb.mode=dvi:1280x720MR-16@60 mpurate=${mpurate}')
2573+
2574+ def __init__(self):
2575+ super(BeagleConfig, self).__init__()
2576+ self.boot_script = 'boot.scr'
2577+ self.bootloader_flavor = 'omap3_beagle'
2578+ self.dtb_addr = '0x815f0000'
2579+ self.dtb_name = 'omap3-beagle.dtb'
2580+ self.extra_boot_args_options = (
2581+ 'earlyprintk fixrtc nocompcache vram=12M '
2582+ 'omapfb.mode=dvi:1280x720MR-16@60 mpurate=${mpurate}')
2583+ self.initrd_addr = '0x81600000'
2584+ self.kernel_addr = '0x80000000'
2585+ self.load_addr = '0x80008000'
2586+ self._serial_tty = 'ttyO2'
2587+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
2588+ self._live_serial_opts = 'serialtty=%s'
2589
2590
2591 class OveroConfig(OmapConfig):
2592- bootloader_flavor = 'omap3_overo'
2593- dtb_name = 'omap3-overo.dtb'
2594- _serial_tty = 'ttyO2'
2595- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
2596- kernel_addr = '0x80000000'
2597- dtb_addr = '0x815f0000'
2598- initrd_addr = '0x81600000'
2599- load_addr = '0x80008000'
2600- boot_script = 'boot.scr'
2601- extra_boot_args_options = (
2602- 'earlyprintk mpurate=${mpurate} vram=12M '
2603- 'omapdss.def_disp=${defaultdisplay} omapfb.mode=dvi:${dvimode}')
2604+ def __init__(self):
2605+ super(OveroConfig, self).__init__()
2606+ self.boot_script = 'boot.scr'
2607+ self.bootloader_flavor = 'omap3_overo'
2608+ self.dtb_addr = '0x815f0000'
2609+ self.dtb_name = 'omap3-overo.dtb'
2610+ self.extra_boot_args_options = (
2611+ 'earlyprintk mpurate=${mpurate} vram=12M '
2612+ 'omapdss.def_disp=${defaultdisplay} omapfb.mode=dvi:${dvimode}')
2613+ self.initrd_addr = '0x81600000'
2614+ self.kernel_addr = '0x80000000'
2615+ self.load_addr = '0x80008000'
2616+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
2617+ self._serial_tty = 'ttyO2'
2618
2619
2620 class PandaConfig(OmapConfig):
2621- bootloader_flavor = 'omap4_panda'
2622- dtb_name = 'omap4-panda.dtb'
2623- _serial_tty = 'ttyO2'
2624- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
2625- _live_serial_opts = 'serialtty=%s'
2626- kernel_addr = '0x80200000'
2627- dtb_addr = '0x815f0000'
2628- initrd_addr = '0x81600000'
2629- load_addr = '0x80008000'
2630- boot_script = 'boot.scr'
2631- extra_boot_args_options = (
2632- 'earlyprintk fixrtc nocompcache vram=48M '
2633- 'omapfb.vram=0:24M mem=456M@0x80000000 mem=512M@0xA0000000')
2634+ def __init__(self):
2635+ super(PandaConfig, self).__init__()
2636+ self._serial_tty = 'ttyO2'
2637+ self.boot_script = 'boot.scr'
2638+ self.bootloader_flavor = 'omap4_panda'
2639+ self.dtb_addr = '0x815f0000'
2640+ self.dtb_name = 'omap4-panda.dtb'
2641+ self.extra_boot_args_options = (
2642+ 'earlyprintk fixrtc nocompcache vram=48M '
2643+ 'omapfb.vram=0:24M mem=456M@0x80000000 mem=512M@0xA0000000')
2644+ self.initrd_addr = '0x81600000'
2645+ self.kernel_addr = '0x80200000'
2646+ self.load_addr = '0x80008000'
2647+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
2648+ self._live_serial_opts = 'serialtty=%s'
2649
2650
2651 class IgepConfig(BeagleConfig):
2652- bootloader_file_in_boot_part = False
2653- bootloader_flavor = None
2654- dtb_name = 'isee-igep-v2.dtb'
2655+ def __init__(self):
2656+ super(IgepConfig, self).__init__()
2657+ self.bootloader_file_in_boot_part = False
2658+ self.bootloader_flavor = None
2659+ self.dtb_name = 'isee-igep-v2.dtb'
2660
2661- @classmethod
2662- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
2663+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
2664 boot_device_or_file, k_img_data, i_img_data,
2665 d_img_data):
2666 # XXX: delete this method when hwpacks V1 can die
2667- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
2668- make_uImage(cls.load_addr, k_img_data, boot_dir)
2669+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
2670+ make_uImage(self.load_addr, k_img_data, boot_dir)
2671 make_uInitrd(i_img_data, boot_dir)
2672 make_dtb(d_img_data, boot_dir)
2673- boot_script_path = os.path.join(boot_dir, cls.boot_script)
2674+ boot_script_path = os.path.join(boot_dir, self.boot_script)
2675 make_boot_script(boot_env, boot_script_path)
2676 make_boot_ini(boot_script_path, boot_dir)
2677
2678
2679 class Ux500Config(BoardConfig):
2680- serial_tty = 'ttyAMA2'
2681- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
2682- _live_serial_opts = 'serialtty=%s'
2683- kernel_addr = '0x00100000'
2684- initrd_addr = '0x08000000'
2685- load_addr = '0x00008000'
2686- kernel_flavors = ['u8500', 'ux500']
2687- boot_script = 'flash.scr'
2688- extra_boot_args_options = (
2689- 'earlyprintk rootdelay=1 fixrtc nocompcache '
2690- 'mem=96M@0 mem_modem=32M@96M mem=44M@128M pmem=22M@172M '
2691- 'mem=30M@194M mem_mali=32M@224M pmem_hwb=54M@256M '
2692- 'hwmem=48M@302M mem=152M@360M')
2693- mmc_option = '1:1'
2694-
2695- @classproperty
2696- def live_serial_opts(cls):
2697- return cls._live_serial_opts % cls.serial_tty
2698-
2699- @classproperty
2700- def extra_serial_opts(cls):
2701- return cls._extra_serial_opts % cls.serial_tty
2702-
2703- @classmethod
2704- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
2705+ def __init__(self):
2706+ super(Ux500Config, self).__init__()
2707+ self.boot_script = 'flash.scr'
2708+ self.extra_boot_args_options = (
2709+ 'earlyprintk rootdelay=1 fixrtc nocompcache '
2710+ 'mem=96M@0 mem_modem=32M@96M mem=44M@128M pmem=22M@172M '
2711+ 'mem=30M@194M mem_mali=32M@224M pmem_hwb=54M@256M '
2712+ 'hwmem=48M@302M mem=152M@360M')
2713+ self.initrd_addr = '0x08000000'
2714+ self.kernel_addr = '0x00100000'
2715+ self.kernel_flavors = ['u8500', 'ux500']
2716+ self.load_addr = '0x00008000'
2717+ self.mmc_option = '1:1'
2718+ self.serial_tty = 'ttyAMA2'
2719+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
2720+ self._live_serial_opts = 'serialtty=%s'
2721+
2722+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
2723 boot_device_or_file, k_img_data, i_img_data,
2724 d_img_data):
2725 # XXX: delete this method when hwpacks V1 can die
2726- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
2727- make_uImage(cls.load_addr, k_img_data, boot_dir)
2728+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
2729+ make_uImage(self.load_addr, k_img_data, boot_dir)
2730 make_uInitrd(i_img_data, boot_dir)
2731- boot_script_path = os.path.join(boot_dir, cls.boot_script)
2732+ boot_script_path = os.path.join(boot_dir, self.boot_script)
2733 make_boot_script(boot_env, boot_script_path)
2734
2735
2736@@ -1314,15 +1084,16 @@
2737 Note that the Snowball board needs a loader partition on the
2738 internal eMMC flash to boot. That partition is created with
2739 the SnowballConfigImage configuration.'''
2740+ def __init__(self):
2741+ super(SnowballSdConfig, self).__init__()
2742
2743- @classmethod
2744- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
2745+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
2746 boot_device_or_file, k_img_data, i_img_data,
2747 d_img_data):
2748 # XXX: delete this method when hwpacks V1 can die
2749- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
2750- make_uImage(cls.load_addr, k_img_data, boot_dir)
2751- boot_script_path = os.path.join(boot_dir, cls.boot_script)
2752+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
2753+ make_uImage(self.load_addr, k_img_data, boot_dir)
2754+ boot_script_path = os.path.join(boot_dir, self.boot_script)
2755 make_boot_script(boot_env, boot_script_path)
2756
2757
2758@@ -1330,16 +1101,18 @@
2759 '''Use only with --image option. Creates a raw image which contains an
2760 additional (raw) loader partition, containing some boot stages
2761 and u-boot.'''
2762- # Boot ROM looks for a boot table of contents (TOC) at 0x20000
2763- # Actually, it first looks at address 0, but that's where l-m-c
2764- # puts the MBR, so the boot loader skips that address.
2765- supports_writing_to_mmc = False
2766 SNOWBALL_LOADER_START_S = (128 * 1024) / SECTOR_SIZE
2767- snowball_startup_files_config = 'startfiles.cfg'
2768 TOC_SIZE = 512
2769
2770- @classmethod
2771- def get_v1_sfdisk_cmd(cls, should_align_boot_part=None):
2772+ def __init__(self):
2773+ super(SnowballEmmcConfig, self).__init__()
2774+ # Boot ROM looks for a boot table of contents (TOC) at 0x20000
2775+ # Actually, it first looks at address 0, but that's where l-m-c
2776+ # puts the MBR, so the boot loader skips that address.
2777+ self.supports_writing_to_mmc = False
2778+ self.snowball_startup_files_config = 'startfiles.cfg'
2779+
2780+ def get_v1_sfdisk_cmd(self, should_align_boot_part=None):
2781 """Return the sfdisk command to partition the media.
2782
2783 :param should_align_boot_part: Ignored.
2784@@ -1357,68 +1130,64 @@
2785 # with the usual SECTOR_SIZE of 0x200.
2786 # (sector 0 is MBR / partition table)
2787 loader_start, loader_end, loader_len = align_partition(
2788- SnowballEmmcConfig.SNOWBALL_LOADER_START_S,
2789- cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
2790+ self.SNOWBALL_LOADER_START_S,
2791+ self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
2792
2793 boot_start, boot_end, boot_len = align_partition(
2794- loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
2795+ loader_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
2796 # we ignore _root_end / _root_len and return an sfdisk command to
2797 # instruct the use of all remaining space; XXX if we had some root size
2798 # config, we could do something more sensible
2799 root_start, _root_end, _root_len = align_partition(
2800- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
2801+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
2802
2803 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
2804 loader_start, loader_len, boot_start, boot_len, root_start)
2805
2806- @classmethod
2807- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
2808+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
2809 boot_device_or_file, k_img_data, i_img_data,
2810 d_img_data):
2811 # XXX: delete this method when hwpacks V1 can die
2812- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
2813- make_uImage(cls.load_addr, k_img_data, boot_dir)
2814- boot_script_path = os.path.join(boot_dir, cls.boot_script)
2815+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
2816+ make_uImage(self.load_addr, k_img_data, boot_dir)
2817+ boot_script_path = os.path.join(boot_dir, self.boot_script)
2818 make_boot_script(boot_env, boot_script_path)
2819- cls.populate_raw_partition(boot_device_or_file, chroot_dir)
2820+ self.populate_raw_partition(boot_device_or_file, chroot_dir)
2821
2822- @classmethod
2823- def populate_raw_partition(cls, boot_device_or_file, chroot_dir):
2824+ def populate_raw_partition(self, boot_device_or_file, chroot_dir):
2825 # Populate created raw partition with TOC and startup files.
2826 _, toc_filename = tempfile.mkstemp()
2827- config_files_dir = cls.snowball_config(chroot_dir)
2828- new_files = cls.get_file_info(chroot_dir, config_files_dir)
2829+ config_files_dir = self.snowball_config(chroot_dir)
2830+ new_files = self.get_file_info(chroot_dir, config_files_dir)
2831 with open(toc_filename, 'wb') as toc:
2832- cls.create_toc(toc, new_files)
2833- cls.install_snowball_boot_loader(toc_filename, new_files,
2834+ self.create_toc(toc, new_files)
2835+ self.install_snowball_boot_loader(toc_filename, new_files,
2836 boot_device_or_file,
2837- cls.SNOWBALL_LOADER_START_S,
2838- cls.delete_startupfiles)
2839- cls.delete_file(toc_filename)
2840- if cls.delete_startupfiles:
2841- cls.delete_file(os.path.join(config_files_dir,
2842- cls.snowball_startup_files_config))
2843+ self.SNOWBALL_LOADER_START_S,
2844+ self.delete_startupfiles)
2845+ self.delete_file(toc_filename)
2846+ if self.delete_startupfiles:
2847+ self.delete_file(os.path.join(config_files_dir,
2848+ self.snowball_startup_files_config))
2849
2850- @classmethod
2851- def snowball_config(cls, chroot_dir):
2852+ def snowball_config(self, chroot_dir):
2853 # We will find the startupfiles in the target boot partition.
2854 return os.path.join(chroot_dir, 'boot')
2855
2856- @classproperty
2857- def delete_startupfiles(cls):
2858+ @property
2859+ def delete_startupfiles(self):
2860 # The startupfiles will have been installed to the target boot
2861 # partition by the hwpack, and should be deleted so we don't leave
2862 # them on the target system.
2863 return True
2864
2865- @classmethod
2866- def install_snowball_boot_loader(cls, toc_file_name, files,
2867+ def install_snowball_boot_loader(self, toc_file_name, files,
2868 boot_device_or_file, start_sector,
2869 delete_startupfiles=False):
2870 ''' Copies TOC and boot files into the boot partition.
2871 A sector size of 1 is used for some files, as they do not
2872 necessarily start on an even address. '''
2873- assert os.path.getsize(toc_file_name) <= cls.TOC_SIZE
2874+ assert os.path.getsize(toc_file_name) <= self.TOC_SIZE
2875 _dd(toc_file_name, boot_device_or_file, seek=start_sector)
2876
2877 for file in files:
2878@@ -1433,16 +1202,14 @@
2879 seek_sectors = start_sector + file['offset'] / SECTOR_SIZE
2880 _dd(filename, boot_device_or_file, seek=seek_sectors)
2881 if delete_startupfiles:
2882- cls.delete_file(filename)
2883+ self.delete_file(filename)
2884
2885- @classmethod
2886- def delete_file(cls, file_path):
2887+ def delete_file(self, file_path):
2888 cmd = ["rm", "%s" % file_path]
2889 proc = cmd_runner.run(cmd, as_root=True)
2890 proc.wait()
2891
2892- @classmethod
2893- def create_toc(cls, f, files):
2894+ def create_toc(self, f, files):
2895 ''' Writes a table of contents of the boot binaries.
2896 Boot rom searches this table to find the binaries.'''
2897 # Format string means: < little endian,
2898@@ -1464,15 +1231,14 @@
2899 file['section_name'])
2900 f.write(data)
2901
2902- @classmethod
2903- def get_file_info(cls, chroot_dir, config_files_dir):
2904+ def get_file_info(self, chroot_dir, config_files_dir):
2905 ''' Fills in the offsets of files that are located in
2906 non-absolute memory locations depending on their sizes.'
2907 Also fills in file sizes'''
2908- ofs = cls.TOC_SIZE
2909+ ofs = self.TOC_SIZE
2910 files = []
2911 with open(os.path.join(config_files_dir,
2912- cls.snowball_startup_files_config),
2913+ self.snowball_startup_files_config),
2914 'r') as info_file:
2915 for line in info_file:
2916 file_data = line.split()
2917@@ -1503,23 +1269,16 @@
2918
2919
2920 class Mx5Config(BoardConfig):
2921- serial_tty = 'ttymxc0'
2922- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
2923- _live_serial_opts = 'serialtty=%s'
2924- boot_script = 'boot.scr'
2925- mmc_part_offset = 1
2926- mmc_option = '0:2'
2927-
2928- @classproperty
2929- def live_serial_opts(cls):
2930- return cls._live_serial_opts % cls.serial_tty
2931-
2932- @classproperty
2933- def extra_serial_opts(cls):
2934- return cls._extra_serial_opts % cls.serial_tty
2935-
2936- @classmethod
2937- def get_v1_sfdisk_cmd(cls, should_align_boot_part=None):
2938+ def __init__(self):
2939+ super(Mx5Config, self).__init__()
2940+ self.boot_script = 'boot.scr'
2941+ self.mmc_option = '0:2'
2942+ self.mmc_part_offset = 1
2943+ self.serial_tty = 'ttymxc0'
2944+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
2945+ self._live_serial_opts = 'serialtty=%s'
2946+
2947+ def get_v1_sfdisk_cmd(self, should_align_boot_part=None):
2948 """Return the sfdisk command to partition the media.
2949
2950 :param should_align_boot_part: Ignored.
2951@@ -1533,103 +1292,107 @@
2952 # onwards, so it's safer to just start at the first sector, sector 1
2953 # (sector 0 is MBR / partition table)
2954 loader_start, loader_end, loader_len = align_partition(
2955- 1, cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
2956+ 1, self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
2957
2958 boot_start, boot_end, boot_len = align_partition(
2959- loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
2960+ loader_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
2961 # we ignore _root_end / _root_len and return a sfdisk command to
2962 # instruct the use of all remaining space; XXX if we had some root size
2963 # config, we could do something more sensible
2964 root_start, _root_end, _root_len = align_partition(
2965- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
2966+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
2967
2968 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
2969 loader_start, loader_len, boot_start, boot_len, root_start)
2970
2971- @classmethod
2972- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
2973+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
2974 boot_device_or_file, k_img_data, i_img_data,
2975 d_img_data):
2976 # XXX: delete this method when hwpacks V1 can die
2977- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
2978- with cls.hardwarepack_handler:
2979- bootloader_file = cls.get_file('bootloader_file',
2980+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
2981+ with self.hardwarepack_handler:
2982+ bootloader_file = self.get_file('bootloader_file',
2983 default=os.path.join(
2984- chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor,
2985+ chroot_dir, 'usr', 'lib', 'u-boot', self.bootloader_flavor,
2986 'u-boot.imx'))
2987 install_mx5_boot_loader(bootloader_file, boot_device_or_file,
2988- cls.LOADER_MIN_SIZE_S)
2989- make_uImage(cls.load_addr, k_img_data, boot_dir)
2990+ self.LOADER_MIN_SIZE_S)
2991+ make_uImage(self.load_addr, k_img_data, boot_dir)
2992 make_uInitrd(i_img_data, boot_dir)
2993 make_dtb(d_img_data, boot_dir)
2994- boot_script_path = os.path.join(boot_dir, cls.boot_script)
2995+ boot_script_path = os.path.join(boot_dir, self.boot_script)
2996 make_boot_script(boot_env, boot_script_path)
2997
2998
2999 class Mx51Config(Mx5Config):
3000- kernel_addr = '0x90000000'
3001- dtb_addr = '0x91ff0000'
3002- initrd_addr = '0x92000000'
3003- load_addr = '0x90008000'
3004- kernel_flavors = ['linaro-mx51', 'linaro-lt-mx5']
3005+ def __init__(self):
3006+ super(Mx51Config, self).__init__()
3007+ self.dtb_addr = '0x91ff0000'
3008+ self.initrd_addr = '0x92000000'
3009+ self.kernel_addr = '0x90000000'
3010+ self.kernel_flavors = ['linaro-mx51', 'linaro-lt-mx5']
3011+ self.load_addr = '0x90008000'
3012
3013
3014 class Mx53Config(Mx5Config):
3015- kernel_addr = '0x70000000'
3016- dtb_addr = '0x71ff0000'
3017- initrd_addr = '0x72000000'
3018- load_addr = '0x70008000'
3019- kernel_flavors = ['linaro-lt-mx53', 'linaro-lt-mx5']
3020+ def __init__(self):
3021+ super(Mx53Config, self).__init__()
3022+ self.dtb_addr = '0x71ff0000'
3023+ self.initrd_addr = '0x72000000'
3024+ self.kernel_addr = '0x70000000'
3025+ self.kernel_flavors = ['linaro-lt-mx53', 'linaro-lt-mx5']
3026+ self.load_addr = '0x70008000'
3027
3028
3029 class EfikamxConfig(Mx51Config):
3030- bootloader_flavor = 'efikamx'
3031- dtb_name = 'genesi-efikamx.dtb'
3032+ def __init__(self):
3033+ super(EfikamxConfig, self).__init__()
3034+ self.bootloader_flavor = 'efikamx'
3035+ self.dtb_name = 'genesi-efikamx.dtb'
3036
3037
3038 class EfikasbConfig(Mx51Config):
3039- bootloader_flavor = 'efikasb'
3040- dtb_name = 'genesi-efikasb.dtb'
3041+ def __init__(self):
3042+ super(EfikasbConfig, self).__init__()
3043+ self.bootloader_flavor = 'efikasb'
3044+ self.dtb_name = 'genesi-efikasb.dtb'
3045
3046
3047 class Mx51evkConfig(Mx51Config):
3048- bootloader_flavor = 'mx51evk'
3049- dtb_name = 'mx51-babbage.dtb'
3050+ def __init__(self):
3051+ super(Mx51evkConfig, self).__init__()
3052+ self.bootloader_flavor = 'mx51evk'
3053+ self.dtb_name = 'mx51-babbage.dtb'
3054
3055
3056 class Mx53LoCoConfig(Mx53Config):
3057- bootloader_flavor = 'mx53loco'
3058- dtb_name = 'mx53-loco.dtb'
3059+ def __init__(self):
3060+ super(Mx53LoCoConfig, self).__init__()
3061+ self.bootloader_flavor = 'mx53loco'
3062+ self.dtb_name = 'mx53-loco.dtb'
3063
3064
3065 class VexpressConfig(BoardConfig):
3066- bootloader_flavor = 'ca9x4_ct_vxp'
3067- bootloader_file_in_boot_part = True
3068- serial_tty = 'ttyAMA0'
3069- _extra_serial_opts = 'console=tty0 console=%s,38400n8'
3070- _live_serial_opts = 'serialtty=%s'
3071- kernel_addr = '0x60000000'
3072- initrd_addr = '0x62000000'
3073- load_addr = '0x60008000'
3074- kernel_flavors = ['linaro-vexpress']
3075- boot_script = 'boot.scr'
3076- # ARM Boot Monitor is used to load u-boot, uImage etc. into flash and
3077- # only allows for FAT16
3078- fat_size = 16
3079-
3080- @classproperty
3081- def live_serial_opts(cls):
3082- return cls._live_serial_opts % cls.serial_tty
3083-
3084- @classproperty
3085- def extra_serial_opts(cls):
3086- return cls._extra_serial_opts % cls.serial_tty
3087-
3088- @classmethod
3089- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
3090+ def __init__(self):
3091+ super(VexpressConfig, self).__init__()
3092+ self.boot_script = 'boot.scr'
3093+ self.bootloader_file_in_boot_part = True
3094+ self.bootloader_flavor = 'ca9x4_ct_vxp'
3095+ # ARM Boot Monitor is used to load u-boot, uImage etc. into flash and
3096+ # only allows for FAT16
3097+ self.fat_size = 16
3098+ self.initrd_addr = '0x62000000'
3099+ self.kernel_addr = '0x60000000'
3100+ self.kernel_flavors = ['linaro-vexpress']
3101+ self.load_addr = '0x60008000'
3102+ self.serial_tty = 'ttyAMA0'
3103+ self._extra_serial_opts = 'console=tty0 console=%s,38400n8'
3104+ self._live_serial_opts = 'serialtty=%s'
3105+
3106+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
3107 boot_device_or_file, k_img_data, i_img_data,
3108 d_img_data):
3109- make_uImage(cls.load_addr, k_img_data, boot_dir)
3110+ make_uImage(self.load_addr, k_img_data, boot_dir)
3111 make_uInitrd(i_img_data, boot_dir)
3112
3113
3114@@ -1637,22 +1400,23 @@
3115 # For now, this is a duplicate of VexpressConfig.
3116 # In future, there will also be A5 and A15 variants.
3117 # For all of these, there should never be any V1 hardware packs.
3118- pass
3119+ def __init__(self):
3120+ super(VexpressA9Config, self).__init__()
3121
3122
3123 class FastModelConfig(BoardConfig):
3124- supports_writing_to_mmc = False
3125+ def __init__(self):
3126+ super(FastModelConfig, self).__init__()
3127+ self.supports_writing_to_mmc = False
3128
3129- @classmethod
3130- def _get_bootcmd(cls, i_img_data, d_img_data):
3131+ def _get_bootcmd(self, i_img_data, d_img_data):
3132 """Get the bootcmd for FastModel.
3133
3134 We override this as we don't do uboot.
3135 """
3136 return ""
3137
3138- @classmethod
3139- def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir,
3140+ def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
3141 boot_device_or_file, k_img_data, i_img_data,
3142 d_img_data):
3143 output_dir = os.path.dirname(boot_device_or_file)
3144@@ -1669,16 +1433,15 @@
3145
3146
3147 class SamsungConfig(BoardConfig):
3148- @classproperty
3149- def extra_serial_opts(cls):
3150- return cls._extra_serial_opts % cls.serial_tty
3151+ def __init__(self):
3152+ super(SamsungConfig, self).__init__()
3153+ self._extra_serial_opts = None
3154
3155- @classmethod
3156- def get_v1_sfdisk_cmd(cls, should_align_boot_part=False):
3157+ def get_v1_sfdisk_cmd(self, should_align_boot_part=False):
3158 # bootloaders partition needs to hold BL1, U-Boot environment, and BL2
3159 loaders_min_len = (
3160- cls.SAMSUNG_V310_BL2_START + cls.SAMSUNG_V310_BL2_LEN -
3161- cls.SAMSUNG_V310_BL1_START)
3162+ self.samsung_v310_bl2_start + self.samsung_v310_bl2_len -
3163+ self.samsung_v310_bl1_start)
3164
3165 # bootloaders partition
3166 loaders_start, loaders_end, loaders_len = align_partition(
3167@@ -1686,44 +1449,42 @@
3168
3169 # FAT boot partition
3170 boot_start, boot_end, boot_len = align_partition(
3171- loaders_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
3172+ loaders_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
3173
3174 # root partition
3175 # we ignore _root_end / _root_len and return a sfdisk command to
3176 # instruct the use of all remaining space; XXX if we had some root size
3177 # config, we could do something more sensible
3178 root_start, _root_end, _root_len = align_partition(
3179- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
3180+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
3181
3182 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
3183 loaders_start, loaders_len, boot_start, boot_len, root_start)
3184
3185- @classmethod
3186- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
3187+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
3188 boot_device_or_file, k_img_data, i_img_data,
3189 d_img_data):
3190 # XXX: delete this method when hwpacks V1 can die
3191- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
3192- cls.install_samsung_boot_loader(cls._get_samsung_spl(chroot_dir),
3193- cls._get_samsung_bootloader(chroot_dir), boot_device_or_file)
3194- env_size = cls.SAMSUNG_V310_ENV_LEN * SECTOR_SIZE
3195+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
3196+ self.install_samsung_boot_loader(self._get_samsung_spl(chroot_dir),
3197+ self._get_samsung_bootloader(chroot_dir), boot_device_or_file)
3198+ env_size = self.samsung_v310_env_len * SECTOR_SIZE
3199 env_file = make_flashable_env(boot_env, env_size)
3200- _dd(env_file, boot_device_or_file, seek=cls.SAMSUNG_V310_ENV_START)
3201+ _dd(env_file, boot_device_or_file, seek=self.samsung_v310_env_start)
3202
3203- make_uImage(cls.load_addr, k_img_data, boot_dir)
3204+ make_uImage(self.load_addr, k_img_data, boot_dir)
3205 make_uInitrd(i_img_data, boot_dir)
3206
3207 # unused at the moment once FAT support enabled for the
3208 # Samsung u-boot this can be used bug 727978
3209- boot_script_path = os.path.join(boot_dir, cls.boot_script)
3210+ boot_script_path = os.path.join(boot_dir, self.boot_script)
3211 make_boot_script(boot_env, boot_script_path)
3212
3213- @classmethod
3214- def _get_samsung_spl(cls, chroot_dir):
3215+ def _get_samsung_spl(self, chroot_dir):
3216 # XXX: delete this method when hwpacks V1 can die
3217- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
3218+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
3219 spl_dir = os.path.join(
3220- chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor)
3221+ chroot_dir, 'usr', 'lib', 'u-boot', self.bootloader_flavor)
3222 old_spl_path = os.path.join(spl_dir, 'v310_mmc_spl.bin')
3223 new_spl_path = os.path.join(spl_dir, 'u-boot-mmc-spl.bin')
3224 new_new_spl_path = os.path.join(spl_dir, 'origen-spl.bin')
3225@@ -1743,49 +1504,48 @@
3226 % (old_spl_path, new_spl_path))
3227 return spl_file
3228
3229- @classmethod
3230- def _get_samsung_bootloader(cls, chroot_dir):
3231+ def _get_samsung_bootloader(self, chroot_dir):
3232 # XXX: delete this method when hwpacks V1 can die
3233- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
3234+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
3235 bootloader_file = os.path.join(
3236- chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor,
3237+ chroot_dir, 'usr', 'lib', 'u-boot', self.bootloader_flavor,
3238 'u-boot.bin')
3239 return bootloader_file
3240
3241- @classmethod
3242- def populate_raw_partition(cls, boot_device_or_file, chroot_dir):
3243+ def populate_raw_partition(self, boot_device_or_file, chroot_dir):
3244 # Zero the env so that the boot_script will get loaded
3245- _dd("/dev/zero", boot_device_or_file, count=cls.SAMSUNG_V310_ENV_LEN,
3246- seek=cls.SAMSUNG_V310_ENV_START)
3247+ _dd("/dev/zero", boot_device_or_file, count=self.samsung_v310_env_len,
3248+ seek=self.samsung_v310_env_start)
3249 # Populate created raw partition with BL1 and u-boot
3250 spl_file = os.path.join(chroot_dir, 'boot', 'u-boot-mmc-spl.bin')
3251 assert os.path.getsize(spl_file) <= (
3252- cls.SAMSUNG_V310_BL1_LEN * SECTOR_SIZE), (
3253- "%s is larger than SAMSUNG_V310_BL1_LEN" % spl_file)
3254- _dd(spl_file, boot_device_or_file, seek=cls.SAMSUNG_V310_BL1_START)
3255+ self.samsung_v310_bl1_len * SECTOR_SIZE), (
3256+ "%s is larger than samsung_v310_bl1_len" % spl_file)
3257+ _dd(spl_file, boot_device_or_file, seek=self.samsung_v310_bl1_start)
3258 uboot_file = os.path.join(chroot_dir, 'boot', 'u-boot.bin')
3259 assert os.path.getsize(uboot_file) <= (
3260- cls.SAMSUNG_V310_BL2_LEN * SECTOR_SIZE), (
3261- "%s is larger than SAMSUNG_V310_BL2_LEN" % uboot_file)
3262- _dd(uboot_file, boot_device_or_file, seek=cls.SAMSUNG_V310_BL2_START)
3263+ self.samsung_v310_bl2_len * SECTOR_SIZE), (
3264+ "%s is larger than samsung_v310_bl2_len" % uboot_file)
3265+ _dd(uboot_file, boot_device_or_file, seek=self.samsung_v310_bl2_start)
3266
3267
3268 class SMDKV310Config(SamsungConfig):
3269- bootloader_flavor = 'smdkv310'
3270- serial_tty = 'ttySAC1'
3271- _extra_serial_opts = 'console=%s,115200n8'
3272- kernel_addr = '0x40007000'
3273- initrd_addr = '0x42000000'
3274- load_addr = '0x40008000'
3275- kernel_flavors = ['s5pv310']
3276- boot_script = 'boot.scr'
3277- mmc_part_offset = 1
3278- mmc_option = '0:2'
3279+ def __init__(self):
3280+ super(SMDKV310Config, self).__init__()
3281+ self.boot_script = 'boot.scr'
3282+ self.bootloader_flavor = 'smdkv310'
3283+ self.initrd_addr = '0x42000000'
3284+ self.kernel_addr = '0x40007000'
3285+ self.kernel_flavors = ['s5pv310']
3286+ self.load_addr = '0x40008000'
3287+ self.mmc_option = '0:2'
3288+ self.mmc_part_offset = 1
3289+ self.serial_tty = 'ttySAC1'
3290+ self._extra_serial_opts = 'console=%s,115200n8'
3291
3292- @classmethod
3293- def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
3294+ def _get_boot_env(self, is_live, is_lowmem, consoles, rootfs_id,
3295 i_img_data, d_img_data):
3296- boot_env = super(SamsungConfig, cls)._get_boot_env(
3297+ boot_env = super(SamsungConfig, self)._get_boot_env(
3298 is_live, is_lowmem, consoles, rootfs_id, i_img_data, d_img_data)
3299
3300 boot_env["ethact"] = "smc911x-0"
3301@@ -1795,27 +1555,22 @@
3302
3303
3304 class OrigenConfig(SamsungConfig):
3305- bootloader_flavor = 'origen'
3306- serial_tty = 'ttySAC2'
3307- _extra_serial_opts = 'console=%s,115200n8'
3308- kernel_addr = '0x40007000'
3309- initrd_addr = '0x42000000'
3310- load_addr = '0x40008000'
3311- kernel_flavors = ['origen']
3312- boot_script = 'boot.scr'
3313- mmc_part_offset = 1
3314- mmc_option = '0:2'
3315+ # TODO test
3316+ def __init__(self):
3317+ super(OrigenConfig, self).__init__()
3318+ self.boot_script = 'boot.scr'
3319+ self.bootloader_flavor = 'origen'
3320+ self.initrd_addr = '0x42000000'
3321+ self.kernel_addr = '0x40007000'
3322+ self.kernel_flavors = ['origen']
3323+ self.load_addr = '0x40008000'
3324+ self.mmc_option = '0:2'
3325+ self.mmc_part_offset = 1
3326+ self.serial_tty = 'ttySAC2'
3327+ self._extra_serial_opts = 'console=%s,115200n8'
3328
3329
3330 class I386Config(BoardConfig):
3331- # define serial
3332- serial_tty = 'ttyS0'
3333- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
3334- _live_serial_opts = 'serialtty=%s'
3335-
3336- # define kernel image
3337- kernel_flavors = ['generic', 'pae']
3338-
3339 # define bootloader
3340 BOOTLOADER_CMD = 'grub-install'
3341 BOOTLOADER_CFG_FILE = 'grub/grub.cfg'
3342@@ -1827,16 +1582,14 @@
3343 initrd /%s
3344 }"""
3345
3346- @classproperty
3347- def live_serial_opts(cls):
3348- return cls._live_serial_opts % cls.serial_tty
3349-
3350- @classproperty
3351- def extra_serial_opts(cls):
3352- return cls._extra_serial_opts % cls.serial_tty
3353-
3354- @classmethod
3355- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
3356+ def __init__(self):
3357+ super(I386Config, self).__init__()
3358+ self.kernel_flavors = ['generic', 'pae']
3359+ self.serial_tty = 'ttyS0'
3360+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
3361+ self._live_serial_opts = 'serialtty=%s'
3362+
3363+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
3364 boot_device_or_file, k_img_data, i_img_data,
3365 d_img_data):
3366 # copy image and init into boot partition
3367@@ -1849,13 +1602,13 @@
3368 img_loop = register_loopback(boot_device_or_file, 0, img_size)
3369
3370 # install bootloader
3371- cmd_runner.run([cls.BOOTLOADER_CMD, '--boot-directory=%s' % boot_dir,
3372+ cmd_runner.run([self.BOOTLOADER_CMD, '--boot-directory=%s' % boot_dir,
3373 '--modules', 'part_msdos', img_loop],
3374 as_root=True).wait()
3375
3376 # generate loader config file
3377- loader_config = cls.BOOTLOADER_CFG % (os.path.basename(k_img_data),
3378- cls.extra_serial_opts, os.path.basename(i_img_data))
3379+ loader_config = self.BOOTLOADER_CFG % (os.path.basename(k_img_data),
3380+ self.extra_serial_opts, os.path.basename(i_img_data))
3381
3382 _, tmpfile = tempfile.mkstemp()
3383 atexit.register(os.unlink, tmpfile)
3384@@ -1863,40 +1616,57 @@
3385 fd.write(loader_config)
3386
3387 cmd_runner.run(['cp', tmpfile, os.path.join(boot_dir,
3388- cls.BOOTLOADER_CFG_FILE)], as_root=True).wait()
3389+ self.BOOTLOADER_CFG_FILE)], as_root=True).wait()
3390
3391- @classmethod
3392- def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir,
3393+ def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
3394 boot_device_or_file, k_img_data, i_img_data,
3395 d_img_data):
3396 # reuse hwpack v1 function
3397- cls._make_boot_files(boot_env, chroot_dir, boot_dir,
3398- boot_device_or_file, k_img_data, i_img_data,
3399- d_img_data)
3400+ self._make_boot_files(boot_env, chroot_dir, boot_dir,
3401+ boot_device_or_file, k_img_data, i_img_data,
3402+ d_img_data)
3403+
3404+
3405+class BoardConfigException(Exception):
3406+ """General board config exception."""
3407
3408
3409 board_configs = {
3410 'beagle': BeagleConfig,
3411- 'igep': IgepConfig,
3412- 'panda': PandaConfig,
3413- 'vexpress': VexpressConfig,
3414- 'vexpress-a9': VexpressA9Config,
3415- 'fastmodel': FastModelConfig,
3416- 'ux500': Ux500Config,
3417- 'snowball_sd': SnowballSdConfig,
3418- 'snowball_emmc': SnowballEmmcConfig,
3419 'efikamx': EfikamxConfig,
3420 'efikasb': EfikasbConfig,
3421+ 'fastmodel': FastModelConfig,
3422+ 'i386': I386Config,
3423+ 'igep': IgepConfig,
3424 'mx51evk': Mx51evkConfig,
3425 'mx53loco': Mx53LoCoConfig,
3426+ 'mx6qsabrelite': BoardConfig,
3427+ 'origen': OrigenConfig,
3428 'overo': OveroConfig,
3429+ 'panda': PandaConfig,
3430 'smdkv310': SMDKV310Config,
3431- 'origen': OrigenConfig,
3432- 'mx6qsabrelite': BoardConfig,
3433- 'i386': I386Config,
3434+ 'snowball_emmc': SnowballEmmcConfig,
3435+ 'snowball_sd': SnowballSdConfig,
3436+ 'ux500': Ux500Config,
3437+ 'vexpress': VexpressConfig,
3438+ 'vexpress-a9': VexpressA9Config,
3439 }
3440
3441
3442+def get_board_config(board):
3443+ """Get the board configuration for the specified board.
3444+
3445+ :param board: The name of the board to get the configuration of.
3446+ :type board: str
3447+ """
3448+ clazz = board_configs.get(board, None)
3449+ if clazz:
3450+ return clazz()
3451+ else:
3452+ raise BoardConfigException("Board name '%s' has no configuration "
3453+ "available." % board)
3454+
3455+
3456 def _dd(input_file, output_file, block_size=SECTOR_SIZE, count=None, seek=None,
3457 skip=None):
3458 """Wrapper around the dd command"""
3459
3460=== modified file 'linaro_image_tools/media_create/chroot_utils.py'
3461--- linaro_image_tools/media_create/chroot_utils.py 2012-10-04 09:12:57 +0000
3462+++ linaro_image_tools/media_create/chroot_utils.py 2012-11-20 10:49:03 +0000
3463@@ -25,7 +25,7 @@
3464 is_arm_host,
3465 find_command,
3466 )
3467-from linaro_image_tools.media_create.boards import HardwarepackHandler
3468+from linaro_image_tools.hwpack.handler import HardwarepackHandler
3469
3470 # It'd be nice if we could use atexit here, but all the things we need to undo
3471 # have to happen right after install_hwpacks completes and the atexit
3472
3473=== modified file 'linaro_image_tools/media_create/tests/__init__.py'
3474--- linaro_image_tools/media_create/tests/__init__.py 2012-06-07 13:12:42 +0000
3475+++ linaro_image_tools/media_create/tests/__init__.py 2012-11-20 10:49:03 +0000
3476@@ -2,8 +2,10 @@
3477
3478
3479 def test_suite():
3480- module_names = ['linaro_image_tools.media_create.tests.test_media_create',
3481- ]
3482+ module_names = [
3483+ 'linaro_image_tools.media_create.tests.test_media_create',
3484+ 'linaro_image_tools.media_create.tests.test_android_boards',
3485+ ]
3486 loader = unittest.TestLoader()
3487 suite = loader.loadTestsFromNames(module_names)
3488 return suite
3489
3490=== added file 'linaro_image_tools/media_create/tests/test_android_boards.py'
3491--- linaro_image_tools/media_create/tests/test_android_boards.py 1970-01-01 00:00:00 +0000
3492+++ linaro_image_tools/media_create/tests/test_android_boards.py 2012-11-20 10:49:03 +0000
3493@@ -0,0 +1,249 @@
3494+# Copyright (C) 2010, 2011 Linaro
3495+#
3496+# Author: Milo Casagrande <milo.casagrande@linaro.org>
3497+#
3498+# This file is part of Linaro Image Tools.
3499+#
3500+# Linaro Image Tools is free software: you can redistribute it and/or modify
3501+# it under the terms of the GNU General Public License as published by
3502+# the Free Software Foundation, either version 3 of the License, or
3503+# (at your option) any later version.
3504+#
3505+# Linaro Image Tools is distributed in the hope that it will be useful,
3506+# but WITHOUT ANY WARRANTY; without even the implied warranty of
3507+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3508+# GNU General Public License for more details.
3509+#
3510+# You should have received a copy of the GNU General Public License
3511+# along with this program. If not, see <http://www.gnu.org/licenses/>.
3512+
3513+from StringIO import StringIO
3514+from testtools import TestCase
3515+
3516+from linaro_image_tools.media_create.boards import (
3517+ BoardConfigException,
3518+ )
3519+
3520+from linaro_image_tools.media_create.android_boards import (
3521+ AndroidBeagleConfig,
3522+ get_board_config,
3523+ )
3524+
3525+
3526+class TestAndroidBoards(TestCase):
3527+ """Class to test small things in android_boards."""
3528+
3529+ def test_get_board_config(self):
3530+ instance = get_board_config('beagle')
3531+ self.assertIsInstance(instance, AndroidBeagleConfig)
3532+
3533+ def test_get_board_config_wrong(self):
3534+ self.assertRaises(BoardConfigException, get_board_config, 'notadevice')
3535+
3536+
3537+class TestAndroidBoardsHwpack(TestCase):
3538+ """Class to test the new Android hwpack configuration file."""
3539+
3540+ def setUp(self):
3541+ super(TestAndroidBoardsHwpack, self).setUp()
3542+ # Pick a default board.
3543+ self.config = get_board_config('beagle')
3544+ self.hwpack_base = "format: 3.0\n"
3545+ self.fake_hwpack = (self.hwpack_base + "dtb_name: a_name\n"
3546+ "fdt_high: '0xFFFFFFFF'\nfat_size: 16\n")
3547+
3548+ def test_read_from_file(self):
3549+ conf = self.config.from_file(StringIO(self.fake_hwpack))
3550+ expected = {'format': 3.0, 'dtb_name': 'a_name',
3551+ 'fdt_high': '0xFFFFFFFF', 'fat_size': 16}
3552+ self.assertEqual(expected, conf)
3553+
3554+ def test_android_specific_args(self):
3555+ """The field android_specific_args should be a concatenated string."""
3556+ specific_args = ("android_specific_args:\n - init=/init\n "
3557+ "- androidboot.console=ttyO2")
3558+ hwpack_config = self.hwpack_base + specific_args
3559+ self.config.from_file(StringIO(hwpack_config))
3560+ expected = 'init=/init androidboot.console=ttyO2'
3561+ self.assertEqual(expected, self.config.android_specific_args)
3562+
3563+ def test_extra_serial_options(self):
3564+ """The field extra_serial_options should be a concatenated string."""
3565+ extra_serial_opts = ("extra_serial_options:\n - console=tty0\n "
3566+ "- console=ttyO2,115200n8")
3567+ hwpack_config = self.hwpack_base + extra_serial_opts
3568+ self.config.from_file(StringIO(hwpack_config))
3569+ expected = 'console=tty0 console=ttyO2,115200n8'
3570+ self.assertEqual(expected, self.config.extra_serial_options)
3571+
3572+ def test_extra_boot_args_options(self):
3573+ """The field extra_boot_args_options should be a concatenated string.
3574+ Testing presence of a field defined in the parent class."""
3575+ extra_boot_args_options = ("extra_boot_args_options:\n "
3576+ "- earlyprintk\n - mem=128M@0\n "
3577+ "- mali.mali_mem=64M@128M\n")
3578+ hwpack_config = self.hwpack_base + extra_boot_args_options
3579+ self.config.from_file(StringIO(hwpack_config))
3580+ expected = 'earlyprintk mem=128M@0 mali.mali_mem=64M@128M'
3581+ self.assertEqual(expected, self.config.extra_boot_args_options)
3582+
3583+ def test_android_mx6(self):
3584+ android_mx6_config = (self.hwpack_base + "bootloader_flavor: "
3585+ "mx6qsabrelite\nextra_boot_args_options:\n - earlyprintk\n"
3586+ " - rootdelay=1\n - fixrtc\n - nocompcache\n - di1_primary\n"
3587+ " - tve\nextra_serial_options:\n - console=%s,115200n8\n"
3588+ "android_specific_args:\n - init=/init\n - "
3589+ "androidboot.console=%s\nkernel_addr: '0x10000000'\n"
3590+ "initrd_addr: '0x12000000'\nload_addr: '0x10008000'\ndtb_addr:"
3591+ " '0x11ff0000'\ndtb_name: board.dtb")
3592+ expected = {
3593+ 'bootargs': 'console=ttymxc0,115200n8 '
3594+ 'rootwait ro earlyprintk rootdelay=1 fixrtc '
3595+ 'nocompcache di1_primary tve init=/init '
3596+ 'androidboot.console=ttymxc0',
3597+ 'bootcmd': 'fatload mmc 0:2 0x10000000 uImage; '
3598+ 'fatload mmc 0:2 0x12000000 uInitrd; '
3599+ 'fatload mmc 0:2 0x11ff0000 board.dtb; '
3600+ 'bootm 0x10000000 0x12000000 0x11ff0000',
3601+ 'fdt_high': '0xffffffff',
3602+ 'initrd_high': '0xffffffff'}
3603+ config = get_board_config('mx6qsabrelite')
3604+ config.from_file(StringIO(android_mx6_config))
3605+ self.assertBootEnv(config, expected)
3606+
3607+ def test_panda(self):
3608+ panda_config = (self.hwpack_base + "bootloader_flavor: omap4_panda\n"
3609+ "dtb_addr: '0x815f0000'\ndtb_name: board.dtb\n"
3610+ "extra_serial_options:\n - console=ttyO2,115200n8\n"
3611+ "extra_boot_args_options:\n - earlyprintk\n"
3612+ " - fixrtc\n - nocompcache\n - vram=48M\n"
3613+ " - omapfb.vram=0:24M,1:24M\n - mem=456M@0x80000000\n"
3614+ " - mem=512M@0xA0000000\nandroid_specific_args:\n"
3615+ " - init=/init\n - androidboot.console=ttyO2")
3616+ # XXX: To fix bug 697824 we have to change class attributes of our
3617+ # OMAP board configs, and some tests do that so to make sure they
3618+ # don't interfere with us we'll reset that before doing anything.
3619+ config = get_board_config('panda')
3620+ config.from_file(StringIO(panda_config))
3621+ expected = {
3622+ 'bootargs': 'console=ttyO2,115200n8 '
3623+ 'rootwait ro earlyprintk fixrtc '
3624+ 'nocompcache vram=48M omapfb.vram=0:24M,1:24M '
3625+ 'mem=456M@0x80000000 mem=512M@0xA0000000 '
3626+ 'init=/init androidboot.console=ttyO2',
3627+ 'bootcmd': 'fatload mmc 0:1 0x80200000 uImage; '
3628+ 'fatload mmc 0:1 0x81600000 uInitrd; '
3629+ 'fatload mmc 0:1 0x815f0000 board.dtb; '
3630+ 'bootm 0x80200000 0x81600000 0x815f0000',
3631+ 'fdt_high': '0xffffffff',
3632+ 'initrd_high': '0xffffffff'}
3633+ self.assertBootEnv(config, expected)
3634+
3635+ def test_android_snowball_sd(self):
3636+ snowball_config = (self.hwpack_base + "boot_script: boot.scr\n"
3637+ "fdt_high: '0x05000000'\ninitrd_addr: '0x05000000'\n"
3638+ "initrd_high: '0x06000000'\nextra_boot_args_options:\n "
3639+ "- earlyprintk\n - mem=128M@0\n - mali.mali_mem=64M@128M\n "
3640+ "- hwmem=168M@192M\n - mem=22M@360M\n - mem_issw=1M@383M\n "
3641+ "- mem=640M@384M\n - vmalloc=500M\nextra_serial_options:\n"
3642+ " - console=ttyAMA2,115200n8\nandroid_specific_args:\n "
3643+ "- init=/init\n - androidboot.console=ttyAMA2\n"
3644+ "dtb_name: board.dtb\ndtb_addr: '0x8000000'")
3645+ config = get_board_config('snowball_sd')
3646+ config.from_file(StringIO(snowball_config))
3647+ expected = {
3648+ 'bootargs': 'console=ttyAMA2,115200n8 '
3649+ 'rootwait ro earlyprintk '
3650+ 'mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
3651+ 'mem=22M@360M mem_issw=1M@383M mem=640M@384M '
3652+ 'vmalloc=500M init=/init androidboot.console=ttyAMA2',
3653+ 'bootcmd': 'fatload mmc 1:1 0x00100000 uImage; '
3654+ 'fatload mmc 1:1 0x05000000 uInitrd; '
3655+ 'fatload mmc 1:1 0x8000000 board.dtb; '
3656+ 'bootm 0x00100000 0x05000000 0x8000000',
3657+ 'fdt_high': '0x05000000',
3658+ 'initrd_high': '0x06000000'}
3659+ self.assertBootEnv(config, expected)
3660+
3661+ def test_android_snowball_emmc(self):
3662+ snowball_config = (self.hwpack_base + "boot_script: boot.scr\n"
3663+ "fdt_high: '0x05000000'\ninitrd_addr: '0x05000000'\n"
3664+ "initrd_high: '0x06000000'\nextra_boot_args_options:\n "
3665+ "- earlyprintk\n - mem=128M@0\n - mali.mali_mem=64M@128M\n "
3666+ "- hwmem=168M@192M\n - mem=22M@360M\n - mem_issw=1M@383M\n "
3667+ "- mem=640M@384M\n - vmalloc=500M\nextra_serial_options:\n"
3668+ " - console=ttyAMA2,115200n8\nandroid_specific_args:\n "
3669+ "- init=/init\n - androidboot.console=ttyAMA2\n"
3670+ "dtb_name: board.dtb\ndtb_addr: '0x8000000'\nmmc_option: '0:2'")
3671+ config = get_board_config('snowball_emmc')
3672+ config.from_file(StringIO(snowball_config))
3673+ expected = {
3674+ 'bootargs': 'console=ttyAMA2,115200n8 '
3675+ 'rootwait ro earlyprintk '
3676+ 'mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
3677+ 'mem=22M@360M mem_issw=1M@383M mem=640M@384M '
3678+ 'vmalloc=500M init=/init androidboot.console=ttyAMA2',
3679+ 'bootcmd': 'fatload mmc 0:2 0x00100000 uImage; '
3680+ 'fatload mmc 0:2 0x05000000 uInitrd; '
3681+ 'fatload mmc 0:2 0x8000000 board.dtb; '
3682+ 'bootm 0x00100000 0x05000000 0x8000000',
3683+ 'fdt_high': '0x05000000',
3684+ 'initrd_high': '0x06000000'}
3685+ self.assertBootEnv(config, expected)
3686+
3687+ def test_android_origen(self):
3688+ origen_config = (self.hwpack_base + "extra_serial_options:\n "
3689+ "- console=tty0\n - console=ttySAC2,115200n8\n"
3690+ "android_specific_args:\n - init=/init\n "
3691+ "- androidboot.console=ttySAC2")
3692+ config = get_board_config('origen')
3693+ config.from_file(StringIO(origen_config))
3694+ expected = {
3695+ 'bootargs': 'console=tty0 console=ttySAC2,115200n8 '
3696+ 'rootwait ro init=/init androidboot.console=ttySAC2',
3697+ 'bootcmd': 'fatload mmc 0:2 0x40007000 uImage; '
3698+ 'fatload mmc 0:2 0x42000000 uInitrd; '
3699+ 'bootm 0x40007000 0x42000000',
3700+ 'fdt_high': '0xffffffff',
3701+ 'initrd_high': '0xffffffff'}
3702+ self.assertBootEnv(config, expected)
3703+
3704+ def test_android_vexpress(self):
3705+ vexpress_config = (self.hwpack_base + "extra_serial_options:\n "
3706+ "- console=tty0\n - console=ttyAMA0,38400n8\n"
3707+ "android_specific_args:\n - init=/init\n "
3708+ "- androidboot.console=ttyAMA0")
3709+ config = get_board_config('vexpress')
3710+ config.from_file(StringIO(vexpress_config))
3711+ expected = {
3712+ 'bootargs': 'console=tty0 console=ttyAMA0,38400n8 '
3713+ 'rootwait ro init=/init androidboot.console=ttyAMA0',
3714+ 'bootcmd': 'fatload mmc 0:1 0x60000000 uImage; '
3715+ 'fatload mmc 0:1 0x62000000 uInitrd; '
3716+ 'bootm 0x60000000 0x62000000',
3717+ 'fdt_high': '0xffffffff',
3718+ 'initrd_high': '0xffffffff'}
3719+ self.assertBootEnv(config, expected)
3720+
3721+ def test_android_mx5(self):
3722+ mx5_config = (self.hwpack_base + "extra_boot_args_options:\n "
3723+ "- earlyprintk\n - rootdelay=1\n - fixrtc\n - nocompcache\n "
3724+ "- di1_primary\n - tve\nextra_serial_options:\n"
3725+ " - console=%s,115200n8\nandroid_specific_args:\n "
3726+ "- init=/init\n - androidboot.console=%s")
3727+ config = get_board_config('mx53loco')
3728+ config.from_file(mx5_config)
3729+ expected = {
3730+ 'bootargs': 'console=ttymxc0,115200n8 '
3731+ 'rootwait ro earlyprintk rootdelay=1 fixrtc '
3732+ 'nocompcache di1_primary tve init=/init '
3733+ 'androidboot.console=ttymxc0',
3734+ 'bootcmd': 'fatload mmc 0:2 0x70000000 uImage; '
3735+ 'fatload mmc 0:2 0x72000000 uInitrd; '
3736+ 'bootm 0x70000000 0x72000000',
3737+ 'fdt_high': '0xffffffff',
3738+ 'initrd_high': '0xffffffff'}
3739+ self.assertBootEnv(config, expected)
3740+
3741+ def assertBootEnv(self, config, expected):
3742+ self.assertEqual(expected, config._get_boot_env(consoles=[]))
3743
3744=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
3745--- linaro_image_tools/media_create/tests/test_media_create.py 2012-10-17 08:59:25 +0000
3746+++ linaro_image_tools/media_create/tests/test_media_create.py 2012-11-20 10:49:03 +0000
3747@@ -36,6 +36,7 @@
3748 from testtools import TestCase
3749
3750 from linaro_image_tools import cmd_runner
3751+from linaro_image_tools.hwpack.handler import HardwarepackHandler
3752 from linaro_image_tools.hwpack.packages import PackageMaker
3753 import linaro_image_tools.media_create
3754 from linaro_image_tools.media_create import (
3755@@ -49,7 +50,6 @@
3756 SECTOR_SIZE,
3757 align_up,
3758 align_partition,
3759- board_configs,
3760 get_plain_boot_script_contents,
3761 make_flashable_env,
3762 install_mx5_boot_loader,
3763@@ -61,12 +61,11 @@
3764 _get_file_matching,
3765 _get_mlo_file,
3766 _run_mkimage,
3767- HardwarepackHandler,
3768 BoardConfig,
3769+ get_board_config,
3770 )
3771 from linaro_image_tools.media_create.android_boards import (
3772 AndroidSnowballEmmcConfig,
3773- android_board_configs,
3774 )
3775 from linaro_image_tools.media_create.chroot_utils import (
3776 copy_file,
3777@@ -427,10 +426,9 @@
3778 linaro_image_tools.media_create.boards, 'HardwarepackHandler',
3779 self.MockHardwarepackHandler))
3780
3781- class config(BoardConfig):
3782- pass
3783- config.set_metadata('ahwpack.tar.gz')
3784- self.assertEquals(None, config.kernel_addr)
3785+ board_conf = BoardConfig()
3786+ board_conf.set_metadata('ahwpack.tar.gz')
3787+ self.assertEquals(None, board_conf.kernel_addr)
3788
3789 def test_sets_kernel_addr(self):
3790 self.useFixture(MockSomethingFixture(
3791@@ -442,10 +440,9 @@
3792 field_to_test: data_to_set,
3793 }
3794
3795- class config(BoardConfig):
3796- pass
3797- config.set_metadata('ahwpack.tar.gz')
3798- self.assertEquals(data_to_set, config.kernel_addr)
3799+ board_conf = BoardConfig()
3800+ board_conf.set_metadata('ahwpack.tar.gz')
3801+ self.assertEquals(data_to_set, board_conf.kernel_addr)
3802
3803 def test_sets_initrd_addr(self):
3804 self.useFixture(MockSomethingFixture(
3805@@ -457,10 +454,9 @@
3806 field_to_test: data_to_set,
3807 }
3808
3809- class config(BoardConfig):
3810- pass
3811- config.set_metadata('ahwpack.tar.gz')
3812- self.assertEquals(data_to_set, config.initrd_addr)
3813+ board_conf = BoardConfig()
3814+ board_conf.set_metadata('ahwpack.tar.gz')
3815+ self.assertEquals(data_to_set, board_conf.initrd_addr)
3816
3817 def test_sets_load_addr(self):
3818 self.useFixture(MockSomethingFixture(
3819@@ -472,10 +468,9 @@
3820 field_to_test: data_to_set,
3821 }
3822
3823- class config(BoardConfig):
3824- pass
3825- config.set_metadata('ahwpack.tar.gz')
3826- self.assertEquals(data_to_set, config.load_addr)
3827+ board_conf = BoardConfig()
3828+ board_conf.set_metadata('ahwpack.tar.gz')
3829+ self.assertEquals(data_to_set, board_conf.load_addr)
3830
3831 def test_sets_serial_tty(self):
3832 self.useFixture(MockSomethingFixture(
3833@@ -487,10 +482,9 @@
3834 field_to_test: data_to_set,
3835 }
3836
3837- class config(BoardConfig):
3838- pass
3839- config.set_metadata('ahwpack.tar.gz')
3840- self.assertEquals(data_to_set, config.serial_tty)
3841+ board_conf = BoardConfig()
3842+ board_conf.set_metadata('ahwpack.tar.gz')
3843+ self.assertEquals(data_to_set, board_conf.serial_tty)
3844
3845 def test_sets_wired_interfaces(self):
3846 self.useFixture(MockSomethingFixture(
3847@@ -502,10 +496,9 @@
3848 field_to_test: data_to_set,
3849 }
3850
3851- class config(BoardConfig):
3852- pass
3853- config.set_metadata('ahwpack.tar.gz')
3854- self.assertEquals(data_to_set, config.wired_interfaces)
3855+ board_conf = BoardConfig()
3856+ board_conf.set_metadata('ahwpack.tar.gz')
3857+ self.assertEquals(data_to_set, board_conf.wired_interfaces)
3858
3859 def test_sets_wireless_interfaces(self):
3860 self.useFixture(MockSomethingFixture(
3861@@ -517,10 +510,9 @@
3862 field_to_test: data_to_set,
3863 }
3864
3865- class config(BoardConfig):
3866- pass
3867- config.set_metadata('ahwpack.tar.gz')
3868- self.assertEquals(data_to_set, config.wireless_interfaces)
3869+ board_conf = BoardConfig()
3870+ board_conf.set_metadata('ahwpack.tar.gz')
3871+ self.assertEquals(data_to_set, board_conf.wireless_interfaces)
3872
3873 def test_sets_mmc_id(self):
3874 self.useFixture(MockSomethingFixture(
3875@@ -532,12 +524,11 @@
3876 field_to_test: data_to_set,
3877 }
3878
3879- class config(BoardConfig):
3880- pass
3881- config.set_metadata('ahwpack.tar.gz')
3882- self.assertEquals(data_to_set, config.mmc_option)
3883- self.assertEquals(0, config.mmc_device_id)
3884- self.assertEquals(0, config.mmc_part_offset)
3885+ board_conf = BoardConfig()
3886+ board_conf.set_metadata('ahwpack.tar.gz')
3887+ self.assertEquals(data_to_set, board_conf.mmc_option)
3888+ self.assertEquals(0, board_conf.mmc_device_id)
3889+ self.assertEquals(0, board_conf.mmc_part_offset)
3890
3891 def test_sets_boot_min_size(self):
3892 self.useFixture(MockSomethingFixture(
3893@@ -551,10 +542,9 @@
3894 field_to_test: data_to_set,
3895 }
3896
3897- class config(BoardConfig):
3898- pass
3899- config.set_metadata('ahwpack.tar.gz')
3900- self.assertEquals(expected, config.BOOT_MIN_SIZE_S)
3901+ board_conf = BoardConfig()
3902+ board_conf.set_metadata('ahwpack.tar.gz')
3903+ self.assertEquals(expected, board_conf.BOOT_MIN_SIZE_S)
3904
3905 def test_sets_root_min_size(self):
3906 self.useFixture(MockSomethingFixture(
3907@@ -568,10 +558,9 @@
3908 field_to_test: data_to_set,
3909 }
3910
3911- class config(BoardConfig):
3912- pass
3913- config.set_metadata('ahwpack.tar.gz')
3914- self.assertEquals(expected, config.ROOT_MIN_SIZE_S)
3915+ board_conf = BoardConfig()
3916+ board_conf.set_metadata('ahwpack.tar.gz')
3917+ self.assertEquals(expected, board_conf.ROOT_MIN_SIZE_S)
3918
3919 def test_sets_loader_min_size(self):
3920 self.useFixture(MockSomethingFixture(
3921@@ -585,10 +574,9 @@
3922 field_to_test: data_to_set,
3923 }
3924
3925- class config(BoardConfig):
3926- pass
3927- config.set_metadata('ahwpack.tar.gz')
3928- self.assertEquals(expected, config.LOADER_MIN_SIZE_S)
3929+ board_conf = BoardConfig()
3930+ board_conf.set_metadata('ahwpack.tar.gz')
3931+ self.assertEquals(expected, board_conf.LOADER_MIN_SIZE_S)
3932
3933 def test_sets_partition_layout_32(self):
3934 self.useFixture(MockSomethingFixture(
3935@@ -600,10 +588,9 @@
3936 field_to_test: data_to_set,
3937 }
3938
3939- class config(BoardConfig):
3940- pass
3941- config.set_metadata('ahwpack.tar.gz')
3942- self.assertEquals(32, config.fat_size)
3943+ board_conf = BoardConfig()
3944+ board_conf.set_metadata('ahwpack.tar.gz')
3945+ self.assertEquals(32, board_conf.fat_size)
3946
3947 def test_sets_partition_layout_16(self):
3948 self.useFixture(MockSomethingFixture(
3949@@ -615,10 +602,9 @@
3950 field_to_test: data_to_set,
3951 }
3952
3953- class config(BoardConfig):
3954- pass
3955- config.set_metadata('ahwpack.tar.gz')
3956- self.assertEquals(16, config.fat_size)
3957+ board_conf = BoardConfig()
3958+ board_conf.set_metadata('ahwpack.tar.gz')
3959+ self.assertEquals(16, board_conf.fat_size)
3960
3961 def test_sets_partition_layout_raises(self):
3962 self.useFixture(MockSomethingFixture(
3963@@ -630,10 +616,9 @@
3964 field_to_test: data_to_set,
3965 }
3966
3967- class config(BoardConfig):
3968- pass
3969+ board_conf = BoardConfig()
3970 self.assertRaises(
3971- AssertionError, config.set_metadata, 'ahwpack.tar.gz')
3972+ AssertionError, board_conf.set_metadata, 'ahwpack.tar.gz')
3973
3974 def test_sets_copy_files(self):
3975 self.useFixture(MockSomethingFixture(
3976@@ -647,10 +632,9 @@
3977 field_to_test: data_to_set,
3978 }
3979
3980- class config(BoardConfig):
3981- pass
3982- config.set_metadata('ahwpack.tar.gz')
3983- self.assertEquals(data_to_set, config.bootloader_copy_files)
3984+ board_conf = BoardConfig()
3985+ board_conf.set_metadata('ahwpack.tar.gz')
3986+ self.assertEquals(data_to_set, board_conf.bootloader_copy_files)
3987
3988
3989 class TestGetMLOFile(TestCaseWithFixtures):
3990@@ -697,7 +681,10 @@
3991
3992
3993 class TestGetSMDKSPL(TestCaseWithFixtures):
3994- config = boards.SMDKV310Config
3995+ def setUp(self):
3996+ super(TestGetSMDKSPL, self).setUp()
3997+ self.config = boards.SMDKV310Config()
3998+ self.config.hwpack_format = '1.0'
3999
4000 def test_no_file_present(self):
4001 tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
4002@@ -729,7 +716,10 @@
4003
4004
4005 class TestGetSMDKUboot(TestCaseWithFixtures):
4006- config = boards.SMDKV310Config
4007+ def setUp(self):
4008+ super(TestGetSMDKUboot, self).setUp()
4009+ self.config = boards.SMDKV310Config()
4010+ self.config.hwpack_format = '1.0'
4011
4012 def test_uses_uboot_flavour(self):
4013 chroot_dir = "chroot"
4014@@ -740,7 +730,10 @@
4015
4016
4017 class TestGetOrigenSPL(TestCaseWithFixtures):
4018- config = boards.OrigenConfig
4019+ def setUp(self):
4020+ super(TestGetOrigenSPL, self).setUp()
4021+ self.config = boards.OrigenConfig()
4022+ self.config.hwpack_format = '1.0'
4023
4024 def test_no_file_present(self):
4025 tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
4026@@ -756,7 +749,7 @@
4027
4028
4029 class TestGetOrigenUboot(TestGetSMDKUboot):
4030- config = boards.OrigenConfig
4031+ config = boards.OrigenConfig()
4032
4033
4034 class TestCreateToc(TestCaseWithFixtures):
4035@@ -778,6 +771,7 @@
4036 '\x05\x00\x00\x00' '\x05\x00\x00\x00' \
4037 'hello' + zero + '\x00\x00\x00'
4038 self.expected = line1 + line2 + line3
4039+ self.board_conf = boards.SnowballEmmcConfig()
4040
4041 def create_files_structure(self, src_data):
4042 ''' Creates the data structure that the tested function
4043@@ -801,7 +795,7 @@
4044 files = self.create_files_structure(correct_data)
4045 filename = os.path.join(self.tempdir, 'toc')
4046 with open(filename, 'w') as f:
4047- boards.SnowballEmmcConfig.create_toc(f, files)
4048+ self.board_conf.create_toc(f, files)
4049 with open(filename, 'r') as f:
4050 actual = f.read()
4051 self.assertEquals(96, len(actual))
4052@@ -816,7 +810,7 @@
4053 files = self.create_files_structure(illegal_name_data)
4054 with open(os.path.join(self.tempdir, 'toc'), 'w') as f:
4055 self.assertRaises(AssertionError,
4056- boards.SnowballEmmcConfig.create_toc,
4057+ self.board_conf.create_toc,
4058 f, files)
4059
4060 def test_create_toc_error_negative_unsigned(self):
4061@@ -826,7 +820,7 @@
4062 files = self.create_files_structure(illegal_unsigned_data)
4063 with open(os.path.join(self.tempdir, 'toc'), 'w') as f:
4064 self.assertRaises(struct.error,
4065- boards.SnowballEmmcConfig.create_toc,
4066+ self.board_conf.create_toc,
4067 f, files)
4068
4069
4070@@ -845,6 +839,8 @@
4071 os.makedirs(self.temp_bootdir_path)
4072 if not os.path.exists(self.temp_configdir_path):
4073 os.makedirs(self.temp_configdir_path)
4074+ self.snowball_config = get_board_config('snowball_emmc')
4075+ self.snowball_config.hwpack_format = HardwarepackHandler.FORMAT_1
4076
4077 def setupFiles(self):
4078 return self.create_test_files(self.temp_bootdir_path)
4079@@ -870,7 +866,7 @@
4080 ('UBOOT_ENV', 'u-boot-env.bin', 0, 0x00C1F000, '10')]
4081 # Create a config file
4082 cfg_file = os.path.join(
4083- path, boards.SnowballEmmcConfig.snowball_startup_files_config)
4084+ path, self.snowball_config.snowball_startup_files_config)
4085 with open(cfg_file, 'w') as f:
4086 for line in src_data:
4087 # Write comments, so we test that the parser can read them
4088@@ -886,8 +882,8 @@
4089 f.write(line[0])
4090 #define the expected values read from the config file
4091 expected = []
4092- ofs = [boards.SnowballEmmcConfig.TOC_SIZE,
4093- boards.SnowballEmmcConfig.TOC_SIZE + len('ISSW'), 0x160000,
4094+ ofs = [self.snowball_config.TOC_SIZE,
4095+ self.snowball_config.TOC_SIZE + len('ISSW'), 0x160000,
4096 0x170000, 0xBA0000, 0xC1F000]
4097 size = [len('ISSW'), len('X-LOADER'), len('MEM_INIT'), \
4098 len('PWR_MGT'), len('NORMAL'), len('UBOOT_ENV')]
4099@@ -906,13 +902,13 @@
4100 def test_get_file_info_relative_path(self):
4101 # Create a config file
4102 cfg_file = os.path.join(self.temp_bootdir_path,
4103- boards.SnowballEmmcConfig.snowball_startup_files_config)
4104+ self.snowball_config.snowball_startup_files_config)
4105 uboot_file = 'u-boot.bin'
4106 with open(cfg_file, 'w') as f:
4107 f.write('%s %s %i %#x %s\n' % ('NORMAL', uboot_file, 0,
4108 0xBA0000, '9'))
4109 with open(os.path.join(self.temp_bootdir_path, uboot_file), 'w') as f:
4110- file_info = boards.SnowballEmmcConfig.get_file_info(
4111+ file_info = self.snowball_config.get_file_info(
4112 self.tempdir, self.temp_bootdir_path)
4113 self.assertEquals(file_info[0]['filename'],
4114 os.path.join(self.temp_bootdir_path, uboot_file))
4115@@ -920,7 +916,7 @@
4116 def test_get_file_info_abs_path(self):
4117 # Create a config file
4118 cfg_file = os.path.join(self.temp_bootdir_path,
4119- boards.SnowballEmmcConfig.snowball_startup_files_config)
4120+ self.snowball_config.snowball_startup_files_config)
4121 uboot_dir = tempfile.mkdtemp(dir=self.tempdir)
4122 uboot_file = os.path.join(uboot_dir, 'u-boot.bin')
4123 uboot_relative_file = uboot_file.replace(self.tempdir, '')
4124@@ -928,19 +924,19 @@
4125 f.write('%s %s %i %#x %s\n' % (
4126 'NORMAL', uboot_relative_file, 0, 0xBA0000, '9'))
4127 with open(uboot_file, 'w') as f:
4128- file_info = boards.SnowballEmmcConfig.get_file_info(
4129+ file_info = self.snowball_config.get_file_info(
4130 self.tempdir, self.temp_bootdir_path)
4131 self.assertEquals(file_info[0]['filename'], uboot_file)
4132
4133 def test_get_file_info_raises(self):
4134 # Create a config file
4135 cfg_file = os.path.join(self.temp_bootdir_path,
4136- boards.SnowballEmmcConfig.snowball_startup_files_config)
4137+ self.snowball_config.snowball_startup_files_config)
4138 with open(cfg_file, 'w') as f:
4139 f.write('%s %s %i %#x %s\n' % ('NORMAL', 'u-boot.bin', 0,
4140 0xBA0000, '9'))
4141 self.assertRaises(
4142- AssertionError, boards.SnowballEmmcConfig.get_file_info,
4143+ AssertionError, self.snowball_config.get_file_info,
4144 self.tempdir, self.temp_bootdir_path)
4145
4146 def test_file_name_size(self):
4147@@ -948,28 +944,28 @@
4148 _, toc_filename = tempfile.mkstemp()
4149 atexit.register(os.unlink, toc_filename)
4150 filedata = 'X'
4151- bytes = boards.SnowballEmmcConfig.TOC_SIZE + 1
4152+ bytes = self.snowball_config.TOC_SIZE + 1
4153 tmpfile = open(toc_filename, 'wb')
4154 for n in xrange(bytes):
4155 tmpfile.write(filedata)
4156 tmpfile.close()
4157 files = self.setupFiles()
4158 self.assertRaises(AssertionError,
4159- boards.SnowballEmmcConfig.install_snowball_boot_loader,
4160+ self.snowball_config.install_snowball_boot_loader,
4161 toc_filename, files, "boot_device_or_file",
4162- boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S)
4163+ self.snowball_config.SNOWBALL_LOADER_START_S)
4164
4165 def test_install_snowball_boot_loader_toc_dont_delete(self):
4166 fixture = self.useFixture(MockCmdRunnerPopenFixture())
4167 toc_filename = self.createTempFileAsFixture()
4168 files = self.setupFiles()
4169- boards.SnowballEmmcConfig.install_snowball_boot_loader(toc_filename,
4170+ self.snowball_config.install_snowball_boot_loader(toc_filename,
4171 files, "boot_device_or_file",
4172- boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S)
4173+ self.snowball_config.SNOWBALL_LOADER_START_S)
4174 expected = [
4175 '%s dd if=%s of=boot_device_or_file bs=512 conv=notrunc' \
4176 ' seek=%s' % (sudo_args, toc_filename,
4177- boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S),
4178+ self.snowball_config.SNOWBALL_LOADER_START_S),
4179 '%s dd if=%s/boot_image_issw.bin of=boot_device_or_file bs=512' \
4180 ' conv=notrunc seek=257' % (sudo_args, self.temp_bootdir_path),
4181 '%s dd if=%s/boot_image_x-loader.bin of=boot_device_or_file' \
4182@@ -990,13 +986,13 @@
4183 fixture = self.useFixture(MockCmdRunnerPopenFixture())
4184 toc_filename = self.createTempFileAsFixture()
4185 files = self.setupFiles()
4186- boards.SnowballEmmcConfig.install_snowball_boot_loader(toc_filename,
4187+ self.snowball_config.install_snowball_boot_loader(toc_filename,
4188 files, "boot_device_or_file",
4189- boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S, True)
4190+ self.snowball_config.SNOWBALL_LOADER_START_S, True)
4191 expected = [
4192 '%s dd if=%s of=boot_device_or_file bs=512 conv=notrunc' \
4193 ' seek=%s' % (sudo_args, toc_filename,
4194- boards.SnowballEmmcConfig.SNOWBALL_LOADER_START_S),
4195+ self.snowball_config.SNOWBALL_LOADER_START_S),
4196 '%s dd if=%s/boot_image_issw.bin of=boot_device_or_file bs=512' \
4197 ' conv=notrunc seek=257' % (sudo_args, self.temp_bootdir_path),
4198 '%s rm %s/boot_image_issw.bin' % (sudo_args,
4199@@ -1026,13 +1022,14 @@
4200 fixture = self.useFixture(MockCmdRunnerPopenFixture())
4201 toc_filename = self.createTempFileAsFixture()
4202 files = self.setupFiles()
4203- AndroidSnowballEmmcConfig.install_snowball_boot_loader(
4204+ board_conf = AndroidSnowballEmmcConfig()
4205+ board_conf.install_snowball_boot_loader(
4206 toc_filename, files, "boot_device_or_file",
4207- AndroidSnowballEmmcConfig.SNOWBALL_LOADER_START_S)
4208+ board_conf.SNOWBALL_LOADER_START_S)
4209 expected = [
4210 '%s dd if=%s of=boot_device_or_file bs=512 conv=notrunc' \
4211 ' seek=%s' % (sudo_args, toc_filename,
4212- AndroidSnowballEmmcConfig.SNOWBALL_LOADER_START_S),
4213+ board_conf.SNOWBALL_LOADER_START_S),
4214 '%s dd if=%s/boot_image_issw.bin of=boot_device_or_file bs=512' \
4215 ' conv=notrunc seek=257' % (sudo_args, self.temp_bootdir_path),
4216 '%s dd if=%s/boot_image_x-loader.bin of=boot_device_or_file' \
4217@@ -1057,11 +1054,11 @@
4218 k_img_file = os.path.join(self.tempdir, 'vmlinuz-1-ux500')
4219 i_img_file = os.path.join(self.tempdir, 'initrd.img-1-ux500')
4220
4221- boot_env = board_configs['snowball_emmc']._get_boot_env(
4222+ boot_env = self.snowball_config._get_boot_env(
4223 is_live=False, is_lowmem=False, consoles=[],
4224 rootfs_id="UUID=test_boot_env_uuid",
4225 i_img_data=None, d_img_data=None)
4226- boards.SnowballEmmcConfig._make_boot_files(boot_env, self.tempdir,
4227+ self.snowball_config._make_boot_files(boot_env, self.tempdir,
4228 self.temp_bootdir_path, 'boot_device_or_file', k_img_file,
4229 i_img_file, None)
4230 expected = [
4231@@ -1105,12 +1102,12 @@
4232 def test_missing_files(self):
4233 '''When the files cannot be read, an IOError should be raised'''
4234 self.assertRaises(IOError,
4235- boards.SnowballEmmcConfig.get_file_info,
4236+ self.snowball_config.get_file_info,
4237 self.tempdir, self.temp_bootdir_path)
4238
4239 def test_normal_case(self):
4240 expected = self.setupFiles()
4241- actual = boards.SnowballEmmcConfig.get_file_info(
4242+ actual = self.snowball_config.get_file_info(
4243 self.tempdir, self.temp_bootdir_path)
4244 self.assertEquals(expected, actual)
4245
4246@@ -1147,8 +1144,8 @@
4247 classmethod(set_appropriate_serial_tty_mock)))
4248
4249 def make_boot_files(self, config):
4250- def _get_kflavor_files_mock(cls, path):
4251- if cls.dtb_name is None:
4252+ def _get_kflavor_files_mock(self, path):
4253+ if self.dtb_name is None:
4254 return (path, path, None)
4255 return (path, path, path)
4256
4257@@ -1159,23 +1156,25 @@
4258 config.make_boot_files('', False, False, [], '', '', '', '')
4259
4260 def test_vexpress_steps(self):
4261- self.make_boot_files(boards.VexpressConfig)
4262+ board_conf = boards.VexpressConfig()
4263+ self.make_boot_files(board_conf)
4264 expected = ['make_uImage', 'make_uInitrd']
4265 self.assertEqual(expected, self.funcs_calls)
4266
4267 def test_vexpress_a9_steps(self):
4268- self.make_boot_files(boards.VexpressA9Config)
4269+ board_conf = boards.VexpressA9Config()
4270+ self.make_boot_files(board_conf)
4271 expected = ['make_uImage', 'make_uInitrd']
4272 self.assertEqual(expected, self.funcs_calls)
4273
4274 def test_mx5_steps(self):
4275- class SomeMx5Config(boards.Mx5Config):
4276- bootloader_flavor = 'bootloader_flavor'
4277- SomeMx5Config.hardwarepack_handler = (
4278+ board_conf = boards.Mx5Config()
4279+ board_conf.bootloader_flavor = 'bootloader_flavor'
4280+ board_conf.hardwarepack_handler = (
4281 TestSetMetadata.MockHardwarepackHandler('ahwpack.tar.gz'))
4282- SomeMx5Config.hardwarepack_handler.get_format = (
4283+ board_conf.hardwarepack_handler.get_format = (
4284 lambda: '1.0')
4285- self.make_boot_files(SomeMx5Config)
4286+ self.make_boot_files(board_conf)
4287 expected = [
4288 'install_mx5_boot_loader', 'make_uImage', 'make_uInitrd',
4289 'make_dtb', 'make_boot_script']
4290@@ -1224,42 +1223,46 @@
4291 self.assertEqual(expected, self.funcs_calls)
4292
4293 def test_ux500_steps(self):
4294- self.make_boot_files(boards.Ux500Config)
4295+ self.make_boot_files(boards.Ux500Config())
4296 expected = ['make_uImage', 'make_uInitrd', 'make_boot_script']
4297 self.assertEqual(expected, self.funcs_calls)
4298
4299 def test_snowball_sd_steps(self):
4300- self.make_boot_files(boards.SnowballSdConfig)
4301+ self.make_boot_files(boards.SnowballSdConfig())
4302 expected = ['make_uImage', 'make_boot_script']
4303 self.assertEqual(expected, self.funcs_calls)
4304
4305 def test_panda_steps(self):
4306- self.mock_set_appropriate_serial_tty(boards.PandaConfig)
4307- self.make_boot_files(boards.PandaConfig)
4308+ board_conf = boards.PandaConfig()
4309+ self.mock_set_appropriate_serial_tty(board_conf)
4310+ self.make_boot_files(board_conf)
4311 expected = [
4312 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd',
4313 'make_dtb', 'make_boot_script', 'make_boot_ini']
4314 self.assertEqual(expected, self.funcs_calls)
4315
4316 def test_beagle_steps(self):
4317- self.mock_set_appropriate_serial_tty(boards.BeagleConfig)
4318- self.make_boot_files(boards.BeagleConfig)
4319+ board_conf = boards.BeagleConfig()
4320+ self.mock_set_appropriate_serial_tty(board_conf)
4321+ self.make_boot_files(board_conf)
4322 expected = [
4323 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd',
4324 'make_dtb', 'make_boot_script', 'make_boot_ini']
4325 self.assertEqual(expected, self.funcs_calls)
4326
4327 def test_igep_steps(self):
4328- self.mock_set_appropriate_serial_tty(boards.IgepConfig)
4329- self.make_boot_files(boards.IgepConfig)
4330+ board_conf = boards.IgepConfig()
4331+ self.mock_set_appropriate_serial_tty(board_conf)
4332+ self.make_boot_files(board_conf)
4333 expected = [
4334 'make_uImage', 'make_uInitrd', 'make_dtb', 'make_boot_script',
4335 'make_boot_ini']
4336 self.assertEqual(expected, self.funcs_calls)
4337
4338 def test_overo_steps(self):
4339- self.mock_set_appropriate_serial_tty(boards.OveroConfig)
4340- self.make_boot_files(boards.OveroConfig)
4341+ board_conf = boards.OveroConfig()
4342+ self.mock_set_appropriate_serial_tty(board_conf)
4343+ self.make_boot_files(board_conf)
4344 expected = [
4345 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd',
4346 'make_dtb', 'make_boot_script', 'make_boot_ini']
4347@@ -1291,20 +1294,20 @@
4348
4349 def test_snowball_config_raises(self):
4350 self.assertRaises(NotImplementedError,
4351- boards.SnowballSdConfig.snowball_config, '')
4352+ boards.SnowballSdConfig().snowball_config, '')
4353
4354 def test_beagle_raw(self):
4355- self.populate_raw_partition(android_boards.AndroidBeagleConfig)
4356+ self.populate_raw_partition(android_boards.AndroidBeagleConfig())
4357 expected = []
4358 self.assertEqual(expected, self.funcs_calls)
4359
4360 def test_panda_raw(self):
4361- self.populate_raw_partition(android_boards.AndroidPandaConfig)
4362+ self.populate_raw_partition(android_boards.AndroidPandaConfig())
4363 expected = []
4364 self.assertEqual(expected, self.funcs_calls)
4365
4366 def test_snowball_sd_raw(self):
4367- self.populate_raw_partition(boards.SnowballSdConfig)
4368+ self.populate_raw_partition(boards.SnowballSdConfig())
4369 expected = []
4370 self.assertEqual(expected, self.funcs_calls)
4371
4372@@ -1329,7 +1332,7 @@
4373 linaro_image_tools.media_create.boards.SnowballEmmcConfig,
4374 'delete_file',
4375 mock_func_creator('delete_file')))
4376- self.populate_raw_partition(boards.SnowballEmmcConfig)
4377+ self.populate_raw_partition(boards.SnowballEmmcConfig())
4378 expected = ['get_file_info', 'create_toc',
4379 'install_snowball_boot_loader', 'delete_file',
4380 'delete_file']
4381@@ -1341,12 +1344,12 @@
4382 self.useFixture(MockSomethingFixture(os.path, 'getsize',
4383 lambda file: 1))
4384
4385- self.populate_raw_partition(boards.SMDKV310Config)
4386+ self.populate_raw_partition(boards.SMDKV310Config())
4387 expected = ['_dd', '_dd', '_dd']
4388 self.assertEqual(expected, self.funcs_calls)
4389
4390 def test_mx53loco_raw(self):
4391- self.populate_raw_partition(boards.Mx53LoCoConfig)
4392+ self.populate_raw_partition(boards.Mx53LoCoConfig())
4393 expected = []
4394 self.assertEqual(expected, self.funcs_calls)
4395
4396@@ -1354,12 +1357,12 @@
4397 self.useFixture(MockSomethingFixture(os.path, 'getsize',
4398 lambda file: 1))
4399
4400- self.populate_raw_partition(boards.OrigenConfig)
4401+ self.populate_raw_partition(boards.OrigenConfig())
4402 expected = ['_dd', '_dd', '_dd']
4403 self.assertEqual(expected, self.funcs_calls)
4404
4405 def test_vexpress_a9_raw(self):
4406- self.populate_raw_partition(boards.VexpressA9Config)
4407+ self.populate_raw_partition(boards.VexpressA9Config())
4408 expected = []
4409 self.assertEqual(expected, self.funcs_calls)
4410
4411@@ -1374,17 +1377,17 @@
4412 config.populate_raw_partition('', '')
4413
4414 def test_beagle_raw(self):
4415- self.populate_raw_partition(android_boards.AndroidBeagleConfig)
4416+ self.populate_raw_partition(android_boards.AndroidBeagleConfig())
4417 expected = []
4418 self.assertEqual(expected, self.funcs_calls)
4419
4420 def test_panda_raw(self):
4421- self.populate_raw_partition(android_boards.AndroidPandaConfig)
4422+ self.populate_raw_partition(android_boards.AndroidPandaConfig())
4423 expected = []
4424 self.assertEqual(expected, self.funcs_calls)
4425
4426 def test_snowball_sd_raw(self):
4427- self.populate_raw_partition(android_boards.AndroidSnowballSdConfig)
4428+ self.populate_raw_partition(android_boards.AndroidSnowballSdConfig())
4429 expected = []
4430 self.assertEqual(expected, self.funcs_calls)
4431
4432@@ -1415,7 +1418,7 @@
4433 android_boards.AndroidSnowballEmmcConfig,
4434 'delete_file',
4435 mock_func_creator('delete_file')))
4436- self.populate_raw_partition(android_boards.AndroidSnowballEmmcConfig)
4437+ self.populate_raw_partition(android_boards.AndroidSnowballEmmcConfig())
4438 expected_calls = ['get_file_info', 'create_toc',
4439 'install_snowball_boot_loader', 'delete_file']
4440 # Test that we copy the u-boot files to the local startupfiles dir.
4441@@ -1435,14 +1438,14 @@
4442 self.useFixture(MockSomethingFixture(os.path, 'getsize',
4443 lambda file: 1))
4444
4445- self.populate_raw_partition(android_boards.AndroidSMDKV310Config)
4446+ self.populate_raw_partition(android_boards.AndroidSMDKV310Config())
4447 expected_calls = []
4448 # Test that we dd the files
4449 self.assertEqual(expected_commands, fixture.mock.commands_executed)
4450 self.assertEqual(expected_calls, self.funcs_calls)
4451
4452 def test_mx53loco_raw(self):
4453- self.populate_raw_partition(android_boards.AndroidMx53LoCoConfig)
4454+ self.populate_raw_partition(android_boards.AndroidMx53LoCoConfig())
4455 expected = []
4456 self.assertEqual(expected, self.funcs_calls)
4457
4458@@ -1457,14 +1460,14 @@
4459 self.useFixture(MockSomethingFixture(os.path, 'getsize',
4460 lambda file: 1))
4461
4462- self.populate_raw_partition(android_boards.AndroidOrigenConfig)
4463+ self.populate_raw_partition(android_boards.AndroidOrigenConfig())
4464 expected = []
4465 # Test that we dd the files
4466 self.assertEqual(expected_commands, fixture.mock.commands_executed)
4467 self.assertEqual(expected, self.funcs_calls)
4468
4469 def test_vexpress_raw(self):
4470- self.populate_raw_partition(android_boards.AndroidVexpressConfig)
4471+ self.populate_raw_partition(android_boards.AndroidVexpressConfig())
4472 expected = []
4473 self.assertEqual(expected, self.funcs_calls)
4474
4475@@ -1505,15 +1508,16 @@
4476
4477 def test_omap_make_boot_files(self):
4478 self.set_appropriate_serial_tty_called = False
4479- self.mock_set_appropriate_serial_tty(board_configs['beagle'])
4480+ board_conf = get_board_config('beagle')
4481+ self.mock_set_appropriate_serial_tty(board_conf)
4482 self.useFixture(MockSomethingFixture(
4483- boards.BoardConfig, 'make_boot_files',
4484+ board_conf, 'make_boot_files',
4485 classmethod(lambda *args: None)))
4486 # We don't need to worry about what's passed to make_boot_files()
4487 # because we mock the method which does the real work above and here
4488 # we're only interested in ensuring that OmapConfig.make_boot_files()
4489 # calls set_appropriate_serial_tty().
4490- board_configs['beagle'].make_boot_files(
4491+ board_conf.make_boot_files(
4492 None, None, None, None, None, None, None, None)
4493 self.assertTrue(
4494 self.set_appropriate_serial_tty_called,
4495@@ -1522,17 +1526,17 @@
4496 def test_omap_make_boot_files_v2(self):
4497 self.set_appropriate_serial_tty_called = False
4498
4499- class config(boards.BeagleConfig):
4500- hwpack_format = HardwarepackHandler.FORMAT_2
4501- self.mock_set_appropriate_serial_tty(config)
4502+ board_conf = boards.BeagleConfig()
4503+ board_conf.hwpack_format = HardwarepackHandler.FORMAT_2
4504+ self.mock_set_appropriate_serial_tty(board_conf)
4505 self.useFixture(MockSomethingFixture(
4506- boards.BoardConfig, 'make_boot_files',
4507+ board_conf, 'make_boot_files',
4508 classmethod(lambda *args: None)))
4509 # We don't need to worry about what's passed to make_boot_files()
4510 # because we mock the method which does the real work above and here
4511 # we're only interested in ensuring that OmapConfig.make_boot_files()
4512 # does not call set_appropriate_serial_tty().
4513- config.make_boot_files(
4514+ board_conf.make_boot_files(
4515 None, None, None, None, None, None, None, None)
4516 self.assertFalse(
4517 self.set_appropriate_serial_tty_called,
4518@@ -1543,149 +1547,173 @@
4519 boot_dir = os.path.join(tempdir, 'boot')
4520 os.makedirs(boot_dir)
4521 open(os.path.join(boot_dir, 'vmlinuz-2.6.35-23-foo'), 'w').close()
4522- boards.BeagleConfig.set_appropriate_serial_tty(tempdir)
4523- self.assertEquals('ttyS2', boards.BeagleConfig.serial_tty)
4524+ board_conf = boards.BeagleConfig()
4525+ board_conf.hwpack_format = '1.0'
4526+ board_conf.set_appropriate_serial_tty(tempdir)
4527+ self.assertEquals('ttyS2', board_conf.serial_tty)
4528
4529 def test_set_appropriate_serial_tty_new_kernel(self):
4530 tempdir = self.useFixture(CreateTempDirFixture()).tempdir
4531 boot_dir = os.path.join(tempdir, 'boot')
4532 os.makedirs(boot_dir)
4533 open(os.path.join(boot_dir, 'vmlinuz-2.6.36-13-foo'), 'w').close()
4534- boards.BeagleConfig.set_appropriate_serial_tty(tempdir)
4535- self.assertEquals('ttyO2', boards.BeagleConfig.serial_tty)
4536+ board_conf = boards.BeagleConfig()
4537+ board_conf.hwpack_format = '1.0'
4538+ board_conf.set_appropriate_serial_tty(tempdir)
4539+ self.assertEquals('ttyO2', board_conf.serial_tty)
4540
4541 def test_set_appropriate_serial_tty_three_dot_oh_kernel(self):
4542 tempdir = self.useFixture(CreateTempDirFixture()).tempdir
4543 boot_dir = os.path.join(tempdir, 'boot')
4544 os.makedirs(boot_dir)
4545 open(os.path.join(boot_dir, 'vmlinuz-3.0-13-foo'), 'w').close()
4546- boards.BeagleConfig.set_appropriate_serial_tty(tempdir)
4547- self.assertEquals('ttyO2', boards.BeagleConfig.serial_tty)
4548+ board_conf = boards.BeagleConfig()
4549+ board_conf.hwpack_format = '1.0'
4550+ board_conf.set_appropriate_serial_tty(tempdir)
4551+ self.assertEquals('ttyO2', board_conf.serial_tty)
4552
4553
4554 class TestGetSfdiskCmd(TestCase):
4555
4556+ def set_up_config(self, config):
4557+ config.hwpack_format = '1.0'
4558+
4559 def test_default(self):
4560+ board_conf = BoardConfig()
4561+ self.set_up_config(board_conf)
4562 self.assertEqual(
4563- '63,106432,0x0C,*\n106496,,,-',
4564- boards.BoardConfig.get_sfdisk_cmd())
4565+ '63,106432,0x0C,*\n106496,,,-', board_conf.get_sfdisk_cmd())
4566
4567 def test_default_aligned(self):
4568+ board_conf = BoardConfig()
4569+ self.set_up_config(board_conf)
4570 self.assertEqual(
4571 '8192,106496,0x0C,*\n114688,,,-',
4572- boards.BoardConfig.get_sfdisk_cmd(should_align_boot_part=True))
4573+ board_conf.get_sfdisk_cmd(should_align_boot_part=True))
4574
4575 def test_mx5(self):
4576+ board_conf = boards.Mx5Config()
4577+ board_conf.hwpack_format = '1.0'
4578 self.assertEqual(
4579 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
4580- boards.Mx5Config.get_sfdisk_cmd())
4581+ board_conf.get_sfdisk_cmd())
4582
4583 def test_snowball_sd(self):
4584+ board_conf = boards.SnowballSdConfig()
4585+ self.set_up_config(board_conf)
4586 self.assertEqual(
4587- '63,106432,0x0C,*\n106496,,,-',
4588- boards.SnowballSdConfig.get_sfdisk_cmd())
4589+ '63,106432,0x0C,*\n106496,,,-', board_conf.get_sfdisk_cmd())
4590
4591 def test_snowball_emmc(self):
4592+ board_conf = boards.SnowballEmmcConfig()
4593+ self.set_up_config(board_conf)
4594 self.assertEqual(
4595 '256,7936,0xDA\n8192,106496,0x0C,*\n114688,,,-',
4596- boards.SnowballEmmcConfig.get_sfdisk_cmd())
4597+ board_conf.get_sfdisk_cmd())
4598
4599 def test_smdkv310(self):
4600+ board_conf = get_board_config('smdkv310')
4601+ self.set_up_config(board_conf)
4602 self.assertEquals(
4603 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
4604- board_configs['smdkv310'].get_sfdisk_cmd())
4605+ board_conf.get_sfdisk_cmd())
4606
4607 def test_origen(self):
4608+ board_conf = get_board_config('origen')
4609+ self.set_up_config(board_conf)
4610 self.assertEquals(
4611 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
4612- board_configs['origen'].get_sfdisk_cmd())
4613+ board_conf.get_sfdisk_cmd())
4614
4615 def test_panda_android(self):
4616 self.assertEqual(
4617 '63,270272,0x0C,*\n270336,1048576,L\n1318912,524288,L\n'
4618 '1843200,-,E\n1843200,1048576,L\n2891776,,,-',
4619- android_boards.AndroidPandaConfig.get_sfdisk_cmd())
4620+ android_boards.AndroidPandaConfig().get_sfdisk_cmd())
4621
4622 def test_origen_android(self):
4623 self.assertEqual(
4624 '1,8191,0xDA\n8253,270274,0x0C,*\n278528,1048576,L\n'
4625 '1327104,-,E\n1327104,524288,L\n1851392,1048576,L\n2899968,,,-',
4626- android_boards.AndroidOrigenConfig.get_sfdisk_cmd())
4627+ android_boards.AndroidOrigenConfig().get_sfdisk_cmd())
4628
4629 def test_snowball_emmc_android(self):
4630 self.assertEqual(
4631 '256,7936,0xDA\n8192,262144,0x0C,*\n270336,1048576,L\n'
4632 '1318912,-,E\n1318912,524288,L\n1843200,1048576,L\n2891776,,,-',
4633- android_boards.AndroidSnowballEmmcConfig.get_sfdisk_cmd())
4634+ android_boards.AndroidSnowballEmmcConfig().get_sfdisk_cmd())
4635
4636 def test_vexpress_android(self):
4637 self.assertEqual(
4638 '63,270272,0x0E,*\n270336,1048576,L\n1318912,524288,L\n'
4639 '1843200,-,E\n1843200,1048576,L\n2891776,,,-',
4640- android_boards.AndroidVexpressConfig.get_sfdisk_cmd())
4641+ android_boards.AndroidVexpressConfig().get_sfdisk_cmd())
4642
4643 def test_mx5_android(self):
4644 self.assertEqual(
4645 '1,8191,0xDA\n8192,262144,0x0C,*\n270336,1048576,L\n'
4646 '1318912,-,E\n1318912,524288,L\n1843200,1048576,L\n2891776,,,-',
4647- android_boards.AndroidMx53LoCoConfig.get_sfdisk_cmd())
4648+ android_boards.AndroidMx53LoCoConfig().get_sfdisk_cmd())
4649
4650 def test_mx6_android(self):
4651 self.assertEqual(
4652 '1,8191,0xDA\n8192,262144,0x0C,*\n270336,1048576,L\n'
4653 '1318912,-,E\n1318912,524288,L\n1843200,1048576,L\n2891776,,,-',
4654- android_boards.AndroidMx6QSabreliteConfig.get_sfdisk_cmd())
4655+ android_boards.AndroidMx6QSabreliteConfig().get_sfdisk_cmd())
4656
4657
4658 class TestGetSfdiskCmdV2(TestCase):
4659
4660 def test_mx5(self):
4661- class config(boards.Mx5Config):
4662- partition_layout = 'reserved_bootfs_rootfs'
4663+ board_conf = boards.Mx5Config()
4664+ board_conf.partition_layout = 'reserved_bootfs_rootfs'
4665 self.assertEqual(
4666 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
4667- config.get_sfdisk_cmd())
4668+ board_conf.get_sfdisk_cmd())
4669
4670 def test_snowball_sd(self):
4671- class config(boards.SnowballSdConfig):
4672- partition_layout = 'bootfs_rootfs'
4673+ board_conf = boards.SnowballSdConfig()
4674+ board_conf.partition_layout = 'bootfs_rootfs'
4675 self.assertEqual(
4676 '63,106432,0x0C,*\n106496,,,-',
4677- config.get_sfdisk_cmd())
4678+ board_conf.get_sfdisk_cmd())
4679
4680 def test_snowball_emmc(self):
4681- class config(boards.SnowballEmmcConfig):
4682- partition_layout = 'reserved_bootfs_rootfs'
4683- LOADER_START_S = (128 * 1024) / SECTOR_SIZE
4684+ board_conf = boards.SnowballEmmcConfig()
4685+ board_conf.partition_layout = 'reserved_bootfs_rootfs'
4686+ board_conf.loader_start_s = (128 * 1024) / SECTOR_SIZE
4687 self.assertEqual(
4688 '256,7936,0xDA\n8192,106496,0x0C,*\n114688,,,-',
4689- config.get_sfdisk_cmd())
4690+ board_conf.get_sfdisk_cmd())
4691
4692 def test_smdkv310(self):
4693- class config(board_configs['smdkv310']):
4694- partition_layout = 'reserved_bootfs_rootfs'
4695- LOADER_MIN_SIZE_S = (boards.BoardConfig.SAMSUNG_V310_BL2_START +
4696- boards.BoardConfig.SAMSUNG_V310_BL2_LEN -
4697- boards.BoardConfig.SAMSUNG_V310_BL1_START)
4698+ board_conf = get_board_config('smdkv310')
4699+ board_conf.partition_layout = 'reserved_bootfs_rootfs'
4700+ board_conf.LOADER_MIN_SIZE_S = (
4701+ board_conf.samsung_v310_bl2_start +
4702+ board_conf.samsung_v310_bl2_len -
4703+ board_conf.samsung_v310_bl1_start)
4704 self.assertEquals(
4705 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
4706- config.get_sfdisk_cmd())
4707+ board_conf.get_sfdisk_cmd())
4708
4709 def test_origen(self):
4710- class config(board_configs['origen']):
4711- partition_layout = 'reserved_bootfs_rootfs'
4712- LOADER_MIN_SIZE_S = (boards.BoardConfig.SAMSUNG_V310_BL2_START +
4713- boards.BoardConfig.SAMSUNG_V310_BL2_LEN -
4714- boards.BoardConfig.SAMSUNG_V310_BL1_START)
4715+ board_conf = get_board_config('origen')
4716+ board_conf.partition_layout = 'reserved_bootfs_rootfs'
4717+ board_conf.LOADER_MIN_SIZE_S = (
4718+ board_conf.samsung_v310_bl2_start +
4719+ board_conf.samsung_v310_bl2_len -
4720+ board_conf.samsung_v310_bl1_start)
4721 self.assertEquals(
4722 '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
4723- config.get_sfdisk_cmd())
4724+ board_conf.get_sfdisk_cmd())
4725
4726
4727 class TestGetBootCmd(TestCase):
4728
4729 def test_vexpress(self):
4730- boot_commands = board_configs['vexpress']._get_boot_env(
4731+ board_conf = get_board_config('vexpress')
4732+ boot_commands = board_conf._get_boot_env(
4733 is_live=False, is_lowmem=False, consoles=['ttyXXX'],
4734 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
4735 expected = {
4736@@ -1699,7 +1727,8 @@
4737 self.assertEqual(expected, boot_commands)
4738
4739 def test_vexpress_a9(self):
4740- boot_commands = board_configs['vexpress-a9']._get_boot_env(
4741+ board_conf = get_board_config('vexpress-a9')
4742+ boot_commands = board_conf._get_boot_env(
4743 is_live=False, is_lowmem=False, consoles=['ttyXXX'],
4744 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
4745 expected = {
4746@@ -1713,7 +1742,8 @@
4747 self.assertEqual(expected, boot_commands)
4748
4749 def test_mx51(self):
4750- boot_commands = boards.Mx51Config._get_boot_env(
4751+ board_conf = boards.Mx51Config()
4752+ boot_commands = board_conf._get_boot_env(
4753 is_live=False, is_lowmem=False, consoles=[],
4754 rootfs_id="UUID=deadbeef", i_img_data="initrd",
4755 d_img_data="mx51.dtb")
4756@@ -1729,7 +1759,8 @@
4757 self.assertEqual(expected, boot_commands)
4758
4759 def test_smdkv310(self):
4760- boot_commands = board_configs['smdkv310']._get_boot_env(
4761+ board_conf = get_board_config('smdkv310')
4762+ boot_commands = board_conf._get_boot_env(
4763 is_live=False, is_lowmem=False, consoles=[],
4764 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
4765 expected = {
4766@@ -1745,7 +1776,8 @@
4767 self.assertEqual(expected, boot_commands)
4768
4769 def test_origen(self):
4770- boot_commands = board_configs['origen']._get_boot_env(
4771+ board_conf = get_board_config('origen')
4772+ boot_commands = board_conf._get_boot_env(
4773 is_live=False, is_lowmem=False, consoles=[],
4774 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
4775 expected = {
4776@@ -1759,7 +1791,8 @@
4777 self.assertEqual(expected, boot_commands)
4778
4779 def test_ux500(self):
4780- boot_commands = board_configs['ux500']._get_boot_env(
4781+ board_conf = get_board_config('ux500')
4782+ boot_commands = board_conf._get_boot_env(
4783 is_live=False, is_lowmem=False, consoles=[],
4784 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
4785 expected = {
4786@@ -1777,7 +1810,8 @@
4787 self.assertEqual(expected, boot_commands)
4788
4789 def test_snowball_emmc(self):
4790- boot_commands = board_configs['snowball_emmc']._get_boot_env(
4791+ board_conf = get_board_config('snowball_emmc')
4792+ boot_commands = board_conf._get_boot_env(
4793 is_live=False, is_lowmem=False, consoles=[],
4794 rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
4795 expected = {
4796@@ -1798,7 +1832,7 @@
4797 # XXX: To fix bug 697824 we have to change class attributes of our
4798 # OMAP board configs, and some tests do that so to make sure they
4799 # don't interfere with us we'll reset that before doing anything.
4800- config = board_configs['panda']
4801+ config = get_board_config('panda')
4802 config.serial_tty = config._serial_tty
4803 boot_commands = config._get_boot_env(
4804 is_live=False, is_lowmem=False, consoles=[],
4805@@ -1821,7 +1855,7 @@
4806 # XXX: To fix bug 697824 we have to change class attributes of our
4807 # OMAP board configs, and some tests do that so to make sure they
4808 # don't interfere with us we'll reset that before doing anything.
4809- config = board_configs['beagle']
4810+ config = get_board_config('beagle')
4811 config.serial_tty = config._serial_tty
4812 boot_commands = config._get_boot_env(
4813 is_live=False, is_lowmem=False, consoles=[],
4814@@ -1844,7 +1878,7 @@
4815 # XXX: To fix bug 697824 we have to change class attributes of our
4816 # OMAP board configs, and some tests do that so to make sure they
4817 # don't interfere with us we'll reset that before doing anything.
4818- config = boards.IgepConfig
4819+ config = boards.IgepConfig()
4820 config.serial_tty = config._serial_tty
4821 boot_cmd = config._get_boot_env(
4822 is_live=False, is_lowmem=False, consoles=[],
4823@@ -1867,7 +1901,7 @@
4824 # XXX: To fix bug 697824 we have to change class attributes of our
4825 # OMAP board configs, and some tests do that so to make sure they
4826 # don't interfere with us we'll reset that before doing anything.
4827- config = board_configs['overo']
4828+ config = get_board_config('overo')
4829 config.serial_tty = config._serial_tty
4830 boot_commands = config._get_boot_env(
4831 is_live=False, is_lowmem=False, consoles=[],
4832@@ -1890,12 +1924,15 @@
4833
4834 class TestExtraBootCmd(TestCaseWithFixtures):
4835
4836+ def setUp(self):
4837+ super(TestExtraBootCmd, self).setUp()
4838+ self.board_conf = BoardConfig()
4839+
4840 def test_extra_boot_args_options_is_picked_by_get_boot_env(self):
4841 boot_args = 'whatever'
4842
4843- class config(BoardConfig):
4844- extra_boot_args_options = boot_args
4845- boot_commands = config._get_boot_env(
4846+ self.board_conf.extra_boot_args_options = boot_args
4847+ boot_commands = self.board_conf._get_boot_env(
4848 is_live=False, is_lowmem=False, consoles=['ttyXXX'],
4849 rootfs_id="UUID=deadbeef", i_img_data=None, d_img_data=None)
4850 expected = (
4851@@ -1905,28 +1942,25 @@
4852 def test_passing_None_to_add_boot_args(self):
4853 boot_args = 'extra-args'
4854
4855- class config(BoardConfig):
4856- extra_boot_args_options = boot_args
4857- config.add_boot_args(None)
4858- self.assertEqual(boot_args, config.extra_boot_args_options)
4859+ self.board_conf.extra_boot_args_options = boot_args
4860+ self.board_conf.add_boot_args(None)
4861+ self.assertEqual(boot_args, self.board_conf.extra_boot_args_options)
4862
4863 def test_passing_string_to_add_boot_args(self):
4864 boot_args = 'extra-args'
4865 extra_args = 'user-args'
4866
4867- class config(BoardConfig):
4868- extra_boot_args_options = boot_args
4869- config.add_boot_args(extra_args)
4870+ self.board_conf.extra_boot_args_options = boot_args
4871+ self.board_conf.add_boot_args(extra_args)
4872 self.assertEqual(
4873- "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
4874+ "%s %s" % (boot_args, extra_args),
4875+ self.board_conf.extra_boot_args_options)
4876
4877 def test_passing_string_to_add_boot_args_with_no_default_extra_args(self):
4878 extra_args = 'user-args'
4879
4880- class config(BoardConfig):
4881- extra_boot_args_options = None
4882- config.add_boot_args(extra_args)
4883- self.assertEqual(extra_args, config.extra_boot_args_options)
4884+ self.board_conf.add_boot_args(extra_args)
4885+ self.assertEqual(extra_args, self.board_conf.extra_boot_args_options)
4886
4887 def test_add_boot_args_from_file(self):
4888 boot_args = 'extra-args'
4889@@ -1935,19 +1969,18 @@
4890 with open(boot_arg_path, 'w') as boot_arg_file:
4891 boot_arg_file.write(extra_args)
4892
4893- class config(BoardConfig):
4894- extra_boot_args_options = boot_args
4895- config.add_boot_args_from_file(boot_arg_path)
4896+ self.board_conf.extra_boot_args_options = boot_args
4897+ self.board_conf.add_boot_args_from_file(boot_arg_path)
4898 self.assertEqual(
4899- "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
4900+ "%s %s" % (boot_args, extra_args),
4901+ self.board_conf.extra_boot_args_options)
4902
4903 def test_passing_None_to_add_boot_args_from_file(self):
4904 boot_args = 'extra-args'
4905
4906- class config(BoardConfig):
4907- extra_boot_args_options = boot_args
4908- config.add_boot_args_from_file(None)
4909- self.assertEqual(boot_args, config.extra_boot_args_options)
4910+ self.board_conf.extra_boot_args_options = boot_args
4911+ self.board_conf.add_boot_args_from_file(None)
4912+ self.assertEqual(boot_args, self.board_conf.extra_boot_args_options)
4913
4914 def test_add_boot_args_from_file_strips_whitespace_from_file(self):
4915 boot_args = 'extra-args'
4916@@ -1956,122 +1989,11 @@
4917 with open(boot_arg_path, 'w') as boot_arg_file:
4918 boot_arg_file.write('\n\n \t ' + extra_args + ' \n\n')
4919
4920- class config(BoardConfig):
4921- extra_boot_args_options = boot_args
4922- config.add_boot_args_from_file(boot_arg_path)
4923+ self.board_conf.extra_boot_args_options = boot_args
4924+ self.board_conf.add_boot_args_from_file(boot_arg_path)
4925 self.assertEqual(
4926- "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
4927-
4928-
4929-class TestGetBootCmdAndroid(TestCase):
4930-
4931- def test_panda(self):
4932- # XXX: To fix bug 697824 we have to change class attributes of our
4933- # OMAP board configs, and some tests do that so to make sure they
4934- # don't interfere with us we'll reset that before doing anything.
4935- config = android_board_configs['panda']
4936- config.serial_tty = config._serial_tty
4937- expected = {
4938- 'bootargs': 'console=ttyO2,115200n8 '
4939- 'rootwait ro earlyprintk fixrtc '
4940- 'nocompcache vram=48M omapfb.vram=0:24M,1:24M '
4941- 'mem=456M@0x80000000 mem=512M@0xA0000000 '
4942- 'init=/init androidboot.console=ttyO2',
4943- 'bootcmd': 'fatload mmc 0:1 0x80200000 uImage; '
4944- 'fatload mmc 0:1 0x81600000 uInitrd; '
4945- 'fatload mmc 0:1 0x815f0000 board.dtb; '
4946- 'bootm 0x80200000 0x81600000 0x815f0000',
4947- 'fdt_high': '0xffffffff',
4948- 'initrd_high': '0xffffffff'}
4949- self.assertBootEnv(config, expected)
4950-
4951- def test_android_snowball_sd(self):
4952- expected = {
4953- 'bootargs': 'console=ttyAMA2,115200n8 '
4954- 'rootwait ro earlyprintk '
4955- 'mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
4956- 'mem=22M@360M mem_issw=1M@383M mem=640M@384M '
4957- 'vmalloc=500M init=/init androidboot.console=ttyAMA2',
4958- 'bootcmd': 'fatload mmc 1:1 0x00100000 uImage; '
4959- 'fatload mmc 1:1 0x05000000 uInitrd; '
4960- 'fatload mmc 1:1 0x8000000 board.dtb; '
4961- 'bootm 0x00100000 0x05000000 0x8000000',
4962- 'fdt_high': '0x05000000',
4963- 'initrd_high': '0x06000000'}
4964- self.assertBootEnv(
4965- android_boards.AndroidSnowballSdConfig, expected)
4966-
4967- def test_android_snowball_emmc(self):
4968- expected = {
4969- 'bootargs': 'console=ttyAMA2,115200n8 '
4970- 'rootwait ro earlyprintk '
4971- 'mem=128M@0 mali.mali_mem=64M@128M hwmem=168M@192M '
4972- 'mem=22M@360M mem_issw=1M@383M mem=640M@384M '
4973- 'vmalloc=500M init=/init androidboot.console=ttyAMA2',
4974- 'bootcmd': 'fatload mmc 0:2 0x00100000 uImage; '
4975- 'fatload mmc 0:2 0x05000000 uInitrd; '
4976- 'fatload mmc 0:2 0x8000000 board.dtb; '
4977- 'bootm 0x00100000 0x05000000 0x8000000',
4978- 'fdt_high': '0x05000000',
4979- 'initrd_high': '0x06000000'}
4980- self.assertBootEnv(
4981- android_boards.AndroidSnowballEmmcConfig, expected)
4982-
4983- def test_android_origen(self):
4984- expected = {
4985- 'bootargs': 'console=tty0 console=ttySAC2,115200n8 '
4986- 'rootwait ro init=/init androidboot.console=ttySAC2',
4987- 'bootcmd': 'fatload mmc 0:2 0x40007000 uImage; '
4988- 'fatload mmc 0:2 0x42000000 uInitrd; '
4989- 'bootm 0x40007000 0x42000000',
4990- 'fdt_high': '0xffffffff',
4991- 'initrd_high': '0xffffffff'}
4992- self.assertBootEnv(
4993- android_boards.AndroidOrigenConfig, expected)
4994-
4995- def test_android_vexpress(self):
4996- expected = {
4997- 'bootargs': 'console=tty0 console=ttyAMA0,38400n8 '
4998- 'rootwait ro init=/init androidboot.console=ttyAMA0',
4999- 'bootcmd': 'fatload mmc 0:1 0x60000000 uImage; '
5000- 'fatload mmc 0:1 0x62000000 uInitrd; '
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches