Merge lp:~salgado/linaro-image-tools/consolidate-board-config into lp:linaro-image-tools/11.11
- consolidate-board-config
- Merge into trunk
Proposed by
Guilherme Salgado
Status: | Merged |
---|---|
Merged at revision: | 238 |
Proposed branch: | lp:~salgado/linaro-image-tools/consolidate-board-config |
Merge into: | lp:linaro-image-tools/11.11 |
Prerequisite: | lp:~salgado/linaro-image-tools/config-class |
Diff against target: |
555 lines (+201/-158) 4 files modified
linaro-media-create (+2/-2) linaro_media_create/boards.py (+177/-10) linaro_media_create/populate_boot.py (+5/-129) linaro_media_create/tests/test_media_create.py (+17/-17) |
To merge this branch: | bzr merge lp:~salgado/linaro-image-tools/consolidate-board-config |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Linaro Maintainers | Pending | ||
Review via email: mp+46062@code.launchpad.net |
Commit message
Description of the change
Move board-specific stuff from populate_boot.py to boards.py
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'linaro-media-create' | |||
2 | --- linaro-media-create 2011-01-13 01:04:08 +0000 | |||
3 | +++ linaro-media-create 2011-01-13 01:04:08 +0000 | |||
4 | @@ -100,8 +100,8 @@ | |||
5 | 100 | 100 | ||
6 | 101 | if args.should_format_bootfs: | 101 | if args.should_format_bootfs: |
7 | 102 | populate_boot( | 102 | populate_boot( |
10 | 103 | args.board, board_config, ROOTFS_DIR, boot_partition, BOOT_DISK, | 103 | board_config, ROOTFS_DIR, boot_partition, BOOT_DISK, args.device, |
11 | 104 | args.device, TMP_DIR, args.is_live, args.is_lowmem, args.consoles) | 104 | args.is_live, args.is_lowmem, args.consoles) |
12 | 105 | 105 | ||
13 | 106 | if args.should_format_rootfs: | 106 | if args.should_format_rootfs: |
14 | 107 | create_swap = False | 107 | create_swap = False |
15 | 108 | 108 | ||
16 | === modified file 'linaro_media_create/boards.py' | |||
17 | --- linaro_media_create/boards.py 2011-01-13 01:04:08 +0000 | |||
18 | +++ linaro_media_create/boards.py 2011-01-13 01:04:08 +0000 | |||
19 | @@ -1,35 +1,48 @@ | |||
20 | 1 | """Configuration for boards supported by linaro-media-create. | 1 | """Configuration for boards supported by linaro-media-create. |
21 | 2 | 2 | ||
24 | 3 | To add support for a new board, you just need to create a subclass of | 3 | To add support for a new board, you need to create a subclass of |
25 | 4 | BoardConfig and set appropriate values for its variables. | 4 | BoardConfig, set appropriate values for its variables and add it to |
26 | 5 | board_configs at the bottom of this file. | ||
27 | 5 | """ | 6 | """ |
28 | 6 | 7 | ||
29 | 8 | import atexit | ||
30 | 9 | import glob | ||
31 | 10 | import os | ||
32 | 11 | import tempfile | ||
33 | 7 | import uuid | 12 | import uuid |
34 | 8 | 13 | ||
35 | 14 | from linaro_media_create import cmd_runner | ||
36 | 15 | |||
37 | 9 | ROOTFS_UUID = str(uuid.uuid4()) | 16 | ROOTFS_UUID = str(uuid.uuid4()) |
38 | 10 | 17 | ||
39 | 11 | 18 | ||
40 | 12 | class BoardConfig(object): | 19 | class BoardConfig(object): |
41 | 13 | """The configuration used when building an image for a board.""" | 20 | """The configuration used when building an image for a board.""" |
42 | 21 | # These attributes may not need to be redefined on some subclasses. | ||
43 | 14 | uboot_flavor = None | 22 | uboot_flavor = None |
44 | 15 | mmc_option = '0:1' | 23 | mmc_option = '0:1' |
45 | 16 | mmc_part_offset = 0 | 24 | mmc_part_offset = 0 |
48 | 17 | extra_serial_opts = None | 25 | fat_size = 32 |
49 | 18 | live_serial_opts = None | 26 | extra_serial_opts = '' |
50 | 27 | live_serial_opts = '' | ||
51 | 28 | extra_boot_args_options = None | ||
52 | 29 | |||
53 | 30 | # These attributes must be defined on all subclasses. | ||
54 | 19 | kernel_addr = None | 31 | kernel_addr = None |
55 | 20 | initrd_addr = None | 32 | initrd_addr = None |
56 | 21 | load_addr = None | 33 | load_addr = None |
57 | 22 | sub_arch = None | 34 | sub_arch = None |
58 | 23 | boot_script = None | 35 | boot_script = None |
59 | 24 | extra_boot_args_options = None | ||
60 | 25 | fat_size = 32 | ||
61 | 26 | 36 | ||
62 | 27 | @classmethod | 37 | @classmethod |
65 | 28 | def get_boot_cmd(cls, is_live, is_lowmem, consoles): | 38 | def _get_boot_cmd(cls, is_live, is_lowmem, consoles): |
66 | 29 | """Get the boot command for this board.""" | 39 | """Get the boot command for this board. |
67 | 40 | |||
68 | 41 | In general subclasses should not have to override this. | ||
69 | 42 | """ | ||
70 | 30 | boot_args_options = 'rootwait ro' | 43 | boot_args_options = 'rootwait ro' |
73 | 31 | if cls.extra_boot_args_options: | 44 | if cls.extra_boot_args_options is not None: |
74 | 32 | boot_args_options += " %s" % cls.extra_boot_args_options | 45 | boot_args_options += ' %s' % cls.extra_boot_args_options |
75 | 33 | serial_opts = '' | 46 | serial_opts = '' |
76 | 34 | if consoles is not None: | 47 | if consoles is not None: |
77 | 35 | for console in consoles: | 48 | for console in consoles: |
78 | @@ -63,6 +76,24 @@ | |||
79 | 63 | "%(boot_snippet)s %(boot_args_options)s'\n" | 76 | "%(boot_snippet)s %(boot_args_options)s'\n" |
80 | 64 | "boot" % replacements) | 77 | "boot" % replacements) |
81 | 65 | 78 | ||
82 | 79 | @classmethod | ||
83 | 80 | def make_boot_files(cls, uboot_parts_dir, is_live, is_lowmem, consoles, | ||
84 | 81 | root_dir, boot_dir, boot_script, boot_device_or_file): | ||
85 | 82 | boot_cmd = cls._get_boot_cmd(is_live, is_lowmem, consoles) | ||
86 | 83 | cls._make_boot_files( | ||
87 | 84 | uboot_parts_dir, boot_cmd, root_dir, boot_dir, boot_script, | ||
88 | 85 | boot_device_or_file) | ||
89 | 86 | |||
90 | 87 | @classmethod | ||
91 | 88 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, root_dir, boot_dir, | ||
92 | 89 | boot_script, boot_device_or_file): | ||
93 | 90 | """Make the necessary boot files for this board. | ||
94 | 91 | |||
95 | 92 | This is usually board-specific so ought to be defined in every | ||
96 | 93 | subclass. | ||
97 | 94 | """ | ||
98 | 95 | raise NotImplementedError() | ||
99 | 96 | |||
100 | 66 | 97 | ||
101 | 67 | class BeagleConfig(BoardConfig): | 98 | class BeagleConfig(BoardConfig): |
102 | 68 | uboot_flavor = 'omap3_beagle' | 99 | uboot_flavor = 'omap3_beagle' |
103 | @@ -77,6 +108,17 @@ | |||
104 | 77 | 'earlyprintk fixrtc nocompcache vram=12M omapfb.debug=y ' | 108 | 'earlyprintk fixrtc nocompcache vram=12M omapfb.debug=y ' |
105 | 78 | 'omapfb.mode=dvi:1280x720MR-16@60') | 109 | 'omapfb.mode=dvi:1280x720MR-16@60') |
106 | 79 | 110 | ||
107 | 111 | @classmethod | ||
108 | 112 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, | ||
109 | 113 | boot_dir, boot_script, boot_device_or_file): | ||
110 | 114 | mlo_file = os.path.join( | ||
111 | 115 | chroot_dir, 'usr', 'lib', 'x-loader-omap', 'MLO') | ||
112 | 116 | install_omap_boot_loader(mlo_file, boot_dir) | ||
113 | 117 | make_uImage(cls.load_addr, uboot_parts_dir, cls.sub_arch, boot_dir) | ||
114 | 118 | make_uInitrd(uboot_parts_dir, cls.sub_arch, boot_dir) | ||
115 | 119 | make_boot_script(boot_cmd, boot_script) | ||
116 | 120 | make_boot_ini(boot_script, boot_dir) | ||
117 | 121 | |||
118 | 80 | 122 | ||
119 | 81 | class PandaConfig(BoardConfig): | 123 | class PandaConfig(BoardConfig): |
120 | 82 | uboot_flavor = 'omap4_panda' | 124 | uboot_flavor = 'omap4_panda' |
121 | @@ -91,10 +133,29 @@ | |||
122 | 91 | 'earlyprintk fixrtc nocompcache vram = 32M omapfb.debug = y ' | 133 | 'earlyprintk fixrtc nocompcache vram = 32M omapfb.debug = y ' |
123 | 92 | 'omapfb.vram = 0:8M mem = 463M ip = none') | 134 | 'omapfb.vram = 0:8M mem = 463M ip = none') |
124 | 93 | 135 | ||
125 | 136 | @classmethod | ||
126 | 137 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, | ||
127 | 138 | boot_dir, boot_script, boot_device_or_file): | ||
128 | 139 | mlo_file = os.path.join( | ||
129 | 140 | chroot_dir, 'usr', 'lib', 'x-loader-omap4', 'MLO') | ||
130 | 141 | install_omap_boot_loader(mlo_file, boot_dir) | ||
131 | 142 | make_uImage(cls.load_addr, uboot_parts_dir, cls.sub_arch, boot_dir) | ||
132 | 143 | make_uInitrd(uboot_parts_dir, cls.sub_arch, boot_dir) | ||
133 | 144 | make_boot_script(boot_cmd, boot_script) | ||
134 | 145 | make_boot_ini(boot_script, boot_dir) | ||
135 | 146 | |||
136 | 94 | 147 | ||
137 | 95 | class IgepConfig(BeagleConfig): | 148 | class IgepConfig(BeagleConfig): |
138 | 96 | uboot_flavor = None | 149 | uboot_flavor = None |
139 | 97 | 150 | ||
140 | 151 | @classmethod | ||
141 | 152 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, | ||
142 | 153 | boot_dir, boot_script, boot_device_or_file): | ||
143 | 154 | make_uImage(cls.load_addr, uboot_parts_dir, cls.sub_arch, boot_dir) | ||
144 | 155 | make_uInitrd(uboot_parts_dir, cls.sub_arch, boot_dir) | ||
145 | 156 | make_boot_script(boot_cmd, boot_script) | ||
146 | 157 | make_boot_ini(boot_script, boot_dir) | ||
147 | 158 | |||
148 | 98 | 159 | ||
149 | 99 | class Ux500Config(BoardConfig): | 160 | class Ux500Config(BoardConfig): |
150 | 100 | extra_serial_opts = 'console = tty0 console = ttyAMA2,115200n8' | 161 | extra_serial_opts = 'console = tty0 console = ttyAMA2,115200n8' |
151 | @@ -111,6 +172,13 @@ | |||
152 | 111 | 'hwmem = 48M@302M mem = 152M@360M') | 172 | 'hwmem = 48M@302M mem = 152M@360M') |
153 | 112 | mmc_option = '1:1' | 173 | mmc_option = '1:1' |
154 | 113 | 174 | ||
155 | 175 | @classmethod | ||
156 | 176 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, | ||
157 | 177 | boot_dir, boot_script, boot_device_or_file): | ||
158 | 178 | make_uImage(cls.load_addr, uboot_parts_dir, cls.sub_arch, boot_dir) | ||
159 | 179 | make_uInitrd(uboot_parts_dir, cls.sub_arch, boot_dir) | ||
160 | 180 | make_boot_script(boot_cmd, boot_script) | ||
161 | 181 | |||
162 | 114 | 182 | ||
163 | 115 | class Mx51evkConfig(BoardConfig): | 183 | class Mx51evkConfig(BoardConfig): |
164 | 116 | extra_serial_opts = 'console = tty0 console = ttymxc0,115200n8' | 184 | extra_serial_opts = 'console = tty0 console = ttymxc0,115200n8' |
165 | @@ -123,6 +191,16 @@ | |||
166 | 123 | mmc_part_offset = 1 | 191 | mmc_part_offset = 1 |
167 | 124 | mmc_option = '0:2' | 192 | mmc_option = '0:2' |
168 | 125 | 193 | ||
169 | 194 | @classmethod | ||
170 | 195 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, | ||
171 | 196 | boot_dir, boot_script, boot_device_or_file): | ||
172 | 197 | uboot_file = os.path.join( | ||
173 | 198 | chroot_dir, 'usr', 'lib', 'u-boot', 'mx51evk', 'u-boot.imx') | ||
174 | 199 | install_mx51evk_boot_loader(uboot_file, boot_device_or_file) | ||
175 | 200 | make_uImage(cls.load_addr, uboot_parts_dir, cls.sub_arch, boot_dir) | ||
176 | 201 | make_uInitrd(uboot_parts_dir, cls.sub_arch, boot_dir) | ||
177 | 202 | make_boot_script(boot_cmd, boot_script) | ||
178 | 203 | |||
179 | 126 | 204 | ||
180 | 127 | class VexpressConfig(BoardConfig): | 205 | class VexpressConfig(BoardConfig): |
181 | 128 | uboot_flavor = 'ca9x4_ct_vxp' | 206 | uboot_flavor = 'ca9x4_ct_vxp' |
182 | @@ -137,6 +215,12 @@ | |||
183 | 137 | # only allows for FAT16 | 215 | # only allows for FAT16 |
184 | 138 | fat_size = 16 | 216 | fat_size = 16 |
185 | 139 | 217 | ||
186 | 218 | @classmethod | ||
187 | 219 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, | ||
188 | 220 | boot_dir, boot_script): | ||
189 | 221 | make_uImage(cls.load_addr, uboot_parts_dir, cls.sub_arch, boot_dir) | ||
190 | 222 | make_uInitrd(uboot_parts_dir, cls.sub_arch, boot_dir) | ||
191 | 223 | |||
192 | 140 | 224 | ||
193 | 141 | board_configs = { | 225 | board_configs = { |
194 | 142 | 'beagle': BeagleConfig, | 226 | 'beagle': BeagleConfig, |
195 | @@ -146,3 +230,86 @@ | |||
196 | 146 | 'ux500': Ux500Config, | 230 | 'ux500': Ux500Config, |
197 | 147 | 'mx51evk': Mx51evkConfig, | 231 | 'mx51evk': Mx51evkConfig, |
198 | 148 | } | 232 | } |
199 | 233 | |||
200 | 234 | |||
201 | 235 | def _run_mkimage(img_type, load_addr, entry_point, name, img_data, img, | ||
202 | 236 | stdout=None, as_root=True): | ||
203 | 237 | cmd = ['mkimage', | ||
204 | 238 | '-A', 'arm', | ||
205 | 239 | '-O', 'linux', | ||
206 | 240 | '-T', img_type, | ||
207 | 241 | '-C', 'none', | ||
208 | 242 | '-a', load_addr, | ||
209 | 243 | '-e', load_addr, | ||
210 | 244 | '-n', name, | ||
211 | 245 | '-d', img_data, | ||
212 | 246 | img] | ||
213 | 247 | proc = cmd_runner.run(cmd, as_root=as_root, stdout=stdout) | ||
214 | 248 | proc.wait() | ||
215 | 249 | return proc.returncode | ||
216 | 250 | |||
217 | 251 | |||
218 | 252 | def _get_file_matching(regex): | ||
219 | 253 | """Return a file whose path matches the given regex. | ||
220 | 254 | |||
221 | 255 | If zero or more than one files match, raise a ValueError. | ||
222 | 256 | """ | ||
223 | 257 | files = glob.glob(regex) | ||
224 | 258 | if len(files) == 1: | ||
225 | 259 | return files[0] | ||
226 | 260 | elif len(files) == 0: | ||
227 | 261 | raise ValueError( | ||
228 | 262 | "No files found matching '%s'; can't continue" % regex) | ||
229 | 263 | else: | ||
230 | 264 | # TODO: Could ask the user to chosse which file to use instead of | ||
231 | 265 | # raising an exception. | ||
232 | 266 | raise ValueError("Too many files matching '%s' found." % regex) | ||
233 | 267 | |||
234 | 268 | |||
235 | 269 | def make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk): | ||
236 | 270 | img_data = _get_file_matching( | ||
237 | 271 | '%s/vmlinuz-*-%s' % (uboot_parts_dir, sub_arch)) | ||
238 | 272 | img = '%s/uImage' % boot_disk | ||
239 | 273 | return _run_mkimage( | ||
240 | 274 | 'kernel', load_addr, load_addr, 'Linux', img_data, img) | ||
241 | 275 | |||
242 | 276 | |||
243 | 277 | def make_uInitrd(uboot_parts_dir, sub_arch, boot_disk): | ||
244 | 278 | img_data = _get_file_matching( | ||
245 | 279 | '%s/initrd.img-*-%s' % (uboot_parts_dir, sub_arch)) | ||
246 | 280 | img = '%s/uInitrd' % boot_disk | ||
247 | 281 | return _run_mkimage('ramdisk', '0', '0', 'initramfs', img_data, img) | ||
248 | 282 | |||
249 | 283 | |||
250 | 284 | def make_boot_script(boot_script_data, boot_script): | ||
251 | 285 | # Need to save the boot script data into a file that will be passed to | ||
252 | 286 | # mkimage. | ||
253 | 287 | _, tmpfile = tempfile.mkstemp() | ||
254 | 288 | atexit.register(os.unlink, tmpfile) | ||
255 | 289 | with open(tmpfile, 'w') as fd: | ||
256 | 290 | fd.write(boot_script_data) | ||
257 | 291 | return _run_mkimage( | ||
258 | 292 | 'script', '0', '0', 'boot script', tmpfile, boot_script) | ||
259 | 293 | |||
260 | 294 | |||
261 | 295 | def install_mx51evk_boot_loader(imx_file, boot_device_or_file): | ||
262 | 296 | proc = cmd_runner.run([ | ||
263 | 297 | "dd", | ||
264 | 298 | "if=%s" % imx_file, | ||
265 | 299 | "of=%s" % boot_device_or_file, | ||
266 | 300 | "bs=1024", | ||
267 | 301 | "seek=1", | ||
268 | 302 | "conv=notrunc"], as_root=True) | ||
269 | 303 | proc.wait() | ||
270 | 304 | |||
271 | 305 | |||
272 | 306 | def install_omap_boot_loader(mlo_file, boot_disk): | ||
273 | 307 | cmd_runner.run(["cp", "-v", mlo_file, boot_disk], as_root=True).wait() | ||
274 | 308 | # XXX: Is this really needed? | ||
275 | 309 | cmd_runner.run(["sync"]).wait() | ||
276 | 310 | |||
277 | 311 | |||
278 | 312 | def make_boot_ini(boot_script, boot_disk): | ||
279 | 313 | proc = cmd_runner.run( | ||
280 | 314 | ["cp", "-v", boot_script, "%s/boot.ini" % boot_disk], as_root=True) | ||
281 | 315 | proc.wait() | ||
282 | 149 | 316 | ||
283 | === modified file 'linaro_media_create/populate_boot.py' | |||
284 | --- linaro_media_create/populate_boot.py 2011-01-13 01:04:08 +0000 | |||
285 | +++ linaro_media_create/populate_boot.py 2011-01-13 01:04:08 +0000 | |||
286 | @@ -1,94 +1,11 @@ | |||
287 | 1 | import errno | 1 | import errno |
288 | 2 | import glob | ||
289 | 3 | import os | 2 | import os |
290 | 4 | 3 | ||
291 | 5 | from linaro_media_create import cmd_runner | 4 | from linaro_media_create import cmd_runner |
292 | 6 | 5 | ||
293 | 7 | 6 | ||
378 | 8 | def _run_mkimage(img_type, load_addr, entry_point, name, img_data, img, | 7 | def populate_boot(board_config, chroot_dir, boot_partition, boot_disk, |
379 | 9 | stdout=None, as_root=True): | 8 | boot_device_or_file, is_live, is_lowmem, consoles): |
296 | 10 | cmd = ['mkimage', | ||
297 | 11 | '-A', 'arm', | ||
298 | 12 | '-O', 'linux', | ||
299 | 13 | '-T', img_type, | ||
300 | 14 | '-C', 'none', | ||
301 | 15 | '-a', load_addr, | ||
302 | 16 | '-e', load_addr, | ||
303 | 17 | '-n', name, | ||
304 | 18 | '-d', img_data, | ||
305 | 19 | img] | ||
306 | 20 | proc = cmd_runner.run(cmd, as_root=as_root, stdout=stdout) | ||
307 | 21 | proc.wait() | ||
308 | 22 | return proc.returncode | ||
309 | 23 | |||
310 | 24 | |||
311 | 25 | def _get_file_matching(regex): | ||
312 | 26 | """Return a file whose path matches the given regex. | ||
313 | 27 | |||
314 | 28 | If zero or more than one files match, raise a ValueError. | ||
315 | 29 | """ | ||
316 | 30 | files = glob.glob(regex) | ||
317 | 31 | if len(files) == 1: | ||
318 | 32 | return files[0] | ||
319 | 33 | elif len(files) == 0: | ||
320 | 34 | raise ValueError( | ||
321 | 35 | "No files found matching '%s'; can't continue" % regex) | ||
322 | 36 | else: | ||
323 | 37 | # TODO: Could ask the user to chosse which file to use instead of | ||
324 | 38 | # raising an exception. | ||
325 | 39 | raise ValueError("Too many files matching '%s' found." % regex) | ||
326 | 40 | |||
327 | 41 | |||
328 | 42 | def make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk): | ||
329 | 43 | img_data = _get_file_matching( | ||
330 | 44 | '%s/vmlinuz-*-%s' % (uboot_parts_dir, sub_arch)) | ||
331 | 45 | img = '%s/uImage' % boot_disk | ||
332 | 46 | return _run_mkimage( | ||
333 | 47 | 'kernel', load_addr, load_addr, 'Linux', img_data, img) | ||
334 | 48 | |||
335 | 49 | |||
336 | 50 | def make_uInitrd(uboot_parts_dir, sub_arch, boot_disk): | ||
337 | 51 | img_data = _get_file_matching( | ||
338 | 52 | '%s/initrd.img-*-%s' % (uboot_parts_dir, sub_arch)) | ||
339 | 53 | img = '%s/uInitrd' % boot_disk | ||
340 | 54 | return _run_mkimage('ramdisk', '0', '0', 'initramfs', img_data, img) | ||
341 | 55 | |||
342 | 56 | |||
343 | 57 | def make_boot_script(boot_script_data, tmp_dir, boot_script): | ||
344 | 58 | # Need to save the boot script data into a file that will be passed to | ||
345 | 59 | # mkimage. | ||
346 | 60 | data_file = '%s/boot.cmd' % tmp_dir | ||
347 | 61 | with open(data_file, 'w') as fd: | ||
348 | 62 | fd.write(boot_script_data) | ||
349 | 63 | return _run_mkimage( | ||
350 | 64 | 'script', '0', '0', 'boot script', data_file, boot_script) | ||
351 | 65 | |||
352 | 66 | |||
353 | 67 | def install_mx51evk_boot_loader(imx_file, boot_device_or_file): | ||
354 | 68 | proc = cmd_runner.run([ | ||
355 | 69 | "dd", | ||
356 | 70 | "if=%s" % imx_file, | ||
357 | 71 | "of=%s" % boot_device_or_file, | ||
358 | 72 | "bs=1024", | ||
359 | 73 | "seek=1", | ||
360 | 74 | "conv=notrunc"], as_root=True) | ||
361 | 75 | proc.wait() | ||
362 | 76 | |||
363 | 77 | |||
364 | 78 | def install_omap_boot_loader(mlo_file, boot_disk): | ||
365 | 79 | cmd_runner.run(["cp", "-v", mlo_file, boot_disk], as_root=True).wait() | ||
366 | 80 | # XXX: Is this really needed? | ||
367 | 81 | cmd_runner.run(["sync"]).wait() | ||
368 | 82 | |||
369 | 83 | |||
370 | 84 | def make_boot_ini(boot_script, boot_disk): | ||
371 | 85 | proc = cmd_runner.run( | ||
372 | 86 | ["cp", "-v", boot_script, "%s/boot.ini" % boot_disk], as_root=True) | ||
373 | 87 | proc.wait() | ||
374 | 88 | |||
375 | 89 | |||
376 | 90 | def populate_boot(board, board_config, chroot_dir, boot_partition, boot_disk, | ||
377 | 91 | boot_device_or_file, tmp_dir, is_live, is_lowmem, consoles): | ||
380 | 92 | 9 | ||
381 | 93 | parts_dir = 'boot' | 10 | parts_dir = 'boot' |
382 | 94 | if is_live: | 11 | if is_live: |
383 | @@ -115,50 +32,9 @@ | |||
384 | 115 | dict(boot_disk=boot_disk, | 32 | dict(boot_disk=boot_disk, |
385 | 116 | boot_script_name=board_config.boot_script)) | 33 | boot_script_name=board_config.boot_script)) |
386 | 117 | 34 | ||
431 | 118 | load_addr = board_config.load_addr | 35 | board_config.make_boot_files( |
432 | 119 | sub_arch = board_config.sub_arch | 36 | uboot_parts_dir, is_live, is_lowmem, consoles, chroot_dir, boot_disk, |
433 | 120 | boot_cmd = board_config.get_boot_cmd(is_live, is_lowmem, consoles) | 37 | boot_script, boot_device_or_file) |
390 | 121 | |||
391 | 122 | # TODO: Once linaro-media-create is fully ported to python, we should | ||
392 | 123 | # split this into several board-specific functions that are defined | ||
393 | 124 | # somewhere else and just called here. | ||
394 | 125 | if board in ["beagle", "panda"]: | ||
395 | 126 | xloader_dir = 'x-loader-omap' | ||
396 | 127 | if board == "panda": | ||
397 | 128 | xloader_dir = 'x-loader-omap4' | ||
398 | 129 | mlo_file = os.path.join( | ||
399 | 130 | chroot_dir, 'usr', 'lib', xloader_dir, 'MLO') | ||
400 | 131 | install_omap_boot_loader(mlo_file, boot_disk) | ||
401 | 132 | make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk) | ||
402 | 133 | make_uInitrd(uboot_parts_dir, sub_arch, boot_disk) | ||
403 | 134 | make_boot_script(boot_cmd, tmp_dir, boot_script) | ||
404 | 135 | make_boot_ini(boot_script, boot_disk) | ||
405 | 136 | |||
406 | 137 | elif board == "igep": | ||
407 | 138 | make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk) | ||
408 | 139 | make_uInitrd(uboot_parts_dir, sub_arch, boot_disk) | ||
409 | 140 | make_boot_script(boot_cmd, tmp_dir, boot_script) | ||
410 | 141 | make_boot_ini(boot_script, boot_disk) | ||
411 | 142 | |||
412 | 143 | elif board == "ux500": | ||
413 | 144 | make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk) | ||
414 | 145 | make_uInitrd(uboot_parts_dir, sub_arch, boot_disk) | ||
415 | 146 | make_boot_script(boot_cmd, tmp_dir, boot_script) | ||
416 | 147 | |||
417 | 148 | elif board == "vexpress": | ||
418 | 149 | make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk) | ||
419 | 150 | make_uInitrd(uboot_parts_dir, sub_arch, boot_disk) | ||
420 | 151 | |||
421 | 152 | elif board == "mx51evk": | ||
422 | 153 | install_mx51evk_boot_loader( | ||
423 | 154 | "binary/usr/lib/u-boot/mx51evk/u-boot.imx", boot_device_or_file) | ||
424 | 155 | make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk) | ||
425 | 156 | make_uInitrd(uboot_parts_dir, sub_arch, boot_disk) | ||
426 | 157 | make_boot_script(boot_cmd, tmp_dir, boot_script) | ||
427 | 158 | |||
428 | 159 | else: | ||
429 | 160 | raise AssertionError( | ||
430 | 161 | "Internal error; missing support for board: %s" % board) | ||
434 | 162 | 38 | ||
435 | 163 | cmd_runner.run(['sync']).wait() | 39 | cmd_runner.run(['sync']).wait() |
436 | 164 | try: | 40 | try: |
437 | 165 | 41 | ||
438 | === modified file 'linaro_media_create/tests/test_media_create.py' | |||
439 | --- linaro_media_create/tests/test_media_create.py 2011-01-13 01:04:08 +0000 | |||
440 | +++ linaro_media_create/tests/test_media_create.py 2011-01-13 01:04:08 +0000 | |||
441 | @@ -6,6 +6,7 @@ | |||
442 | 6 | import string | 6 | import string |
443 | 7 | import subprocess | 7 | import subprocess |
444 | 8 | import sys | 8 | import sys |
445 | 9 | import tempfile | ||
446 | 9 | import time | 10 | import time |
447 | 10 | 11 | ||
448 | 11 | from testtools import TestCase | 12 | from testtools import TestCase |
449 | @@ -16,13 +17,18 @@ | |||
450 | 16 | check_device, | 17 | check_device, |
451 | 17 | cmd_runner, | 18 | cmd_runner, |
452 | 18 | ensure_command, | 19 | ensure_command, |
454 | 19 | populate_boot, | 20 | boards, |
455 | 20 | partitions, | 21 | partitions, |
456 | 21 | rootfs, | 22 | rootfs, |
457 | 22 | ) | 23 | ) |
458 | 23 | from linaro_media_create.boards import ( | 24 | from linaro_media_create.boards import ( |
459 | 24 | board_configs, | 25 | board_configs, |
460 | 26 | make_boot_script, | ||
461 | 27 | make_uImage, | ||
462 | 28 | make_uInitrd, | ||
463 | 25 | ROOTFS_UUID, | 29 | ROOTFS_UUID, |
464 | 30 | _get_file_matching, | ||
465 | 31 | _run_mkimage, | ||
466 | 26 | ) | 32 | ) |
467 | 27 | from linaro_media_create.hwpack import ( | 33 | from linaro_media_create.hwpack import ( |
468 | 28 | copy_file, | 34 | copy_file, |
469 | @@ -43,13 +49,6 @@ | |||
470 | 43 | run_sfdisk_commands, | 49 | run_sfdisk_commands, |
471 | 44 | setup_partitions, | 50 | setup_partitions, |
472 | 45 | ) | 51 | ) |
473 | 46 | from linaro_media_create.populate_boot import ( | ||
474 | 47 | make_boot_script, | ||
475 | 48 | make_uImage, | ||
476 | 49 | make_uInitrd, | ||
477 | 50 | _get_file_matching, | ||
478 | 51 | _run_mkimage, | ||
479 | 52 | ) | ||
480 | 53 | from linaro_media_create.remove_binary_dir import remove_dir | 52 | from linaro_media_create.remove_binary_dir import remove_dir |
481 | 54 | from linaro_media_create.rootfs import ( | 53 | from linaro_media_create.rootfs import ( |
482 | 55 | create_flash_kernel_config, | 54 | create_flash_kernel_config, |
483 | @@ -96,7 +95,7 @@ | |||
484 | 96 | class TestGetBootCmd(TestCase): | 95 | class TestGetBootCmd(TestCase): |
485 | 97 | 96 | ||
486 | 98 | def test_vexpress(self): | 97 | def test_vexpress(self): |
488 | 99 | boot_cmd = board_configs['vexpress'].get_boot_cmd( | 98 | boot_cmd = board_configs['vexpress']._get_boot_cmd( |
489 | 100 | is_live=False, is_lowmem=False, consoles=None) | 99 | is_live=False, is_lowmem=False, consoles=None) |
490 | 101 | expected = ( | 100 | expected = ( |
491 | 102 | "setenv bootcmd 'fatload mmc 0:1 0x60008000 uImage; fatload mmc " | 101 | "setenv bootcmd 'fatload mmc 0:1 0x60008000 uImage; fatload mmc " |
492 | @@ -106,7 +105,7 @@ | |||
493 | 106 | self.assertEqual(expected, boot_cmd) | 105 | self.assertEqual(expected, boot_cmd) |
494 | 107 | 106 | ||
495 | 108 | def test_mx51evk(self): | 107 | def test_mx51evk(self): |
497 | 109 | boot_cmd = board_configs['mx51evk'].get_boot_cmd( | 108 | boot_cmd = board_configs['mx51evk']._get_boot_cmd( |
498 | 110 | is_live=False, is_lowmem=False, consoles=None) | 109 | is_live=False, is_lowmem=False, consoles=None) |
499 | 111 | expected = ( | 110 | expected = ( |
500 | 112 | "setenv bootcmd 'fatload mmc 0:2 0x90000000 uImage; fatload mmc " | 111 | "setenv bootcmd 'fatload mmc 0:2 0x90000000 uImage; fatload mmc " |
501 | @@ -116,7 +115,7 @@ | |||
502 | 116 | self.assertEqual(expected, boot_cmd) | 115 | self.assertEqual(expected, boot_cmd) |
503 | 117 | 116 | ||
504 | 118 | def test_ux500(self): | 117 | def test_ux500(self): |
506 | 119 | boot_cmd = board_configs['ux500'].get_boot_cmd( | 118 | boot_cmd = board_configs['ux500']._get_boot_cmd( |
507 | 120 | is_live=False, is_lowmem=False, consoles=None) | 119 | is_live=False, is_lowmem=False, consoles=None) |
508 | 121 | expected = ( | 120 | expected = ( |
509 | 122 | "setenv bootcmd 'fatload mmc 1:1 0x00100000 uImage; fatload mmc " | 121 | "setenv bootcmd 'fatload mmc 1:1 0x00100000 uImage; fatload mmc " |
510 | @@ -130,7 +129,7 @@ | |||
511 | 130 | self.assertEqual(expected, boot_cmd) | 129 | self.assertEqual(expected, boot_cmd) |
512 | 131 | 130 | ||
513 | 132 | def test_panda(self): | 131 | def test_panda(self): |
515 | 133 | boot_cmd = board_configs['panda'].get_boot_cmd( | 132 | boot_cmd = board_configs['panda']._get_boot_cmd( |
516 | 134 | is_live=False, is_lowmem=False, consoles=None) | 133 | is_live=False, is_lowmem=False, consoles=None) |
517 | 135 | expected = ( | 134 | expected = ( |
518 | 136 | "setenv bootcmd 'fatload mmc 0:1 0x80200000 uImage; fatload mmc " | 135 | "setenv bootcmd 'fatload mmc 0:1 0x80200000 uImage; fatload mmc " |
519 | @@ -142,7 +141,7 @@ | |||
520 | 142 | self.assertEqual(expected, boot_cmd) | 141 | self.assertEqual(expected, boot_cmd) |
521 | 143 | 142 | ||
522 | 144 | def test_beagle(self): | 143 | def test_beagle(self): |
524 | 145 | boot_cmd = board_configs['beagle'].get_boot_cmd( | 144 | boot_cmd = board_configs['beagle']._get_boot_cmd( |
525 | 146 | is_live=False, is_lowmem=False, consoles=None) | 145 | is_live=False, is_lowmem=False, consoles=None) |
526 | 147 | expected = ( | 146 | expected = ( |
527 | 148 | "setenv bootcmd 'fatload mmc 0:1 0x80000000 uImage; " | 147 | "setenv bootcmd 'fatload mmc 0:1 0x80000000 uImage; " |
528 | @@ -229,7 +228,7 @@ | |||
529 | 229 | 228 | ||
530 | 230 | def _mock_get_file_matching(self): | 229 | def _mock_get_file_matching(self): |
531 | 231 | self.useFixture(MockSomethingFixture( | 230 | self.useFixture(MockSomethingFixture( |
533 | 232 | populate_boot, '_get_file_matching', | 231 | boards, '_get_file_matching', |
534 | 233 | lambda regex: regex)) | 232 | lambda regex: regex)) |
535 | 234 | 233 | ||
536 | 235 | def _mock_Popen(self): | 234 | def _mock_Popen(self): |
537 | @@ -258,14 +257,15 @@ | |||
538 | 258 | self.assertEqual([expected], fixture.mock.calls) | 257 | self.assertEqual([expected], fixture.mock.calls) |
539 | 259 | 258 | ||
540 | 260 | def test_make_boot_script(self): | 259 | def test_make_boot_script(self): |
541 | 260 | self.useFixture(MockSomethingFixture( | ||
542 | 261 | tempfile, 'mkstemp', lambda: (-1, '/tmp/random-abxzr'))) | ||
543 | 261 | self._mock_get_file_matching() | 262 | self._mock_get_file_matching() |
544 | 262 | fixture = self._mock_Popen() | 263 | fixture = self._mock_Popen() |
547 | 263 | tempdir = self.useFixture(CreateTempDirFixture()).tempdir | 264 | make_boot_script('boot script data', 'boot_script') |
546 | 264 | make_boot_script('boot script data', tempdir, 'boot_script') | ||
548 | 265 | expected = [ | 265 | expected = [ |
549 | 266 | 'sudo', 'mkimage', '-A', 'arm', '-O', 'linux', '-T', 'script', | 266 | 'sudo', 'mkimage', '-A', 'arm', '-O', 'linux', '-T', 'script', |
550 | 267 | '-C', 'none', '-a', '0', '-e', '0', '-n', 'boot script', | 267 | '-C', 'none', '-a', '0', '-e', '0', '-n', 'boot script', |
552 | 268 | '-d', '%s/boot.cmd' % tempdir, 'boot_script'] | 268 | '-d', '/tmp/random-abxzr', 'boot_script'] |
553 | 269 | self.assertEqual([expected], fixture.mock.calls) | 269 | self.assertEqual([expected], fixture.mock.calls) |
554 | 270 | 270 | ||
555 | 271 | def test_get_file_matching(self): | 271 | def test_get_file_matching(self): |