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