Merge lp:~mabac/linaro-image-tools/hwpacks-v2-snowball into lp:linaro-image-tools/11.11

Proposed by Mattias Backman
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 419
Merged at revision: 428
Proposed branch: lp:~mabac/linaro-image-tools/hwpacks-v2-snowball
Merge into: lp:linaro-image-tools/11.11
Diff against target: 471 lines (+197/-19)
4 files modified
linaro_image_tools/hwpack/config.py (+40/-1)
linaro_image_tools/hwpack/hardwarepack.py (+11/-2)
linaro_image_tools/media_create/boards.py (+97/-12)
linaro_image_tools/media_create/tests/test_media_create.py (+49/-4)
To merge this branch: bzr merge lp:~mabac/linaro-image-tools/hwpacks-v2-snowball
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+72898@code.launchpad.net

Description of the change

Hi,

This branch adds support for Snowball in hwpack 2.0 config files. Basically just by allowing for the startfiles.cfg path to be specified in metadata.

It also makes some changes to get_sfdisk_cmd() so that if the v2 field partition_layout is not specified, the V1 get_sfdisk_cmd() functions will be called. If the partition_layout field is specified we run an appropriate get_x_sfdisk_cmd() for either two or three partitions. This will need testing on each board type for me to be comfortable with this going into the next release.

The latter change is the reason for adding the metadata field 'loader_start' since the Snowball board needs the loader partition to start on 256 rather than 1 which is default.

Thanks,

Mattias

