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
1=== modified file 'linaro_image_tools/hwpack/config.py'
2--- linaro_image_tools/hwpack/config.py 2012-09-11 14:28:20 +0000
3+++ linaro_image_tools/hwpack/config.py 2012-10-02 14:52:22 +0000
4@@ -44,6 +44,7 @@
5 DD_FIELD,
6 DTB_ADDR_FIELD,
7 DTB_FILE_FIELD,
8+ DEFAULT_BOOTLOADER,
9 ENV_DD_FIELD,
10 EXTRA_BOOT_OPTIONS_FIELD,
11 EXTRA_SERIAL_OPTIONS_FIELD,
12@@ -85,6 +86,8 @@
13 hwpack_v3_layout,
14 )
15
16+import logging
17+
18
19 class HwpackConfigError(Exception):
20 pass
21@@ -152,8 +155,10 @@
22 # difference to what is returned when querying the object.
23 #
24 # self.allow_unset_bootloader allows for both modes of operation.
25+ self.logger = logging.getLogger('linaro_image_tools')
26 self.allow_unset_bootloader = allow_unset_bootloader
27 self.bootloader = None
28+
29 obfuscated_e = None
30 obfuscated_yaml_e = ""
31 try:
32@@ -175,8 +180,10 @@
33 else:
34 # If YAML parsed OK, we don't have an error.
35 obfuscated_e = None
36- self.set_board(board)
37- self.set_bootloader(bootloader)
38+ if board:
39+ self.set_board(board)
40+ if bootloader:
41+ self.set_bootloader(bootloader)
42
43 if obfuscated_e:
44 # If INI parsing from ConfigParser or YAML parsing failed,
45@@ -201,8 +208,22 @@
46 if isinstance(bootloaders, dict):
47 # We have a list of bootloaders in the expected format
48 bootloaders = bootloaders.keys()
49- if len(bootloaders) == 1:
50- bootloader = bootloaders[0]
51+ bootloader = bootloaders[0]
52+ if len(bootloaders) > 1:
53+ # We have more than one bootloader, use 'u_boot'.
54+ if DEFAULT_BOOTLOADER in bootloaders:
55+ bootloader = DEFAULT_BOOTLOADER
56+ self.logger.warning('WARNING: no bootloader specified '
57+ 'on the command line. Defaulting '
58+ 'to \'%s\'.' % DEFAULT_BOOTLOADER)
59+ self.logger.warning('WARNING: specify another '
60+ 'bootloader if this is not the '
61+ 'correct one to use.')
62+ else:
63+ self.logger.warning('Default bootloader \'%s\' not '
64+ 'found. Will try to use \'%s\'. '
65+ 'instead.' % (DEFAULT_BOOTLOADER,
66+ bootloader))
67
68 self.bootloader = bootloader
69
70@@ -246,11 +267,10 @@
71
72 if self.format.has_v2_fields:
73 # Check config for all bootloaders if one isn't specified.
74- if self.bootloader == None and self._is_v3:
75+ if not self.bootloader and self._is_v3:
76 for bootloader in self.get_bootloader_list():
77 self.set_bootloader(bootloader)
78 self.validate_bootloader_fields()
79- self.set_bootloader(None)
80 else:
81 self.validate_bootloader_fields()
82
83
84=== modified file 'linaro_image_tools/media_create/boards.py'
85--- linaro_image_tools/media_create/boards.py 2012-10-01 12:58:41 +0000
86+++ linaro_image_tools/media_create/boards.py 2012-10-02 14:52:22 +0000
87@@ -47,10 +47,6 @@
88 partition_mounted, SECTOR_SIZE, register_loopback)
89 from StringIO import StringIO
90
91-from linaro_image_tools.hwpack.hwpack_fields import (
92- DEFAULT_BOOTLOADER,
93-)
94-
95 KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s'
96 INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s'
97 DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s'
98@@ -134,6 +130,8 @@
99 self.bootloader = bootloader
100 self.board = board
101 self.tempdirs = {}
102+ # Used to store the config created from the metadata.
103+ self.config = None
104
105 class FakeSecHead(object):
106 """ Add a fake section header to the metadata file.
107@@ -173,18 +171,30 @@
108 if tempdir is not None and os.path.exists(tempdir):
109 shutil.rmtree(tempdir)
110
111+ def _get_config_from_metadata(self, metadata):
112+ """
113+ Retrieves a Config object associated with the metadata.
114+
115+ :param metadata: The metadata to parse.
116+ :return: A Config instance.
117+ """
118+ if not self.config:
119+ lines = metadata.readlines()
120+ if re.search("=", lines[0]) and not re.search(":", lines[0]):
121+ # Probably V2 hardware pack without [hwpack] on the first line
122+ lines = ["[hwpack]\n"] + lines
123+ self.config = Config(StringIO("".join(lines)))
124+ self.config.set_board(self.board)
125+ self.config.set_bootloader(self.bootloader)
126+ return self.config
127+
128 def get_field(self, field, return_keys=False):
129 data = None
130 hwpack_with_data = None
131 keys = None
132 for hwpack_tarfile in self.hwpack_tarfiles:
133 metadata = hwpack_tarfile.extractfile(self.metadata_filename)
134- lines = metadata.readlines()
135- if re.search("=", lines[0]) and not re.search(":", lines[0]):
136- # Probably V2 hardware pack without [hwpack] on the first line
137- lines = ["[hwpack]\n"] + lines
138- parser = Config(StringIO("".join(lines)), self.bootloader,
139- self.board)
140+ parser = self._get_config_from_metadata(metadata)
141 try:
142 new_data = parser.get_option(field)
143 if new_data is not None:
144@@ -463,14 +473,6 @@
145
146 @classmethod
147 def set_metadata(cls, hwpacks, bootloader=None, board=None):
148- # If not bootloader is specified, we use the default one.
149- logger = cls._get_logger()
150- if not bootloader:
151- logger.warning('WARNING: no bootloader specified on the command '
152- 'line. Defaulting to \'%s\'.' % DEFAULT_BOOTLOADER)
153- logger.warning('WARNING: specify another bootloader if this is '
154- 'not the correct one to use.')
155- bootloader = DEFAULT_BOOTLOADER
156 cls.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
157 board)
158 with cls.hardwarepack_handler:

Subscribers

People subscribed via source and target branches