Merge lp:~milo/linaro-image-tools/dtb-files-support into lp:linaro-image-tools/11.11

Proposed by Milo Casagrande
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 571
Merged at revision: 569
Proposed branch: lp:~milo/linaro-image-tools/dtb-files-support
Merge into: lp:linaro-image-tools/11.11
Diff against target: 228 lines (+104/-4)
5 files modified
linaro_image_tools/hwpack/config.py (+20/-1)
linaro_image_tools/hwpack/hardwarepack.py (+9/-3)
linaro_image_tools/hwpack/hwpack_fields.py (+1/-0)
linaro_image_tools/hwpack/tests/test_config_v3.py (+19/-0)
linaro_image_tools/media_create/boards.py (+55/-0)
To merge this branch: bzr merge lp:~milo/linaro-image-tools/dtb-files-support
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Paul Sokolovsky Pending
Review via email: mp+127224@code.launchpad.net

Description of the change

Branch adds dtb_files support for hwpack config and metadata.
dtb_files syntax is:

dtb_files:
- destination.dtb : source.dtb

source.dtb can contain basic globbing.

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

Looks good.

It would be nice if we could combine all the static files copying code into one place. This is similar to the boot files copying that we do, but not the same as copy_files (since those files stay in their packages).

There is definitely room for tidying up that whole code area, but a bug fix isn't the place for it. If you have nothing else to do I am sure it will be... entertaining :-)

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

Hey James,

thanks for taking a look.

On Mon, Oct 1, 2012 at 5:14 PM, James Tunnicliffe
<email address hidden> wrote:
> Review: Approve
>
> Looks good.
>
> It would be nice if we could combine all the static files copying code into one place. This is similar to the boot files copying that we do, but not the same as copy_files (since those files stay in their packages).
>
> There is definitely room for tidying up that whole code area, but a bug fix isn't the place for it. If you have nothing else to do I am sure it will be... entertaining :-)

Indeed, I wanted to combine them, but it would have been a little bit
too much for the bug report.
I will indeed try to do it during this maintenance cycle, maybe in a
separate bug.

Ciao.

