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