Merge lp:~salgado/linaro-image-tools/bug-697824 into lp:linaro-image-tools/11.11
- bug-697824
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 269 |
Proposed branch: | lp:~salgado/linaro-image-tools/bug-697824 |
Merge into: | lp:linaro-image-tools/11.11 |
Diff against target: |
280 lines (+109/-29) 2 files modified
linaro_media_create/boards.py (+62/-13) linaro_media_create/tests/test_media_create.py (+47/-16) |
To merge this branch: | bzr merge lp:~salgado/linaro-image-tools/bug-697824 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Loïc Minier (community) | Approve | ||
Review via email: mp+47818@code.launchpad.net |
Commit message
Description of the change
Change OMAP configs to use the correct serial tty depending on the kernel version that is installed on the rootfs. This is a better fix for bug 697824, but is still a temporary one which we hope to get rid of soon.
Guilherme Salgado (salgado) wrote : | # |
> It's much longer than I had hoped for a temporary workaround, but it's all
> tested so that's nice!
>
> One thing which is a bit odd is that we do the runtime serialtty only for OMAP
> boards, so that it looks like:
> + _serial_tty = 'ttyO2'
> + _extra_serial_opts = 'console=tty0 console=
> + _live_serial_opts = 'serialtty=%s'
>
> for OMAP boards and like this for non-OMAP boards:
> + serial_tty = 'ttyAMA2'
> + extra_serial_opts = 'console=tty0 console=
> + live_serial_opts = 'serialtty=%s' % serial_tty
>
> could we just use the same approach for all boards (i.e. do all boards at
> runtime) as to have the same structure for all configs?
That's because OMAP configs are the exception, but once this hack is reverted they will look just like the other ones. The special case in the OMAP config is even described in an XXX comment (with a mention to the bug) to make it clear why it's different. But maybe you're anticipating some sort of problems we might have because of the different structure?
James Westby (james-w) wrote : | # |
On Fri, 28 Jan 2011 15:52:44 -0000, Guilherme Salgado <email address hidden> wrote:
> Change OMAP configs to use the correct serial tty depending on the
> kernel version that is installed on the rootfs. This is a better fix
> for bug 697824, but is still a temporary one which we hope to get rid
> of soon.
Can we gate this based on the hwpack version? Or will that happen as
part of the new version support going in.
Thanks,
James
Guilherme Salgado (salgado) wrote : | # |
On Fri, 2011-01-28 at 11:14 -0500, James Westby wrote:
> On Fri, 28 Jan 2011 15:52:44 -0000, Guilherme Salgado <email address hidden> wrote:
> > Change OMAP configs to use the correct serial tty depending on the
> > kernel version that is installed on the rootfs. This is a better fix
> > for bug 697824, but is still a temporary one which we hope to get rid
> > of soon.
>
> Can we gate this based on the hwpack version? Or will that happen as
> part of the new version support going in.
That's the plan; we'll use whatever serial_tty is in a v2 hwpack,
falling back to ttyS2 for v1 hwpacks.
Loïc Minier (lool) wrote : | # |
When we move to hwpack v2, we can move back to hardcoding ttyS2 for hardware pack v1, and use the hwpack serial_tty field with hardware pack v2.
Preview Diff
1 | === modified file 'linaro_media_create/boards.py' |
2 | --- linaro_media_create/boards.py 2011-01-26 18:03:50 +0000 |
3 | +++ linaro_media_create/boards.py 2011-01-28 15:52:27 +0000 |
4 | @@ -8,6 +8,7 @@ |
5 | import atexit |
6 | import glob |
7 | import os |
8 | +import re |
9 | import tempfile |
10 | |
11 | from linaro_media_create import cmd_runner |
12 | @@ -30,6 +31,7 @@ |
13 | load_addr = None |
14 | kernel_suffix = None |
15 | boot_script = None |
16 | + serial_tty = None |
17 | |
18 | @classmethod |
19 | def get_sfdisk_cmd(cls): |
20 | @@ -61,7 +63,7 @@ |
21 | # XXX: I think this is not needed as we have board-specific |
22 | # serial options for when is_live is true. |
23 | if is_live: |
24 | - serial_opts += ' serialtty=ttyS2' |
25 | + serial_opts += ' serialtty=%s' % cls.serial_tty |
26 | |
27 | serial_opts += ' %s' % cls.extra_serial_opts |
28 | |
29 | @@ -90,7 +92,8 @@ |
30 | def make_boot_files(cls, uboot_parts_dir, is_live, is_lowmem, consoles, |
31 | root_dir, rootfs_uuid, boot_dir, boot_script, |
32 | boot_device_or_file): |
33 | - boot_cmd = cls._get_boot_cmd(is_live, is_lowmem, consoles, rootfs_uuid) |
34 | + boot_cmd = cls._get_boot_cmd( |
35 | + is_live, is_lowmem, consoles, rootfs_uuid) |
36 | cls._make_boot_files( |
37 | uboot_parts_dir, boot_cmd, root_dir, boot_dir, boot_script, |
38 | boot_device_or_file) |
39 | @@ -106,11 +109,51 @@ |
40 | raise NotImplementedError() |
41 | |
42 | |
43 | +class classproperty(object): |
44 | + """A descriptor that provides @property behavior on class methods.""" |
45 | + def __init__(self, getter): |
46 | + self.getter = getter |
47 | + def __get__(self, instance, cls): |
48 | + return self.getter(cls) |
49 | + |
50 | + |
51 | class OmapConfig(BoardConfig): |
52 | |
53 | + # XXX: Here we define these things as dynamic properties because our |
54 | + # temporary hack to fix bug 697824 relies on changing the board's |
55 | + # serial_tty at run time. |
56 | + _extra_serial_opts = None |
57 | + _live_serial_opts = None |
58 | + _serial_tty = None |
59 | + |
60 | + @classproperty |
61 | + def live_serial_opts(cls): |
62 | + return cls._live_serial_opts % cls.serial_tty |
63 | + |
64 | + @classproperty |
65 | + def extra_serial_opts(cls): |
66 | + return cls._extra_serial_opts % cls.serial_tty |
67 | + |
68 | + @classmethod |
69 | + def set_appropriate_serial_tty(cls, chroot_dir): |
70 | + """Set the appropriate serial_tty depending on the kernel used. |
71 | + |
72 | + If the kernel found in the chroot dir is << 2.6.36 we use tyyS2, else |
73 | + we use the default value (_serial_tty). |
74 | + """ |
75 | + # XXX: This is also part of our temporary hack to fix bug 697824. |
76 | + cls.serial_tty = cls._serial_tty |
77 | + vmlinuz = _get_file_matching( |
78 | + os.path.join(chroot_dir, 'boot', 'vmlinuz*')) |
79 | + basename = os.path.basename(vmlinuz) |
80 | + minor_version = re.match('.*2\.6\.([0-9]{2}).*', basename).group(1) |
81 | + if int(minor_version) < 36: |
82 | + cls.serial_tty = 'ttyS2' |
83 | + |
84 | @classmethod |
85 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, |
86 | boot_dir, boot_script, boot_device_or_file): |
87 | + cls.set_appropriate_serial_tty(chroot_dir) |
88 | install_omap_boot_loader(chroot_dir, boot_dir) |
89 | make_uImage( |
90 | cls.load_addr, uboot_parts_dir, cls.kernel_suffix, boot_dir) |
91 | @@ -121,8 +164,9 @@ |
92 | |
93 | class BeagleConfig(OmapConfig): |
94 | uboot_flavor = 'omap3_beagle' |
95 | - extra_serial_opts = 'console=tty0 console=ttyO2,115200n8' |
96 | - live_serial_opts = 'serialtty=ttyO2' |
97 | + _serial_tty = 'ttyO2' |
98 | + _extra_serial_opts = 'console=tty0 console=%s,115200n8' |
99 | + _live_serial_opts = 'serialtty=%s' |
100 | kernel_addr = '0x80000000' |
101 | initrd_addr = '0x81600000' |
102 | load_addr = '0x80008000' |
103 | @@ -135,7 +179,8 @@ |
104 | |
105 | class OveroConfig(OmapConfig): |
106 | uboot_flavor = 'omap3_overo' |
107 | - extra_serial_opts = 'console=tty0 console=ttyO2,115200n8' |
108 | + _serial_tty = 'ttyO2' |
109 | + _extra_serial_opts = 'console=tty0 console=%s,115200n8' |
110 | kernel_addr = '0x80000000' |
111 | initrd_addr = '0x81600000' |
112 | load_addr = '0x80008000' |
113 | @@ -147,8 +192,9 @@ |
114 | |
115 | class PandaConfig(OmapConfig): |
116 | uboot_flavor = 'omap4_panda' |
117 | - extra_serial_opts = 'console=tty0 console=ttyO2,115200n8' |
118 | - live_serial_opts = 'serialtty=ttyO2' |
119 | + _serial_tty = 'ttyO2' |
120 | + _extra_serial_opts = 'console=tty0 console=%s,115200n8' |
121 | + _live_serial_opts = 'serialtty=%s' |
122 | kernel_addr = '0x80200000' |
123 | initrd_addr = '0x81600000' |
124 | load_addr = '0x80008000' |
125 | @@ -173,8 +219,9 @@ |
126 | |
127 | |
128 | class Ux500Config(BoardConfig): |
129 | - extra_serial_opts = 'console=tty0 console=ttyAMA2,115200n8' |
130 | - live_serial_opts = 'serialtty=ttyAMA2' |
131 | + serial_tty = 'ttyAMA2' |
132 | + extra_serial_opts = 'console=tty0 console=%s,115200n8' % serial_tty |
133 | + live_serial_opts = 'serialtty=%s' % serial_tty |
134 | kernel_addr = '0x00100000' |
135 | initrd_addr = '0x08000000' |
136 | load_addr = '0x00008000' |
137 | @@ -197,8 +244,9 @@ |
138 | |
139 | |
140 | class Mx51evkConfig(BoardConfig): |
141 | - extra_serial_opts = 'console=tty0 console=ttymxc0,115200n8' |
142 | - live_serial_opts = 'serialtty=ttymxc0' |
143 | + serial_tty = 'ttymxc0' |
144 | + extra_serial_opts = 'console=tty0 console=%s,115200n8' % serial_tty |
145 | + live_serial_opts = 'serialtty=%s' % serial_tty |
146 | kernel_addr = '0x90000000' |
147 | initrd_addr = '0x90800000' |
148 | load_addr = '0x90008000' |
149 | @@ -229,8 +277,9 @@ |
150 | |
151 | class VexpressConfig(BoardConfig): |
152 | uboot_flavor = 'ca9x4_ct_vxp' |
153 | - extra_serial_opts = 'console=tty0 console=ttyAMA0,38400n8' |
154 | - live_serial_opts = 'serialtty=ttyAMA0' |
155 | + serial_tty = 'ttyAMA0' |
156 | + extra_serial_opts = 'console=tty0 console=%s,38400n8' % serial_tty |
157 | + live_serial_opts = 'serialtty=%s' % serial_tty |
158 | kernel_addr = '0x60008000' |
159 | initrd_addr = '0x81000000' |
160 | load_addr = kernel_addr |
161 | |
162 | === modified file 'linaro_media_create/tests/test_media_create.py' |
163 | --- linaro_media_create/tests/test_media_create.py 2011-01-27 18:43:55 +0000 |
164 | +++ linaro_media_create/tests/test_media_create.py 2011-01-28 15:52:27 +0000 |
165 | @@ -166,60 +166,86 @@ |
166 | def mock_func_creator(name): |
167 | return lambda *args, **kwargs: self.funcs_calls.append(name) |
168 | |
169 | - for name in dir(linaro_media_create.boards): |
170 | - attr = getattr(linaro_media_create.boards, name) |
171 | + for name in dir(boards): |
172 | + attr = getattr(boards, name) |
173 | if type(attr) == types.FunctionType: |
174 | self.useFixture(MockSomethingFixture( |
175 | - linaro_media_create.boards, name, mock_func_creator(name))) |
176 | + linaro_media_create.boards, name, |
177 | + mock_func_creator(name))) |
178 | + |
179 | + def mock_set_appropriate_serial_tty(self, config): |
180 | + |
181 | + def set_appropriate_serial_tty_mock(cls, chroot_dir): |
182 | + cls.serial_tty = cls._serial_tty |
183 | + |
184 | + self.useFixture(MockSomethingFixture( |
185 | + config, 'set_appropriate_serial_tty', |
186 | + classmethod(set_appropriate_serial_tty_mock))) |
187 | |
188 | def make_boot_files(self, config): |
189 | config.make_boot_files('', False, False, [], '', '', '', '', '') |
190 | |
191 | def test_vexpress_steps(self): |
192 | - config = linaro_media_create.boards.VexpressConfig |
193 | - self.make_boot_files(config) |
194 | + self.make_boot_files(boards.VexpressConfig) |
195 | expected = ['make_uImage', 'make_uInitrd'] |
196 | self.assertEqual(expected, self.funcs_calls) |
197 | |
198 | def test_mx51evk_steps(self): |
199 | - config = linaro_media_create.boards.Mx51evkConfig |
200 | - self.make_boot_files(config) |
201 | + self.make_boot_files(boards.Mx51evkConfig) |
202 | expected = [ |
203 | 'install_mx51evk_boot_loader', 'make_uImage', 'make_uInitrd', |
204 | 'make_boot_script'] |
205 | self.assertEqual(expected, self.funcs_calls) |
206 | |
207 | def test_ux500_steps(self): |
208 | - config = linaro_media_create.boards.Ux500Config |
209 | - self.make_boot_files(config) |
210 | + self.make_boot_files(boards.Ux500Config) |
211 | expected = ['make_uImage', 'make_uInitrd', 'make_boot_script'] |
212 | self.assertEqual(expected, self.funcs_calls) |
213 | |
214 | def test_panda_steps(self): |
215 | - config = linaro_media_create.boards.PandaConfig |
216 | - self.make_boot_files(config) |
217 | + self.mock_set_appropriate_serial_tty(boards.PandaConfig) |
218 | + self.make_boot_files(boards.PandaConfig) |
219 | expected = [ |
220 | 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd', |
221 | 'make_boot_script', 'make_boot_ini'] |
222 | self.assertEqual(expected, self.funcs_calls) |
223 | |
224 | def test_beagle_steps(self): |
225 | - config = linaro_media_create.boards.BeagleConfig |
226 | - self.make_boot_files(config) |
227 | + self.mock_set_appropriate_serial_tty(boards.BeagleConfig) |
228 | + self.make_boot_files(boards.BeagleConfig) |
229 | expected = [ |
230 | 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd', |
231 | 'make_boot_script', 'make_boot_ini'] |
232 | self.assertEqual(expected, self.funcs_calls) |
233 | |
234 | def test_overo_steps(self): |
235 | - config = linaro_media_create.boards.OveroConfig |
236 | - self.make_boot_files(config) |
237 | + self.mock_set_appropriate_serial_tty(boards.OveroConfig) |
238 | + self.make_boot_files(boards.OveroConfig) |
239 | expected = [ |
240 | 'install_omap_boot_loader', 'make_uImage', 'make_uInitrd', |
241 | 'make_boot_script', 'make_boot_ini'] |
242 | self.assertEqual(expected, self.funcs_calls) |
243 | |
244 | |
245 | +class TestFixForBug697824(TestCaseWithFixtures): |
246 | + |
247 | + def test_set_appropriate_serial_tty_old_kernel(self): |
248 | + tempdir = self.useFixture(CreateTempDirFixture()).tempdir |
249 | + boot_dir = os.path.join(tempdir, 'boot') |
250 | + os.makedirs(boot_dir) |
251 | + open(os.path.join(boot_dir, 'vmlinuz-2.6.35-23-foo'), 'w').close() |
252 | + boards.BeagleConfig.set_appropriate_serial_tty(tempdir) |
253 | + self.assertEquals('ttyS2', boards.BeagleConfig.serial_tty) |
254 | + |
255 | + def test_set_appropriate_serial_tty_new_kernel(self): |
256 | + tempdir = self.useFixture(CreateTempDirFixture()).tempdir |
257 | + boot_dir = os.path.join(tempdir, 'boot') |
258 | + os.makedirs(boot_dir) |
259 | + open(os.path.join(boot_dir, 'vmlinuz-2.6.36-13-foo'), 'w').close() |
260 | + boards.BeagleConfig.set_appropriate_serial_tty(tempdir) |
261 | + self.assertEquals('ttyO2', boards.BeagleConfig.serial_tty) |
262 | + |
263 | + |
264 | class TestGetSfdiskCmd(TestCase): |
265 | |
266 | def test_default(self): |
267 | @@ -284,7 +310,12 @@ |
268 | self.assertEqual(expected, boot_cmd) |
269 | |
270 | def test_beagle(self): |
271 | - boot_cmd = board_configs['beagle']._get_boot_cmd( |
272 | + # XXX: To fix bug 697824 we have to change class attributes of our |
273 | + # OMAP board configs, and some tests do that so to make sure they |
274 | + # don't interfere with us we'll reset that before doing anything. |
275 | + config = board_configs['beagle'] |
276 | + config.serial_tty = config._serial_tty |
277 | + boot_cmd = config._get_boot_cmd( |
278 | is_live=False, is_lowmem=False, consoles=None, |
279 | rootfs_uuid="deadbeef") |
280 | expected = ( |
It's much longer than I had hoped for a temporary workaround, but it's all tested so that's nice!
One thing which is a bit odd is that we do the runtime serialtty only for OMAP boards, so that it looks like: %s,115200n8'
+ _serial_tty = 'ttyO2'
+ _extra_serial_opts = 'console=tty0 console=
+ _live_serial_opts = 'serialtty=%s'
for OMAP boards and like this for non-OMAP boards: %s,115200n8' % serial_tty
+ serial_tty = 'ttyAMA2'
+ extra_serial_opts = 'console=tty0 console=
+ live_serial_opts = 'serialtty=%s' % serial_tty
could we just use the same approach for all boards (i.e. do all boards at runtime) as to have the same structure for all configs?