mbligh | c9fdc40 | 2006-10-01 19:57:02 +0000 | [diff] [blame] | 1 | import shutil, re, os, os.path, string |
| 2 | from autotest_utils import * |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 3 | |
| 4 | class boottool: |
| 5 | def __init__(self, boottool_exec=None): |
| 6 | if boottool_exec: |
| 7 | self.boottool_exec = boottool_exec |
| 8 | else: |
mbligh | c9fdc40 | 2006-10-01 19:57:02 +0000 | [diff] [blame] | 9 | autodir = os.environ['AUTODIR'] |
| 10 | self.boottool_exec = autodir + '/tools/boottool' |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 11 | |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 12 | def run_boottool(self, params): |
| 13 | return system_output('%s %s' % (self.boottool_exec, params)) |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 14 | |
| 15 | def bootloader(self): |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 16 | return self.run_boottool('--bootloader-probe') |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 17 | |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 18 | def architecture(self): |
| 19 | return self.run_boottool('--arch-probe') |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 20 | |
| 21 | def list_titles(self): |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 22 | print self.run_boottool('--info all | grep title') |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 23 | |
| 24 | def print_entry(self, index): |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 25 | print self.run_boottool('--info=%s' % index) |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 26 | |
mbligh | c9fdc40 | 2006-10-01 19:57:02 +0000 | [diff] [blame] | 27 | def get_default(self): |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 28 | self.run_boottool('--default') |
mbligh | c9fdc40 | 2006-10-01 19:57:02 +0000 | [diff] [blame] | 29 | |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 30 | def set_default(self, index): |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 31 | self.run_boottool('--set-default=%s' % index) |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 32 | |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 33 | # 'kernel' can be an position number or a title |
| 34 | def add_args(self, kernel, args): |
| 35 | self.run_boottool('--update-kernel=%s --args=%s' % \ |
mbligh | c9fdc40 | 2006-10-01 19:57:02 +0000 | [diff] [blame] | 36 | (kernel, args) ) |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 37 | |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 38 | def remove_args(self, kernel, args): |
| 39 | self.run_boottool('--update-kernel=%s --remove-args=%s' % \ |
mbligh | c9fdc40 | 2006-10-01 19:57:02 +0000 | [diff] [blame] | 40 | (kernel, args) ) |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 41 | |
mbligh | 9ef1f8b | 2006-10-10 02:17:46 +0000 | [diff] [blame] | 42 | def add_kernel(self, path, title='autotest', initrd=''): |
| 43 | # boot tool needs a dummy argument for add_args to work |
| 44 | parameters = '--add-kernel=%s --title=%s --args=dummy' % \ |
| 45 | (path, title) |
| 46 | # add an initrd now or forever hold your peace |
| 47 | if initrd: |
| 48 | parameters += ' --initrd=%s' % initrd |
| 49 | self.run_boottool(parameters) |
| 50 | |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 51 | |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 52 | def remove_kernel(self, kernel): |
| 53 | self.run_boottool('--remove-kernel=%s' % kernel) |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 54 | |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 55 | def boot_once(self, title): |
| 56 | self.run_boottool('--boot-once --title=%s' % title) |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 57 | |
mbligh | f133d01 | 2006-10-05 06:57:19 +0000 | [diff] [blame] | 58 | def info(self, index): |
apw | 227ef65 | 2006-10-16 09:24:16 +0000 | [diff] [blame^] | 59 | return self.run_boottool('--info=%s' % index) |
mbligh | e404619 | 2006-09-15 14:31:01 +0000 | [diff] [blame] | 60 | |
| 61 | |
| 62 | # TODO: backup() |
| 63 | # TODO: set_timeout() |
| 64 | |