Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # syslinux.bbclass |
| 2 | # Copyright (C) 2004-2006, Advanced Micro Devices, Inc. All Rights Reserved |
| 3 | # Released under the MIT license (see packages/COPYING) |
| 4 | |
| 5 | # Provide syslinux specific functions for building bootable images. |
| 6 | |
| 7 | # External variables |
| 8 | # ${INITRD} - indicates a list of filesystem images to concatenate and use as an initrd (optional) |
| 9 | # ${ROOTFS} - indicates a filesystem image to include as the root filesystem (optional) |
| 10 | # ${AUTO_SYSLINUXMENU} - set this to 1 to enable creating an automatic menu |
| 11 | # ${LABELS} - a list of targets for the automatic config |
| 12 | # ${APPEND} - an override list of append strings for each label |
| 13 | # ${SYSLINUX_OPTS} - additional options to add to the syslinux file ';' delimited |
| 14 | # ${SYSLINUX_SPLASH} - A background for the vga boot menu if using the boot menu |
| 15 | # ${SYSLINUX_DEFAULT_CONSOLE} - set to "console=ttyX" to change kernel boot default console |
| 16 | # ${SYSLINUX_SERIAL} - Set an alternate serial port or turn off serial with empty string |
| 17 | # ${SYSLINUX_SERIAL_TTY} - Set alternate console=tty... kernel boot argument |
| 18 | # ${SYSLINUX_KERNEL_ARGS} - Add additional kernel arguments |
| 19 | |
| 20 | do_bootimg[depends] += "${MLPREFIX}syslinux:do_populate_sysroot \ |
| 21 | syslinux-native:do_populate_sysroot" |
| 22 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 23 | ISOLINUXDIR ?= "/isolinux" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | SYSLINUXDIR = "/" |
| 25 | # The kernel has an internal default console, which you can override with |
| 26 | # a console=...some_tty... |
| 27 | SYSLINUX_DEFAULT_CONSOLE ?= "" |
| 28 | SYSLINUX_SERIAL ?= "0 115200" |
| 29 | SYSLINUX_SERIAL_TTY ?= "console=ttyS0,115200" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 30 | SYSLINUX_PROMPT ?= "0" |
| 31 | SYSLINUX_TIMEOUT ?= "50" |
| 32 | AUTO_SYSLINUXMENU ?= "1" |
| 33 | SYSLINUX_ROOT ?= "${ROOT}" |
| 34 | SYSLINUX_CFG_VM ?= "${S}/syslinux_vm.cfg" |
| 35 | SYSLINUX_CFG_LIVE ?= "${S}/syslinux_live.cfg" |
| 36 | APPEND ?= "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | |
| 38 | # Need UUID utility code. |
| 39 | inherit fs-uuid |
| 40 | |
| 41 | syslinux_populate() { |
| 42 | DEST=$1 |
| 43 | BOOTDIR=$2 |
| 44 | CFGNAME=$3 |
| 45 | |
| 46 | install -d ${DEST}${BOOTDIR} |
| 47 | |
| 48 | # Install the config files |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 49 | install -m 0644 ${SYSLINUX_CFG} ${DEST}${BOOTDIR}/${CFGNAME} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | if [ "${AUTO_SYSLINUXMENU}" = 1 ] ; then |
| 51 | install -m 0644 ${STAGING_DATADIR}/syslinux/vesamenu.c32 ${DEST}${BOOTDIR}/vesamenu.c32 |
| 52 | install -m 0444 ${STAGING_DATADIR}/syslinux/libcom32.c32 ${DEST}${BOOTDIR}/libcom32.c32 |
| 53 | install -m 0444 ${STAGING_DATADIR}/syslinux/libutil.c32 ${DEST}${BOOTDIR}/libutil.c32 |
| 54 | if [ "${SYSLINUX_SPLASH}" != "" ] ; then |
| 55 | install -m 0644 ${SYSLINUX_SPLASH} ${DEST}${BOOTDIR}/splash.lss |
| 56 | fi |
| 57 | fi |
| 58 | } |
| 59 | |
| 60 | syslinux_iso_populate() { |
| 61 | iso_dir=$1 |
| 62 | syslinux_populate $iso_dir ${ISOLINUXDIR} isolinux.cfg |
| 63 | install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin $iso_dir${ISOLINUXDIR} |
| 64 | install -m 0644 ${STAGING_DATADIR}/syslinux/ldlinux.c32 $iso_dir${ISOLINUXDIR} |
| 65 | } |
| 66 | |
| 67 | syslinux_hddimg_populate() { |
| 68 | hdd_dir=$1 |
| 69 | syslinux_populate $hdd_dir ${SYSLINUXDIR} syslinux.cfg |
| 70 | install -m 0444 ${STAGING_DATADIR}/syslinux/ldlinux.sys $hdd_dir${SYSLINUXDIR}/ldlinux.sys |
| 71 | } |
| 72 | |
| 73 | syslinux_hddimg_install() { |
| 74 | syslinux ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg |
| 75 | } |
| 76 | |
| 77 | syslinux_hdddirect_install() { |
| 78 | DEST=$1 |
| 79 | syslinux $DEST |
| 80 | } |
| 81 | |
| 82 | python build_syslinux_cfg () { |
| 83 | import copy |
| 84 | import sys |
| 85 | |
| 86 | workdir = d.getVar('WORKDIR', True) |
| 87 | if not workdir: |
| 88 | bb.error("WORKDIR not defined, unable to package") |
| 89 | return |
| 90 | |
| 91 | labels = d.getVar('LABELS', True) |
| 92 | if not labels: |
| 93 | bb.debug(1, "LABELS not defined, nothing to do") |
| 94 | return |
| 95 | |
| 96 | if labels == []: |
| 97 | bb.debug(1, "No labels, nothing to do") |
| 98 | return |
| 99 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 100 | cfile = d.getVar('SYSLINUX_CFG', True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 101 | if not cfile: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 102 | raise bb.build.FuncFailed('Unable to read SYSLINUX_CFG') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | |
| 104 | try: |
| 105 | cfgfile = file(cfile, 'w') |
| 106 | except OSError: |
| 107 | raise bb.build.funcFailed('Unable to open %s' % (cfile)) |
| 108 | |
| 109 | cfgfile.write('# Automatically created by OE\n') |
| 110 | |
| 111 | opts = d.getVar('SYSLINUX_OPTS', True) |
| 112 | |
| 113 | if opts: |
| 114 | for opt in opts.split(';'): |
| 115 | cfgfile.write('%s\n' % opt) |
| 116 | |
| 117 | cfgfile.write('ALLOWOPTIONS 1\n'); |
| 118 | syslinux_default_console = d.getVar('SYSLINUX_DEFAULT_CONSOLE', True) |
| 119 | syslinux_serial_tty = d.getVar('SYSLINUX_SERIAL_TTY', True) |
| 120 | syslinux_serial = d.getVar('SYSLINUX_SERIAL', True) |
| 121 | if syslinux_serial: |
| 122 | cfgfile.write('SERIAL %s\n' % syslinux_serial) |
| 123 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 124 | menu = (d.getVar('AUTO_SYSLINUXMENU', True) == "1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 125 | |
| 126 | if menu and syslinux_serial: |
| 127 | cfgfile.write('DEFAULT Graphics console %s\n' % (labels.split()[0])) |
| 128 | else: |
| 129 | cfgfile.write('DEFAULT %s\n' % (labels.split()[0])) |
| 130 | |
| 131 | timeout = d.getVar('SYSLINUX_TIMEOUT', True) |
| 132 | |
| 133 | if timeout: |
| 134 | cfgfile.write('TIMEOUT %s\n' % timeout) |
| 135 | else: |
| 136 | cfgfile.write('TIMEOUT 50\n') |
| 137 | |
| 138 | prompt = d.getVar('SYSLINUX_PROMPT', True) |
| 139 | if prompt: |
| 140 | cfgfile.write('PROMPT %s\n' % prompt) |
| 141 | else: |
| 142 | cfgfile.write('PROMPT 1\n') |
| 143 | |
| 144 | if menu: |
| 145 | cfgfile.write('ui vesamenu.c32\n') |
| 146 | cfgfile.write('menu title Select kernel options and boot kernel\n') |
| 147 | cfgfile.write('menu tabmsg Press [Tab] to edit, [Return] to select\n') |
| 148 | splash = d.getVar('SYSLINUX_SPLASH', True) |
| 149 | if splash: |
| 150 | cfgfile.write('menu background splash.lss\n') |
| 151 | |
| 152 | for label in labels.split(): |
| 153 | localdata = bb.data.createCopy(d) |
| 154 | |
| 155 | overrides = localdata.getVar('OVERRIDES', True) |
| 156 | if not overrides: |
| 157 | raise bb.build.FuncFailed('OVERRIDES not defined') |
| 158 | |
| 159 | localdata.setVar('OVERRIDES', label + ':' + overrides) |
| 160 | bb.data.update_data(localdata) |
| 161 | |
| 162 | btypes = [ [ "", syslinux_default_console ] ] |
| 163 | if menu and syslinux_serial: |
| 164 | btypes = [ [ "Graphics console ", syslinux_default_console ], |
| 165 | [ "Serial console ", syslinux_serial_tty ] ] |
| 166 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 167 | root= d.getVar('SYSLINUX_ROOT', True) |
| 168 | if not root: |
| 169 | raise bb.build.FuncFailed('SYSLINUX_ROOT not defined') |
| 170 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 171 | for btype in btypes: |
| 172 | cfgfile.write('LABEL %s%s\nKERNEL /vmlinuz\n' % (btype[0], label)) |
| 173 | |
| 174 | exargs = d.getVar('SYSLINUX_KERNEL_ARGS', True) |
| 175 | if exargs: |
| 176 | btype[1] += " " + exargs |
| 177 | |
| 178 | append = localdata.getVar('APPEND', True) |
| 179 | initrd = localdata.getVar('INITRD', True) |
| 180 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 181 | append = root + " " + append |
| 182 | cfgfile.write('APPEND ') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 183 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 184 | if initrd: |
| 185 | cfgfile.write('initrd=/initrd ') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 187 | cfgfile.write('LABEL=%s '% (label)) |
| 188 | append = replace_rootfs_uuid(d, append) |
| 189 | cfgfile.write('%s %s\n' % (append, btype[1])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 190 | |
| 191 | cfgfile.close() |
| 192 | } |