Merge lp:~milo/linaro-image-tools/default-bootloader into lp:linaro-image-tools/11.11

Proposed by Milo Casagrande
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 570
Merged at revision: 570
Proposed branch: lp:~milo/linaro-image-tools/default-bootloader
Merge into: lp:linaro-image-tools/11.11
Diff against target: 158 lines (+46/-24)
2 files modified
linaro_image_tools/hwpack/config.py (+26/-6)
linaro_image_tools/media_create/boards.py (+20/-18)
To merge this branch: bzr merge lp:~milo/linaro-image-tools/default-bootloader
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Paul Sokolovsky Pending
Linaro Infrastructure Pending
Review via email: mp+127500@code.launchpad.net

Description of the change

This branch sets the default bootloader in a slightly different way than it was done before.
There is a small change in how two methods are called, and how a Config object is created.

In the code, we are using the Config object to create the real config when running linaro-hwpack-create (to create an hwpack) and also when running linaro-media-create (we are using the Config class to read the metadata file treating it as a Config object).

To maintain a little bit of compatibility with what was done before, now the Config object will call the set_board and set_bootloader methods only when the two parameters passed to the constuctor are defined (not None). Since when we are creating the hwpack with linaro-hwpack-create we are not interested in which bootloaders are present, but just if they are valid, we do not need to go through the setting of boards and bootloaders at that time. When we use linaro-media-create instead, we explicitly call set_board and set_bootloader, after validating the Config, in order to set the correct values.

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