--
Milo Casagrande
Infrastructure Engineer
Linaro.org <www.linaro.org> │ Open source software for ARM SoCs

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-01 10:21:03 +0000
4@@ -44,6 +44,7 @@
5 DD_FIELD,
6 DTB_ADDR_FIELD,
7 DTB_FILE_FIELD,
8+ DTB_FILES_FIELD,
9 ENV_DD_FIELD,
10 EXTRA_BOOT_OPTIONS_FIELD,
11 EXTRA_SERIAL_OPTIONS_FIELD,
12@@ -269,6 +270,7 @@
13 self._validate_vmlinuz()
14 self._validate_initrd()
15 self._validate_dtb_file()
16+ self._validate_dtb_files()
17 self._validate_mmc_id()
18 self._validate_extra_boot_options()
19 self._validate_boot_script()
20@@ -821,6 +823,14 @@
21 return self._get_option(DTB_FILE_FIELD)
22
23 @property
24+ def dtb_files(self):
25+ """
26+ The list of dtb files.
27+ :return: A list of dtb files
28+ """
29+ return self._get_option(DTB_FILES_FIELD)
30+
31+ @property
32 def samsung_bl1_start(self):
33 """BL1 start offset for Samsung boards.
34
35@@ -953,7 +963,16 @@
36 return "No " + thing + " in the [" + v2_section + "] section"
37
38 def _validate_dtb_file(self):
39- dtb_file = self.dtb_file
40+ self._check_single_dtb_file(self.dtb_file)
41+
42+ def _validate_dtb_files(self):
43+ dtb_files = self.dtb_files
44+ if dtb_files:
45+ for dtb_file in dtb_files:
46+ for _, src in dtb_file.iteritems():
47+ self._check_single_dtb_file(src)
48+
49+ def _check_single_dtb_file(self, dtb_file):
50 if dtb_file is not None:
51 self._assert_matches_pattern(
52 self.GLOB_REGEX, dtb_file, "Invalid path: %s" % dtb_file)
53
54=== modified file 'linaro_image_tools/hwpack/hardwarepack.py'
55--- linaro_image_tools/hwpack/hardwarepack.py 2012-08-29 10:31:19 +0000
56+++ linaro_image_tools/hwpack/hardwarepack.py 2012-10-01 10:21:03 +0000
57@@ -43,6 +43,7 @@
58 BOOT_SCRIPT_FIELD,
59 DTB_ADDR_FIELD,
60 DTB_FILE_FIELD,
61+ DTB_FILES_FIELD,
62 EXTRA_SERIAL_OPTIONS_FIELD,
63 FORMAT_FIELD,
64 INITRD_ADDR_FIELD,
65@@ -166,14 +167,16 @@
66 self.samsung_bl2_len = samsung_bl2_len
67
68 @classmethod
69- def add_v3_config(self, boards=None, bootloaders=None):
70+ def add_v3_config(self, boards=None, bootloaders=None, dtb_files=None):
71 """Add fields that are specific to the v3 config format.
72 These fields are not present in the earlier config files.
73
74 :param boards: The boards section of the hwpack.
75- :param bootloaders: The bootloaders section of the hwpack."""
76+ :param bootloaders: The bootloaders section of the hwpack.
77+ :param dtb_files: The dtb_files section of the hwpack."""
78 self.boards = boards
79 self.bootloaders = bootloaders
80+ self.dtb_files = dtb_files
81
82 @classmethod
83 def from_config(cls, config, version, architecture):
84@@ -235,7 +238,8 @@
85 )
86 if config.format.format_as_string == '3.0':
87 metadata.add_v3_config(boards=config.boards,
88- bootloaders=config.bootloaders)
89+ bootloaders=config.bootloaders,
90+ dtb_files=config.dtb_files)
91 return metadata
92
93 def __str__(self):
94@@ -305,6 +309,8 @@
95 if self.dtb_file is not None:
96 # XXX In V3 this one should be a list, called dtb_files.
97 metadata += dump({DTB_FILE_FIELD: self.dtb_file})
98+ if self.dtb_files is not None:
99+ metadata += dump({DTB_FILES_FIELD: self.dtb_files})
100 if self.boot_script is not None:
101 metadata += dump({BOOT_SCRIPT_FIELD: self.boot_script})
102 if self.extra_serial_opts is not None:
103
104=== modified file 'linaro_image_tools/hwpack/hwpack_fields.py'
105--- linaro_image_tools/hwpack/hwpack_fields.py 2012-09-24 09:07:37 +0000
106+++ linaro_image_tools/hwpack/hwpack_fields.py 2012-10-01 10:21:03 +0000
107@@ -110,6 +110,7 @@
108 ASSUME_INSTALLED_FIELD: None,
109 INCLUDE_DEBS_FIELD: None,
110 DTB_FILE_FIELD: None,
111+ DTB_FILES_FIELD: None,
112 DTB_ADDR_FIELD: None,
113 SERIAL_TTY_FIELD: None,
114 EXTRA_SERIAL_OPTIONS_FIELD: None,
115
116=== modified file 'linaro_image_tools/hwpack/tests/test_config_v3.py'
117--- linaro_image_tools/hwpack/tests/test_config_v3.py 2012-09-24 11:29:40 +0000
118+++ linaro_image_tools/hwpack/tests/test_config_v3.py 2012-10-01 10:21:03 +0000
119@@ -825,3 +825,22 @@
120 config = self.get_config(self.valid_start_v3 +
121 'samsung_wrong_field: 1\n')
122 self.assertRaises(HwpackConfigError, config._validate_keys)
123+
124+ # Tests for dtb_files support
125+ def test_dtb_files(self):
126+ dtb_files = ('dtb_files:\n' +
127+ ' - adest.dtb : boot/dt-*-linaro-omap/omap4-panda.dtb\n' +
128+ ' - bdest.dtb : ' +
129+ 'boot/dt-*-linaro-omap2/omap4-panda2.dtb\n')
130+ expected = [{'adest.dtb':'boot/dt-*-linaro-omap/omap4-panda.dtb'},
131+ {'bdest.dtb': 'boot/dt-*-linaro-omap2/omap4-panda2.dtb'}]
132+ config = self.get_config(self.valid_complete_v3 + dtb_files)
133+ config.validate()
134+ self.assertEqual(expected, config.dtb_files)
135+
136+ def test_dtb_files_one_wrong(self):
137+ dtb_files = ('dtb_files:\n' +
138+ ' - adest.dtb : boot/dt-*-linaro-omap/omap4-panda.dtb\n' +
139+ ' - bdest.dtb : ~~~\n')
140+ config = self.get_config(self.valid_start_v3 + dtb_files)
141+ self.assertRaises(HwpackConfigError, config._validate_dtb_files)
142
143=== modified file 'linaro_image_tools/media_create/boards.py'
144--- linaro_image_tools/media_create/boards.py 2012-09-12 10:51:00 +0000
145+++ linaro_image_tools/media_create/boards.py 2012-10-01 10:21:03 +0000
146@@ -404,6 +404,9 @@
147 partition_layout = None
148 LOADER_START_S = 1
149
150+ # Support for dtb_files as per hwpack v3 format.
151+ dtb_files = None
152+
153 # Samsung v310 implementation notes and terminology
154 #
155 # * BL0, BL1 etc. are the various bootloaders in order of execution
156@@ -495,6 +498,7 @@
157 cls.vmlinuz = cls.get_metadata_field('vmlinuz')
158 cls.initrd = cls.get_metadata_field('initrd')
159 cls.dtb_file = cls.get_metadata_field('dtb_file')
160+ cls.dtb_files = cls.get_metadata_field('dtb_files')
161 cls.extra_boot_args_options = cls.get_metadata_field(
162 'extra_boot_options')
163 cls.boot_script = cls.get_metadata_field('boot_script')
164@@ -840,6 +844,53 @@
165 boot_device_or_file, k_img_data, i_img_data, d_img_data)
166
167 @classmethod
168+ def _copy_dtb_files(cls, dtb_files, dest_dir, search_dir):
169+ """Copy the files defined in dtb_files into the boot directory.
170+
171+ :param dtb_files: The list of dtb files
172+ :param dest_dir: The directory where to copy each dtb file.
173+ :param search_dir: The directory where to search for the real file.
174+ """
175+ logger = logging.getLogger("linaro_image_tools")
176+ logger.info("Copying dtb files")
177+ for dtb_file in dtb_files:
178+ if dtb_file:
179+ if isinstance(dtb_file, dict):
180+ for key, value in dtb_file.iteritems():
181+ # The name of the dtb file in the new position.
182+ to_file = os.path.basename(key)
183+ # The directory where to copy the dtb file.
184+ to_dir = os.path.join(dest_dir, os.path.dirname(key))
185+ from_file = value
186+
187+ # User specified only the directory, without renaming
188+ # the file.
189+ if not to_file:
190+ to_file = os.path.basename(from_file)
191+
192+ if not os.path.exists(to_dir):
193+ cmd_runner.run(["mkdir", "-p", to_dir],
194+ as_root=True).wait()
195+ dtb = _get_file_matching(os.path.join(search_dir,
196+ from_file))
197+ if not dtb:
198+ logger.warn('Could not find a valid dtb file, '
199+ 'skipping it.')
200+ continue
201+ else:
202+ dest = os.path.join(to_dir, to_file)
203+ logger.debug('Copying %s into %s' % (dtb, dest))
204+ cmd_runner.run(['cp', dtb, dest],
205+ as_root=True).wait()
206+ else:
207+ # Hopefully we should never get here.
208+ # This should only happen if the hwpack config YAML file is
209+ # wrong
210+ logger.warn('WARNING: Wrong syntax in metadata file. '
211+ 'Check the hwpack configuration file used to '
212+ 'generate the hwpack archive.')
213+
214+ @classmethod
215 def _dd_file(cls, from_file, to_file, seek, max_size=None):
216 assert from_file is not None, "No source file name given."
217 if max_size is not None:
218@@ -959,6 +1010,10 @@
219 # Handle copy_files field.
220 cls.copy_files(boot_disk)
221
222+ # Handle dtb_files field.
223+ if cls.dtb_files:
224+ cls._copy_dtb_files(cls.dtb_files, boot_disk, chroot_dir)
225+
226 cls.make_boot_files(
227 bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
228 rootfs_id, boot_disk, boot_device_or_file)

Subscribers

People subscribed via source and target branches