mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 1 | __author__ = """Copyright Martin J. Bligh, 2006""" |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 2 | |
apw | ba5bbfd | 2006-10-16 09:25:45 +0000 | [diff] [blame] | 3 | import os,os.path,shutil,urllib,copy,pickle,re,glob |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 4 | from autotest_utils import * |
mbligh | 1003801 | 2006-10-19 03:32:45 +0000 | [diff] [blame] | 5 | import kernel_config, test, os_dep |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 6 | |
| 7 | class kernel: |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 8 | """ 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) |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 19 | src_dir |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 20 | <tmp_dir>/src/ |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 21 | build_dir |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 22 | <tmp_dir>/linux/ |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 23 | config_dir |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 24 | <results_dir>/config/ |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 25 | log_dir |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 26 | <results_dir>/debug/ |
| 27 | results_dir |
| 28 | <results_dir>/results/ |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 29 | """ |
| 30 | |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 31 | autodir = '' |
| 32 | |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 33 | def __init__(self, job, base_tree, results_dir, tmp_dir, leave = False): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 34 | """Initialize the kernel build environment |
| 35 | |
| 36 | job |
| 37 | which job this build is part of |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 38 | base_tree |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 39 | 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') |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 44 | results_dir |
| 45 | Results directory (holds config/, debug/, results/) |
| 46 | tmp_dir |
| 47 | |
| 48 | leave |
| 49 | Boolean, whether to leave existing tmpdir or not |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 50 | """ |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 51 | self.job = job |
| 52 | autodir = job.autodir |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 53 | |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 54 | self.src_dir = os.path.join(tmp_dir, 'src') |
| 55 | self.build_dir = os.path.join(tmp_dir, 'linux') |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 56 | # created by get_kernel_tree |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 57 | 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 | |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 67 | os.mkdir(self.src_dir) |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 68 | 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) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 72 | |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 73 | logpath = os.path.join(self.log_dir, 'build_log') |
| 74 | self.logfile = open(logpath, 'w+') |
| 75 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 76 | self.target_arch = None |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 77 | self.build_target = 'bzImage' |
| 78 | |
| 79 | if leave: |
| 80 | return |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 81 | |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 82 | self.logfile.write('BASE: %s\n' % base_tree) |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 83 | if os.path.exists(base_tree): |
| 84 | self.get_kernel_tree(base_tree) |
| 85 | else: |
apw | 8ad56be | 2006-11-06 17:49:54 +0000 | [diff] [blame] | 86 | args = self.job.config_get('mirror.ftp_kernel_org') |
mbligh | 548f29a | 2006-10-17 04:55:12 +0000 | [diff] [blame] | 87 | if args: |
| 88 | args = '-l ' + args |
| 89 | base_components = kernelexpand(base_tree, args) |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 90 | print 'kernelexpand: ' |
| 91 | print base_components |
| 92 | self.get_kernel_tree(base_components.pop(0)) |
| 93 | if base_components: # apply remaining patches |
| 94 | self.patch(*base_components) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 95 | |
| 96 | |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 97 | def patch(self, patches): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 98 | """Apply a list of patches (in order)""" |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 99 | if not patches: |
| 100 | return |
| 101 | if isinstance(patches, basestring): |
| 102 | patches = [patches] |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 103 | print 'Applying patches: ', patches |
| 104 | # self.job.stdout.redirect(os.path.join(self.log_dir, 'stdout')) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 105 | local_patches = self.get_patches(patches) |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 106 | for patch in patches: |
| 107 | self.logfile.write('PATCH: %s\n' % patch) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 108 | self.apply_patches(local_patches) |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 109 | # self.job.stdout.restore() |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 110 | |
| 111 | |
apw | fa52695 | 2006-04-21 17:27:09 +0000 | [diff] [blame] | 112 | def config(self, config_file, config_list = None): |
mbligh | 9305701 | 2006-08-06 15:51:56 +0000 | [diff] [blame] | 113 | self.job.stdout.redirect(os.path.join(self.log_dir, 'stdout')) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 114 | config = kernel_config.kernel_config(self.build_dir, self.config_dir, config_file, config_list) |
| 115 | self.job.stdout.restore() |
| 116 | |
| 117 | |
| 118 | def get_patches(self, patches): |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 119 | """fetch the patches to the local src_dir""" |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 120 | local_patches = [] |
| 121 | for patch in patches: |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 122 | dest = os.path.join(self.src_dir, basename(patch)) |
| 123 | print "get_file %s %s %s %s" % (patch, dest, self.src_dir, basename(patch)) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 124 | get_file(patch, dest) |
| 125 | local_patches.append(dest) |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 126 | return local_patches |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 127 | |
| 128 | |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 129 | def apply_patches(self, local_patches): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 130 | """apply the list of patches, in order""" |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 131 | builddir = self.build_dir |
| 132 | os.chdir(builddir) |
| 133 | |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 134 | if not local_patches: |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 135 | return None |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 136 | for patch in local_patches: |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 137 | print 'Patching from', basename(patch), '...' |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 138 | cat_file_to_cmd(patch, 'patch -p1 > /dev/null') |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 139 | |
| 140 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 141 | def get_kernel_tree(self, base_tree): |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 142 | """Extract/link base_tree to self.build_dir""" |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 143 | |
| 144 | # if base_tree is a dir, assume uncompressed kernel |
| 145 | if os.path.isdir(base_tree): |
| 146 | print 'Symlinking existing kernel source' |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 147 | os.symlink(base_tree, self.build_dir) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 148 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 149 | # otherwise, extract tarball |
| 150 | else: |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 151 | os.chdir(os.path.dirname(self.src_dir)) |
| 152 | # Figure out local destination for tarball |
| 153 | tarball = os.path.join(self.src_dir, os.path.basename(base_tree)) |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 154 | get_file(base_tree, tarball) |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 155 | print 'Extracting kernel tarball:', tarball, '...' |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 156 | extract_tarball_to_dir(tarball, self.build_dir) |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 157 | |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 158 | |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 159 | def extraversion(self, tag, append=1): |
| 160 | os.chdir(self.build_dir) |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 161 | extraversion_sub = r's/^EXTRAVERSION =\s*\(.*\)/EXTRAVERSION = ' |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 162 | if append: |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 163 | p = extraversion_sub + '\\1-%s/' % tag |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 164 | else: |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 165 | p = extraversion_sub + '-%s/' % tag |
| 166 | system('sed -i.old "%s" Makefile' % p) |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 167 | |
| 168 | |
| 169 | def build(self, make_opts = '', logfile = '', extraversion='autotest'): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 170 | """build the kernel |
| 171 | |
| 172 | make_opts |
| 173 | additional options to make, if any |
| 174 | """ |
mbligh | 1003801 | 2006-10-19 03:32:45 +0000 | [diff] [blame] | 175 | os_dep.commands('gcc', 'make') |
mbligh | 6d4c941 | 2006-09-13 23:08:44 +0000 | [diff] [blame] | 176 | if logfile == '': |
| 177 | logfile = os.path.join(self.log_dir, 'kernel_build') |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 178 | os.chdir(self.build_dir) |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 179 | if extraversion: |
| 180 | self.extraversion(extraversion) |
mbligh | 9305701 | 2006-08-06 15:51:56 +0000 | [diff] [blame] | 181 | print os.path.join(self.log_dir, 'stdout') |
mbligh | 6d4c941 | 2006-09-13 23:08:44 +0000 | [diff] [blame] | 182 | self.job.stdout.redirect(logfile + '.stdout') |
| 183 | self.job.stderr.redirect(logfile + '.stderr') |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 184 | self.set_cross_cc() |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 185 | # setup_config_file(config_file, config_overrides) |
apw | c784610 | 2006-04-06 18:22:13 +0000 | [diff] [blame] | 186 | |
| 187 | # Not needed on 2.6, but hard to tell -- handle failure |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 188 | system('make dep', ignorestatus=1) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 189 | threads = 2 * count_cpus() |
mbligh | 6d4c941 | 2006-09-13 23:08:44 +0000 | [diff] [blame] | 190 | build_string = 'make -j %d %s %s' % (threads, make_opts, |
| 191 | self.build_target) |
| 192 | # eg make bzImage, or make zImage |
| 193 | print build_string |
| 194 | system(build_string) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 195 | if kernel_config.modules_needed('.config'): |
apw | d470197 | 2006-10-16 09:24:56 +0000 | [diff] [blame] | 196 | system('make -j %d modules' % (threads)) |
apw | c784610 | 2006-04-06 18:22:13 +0000 | [diff] [blame] | 197 | |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 198 | self.job.stdout.restore() |
| 199 | self.job.stderr.restore() |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 200 | |
| 201 | kernel_version = self.get_kernel_build_ver() |
| 202 | kernel_version = re.sub('-autotest', '', kernel_version) |
| 203 | self.logfile.write('BUILD VERSION: %s\n' % kernel_version) |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame^] | 204 | |
| 205 | force_copy(self.build_dir+'/System.map', self.results_dir) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 206 | |
| 207 | |
| 208 | def build_timed(self, threads, timefile = '/dev/null', make_opts = ''): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 209 | """time the bulding of the kernel""" |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 210 | os.chdir(self.build_dir) |
| 211 | print "make clean" |
| 212 | system('make clean') |
mbligh | a2bb9d6 | 2006-10-09 16:26:03 +0000 | [diff] [blame] | 213 | build_string = "/usr/bin/time -o %s make %s -j %s vmlinux" % (timefile, make_opts, threads) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 214 | print build_string |
apw | c784610 | 2006-04-06 18:22:13 +0000 | [diff] [blame] | 215 | system(build_string) |
| 216 | if (not os.path.isfile('vmlinux')): |
| 217 | raise TestError("no vmlinux found, kernel build failed") |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 218 | |
| 219 | |
| 220 | def clean(self): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 221 | """make clean in the kernel tree""" |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 222 | os.chdir(self.build_dir) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 223 | print "make clean" |
apw | c784610 | 2006-04-06 18:22:13 +0000 | [diff] [blame] | 224 | system('make clean') |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 225 | |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 226 | |
| 227 | def mkinitrd(self, version, image, system_map, initrd): |
| 228 | """Build kernel initrd image. |
| 229 | Try to use distro specific way to build initrd image. |
| 230 | Parameters: |
| 231 | version |
| 232 | new kernel version |
| 233 | image |
| 234 | new kernel image file |
| 235 | system_map |
| 236 | System.map file |
| 237 | initrd |
| 238 | initrd image file to build |
| 239 | """ |
| 240 | vendor = get_os_vendor() |
| 241 | |
| 242 | if os.path.isfile(initrd): |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 243 | print "Existing %s file, will remove it." % initrd |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 244 | os.remove(initrd) |
| 245 | |
| 246 | if vendor in ['Red Hat', 'Fedora Core']: |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 247 | system('mkinitrd %s %s' % (initrd, version)) |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 248 | elif vendor in ['SUSE']: |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 249 | system('mkinitrd -k %s -i %s -M %s' % (image, initrd, system_map)) |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 250 | else: |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 251 | raise TestError('Unsupported vendor %s' % vendor) |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 252 | |
| 253 | |
mbligh | 6a1d4db | 2006-10-06 04:30:16 +0000 | [diff] [blame] | 254 | def install(self, tag='autotest', prefix = '/'): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 255 | """make install in the kernel tree""" |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 256 | os.chdir(self.build_dir) |
mbligh | 0ad6558 | 2006-10-06 04:16:36 +0000 | [diff] [blame] | 257 | |
mbligh | 6a1d4db | 2006-10-06 04:30:16 +0000 | [diff] [blame] | 258 | if not os.path.isdir(prefix): |
| 259 | os.mkdir(prefix) |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 260 | self.boot_dir = os.path.join(prefix, 'boot') |
| 261 | if not os.path.isdir(self.boot_dir): |
| 262 | os.mkdir(self.boot_dir) |
mbligh | 0ad6558 | 2006-10-06 04:16:36 +0000 | [diff] [blame] | 263 | |
apw | ba5bbfd | 2006-10-16 09:25:45 +0000 | [diff] [blame] | 264 | image = glob.glob('arch/*/boot/' + self.build_target)[0] |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 265 | |
| 266 | # remember installed files |
| 267 | self.image = self.boot_dir + '/vmlinuz-' + tag |
| 268 | self.vmlinux = self.boot_dir + '/vmlinux-' + tag |
| 269 | self.system_map = self.boot_dir + '/System.map-' + tag |
| 270 | self.config = self.boot_dir + '/config-' + tag |
| 271 | self.initrd = '' |
| 272 | |
| 273 | # copy to boot dir |
| 274 | force_copy(image, self.image) |
| 275 | force_copy('vmlinux', self.vmlinux) |
| 276 | force_copy('System.map', self.system_map) |
| 277 | force_copy('.config', self.config) |
| 278 | |
mbligh | 6a1d4db | 2006-10-06 04:30:16 +0000 | [diff] [blame] | 279 | if not kernel_config.modules_needed('.config'): |
| 280 | return |
| 281 | |
| 282 | system('make modules_install INSTALL_MOD_PATH=%s' % prefix) |
| 283 | if prefix == '/': |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 284 | self.initrd = self.boot_dir + '/initrd-' + tag |
| 285 | self.mkinitrd(self.get_kernel_build_ver(), self.image, \ |
| 286 | self.system_map, self.initrd) |
| 287 | |
| 288 | |
| 289 | def add_to_bootloader(self, tag='autotest', args=''): |
| 290 | """ add this kernel to bootloader, taking an |
| 291 | optional parameter of space separated parameters |
| 292 | e.g.: kernel.add_to_bootloader('mykernel', 'ro acpi=off') |
| 293 | """ |
| 294 | |
| 295 | # remove existing entry if present |
| 296 | self.job.bootloader.remove_kernel(tag) |
| 297 | |
| 298 | # add the kernel entry |
| 299 | # add_kernel(image, title='autotest', inird='') |
| 300 | self.job.bootloader.add_kernel(self.image, tag, self.initrd) |
| 301 | |
| 302 | # if no args passed, populate from /proc/cmdline |
| 303 | if not args: |
| 304 | args = open('/proc/cmdline', 'r').readline().strip() |
| 305 | |
| 306 | # add args to entry one at a time |
| 307 | for a in args.split(' '): |
| 308 | self.job.bootloader.add_args(tag, a) |
mbligh | 6a1d4db | 2006-10-06 04:30:16 +0000 | [diff] [blame] | 309 | |
mbligh | 201aa89 | 2006-10-29 04:02:05 +0000 | [diff] [blame] | 310 | |
mbligh | 548f29a | 2006-10-17 04:55:12 +0000 | [diff] [blame] | 311 | def get_kernel_build_arch(self, arch=None): |
mbligh | 201aa89 | 2006-10-29 04:02:05 +0000 | [diff] [blame] | 312 | """ |
| 313 | Work out the current kernel architecture (as a kernel arch) |
| 314 | """ |
mbligh | 548f29a | 2006-10-17 04:55:12 +0000 | [diff] [blame] | 315 | if not arch: |
| 316 | arch = get_current_kernel_arch() |
| 317 | if re.match('i.86', arch): |
| 318 | return 'i386' |
| 319 | elif re.match('sun4u', arch): |
| 320 | return 'sparc64' |
| 321 | elif re.match('arm.*', arch): |
| 322 | return 'arm' |
| 323 | elif re.match('sa110', arch): |
| 324 | return 'arm' |
| 325 | elif re.match('s390x', arch): |
| 326 | return 's390' |
| 327 | elif re.match('parisc64', arch): |
| 328 | return 'parisc' |
| 329 | elif re.match('ppc.*', arch): |
| 330 | return 'powerpc' |
| 331 | elif re.match('mips.*', arch): |
| 332 | return 'mips' |
| 333 | else: |
| 334 | return arch |
| 335 | |
mbligh | 6a1d4db | 2006-10-06 04:30:16 +0000 | [diff] [blame] | 336 | |
apw | 1b5dc36 | 2006-10-31 11:24:26 +0000 | [diff] [blame] | 337 | def boot(self, args=''): |
| 338 | """ install and boot this kernel, do not care how |
| 339 | just make it happen. |
| 340 | """ |
| 341 | |
| 342 | # Install this kernel. |
| 343 | self.install() |
| 344 | self.add_to_bootloader(args=args) |
| 345 | |
| 346 | # Boot it. |
| 347 | self.job.reboot() |
| 348 | |
| 349 | |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 350 | def get_kernel_build_ver(self): |
mbligh | e11f5fc | 2006-10-04 04:42:22 +0000 | [diff] [blame] | 351 | """Check Makefile and .config to return kernel version""" |
| 352 | version = patchlevel = sublevel = extraversion = localversion = '' |
| 353 | |
| 354 | for line in open(self.build_dir + '/Makefile', 'r').readlines(): |
| 355 | if line.startswith('VERSION'): |
| 356 | version = line[line.index('=') + 1:].strip() |
| 357 | if line.startswith('PATCHLEVEL'): |
| 358 | patchlevel = line[line.index('=') + 1:].strip() |
| 359 | if line.startswith('SUBLEVEL'): |
| 360 | sublevel = line[line.index('=') + 1:].strip() |
| 361 | if line.startswith('EXTRAVERSION'): |
| 362 | extraversion = line[line.index('=') + 1:].strip() |
| 363 | |
| 364 | for line in open(self.build_dir + '/.config', 'r').readlines(): |
| 365 | if line.startswith('CONFIG_LOCALVERSION='): |
| 366 | localversion = line.rstrip().split('"')[1] |
| 367 | |
| 368 | return "%s.%s.%s%s%s" %(version, patchlevel, sublevel, extraversion, localversion) |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 369 | |
| 370 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 371 | def set_cross_cc(self, target_arch=None, cross_compile=None, |
| 372 | build_target='bzImage'): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 373 | """Set up to cross-compile. |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 374 | This is broken. We need to work out what the default |
| 375 | compile produces, and if not, THEN set the cross |
| 376 | compiler. |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 377 | """ |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 378 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 379 | if self.target_arch: |
| 380 | return |
| 381 | |
| 382 | self.build_target = build_target |
| 383 | |
| 384 | # If no 'target_arch' given assume native compilation |
| 385 | if target_arch == None: |
mbligh | 548f29a | 2006-10-17 04:55:12 +0000 | [diff] [blame] | 386 | target_arch = get_current_kernel_arch() |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 387 | if target_arch == 'ppc64': |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 388 | if self.build_target == 'bzImage': |
| 389 | self.build_target = 'zImage' |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 390 | |
| 391 | return # HACK. Crap out for now. |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 392 | |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 393 | # At this point I know what arch I *want* to build for |
| 394 | # but have no way of working out what arch the default |
| 395 | # compiler DOES build for. |
| 396 | |
| 397 | # Oh, and BTW, install_package() doesn't exist yet. |
| 398 | |
| 399 | if target_arch == 'ppc64': |
| 400 | install_package('ppc64-cross') |
| 401 | cross_compile = os.path.join(autodir, 'sources/ppc64-cross/bin') |
| 402 | |
| 403 | elif target_arch == 'x86_64': |
| 404 | install_package('x86_64-cross') |
| 405 | cross_compile = os.path.join(autodir, 'sources/x86_64-cross/bin') |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 406 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 407 | os.environ['ARCH'] = self.target_arch = target_arch |
| 408 | |
| 409 | self.cross_compile = cross_compile |
| 410 | if self.cross_compile: |
| 411 | os.environ['CROSS_COMPILE'] = self.cross_compile |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 412 | |
| 413 | |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 414 | def pickle_dump(self, filename): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 415 | """dump a pickle of ourself out to the specified filename |
| 416 | |
| 417 | we can't pickle the backreference to job (it contains fd's), |
mbligh | 709bb9b | 2006-10-12 04:32:16 +0000 | [diff] [blame] | 418 | nor would we want to. Same for logfile (fd's). |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 419 | """ |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 420 | temp = copy.copy(self) |
| 421 | temp.job = None |
mbligh | 709bb9b | 2006-10-12 04:32:16 +0000 | [diff] [blame] | 422 | temp.logfile = None |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 423 | pickle.dump(temp, open(filename, 'w')) |
| 424 | |