blob: 3344bb5cef7f13271a75158a56d0ec4192f34921 [file] [log] [blame]
mblighc86b0b42006-07-28 17:35:28 +00001__author__ = """Copyright Martin J. Bligh, 2006"""
mbligha2508052006-05-28 21:29:53 +00002
apwba5bbfd2006-10-16 09:25:45 +00003import os,os.path,shutil,urllib,copy,pickle,re,glob
mblighf4c35322006-03-13 01:01:10 +00004from autotest_utils import *
mbligh10038012006-10-19 03:32:45 +00005import kernel_config, test, os_dep
mblighf4c35322006-03-13 01:01:10 +00006
7class kernel:
mblighc86b0b42006-07-28 17:35:28 +00008 """ Class for compiling kernels.
9
10 Data for the object includes the src files
11 used to create the kernel, patches applied, config (base + changes),
12 the build directory itself, and logged output
13
14 Properties:
15 job
16 Backpointer to the job object we're part of
17 autodir
18 Path to the top level autotest dir (/usr/local/autotest)
mblighc86b0b42006-07-28 17:35:28 +000019 src_dir
mbligh1e8858e2006-11-24 22:18:35 +000020 <tmp_dir>/src/
mblighc49af7b2006-11-24 04:02:21 +000021 build_dir
mbligh1e8858e2006-11-24 22:18:35 +000022 <tmp_dir>/linux/
mblighc86b0b42006-07-28 17:35:28 +000023 config_dir
mbligh1e8858e2006-11-24 22:18:35 +000024 <results_dir>/config/
mblighc86b0b42006-07-28 17:35:28 +000025 log_dir
mbligh1e8858e2006-11-24 22:18:35 +000026 <results_dir>/debug/
27 results_dir
28 <results_dir>/results/
mblighc86b0b42006-07-28 17:35:28 +000029 """
30
mbligh8baa2ea2006-12-17 23:01:24 +000031 autodir = ''
32
33 def __init__(self, job, base_tree, results_dir, tmp_dir, build_dir, leave = False):
mblighc86b0b42006-07-28 17:35:28 +000034 """Initialize the kernel build environment
35
36 job
37 which job this build is part of
mblighc86b0b42006-07-28 17:35:28 +000038 base_tree
mbligh534015f2006-09-15 03:28:56 +000039 base kernel tree. Can be one of the following:
40 1. A local tarball
41 2. A URL to a tarball
42 3. A local directory (will symlink it)
43 4. A shorthand expandable (eg '2.6.11-git3')
mbligh1e8858e2006-11-24 22:18:35 +000044 results_dir
45 Results directory (holds config/, debug/, results/)
46 tmp_dir
mbligh72b88fc2006-12-16 18:41:35 +000047
mbligh1e8858e2006-11-24 22:18:35 +000048 leave
49 Boolean, whether to leave existing tmpdir or not
mblighc86b0b42006-07-28 17:35:28 +000050 """
mblighf4c35322006-03-13 01:01:10 +000051 self.job = job
mbligh678823f2006-12-07 18:49:00 +000052 self.autodir = job.autodir
mblighf4c35322006-03-13 01:01:10 +000053
mbligh1e8858e2006-11-24 22:18:35 +000054 self.src_dir = os.path.join(tmp_dir, 'src')
mbligh8baa2ea2006-12-17 23:01:24 +000055 self.build_dir = os.path.join(tmp_dir, build_dir)
mbligha2508052006-05-28 21:29:53 +000056 # created by get_kernel_tree
mbligh1e8858e2006-11-24 22:18:35 +000057 self.config_dir = os.path.join(results_dir, 'config')
58 self.log_dir = os.path.join(results_dir, 'debug')
59 self.results_dir = os.path.join(results_dir, 'results')
60
61 if not leave:
62 if os.path.isdir(self.src_dir):
63 system('rm -rf ' + self.src_dir)
64 if os.path.isdir(self.build_dir):
65 system('rm -rf ' + self.build_dir)
66
mblighf4c35322006-03-13 01:01:10 +000067 os.mkdir(self.src_dir)
mbligh1e8858e2006-11-24 22:18:35 +000068 for path in [self.config_dir, self.log_dir, self.results_dir]:
69 if os.path.exists(path):
70 system('rm -rf ' + path)
71 os.mkdir(path)
mblighf4c35322006-03-13 01:01:10 +000072
mbligh4426de02006-10-10 07:18:28 +000073 logpath = os.path.join(self.log_dir, 'build_log')
74 self.logfile = open(logpath, 'w+')
75
mbligh72b88fc2006-12-16 18:41:35 +000076 self.target_arch = None
mblighfdbcaec2006-10-01 23:28:57 +000077 self.build_target = 'bzImage'
mbligh8baa2ea2006-12-17 23:01:24 +000078 self.build_image = None
mblighfdbcaec2006-10-01 23:28:57 +000079
mblighcac347a2007-06-02 17:21:48 +000080 if get_current_kernel_arch() == 'ia64':
81 self.build_target = 'all'
82 self.build_image = 'vmlinux.gz'
83
mblighfdbcaec2006-10-01 23:28:57 +000084 if leave:
85 return
mbligh534015f2006-09-15 03:28:56 +000086
mbligh4426de02006-10-10 07:18:28 +000087 self.logfile.write('BASE: %s\n' % base_tree)
apw2366d992007-03-12 20:35:57 +000088
89 # Where we have direct version hint record that
90 # for later configuration selection.
91 shorthand = re.compile(r'^\d+\.\d+\.\d+')
92 if shorthand.match(base_tree):
93 self.base_tree_version = base_tree
94 else:
95 self.base_tree_version = None
96
mbligh534015f2006-09-15 03:28:56 +000097 if os.path.exists(base_tree):
98 self.get_kernel_tree(base_tree)
99 else:
apw8ad56be2006-11-06 17:49:54 +0000100 args = self.job.config_get('mirror.ftp_kernel_org')
mbligh548f29a2006-10-17 04:55:12 +0000101 if args:
102 args = '-l ' + args
mbligh72b88fc2006-12-16 18:41:35 +0000103 base_components = kernelexpand(base_tree, args)
mbligh534015f2006-09-15 03:28:56 +0000104 print 'kernelexpand: '
105 print base_components
106 self.get_kernel_tree(base_components.pop(0))
107 if base_components: # apply remaining patches
108 self.patch(*base_components)
mblighf4c35322006-03-13 01:01:10 +0000109
110
mbligh5925e962007-08-30 17:05:22 +0000111 def __record(self, fn, name, *args, **dargs):
112 try:
113 fn(*args, **dargs)
114 self.job.record("GOOD " + name + \
115 " completed successfully\n")
116 except Exception, detail:
117 self.job.record("FAIL " + name + \
118 detail.__str__() + "\n")
119 raise
120
121
122 def _patch(self, *patches):
mblighc86b0b42006-07-28 17:35:28 +0000123 """Apply a list of patches (in order)"""
mbligh1e8858e2006-11-24 22:18:35 +0000124 if not patches:
125 return
mblighd016ecc2006-11-25 21:41:07 +0000126 # if isinstance(patches, basestring):
127 # patches = [patches]
mbligh534015f2006-09-15 03:28:56 +0000128 print 'Applying patches: ', patches
129 # self.job.stdout.redirect(os.path.join(self.log_dir, 'stdout'))
mbligh0763e732007-08-30 16:35:06 +0000130 self.apply_patches(self.get_patches(patches))
mbligh534015f2006-09-15 03:28:56 +0000131 # self.job.stdout.restore()
mblighf4c35322006-03-13 01:01:10 +0000132
133
mbligh5925e962007-08-30 17:05:22 +0000134 def patch(self, *args, **dargs):
135 self.__record(self._patch, "kernel.patch", *args, **dargs)
136
137
138 def _config(self, config_file = '', config_list = None,
apwb449c7d2006-12-05 12:21:44 +0000139 defconfig = False):
mbligh93057012006-08-06 15:51:56 +0000140 self.job.stdout.redirect(os.path.join(self.log_dir, 'stdout'))
mbligh678823f2006-12-07 18:49:00 +0000141 self.set_cross_cc()
apwb449c7d2006-12-05 12:21:44 +0000142 config = kernel_config.kernel_config(self.job, self.build_dir,
apw2366d992007-03-12 20:35:57 +0000143 self.config_dir, config_file, config_list,
144 defconfig, self.base_tree_version)
mblighf4c35322006-03-13 01:01:10 +0000145 self.job.stdout.restore()
146
147
mbligh5925e962007-08-30 17:05:22 +0000148 def config(self, *args, **dargs):
149 self.__record(self._config, "kernel.config", *args, **dargs)
150
151
mblighf4c35322006-03-13 01:01:10 +0000152 def get_patches(self, patches):
mbligh1e8858e2006-11-24 22:18:35 +0000153 """fetch the patches to the local src_dir"""
mblighf4c35322006-03-13 01:01:10 +0000154 local_patches = []
155 for patch in patches:
mbligh1e8858e2006-11-24 22:18:35 +0000156 dest = os.path.join(self.src_dir, basename(patch))
mbligh0763e732007-08-30 16:35:06 +0000157 # FIXME: this isn't unique. Append something to it
158 # like wget does if it's not there?
mbligh1e8858e2006-11-24 22:18:35 +0000159 print "get_file %s %s %s %s" % (patch, dest, self.src_dir, basename(patch))
mblighf4c35322006-03-13 01:01:10 +0000160 get_file(patch, dest)
mbligh0763e732007-08-30 16:35:06 +0000161 # probably safer to use the command, not python library
162 md5sum = system_output('md5sum ' + dest).split()[0]
163 local_patches.append((patch, dest, md5sum))
mbligh534015f2006-09-15 03:28:56 +0000164 return local_patches
mblighf4c35322006-03-13 01:01:10 +0000165
mbligh72b88fc2006-12-16 18:41:35 +0000166
mbligh534015f2006-09-15 03:28:56 +0000167 def apply_patches(self, local_patches):
mblighc86b0b42006-07-28 17:35:28 +0000168 """apply the list of patches, in order"""
mblighf4c35322006-03-13 01:01:10 +0000169 builddir = self.build_dir
170 os.chdir(builddir)
171
mbligh534015f2006-09-15 03:28:56 +0000172 if not local_patches:
mblighf4c35322006-03-13 01:01:10 +0000173 return None
mbligh0763e732007-08-30 16:35:06 +0000174 for (spec, local, md5sum) in local_patches:
175 if local.endswith('.bz2') or local.endswith('.gz'):
176 ref = spec
177 else:
178 ref = force_copy(local, self.results_dir)
179 ref = self.job.relative_path(ref)
180 log = 'PATCH: %s %s %s\n' % (spec, ref, md5sum)
181 print log
182 cat_file_to_cmd(local, 'patch -p1 > /dev/null')
183 self.logfile.write(log)
mbligh72b88fc2006-12-16 18:41:35 +0000184
185
186 def get_kernel_tree(self, base_tree):
mblighc49af7b2006-11-24 04:02:21 +0000187 """Extract/link base_tree to self.build_dir"""
mbligh5970cf02006-08-06 15:39:22 +0000188
189 # if base_tree is a dir, assume uncompressed kernel
190 if os.path.isdir(base_tree):
191 print 'Symlinking existing kernel source'
mblighc49af7b2006-11-24 04:02:21 +0000192 os.symlink(base_tree, self.build_dir)
mblighf4c35322006-03-13 01:01:10 +0000193
mbligh5970cf02006-08-06 15:39:22 +0000194 # otherwise, extract tarball
195 else:
mblighc49af7b2006-11-24 04:02:21 +0000196 os.chdir(os.path.dirname(self.src_dir))
197 # Figure out local destination for tarball
198 tarball = os.path.join(self.src_dir, os.path.basename(base_tree))
mbligh5970cf02006-08-06 15:39:22 +0000199 get_file(base_tree, tarball)
mbligh5970cf02006-08-06 15:39:22 +0000200 print 'Extracting kernel tarball:', tarball, '...'
mblighc49af7b2006-11-24 04:02:21 +0000201 extract_tarball_to_dir(tarball, self.build_dir)
mbligh5970cf02006-08-06 15:39:22 +0000202
mblighf4c35322006-03-13 01:01:10 +0000203
mblighfdbcaec2006-10-01 23:28:57 +0000204 def extraversion(self, tag, append=1):
205 os.chdir(self.build_dir)
mbligh4426de02006-10-10 07:18:28 +0000206 extraversion_sub = r's/^EXTRAVERSION =\s*\(.*\)/EXTRAVERSION = '
mblighfdbcaec2006-10-01 23:28:57 +0000207 if append:
mbligh4426de02006-10-10 07:18:28 +0000208 p = extraversion_sub + '\\1-%s/' % tag
mblighfdbcaec2006-10-01 23:28:57 +0000209 else:
mbligh4426de02006-10-10 07:18:28 +0000210 p = extraversion_sub + '-%s/' % tag
mbligh4c3fe4a2007-07-31 17:59:21 +0000211 system('mv Makefile Makefile.old')
212 system('sed "%s" < Makefile.old > Makefile' % p)
mblighfdbcaec2006-10-01 23:28:57 +0000213
214
mbligh5925e962007-08-30 17:05:22 +0000215 def _build(self, make_opts = '', logfile = '', extraversion='autotest'):
mblighc86b0b42006-07-28 17:35:28 +0000216 """build the kernel
mbligh72b88fc2006-12-16 18:41:35 +0000217
mblighc86b0b42006-07-28 17:35:28 +0000218 make_opts
219 additional options to make, if any
220 """
mbligh10038012006-10-19 03:32:45 +0000221 os_dep.commands('gcc', 'make')
mbligh6d4c9412006-09-13 23:08:44 +0000222 if logfile == '':
223 logfile = os.path.join(self.log_dir, 'kernel_build')
mblighf4c35322006-03-13 01:01:10 +0000224 os.chdir(self.build_dir)
mblighfdbcaec2006-10-01 23:28:57 +0000225 if extraversion:
226 self.extraversion(extraversion)
mbligh93057012006-08-06 15:51:56 +0000227 print os.path.join(self.log_dir, 'stdout')
mbligh6d4c9412006-09-13 23:08:44 +0000228 self.job.stdout.redirect(logfile + '.stdout')
229 self.job.stderr.redirect(logfile + '.stderr')
mbligha2508052006-05-28 21:29:53 +0000230 self.set_cross_cc()
mblighf4c35322006-03-13 01:01:10 +0000231 # setup_config_file(config_file, config_overrides)
apwc7846102006-04-06 18:22:13 +0000232
233 # Not needed on 2.6, but hard to tell -- handle failure
mblighfdbcaec2006-10-01 23:28:57 +0000234 system('make dep', ignorestatus=1)
mblighf4c35322006-03-13 01:01:10 +0000235 threads = 2 * count_cpus()
mbligh6d4c9412006-09-13 23:08:44 +0000236 build_string = 'make -j %d %s %s' % (threads, make_opts,
237 self.build_target)
238 # eg make bzImage, or make zImage
239 print build_string
240 system(build_string)
mblighf4c35322006-03-13 01:01:10 +0000241 if kernel_config.modules_needed('.config'):
apwd4701972006-10-16 09:24:56 +0000242 system('make -j %d modules' % (threads))
apwc7846102006-04-06 18:22:13 +0000243
mblighf4c35322006-03-13 01:01:10 +0000244 self.job.stdout.restore()
245 self.job.stderr.restore()
mbligh72b88fc2006-12-16 18:41:35 +0000246
mbligh4426de02006-10-10 07:18:28 +0000247 kernel_version = self.get_kernel_build_ver()
248 kernel_version = re.sub('-autotest', '', kernel_version)
249 self.logfile.write('BUILD VERSION: %s\n' % kernel_version)
mbligh1e8858e2006-11-24 22:18:35 +0000250
251 force_copy(self.build_dir+'/System.map', self.results_dir)
mblighf4c35322006-03-13 01:01:10 +0000252
253
mbligh5925e962007-08-30 17:05:22 +0000254 def build(self, *args, **dargs):
255 self.__record(self._build, "kernel.build", *args, **dargs)
256
257
mblighf4c35322006-03-13 01:01:10 +0000258 def build_timed(self, threads, timefile = '/dev/null', make_opts = ''):
mblighc86b0b42006-07-28 17:35:28 +0000259 """time the bulding of the kernel"""
mblighb8a14e32006-05-06 00:17:35 +0000260 os.chdir(self.build_dir)
mbligh678823f2006-12-07 18:49:00 +0000261 self.set_cross_cc()
mblighb8a14e32006-05-06 00:17:35 +0000262 print "make clean"
263 system('make clean')
mbligha2bb9d62006-10-09 16:26:03 +0000264 build_string = "/usr/bin/time -o %s make %s -j %s vmlinux" % (timefile, make_opts, threads)
mblighf4c35322006-03-13 01:01:10 +0000265 print build_string
apwc7846102006-04-06 18:22:13 +0000266 system(build_string)
267 if (not os.path.isfile('vmlinux')):
268 raise TestError("no vmlinux found, kernel build failed")
mblighb8a14e32006-05-06 00:17:35 +0000269
270
mbligh5925e962007-08-30 17:05:22 +0000271 def _clean(self):
mblighc86b0b42006-07-28 17:35:28 +0000272 """make clean in the kernel tree"""
mblighb8a14e32006-05-06 00:17:35 +0000273 os.chdir(self.build_dir)
mblighf4c35322006-03-13 01:01:10 +0000274 print "make clean"
apwc7846102006-04-06 18:22:13 +0000275 system('make clean')
mblighf4c35322006-03-13 01:01:10 +0000276
mbligh50f42ea2006-09-30 22:22:21 +0000277
mbligh5925e962007-08-30 17:05:22 +0000278 def clean(self, *args, **dargs):
279 self.__record(self._clean, "kernel.clean", *args, **dargs)
280
281
282 def _mkinitrd(self, version, image, system_map, initrd):
mbligh50f42ea2006-09-30 22:22:21 +0000283 """Build kernel initrd image.
284 Try to use distro specific way to build initrd image.
285 Parameters:
286 version
287 new kernel version
288 image
289 new kernel image file
290 system_map
291 System.map file
292 initrd
293 initrd image file to build
294 """
295 vendor = get_os_vendor()
296
297 if os.path.isfile(initrd):
mblighfdbcaec2006-10-01 23:28:57 +0000298 print "Existing %s file, will remove it." % initrd
mbligh50f42ea2006-09-30 22:22:21 +0000299 os.remove(initrd)
mbligh72b88fc2006-12-16 18:41:35 +0000300
mbligh50f42ea2006-09-30 22:22:21 +0000301 if vendor in ['Red Hat', 'Fedora Core']:
mblighfdbcaec2006-10-01 23:28:57 +0000302 system('mkinitrd %s %s' % (initrd, version))
mbligh50f42ea2006-09-30 22:22:21 +0000303 elif vendor in ['SUSE']:
mblighfdbcaec2006-10-01 23:28:57 +0000304 system('mkinitrd -k %s -i %s -M %s' % (image, initrd, system_map))
apwc898a1f2007-02-28 15:27:22 +0000305 elif vendor in ['Debian', 'Ubuntu']:
306 if os.path.isfile('/usr/sbin/mkinitrd'):
307 cmd = '/usr/sbin/mkinitrd'
308 elif os.path.isfile('/usr/sbin/mkinitramfs'):
309 cmd = '/usr/sbin/mkinitramfs'
310 else:
311 raise TestError('No Debian initrd builder')
312 system('%s -o %s %s' % (cmd, initrd, version))
mbligh50f42ea2006-09-30 22:22:21 +0000313 else:
mblighfdbcaec2006-10-01 23:28:57 +0000314 raise TestError('Unsupported vendor %s' % vendor)
mbligh50f42ea2006-09-30 22:22:21 +0000315
316
mbligh5925e962007-08-30 17:05:22 +0000317 def mkinitrd(self, *args, **dargs):
318 self.__record(self._mkinitrd, "kernel.mkinitrd", *args, **dargs)
319
320
mbligh8baa2ea2006-12-17 23:01:24 +0000321 def set_build_image(self, image):
322 self.build_image = image
323
324
mbligh5925e962007-08-30 17:05:22 +0000325 def _install(self, tag='autotest', prefix = '/'):
mblighc86b0b42006-07-28 17:35:28 +0000326 """make install in the kernel tree"""
mblighf4c35322006-03-13 01:01:10 +0000327 os.chdir(self.build_dir)
mbligh72b88fc2006-12-16 18:41:35 +0000328
mbligh6a1d4db2006-10-06 04:30:16 +0000329 if not os.path.isdir(prefix):
330 os.mkdir(prefix)
mbligha87116f2006-10-10 02:47:08 +0000331 self.boot_dir = os.path.join(prefix, 'boot')
332 if not os.path.isdir(self.boot_dir):
333 os.mkdir(self.boot_dir)
mbligh0ad65582006-10-06 04:16:36 +0000334
mbligh8baa2ea2006-12-17 23:01:24 +0000335 if not self.build_image:
336 images = glob.glob('arch/*/boot/' + self.build_target)
337 if len(images):
338 self.build_image = images[0]
339 else:
340 self.build_image = self.build_target
mbligha87116f2006-10-10 02:47:08 +0000341
342 # remember installed files
mbligha87116f2006-10-10 02:47:08 +0000343 self.vmlinux = self.boot_dir + '/vmlinux-' + tag
mbligh8baa2ea2006-12-17 23:01:24 +0000344 if (self.build_image != 'vmlinux'):
apw9a61c5b2006-11-28 10:03:15 +0000345 self.image = self.boot_dir + '/vmlinuz-' + tag
346 else:
347 self.image = self.vmlinux
mbligha87116f2006-10-10 02:47:08 +0000348 self.system_map = self.boot_dir + '/System.map-' + tag
349 self.config = self.boot_dir + '/config-' + tag
350 self.initrd = ''
351
352 # copy to boot dir
mbligha87116f2006-10-10 02:47:08 +0000353 force_copy('vmlinux', self.vmlinux)
mbligh8baa2ea2006-12-17 23:01:24 +0000354 if (self.build_image != 'vmlinux'):
355 force_copy(self.build_image, self.image)
mbligha87116f2006-10-10 02:47:08 +0000356 force_copy('System.map', self.system_map)
357 force_copy('.config', self.config)
358
mbligh6a1d4db2006-10-06 04:30:16 +0000359 if not kernel_config.modules_needed('.config'):
360 return
361
362 system('make modules_install INSTALL_MOD_PATH=%s' % prefix)
363 if prefix == '/':
mbligha87116f2006-10-10 02:47:08 +0000364 self.initrd = self.boot_dir + '/initrd-' + tag
365 self.mkinitrd(self.get_kernel_build_ver(), self.image, \
366 self.system_map, self.initrd)
367
368
mbligh5925e962007-08-30 17:05:22 +0000369 def install(self, *args, **dargs):
370 self.__record(self._install, "kernel.install", *args, **dargs)
371
372
mbligha87116f2006-10-10 02:47:08 +0000373 def add_to_bootloader(self, tag='autotest', args=''):
374 """ add this kernel to bootloader, taking an
375 optional parameter of space separated parameters
376 e.g.: kernel.add_to_bootloader('mykernel', 'ro acpi=off')
377 """
378
379 # remove existing entry if present
380 self.job.bootloader.remove_kernel(tag)
381
apwcbe32572006-11-28 10:00:23 +0000382 # pull the base argument set from the job config,
apwcbe32572006-11-28 10:00:23 +0000383 baseargs = self.job.config_get('boot.default_args')
mbligh78bc05e2006-12-25 02:29:59 +0000384 if baseargs:
385 args = baseargs + " " + args
386
387 # otherwise populate from /proc/cmdline
388 # if not baseargs:
389 # baseargs = open('/proc/cmdline', 'r').readline().strip()
390 # NOTE: This is unnecessary, because boottool does it.
apwcbe32572006-11-28 10:00:23 +0000391
mbligh78bc05e2006-12-25 02:29:59 +0000392 root = None
393 roots = [x for x in args.split() if x.startswith('root=')]
394 if roots:
395 root = re.sub('^root=', '', roots[0])
396 arglist = [x for x in args.split() if not x.startswith('root=')]
397 args = ' '.join(arglist)
mbligha87116f2006-10-10 02:47:08 +0000398
mbligh78bc05e2006-12-25 02:29:59 +0000399 # add the kernel entry
400 # add_kernel(image, title='autotest', initrd='')
401 self.job.bootloader.add_kernel(self.image, tag, self.initrd, \
402 args = args, root = root)
mbligh6a1d4db2006-10-06 04:30:16 +0000403
mbligh201aa892006-10-29 04:02:05 +0000404
mbligh548f29a2006-10-17 04:55:12 +0000405 def get_kernel_build_arch(self, arch=None):
mbligh201aa892006-10-29 04:02:05 +0000406 """
407 Work out the current kernel architecture (as a kernel arch)
408 """
mbligh548f29a2006-10-17 04:55:12 +0000409 if not arch:
410 arch = get_current_kernel_arch()
411 if re.match('i.86', arch):
412 return 'i386'
413 elif re.match('sun4u', arch):
414 return 'sparc64'
415 elif re.match('arm.*', arch):
416 return 'arm'
417 elif re.match('sa110', arch):
418 return 'arm'
419 elif re.match('s390x', arch):
420 return 's390'
421 elif re.match('parisc64', arch):
422 return 'parisc'
423 elif re.match('ppc.*', arch):
424 return 'powerpc'
425 elif re.match('mips.*', arch):
426 return 'mips'
427 else:
428 return arch
429
mbligh6a1d4db2006-10-06 04:30:16 +0000430
mblighda76b212007-07-19 16:50:41 +0000431 def boot(self, args='', once=True):
apw1b5dc362006-10-31 11:24:26 +0000432 """ install and boot this kernel, do not care how
433 just make it happen.
434 """
435
436 # Install this kernel.
437 self.install()
mblighda76b212007-07-19 16:50:41 +0000438 self.add_to_bootloader(args=args, tag='autotest')
439 if once:
440 self.job.bootloader.boot_once('autotest')
apw1b5dc362006-10-31 11:24:26 +0000441
442 # Boot it.
443 self.job.reboot()
444
445
mblighfdbcaec2006-10-01 23:28:57 +0000446 def get_kernel_build_ver(self):
mblighe11f5fc2006-10-04 04:42:22 +0000447 """Check Makefile and .config to return kernel version"""
448 version = patchlevel = sublevel = extraversion = localversion = ''
449
450 for line in open(self.build_dir + '/Makefile', 'r').readlines():
451 if line.startswith('VERSION'):
452 version = line[line.index('=') + 1:].strip()
453 if line.startswith('PATCHLEVEL'):
454 patchlevel = line[line.index('=') + 1:].strip()
455 if line.startswith('SUBLEVEL'):
456 sublevel = line[line.index('=') + 1:].strip()
457 if line.startswith('EXTRAVERSION'):
458 extraversion = line[line.index('=') + 1:].strip()
459
460 for line in open(self.build_dir + '/.config', 'r').readlines():
461 if line.startswith('CONFIG_LOCALVERSION='):
462 localversion = line.rstrip().split('"')[1]
463
mbligh72b88fc2006-12-16 18:41:35 +0000464 return "%s.%s.%s%s%s" %(version, patchlevel, sublevel, extraversion, localversion)
mblighfdbcaec2006-10-01 23:28:57 +0000465
466
mbligh8baa2ea2006-12-17 23:01:24 +0000467 def set_build_target(self, build_target):
468 if build_target:
469 self.build_target = build_target
470 print 'BUILD TARGET: %s' % self.build_target
471
472
mbligh5970cf02006-08-06 15:39:22 +0000473 def set_cross_cc(self, target_arch=None, cross_compile=None,
474 build_target='bzImage'):
mblighc86b0b42006-07-28 17:35:28 +0000475 """Set up to cross-compile.
mblighcc2e6662006-09-14 01:24:07 +0000476 This is broken. We need to work out what the default
477 compile produces, and if not, THEN set the cross
478 compiler.
mblighc86b0b42006-07-28 17:35:28 +0000479 """
mblighcc2e6662006-09-14 01:24:07 +0000480
mbligh5970cf02006-08-06 15:39:22 +0000481 if self.target_arch:
482 return
mbligh678823f2006-12-07 18:49:00 +0000483
mbligh8baa2ea2006-12-17 23:01:24 +0000484 # if someone has set build_target, don't clobber in set_cross_cc
485 # run set_build_target before calling set_cross_cc
486 if not self.build_target:
487 self.set_build_target(build_target)
mbligh72b88fc2006-12-16 18:41:35 +0000488
mbligh5970cf02006-08-06 15:39:22 +0000489 # If no 'target_arch' given assume native compilation
490 if target_arch == None:
mbligh548f29a2006-10-17 04:55:12 +0000491 target_arch = get_current_kernel_arch()
mbligh5970cf02006-08-06 15:39:22 +0000492 if target_arch == 'ppc64':
mbligh5970cf02006-08-06 15:39:22 +0000493 if self.build_target == 'bzImage':
apw9a61c5b2006-11-28 10:03:15 +0000494 self.build_target = 'vmlinux'
mbligh678823f2006-12-07 18:49:00 +0000495
496 if not cross_compile:
497 cross_compile = self.job.config_get('kernel.cross_cc')
498
499 if cross_compile:
500 os.environ['CROSS_COMPILE'] = cross_compile
501 else:
502 if os.environ.has_key('CROSS_COMPILE'):
503 del os.environ['CROSS_COMPILE']
504
mblighcc2e6662006-09-14 01:24:07 +0000505 return # HACK. Crap out for now.
mblighf4c35322006-03-13 01:01:10 +0000506
mblighcc2e6662006-09-14 01:24:07 +0000507 # At this point I know what arch I *want* to build for
508 # but have no way of working out what arch the default
509 # compiler DOES build for.
510
511 # Oh, and BTW, install_package() doesn't exist yet.
mbligh72b88fc2006-12-16 18:41:35 +0000512
mblighcc2e6662006-09-14 01:24:07 +0000513 if target_arch == 'ppc64':
514 install_package('ppc64-cross')
mbligh678823f2006-12-07 18:49:00 +0000515 cross_compile = os.path.join(self.autodir, 'sources/ppc64-cross/bin')
mblighcc2e6662006-09-14 01:24:07 +0000516
517 elif target_arch == 'x86_64':
518 install_package('x86_64-cross')
mbligh678823f2006-12-07 18:49:00 +0000519 cross_compile = os.path.join(self.autodir, 'sources/x86_64-cross/bin')
mblighb8a14e32006-05-06 00:17:35 +0000520
mbligh5970cf02006-08-06 15:39:22 +0000521 os.environ['ARCH'] = self.target_arch = target_arch
522
523 self.cross_compile = cross_compile
524 if self.cross_compile:
525 os.environ['CROSS_COMPILE'] = self.cross_compile
mblighcc2e6662006-09-14 01:24:07 +0000526
mbligh72b88fc2006-12-16 18:41:35 +0000527
mblighb8a14e32006-05-06 00:17:35 +0000528 def pickle_dump(self, filename):
mblighc86b0b42006-07-28 17:35:28 +0000529 """dump a pickle of ourself out to the specified filename
530
531 we can't pickle the backreference to job (it contains fd's),
mbligh709bb9b2006-10-12 04:32:16 +0000532 nor would we want to. Same for logfile (fd's).
mblighc86b0b42006-07-28 17:35:28 +0000533 """
mblighb8a14e32006-05-06 00:17:35 +0000534 temp = copy.copy(self)
535 temp.job = None
mbligh709bb9b2006-10-12 04:32:16 +0000536 temp.logfile = None
mblighb8a14e32006-05-06 00:17:35 +0000537 pickle.dump(temp, open(filename, 'w'))