summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorJames Thomas <james.thomas@codethink.co.uk>2014-07-30 18:15:49 +0100
committerJames Thomas <james.thomas@codethink.co.uk>2014-08-03 12:49:22 +0100
commit62d9721c1cda780aacb1ca72e598a2ad969725c6 (patch)
tree42379eeb1cd03cedca938b9772136d7806b490bd /morphlib
parentde35a0f256999e107ee524a4647151aab6cbfc87 (diff)
downloadmorph-62d9721c1cda780aacb1ca72e598a2ad969725c6.tar.gz
Make bootloader config/install more generic
Remove the BOOTLOADER environment variable and instead favour BOOTLOADER_CONFIG_FORMAT to set the desired bootloader format, and BOOTLOADER_INSTALL to set the type of bootloader to install. For example, since u-boot can boot using extlinux.conf files, it's conceivable that someone might want to do CONFIG_FORMAT=extlinux.conf, INSTALL=u-boot. However, for most platforms you would want to set INSTALL to "none"
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/writeexts.py69
1 files changed, 52 insertions, 17 deletions
diff --git a/morphlib/writeexts.py b/morphlib/writeexts.py
index 1b8770e2..dec318d9 100644
--- a/morphlib/writeexts.py
+++ b/morphlib/writeexts.py
@@ -257,15 +257,15 @@ class WriteExtension(cliapp.Application):
os.symlink(
version_label, os.path.join(mountpoint, 'systems', 'default'))
- if self.bootloader_is_wanted():
+ if self.bootloader_config_is_wanted():
self.install_kernel(version_root, temp_root)
self.install_syslinux_menu(mountpoint, version_root)
if initramfs is not None:
self.install_initramfs(initramfs, version_root)
- self.install_extlinux(mountpoint, disk_uuid)
+ self.generate_bootloader_config(mountpoint, disk_uuid)
else:
- self.install_extlinux(mountpoint)
-
+ self.generate_bootloader_config(mountpoint)
+ self.install_bootloader(mountpoint)
def create_orig(self, version_root, temp_root):
'''Create the default "factory" system.'''
@@ -385,13 +385,36 @@ class WriteExtension(cliapp.Application):
cliapp.runcmd(['cp', '-a', try_path, kernel_dest])
break
+ def get_bootloader_install(self):
+ # Do we actually want to install the bootloader?
+ # Set this to "none" to prevent the install
+ return os.environ.get('BOOTLOADER_INSTALL', 'extlinux')
+
+ def get_bootloader_config_format(self):
+ # The config format for the bootloader,
+ # if not set we default to extlinux for x86
+ return os.environ.get('BOOTLOADER_CONFIG_FORMAT', 'extlinux')
+
def get_extra_kernel_args(self):
return os.environ.get('KERNEL_ARGS', '')
def get_root_device(self):
return os.environ.get('ROOT_DEVICE', '/dev/sda')
- def install_extlinux(self, real_root, disk_uuid=None):
+ def generate_bootloader_config(self, real_root, disk_uuid=None):
+ '''Install extlinux on the newly created disk image.'''
+ config_function_dict = {
+ 'extlinux': self.generate_extlinux_config,
+ }
+
+ config_type = self.get_bootloader_config_format()
+ if config_type in config_function_dict:
+ config_function_dict[config_type](real_root, disk_uuid)
+ else:
+ raise cliapp.AppException(
+ 'Invalid BOOTLOADER_CONFIG_FORMAT %s' % config_type)
+
+ def generate_extlinux_config(self, real_root, disk_uuid=None):
'''Install extlinux on the newly created disk image.'''
self.status(msg='Creating extlinux.conf')
@@ -414,6 +437,19 @@ class WriteExtension(cliapp.Application):
f.write('initrd /systems/default/initramfs\n')
f.write('append %s\n' % kernel_args)
+ def install_bootloader(self, real_root):
+ install_function_dict = {
+ 'extlinux': self.install_bootloader_extlinux,
+ }
+
+ install_type = self.get_bootloader_install()
+ if install_type in install_function_dict:
+ install_function_dict[install_type](real_root)
+ elif install_type != 'none':
+ raise cliapp.AppException(
+ 'Invalid BOOTLOADER_INSTALL %s' % install_type)
+
+ def install_bootloader_extlinux(self, real_root):
self.status(msg='Installing extlinux')
cliapp.runcmd(['extlinux', '--install', real_root])
@@ -447,12 +483,13 @@ class WriteExtension(cliapp.Application):
else:
return []
- def bootloader_is_wanted(self):
- '''Does the user request a bootloader?
+ def bootloader_config_is_wanted(self):
+ '''Does the user want to generate a bootloader config?
- The user may set $BOOTLOADER to yes, no, or auto. If not
- set, auto is the default and means that the bootloader will
- be installed on x86-32 and x86-64, but not otherwise.
+ The user may set $BOOTLOADER_CONFIG_FORMAT to the desired
+ format (u-boot or extlinux). If not set, extlinux is the
+ default but will be generated on x86-32 and x86-64, but not
+ otherwise.
'''
@@ -460,14 +497,12 @@ class WriteExtension(cliapp.Application):
return (arch == 'x86_64' or
(arch.startswith('i') and arch.endswith('86')))
- value = os.environ.get('BOOTLOADER', 'auto')
- if value == 'auto':
- if is_x86(os.uname()[-1]):
- value = 'yes'
- else:
- value = 'no'
+ value = os.environ.get('BOOTLOADER_CONFIG_FORMAT', '')
+ if value == '':
+ if not is_x86(os.uname()[-1]):
+ return False
- return value == 'yes'
+ return True
def get_environment_boolean(self, variable):
'''Parse a yes/no boolean passed through the environment.'''