To post a comment you must log in.
Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro_image_tools/hwpack/config.py'
2--- linaro_image_tools/hwpack/config.py 2011-08-18 15:46:52 +0000
3+++ linaro_image_tools/hwpack/config.py 2011-08-25 13:51:23 +0000
4@@ -64,6 +64,7 @@
5 BOOT_MIN_SIZE_KEY = "boot_min_size"
6 ROOT_MIN_SIZE_KEY = "root_min_size"
7 LOADER_MIN_SIZE_KEY = "loader_min_size"
8+ LOADER_START_KEY = "loader_start"
9 X_LOADER_PACKAGE_KEY = "x_loader_package"
10 X_LOADER_FILE_KEY = "x_loader_file"
11 VMLINUZ_KEY = "kernel_file"
12@@ -73,11 +74,12 @@
13 BOOT_SCRIPT_KEY = 'boot_script'
14 UBOOT_IN_BOOT_PART_KEY = 'u_boot_in_boot_part'
15 EXTRA_SERIAL_OPTS_KEY = 'extra_serial_options'
16+ SNOWBALL_STARTUP_FILES_CONFIG_KEY = 'snowball_startup_files_config'
17
18 DEFINED_PARTITION_LAYOUTS = [
19 'bootfs16_rootfs',
20 'bootfs_rootfs',
21- #'reserved_bootfs_rootfs',
22+ 'reserved_bootfs_rootfs',
23 ]
24
25
26@@ -119,6 +121,7 @@
27 self._validate_boot_min_size()
28 self._validate_root_min_size()
29 self._validate_loader_min_size()
30+ self._validate_loader_start()
31 self._validate_x_loader_package()
32 self._validate_x_loader_file()
33 self._validate_vmlinuz()
34@@ -128,6 +131,7 @@
35 self._validate_boot_script()
36 self._validate_uboot_in_boot_part()
37 self._validate_extra_serial_opts()
38+ self._validate_snowball_startup_files_config()
39
40 self._validate_sections()
41
42@@ -223,6 +227,15 @@
43 return self._get_option_from_main_section(self.BOOT_SCRIPT_KEY)
44
45 @property
46+ def snowball_startup_files_config(self):
47+ """File name of the snowball startfiles config file.
48+
49+ A str.
50+ """
51+ return self._get_option_from_main_section(
52+ self.SNOWBALL_STARTUP_FILES_CONFIG_KEY)
53+
54+ @property
55 def kernel_addr(self):
56 """address where u-boot should load the kernel
57
58@@ -313,6 +326,14 @@
59 return self._get_option_from_main_section(self.LOADER_MIN_SIZE_KEY)
60
61 @property
62+ def loader_start(self):
63+ """Start of loader partition. If left out, defaults to 1.
64+
65+ An int.
66+ """
67+ return self._get_option_from_main_section(self.LOADER_START_KEY)
68+
69+ @property
70 def origin(self):
71 """The origin that should be recorded in the hwpack.
72
73@@ -518,6 +539,14 @@
74 self._assert_matches_pattern(
75 self.PATH_REGEX, boot_script, "Invalid path: %s" % boot_script)
76
77+
78+ def _validate_snowball_startup_files_config(self):
79+ snowball_startup_files_config = self.snowball_startup_files_config
80+ if snowball_startup_files_config is not None:
81+ self._assert_matches_pattern(
82+ self.PATH_REGEX, snowball_startup_files_config,
83+ "Invalid path: %s" % snowball_startup_files_config)
84+
85 def _validate_serial_tty(self):
86 serial_tty = self.serial_tty
87 if serial_tty is None:
88@@ -609,6 +638,16 @@
89 raise HwpackConfigError(
90 "Invalid loader min size %s" % (loader_min_size))
91
92+ def _validate_loader_start(self):
93+ loader_start = self.loader_start
94+ if loader_start is None:
95+ return
96+ try:
97+ assert int(loader_start) > 0
98+ except:
99+ raise HwpackConfigError(
100+ "Invalid loader start %s" % (loader_start))
101+
102 def _validate_include_debs(self):
103 try:
104 self.include_debs
105
106=== modified file 'linaro_image_tools/hwpack/hardwarepack.py'
107--- linaro_image_tools/hwpack/hardwarepack.py 2011-08-18 13:46:36 +0000
108+++ linaro_image_tools/hwpack/hardwarepack.py 2011-08-25 13:51:23 +0000
109@@ -84,7 +84,8 @@
110 loader_min_size=None, vmlinuz=None, initrd=None,
111 dtb_addr=None, extra_boot_options=None,
112 boot_script=None, uboot_in_boot_part=None,
113- extra_serial_opts=None):
114+ extra_serial_opts=None, loader_start=None,
115+ snowball_startup_files_config=None):
116 """Add fields that are specific to the new format.
117
118 These fields are not present in earlier config files.
119@@ -101,6 +102,7 @@
120 self.boot_min_size = boot_min_size
121 self.root_min_size = root_min_size
122 self.loader_min_size = loader_min_size
123+ self.loader_start = loader_start
124 self.x_loader = None
125 self.vmlinuz = vmlinuz
126 self.initrd = initrd
127@@ -110,6 +112,7 @@
128 self.boot_script = boot_script
129 self.uboot_in_boot_part = uboot_in_boot_part
130 self.extra_serial_opts = extra_serial_opts
131+ self.snowball_startup_files_config = snowball_startup_files_config
132
133 @classmethod
134 def from_config(cls, config, version, architecture):
135@@ -146,6 +149,7 @@
136 boot_min_size=config.boot_min_size,
137 root_min_size=config.root_min_size,
138 loader_min_size=config.loader_min_size,
139+ loader_start=config.loader_start,
140 vmlinuz=config.vmlinuz,
141 initrd=config.initrd,
142 dtb_file=config.dtb_file,
143@@ -153,7 +157,8 @@
144 extra_boot_options=config.extra_boot_options,
145 boot_script=config.boot_script,
146 uboot_in_boot_part=config.uboot_in_boot_part,
147- extra_serial_opts=config.extra_serial_opts)
148+ extra_serial_opts=config.extra_serial_opts,
149+ snowball_startup_files_config=config.snowball_startup_files_config)
150 return metadata
151
152 def __str__(self):
153@@ -198,6 +203,8 @@
154 metadata += "ROOT_MIN_SIZE=%s\n" % self.root_min_size
155 if self.loader_min_size is not None:
156 metadata += "LOADER_MIN_SIZE=%s\n" % self.loader_min_size
157+ if self.loader_start is not None:
158+ metadata += "LOADER_START=%s\n" % self.loader_start
159 if self.x_loader is not None:
160 metadata += "X_LOADER=%s\n" % self.x_loader
161 if self.vmlinuz is not None:
162@@ -214,6 +221,8 @@
163 metadata += "U_BOOT_IN_BOOT_PART=%s\n" % self.uboot_in_boot_part
164 if self.extra_serial_opts is not None:
165 metadata += "EXTRA_SERIAL_OPTIONS=%s\n" % self.extra_serial_opts
166+ if self.snowball_startup_files_config is not None:
167+ metadata += "SNOWBALL_STARTUP_FILES_CONFIG=%s\n" % self.snowball_startup_files_config
168
169 return metadata
170
171
172=== modified file 'linaro_image_tools/media_create/boards.py'
173--- linaro_image_tools/media_create/boards.py 2011-08-25 09:57:46 +0000
174+++ linaro_image_tools/media_create/boards.py 2011-08-25 13:51:23 +0000
175@@ -253,6 +253,8 @@
176 mmc_id = None
177 vmlinuz = None
178 initrd = None
179+ partition_layout = None
180+ LOADER_START_S = 1
181
182 hardwarepack_handler = None
183
184@@ -293,7 +295,8 @@
185 cls.dtb_addr = cls.get_metadata_field('dtb_addr')
186 cls.serial_tty = cls.get_metadata_field('serial_tty')
187 cls.wired_interfaces = cls.get_metadata_field('wired_interfaces')
188- cls.wireless_interfaces = cls.get_metadata_field('wireless_interfaces')
189+ cls.wireless_interfaces = cls.get_metadata_field(
190+ 'wireless_interfaces')
191 cls.mmc_id = cls.get_metadata_field('mmc_id')
192 cls.vmlinuz = cls.get_metadata_field('kernel_file')
193 cls.initrd = cls.get_metadata_field('initrd_file')
194@@ -302,14 +305,18 @@
195 'extra_boot_options')
196 cls.boot_script = cls.get_metadata_field('boot_script')
197 cls.extra_serial_opts = cls.get_metadata_field('extra_serial_options')
198+ cls.snowball_startup_files_config = cls.get_metadata_field(
199+ 'snowball_startup_files_config')
200
201- partition_layout = cls.get_metadata_field('partition_layout')
202- if partition_layout == 'bootfs_rootfs' or partition_layout is None:
203+ cls.partition_layout = cls.get_metadata_field('partition_layout')
204+ if cls.partition_layout in ['bootfs_rootfs', 'reserved_bootfs_rootfs',
205+ None]:
206 cls.fat_size = 32
207- elif partition_layout == 'bootfs16_rootfs':
208+ elif cls.partition_layout == 'bootfs16_rootfs':
209 cls.fat_size = 16
210 else:
211- raise AssertionError("Unknown partition layout '%s'." % partition_layout)
212+ raise AssertionError("Unknown partition layout '%s'." % \
213+ cls.partition_layout)
214
215 boot_min_size = cls.get_metadata_field('boot_min_size')
216 if boot_min_size is not None:
217@@ -332,6 +339,10 @@
218 elif string.lower(uboot_in_boot_part) == 'no':
219 cls.uboot_in_boot_part = False
220
221+ loader_start = cls.get_metadata_field('loader_start')
222+ if loader_start is not None:
223+ cls.LOADER_START_S = int(loader_start)
224+
225 @classmethod
226 def get_file(cls, file_alias, default=None):
227 file_in_hwpack = cls.hardwarepack_handler.get_file(file_alias)
228@@ -341,13 +352,17 @@
229 return default
230
231 @classmethod
232- def get_sfdisk_cmd(cls, should_align_boot_part=False):
233+ def get_v1_sfdisk_cmd(cls, should_align_boot_part=False):
234 """Return the sfdisk command to partition the media.
235
236 :param should_align_boot_part: Whether to align the boot partition too.
237
238 This default implementation returns a boot vfat partition of type FAT16
239 or FAT32, followed by a root partition.
240+
241+ XXX: This default implementation and all overrides are left for V1
242+ compatibility only. They should be removed as part of the work to
243+ kill off hwpacks V1.
244 """
245 if cls.fat_size == 32:
246 partition_type = '0x0C'
247@@ -379,6 +394,76 @@
248 boot_start, boot_len, partition_type, root_start)
249
250 @classmethod
251+ def get_normal_sfdisk_cmd(cls, should_align_boot_part=False):
252+ """Return the sfdisk command to partition the media.
253+
254+ :param should_align_boot_part: Whether to align the boot partition too.
255+
256+ This returns a boot vfat partition of type FAT16
257+ or FAT32, followed by a root partition.
258+ """
259+ if cls.fat_size == 32:
260+ partition_type = '0x0C'
261+ else:
262+ partition_type = '0x0E'
263+
264+ # align on sector 63 for compatibility with broken versions of x-loader
265+ # unless align_boot_part is set
266+ # XXX OMAP specific, might break other boards?
267+ boot_align = 63
268+ if should_align_boot_part:
269+ boot_align = PART_ALIGN_S
270+
271+ # can only start on sector 1 (sector 0 is MBR / partition table)
272+ boot_start, boot_end, boot_len = align_partition(
273+ 1, cls.BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
274+ # apparently OMAP3 ROMs require the vfat length to be an even number
275+ # of sectors (multiple of 1 KiB); decrease the length if it's odd,
276+ # there should still be enough room
277+ # XXX OMAP specific, might break other boards?
278+ boot_len = boot_len - boot_len % 2
279+ boot_end = boot_start + boot_len - 1
280+
281+ # we ignore _root_end / _root_len and return a sfdisk command to
282+ # instruct the use of all remaining space; XXX we now have root size
283+ # config, so we can do something more sensible
284+ root_start, _root_end, _root_len = align_partition(
285+ boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
286+
287+ return '%s,%s,%s,*\n%s,,,-' % (
288+ boot_start, boot_len, partition_type, root_start)
289+
290+ @classmethod
291+ def get_reserved_sfdisk_cmd(cls, should_align_boot_part=None):
292+ """Return the sfdisk command to partition the media.
293+
294+ :param should_align_boot_part: Ignored.
295+
296+ This returns a loader partition, then a boot vfat partition of type
297+ FAT16 or FAT32, followed by a root partition.
298+ """
299+ loader_start, loader_end, loader_len = align_partition(
300+ cls.LOADER_START_S, cls.LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
301+
302+ boot_start, boot_end, boot_len = align_partition(
303+ loader_end + 1, cls.BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
304+
305+ root_start, _root_end, _root_len = align_partition(
306+ boot_end + 1, cls.ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
307+
308+ return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
309+ loader_start, loader_len, boot_start, boot_len, root_start)
310+
311+ @classmethod
312+ def get_sfdisk_cmd(cls, should_align_boot_part=False):
313+ if cls.partition_layout in ['bootfs_rootfs', 'bootfs16_rootfs']:
314+ return cls.get_normal_sfdisk_cmd(should_align_boot_part)
315+ elif cls.partition_layout in ['reserved_bootfs_rootfs']:
316+ return cls.get_reserved_sfdisk_cmd(should_align_boot_part)
317+ else:
318+ return cls.get_v1_sfdisk_cmd(should_align_boot_part)
319+
320+ @classmethod
321 def _get_bootcmd(cls, d_img_data):
322 """Get the bootcmd for this board.
323
324@@ -743,11 +828,11 @@
325 # puts the MBR, so the boot loader skips that address.
326 supports_writing_to_mmc = False
327 SNOWBALL_LOADER_START_S = (128 * 1024) / SECTOR_SIZE
328- SNOWBALL_STARTUP_FILES_CONFIG = 'startfiles.cfg'
329+ snowball_startup_files_config = 'startfiles.cfg'
330 TOC_SIZE = 512
331
332 @classmethod
333- def get_sfdisk_cmd(cls, should_align_boot_part=None):
334+ def get_v1_sfdisk_cmd(cls, should_align_boot_part=None):
335 """Return the sfdisk command to partition the media.
336
337 :param should_align_boot_part: Ignored.
338@@ -800,7 +885,7 @@
339 cls.SNOWBALL_LOADER_START_S)
340 cls.delete_file(toc_filename)
341 cls.delete_file(os.path.join(config_files_path,
342- cls.SNOWBALL_STARTUP_FILES_CONFIG))
343+ cls.snowball_startup_files_config))
344
345 @classmethod
346 def install_snowball_boot_loader(cls, toc_file_name, files,
347@@ -860,7 +945,7 @@
348 ofs = cls.TOC_SIZE
349 files = []
350 bin_dir = os.path.join(chroot_dir, 'boot')
351- with open(os.path.join(bin_dir, cls.SNOWBALL_STARTUP_FILES_CONFIG),
352+ with open(os.path.join(bin_dir, cls.snowball_startup_files_config),
353 'r') as info_file:
354 for line in info_file:
355 file_data = line.split()
356@@ -904,7 +989,7 @@
357 return cls._extra_serial_opts % cls.serial_tty
358
359 @classmethod
360- def get_sfdisk_cmd(cls, should_align_boot_part=None):
361+ def get_v1_sfdisk_cmd(cls, should_align_boot_part=None):
362 """Return the sfdisk command to partition the media.
363
364 :param should_align_boot_part: Ignored.
365@@ -1020,7 +1105,7 @@
366 return cls._extra_serial_opts % cls.serial_tty
367
368 @classmethod
369- def get_sfdisk_cmd(cls, should_align_boot_part=False):
370+ def get_v1_sfdisk_cmd(cls, should_align_boot_part=False):
371 # bootloaders partition needs to hold BL1, U-Boot environment, and BL2
372 loaders_min_len = (
373 SAMSUNG_V310_BL2_START + SAMSUNG_V310_BL2_LEN -
374
375=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
376--- linaro_image_tools/media_create/tests/test_media_create.py 2011-08-25 09:57:46 +0000
377+++ linaro_image_tools/media_create/tests/test_media_create.py 2011-08-25 13:51:23 +0000
378@@ -46,6 +46,7 @@
379 from linaro_image_tools.media_create.boards import (
380 SAMSUNG_V310_BL1_START,
381 SAMSUNG_V310_BL2_START,
382+ SAMSUNG_V310_BL2_LEN,
383 SECTOR_SIZE,
384 align_up,
385 align_partition,
386@@ -685,7 +686,7 @@
387 ('UBOOT_ENV', 'u-boot-env.bin', 0, 0x00C1F000, '10')]
388 # Create a config file
389 cfg_file = os.path.join(self.temp_bootdir_path,
390- boards.SnowballEmmcConfig.SNOWBALL_STARTUP_FILES_CONFIG)
391+ boards.SnowballEmmcConfig.snowball_startup_files_config)
392 with open(cfg_file, 'w') as f:
393 for line in src_data:
394 # Write comments, so we test that the parser can read them
395@@ -719,7 +720,7 @@
396 def test_get_file_info_relative_path(self):
397 # Create a config file
398 cfg_file = os.path.join(self.temp_bootdir_path,
399- boards.SnowballEmmcConfig.SNOWBALL_STARTUP_FILES_CONFIG)
400+ boards.SnowballEmmcConfig.snowball_startup_files_config)
401 uboot_file = 'u-boot.bin'
402 with open(cfg_file, 'w') as f:
403 f.write('%s %s %i %#x %s\n' % ('NORMAL', uboot_file, 0,
404@@ -733,7 +734,7 @@
405 def test_get_file_info_abs_path(self):
406 # Create a config file
407 cfg_file = os.path.join(self.temp_bootdir_path,
408- boards.SnowballEmmcConfig.SNOWBALL_STARTUP_FILES_CONFIG)
409+ boards.SnowballEmmcConfig.snowball_startup_files_config)
410 uboot_dir = tempfile.mkdtemp(dir=self.tempdir)
411 uboot_file = os.path.join(uboot_dir, 'u-boot.bin')
412 uboot_relative_file = uboot_file.replace(self.tempdir, '')
413@@ -748,7 +749,7 @@
414 def test_get_file_info_raises(self):
415 # Create a config file
416 cfg_file = os.path.join(self.temp_bootdir_path,
417- boards.SnowballEmmcConfig.SNOWBALL_STARTUP_FILES_CONFIG)
418+ boards.SnowballEmmcConfig.snowball_startup_files_config)
419 with open(cfg_file, 'w') as f:
420 f.write('%s %s %i %#x %s\n' % ('NORMAL', 'u-boot.bin', 0,
421 0xBA0000, '9'))
422@@ -1142,6 +1143,50 @@
423 '794624,-,E\n794624,524288,L\n1318912,1048576,L\n2367488,,,-',
424 android_boards.AndroidSnowballEmmcConfig.get_sfdisk_cmd())
425
426+class TestGetSfdiskCmdV2(TestCase):
427+
428+ def test_mx5(self):
429+ class config(boards.Mx5Config):
430+ partition_layout = 'reserved_bootfs_rootfs'
431+ self.assertEqual(
432+ '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
433+ config.get_sfdisk_cmd())
434+
435+ def test_snowball_sd(self):
436+ class config(boards.SnowballSdConfig):
437+ partition_layout = 'bootfs_rootfs'
438+ self.assertEqual(
439+ '63,106432,0x0C,*\n106496,,,-',
440+ config.get_sfdisk_cmd())
441+
442+ def test_snowball_emmc(self):
443+ class config(boards.SnowballEmmcConfig):
444+ partition_layout = 'reserved_bootfs_rootfs'
445+ LOADER_START_S = (128 * 1024) / SECTOR_SIZE
446+ self.assertEqual(
447+ '256,7936,0xDA\n8192,106496,0x0C,*\n114688,,,-',
448+ config.get_sfdisk_cmd())
449+
450+ def test_smdkv310(self):
451+ class config(board_configs['smdkv310']):
452+ partition_layout = 'reserved_bootfs_rootfs'
453+ LOADER_MIN_SIZE_S = (SAMSUNG_V310_BL2_START +
454+ SAMSUNG_V310_BL2_LEN -
455+ SAMSUNG_V310_BL1_START)
456+ self.assertEquals(
457+ '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
458+ config.get_sfdisk_cmd())
459+
460+ def test_origen(self):
461+ class config(board_configs['origen']):
462+ partition_layout = 'reserved_bootfs_rootfs'
463+ LOADER_MIN_SIZE_S = (SAMSUNG_V310_BL2_START +
464+ SAMSUNG_V310_BL2_LEN -
465+ SAMSUNG_V310_BL1_START)
466+ self.assertEquals(
467+ '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
468+ config.get_sfdisk_cmd())
469+
470
471 class TestGetBootCmd(TestCase):
472

Subscribers

People subscribed via source and target branches