=== modified file 'linaro_image_tools/hwpack/config.py'
@@ -44,6 +44,7 @@
DD_FIELD,
DTB_ADDR_FIELD,
DTB_FILE_FIELD,
+ DEFAULT_BOOTLOADER,
DTB_FILES_FIELD,
ENV_DD_FIELD,
EXTRA_BOOT_OPTIONS_FIELD,
@@ -86,6 +87,8 @@
hwpack_v3_layout,
)
+import logging
+
class HwpackConfigError(Exception):
pass
@@ -153,8 +156,10 @@
# difference to what is returned when querying the object.
#
# self.allow_unset_bootloader allows for both modes of operation.
+ self.logger = logging.getLogger('linaro_image_tools')
self.allow_unset_bootloader = allow_unset_bootloader
self.bootloader = None
+
obfuscated_e = None
obfuscated_yaml_e = ""
try:
@@ -176,8 +181,10 @@
else:
# If YAML parsed OK, we don't have an error.
obfuscated_e = None
- self.set_board(board)
- self.set_bootloader(bootloader)
+ if board:
+ self.set_board(board)
+ if bootloader:
+ self.set_bootloader(bootloader)
if obfuscated_e:
# If INI parsing from ConfigParser or YAML parsing failed,
@@ -202,8 +209,22 @@
if isinstance(bootloaders, dict):
# We have a list of bootloaders in the expected format
bootloaders = bootloaders.keys()
- if len(bootloaders) == 1:
- bootloader = bootloaders[0]
+ bootloader = bootloaders[0]
+ if len(bootloaders) > 1:
+ # We have more than one bootloader, use 'u_boot'.
+ if DEFAULT_BOOTLOADER in bootloaders:
+ bootloader = DEFAULT_BOOTLOADER
+ self.logger.warning('WARNING: no bootloader specified '
+ 'on the command line. Defaulting '
+ 'to \'%s\'.' % DEFAULT_BOOTLOADER)
+ self.logger.warning('WARNING: specify another '
+ 'bootloader if this is not the '
+ 'correct one to use.')
+ else:
+ self.logger.warning('Default bootloader \'%s\' not '
+ 'found. Will try to use \'%s\'. '
+ 'instead.' % (DEFAULT_BOOTLOADER,
+ bootloader))
self.bootloader = bootloader
@@ -247,11 +268,10 @@
if self.format.has_v2_fields:
# Check config for all bootloaders if one isn't specified.
- if self.bootloader == None and self._is_v3:
+ if not self.bootloader and self._is_v3:
for bootloader in self.get_bootloader_list():
self.set_bootloader(bootloader)
self.validate_bootloader_fields()
- self.set_bootloader(None)
else:
self.validate_bootloader_fields()
=== modified file 'linaro_image_tools/media_create/boards.py'
@@ -47,10 +47,6 @@
partition_mounted, SECTOR_SIZE, register_loopback)
from StringIO import StringIO
-from linaro_image_tools.hwpack.hwpack_fields import (
- DEFAULT_BOOTLOADER,
-)
-
KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s'
INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s'
DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s'
@@ -134,6 +130,8 @@
self.bootloader = bootloader
self.board = board
self.tempdirs = {}
+ # Used to store the config created from the metadata.
+ self.config = None
class FakeSecHead(object):
""" Add a fake section header to the metadata file.
@@ -173,18 +171,30 @@
if tempdir is not None and os.path.exists(tempdir):
shutil.rmtree(tempdir)
+ def _get_config_from_metadata(self, metadata):
+ """
+ Retrieves a Config object associated with the metadata.
+
+ :param metadata: The metadata to parse.
+ :return: A Config instance.
+ """
+ if not self.config:
+ lines = metadata.readlines()
+ if re.search("=", lines[0]) and not re.search(":", lines[0]):
+ # Probably V2 hardware pack without [hwpack] on the first line
+ lines = ["[hwpack]\n"] + lines
+ self.config = Config(StringIO("".join(lines)))
+ self.config.set_board(self.board)
+ self.config.set_bootloader(self.bootloader)
+ return self.config
+
def get_field(self, field, return_keys=False):
data = None
hwpack_with_data = None
keys = None
for hwpack_tarfile in self.hwpack_tarfiles:
metadata = hwpack_tarfile.extractfile(self.metadata_filename)
- lines = metadata.readlines()
- if re.search("=", lines[0]) and not re.search(":", lines[0]):
- # Probably V2 hardware pack without [hwpack] on the first line
- lines = ["[hwpack]\n"] + lines
- parser = Config(StringIO("".join(lines)), self.bootloader,
- self.board)
+ parser = self._get_config_from_metadata(metadata)
try:
new_data = parser.get_option(field)
if new_data is not None:
@@ -466,14 +476,6 @@
@classmethod
def set_metadata(cls, hwpacks, bootloader=None, board=None):
- # If not bootloader is specified, we use the default one.
- logger = cls._get_logger()
- if not bootloader:
- logger.warning('WARNING: no bootloader specified on the command '
- 'line. Defaulting to \'%s\'.' % DEFAULT_BOOTLOADER)
- logger.warning('WARNING: specify another bootloader if this is '
- 'not the correct one to use.')
- bootloader = DEFAULT_BOOTLOADER
cls.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
board)
with cls.hardwarepack_handler: