Merge lp:~milo/linaro-image-tools/boards-refactoring into lp:linaro-image-tools/11.11

Proposed by Milo Casagrande
Status: Merged
Merged at revision: 596
Proposed branch: lp:~milo/linaro-image-tools/boards-refactoring
Merge into: lp:linaro-image-tools/11.11
Prerequisite: lp:~milo/linaro-image-tools/hwpack-handler
Diff against target: 2224 lines (+773/-771)
2 files modified
linaro-media-create (+3/-3)
linaro_image_tools/media_create/boards.py (+770/-768)
To merge this branch: bzr merge lp:~milo/linaro-image-tools/boards-refactoring
Reviewer Review Type Date Requested Status
Paul Sokolovsky Approve
linaro-image-tools maintainers Pending
Review via email: mp+138228@code.launchpad.net

Commit message

Boards class refactoring and clean-up.

Description of the change

Second, and a little big, merge request.

This is the initial refactoring work of the boards module moving from class methods to instance methods.
Some code needs further clean-up. In this branch tests have not been fixed.

To post a comment you must log in.
592. By Milo Casagrande

Merged hwpack-handler into boards-refactoring.

593. By Milo Casagrande

Merged from trunk.

594. By Milo Casagrande

Readedd wrongly removed attribute.

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

No reason was given for going from class to instance attributes, neither in commit message, nor in MR. Why would that matter? And character content of changes is massive, typo can lurk in easily. Merging this without passing tests is a bit brave IMHO.

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

> No reason was given for going from class to instance attributes, neither in
> commit message, nor in MR. Why would that matter?

You are right, I just discussed this with Danilo.
The problem is due to the introduction of the Android hwpack: a config file that needs to be parsed, and whose values have to be stored in the already defined board classes (both in AndrodiBoardConfig and in BoardConfig, since the former inherits from the latter and uses methods defined in its own and also from the parent one).

The problem I had with the first easy implementation (just parse the file and use everything as it was), was that it was not working, and tests were failing simply because the values were not correctly stored and the "default" ones were used. After a little bit of investigation and trying with different approaches, the "easiest" solution would have been to switch to instance attributes and methods instead of class based ones.

