Merge lp:~mabac/linaro-image-tools/bug-744857 into lp:linaro-image-tools/11.11
- bug-744857
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 315 |
Proposed branch: | lp:~mabac/linaro-image-tools/bug-744857 |
Merge into: | lp:linaro-image-tools/11.11 |
Diff against target: |
346 lines (+104/-56) 3 files modified
linaro_image_tools/hwpack/packages.py (+1/-1) linaro_image_tools/media_create/boards.py (+60/-51) linaro_image_tools/media_create/tests/test_media_create.py (+43/-4) |
To merge this branch: | bzr merge lp:~mabac/linaro-image-tools/bug-744857 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Loïc Minier (community) | Approve | ||
James Westby (community) | Approve | ||
Guilherme Salgado | Pending | ||
Review via email: mp+55492@code.launchpad.net |
Commit message
Description of the change
Hi,
This branch addresses Bug #744857 by changing the board config item 'kernel_suffix' to become 'kernel_flavors' which accepts a list of strings.
Each string in the list is supposed to be a partial regexp just as the kernel_suffix was.
This change is implemented by making boards.
An alternative to the prefix parameter would be to have make_uImage and make_uInitrd prepend their respective prefixes and supply a list of complete regexps to _get_file_matching but I found that uglier.
Thanks,
Mattias
Mattias Backman (mabac) wrote : | # |
> Hi,
>
> 253 + prefix = ''.join(
> 254 + random.
> 255 + junk_prefix = ''.join(
> 256 + random.
>
> Please avoid things like this in tests. This particular test will test
> the wrong thing occasionally when the strings end up the same. Not so bad in
> this
> case, but something to avoid anyway.
>
> If you want to signal that the actual strings don't matter then you can use
> self.getUniqueS
Ok, that's fixed.
>
> Otherwise this looks good to me, provided that the mx changes are what we want
> to do.
I think they are.
Eric, does this look ok?
Thanks,
Mattias
Loïc Minier (lool) wrote : | # |
Thanks for working on this!
On Wed, Mar 30, 2011, Mattias Backman wrote:
> vmlinuz = _get_file_matching(
> + [os.path.
[...]
> + kernel_flavors = ['linaro-lt-mx5', 'linaro-mx51']
[...]
> +def _get_file_
[...]
> + for suffix in suffixes:
> + regex = prefix + suffix
> + files = glob.glob(regex)
> + if len(files) == 1:
> + return files[0]
> + elif len(files) > 1:
> + # TODO: Could ask the user to choose which file to use instead of
> + # raising an exception.
> + raise ValueError("Too many files matching '%s' found." % regex)
> + raise ValueError(
> + "No files found matching '%s[%s]'; can't continue" % (prefix,
> + '|'.join(
I wonder whether it would look a bit nicer with:
_get_
so that we're not dealing with "prefix" and "suffix".
(_get_
Since it's also getting quite specific, perhaps it would make sense to
move this to a BoardConfig function like:
_get_
and let it use self.kflavors.
I'm not sold on my own proposals above; the code can also go in as is,
except for James comment, I don't think we actually need random strings
and something like "foo" and "bar" would probably be fine.
Technically, there's also a potential bug if there is:
vmlinuz-mx5
vmlinuz-mx51
initrd-mx51
you might pick vmlinuz-mx5 + initrd-mx51, but that's a bug in the
rootfs in the first place, so not too worried about; if there was some
kind of assert, I wouldn't mind.
Thanks!
--
Loïc Minier
Loïc Minier (lool) wrote : | # |
On r311, you drop -mx53 and add -mx5; I think it wouldn't hurt to keep -mx5 working, for instance until 11.05 is released; it's cheap and it allows using older hwpacks.
There is a question of which order we use for kernel flavors; do we prefer the more specific name over the least specific name (mx51 first, then mx5) or do we prefer the latest name over the older names (linaro-lt-mx5 before linaro-lt-mx53). The latter is interesting because it's expected that you have exactly one kernel and we know which Linaro ones are the best ones, but I find the former rules easier to be consistent with. Anyway, we can think of a better mechanism in the future or allow overriding the kernel flavor.
If you're tempted, you could also commit a similar fix for bug #720114 by supporting the "omap4" kernel flavor. I think it was used in 10.11, and is still used in 11.05, so ordering wont help as both omap and omap4 are valid.
Loïc Minier (lool) wrote : | # |
Would also be nice to set kernel_flavors to u8500, ux500 or something similar for bug #737173
- 308. By Loïc Minier
-
Merge lp:~lag/linaro-image-tools/lt-ux500-support but change glob from "u*500"
to "u?500"; fixes support for new name of vmlinuz file in U8500 hwpack;
LP: #737173.
Mattias Backman (mabac) wrote : | # |
> On r311, you drop -mx53 and add -mx5; I think it wouldn't hurt to keep -mx5
> working, for instance until 11.05 is released; it's cheap and it allows using
> older hwpacks.
Ok, I re-added -mx53.
>
> There is a question of which order we use for kernel flavors; do we prefer the
> more specific name over the least specific name (mx51 first, then mx5) or do
> we prefer the latest name over the older names (linaro-lt-mx5 before linaro-
> lt-mx53). The latter is interesting because it's expected that you have
> exactly one kernel and we know which Linaro ones are the best ones, but I find
> the former rules easier to be consistent with. Anyway, we can think of a
> better mechanism in the future or allow overriding the kernel flavor.
The current fix is as simple as just using the suffixes in order and if one early in the list matches more than one kernel it fails, even if a later suffix would match just one file. Is it ok to keep this behavior until the above is looked into?
>
> If you're tempted, you could also commit a similar fix for bug #720114 by
> supporting the "omap4" kernel flavor. I think it was used in 10.11, and is
> still used in 11.05, so ordering wont help as both omap and omap4 are valid.
So this might not work as expected?
+ kernel_flavors = ['linaro-omap4', 'linaro-omap']
It will use -omap4 if that kernel is found and -omap otherwise.
Mattias Backman (mabac) wrote : | # |
> Would also be nice to set kernel_flavors to u8500, ux500 or something similar
> for bug #737173
I see this has been worked on in trunk. Should I make this
60 + kernel_flavors = ['u8500', 'ux500', 'u?500']
or will the explicit list ['u8500', 'ux500'] cover it?
Mattias Backman (mabac) wrote : | # |
> Thanks for working on this!
>
> On Wed, Mar 30, 2011, Mattias Backman wrote:
> > vmlinuz = _get_file_matching(
> > + [os.path.
> [...]
> > + kernel_flavors = ['linaro-lt-mx5', 'linaro-mx51']
> [...]
> > +def _get_file_
> [...]
> > + for suffix in suffixes:
> > + regex = prefix + suffix
> > + files = glob.glob(regex)
> > + if len(files) == 1:
> > + return files[0]
> > + elif len(files) > 1:
> > + # TODO: Could ask the user to choose which file to use instead
> of
> > + # raising an exception.
> > + raise ValueError("Too many files matching '%s' found." % regex)
> > + raise ValueError(
> > + "No files found matching '%s[%s]'; can't continue" % (prefix,
> > +
> '|'.join(
>
> I wonder whether it would look a bit nicer with:
> _get_file_
> so that we're not dealing with "prefix" and "suffix".
> (_get_file_
>
> Since it's also getting quite specific, perhaps it would make sense to
> move this to a BoardConfig function like:
> _get_kflavor_
> and let it use self.kflavors.
That would actually help with the assert suggestion below.
>
> I'm not sold on my own proposals above; the code can also go in as is,
> except for James comment, I don't think we actually need random strings
> and something like "foo" and "bar" would probably be fine.
>
>
> Technically, there's also a potential bug if there is:
> vmlinuz-mx5
> vmlinuz-mx51
> initrd-mx51
> you might pick vmlinuz-mx5 + initrd-mx51, but that's a bug in the
> rootfs in the first place, so not too worried about; if there was some
> kind of assert, I wouldn't mind.
I can't find a good place to do this since the file names matched by the regexp are not available on the same level. Something like this in BoardConfig would make that assert simpler.
def _make_boot_
...
kfile = _get_kflavor_
ifile = _get_initrd_
assert(files match in some way)
make_
make_
Would you like me to make this change?
Loïc Minier (lool) wrote : | # |
On Mon, Apr 04, 2011, Mattias Backman wrote:
> ...
> kfile = _get_kflavor_
> ifile = _get_initrd_
> assert(files match in some way)
> make_uImage(kfile, boot_dir)
> make_uInitrd(ifile, boot_dir)
Sounds good!
There might be another way to deal with this:
(kfile, flavor) = _get_kflavor_
(ifile, _) _get_kflavor_
i.e. pass the list of flavors to the matching function.
That way, you don't need an assert but kfile and ifile are of the same
flavor by construction.
--
Loïc Minier
Loïc Minier (lool) wrote : | # |
On Mon, Apr 04, 2011, Mattias Backman wrote:
> The current fix is as simple as just using the suffixes in order and
> if one early in the list matches more than one kernel it fails, even
> if a later suffix would match just one file. Is it ok to keep this
> behavior until the above is looked into?
I think it's fine for now, yes
> > If you're tempted, you could also commit a similar fix for bug #720114 by
> > supporting the "omap4" kernel flavor. I think it was used in 10.11, and is
> > still used in 11.05, so ordering wont help as both omap and omap4 are valid.
>
> So this might not work as expected?
> + kernel_flavors = ['linaro-omap4', 'linaro-omap']
> It will use -omap4 if that kernel is found and -omap otherwise.
I think that's just fine for linaro-image-tools right now! :-)
--
Loïc Minier
Loïc Minier (lool) wrote : | # |
On Mon, Apr 04, 2011, Mattias Backman wrote:
> I see this has been worked on in trunk. Should I make this
> 60 + kernel_flavors = ['u8500', 'ux500', 'u?500']
> or will the explicit list ['u8500', 'ux500'] cover it?
I committed to trunk so that people could continue using bzr
linaro-image-tools while you were implementing support for multiple
flavors. I prefer the explicit list rather than regexps in the
flavors.
Thanks!
--
Loïc Minier
- 309. By Mattias Backman
-
Change kernel_suffix to kernel_flavors.
- 310. By Mattias Backman
-
Add get_kflavor_file function.
- 311. By Mattias Backman
-
Make the changes to _make_boot_files.
Mattias Backman (mabac) wrote : | # |
> On Mon, Apr 04, 2011, Mattias Backman wrote:
> > ...
> > kfile = _get_kflavor_
> > ifile = _get_initrd_
> > assert(files match in some way)
> > make_uImage(kfile, boot_dir)
> > make_uInitrd(ifile, boot_dir)
>
> Sounds good!
>
> There might be another way to deal with this:
> (kfile, flavor) = _get_kflavor_
> all_flavors)
> (ifile, _) _get_kflavor_
> [flavor])
I tried something like this in bug-744857-kflavor-file but I'm not sure that anything really became more beautiful. ;) Can you have a look and see if this is getting close to what you're after?
I'm aware that some of the tests fail, since my class function get None from mocked module functions. I've spent a little too much time on finding a way to fix that without mocking the crap out of existing tests. Will keep working on that if this is a change we want to keep. Any help with the tests will be very appreciated. (the mock of _get_file_matching returns None, which to BoardConfig.
Thanks,
Mattias
Mattias Backman (mabac) wrote : | # |
Here's the new branch https:/
Loïc Minier (lool) wrote : | # |
I've sent some fixes for your branch at https:/
Looking at making things more elegant, I opted to make _get_kflavor_files a function taking just a directory and returning both kernel and initrd; let me know if that looks good.
I've fixed some typos and your tests to pass, but there are regressions in other tests.
Guilherme, we could lookup kernel and initrd in make_boot_files() and pass that down to _make_boot_files(), but that's two more args; are you ok with this?
Guilherme Salgado (salgado) wrote : | # |
If it's safe to assume that all hwpacks will include kernel/initrd images matching the current glob, then that should be fine -- I don't think adding a couple extra arguments to _make_boot_files() is a big deal.
Oh, you might want to merge from trunk before doing any more changes here as you're touching some code that was changed yesterday.
- 312. By Mattias Backman
-
Merge lool's changes for _get_kflavor_files.
- 313. By Mattias Backman
-
Fix tests by mocking _get_kflavor_files.
- 314. By Mattias Backman
-
Merge from trunk.
Mattias Backman (mabac) wrote : | # |
> I've sent some fixes for your branch at https:/
> /linaro-
>
> Looking at making things more elegant, I opted to make _get_kflavor_files a
> function taking just a directory and returning both kernel and initrd; let me
> know if that looks good.
Looks great, I have merged your changes. Thanks!
>
> I've fixed some typos and your tests to pass, but there are regressions in
> other tests.
Yeah, those where there failing tests I mentioned. Guilherme has helped me fix those now.
>
> Guilherme, we could lookup kernel and initrd in make_boot_files() and pass
> that down to _make_boot_files(), but that's two more args; are you ok with
> this?
That would take away the last smell I think, no need for all configs to look them up. I'll change that too.
- 315. By Mattias Backman
-
Move looking up kernel and initrd files to make_boot_files().
Mattias Backman (mabac) wrote : | # |
Left to do is some digging for kernel flavors used by old hwpacks, which I haven't done yet.
Mattias Backman (mabac) wrote : | # |
I checked the hwpacks at http://
bsp-omap4 which contains kernel 2.6.35-903-omap4
- 316. By Mattias Backman
-
Add kernel_flavor 'omap4' for linaro-m hwpack bsp-omap4.
- 317. By Mattias Backman
-
Merge from trunk.
- 318. By Mattias Backman
-
Fix deprecation warning. Unrelated but maybe I can sneak it in here.
Loïc Minier (lool) wrote : | # |
Looks good! I'd do some minor changes while merging if you don't mind:
- drop newline added near mock_set_
- add a test when no kflavor matches
- sort kflavors to have the most specific flavor first (e.g. omap4 before omap)
let me know if you'd disagree with the above changes
- 319. By Mattias Backman
-
Remove blank line, sort kernel_flavors and add test for _get_kflavor_files not finding files.
Preview Diff
1 | === modified file 'linaro_image_tools/hwpack/packages.py' |
2 | --- linaro_image_tools/hwpack/packages.py 2011-03-24 21:47:55 +0000 |
3 | +++ linaro_image_tools/hwpack/packages.py 2011-04-06 12:55:54 +0000 |
4 | @@ -617,7 +617,7 @@ |
5 | base = os.path.basename(candidate.filename) |
6 | installed.append(FetchedPackage.from_apt(candidate, base)) |
7 | for package in self.cache.cache: |
8 | - if not package.isInstalled: |
9 | + if not package.is_installed: |
10 | continue |
11 | candidate = package.installed |
12 | base = os.path.basename(candidate.filename) |
13 | |
14 | === modified file 'linaro_image_tools/media_create/boards.py' |
15 | --- linaro_image_tools/media_create/boards.py 2011-04-05 11:06:49 +0000 |
16 | +++ linaro_image_tools/media_create/boards.py 2011-04-06 12:55:54 +0000 |
17 | @@ -36,6 +36,9 @@ |
18 | |
19 | from linaro_image_tools.media_create.partitions import SECTOR_SIZE |
20 | |
21 | +KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s' |
22 | +INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s' |
23 | + |
24 | # Notes: |
25 | # * since we align partitions on 4 MiB by default, geometry is currently 128 |
26 | # heads and 32 sectors (2 MiB) as to have CHS-aligned partition start/end |
27 | @@ -150,7 +153,7 @@ |
28 | kernel_addr = None |
29 | initrd_addr = None |
30 | load_addr = None |
31 | - kernel_suffix = None |
32 | + kernel_flavors = None |
33 | boot_script = None |
34 | serial_tty = None |
35 | |
36 | @@ -304,13 +307,14 @@ |
37 | def make_boot_files(cls, uboot_parts_dir, is_live, is_lowmem, consoles, |
38 | chroot_dir, rootfs_uuid, boot_dir, boot_device_or_file): |
39 | boot_env = cls._get_boot_env(is_live, is_lowmem, consoles, rootfs_uuid) |
40 | + (k_img_data, i_img_data) = cls._get_kflavor_files(uboot_parts_dir) |
41 | cls._make_boot_files( |
42 | - uboot_parts_dir, boot_env, chroot_dir, boot_dir, |
43 | - boot_device_or_file) |
44 | + boot_env, chroot_dir, boot_dir, |
45 | + boot_device_or_file, k_img_data, i_img_data) |
46 | |
47 | @classmethod |
48 | - def _make_boot_files(cls, uboot_parts_dir, boot_env, chroot_dir, boot_dir, |
49 | - boot_device_or_file): |
50 | + def _make_boot_files(cls, boot_env, chroot_dir, boot_dir, |
51 | + boot_device_or_file, k_img_data, i_img_data): |
52 | """Make the necessary boot files for this board. |
53 | |
54 | This is usually board-specific so ought to be defined in every |
55 | @@ -348,9 +352,27 @@ |
56 | except cmd_runner.SubcommandNonZeroReturnValue: |
57 | pass |
58 | |
59 | + @classmethod |
60 | + def _get_kflavor_files(cls, path): |
61 | + """Search for kernel and initrd in path.""" |
62 | + for flavor in cls.kernel_flavors: |
63 | + kregex = KERNEL_GLOB % {'kernel_flavor' : flavor} |
64 | + iregex = INITRD_GLOB % {'kernel_flavor' : flavor} |
65 | + kernel = _get_file_matching(os.path.join(path, kregex)) |
66 | + if kernel is not None: |
67 | + initrd = _get_file_matching(os.path.join(path, iregex)) |
68 | + if initrd is not None: |
69 | + return (kernel, initrd) |
70 | + raise ValueError( |
71 | + "Found kernel for flavor %s but no initrd matching %s" % ( |
72 | + flavor, iregex)) |
73 | + raise ValueError( |
74 | + "No kernel found matching %s for flavors %s" % ( |
75 | + KERNEL_GLOB, " ".join(cls.kernel_flavors))) |
76 | + |
77 | |
78 | class OmapConfig(BoardConfig): |
79 | - kernel_suffix = 'linaro-omap' |
80 | + kernel_flavors = ['linaro-omap4', 'linaro-omap', 'omap4'] |
81 | uboot_in_boot_part = True |
82 | |
83 | # XXX: Here we define these things as dynamic properties because our |
84 | @@ -405,12 +427,11 @@ |
85 | rootfs_uuid, boot_dir, boot_device_or_file) |
86 | |
87 | @classmethod |
88 | - def _make_boot_files(cls, uboot_parts_dir, boot_env, chroot_dir, boot_dir, |
89 | - boot_device_or_file): |
90 | + def _make_boot_files(cls, boot_env, chroot_dir, boot_dir, |
91 | + boot_device_or_file, k_img_data, i_img_data): |
92 | install_omap_boot_loader(chroot_dir, boot_dir) |
93 | - make_uImage( |
94 | - cls.load_addr, uboot_parts_dir, cls.kernel_suffix, boot_dir) |
95 | - make_uInitrd(uboot_parts_dir, cls.kernel_suffix, boot_dir) |
96 | + make_uImage(cls.load_addr, k_img_data, boot_dir) |
97 | + make_uInitrd(i_img_data, boot_dir) |
98 | boot_script_path = os.path.join(boot_dir, cls.boot_script) |
99 | make_boot_script(boot_env, boot_script_path) |
100 | make_boot_ini(boot_script_path, boot_dir) |
101 | @@ -462,11 +483,10 @@ |
102 | uboot_flavor = None |
103 | |
104 | @classmethod |
105 | - def _make_boot_files(cls, uboot_parts_dir, boot_env, chroot_dir, boot_dir, |
106 | - boot_device_or_file): |
107 | - make_uImage( |
108 | - cls.load_addr, uboot_parts_dir, cls.kernel_suffix, boot_dir) |
109 | - make_uInitrd(uboot_parts_dir, cls.kernel_suffix, boot_dir) |
110 | + def _make_boot_files(cls, boot_env, chroot_dir, boot_dir, |
111 | + boot_device_or_file, k_img_data, i_img_data): |
112 | + make_uImage(cls.load_addr, k_img_data, boot_dir) |
113 | + make_uInitrd(i_img_data, boot_dir) |
114 | boot_script_path = os.path.join(boot_dir, cls.boot_script) |
115 | make_boot_script(boot_env, boot_script_path) |
116 | make_boot_ini(boot_script_path, boot_dir) |
117 | @@ -479,7 +499,7 @@ |
118 | kernel_addr = '0x00100000' |
119 | initrd_addr = '0x08000000' |
120 | load_addr = '0x00008000' |
121 | - kernel_suffix = 'u?500' |
122 | + kernel_flavors = ['u8500', 'ux500'] |
123 | boot_script = 'flash.scr' |
124 | extra_boot_args_options = ( |
125 | 'earlyprintk rootdelay=1 fixrtc nocompcache ' |
126 | @@ -489,11 +509,10 @@ |
127 | mmc_option = '1:1' |
128 | |
129 | @classmethod |
130 | - def _make_boot_files(cls, uboot_parts_dir, boot_env, chroot_dir, boot_dir, |
131 | - boot_device_or_file): |
132 | - make_uImage( |
133 | - cls.load_addr, uboot_parts_dir, cls.kernel_suffix, boot_dir) |
134 | - make_uInitrd(uboot_parts_dir, cls.kernel_suffix, boot_dir) |
135 | + def _make_boot_files(cls, boot_env, chroot_dir, boot_dir, |
136 | + boot_device_or_file, k_img_data, i_img_data): |
137 | + make_uImage(cls.load_addr, k_img_data, boot_dir) |
138 | + make_uInitrd(i_img_data, boot_dir) |
139 | boot_script_path = os.path.join(boot_dir, cls.boot_script) |
140 | make_boot_script(boot_env, boot_script_path) |
141 | |
142 | @@ -535,14 +554,13 @@ |
143 | loader_start, loader_len, boot_start, boot_len, root_start) |
144 | |
145 | @classmethod |
146 | - def _make_boot_files(cls, uboot_parts_dir, boot_env, chroot_dir, boot_dir, |
147 | - boot_device_or_file): |
148 | + def _make_boot_files(cls, boot_env, chroot_dir, boot_dir, |
149 | + boot_device_or_file, k_img_data, i_img_data): |
150 | uboot_file = os.path.join( |
151 | chroot_dir, 'usr', 'lib', 'u-boot', cls.uboot_flavor, 'u-boot.imx') |
152 | install_mx5_boot_loader(uboot_file, boot_device_or_file) |
153 | - make_uImage( |
154 | - cls.load_addr, uboot_parts_dir, cls.kernel_suffix, boot_dir) |
155 | - make_uInitrd(uboot_parts_dir, cls.kernel_suffix, boot_dir) |
156 | + make_uImage(cls.load_addr, k_img_data, boot_dir) |
157 | + make_uInitrd(i_img_data, boot_dir) |
158 | boot_script_path = os.path.join(boot_dir, cls.boot_script) |
159 | make_boot_script(boot_env, boot_script_path) |
160 | |
161 | @@ -551,14 +569,14 @@ |
162 | kernel_addr = '0x90000000' |
163 | initrd_addr = '0x92000000' |
164 | load_addr = '0x90008000' |
165 | - kernel_suffix = 'linaro-mx51' |
166 | + kernel_flavors = ['linaro-mx51', 'linaro-lt-mx5'] |
167 | |
168 | |
169 | class Mx53Config(Mx5Config): |
170 | kernel_addr = '0x70800000' |
171 | initrd_addr = '0x71800000' |
172 | load_addr = '0x70008000' |
173 | - kernel_suffix = 'linaro-lt-mx53' |
174 | + kernel_flavors = ['linaro-lt-mx53', 'linaro-lt-mx5'] |
175 | |
176 | |
177 | class EfikamxConfig(Mx51Config): |
178 | @@ -586,18 +604,17 @@ |
179 | kernel_addr = '0x60008000' |
180 | initrd_addr = '0x81000000' |
181 | load_addr = kernel_addr |
182 | - kernel_suffix = 'linaro-vexpress' |
183 | + kernel_flavors = ['linaro-vexpress'] |
184 | boot_script = None |
185 | # ARM Boot Monitor is used to load u-boot, uImage etc. into flash and |
186 | # only allows for FAT16 |
187 | fat_size = 16 |
188 | |
189 | @classmethod |
190 | - def _make_boot_files(cls, uboot_parts_dir, boot_env, chroot_dir, boot_dir, |
191 | - boot_device_or_file): |
192 | - make_uImage( |
193 | - cls.load_addr, uboot_parts_dir, cls.kernel_suffix, boot_dir) |
194 | - make_uInitrd(uboot_parts_dir, cls.kernel_suffix, boot_dir) |
195 | + def _make_boot_files(cls, boot_env, chroot_dir, boot_dir, |
196 | + boot_device_or_file, k_img_data, i_img_data): |
197 | + make_uImage(cls.load_addr, k_img_data, boot_dir) |
198 | + make_uInitrd(i_img_data, boot_dir) |
199 | |
200 | class SMDKV310Config(BoardConfig): |
201 | serial_tty = 'ttySAC1' |
202 | @@ -605,7 +622,7 @@ |
203 | kernel_addr = '0x40007000' |
204 | initrd_addr = '0x41000000' |
205 | load_addr = '0x40008000' |
206 | - kernel_suffix = 's5pv310' |
207 | + kernel_flavors = ['s5pv310'] |
208 | boot_script = 'boot.scr' |
209 | mmc_part_offset = 1 |
210 | mmc_option = '0:2' |
211 | @@ -655,8 +672,8 @@ |
212 | return boot_env |
213 | |
214 | @classmethod |
215 | - def _make_boot_files(cls, uboot_parts_dir, boot_env, chroot_dir, boot_dir, |
216 | - boot_device_or_file): |
217 | + def _make_boot_files(cls, boot_env, chroot_dir, boot_dir, |
218 | + boot_device_or_file, k_img_data, i_img_data): |
219 | uboot_file = os.path.join( |
220 | chroot_dir, 'usr', 'lib', 'u-boot', 'smdkv310', 'u-boot.v310') |
221 | install_smdkv310_boot_loader(uboot_file, boot_device_or_file) |
222 | @@ -665,12 +682,9 @@ |
223 | env_file = make_flashable_env(boot_env, env_size) |
224 | install_smdkv310_boot_env(env_file, boot_device_or_file) |
225 | |
226 | - uImage_file = make_uImage( |
227 | - cls.load_addr, uboot_parts_dir, cls.kernel_suffix, boot_dir) |
228 | + uImage_file = make_uImage(cls.load_addr, k_img_data, boot_dir) |
229 | install_smdkv310_uImage(uImage_file, boot_device_or_file) |
230 | - |
231 | - uInitrd_file = make_uInitrd( |
232 | - uboot_parts_dir, cls.kernel_suffix, boot_dir) |
233 | + uInitrd_file = make_uInitrd(i_img_data, boot_dir) |
234 | install_smdkv310_initrd(uInitrd_file, boot_device_or_file) |
235 | |
236 | # unused at the moment once FAT support enabled for the |
237 | @@ -741,26 +755,21 @@ |
238 | if len(files) == 1: |
239 | return files[0] |
240 | elif len(files) == 0: |
241 | - raise ValueError( |
242 | - "No files found matching '%s'; can't continue" % regex) |
243 | + return None |
244 | else: |
245 | # TODO: Could ask the user to chosse which file to use instead of |
246 | # raising an exception. |
247 | raise ValueError("Too many files matching '%s' found." % regex) |
248 | |
249 | |
250 | -def make_uImage(load_addr, uboot_parts_dir, suffix, boot_disk): |
251 | - img_data = _get_file_matching( |
252 | - '%s/vmlinuz-*-%s' % (uboot_parts_dir, suffix)) |
253 | +def make_uImage(load_addr, img_data, boot_disk): |
254 | img = '%s/uImage' % boot_disk |
255 | _run_mkimage( |
256 | 'kernel', load_addr, load_addr, 'Linux', img_data, img) |
257 | return img |
258 | |
259 | |
260 | -def make_uInitrd(uboot_parts_dir, suffix, boot_disk): |
261 | - img_data = _get_file_matching( |
262 | - '%s/initrd.img-*-%s' % (uboot_parts_dir, suffix)) |
263 | +def make_uInitrd(img_data, boot_disk): |
264 | img = '%s/uInitrd' % boot_disk |
265 | _run_mkimage('ramdisk', '0', '0', 'initramfs', img_data, img) |
266 | return img |
267 | |
268 | === modified file 'linaro_image_tools/media_create/tests/test_media_create.py' |
269 | --- linaro_image_tools/media_create/tests/test_media_create.py 2011-04-04 22:28:58 +0000 |
270 | +++ linaro_image_tools/media_create/tests/test_media_create.py 2011-04-06 12:55:54 +0000 |
271 | @@ -175,6 +175,13 @@ |
272 | classmethod(set_appropriate_serial_tty_mock))) |
273 | |
274 | def make_boot_files(self, config): |
275 | + def _get_kflavor_files_mock(cls, path): |
276 | + return (path, path) |
277 | + |
278 | + self.useFixture(MockSomethingFixture( |
279 | + config, '_get_kflavor_files', |
280 | + classmethod(_get_kflavor_files_mock))) |
281 | + |
282 | config.make_boot_files('', False, False, [], '', '', '', '') |
283 | |
284 | def test_vexpress_steps(self): |
285 | @@ -518,7 +525,7 @@ |
286 | def test_make_uImage(self): |
287 | self._mock_get_file_matching() |
288 | fixture = self._mock_Popen() |
289 | - make_uImage('load_addr', 'parts_dir', 'sub_arch', 'boot_disk') |
290 | + make_uImage('load_addr', 'parts_dir/vmlinuz-*-sub_arch', 'boot_disk') |
291 | expected = [ |
292 | '%s mkimage -A arm -O linux -T kernel -C none -a load_addr ' |
293 | '-e load_addr -n Linux -d parts_dir/vmlinuz-*-sub_arch ' |
294 | @@ -528,7 +535,7 @@ |
295 | def test_make_uInitrd(self): |
296 | self._mock_get_file_matching() |
297 | fixture = self._mock_Popen() |
298 | - make_uInitrd('parts_dir', 'sub_arch', 'boot_disk') |
299 | + make_uInitrd('parts_dir/initrd.img-*-sub_arch', 'boot_disk') |
300 | expected = [ |
301 | '%s mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 ' |
302 | '-n initramfs -d parts_dir/initrd.img-*-sub_arch ' |
303 | @@ -609,9 +616,41 @@ |
304 | self.assertRaises( |
305 | ValueError, _get_file_matching, '%s/%s*' % (directory, prefix)) |
306 | |
307 | + def test_get_kflavor_files_more_specific(self): |
308 | + tempdir = self.useFixture(CreateTempDirFixture()).tempdir |
309 | + flavorx = 'flavorX' |
310 | + flavorxy = 'flavorXY' |
311 | + class config(boards.BoardConfig): |
312 | + kernel_flavors = [flavorx, flavorxy] |
313 | + for f in reversed(config.kernel_flavors): |
314 | + kfile = os.path.join(tempdir, 'vmlinuz-1-%s' % f) |
315 | + ifile = os.path.join(tempdir, 'initrd.img-1-%s' % f) |
316 | + open(kfile, "w").close() |
317 | + open(ifile, "w").close() |
318 | + self.assertEqual((kfile, ifile), config._get_kflavor_files(tempdir)) |
319 | + |
320 | + def test_get_kflavor_files_later_in_flavors(self): |
321 | + tempdir = self.useFixture(CreateTempDirFixture()).tempdir |
322 | + flavor1 = 'flavorXY' |
323 | + flavor2 = 'flavorAA' |
324 | + class config(boards.BoardConfig): |
325 | + kernel_flavors = [flavor1, flavor2] |
326 | + kfile = os.path.join(tempdir, 'vmlinuz-1-%s' % flavor1) |
327 | + ifile = os.path.join(tempdir, 'initrd.img-1-%s' % flavor1) |
328 | + open(kfile, "w").close() |
329 | + open(ifile, "w").close() |
330 | + self.assertEqual((kfile, ifile), config._get_kflavor_files(tempdir)) |
331 | + |
332 | + def test_get_kflavor_files_raises_when_no_match(self): |
333 | + tempdir = self.useFixture(CreateTempDirFixture()).tempdir |
334 | + flavor1 = 'flavorXY' |
335 | + flavor2 = 'flavorAA' |
336 | + class config(boards.BoardConfig): |
337 | + kernel_flavors = [flavor1, flavor2] |
338 | + self.assertRaises(ValueError, config._get_kflavor_files, tempdir) |
339 | + |
340 | def test_get_file_matching_no_files_found(self): |
341 | - self.assertRaises( |
342 | - ValueError, _get_file_matching, '/foo/bar/baz/*non-existent') |
343 | + self.assertEqual(None, _get_file_matching('/foo/bar/baz/*non-existent')) |
344 | |
345 | def test_run_mkimage(self): |
346 | # Create a fake boot script. |
Hi,
253 + prefix = ''.join( choice( string. ascii_lowercase ) for x in range(5)) choice( string. ascii_lowercase ) for x in range(5))
254 + random.
255 + junk_prefix = ''.join(
256 + random.
Please avoid things like this in tests. This particular test will test
the wrong thing occasionally when the strings end up the same. Not so bad in this
case, but something to avoid anyway.
If you want to signal that the actual strings don't matter then you can use tring() which will never return the same thing twice.
self.getUniqueS
Otherwise this looks good to me, provided that the mx changes are what we want
to do.
Thanks,
James