Removed unnecessary comment.

Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Looks great. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro_image_tools/hwpack/config.py'
--- linaro_image_tools/hwpack/config.py 2012-09-11 14:28:20 +0000
+++ linaro_image_tools/hwpack/config.py 2012-10-02 14:52:22 +0000
@@ -44,6 +44,7 @@
44 DD_FIELD,44 DD_FIELD,
45 DTB_ADDR_FIELD,45 DTB_ADDR_FIELD,
46 DTB_FILE_FIELD,46 DTB_FILE_FIELD,
47 DEFAULT_BOOTLOADER,
47 ENV_DD_FIELD,48 ENV_DD_FIELD,
48 EXTRA_BOOT_OPTIONS_FIELD,49 EXTRA_BOOT_OPTIONS_FIELD,
49 EXTRA_SERIAL_OPTIONS_FIELD,50 EXTRA_SERIAL_OPTIONS_FIELD,
@@ -85,6 +86,8 @@
85 hwpack_v3_layout,86 hwpack_v3_layout,
86)87)
8788
89import logging
90
8891
89class HwpackConfigError(Exception):92class HwpackConfigError(Exception):
90 pass93 pass
@@ -152,8 +155,10 @@
152 # difference to what is returned when querying the object.155 # difference to what is returned when querying the object.
153 #156 #
154 # self.allow_unset_bootloader allows for both modes of operation.157 # self.allow_unset_bootloader allows for both modes of operation.
158 self.logger = logging.getLogger('linaro_image_tools')
155 self.allow_unset_bootloader = allow_unset_bootloader159 self.allow_unset_bootloader = allow_unset_bootloader
156 self.bootloader = None160 self.bootloader = None
161
157 obfuscated_e = None162 obfuscated_e = None
158 obfuscated_yaml_e = ""163 obfuscated_yaml_e = ""
159 try:164 try:
@@ -175,8 +180,10 @@
175 else:180 else:
176 # If YAML parsed OK, we don't have an error.181 # If YAML parsed OK, we don't have an error.
177 obfuscated_e = None182 obfuscated_e = None
178 self.set_board(board)183 if board:
179 self.set_bootloader(bootloader)184 self.set_board(board)
185 if bootloader:
186 self.set_bootloader(bootloader)
180187
181 if obfuscated_e:188 if obfuscated_e:
182 # If INI parsing from ConfigParser or YAML parsing failed,189 # If INI parsing from ConfigParser or YAML parsing failed,
@@ -201,8 +208,22 @@
201 if isinstance(bootloaders, dict):208 if isinstance(bootloaders, dict):
202 # We have a list of bootloaders in the expected format209 # We have a list of bootloaders in the expected format
203 bootloaders = bootloaders.keys()210 bootloaders = bootloaders.keys()
204 if len(bootloaders) == 1:211 bootloader = bootloaders[0]
205 bootloader = bootloaders[0]212 if len(bootloaders) > 1:
213 # We have more than one bootloader, use 'u_boot'.
214 if DEFAULT_BOOTLOADER in bootloaders:
215 bootloader = DEFAULT_BOOTLOADER
216 self.logger.warning('WARNING: no bootloader specified '
217 'on the command line. Defaulting '
218 'to \'%s\'.' % DEFAULT_BOOTLOADER)
219 self.logger.warning('WARNING: specify another '
220 'bootloader if this is not the '
221 'correct one to use.')
222 else:
223 self.logger.warning('Default bootloader \'%s\' not '
224 'found. Will try to use \'%s\'. '
225 'instead.' % (DEFAULT_BOOTLOADER,
226 bootloader))
206227
207 self.bootloader = bootloader228 self.bootloader = bootloader
208229
@@ -246,11 +267,10 @@
246267
247 if self.format.has_v2_fields:268 if self.format.has_v2_fields:
248 # Check config for all bootloaders if one isn't specified.269 # Check config for all bootloaders if one isn't specified.
249 if self.bootloader == None and self._is_v3:270 if not self.bootloader and self._is_v3:
250 for bootloader in self.get_bootloader_list():271 for bootloader in self.get_bootloader_list():
251 self.set_bootloader(bootloader)272 self.set_bootloader(bootloader)
252 self.validate_bootloader_fields()273 self.validate_bootloader_fields()
253 self.set_bootloader(None)
254 else:274 else:
255 self.validate_bootloader_fields()275 self.validate_bootloader_fields()
256276
257277
=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py 2012-10-01 12:58:41 +0000
+++ linaro_image_tools/media_create/boards.py 2012-10-02 14:52:22 +0000
@@ -47,10 +47,6 @@
47 partition_mounted, SECTOR_SIZE, register_loopback)47 partition_mounted, SECTOR_SIZE, register_loopback)
48from StringIO import StringIO48from StringIO import StringIO
4949
50from linaro_image_tools.hwpack.hwpack_fields import (
51 DEFAULT_BOOTLOADER,
52)
53
54KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s'50KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s'
55INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s'51INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s'
56DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s'52DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s'
@@ -134,6 +130,8 @@
134 self.bootloader = bootloader130 self.bootloader = bootloader
135 self.board = board131 self.board = board
136 self.tempdirs = {}132 self.tempdirs = {}
133 # Used to store the config created from the metadata.
134 self.config = None
137135
138 class FakeSecHead(object):136 class FakeSecHead(object):
139 """ Add a fake section header to the metadata file.137 """ Add a fake section header to the metadata file.
@@ -173,18 +171,30 @@
173 if tempdir is not None and os.path.exists(tempdir):171 if tempdir is not None and os.path.exists(tempdir):
174 shutil.rmtree(tempdir)172 shutil.rmtree(tempdir)
175173
174 def _get_config_from_metadata(self, metadata):
175 """
176 Retrieves a Config object associated with the metadata.
177
178 :param metadata: The metadata to parse.
179 :return: A Config instance.
180 """
181 if not self.config:
182 lines = metadata.readlines()
183 if re.search("=", lines[0]) and not re.search(":", lines[0]):
184 # Probably V2 hardware pack without [hwpack] on the first line
185 lines = ["[hwpack]\n"] + lines
186 self.config = Config(StringIO("".join(lines)))
187 self.config.set_board(self.board)
188 self.config.set_bootloader(self.bootloader)
189 return self.config
190
176 def get_field(self, field, return_keys=False):191 def get_field(self, field, return_keys=False):
177 data = None192 data = None
178 hwpack_with_data = None193 hwpack_with_data = None
179 keys = None194 keys = None
180 for hwpack_tarfile in self.hwpack_tarfiles:195 for hwpack_tarfile in self.hwpack_tarfiles:
181 metadata = hwpack_tarfile.extractfile(self.metadata_filename)196 metadata = hwpack_tarfile.extractfile(self.metadata_filename)
182 lines = metadata.readlines()197 parser = self._get_config_from_metadata(metadata)
183 if re.search("=", lines[0]) and not re.search(":", lines[0]):
184 # Probably V2 hardware pack without [hwpack] on the first line
185 lines = ["[hwpack]\n"] + lines
186 parser = Config(StringIO("".join(lines)), self.bootloader,
187 self.board)
188 try:198 try:
189 new_data = parser.get_option(field)199 new_data = parser.get_option(field)
190 if new_data is not None:200 if new_data is not None:
@@ -463,14 +473,6 @@
463473
464 @classmethod474 @classmethod
465 def set_metadata(cls, hwpacks, bootloader=None, board=None):475 def set_metadata(cls, hwpacks, bootloader=None, board=None):
466 # If not bootloader is specified, we use the default one.
467 logger = cls._get_logger()
468 if not bootloader:
469 logger.warning('WARNING: no bootloader specified on the command '
470 'line. Defaulting to \'%s\'.' % DEFAULT_BOOTLOADER)
471 logger.warning('WARNING: specify another bootloader if this is '
472 'not the correct one to use.')
473 bootloader = DEFAULT_BOOTLOADER
474 cls.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,476 cls.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
475 board)477 board)
476 with cls.hardwarepack_handler:478 with cls.hardwarepack_handler:

Subscribers

People subscribed via source and target branches