This is due to the fact that I wanted to have an easy way to set-up the attribute values, moslty using getattr and setattr, that work only with instances, not classes. In the old code, the attribute or properties where custom-defined as "classproperty", something that python does not have natively: keeping that approach would have meant an hack to be able to properly set the "classproperty" (not really an hack, but something that doesn't feel natual and definitely not easy to implement: we would have had to use "metaclasses"), since the get part is the only one to work correctly, and defining a class-based setter is close to impossible.

> And character content of
> changes is massive, typo can lurk in easily. Merging this without passing
> tests is a bit brave IMHO.

You are right, but if I fix the tests in the same MP, it will be even bigger than it is now (and there will be that complaint :-P). The tests have been fixed and the branches should be applied one on top of the other until the last one. I know it is sub-optimal, but at least changes have been split out into "smaller" review chunks (even if they result in more than 2000 lines). If I put the test fixes here, I will add almost 3000 more lines.

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

Thanks for explanation, makes sense to clean up that mess.

If tests are updated in following merge and pass, then it looks good.

review: Approve
595. By Milo Casagrande

Merged from trunk.

596. By Milo Casagrande

Refactored OrigenQuad to be an instance.

597. By Milo Casagrande

Merged from trunk.

598. By Milo Casagrande

Merged from trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro-media-create'
2--- linaro-media-create 2012-10-22 06:57:20 +0000
3+++ linaro-media-create 2012-12-27 15:00:29 +0000
4@@ -25,7 +25,7 @@
5
6 from linaro_image_tools import cmd_runner
7
8-from linaro_image_tools.media_create.boards import board_configs
9+from linaro_image_tools.media_create.boards import get_board_config
10 from linaro_image_tools.media_create.check_device import (
11 confirm_device_selection_and_ensure_it_is_ready)
12 from linaro_image_tools.media_create.chroot_utils import (
13@@ -131,9 +131,9 @@
14 logger.error(e.value)
15 sys.exit(1)
16
17- board_config = board_configs[args.dev]
18+ board_config = get_board_config(args.dev)
19 board_config.set_metadata(args.hwpacks, args.bootloader, args.dev)
20- board_config.set_board(args.dev)
21+ board_config.board(args.dev)
22 board_config.add_boot_args(args.extra_boot_args)
23 board_config.add_boot_args_from_file(args.extra_boot_args_file)
24
25
26=== modified file 'linaro_image_tools/media_create/boards.py'
27--- linaro_image_tools/media_create/boards.py 2012-12-23 12:49:02 +0000
28+++ linaro_image_tools/media_create/boards.py 2012-12-27 15:00:29 +0000
29@@ -24,24 +24,59 @@
30 board_configs at the bottom of this file.
31 """
32
33+from binascii import crc32
34+from parted import Device
35 import atexit
36 import glob
37+import logging
38 import os
39 import re
40+import string
41+import struct
42 import tempfile
43-import struct
44-from binascii import crc32
45-import string
46-import logging
47-
48-from parted import Device
49
50 from linaro_image_tools import cmd_runner
51
52+from linaro_image_tools.hwpack.handler import HardwarepackHandler
53 from linaro_image_tools.media_create.partitions import (
54- partition_mounted, SECTOR_SIZE, register_loopback)
55+ SECTOR_SIZE,
56+ partition_mounted,
57+ register_loopback,
58+ )
59
60-from linaro_image_tools.hwpack.handler import HardwarepackHandler
61+from linaro_image_tools.hwpack.hwpack_fields import (
62+ BOOTFS,
63+ BOOTFS16,
64+ BOOT_MIN_SIZE_FIELD,
65+ BOOT_SCRIPT_FIELD,
66+ DTB_ADDR_FIELD,
67+ DTB_FILES_FIELD,
68+ DTB_FILE_FIELD,
69+ ENV_DD_FIELD,
70+ EXTRA_BOOT_OPTIONS_FIELD,
71+ EXTRA_SERIAL_OPTIONS_FIELD,
72+ INITRD_ADDR_FIELD,
73+ KERNEL_ADDR_FIELD,
74+ LOADER_MIN_SIZE_FIELD,
75+ LOADER_START_FIELD,
76+ LOAD_ADDR_FIELD,
77+ MMC_ID_FIELD,
78+ PARTITION_LAYOUT_FIELD,
79+ RESERVED_BOOTFS,
80+ ROOT_MIN_SIZE_FIELD,
81+ SAMSUNG_BL1_LEN_FIELD,
82+ SAMSUNG_BL1_START_FIELD,
83+ SAMSUNG_BL2_LEN_FIELD,
84+ SAMSUNG_BL2_START_FIELD,
85+ SAMSUNG_ENV_LEN_FIELD,
86+ SAMSUNG_ENV_START_FILED,
87+ SERIAL_TTY_FIELD,
88+ SNOWBALL_STARTUP_FILES_CONFIG_FIELD,
89+ SPL_DD_FIELD,
90+ SPL_IN_BOOT_PART_FIELD,
91+ WIRED_INTERFACES_FIELD,
92+ WIRELESS_INTERFACES_FIELD,
93+ )
94
95 logger = logging.getLogger(__name__)
96
97@@ -102,310 +137,290 @@
98 cmd_runner.run(cmd, as_root=True).wait()
99
100
101-class classproperty(object):
102- """A descriptor that provides @property behavior on class methods."""
103- def __init__(self, getter):
104- self.getter = getter
105-
106- def __get__(self, instance, cls):
107- return self.getter(cls)
108-
109-
110 class BoardConfig(object):
111- board = None
112 """The configuration used when building an image for a board."""
113- hwpack_format = None
114- # These attributes may not need to be redefined on some subclasses.
115- bootloader_flavor = None
116- # whether to copy u-boot to the boot partition
117- bootloader_file_in_boot_part = False
118- bootloader_dd = False
119- spl_in_boot_part = False
120- spl_dd = False
121- env_dd = False
122- fatload_command = 'fatload'
123- mmc_option = '0:1'
124- mmc_device_id = 0
125- mmc_part_offset = 0
126- uimage_path = ''
127- fat_size = 32
128- extra_serial_opts = ''
129- _extra_serial_opts = ''
130- _live_serial_opts = ''
131- extra_boot_args_options = None
132- supports_writing_to_mmc = True
133+
134 LOADER_MIN_SIZE_S = align_up(1 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE
135 BOOT_MIN_SIZE_S = align_up(50 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE
136 ROOT_MIN_SIZE_S = align_up(50 * 1024 ** 2, SECTOR_SIZE) / SECTOR_SIZE
137
138- # These attributes must be defined on all subclasses for backwards
139- # compatibility with hwpacks v1 format. Hwpacks v2 format allows these to
140- # be specified in the hwpack metadata.
141- kernel_addr = None
142- initrd_addr = None
143- initrd_high = '0xffffffff'
144- load_addr = None
145- dtb_addr = None
146- dtb_name = None
147- dtb_file = None
148- fdt_high = '0xffffffff'
149- kernel_flavors = None
150- boot_script = None
151- serial_tty = None
152- wired_interfaces = None
153- wireless_interfaces = None
154- mmc_id = None
155- vmlinuz = None
156- initrd = None
157- partition_layout = None
158- LOADER_START_S = 1
159-
160- # Support for dtb_files as per hwpack v3 format.
161- dtb_files = None
162-
163- # Samsung Boot-loader implementation notes and terminology
164- #
165- # * BL0, BL1 etc. are the various bootloaders in order of execution
166- # * BL0 is the first stage bootloader, located in ROM; it loads BL1/SPL
167- # from MMC offset +1s and runs it.
168- # * BL1 is the secondary program loader (SPL), a small version
169- # of U-Boot with a checksum; it inits DRAM and loads a 1024s long BL2
170- # from MMC and runs it.
171- # * BL2 is the U-Boot.
172- #
173- # samsung_bl1_{start,len}: Offset and maximum size for BL1
174- # samsung_bl2_{start,len}: Offset and maximum size for BL2
175- # samsung_env_{start,len}: Offset and maximum size for Environment settings
176- #
177- samsung_bl1_start = 1
178- samsung_bl1_len = 32
179- samsung_bl2_start = 65
180- samsung_bl2_len = 1024
181- samsung_env_start = 33
182- samsung_env_len = 32
183-
184- hardwarepack_handler = None
185-
186- @classmethod
187- def get_metadata_field(cls, field_name):
188+ def __init__(self):
189+ super(BoardConfig, self).__init__()
190+ # XXX: when killing v1 hwpack, we might rename these two without the
191+ # leading underscore. It is done in this way since sublcasses use
192+ # placeholders in the string for dinamically change values. But this
193+ # is done only for hwpack v1.
194+ self._extra_serial_opts = ''
195+ self._live_serial_opts = ''
196+ self.board = None
197+ self.boot_script = None
198+ self.bootloader_dd = False
199+ self.bootloader_file_in_boot_part = False
200+ self.bootloader_flavor = None
201+ self.dtb_addr = None
202+ self.dtb_file = None
203+ self.dtb_files = None
204+ self.dtb_name = None
205+ self.env_dd = False
206+ self.extra_boot_args_options = None
207+ self.fat_size = 32
208+ self.fatload_command = 'fatload'
209+ self.fdt_high = '0xffffffff'
210+ self.hardwarepack_handler = None
211+ self.hwpack_format = None
212+ self.initrd_addr = None
213+ self.initrd_high = '0xffffffff'
214+ self.kernel_addr = None
215+ self.kernel_flavors = None
216+ self.load_addr = None
217+ self.loader_start_s = 1
218+ self.mmc_device_id = 0
219+ self.mmc_id = None
220+ self.mmc_option = '0:1'
221+ self.mmc_part_offset = 0
222+ self.partition_layout = None
223+ self.serial_tty = None
224+ self.spl_dd = False
225+ self.spl_in_boot_part = False
226+ self.supports_writing_to_mmc = True
227+ self.uimage_path = ''
228+ self.wired_interfaces = None
229+ self.wireless_interfaces = None
230+ # Samsung Boot-loader implementation notes and terminology
231+ #
232+ # * BL0, BL1 etc. are the various bootloaders in order of execution
233+ # * BL0 is the first stage bootloader, located in ROM; it loads BL1/SPL
234+ # from MMC offset +1s and runs it.
235+ # * BL1 is the secondary program loader (SPL), a small version
236+ # of U-Boot with a checksum; it inits DRAM and loads a 1024s long BL2
237+ # from MMC and runs it.
238+ # * BL2 is the U-Boot.
239+ #
240+ # samsung_bl1_{start,len}: Offset and maximum size for BL1
241+ # samsung_bl2_{start,len}: Offset and maximum size for BL2
242+ # samsung_env_{start,len}: Offset and maximum size for Environment settings
243+ #
244+ self.samsung_bl1_start = 1
245+ self.samsung_bl1_len = 32
246+ self.samsung_bl2_start = 65
247+ self.samsung_bl2_len = 1024
248+ self.samsung_env_start = 33
249+ self.samsung_env_len = 32
250+ # XXX: attributes that are not listed in hwpackV3, should be removed?
251+ self.vmlinuz = None
252+ self.initrd = None
253+
254+ # XXX: can be removed when killing v1 hwpack.
255+ def _get_live_serial_opts(self):
256+ return_value = self._live_serial_opts
257+ if self._check_placeholder_presence(return_value, r'%s'):
258+ return_value = self._live_serial_opts % self.serial_tty
259+ return return_value
260+
261+ def _set_live_serial_opts(self, value):
262+ self._live_serial_opts = value
263+
264+ live_serial_opts = property(_get_live_serial_opts, _set_live_serial_opts)
265+
266+ # XXX: can be removed when killing v1 hwpack.
267+ def _get_extra_serial_opts(self):
268+ return_value = self._extra_serial_opts
269+ if self._check_placeholder_presence(return_value, r'%s'):
270+ return_value = return_value % self.serial_tty
271+ return return_value
272+
273+ def _set_extra_serial_opts(self, value):
274+ self._extra_serial_opts = value
275+
276+ extra_serial_opts = property(_get_extra_serial_opts,
277+ _set_extra_serial_opts)
278+
279+ def get_metadata_field(self, field_name):
280 """ Return the metadata value for field_name if it can be found.
281 """
282- data, _ = cls.hardwarepack_handler.get_field(field_name)
283+ data, _ = self.hardwarepack_handler.get_field(field_name)
284 return data
285
286- @classmethod
287- def set_board(cls, board):
288- cls.board = board
289-
290- @classmethod
291- def set_metadata(cls, hwpacks, bootloader=None, board=None):
292- cls.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
293+ def set_metadata(self, hwpacks, bootloader=None, board=None):
294+ self.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
295 board)
296- with cls.hardwarepack_handler:
297- cls.hwpack_format = cls.hardwarepack_handler.get_format()
298- if (cls.hwpack_format == cls.hardwarepack_handler.FORMAT_1):
299+ with self.hardwarepack_handler:
300+ self.hwpack_format = self.hardwarepack_handler.get_format()
301+ if (self.hwpack_format == self.hardwarepack_handler.FORMAT_1):
302 return
303
304- if (cls.hwpack_format != cls.hardwarepack_handler.FORMAT_1):
305+ if (self.hwpack_format != self.hardwarepack_handler.FORMAT_1):
306 # Clear V1 defaults.
307- cls.kernel_addr = None
308- cls.initrd_addr = None
309- cls.load_addr = None
310- cls.serial_tty = None
311- cls.fat_size = None
312- cls.dtb_name = None
313- cls.dtb_addr = None
314- cls.extra_boot_args_options = None
315- cls.boot_script = None
316- cls.kernel_flavors = None
317- cls.mmc_option = None
318- cls.mmc_part_offset = None
319- cls.samsung_bl1_start = None
320- cls.samsung_bl1_len = None
321- cls.samsung_env_len = None
322- cls.samsung_bl2_len = None
323+ # TODO When removing v1 support, remove also default values
324+ # in the constructor and avoid all this.
325+ self.kernel_addr = None
326+ self.initrd_addr = None
327+ self.load_addr = None
328+ self.serial_tty = None
329+ self.fat_size = None
330+ self.dtb_name = None
331+ self.dtb_addr = None
332+ self.extra_boot_args_options = None
333+ self.boot_script = None
334+ self.kernel_flavors = None
335+ self.mmc_option = None
336+ self.mmc_part_offset = None
337+ self.samsung_bl1_start = None
338+ self.samsung_bl1_len = None
339+ self.samsung_env_len = None
340+ self.samsung_bl2_len = None
341 # cls.samsung_bl2_start and cls.samsung_env_start should
342- # be initialized to default value for backward compatibility.
343+ # be initialized to default values for backward compatibility.
344
345+ self.board = board
346 # Set new values from metadata.
347- cls.kernel_addr = cls.get_metadata_field('kernel_addr')
348- cls.initrd_addr = cls.get_metadata_field('initrd_addr')
349- cls.load_addr = cls.get_metadata_field('load_addr')
350- cls.dtb_addr = cls.get_metadata_field('dtb_addr')
351- cls.serial_tty = cls.get_metadata_field('serial_tty')
352- wired_interfaces = cls.get_metadata_field('wired_interfaces')
353- if wired_interfaces is not None:
354- cls.wired_interfaces = wired_interfaces
355- wireless_interfaces = cls.get_metadata_field(
356- 'wireless_interfaces')
357- if wireless_interfaces is not None:
358- cls.wireless_interfaces = wireless_interfaces
359- cls.vmlinuz = cls.get_metadata_field('vmlinuz')
360- cls.initrd = cls.get_metadata_field('initrd')
361- cls.dtb_file = cls.get_metadata_field('dtb_file')
362- cls.dtb_files = cls.get_metadata_field('dtb_files')
363- cls.extra_boot_args_options = cls.get_metadata_field(
364- 'extra_boot_options')
365- cls.boot_script = cls.get_metadata_field('boot_script')
366- cls.extra_serial_opts = cls.get_metadata_field(
367- 'extra_serial_opts')
368- cls.snowball_startup_files_config = cls.get_metadata_field(
369- 'snowball_startup_files_config')
370-
371- cls.partition_layout = cls.get_metadata_field('partition_layout')
372- if cls.partition_layout in [
373- 'bootfs_rootfs', 'reserved_bootfs_rootfs', None]:
374- cls.fat_size = 32
375- elif cls.partition_layout == 'bootfs16_rootfs':
376- cls.fat_size = 16
377+ self.kernel_addr = self.get_metadata_field(KERNEL_ADDR_FIELD)
378+ self.initrd_addr = self.get_metadata_field(INITRD_ADDR_FIELD)
379+ self.load_addr = self.get_metadata_field(LOAD_ADDR_FIELD)
380+ self.dtb_addr = self.get_metadata_field(DTB_ADDR_FIELD)
381+ self.serial_tty = self.get_metadata_field(SERIAL_TTY_FIELD)
382+ wired_interfaces = self.get_metadata_field(WIRED_INTERFACES_FIELD)
383+ if wired_interfaces:
384+ self.wired_interfaces = wired_interfaces
385+ wireless_interfaces = self.get_metadata_field(
386+ WIRELESS_INTERFACES_FIELD)
387+ if wireless_interfaces:
388+ self.wireless_interfaces = wireless_interfaces
389+ self.dtb_file = self.get_metadata_field(DTB_FILE_FIELD)
390+ # XXX: need to deprecate dtb_file field and use only dtb_files
391+ # for multiple entries.
392+ if self.dtb_file:
393+ logger.warn("Deprecation warning: use the 'dtb_files' field "
394+ "instead of 'dtb_file'.")
395+ self.dtb_files = self.get_metadata_field(DTB_FILES_FIELD)
396+ self.extra_boot_args_options = self.get_metadata_field(
397+ EXTRA_BOOT_OPTIONS_FIELD)
398+ self.boot_script = self.get_metadata_field(BOOT_SCRIPT_FIELD)
399+ self.extra_serial_opts = self.get_metadata_field(
400+ EXTRA_SERIAL_OPTIONS_FIELD)
401+ self.snowball_startup_files_config = self.get_metadata_field(
402+ SNOWBALL_STARTUP_FILES_CONFIG_FIELD)
403+ self.partition_layout = self.get_metadata_field(
404+ PARTITION_LAYOUT_FIELD)
405+ if self.partition_layout in [BOOTFS, RESERVED_BOOTFS, None]:
406+ self.fat_size = 32
407+ elif self.partition_layout == BOOTFS16:
408+ self.fat_size = 16
409 else:
410 raise AssertionError("Unknown partition layout '%s'." % \
411- cls.partition_layout)
412-
413- cls.mmc_option = cls.get_metadata_field('mmc_id')
414- if cls.mmc_option is not None:
415- cls.mmc_device_id = int(cls.mmc_option.split(':')[0])
416- cls.mmc_part_offset = int(cls.mmc_option.split(':')[1]) - 1
417-
418- boot_min_size = cls.get_metadata_field('boot_min_size')
419- if boot_min_size is not None:
420- cls.BOOT_MIN_SIZE_S = align_up(int(boot_min_size) * 1024 ** 2,
421- SECTOR_SIZE) / SECTOR_SIZE
422- root_min_size = cls.get_metadata_field('root_min_size')
423- if root_min_size is not None:
424- cls.ROOT_MIN_SIZE_S = align_up(int(root_min_size) * 1024 ** 2,
425- SECTOR_SIZE) / SECTOR_SIZE
426- loader_min_size = cls.get_metadata_field('loader_min_size')
427- if loader_min_size is not None:
428- cls.LOADER_MIN_SIZE_S = (
429+ self.partition_layout)
430+
431+ self.mmc_option = self.get_metadata_field(MMC_ID_FIELD)
432+ if self.mmc_option:
433+ self.mmc_device_id = int(self.mmc_option.split(':')[0])
434+ self.mmc_part_offset = int(self.mmc_option.split(':')[1]) - 1
435+
436+ # XXX: need to fix these values.
437+ boot_min_size = self.get_metadata_field(BOOT_MIN_SIZE_FIELD)
438+ if boot_min_size:
439+ self.BOOT_MIN_SIZE_S = align_up(int(boot_min_size) * 1024 ** 2,
440+ SECTOR_SIZE) / SECTOR_SIZE
441+ root_min_size = self.get_metadata_field(ROOT_MIN_SIZE_FIELD)
442+ if root_min_size:
443+ self.ROOT_MIN_SIZE_S = align_up(int(root_min_size) * 1024 ** 2,
444+ SECTOR_SIZE) / SECTOR_SIZE
445+ loader_min_size = self.get_metadata_field(LOADER_MIN_SIZE_FIELD)
446+ if loader_min_size:
447+ self.LOADER_MIN_SIZE_S = (
448 align_up(int(loader_min_size) * 1024 ** 2,
449 SECTOR_SIZE) / SECTOR_SIZE)
450
451- bootloader_file_in_boot_part = cls.get_metadata_field(
452- 'bootloader_file_in_boot_part')
453- if bootloader_file_in_boot_part is None:
454- cls.bootloader_file_in_boot_part = False
455- elif string.lower(bootloader_file_in_boot_part) == 'yes':
456- cls.bootloader_file_in_boot_part = True
457- elif string.lower(bootloader_file_in_boot_part) == 'no':
458- cls.bootloader_file_in_boot_part = False
459- spl_in_boot_part = cls.get_metadata_field('spl_in_boot_part')
460+ spl_in_boot_part = self.get_metadata_field(SPL_IN_BOOT_PART_FIELD)
461 if spl_in_boot_part is None:
462- cls.spl_in_boot_part = False
463+ self.spl_in_boot_part = False
464 elif string.lower(spl_in_boot_part) == 'yes':
465- cls.spl_in_boot_part = True
466+ self.spl_in_boot_part = True
467 elif string.lower(spl_in_boot_part) == 'no':
468- cls.spl_in_boot_part = False
469- env_dd = cls.get_metadata_field('env_dd')
470+ self.spl_in_boot_part = False
471+
472+ env_dd = self.get_metadata_field(ENV_DD_FIELD)
473 if env_dd is None:
474- cls.env_dd = False
475+ self.env_dd = False
476 elif string.lower(env_dd) == 'yes':
477- cls.env_dd = True
478+ self.env_dd = True
479 elif string.lower(env_dd) == 'no':
480- cls.env_dd = False
481+ self.env_dd = False
482
483- bootloader_dd = cls.get_metadata_field('bootloader_dd')
484+ # XXX: in hwpack v3 this field is just called 'dd'.
485+ # Need to check its use.
486+ bootloader_dd = self.get_metadata_field('bootloader_dd')
487 # Either bootloader_dd is not specified, or it contains the dd
488 # offset.
489 if bootloader_dd is None:
490- cls.bootloader_dd = False
491+ self.bootloader_dd = False
492 else:
493- cls.bootloader_dd = int(bootloader_dd)
494- spl_dd = cls.get_metadata_field('spl_dd')
495+ self.bootloader_dd = int(bootloader_dd)
496+ spl_dd = self.get_metadata_field(SPL_DD_FIELD)
497 # Either spl_dd is not specified, or it contains the dd offset.
498 if spl_dd is None:
499- cls.spl_dd = False
500+ self.spl_dd = False
501 else:
502- cls.spl_dd = int(spl_dd)
503-
504- loader_start = cls.get_metadata_field('loader_start')
505- if loader_start is not None:
506- cls.LOADER_START_S = int(loader_start)
507-
508- samsung_bl1_start = cls.get_metadata_field('samsung_bl1_start')
509- if samsung_bl1_start is not None:
510- cls.samsung_bl1_start = int(samsung_bl1_start)
511-
512- samsung_bl1_len = cls.get_metadata_field('samsung_bl1_len')
513- if samsung_bl1_len is not None:
514- cls.samsung_bl1_len = int(samsung_bl1_len)
515-
516- samsung_bl2_len = cls.get_metadata_field('samsung_bl2_len')
517- if samsung_bl2_len is not None:
518- cls.samsung_bl2_len = int(samsung_bl2_len)
519-
520- samsung_bl2_start = cls.get_metadata_field('samsung_bl2_start')
521- if samsung_bl2_start is not None:
522- cls.samsung_bl2_start = int(samsung_bl2_start)
523-
524- samsung_env_len = cls.get_metadata_field('samsung_env_len')
525- if samsung_env_len is not None:
526- cls.samsung_env_len = int(samsung_env_len)
527-
528- samsung_env_start = cls.get_metadata_field('samsung_env_start')
529- if samsung_env_start is not None:
530- cls.samsung_env_start = int(samsung_env_start)
531-
532- cls.bootloader_copy_files = cls.hardwarepack_handler.get_field(
533+ self.spl_dd = int(spl_dd)
534+
535+ loader_start = self.get_metadata_field(LOADER_START_FIELD)
536+ if loader_start:
537+ self.loader_start_s = int(loader_start)
538+
539+ samsung_bl1_start = self.get_metadata_field(
540+ SAMSUNG_BL1_START_FIELD)
541+ if samsung_bl1_start:
542+ self.samsung_v310_bl1_start = int(samsung_bl1_start)
543+ samsung_bl1_len = self.get_metadata_field(SAMSUNG_BL1_LEN_FIELD)
544+ if samsung_bl1_len:
545+ self.samsung_v310_bl1_len = int(samsung_bl1_len)
546+ samsung_env_len = self.get_metadata_field(SAMSUNG_ENV_LEN_FIELD)
547+ if samsung_env_len:
548+ self.samsung_v310_env_len = int(samsung_env_len)
549+ samsung_bl2_len = self.get_metadata_field(SAMSUNG_BL2_LEN_FIELD)
550+ if samsung_bl2_len:
551+ self.samsung_v310_bl2_len = int(samsung_bl2_len)
552+ samsung_bl2_start = self.get_metadata_field(
553+ SAMSUNG_BL2_START_FIELD)
554+ if samsung_bl2_start:
555+ self.samsung_bl2_start = int(samsung_bl2_start)
556+ samsung_env_start = self.get_metadata_field(
557+ SAMSUNG_ENV_START_FILED)
558+ if samsung_env_start:
559+ self.samsung_env_start = int(samsung_env_start)
560+
561+ self.bootloader_copy_files = self.hardwarepack_handler.get_field(
562 "bootloader_copy_files")[0]
563
564- cls.bootloader = cls.hardwarepack_handler.get_field(
565- "bootloader")
566- cls.board = board
567+ # XXX: no reference in hwpackV3 format of these fields, double
568+ # check if they can be dropped when killing v1.
569+ self.bootloader = self.hardwarepack_handler.get_field(
570+ "bootloader")
571+ self.vmlinuz = self.get_metadata_field('vmlinuz')
572+ self.initrd = self.get_metadata_field('initrd')
573+ bootloader_file_in_boot_part = self.get_metadata_field(
574+ 'bootloader_file_in_boot_part')
575+ if bootloader_file_in_boot_part is None:
576+ self.bootloader_file_in_boot_part = False
577+ elif string.lower(bootloader_file_in_boot_part) == 'yes':
578+ self.bootloader_file_in_boot_part = True
579+ elif string.lower(bootloader_file_in_boot_part) == 'no':
580+ self.bootloader_file_in_boot_part = False
581
582- @classmethod
583- def get_file(cls, file_alias, default=None):
584+ def get_file(self, file_alias, default=None):
585 # XXX remove the 'default' parameter when V1 support is removed!
586- file_in_hwpack = cls.hardwarepack_handler.get_file(file_alias)
587+ file_in_hwpack = self.hardwarepack_handler.get_file(file_alias)
588 if file_in_hwpack is not None:
589 return file_in_hwpack
590 else:
591 return default
592
593- @classmethod
594- def get_v1_sfdisk_cmd(cls, should_align_boot_part=False):
595- """Return the sfdisk command to partition the media.
596-
597- :param should_align_boot_part: Whether to align the boot partition too.
598-
599- This default implementation returns a boot vfat partition of type
600- FAT16 or FAT32, followed by a root partition.
601-
602- XXX: This default implementation and all overrides are left for V1
603- compatibility only. They should be removed as part of the work to
604- kill off hwpacks V1.
605- """
606- if cls.fat_size == 32:
607- partition_type = '0x0C'
608- else:
609- partition_type = '0x0E'
610-
611- # align on sector 63 for compatibility with broken versions of x-loader
612- # unless align_boot_part is set
613- boot_align = 63
614- if should_align_boot_part:
615- boot_align = PART_ALIGN_S
616-
617- # can only start on sector 1 (sector 0 is MBR / partition table)
618- boot_start, boot_end, boot_len = align_partition(
619- 1, cls.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
620- # apparently OMAP3 ROMs require the vfat length to be an even number
621- # of sectors (multiple of 1 KiB); decrease the length if it's odd,
622- # there should still be enough room
623- boot_len = boot_len - boot_len % 2
624- boot_end = boot_start + boot_len - 1
625-
626- # we ignore _root_end / _root_len and return a sfdisk command to
627- # instruct the use of all remaining space; XXX if we had some root size
628- # config, we could do something more sensible
629- root_start, _root_end, _root_len = align_partition(
630- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
631-
632- return '%s,%s,%s,*\n%s,,,-' % (
633- boot_start, boot_len, partition_type, root_start)
634-
635- @classmethod
636- def get_normal_sfdisk_cmd(cls, should_align_boot_part=False):
637+ def get_v1_sfdisk_cmd(self, should_align_boot_part=False):
638+ # XXX: This default implementation and all overrides are left for V1
639+ # compatibility only. They should be removed as part of the work to
640+ # kill off hwpacks V1.
641+ return self.get_normal_sfdisk_cmd(should_align_boot_part)
642+
643+ def get_normal_sfdisk_cmd(self, should_align_boot_part=False):
644 """Return the sfdisk command to partition the media.
645
646 :param should_align_boot_part: Whether to align the boot partition too.
647@@ -413,7 +428,7 @@
648 This returns a boot vfat partition of type FAT16
649 or FAT32, followed by a root partition.
650 """
651- if cls.fat_size == 32:
652+ if self.fat_size == 32:
653 partition_type = '0x0C'
654 else:
655 partition_type = '0x0E'
656@@ -427,7 +442,7 @@
657
658 # can only start on sector 1 (sector 0 is MBR / partition table)
659 boot_start, boot_end, boot_len = align_partition(
660- 1, cls.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
661+ 1, self.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
662 # apparently OMAP3 ROMs require the vfat length to be an even number
663 # of sectors (multiple of 1 KiB); decrease the length if it's odd,
664 # there should still be enough room
665@@ -439,13 +454,12 @@
666 # instruct the use of all remaining space; XXX we now have root size
667 # config, so we can do something more sensible
668 root_start, _root_end, _root_len = align_partition(
669- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
670+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
671
672 return '%s,%s,%s,*\n%s,,,-' % (
673 boot_start, boot_len, partition_type, root_start)
674
675- @classmethod
676- def get_reserved_sfdisk_cmd(cls, should_align_boot_part=None):
677+ def get_reserved_sfdisk_cmd(self, should_align_boot_part=None):
678 """Return the sfdisk command to partition the media.
679
680 :param should_align_boot_part: Ignored.
681@@ -454,40 +468,38 @@
682 FAT16 or FAT32, followed by a root partition.
683 """
684 loader_start, loader_end, loader_len = align_partition(
685- cls.LOADER_START_S, cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
686+ self.loader_start_s, self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
687
688 boot_start, boot_end, boot_len = align_partition(
689- loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
690+ loader_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
691
692 root_start, _root_end, _root_len = align_partition(
693- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
694+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
695
696 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
697 loader_start, loader_len, boot_start, boot_len, root_start)
698
699- @classmethod
700- def get_sfdisk_cmd(cls, should_align_boot_part=False):
701- if (cls.partition_layout in ['bootfs_rootfs', 'bootfs16_rootfs'] or
702- cls.board == 'snowball_sd'):
703- return cls.get_normal_sfdisk_cmd(should_align_boot_part)
704- elif cls.partition_layout in ['reserved_bootfs_rootfs']:
705- return cls.get_reserved_sfdisk_cmd(should_align_boot_part)
706+ def get_sfdisk_cmd(self, should_align_boot_part=False):
707+ if (self.partition_layout in ['bootfs_rootfs', 'bootfs16_rootfs'] or
708+ self.board == 'snowball_sd'):
709+ return self.get_normal_sfdisk_cmd(should_align_boot_part)
710+ elif self.partition_layout in ['reserved_bootfs_rootfs']:
711+ return self.get_reserved_sfdisk_cmd(should_align_boot_part)
712 else:
713- assert (cls.hwpack_format == HardwarepackHandler.FORMAT_1), (
714+ assert (self.hwpack_format == HardwarepackHandler.FORMAT_1), (
715 "Hwpack format is not 1.0 but "
716 "partition_layout is unspecified.")
717- return cls.get_v1_sfdisk_cmd(should_align_boot_part)
718+ return self.get_v1_sfdisk_cmd(should_align_boot_part)
719
720- @classmethod
721- def _get_bootcmd(cls, i_img_data, d_img_data):
722+ def _get_bootcmd(self, i_img_data, d_img_data):
723 """Get the bootcmd for this board.
724
725 In general subclasses should not have to override this.
726 """
727 replacements = dict(
728- fatload_command=cls.fatload_command, uimage_path=cls.uimage_path,
729- mmc_option=cls.mmc_option, kernel_addr=cls.kernel_addr,
730- initrd_addr=cls.initrd_addr, dtb_addr=cls.dtb_addr)
731+ fatload_command=self.fatload_command, uimage_path=self.uimage_path,
732+ mmc_option=self.mmc_option, kernel_addr=self.kernel_addr,
733+ initrd_addr=self.initrd_addr, dtb_addr=self.dtb_addr)
734 boot_script = (
735 ("%(fatload_command)s mmc %(mmc_option)s %(kernel_addr)s " +
736 "%(uimage_path)suImage; ")) % replacements
737@@ -496,7 +508,7 @@
738 ("%(fatload_command)s mmc %(mmc_option)s %(initrd_addr)s " +
739 "%(uimage_path)suInitrd; ")) % replacements
740 if d_img_data is not None:
741- assert cls.dtb_addr is not None, (
742+ assert self.dtb_addr is not None, (
743 "Need a dtb_addr when passing d_img_data")
744 boot_script += (
745 ("%(fatload_command)s mmc %(mmc_option)s %(dtb_addr)s " +
746@@ -508,37 +520,34 @@
747 boot_script += ((" %(dtb_addr)s")) % replacements
748 return boot_script
749
750- @classmethod
751- def add_boot_args(cls, extra_args):
752+ def add_boot_args(self, extra_args):
753 if extra_args is not None:
754- if cls.extra_boot_args_options is None:
755- cls.extra_boot_args_options = extra_args
756+ if self.extra_boot_args_options is None:
757+ self.extra_boot_args_options = extra_args
758 else:
759- cls.extra_boot_args_options += ' %s' % extra_args
760+ self.extra_boot_args_options += ' %s' % extra_args
761
762- @classmethod
763- def add_boot_args_from_file(cls, path):
764+ def add_boot_args_from_file(self, path):
765 if path is not None:
766 with open(path, 'r') as boot_args_file:
767- cls.add_boot_args(boot_args_file.read().strip())
768+ self.add_boot_args(boot_args_file.read().strip())
769
770- @classmethod
771- def _get_bootargs(cls, is_live, is_lowmem, consoles, rootfs_id):
772+ def _get_bootargs(self, is_live, is_lowmem, consoles, rootfs_id):
773 """Get the bootargs for this board.
774
775 In general subclasses should not have to override this.
776 """
777 boot_args_options = 'rootwait ro'
778- if cls.extra_boot_args_options is not None:
779- boot_args_options += ' %s' % cls.extra_boot_args_options
780- serial_opts = cls.extra_serial_opts
781+ if self.extra_boot_args_options:
782+ boot_args_options += ' %s' % self.extra_boot_args_options
783+ serial_opts = self.extra_serial_opts
784 for console in consoles:
785 serial_opts += ' console=%s' % console
786
787 lowmem_opt = ''
788 boot_snippet = 'root=%s' % rootfs_id
789 if is_live:
790- serial_opts += ' %s' % cls.live_serial_opts
791+ serial_opts += ' %s' % self.live_serial_opts
792 boot_snippet = 'boot=casper'
793 if is_lowmem:
794 lowmem_opt = 'only-ubiquity'
795@@ -552,45 +561,42 @@
796 "%(boot_snippet)s %(boot_args_options)s"
797 % replacements)
798
799- @classmethod
800- def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
801+ def _get_boot_env(self, is_live, is_lowmem, consoles, rootfs_id,
802 i_img_data, d_img_data):
803 """Get the boot environment for this board.
804
805 In general subclasses should not have to override this.
806 """
807 boot_env = {}
808- boot_env["bootargs"] = cls._get_bootargs(
809+ boot_env["bootargs"] = self._get_bootargs(
810 is_live, is_lowmem, consoles, rootfs_id)
811- boot_env["bootcmd"] = cls._get_bootcmd(i_img_data, d_img_data)
812- boot_env["initrd_high"] = cls.initrd_high
813- boot_env["fdt_high"] = cls.fdt_high
814+ boot_env["bootcmd"] = self._get_bootcmd(i_img_data, d_img_data)
815+ boot_env["initrd_high"] = self.initrd_high
816+ boot_env["fdt_high"] = self.fdt_high
817 return boot_env
818
819- @classmethod
820- def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
821+ def make_boot_files(self, bootloader_parts_dir, is_live, is_lowmem,
822 consoles, chroot_dir, rootfs_id, boot_dir,
823 boot_device_or_file):
824- if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
825+ if self.hwpack_format == HardwarepackHandler.FORMAT_1:
826 parts_dir = bootloader_parts_dir
827 else:
828 parts_dir = chroot_dir
829- (k_img_data, i_img_data, d_img_data) = cls._get_kflavor_files(
830+ (k_img_data, i_img_data, d_img_data) = self._get_kflavor_files(
831 parts_dir)
832- boot_env = cls._get_boot_env(is_live, is_lowmem, consoles, rootfs_id,
833+ boot_env = self._get_boot_env(is_live, is_lowmem, consoles, rootfs_id,
834 i_img_data, d_img_data)
835
836- if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
837- cls._make_boot_files(
838+ if self.hwpack_format == HardwarepackHandler.FORMAT_1:
839+ self._make_boot_files(
840 boot_env, chroot_dir, boot_dir,
841 boot_device_or_file, k_img_data, i_img_data, d_img_data)
842 else:
843- cls._make_boot_files_v2(
844+ self._make_boot_files_v2(
845 boot_env, chroot_dir, boot_dir,
846 boot_device_or_file, k_img_data, i_img_data, d_img_data)
847
848- @classmethod
849- def _copy_dtb_files(cls, dtb_files, dest_dir, search_dir):
850+ def _copy_dtb_files(self, dtb_files, dest_dir, search_dir):
851 """Copy the files defined in dtb_files into the boot directory.
852
853 :param dtb_files: The list of dtb files
854@@ -630,13 +636,12 @@
855 else:
856 # Hopefully we should never get here.
857 # This should only happen if the hwpack config YAML file is
858- # wrong
859+ # wrong.
860 logger.warn('WARNING: Wrong syntax in metadata file. '
861 'Check the hwpack configuration file used to '
862 'generate the hwpack archive.')
863
864- @classmethod
865- def _dd_file(cls, from_file, to_file, seek, max_size=None):
866+ def _dd_file(self, from_file, to_file, seek, max_size=None):
867 assert from_file is not None, "No source file name given."
868 if max_size is not None:
869 assert os.path.getsize(from_file) <= max_size, (
870@@ -644,23 +649,21 @@
871 logger.info("Writing '%s' to '%s' at %s." % (from_file, to_file, seek))
872 _dd(from_file, to_file, seek=seek)
873
874- @classmethod
875- def install_samsung_boot_loader(cls, samsung_spl_file, bootloader_file,
876+ def install_samsung_boot_loader(self, samsung_spl_file, bootloader_file,
877 boot_device_or_file):
878- cls._dd_file(samsung_spl_file, boot_device_or_file,
879- cls.samsung_bl1_start,
880- cls.samsung_bl1_len * SECTOR_SIZE)
881- cls._dd_file(bootloader_file, boot_device_or_file,
882- cls.samsung_bl2_start,
883- cls.samsung_bl2_len * SECTOR_SIZE)
884+ self._dd_file(samsung_spl_file, boot_device_or_file,
885+ self.samsung_bl1_start,
886+ self.samsung_bl1_len * SECTOR_SIZE)
887+ self._dd_file(bootloader_file, boot_device_or_file,
888+ self.samsung_bl2_start,
889+ self.samsung_bl2_len * SECTOR_SIZE)
890
891- @classmethod
892- def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir,
893+ def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
894 boot_device_or_file, k_img_data, i_img_data,
895 d_img_data):
896- with cls.hardwarepack_handler:
897- spl_file = cls.get_file('spl_file')
898- if cls.spl_in_boot_part:
899+ with self.hardwarepack_handler:
900+ spl_file = self.get_file('spl_file')
901+ if self.spl_in_boot_part:
902 assert spl_file is not None, (
903 "SPL binary could not be found")
904 logger.info(
905@@ -670,15 +673,15 @@
906 # XXX: Is this really needed?
907 cmd_runner.run(["sync"]).wait()
908
909- if cls.spl_dd:
910- cls._dd_file(spl_file, boot_device_or_file, cls.spl_dd)
911-
912- bootloader_file = cls.get_file('bootloader_file')
913- if cls.bootloader_dd:
914- cls._dd_file(bootloader_file, boot_device_or_file,
915- cls.bootloader_dd)
916-
917- make_uImage(cls.load_addr, k_img_data, boot_dir)
918+ if self.spl_dd:
919+ self._dd_file(spl_file, boot_device_or_file, self.spl_dd)
920+
921+ bootloader_file = self.get_file('bootloader_file')
922+ if self.bootloader_dd:
923+ self._dd_file(bootloader_file, boot_device_or_file,
924+ self.bootloader_dd)
925+
926+ make_uImage(self.load_addr, k_img_data, boot_dir)
927
928 if i_img_data is not None:
929 make_uInitrd(i_img_data, boot_dir)
930@@ -686,29 +689,28 @@
931 if d_img_data is not None:
932 make_dtb(d_img_data, boot_dir)
933
934- if cls.boot_script is not None:
935- boot_script_path = os.path.join(boot_dir, cls.boot_script)
936+ if self.boot_script is not None:
937+ boot_script_path = os.path.join(boot_dir, self.boot_script)
938 make_boot_script(boot_env, boot_script_path)
939
940 # Only used for Omap, will this be bad for the other boards?
941 make_boot_ini(boot_script_path, boot_dir)
942
943- if (cls.snowball_startup_files_config is not None and
944- cls.board != 'snowball_sd'):
945- cls.populate_raw_partition(boot_device_or_file, chroot_dir)
946+ if (self.snowball_startup_files_config is not None and
947+ self.board != 'snowball_sd'):
948+ self.populate_raw_partition(boot_device_or_file, chroot_dir)
949
950- if cls.env_dd:
951+ if self.env_dd:
952 # Do we need to zero out the env before flashing it?
953 _dd("/dev/zero", boot_device_or_file,
954- count=cls.samsung_env_len,
955- seek=cls.samsung_env_start)
956- env_size = cls.samsung_env_len * SECTOR_SIZE
957+ count=self.samsung_env_len,
958+ seek=self.samsung_env_start)
959+ env_size = self.samsung_env_len * SECTOR_SIZE
960 env_file = make_flashable_env(boot_env, env_size)
961- cls._dd_file(env_file, boot_device_or_file,
962- cls.samsung_env_start)
963+ self._dd_file(env_file, boot_device_or_file,
964+ self.samsung_env_start)
965
966- @classmethod
967- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
968+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
969 boot_device_or_file, k_img_data, i_img_data,
970 d_img_data):
971 """Make the necessary boot files for this board.
972@@ -718,8 +720,7 @@
973 """
974 raise NotImplementedError()
975
976- @classmethod
977- def populate_boot(cls, chroot_dir, rootfs_id, boot_partition, boot_disk,
978+ def populate_boot(self, chroot_dir, rootfs_id, boot_partition, boot_disk,
979 boot_device_or_file, is_live, is_lowmem, consoles):
980 parts_dir = 'boot'
981 if is_live:
982@@ -727,21 +728,21 @@
983 bootloader_parts_dir = os.path.join(chroot_dir, parts_dir)
984 cmd_runner.run(['mkdir', '-p', boot_disk]).wait()
985 with partition_mounted(boot_partition, boot_disk):
986- with cls.hardwarepack_handler:
987- if cls.bootloader_file_in_boot_part:
988+ with self.hardwarepack_handler:
989+ if self.bootloader_file_in_boot_part:
990 # <legacy v1 support>
991- if cls.bootloader_flavor is not None:
992+ if self.bootloader_flavor is not None:
993 default = os.path.join(
994 chroot_dir, 'usr', 'lib', 'u-boot',
995- cls.bootloader_flavor, 'u-boot.img')
996+ self.bootloader_flavor, 'u-boot.img')
997 if not os.path.exists(default):
998 default = os.path.join(
999 chroot_dir, 'usr', 'lib', 'u-boot',
1000- cls.bootloader_flavor, 'u-boot.bin')
1001+ self.bootloader_flavor, 'u-boot.bin')
1002 else:
1003 default = None
1004 # </legacy v1 support>
1005- bootloader_bin = cls.get_file('bootloader_file',
1006+ bootloader_bin = self.get_file('bootloader_file',
1007 default=default)
1008 assert bootloader_bin is not None, (
1009 "bootloader binary could not be found")
1010@@ -751,18 +752,17 @@
1011 proc.wait()
1012
1013 # Handle copy_files field.
1014- cls.copy_files(boot_disk)
1015+ self.copy_files(boot_disk)
1016
1017 # Handle dtb_files field.
1018- if cls.dtb_files:
1019- cls._copy_dtb_files(cls.dtb_files, boot_disk, chroot_dir)
1020+ if self.dtb_files:
1021+ self._copy_dtb_files(self.dtb_files, boot_disk, chroot_dir)
1022
1023- cls.make_boot_files(
1024+ self.make_boot_files(
1025 bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
1026 rootfs_id, boot_disk, boot_device_or_file)
1027
1028- @classmethod
1029- def copy_files(cls, boot_disk):
1030+ def copy_files(self, boot_disk):
1031 """Handle the copy_files metadata field."""
1032
1033 # Extract anything specified by copy_files sections
1034@@ -772,13 +772,14 @@
1035 # {'source_path': 'dest_path'}
1036 # ]
1037 # }
1038- if cls.bootloader_copy_files is None:
1039+ if self.bootloader_copy_files is None:
1040 return
1041
1042- for source_package, file_list in cls.bootloader_copy_files.iteritems():
1043+ for source_package, file_list in \
1044+ self.bootloader_copy_files.iteritems():
1045 for file_info in file_list:
1046 for source_path, dest_path in file_info.iteritems():
1047- source = cls.hardwarepack_handler.get_file_from_package(
1048+ source = self.hardwarepack_handler.get_file_from_package(
1049 source_path, source_package)
1050 dest_path = dest_path.lstrip("/\\")
1051 dirname = os.path.dirname(dest_path)
1052@@ -791,25 +792,24 @@
1053 os.path.join(boot_disk, dest_path)], as_root=True)
1054 proc.wait()
1055
1056- @classmethod
1057- def _get_kflavor_files(cls, path):
1058+ def _get_kflavor_files(self, path):
1059 """Search for kernel, initrd and optional dtb in path."""
1060- if cls.kernel_flavors is None:
1061+ if self.kernel_flavors is None:
1062 # V2 metadata specifies each glob, not flavors.
1063 # XXX This duplication is temporary until V1 dies.
1064- return cls._get_kflavor_files_v2(path)
1065+ return self._get_kflavor_files_v2(path)
1066
1067- for flavor in cls.kernel_flavors:
1068+ for flavor in self.kernel_flavors:
1069 kregex = KERNEL_GLOB % {'kernel_flavor': flavor}
1070 iregex = INITRD_GLOB % {'kernel_flavor': flavor}
1071 dregex = DTB_GLOB % {'kernel_flavor': flavor,
1072- 'dtb_name': cls.dtb_name}
1073+ 'dtb_name': self.dtb_name}
1074 kernel = _get_file_matching(os.path.join(path, kregex))
1075 if kernel is not None:
1076 initrd = _get_file_matching(os.path.join(path, iregex))
1077 if initrd is not None:
1078 dtb = None
1079- if cls.dtb_name is not None:
1080+ if self.dtb_name is not None:
1081 dtb = _get_file_matching(os.path.join(path, dregex))
1082 return (kernel, initrd, dtb)
1083 raise ValueError(
1084@@ -817,83 +817,83 @@
1085 flavor, iregex))
1086 raise ValueError(
1087 "No kernel found matching %s for flavors %s" % (
1088- KERNEL_GLOB, " ".join(cls.kernel_flavors)))
1089+ KERNEL_GLOB, " ".join(self.kernel_flavors)))
1090
1091- @classmethod
1092- def _get_kflavor_files_v2(cls, path):
1093+ def _get_kflavor_files_v2(self, path):
1094 kernel = initrd = dtb = None
1095
1096- if cls.vmlinuz:
1097- kernel = _get_file_matching(os.path.join(path, cls.vmlinuz))
1098- if not cls.vmlinuz or not kernel:
1099+ if self.vmlinuz:
1100+ kernel = _get_file_matching(os.path.join(path, self.vmlinuz))
1101+ if not self.vmlinuz or not kernel:
1102 raise ValueError("Unable to find a valid kernel image.")
1103
1104- if cls.initrd:
1105- initrd = _get_file_matching(os.path.join(path, cls.initrd))
1106- if not cls.initrd or not initrd:
1107+ if self.initrd:
1108+ initrd = _get_file_matching(os.path.join(path, self.initrd))
1109+ if not self.initrd or not initrd:
1110 logger.warn("Could not find a valid initrd, skipping uInitd.")
1111
1112- if cls.dtb_file:
1113- dtb = _get_file_matching(os.path.join(path, cls.dtb_file))
1114- if not cls.dtb_file or not dtb:
1115+ if self.dtb_file:
1116+ dtb = _get_file_matching(os.path.join(path, self.dtb_file))
1117+ if not self.dtb_file or not dtb:
1118 logger.warn("Could not find a valid dtb file, skipping it.")
1119
1120 logger.info("Will use kernel=%s, initrd=%s, dtb=%s." % \
1121 (kernel, initrd, dtb))
1122 return (kernel, initrd, dtb)
1123
1124- @classmethod
1125- def populate_raw_partition(cls, media, boot_dir):
1126+ def populate_raw_partition(self, media, boot_dir):
1127 # Override in subclass if needed
1128 pass
1129
1130- @classmethod
1131- def snowball_config(cls, chroot_dir):
1132+ def snowball_config(self, chroot_dir):
1133 # Override in subclasses where applicable
1134 raise NotImplementedError(
1135 "snowball_config() must only be called on BoardConfigs that "
1136 "use the Snowball startupfiles.")
1137
1138+ # XXX: can be removed when killing v1 hwpack and updating the attributes
1139+ # that use it.
1140+ @staticmethod
1141+ def _check_placeholder_presence(string, placeholder):
1142+ """Checks if the passed string contains the particular placeholder."""
1143+ # Very simple way of achieving that.
1144+ presence = False
1145+ if placeholder in string:
1146+ presence = True
1147+ return presence
1148+
1149
1150 class OmapConfig(BoardConfig):
1151- kernel_flavors = ['linaro-omap4', 'linaro-lt-omap', 'linaro-omap', 'omap4']
1152- bootloader_file_in_boot_part = True
1153-
1154- # XXX: Here we define these things as dynamic properties because our
1155- # temporary hack to fix bug 697824 relies on changing the board's
1156- # serial_tty at run time.
1157- _extra_serial_opts = None
1158- _live_serial_opts = None
1159- _serial_tty = None
1160-
1161- @classproperty
1162- def serial_tty(cls):
1163- # This is just to make sure no callsites use .serial_tty before
1164- # calling set_appropriate_serial_tty(). If we had this in the first
1165- # place we'd have uncovered bug 710971 before releasing.
1166- raise AttributeError(
1167- "You must not use this attribute before calling "
1168- "set_appropriate_serial_tty")
1169-
1170- @classproperty
1171- def live_serial_opts(cls):
1172- return cls._live_serial_opts % cls.serial_tty
1173-
1174- @classproperty
1175- def extra_serial_opts(cls):
1176- return cls._extra_serial_opts % cls.serial_tty
1177-
1178- @classmethod
1179- def set_appropriate_serial_tty(cls, chroot_dir):
1180+
1181+ def __init__(self):
1182+ super(OmapConfig, self).__init__()
1183+ self.kernel_flavors = ['linaro-omap4', 'linaro-lt-omap',
1184+ 'linaro-omap', 'omap4']
1185+ self.bootloader_file_in_boot_part = True
1186+ # XXX: Here we define these things as dynamic properties because our
1187+ # temporary hack to fix bug 697824 relies on changing the board's
1188+ # serial_tty at run time.
1189+ self._serial_tty = None
1190+
1191+ # XXX: when killing v1 hwpack this should be safely removed.
1192+ def _get_serial_tty(self):
1193+ return self._serial_tty
1194+
1195+ def _set_serial_tty(self, value):
1196+ self._serial_tty = value
1197+
1198+ serial_tty = property(_get_serial_tty, _set_serial_tty)
1199+
1200+ def set_appropriate_serial_tty(self, chroot_dir):
1201 """Set the appropriate serial_tty depending on the kernel used.
1202
1203 If the kernel found in the chroot dir is << 2.6.36 we use tyyS2, else
1204 we use the default value (_serial_tty).
1205 """
1206 # XXX: delete this method when hwpacks V1 can die
1207- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1208+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1209 # XXX: This is also part of our temporary hack to fix bug 697824.
1210- cls.serial_tty = classproperty(lambda cls: cls._serial_tty)
1211+ # cls.serial_tty = classproperty(lambda cls: cls._serial_tty)
1212 vmlinuz = _get_file_matching(
1213 os.path.join(chroot_dir, 'boot', 'vmlinuz*'))
1214 basename = os.path.basename(vmlinuz)
1215@@ -902,135 +902,134 @@
1216 if match is not None:
1217 minor_version = match.group(1)
1218 if int(minor_version) < 36:
1219- cls.serial_tty = classproperty(lambda cls: 'ttyS2')
1220+ self.serial_tty = 'ttyS2'
1221
1222- @classmethod
1223- def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
1224+ def make_boot_files(self, bootloader_parts_dir, is_live, is_lowmem,
1225 consoles, chroot_dir, rootfs_id, boot_dir,
1226 boot_device_or_file):
1227 # XXX: This is also part of our temporary hack to fix bug 697824; we
1228 # need to call set_appropriate_serial_tty() before doing anything that
1229- # may use cls.serial_tty.
1230- if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
1231- cls.set_appropriate_serial_tty(chroot_dir)
1232- super(OmapConfig, cls).make_boot_files(
1233+ # may use self.serial_tty.
1234+ if self.hwpack_format == HardwarepackHandler.FORMAT_1:
1235+ self.set_appropriate_serial_tty(chroot_dir)
1236+ super(OmapConfig, self).make_boot_files(
1237 bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
1238 rootfs_id, boot_dir, boot_device_or_file)
1239
1240- @classmethod
1241- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1242+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1243 boot_device_or_file, k_img_data, i_img_data,
1244 d_img_data):
1245 # XXX: delete this method when hwpacks V1 can die
1246- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1247- install_omap_boot_loader(chroot_dir, boot_dir, cls)
1248- make_uImage(cls.load_addr, k_img_data, boot_dir)
1249+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1250+ install_omap_boot_loader(chroot_dir, boot_dir, self)
1251+ make_uImage(self.load_addr, k_img_data, boot_dir)
1252 make_uInitrd(i_img_data, boot_dir)
1253 make_dtb(d_img_data, boot_dir)
1254- boot_script_path = os.path.join(boot_dir, cls.boot_script)
1255+ boot_script_path = os.path.join(boot_dir, self.boot_script)
1256 make_boot_script(boot_env, boot_script_path)
1257 make_boot_ini(boot_script_path, boot_dir)
1258
1259
1260 class BeagleConfig(OmapConfig):
1261- bootloader_flavor = 'omap3_beagle'
1262- dtb_name = 'omap3-beagle.dtb'
1263- _serial_tty = 'ttyO2'
1264- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
1265- _live_serial_opts = 'serialtty=%s'
1266- kernel_addr = '0x80000000'
1267- dtb_addr = '0x815f0000'
1268- initrd_addr = '0x81600000'
1269- load_addr = '0x80008000'
1270- boot_script = 'boot.scr'
1271- extra_boot_args_options = (
1272- 'earlyprintk fixrtc nocompcache vram=12M '
1273- 'omapfb.mode=dvi:1280x720MR-16@60 mpurate=${mpurate}')
1274+
1275+ def __init__(self):
1276+ super(BeagleConfig, self).__init__()
1277+ self.boot_script = 'boot.scr'
1278+ self.bootloader_flavor = 'omap3_beagle'
1279+ self.dtb_addr = '0x815f0000'
1280+ self.dtb_name = 'omap3-beagle.dtb'
1281+ self.extra_boot_args_options = (
1282+ 'earlyprintk fixrtc nocompcache vram=12M '
1283+ 'omapfb.mode=dvi:1280x720MR-16@60 mpurate=${mpurate}')
1284+ self.initrd_addr = '0x81600000'
1285+ self.kernel_addr = '0x80000000'
1286+ self.load_addr = '0x80008000'
1287+ self._serial_tty = 'ttyO2'
1288+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1289+ self._live_serial_opts = 'serialtty=%s'
1290
1291
1292 class OveroConfig(OmapConfig):
1293- bootloader_flavor = 'omap3_overo'
1294- dtb_name = 'omap3-overo.dtb'
1295- _serial_tty = 'ttyO2'
1296- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
1297- kernel_addr = '0x80000000'
1298- dtb_addr = '0x815f0000'
1299- initrd_addr = '0x81600000'
1300- load_addr = '0x80008000'
1301- boot_script = 'boot.scr'
1302- extra_boot_args_options = (
1303- 'earlyprintk mpurate=${mpurate} vram=12M '
1304- 'omapdss.def_disp=${defaultdisplay} omapfb.mode=dvi:${dvimode}')
1305+ def __init__(self):
1306+ super(OveroConfig, self).__init__()
1307+ self.boot_script = 'boot.scr'
1308+ self.bootloader_flavor = 'omap3_overo'
1309+ self.dtb_addr = '0x815f0000'
1310+ self.dtb_name = 'omap3-overo.dtb'
1311+ self.extra_boot_args_options = (
1312+ 'earlyprintk mpurate=${mpurate} vram=12M '
1313+ 'omapdss.def_disp=${defaultdisplay} omapfb.mode=dvi:${dvimode}')
1314+ self.initrd_addr = '0x81600000'
1315+ self.kernel_addr = '0x80000000'
1316+ self.load_addr = '0x80008000'
1317+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1318+ self._serial_tty = 'ttyO2'
1319
1320
1321 class PandaConfig(OmapConfig):
1322- bootloader_flavor = 'omap4_panda'
1323- dtb_name = 'omap4-panda.dtb'
1324- _serial_tty = 'ttyO2'
1325- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
1326- _live_serial_opts = 'serialtty=%s'
1327- kernel_addr = '0x80200000'
1328- dtb_addr = '0x815f0000'
1329- initrd_addr = '0x81600000'
1330- load_addr = '0x80008000'
1331- boot_script = 'boot.scr'
1332- extra_boot_args_options = (
1333- 'earlyprintk fixrtc nocompcache vram=48M '
1334- 'omapfb.vram=0:24M mem=456M@0x80000000 mem=512M@0xA0000000')
1335+ def __init__(self):
1336+ super(PandaConfig, self).__init__()
1337+ self._serial_tty = 'ttyO2'
1338+ self.boot_script = 'boot.scr'
1339+ self.bootloader_flavor = 'omap4_panda'
1340+ self.dtb_addr = '0x815f0000'
1341+ self.dtb_name = 'omap4-panda.dtb'
1342+ self.extra_boot_args_options = (
1343+ 'earlyprintk fixrtc nocompcache vram=48M '
1344+ 'omapfb.vram=0:24M mem=456M@0x80000000 mem=512M@0xA0000000')
1345+ self.initrd_addr = '0x81600000'
1346+ self.kernel_addr = '0x80200000'
1347+ self.load_addr = '0x80008000'
1348+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1349+ self._live_serial_opts = 'serialtty=%s'
1350
1351
1352 class IgepConfig(BeagleConfig):
1353- bootloader_file_in_boot_part = False
1354- bootloader_flavor = None
1355- dtb_name = 'isee-igep-v2.dtb'
1356+ def __init__(self):
1357+ super(IgepConfig, self).__init__()
1358+ self.bootloader_file_in_boot_part = False
1359+ self.bootloader_flavor = None
1360+ self.dtb_name = 'isee-igep-v2.dtb'
1361
1362- @classmethod
1363- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1364+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1365 boot_device_or_file, k_img_data, i_img_data,
1366 d_img_data):
1367 # XXX: delete this method when hwpacks V1 can die
1368- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1369- make_uImage(cls.load_addr, k_img_data, boot_dir)
1370+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1371+ make_uImage(self.load_addr, k_img_data, boot_dir)
1372 make_uInitrd(i_img_data, boot_dir)
1373 make_dtb(d_img_data, boot_dir)
1374- boot_script_path = os.path.join(boot_dir, cls.boot_script)
1375+ boot_script_path = os.path.join(boot_dir, self.boot_script)
1376 make_boot_script(boot_env, boot_script_path)
1377 make_boot_ini(boot_script_path, boot_dir)
1378
1379
1380 class Ux500Config(BoardConfig):
1381- serial_tty = 'ttyAMA2'
1382- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
1383- _live_serial_opts = 'serialtty=%s'
1384- kernel_addr = '0x00100000'
1385- initrd_addr = '0x08000000'
1386- load_addr = '0x00008000'
1387- kernel_flavors = ['u8500', 'ux500']
1388- boot_script = 'flash.scr'
1389- extra_boot_args_options = (
1390- 'earlyprintk rootdelay=1 fixrtc nocompcache '
1391- 'mem=96M@0 mem_modem=32M@96M mem=44M@128M pmem=22M@172M '
1392- 'mem=30M@194M mem_mali=32M@224M pmem_hwb=54M@256M '
1393- 'hwmem=48M@302M mem=152M@360M')
1394- mmc_option = '1:1'
1395-
1396- @classproperty
1397- def live_serial_opts(cls):
1398- return cls._live_serial_opts % cls.serial_tty
1399-
1400- @classproperty
1401- def extra_serial_opts(cls):
1402- return cls._extra_serial_opts % cls.serial_tty
1403-
1404- @classmethod
1405- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1406+ def __init__(self):
1407+ super(Ux500Config, self).__init__()
1408+ self.boot_script = 'flash.scr'
1409+ self.extra_boot_args_options = (
1410+ 'earlyprintk rootdelay=1 fixrtc nocompcache '
1411+ 'mem=96M@0 mem_modem=32M@96M mem=44M@128M pmem=22M@172M '
1412+ 'mem=30M@194M mem_mali=32M@224M pmem_hwb=54M@256M '
1413+ 'hwmem=48M@302M mem=152M@360M')
1414+ self.initrd_addr = '0x08000000'
1415+ self.kernel_addr = '0x00100000'
1416+ self.kernel_flavors = ['u8500', 'ux500']
1417+ self.load_addr = '0x00008000'
1418+ self.mmc_option = '1:1'
1419+ self.serial_tty = 'ttyAMA2'
1420+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1421+ self._live_serial_opts = 'serialtty=%s'
1422+
1423+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1424 boot_device_or_file, k_img_data, i_img_data,
1425 d_img_data):
1426 # XXX: delete this method when hwpacks V1 can die
1427- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1428- make_uImage(cls.load_addr, k_img_data, boot_dir)
1429+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1430+ make_uImage(self.load_addr, k_img_data, boot_dir)
1431 make_uInitrd(i_img_data, boot_dir)
1432- boot_script_path = os.path.join(boot_dir, cls.boot_script)
1433+ boot_script_path = os.path.join(boot_dir, self.boot_script)
1434 make_boot_script(boot_env, boot_script_path)
1435
1436
1437@@ -1040,15 +1039,16 @@
1438 Note that the Snowball board needs a loader partition on the
1439 internal eMMC flash to boot. That partition is created with
1440 the SnowballConfigImage configuration.'''
1441+ def __init__(self):
1442+ super(SnowballSdConfig, self).__init__()
1443
1444- @classmethod
1445- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1446+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1447 boot_device_or_file, k_img_data, i_img_data,
1448 d_img_data):
1449 # XXX: delete this method when hwpacks V1 can die
1450- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1451- make_uImage(cls.load_addr, k_img_data, boot_dir)
1452- boot_script_path = os.path.join(boot_dir, cls.boot_script)
1453+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1454+ make_uImage(self.load_addr, k_img_data, boot_dir)
1455+ boot_script_path = os.path.join(boot_dir, self.boot_script)
1456 make_boot_script(boot_env, boot_script_path)
1457
1458
1459@@ -1056,16 +1056,18 @@
1460 '''Use only with --image option. Creates a raw image which contains an
1461 additional (raw) loader partition, containing some boot stages
1462 and u-boot.'''
1463- # Boot ROM looks for a boot table of contents (TOC) at 0x20000
1464- # Actually, it first looks at address 0, but that's where l-m-c
1465- # puts the MBR, so the boot loader skips that address.
1466- supports_writing_to_mmc = False
1467 SNOWBALL_LOADER_START_S = (128 * 1024) / SECTOR_SIZE
1468- snowball_startup_files_config = 'startfiles.cfg'
1469 TOC_SIZE = 512
1470
1471- @classmethod
1472- def get_v1_sfdisk_cmd(cls, should_align_boot_part=None):
1473+ def __init__(self):
1474+ super(SnowballEmmcConfig, self).__init__()
1475+ # Boot ROM looks for a boot table of contents (TOC) at 0x20000
1476+ # Actually, it first looks at address 0, but that's where l-m-c
1477+ # puts the MBR, so the boot loader skips that address.
1478+ self.supports_writing_to_mmc = False
1479+ self.snowball_startup_files_config = 'startfiles.cfg'
1480+
1481+ def get_v1_sfdisk_cmd(self, should_align_boot_part=None):
1482 """Return the sfdisk command to partition the media.
1483
1484 :param should_align_boot_part: Ignored.
1485@@ -1083,68 +1085,64 @@
1486 # with the usual SECTOR_SIZE of 0x200.
1487 # (sector 0 is MBR / partition table)
1488 loader_start, loader_end, loader_len = align_partition(
1489- SnowballEmmcConfig.SNOWBALL_LOADER_START_S,
1490- cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
1491+ self.SNOWBALL_LOADER_START_S,
1492+ self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
1493
1494 boot_start, boot_end, boot_len = align_partition(
1495- loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1496+ loader_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1497 # we ignore _root_end / _root_len and return an sfdisk command to
1498 # instruct the use of all remaining space; XXX if we had some root size
1499 # config, we could do something more sensible
1500 root_start, _root_end, _root_len = align_partition(
1501- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1502+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1503
1504 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
1505 loader_start, loader_len, boot_start, boot_len, root_start)
1506
1507- @classmethod
1508- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1509+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1510 boot_device_or_file, k_img_data, i_img_data,
1511 d_img_data):
1512 # XXX: delete this method when hwpacks V1 can die
1513- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1514- make_uImage(cls.load_addr, k_img_data, boot_dir)
1515- boot_script_path = os.path.join(boot_dir, cls.boot_script)
1516+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1517+ make_uImage(self.load_addr, k_img_data, boot_dir)
1518+ boot_script_path = os.path.join(boot_dir, self.boot_script)
1519 make_boot_script(boot_env, boot_script_path)
1520- cls.populate_raw_partition(boot_device_or_file, chroot_dir)
1521+ self.populate_raw_partition(boot_device_or_file, chroot_dir)
1522
1523- @classmethod
1524- def populate_raw_partition(cls, boot_device_or_file, chroot_dir):
1525+ def populate_raw_partition(self, boot_device_or_file, chroot_dir):
1526 # Populate created raw partition with TOC and startup files.
1527 _, toc_filename = tempfile.mkstemp()
1528- config_files_dir = cls.snowball_config(chroot_dir)
1529- new_files = cls.get_file_info(chroot_dir, config_files_dir)
1530+ config_files_dir = self.snowball_config(chroot_dir)
1531+ new_files = self.get_file_info(chroot_dir, config_files_dir)
1532 with open(toc_filename, 'wb') as toc:
1533- cls.create_toc(toc, new_files)
1534- cls.install_snowball_boot_loader(toc_filename, new_files,
1535+ self.create_toc(toc, new_files)
1536+ self.install_snowball_boot_loader(toc_filename, new_files,
1537 boot_device_or_file,
1538- cls.SNOWBALL_LOADER_START_S,
1539- cls.delete_startupfiles)
1540- cls.delete_file(toc_filename)
1541- if cls.delete_startupfiles:
1542- cls.delete_file(os.path.join(config_files_dir,
1543- cls.snowball_startup_files_config))
1544+ self.SNOWBALL_LOADER_START_S,
1545+ self.delete_startupfiles)
1546+ self.delete_file(toc_filename)
1547+ if self.delete_startupfiles:
1548+ self.delete_file(os.path.join(config_files_dir,
1549+ self.snowball_startup_files_config))
1550
1551- @classmethod
1552- def snowball_config(cls, chroot_dir):
1553+ def snowball_config(self, chroot_dir):
1554 # We will find the startupfiles in the target boot partition.
1555 return os.path.join(chroot_dir, 'boot')
1556
1557- @classproperty
1558- def delete_startupfiles(cls):
1559+ @property
1560+ def delete_startupfiles(self):
1561 # The startupfiles will have been installed to the target boot
1562 # partition by the hwpack, and should be deleted so we don't leave
1563 # them on the target system.
1564 return True
1565
1566- @classmethod
1567- def install_snowball_boot_loader(cls, toc_file_name, files,
1568+ def install_snowball_boot_loader(self, toc_file_name, files,
1569 boot_device_or_file, start_sector,
1570 delete_startupfiles=False):
1571 ''' Copies TOC and boot files into the boot partition.
1572 A sector size of 1 is used for some files, as they do not
1573 necessarily start on an even address. '''
1574- assert os.path.getsize(toc_file_name) <= cls.TOC_SIZE
1575+ assert os.path.getsize(toc_file_name) <= self.TOC_SIZE
1576 _dd(toc_file_name, boot_device_or_file, seek=start_sector)
1577
1578 for file in files:
1579@@ -1159,16 +1157,14 @@
1580 seek_sectors = start_sector + file['offset'] / SECTOR_SIZE
1581 _dd(filename, boot_device_or_file, seek=seek_sectors)
1582 if delete_startupfiles:
1583- cls.delete_file(filename)
1584+ self.delete_file(filename)
1585
1586- @classmethod
1587- def delete_file(cls, file_path):
1588+ def delete_file(self, file_path):
1589 cmd = ["rm", "%s" % file_path]
1590 proc = cmd_runner.run(cmd, as_root=True)
1591 proc.wait()
1592
1593- @classmethod
1594- def create_toc(cls, f, files):
1595+ def create_toc(self, f, files):
1596 ''' Writes a table of contents of the boot binaries.
1597 Boot rom searches this table to find the binaries.'''
1598 # Format string means: < little endian,
1599@@ -1190,15 +1186,14 @@
1600 file['section_name'])
1601 f.write(data)
1602
1603- @classmethod
1604- def get_file_info(cls, chroot_dir, config_files_dir):
1605+ def get_file_info(self, chroot_dir, config_files_dir):
1606 ''' Fills in the offsets of files that are located in
1607 non-absolute memory locations depending on their sizes.'
1608 Also fills in file sizes'''
1609- ofs = cls.TOC_SIZE
1610+ ofs = self.TOC_SIZE
1611 files = []
1612 with open(os.path.join(config_files_dir,
1613- cls.snowball_startup_files_config),
1614+ self.snowball_startup_files_config),
1615 'r') as info_file:
1616 for line in info_file:
1617 file_data = line.split()
1618@@ -1229,23 +1224,16 @@
1619
1620
1621 class Mx5Config(BoardConfig):
1622- serial_tty = 'ttymxc0'
1623- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
1624- _live_serial_opts = 'serialtty=%s'
1625- boot_script = 'boot.scr'
1626- mmc_part_offset = 1
1627- mmc_option = '0:2'
1628-
1629- @classproperty
1630- def live_serial_opts(cls):
1631- return cls._live_serial_opts % cls.serial_tty
1632-
1633- @classproperty
1634- def extra_serial_opts(cls):
1635- return cls._extra_serial_opts % cls.serial_tty
1636-
1637- @classmethod
1638- def get_v1_sfdisk_cmd(cls, should_align_boot_part=None):
1639+ def __init__(self):
1640+ super(Mx5Config, self).__init__()
1641+ self.boot_script = 'boot.scr'
1642+ self.mmc_option = '0:2'
1643+ self.mmc_part_offset = 1
1644+ self.serial_tty = 'ttymxc0'
1645+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
1646+ self._live_serial_opts = 'serialtty=%s'
1647+
1648+ def get_v1_sfdisk_cmd(self, should_align_boot_part=None):
1649 """Return the sfdisk command to partition the media.
1650
1651 :param should_align_boot_part: Ignored.
1652@@ -1259,103 +1247,107 @@
1653 # onwards, so it's safer to just start at the first sector, sector 1
1654 # (sector 0 is MBR / partition table)
1655 loader_start, loader_end, loader_len = align_partition(
1656- 1, cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
1657+ 1, self.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
1658
1659 boot_start, boot_end, boot_len = align_partition(
1660- loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1661+ loader_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1662 # we ignore _root_end / _root_len and return a sfdisk command to
1663 # instruct the use of all remaining space; XXX if we had some root size
1664 # config, we could do something more sensible
1665 root_start, _root_end, _root_len = align_partition(
1666- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1667+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1668
1669 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
1670 loader_start, loader_len, boot_start, boot_len, root_start)
1671
1672- @classmethod
1673- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1674+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1675 boot_device_or_file, k_img_data, i_img_data,
1676 d_img_data):
1677 # XXX: delete this method when hwpacks V1 can die
1678- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1679- with cls.hardwarepack_handler:
1680- bootloader_file = cls.get_file('bootloader_file',
1681+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1682+ with self.hardwarepack_handler:
1683+ bootloader_file = self.get_file('bootloader_file',
1684 default=os.path.join(
1685- chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor,
1686+ chroot_dir, 'usr', 'lib', 'u-boot', self.bootloader_flavor,
1687 'u-boot.imx'))
1688 install_mx5_boot_loader(bootloader_file, boot_device_or_file,
1689- cls.LOADER_MIN_SIZE_S)
1690- make_uImage(cls.load_addr, k_img_data, boot_dir)
1691+ self.LOADER_MIN_SIZE_S)
1692+ make_uImage(self.load_addr, k_img_data, boot_dir)
1693 make_uInitrd(i_img_data, boot_dir)
1694 make_dtb(d_img_data, boot_dir)
1695- boot_script_path = os.path.join(boot_dir, cls.boot_script)
1696+ boot_script_path = os.path.join(boot_dir, self.boot_script)
1697 make_boot_script(boot_env, boot_script_path)
1698
1699
1700 class Mx51Config(Mx5Config):
1701- kernel_addr = '0x90000000'
1702- dtb_addr = '0x91ff0000'
1703- initrd_addr = '0x92000000'
1704- load_addr = '0x90008000'
1705- kernel_flavors = ['linaro-mx51', 'linaro-lt-mx5']
1706+ def __init__(self):
1707+ super(Mx51Config, self).__init__()
1708+ self.dtb_addr = '0x91ff0000'
1709+ self.initrd_addr = '0x92000000'
1710+ self.kernel_addr = '0x90000000'
1711+ self.kernel_flavors = ['linaro-mx51', 'linaro-lt-mx5']
1712+ self.load_addr = '0x90008000'
1713
1714
1715 class Mx53Config(Mx5Config):
1716- kernel_addr = '0x70000000'
1717- dtb_addr = '0x71ff0000'
1718- initrd_addr = '0x72000000'
1719- load_addr = '0x70008000'
1720- kernel_flavors = ['linaro-lt-mx53', 'linaro-lt-mx5']
1721+ def __init__(self):
1722+ super(Mx53Config, self).__init__()
1723+ self.dtb_addr = '0x71ff0000'
1724+ self.initrd_addr = '0x72000000'
1725+ self.kernel_addr = '0x70000000'
1726+ self.kernel_flavors = ['linaro-lt-mx53', 'linaro-lt-mx5']
1727+ self.load_addr = '0x70008000'
1728
1729
1730 class EfikamxConfig(Mx51Config):
1731- bootloader_flavor = 'efikamx'
1732- dtb_name = 'genesi-efikamx.dtb'
1733+ def __init__(self):
1734+ super(EfikamxConfig, self).__init__()
1735+ self.bootloader_flavor = 'efikamx'
1736+ self.dtb_name = 'genesi-efikamx.dtb'
1737
1738
1739 class EfikasbConfig(Mx51Config):
1740- bootloader_flavor = 'efikasb'
1741- dtb_name = 'genesi-efikasb.dtb'
1742+ def __init__(self):
1743+ super(EfikasbConfig, self).__init__()
1744+ self.bootloader_flavor = 'efikasb'
1745+ self.dtb_name = 'genesi-efikasb.dtb'
1746
1747
1748 class Mx51evkConfig(Mx51Config):
1749- bootloader_flavor = 'mx51evk'
1750- dtb_name = 'mx51-babbage.dtb'
1751+ def __init__(self):
1752+ super(Mx51evkConfig, self).__init__()
1753+ self.bootloader_flavor = 'mx51evk'
1754+ self.dtb_name = 'mx51-babbage.dtb'
1755
1756
1757 class Mx53LoCoConfig(Mx53Config):
1758- bootloader_flavor = 'mx53loco'
1759- dtb_name = 'mx53-loco.dtb'
1760+ def __init__(self):
1761+ super(Mx53LoCoConfig, self).__init__()
1762+ self.bootloader_flavor = 'mx53loco'
1763+ self.dtb_name = 'mx53-loco.dtb'
1764
1765
1766 class VexpressConfig(BoardConfig):
1767- bootloader_flavor = 'ca9x4_ct_vxp'
1768- bootloader_file_in_boot_part = True
1769- serial_tty = 'ttyAMA0'
1770- _extra_serial_opts = 'console=tty0 console=%s,38400n8'
1771- _live_serial_opts = 'serialtty=%s'
1772- kernel_addr = '0x60000000'
1773- initrd_addr = '0x62000000'
1774- load_addr = '0x60008000'
1775- kernel_flavors = ['linaro-vexpress']
1776- boot_script = 'boot.scr'
1777- # ARM Boot Monitor is used to load u-boot, uImage etc. into flash and
1778- # only allows for FAT16
1779- fat_size = 16
1780-
1781- @classproperty
1782- def live_serial_opts(cls):
1783- return cls._live_serial_opts % cls.serial_tty
1784-
1785- @classproperty
1786- def extra_serial_opts(cls):
1787- return cls._extra_serial_opts % cls.serial_tty
1788-
1789- @classmethod
1790- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1791+ def __init__(self):
1792+ super(VexpressConfig, self).__init__()
1793+ self.boot_script = 'boot.scr'
1794+ self.bootloader_file_in_boot_part = True
1795+ self.bootloader_flavor = 'ca9x4_ct_vxp'
1796+ # ARM Boot Monitor is used to load u-boot, uImage etc. into flash and
1797+ # only allows for FAT16
1798+ self.fat_size = 16
1799+ self.initrd_addr = '0x62000000'
1800+ self.kernel_addr = '0x60000000'
1801+ self.kernel_flavors = ['linaro-vexpress']
1802+ self.load_addr = '0x60008000'
1803+ self.serial_tty = 'ttyAMA0'
1804+ self._extra_serial_opts = 'console=tty0 console=%s,38400n8'
1805+ self._live_serial_opts = 'serialtty=%s'
1806+
1807+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1808 boot_device_or_file, k_img_data, i_img_data,
1809 d_img_data):
1810- make_uImage(cls.load_addr, k_img_data, boot_dir)
1811+ make_uImage(self.load_addr, k_img_data, boot_dir)
1812 make_uInitrd(i_img_data, boot_dir)
1813
1814
1815@@ -1363,22 +1355,23 @@
1816 # For now, this is a duplicate of VexpressConfig.
1817 # In future, there will also be A5 and A15 variants.
1818 # For all of these, there should never be any V1 hardware packs.
1819- pass
1820+ def __init__(self):
1821+ super(VexpressA9Config, self).__init__()
1822
1823
1824 class FastModelConfig(BoardConfig):
1825- supports_writing_to_mmc = False
1826+ def __init__(self):
1827+ super(FastModelConfig, self).__init__()
1828+ self.supports_writing_to_mmc = False
1829
1830- @classmethod
1831- def _get_bootcmd(cls, i_img_data, d_img_data):
1832+ def _get_bootcmd(self, i_img_data, d_img_data):
1833 """Get the bootcmd for FastModel.
1834
1835 We override this as we don't do uboot.
1836 """
1837 return ""
1838
1839- @classmethod
1840- def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir,
1841+ def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
1842 boot_device_or_file, k_img_data, i_img_data,
1843 d_img_data):
1844 output_dir = os.path.dirname(boot_device_or_file)
1845@@ -1395,16 +1388,14 @@
1846
1847
1848 class SamsungConfig(BoardConfig):
1849- @classproperty
1850- def extra_serial_opts(cls):
1851- return cls._extra_serial_opts % cls.serial_tty
1852+ def __init__(self):
1853+ super(SamsungConfig, self).__init__()
1854+ self._extra_serial_opts = None
1855
1856- @classmethod
1857- def get_v1_sfdisk_cmd(cls, should_align_boot_part=False):
1858+ def get_v1_sfdisk_cmd(self, should_align_boot_part=False):
1859 # bootloaders partition needs to hold BL1, U-Boot environment, and BL2
1860- loaders_min_len = (
1861- cls.samsung_bl1_start + cls.samsung_bl1_len + cls.samsung_bl2_len +
1862- cls.samsung_env_len)
1863+ loaders_min_len = (self.samsung_bl1_start + self.samsung_bl1_len +
1864+ self.samsung_bl2_len + self.samsung_env_len)
1865
1866 # bootloaders partition
1867 loaders_start, loaders_end, loaders_len = align_partition(
1868@@ -1412,44 +1403,42 @@
1869
1870 # FAT boot partition
1871 boot_start, boot_end, boot_len = align_partition(
1872- loaders_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1873+ loaders_end + 1, self.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1874
1875 # root partition
1876 # we ignore _root_end / _root_len and return a sfdisk command to
1877 # instruct the use of all remaining space; XXX if we had some root size
1878 # config, we could do something more sensible
1879 root_start, _root_end, _root_len = align_partition(
1880- boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1881+ boot_end + 1, self.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
1882
1883 return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
1884 loaders_start, loaders_len, boot_start, boot_len, root_start)
1885
1886- @classmethod
1887- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1888+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
1889 boot_device_or_file, k_img_data, i_img_data,
1890 d_img_data):
1891 # XXX: delete this method when hwpacks V1 can die
1892- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1893- cls.install_samsung_boot_loader(cls._get_samsung_spl(chroot_dir),
1894- cls._get_samsung_bootloader(chroot_dir), boot_device_or_file)
1895- env_size = cls.samsung_env_len * SECTOR_SIZE
1896+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1897+ self.install_samsung_boot_loader(self._get_samsung_spl(chroot_dir),
1898+ self._get_samsung_bootloader(chroot_dir), boot_device_or_file)
1899+ env_size = self.samsung_env_len * SECTOR_SIZE
1900 env_file = make_flashable_env(boot_env, env_size)
1901- _dd(env_file, boot_device_or_file, seek=cls.samsung_env_start)
1902+ _dd(env_file, boot_device_or_file, seek=self.samsung_env_start)
1903
1904- make_uImage(cls.load_addr, k_img_data, boot_dir)
1905+ make_uImage(self.load_addr, k_img_data, boot_dir)
1906 make_uInitrd(i_img_data, boot_dir)
1907
1908 # unused at the moment once FAT support enabled for the
1909 # Samsung u-boot this can be used bug 727978
1910- boot_script_path = os.path.join(boot_dir, cls.boot_script)
1911+ boot_script_path = os.path.join(boot_dir, self.boot_script)
1912 make_boot_script(boot_env, boot_script_path)
1913
1914- @classmethod
1915- def _get_samsung_spl(cls, chroot_dir):
1916+ def _get_samsung_spl(self, chroot_dir):
1917 # XXX: delete this method when hwpacks V1 can die
1918- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1919+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1920 spl_dir = os.path.join(
1921- chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor)
1922+ chroot_dir, 'usr', 'lib', 'u-boot', self.bootloader_flavor)
1923 old_spl_path = os.path.join(spl_dir, 'v310_mmc_spl.bin')
1924 new_spl_path = os.path.join(spl_dir, 'u-boot-mmc-spl.bin')
1925 spl_path_origen2 = os.path.join(spl_dir, 'origen-spl.bin')
1926@@ -1479,49 +1468,48 @@
1927 % (old_spl_path, new_spl_path))
1928 return spl_file
1929
1930- @classmethod
1931- def _get_samsung_bootloader(cls, chroot_dir):
1932+ def _get_samsung_bootloader(self, chroot_dir):
1933 # XXX: delete this method when hwpacks V1 can die
1934- assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1935+ assert self.hwpack_format == HardwarepackHandler.FORMAT_1
1936 bootloader_file = os.path.join(
1937- chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor,
1938+ chroot_dir, 'usr', 'lib', 'u-boot', self.bootloader_flavor,
1939 'u-boot.bin')
1940 return bootloader_file
1941
1942- @classmethod
1943- def populate_raw_partition(cls, boot_device_or_file, chroot_dir):
1944+ def populate_raw_partition(self, boot_device_or_file, chroot_dir):
1945 # Zero the env so that the boot_script will get loaded
1946- _dd("/dev/zero", boot_device_or_file, count=cls.samsung_env_len,
1947- seek=cls.samsung_env_start)
1948+ _dd("/dev/zero", boot_device_or_file, count=self.samsung_env_len,
1949+ seek=self.samsung_env_start)
1950 # Populate created raw partition with BL1 and u-boot
1951 spl_file = os.path.join(chroot_dir, 'boot', 'u-boot-mmc-spl.bin')
1952 assert os.path.getsize(spl_file) <= (
1953- cls.samsung_bl1_len * SECTOR_SIZE), (
1954+ self.samsung_bl1_len * SECTOR_SIZE), (
1955 "%s is larger than Samsung BL1 size" % spl_file)
1956- _dd(spl_file, boot_device_or_file, seek=cls.samsung_bl1_start)
1957+ _dd(spl_file, boot_device_or_file, seek=self.samsung_bl1_start)
1958 uboot_file = os.path.join(chroot_dir, 'boot', 'u-boot.bin')
1959 assert os.path.getsize(uboot_file) <= (
1960- cls.samsung_bl2_len * SECTOR_SIZE), (
1961+ self.samsung_bl2_len * SECTOR_SIZE), (
1962 "%s is larger than Samsung BL2 size" % uboot_file)
1963- _dd(uboot_file, boot_device_or_file, seek=cls.samsung_bl2_start)
1964+ _dd(uboot_file, boot_device_or_file, seek=self.samsung_bl2_start)
1965
1966
1967 class SMDKV310Config(SamsungConfig):
1968- bootloader_flavor = 'smdkv310'
1969- serial_tty = 'ttySAC1'
1970- _extra_serial_opts = 'console=%s,115200n8'
1971- kernel_addr = '0x40007000'
1972- initrd_addr = '0x42000000'
1973- load_addr = '0x40008000'
1974- kernel_flavors = ['s5pv310']
1975- boot_script = 'boot.scr'
1976- mmc_part_offset = 1
1977- mmc_option = '0:2'
1978+ def __init__(self):
1979+ super(SMDKV310Config, self).__init__()
1980+ self.boot_script = 'boot.scr'
1981+ self.bootloader_flavor = 'smdkv310'
1982+ self.initrd_addr = '0x42000000'
1983+ self.kernel_addr = '0x40007000'
1984+ self.kernel_flavors = ['s5pv310']
1985+ self.load_addr = '0x40008000'
1986+ self.mmc_option = '0:2'
1987+ self.mmc_part_offset = 1
1988+ self.serial_tty = 'ttySAC1'
1989+ self._extra_serial_opts = 'console=%s,115200n8'
1990
1991- @classmethod
1992- def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
1993+ def _get_boot_env(self, is_live, is_lowmem, consoles, rootfs_id,
1994 i_img_data, d_img_data):
1995- boot_env = super(SamsungConfig, cls)._get_boot_env(
1996+ boot_env = super(SamsungConfig, self)._get_boot_env(
1997 is_live, is_lowmem, consoles, rootfs_id, i_img_data, d_img_data)
1998
1999 boot_env["ethact"] = "smc911x-0"
2000@@ -1531,60 +1519,59 @@
2001
2002
2003 class OrigenConfig(SamsungConfig):
2004- bootloader_flavor = 'origen'
2005- serial_tty = 'ttySAC2'
2006- _extra_serial_opts = 'console=%s,115200n8'
2007- kernel_addr = '0x40007000'
2008- initrd_addr = '0x42000000'
2009- load_addr = '0x40008000'
2010- kernel_flavors = ['origen']
2011- boot_script = 'boot.scr'
2012- mmc_part_offset = 1
2013- mmc_option = '0:2'
2014+ # TODO test
2015+ def __init__(self):
2016+ super(OrigenConfig, self).__init__()
2017+ self.boot_script = 'boot.scr'
2018+ self.bootloader_flavor = 'origen'
2019+ self.initrd_addr = '0x42000000'
2020+ self.kernel_addr = '0x40007000'
2021+ self.kernel_flavors = ['origen']
2022+ self.load_addr = '0x40008000'
2023+ self.mmc_option = '0:2'
2024+ self.mmc_part_offset = 1
2025+ self.serial_tty = 'ttySAC2'
2026+ self._extra_serial_opts = 'console=%s,115200n8'
2027
2028
2029 class OrigenQuadConfig(SamsungConfig):
2030- bootloader_flavor = 'origen_quad'
2031- serial_tty = 'ttySAC2'
2032- _extra_serial_opts = 'console=%s,115200n8'
2033- kernel_addr = '0x40007000'
2034- initrd_addr = '0x42000000'
2035- load_addr = '0x40008000'
2036- kernel_flavors = ['origen_quad']
2037- boot_script = 'boot.scr'
2038- mmc_part_offset = 1
2039- mmc_option = '0:2'
2040- samsung_bl1_len = 48
2041- samsung_bl2_start = 49
2042- samsung_env_start = 1073
2043+ def __init__(self):
2044+ super(OrigenQuadConfig, self).__init__()
2045+ self.boot_script = 'boot.scr'
2046+ self.bootloader_flavor = 'origen_quad'
2047+ self.initrd_addr = '0x42000000'
2048+ self.kernel_addr = '0x40007000'
2049+ self.kernel_flavors = ['origen_quad']
2050+ self.load_addr = '0x40008000'
2051+ self.mmc_option = '0:2'
2052+ self.mmc_part_offset = 1
2053+ self.samsung_bl1_len = 48
2054+ self.samsung_bl2_start = 49
2055+ self.samsung_env_start = 1073
2056+ self.serial_tty = 'ttySAC2'
2057+ self._extra_serial_opts = 'console=%s,115200n8'
2058
2059
2060 class ArndaleConfig(SamsungConfig):
2061- bootloader_flavor = 'arndale'
2062- serial_tty = 'ttySAC2'
2063- _extra_serial_opts = 'console=%s,115200n8'
2064- kernel_addr = '0x40007000'
2065- initrd_addr = '0x42000000'
2066- dtb_addr = '0x41f00000'
2067- load_addr = '0x40008000'
2068- kernel_flavors = ['arndale']
2069- boot_script = 'boot.scr'
2070- mmc_part_offset = 1
2071- mmc_option = '0:2'
2072- samsung_bl1_start = 17
2073- samsung_bl2_start = 49
2074- samsung_env_start = 1073
2075+ def __init__(self):
2076+ super(ArndaleConfig, self).__init__()
2077+ self.boot_script = 'boot.scr'
2078+ self.bootloader_flavor = 'arndale'
2079+ self.dtb_addr = '0x41f00000'
2080+ self.initrd_addr = '0x42000000'
2081+ self.kernel_addr = '0x40007000'
2082+ self.kernel_flavors = ['arndale']
2083+ self.load_addr = '0x40008000'
2084+ self.mmc_option = '0:2'
2085+ self.mmc_part_offset = 1
2086+ self.samsung_bl1_start = 17
2087+ self.samsung_bl2_start = 49
2088+ self.samsung_env_start = 1073
2089+ self.serial_tty = 'ttySAC2'
2090+ self._extra_serial_opts = 'console=%s,115200n8'
2091
2092
2093 class I386Config(BoardConfig):
2094- # define serial
2095- serial_tty = 'ttyS0'
2096- _extra_serial_opts = 'console=tty0 console=%s,115200n8'
2097- _live_serial_opts = 'serialtty=%s'
2098-
2099- # define kernel image
2100- kernel_flavors = ['generic', 'pae']
2101-
2102 # define bootloader
2103 BOOTLOADER_CMD = 'grub-install'
2104 BOOTLOADER_CFG_FILE = 'grub/grub.cfg'
2105@@ -1596,16 +1583,14 @@
2106 initrd /%s
2107 }"""
2108
2109- @classproperty
2110- def live_serial_opts(cls):
2111- return cls._live_serial_opts % cls.serial_tty
2112-
2113- @classproperty
2114- def extra_serial_opts(cls):
2115- return cls._extra_serial_opts % cls.serial_tty
2116-
2117- @classmethod
2118- def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
2119+ def __init__(self):
2120+ super(I386Config, self).__init__()
2121+ self.kernel_flavors = ['generic', 'pae']
2122+ self.serial_tty = 'ttyS0'
2123+ self._extra_serial_opts = 'console=tty0 console=%s,115200n8'
2124+ self._live_serial_opts = 'serialtty=%s'
2125+
2126+ def _make_boot_files(self, boot_env, chroot_dir, boot_dir,
2127 boot_device_or_file, k_img_data, i_img_data,
2128 d_img_data):
2129 # copy image and init into boot partition
2130@@ -1618,13 +1603,13 @@
2131 img_loop = register_loopback(boot_device_or_file, 0, img_size)
2132
2133 # install bootloader
2134- cmd_runner.run([cls.BOOTLOADER_CMD, '--boot-directory=%s' % boot_dir,
2135+ cmd_runner.run([self.BOOTLOADER_CMD, '--boot-directory=%s' % boot_dir,
2136 '--modules', 'part_msdos', img_loop],
2137 as_root=True).wait()
2138
2139 # generate loader config file
2140- loader_config = cls.BOOTLOADER_CFG % (os.path.basename(k_img_data),
2141- cls.extra_serial_opts, os.path.basename(i_img_data))
2142+ loader_config = self.BOOTLOADER_CFG % (os.path.basename(k_img_data),
2143+ self.extra_serial_opts, os.path.basename(i_img_data))
2144
2145 _, tmpfile = tempfile.mkstemp()
2146 atexit.register(os.unlink, tmpfile)
2147@@ -1632,42 +1617,59 @@
2148 fd.write(loader_config)
2149
2150 cmd_runner.run(['cp', tmpfile, os.path.join(boot_dir,
2151- cls.BOOTLOADER_CFG_FILE)], as_root=True).wait()
2152+ self.BOOTLOADER_CFG_FILE)], as_root=True).wait()
2153
2154- @classmethod
2155- def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir,
2156+ def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
2157 boot_device_or_file, k_img_data, i_img_data,
2158 d_img_data):
2159 # reuse hwpack v1 function
2160- cls._make_boot_files(boot_env, chroot_dir, boot_dir,
2161- boot_device_or_file, k_img_data, i_img_data,
2162- d_img_data)
2163+ self._make_boot_files(boot_env, chroot_dir, boot_dir,
2164+ boot_device_or_file, k_img_data, i_img_data,
2165+ d_img_data)
2166+
2167+
2168+class BoardConfigException(Exception):
2169+ """General board config exception."""
2170
2171
2172 board_configs = {
2173 'arndale': ArndaleConfig,
2174 'beagle': BeagleConfig,
2175- 'igep': IgepConfig,
2176- 'panda': PandaConfig,
2177- 'vexpress': VexpressConfig,
2178- 'vexpress-a9': VexpressA9Config,
2179- 'fastmodel': FastModelConfig,
2180- 'ux500': Ux500Config,
2181- 'snowball_sd': SnowballSdConfig,
2182- 'snowball_emmc': SnowballEmmcConfig,
2183 'efikamx': EfikamxConfig,
2184 'efikasb': EfikasbConfig,
2185+ 'fastmodel': FastModelConfig,
2186+ 'i386': I386Config,
2187+ 'igep': IgepConfig,
2188 'mx51evk': Mx51evkConfig,
2189 'mx53loco': Mx53LoCoConfig,
2190+ 'mx6qsabrelite': BoardConfig,
2191+ 'origen': OrigenConfig,
2192+ 'origen_quad': OrigenQuadConfig,
2193 'overo': OveroConfig,
2194+ 'panda': PandaConfig,
2195 'smdkv310': SMDKV310Config,
2196- 'origen': OrigenConfig,
2197- 'origen_quad': OrigenQuadConfig,
2198- 'mx6qsabrelite': BoardConfig,
2199- 'i386': I386Config,
2200+ 'snowball_emmc': SnowballEmmcConfig,
2201+ 'snowball_sd': SnowballSdConfig,
2202+ 'ux500': Ux500Config,
2203+ 'vexpress': VexpressConfig,
2204+ 'vexpress-a9': VexpressA9Config,
2205 }
2206
2207
2208+def get_board_config(board):
2209+ """Get the board configuration for the specified board.
2210+
2211+ :param board: The name of the board to get the configuration of.
2212+ :type board: str
2213+ """
2214+ clazz = board_configs.get(board, None)
2215+ if clazz:
2216+ return clazz()
2217+ else:
2218+ raise BoardConfigException("Board name '%s' has no configuration "
2219+ "available." % board)
2220+
2221+
2222 def _dd(input_file, output_file, block_size=SECTOR_SIZE, count=None, seek=None,
2223 skip=None):
2224 """Wrapper around the dd command"""

Subscribers

People subscribed via source and target branches