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" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 33 | SYSLINUX_ALLOWOPTIONS ?= "1" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 34 | SYSLINUX_ROOT ?= "${ROOT}" |
| 35 | SYSLINUX_CFG_VM ?= "${S}/syslinux_vm.cfg" |
| 36 | SYSLINUX_CFG_LIVE ?= "${S}/syslinux_live.cfg" |
| 37 | APPEND ?= "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | |
| 39 | # Need UUID utility code. |
| 40 | inherit fs-uuid |
| 41 | |
| 42 | syslinux_populate() { |
| 43 | DEST=$1 |
| 44 | BOOTDIR=$2 |
| 45 | CFGNAME=$3 |
| 46 | |
| 47 | install -d ${DEST}${BOOTDIR} |
| 48 | |
| 49 | # Install the config files |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 50 | install -m 0644 ${SYSLINUX_CFG} ${DEST}${BOOTDIR}/${CFGNAME} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | if [ "${AUTO_SYSLINUXMENU}" = 1 ] ; then |
| 52 | install -m 0644 ${STAGING_DATADIR}/syslinux/vesamenu.c32 ${DEST}${BOOTDIR}/vesamenu.c32 |
| 53 | install -m 0444 ${STAGING_DATADIR}/syslinux/libcom32.c32 ${DEST}${BOOTDIR}/libcom32.c32 |
| 54 | install -m 0444 ${STAGING_DATADIR}/syslinux/libutil.c32 ${DEST}${BOOTDIR}/libutil.c32 |
| 55 | if [ "${SYSLINUX_SPLASH}" != "" ] ; then |
| 56 | install -m 0644 ${SYSLINUX_SPLASH} ${DEST}${BOOTDIR}/splash.lss |
| 57 | fi |
| 58 | fi |
| 59 | } |
| 60 | |
| 61 | syslinux_iso_populate() { |
| 62 | iso_dir=$1 |
| 63 | syslinux_populate $iso_dir ${ISOLINUXDIR} isolinux.cfg |
| 64 | install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin $iso_dir${ISOLINUXDIR} |
| 65 | install -m 0644 ${STAGING_DATADIR}/syslinux/ldlinux.c32 $iso_dir${ISOLINUXDIR} |
| 66 | } |
| 67 | |
| 68 | syslinux_hddimg_populate() { |
| 69 | hdd_dir=$1 |
| 70 | syslinux_populate $hdd_dir ${SYSLINUXDIR} syslinux.cfg |
| 71 | install -m 0444 ${STAGING_DATADIR}/syslinux/ldlinux.sys $hdd_dir${SYSLINUXDIR}/ldlinux.sys |
| 72 | } |
| 73 | |
| 74 | syslinux_hddimg_install() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 75 | syslinux ${IMGDEPLOYDIR}/${IMAGE_NAME}.hddimg |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | syslinux_hdddirect_install() { |
| 79 | DEST=$1 |
| 80 | syslinux $DEST |
| 81 | } |
| 82 | |
| 83 | python build_syslinux_cfg () { |
| 84 | import copy |
| 85 | import sys |
| 86 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 87 | workdir = d.getVar('WORKDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | if not workdir: |
| 89 | bb.error("WORKDIR not defined, unable to package") |
| 90 | return |
| 91 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 92 | labels = d.getVar('LABELS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 93 | if not labels: |
| 94 | bb.debug(1, "LABELS not defined, nothing to do") |
| 95 | return |
| 96 | |
| 97 | if labels == []: |
| 98 | bb.debug(1, "No labels, nothing to do") |
| 99 | return |
| 100 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 101 | cfile = d.getVar('SYSLINUX_CFG') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | if not cfile: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 103 | bb.fatal('Unable to read SYSLINUX_CFG') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | |
| 105 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 106 | cfgfile = open(cfile, 'w') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 107 | except OSError: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 108 | bb.fatal('Unable to open %s' % cfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | |
| 110 | cfgfile.write('# Automatically created by OE\n') |
| 111 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 112 | opts = d.getVar('SYSLINUX_OPTS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | |
| 114 | if opts: |
| 115 | for opt in opts.split(';'): |
| 116 | cfgfile.write('%s\n' % opt) |
| 117 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | allowoptions = d.getVar('SYSLINUX_ALLOWOPTIONS') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 119 | if allowoptions: |
| 120 | cfgfile.write('ALLOWOPTIONS %s\n' % allowoptions) |
| 121 | else: |
| 122 | cfgfile.write('ALLOWOPTIONS 1\n') |
| 123 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 124 | syslinux_default_console = d.getVar('SYSLINUX_DEFAULT_CONSOLE') |
| 125 | syslinux_serial_tty = d.getVar('SYSLINUX_SERIAL_TTY') |
| 126 | syslinux_serial = d.getVar('SYSLINUX_SERIAL') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | if syslinux_serial: |
| 128 | cfgfile.write('SERIAL %s\n' % syslinux_serial) |
| 129 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 130 | menu = (d.getVar('AUTO_SYSLINUXMENU') == "1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | |
| 132 | if menu and syslinux_serial: |
| 133 | cfgfile.write('DEFAULT Graphics console %s\n' % (labels.split()[0])) |
| 134 | else: |
| 135 | cfgfile.write('DEFAULT %s\n' % (labels.split()[0])) |
| 136 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 137 | timeout = d.getVar('SYSLINUX_TIMEOUT') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | |
| 139 | if timeout: |
| 140 | cfgfile.write('TIMEOUT %s\n' % timeout) |
| 141 | else: |
| 142 | cfgfile.write('TIMEOUT 50\n') |
| 143 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 144 | prompt = d.getVar('SYSLINUX_PROMPT') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 | if prompt: |
| 146 | cfgfile.write('PROMPT %s\n' % prompt) |
| 147 | else: |
| 148 | cfgfile.write('PROMPT 1\n') |
| 149 | |
| 150 | if menu: |
| 151 | cfgfile.write('ui vesamenu.c32\n') |
| 152 | cfgfile.write('menu title Select kernel options and boot kernel\n') |
| 153 | cfgfile.write('menu tabmsg Press [Tab] to edit, [Return] to select\n') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 154 | splash = d.getVar('SYSLINUX_SPLASH') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | if splash: |
| 156 | cfgfile.write('menu background splash.lss\n') |
| 157 | |
| 158 | for label in labels.split(): |
| 159 | localdata = bb.data.createCopy(d) |
| 160 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 161 | overrides = localdata.getVar('OVERRIDES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 162 | if not overrides: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 163 | bb.fatal('OVERRIDES not defined') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | |
| 165 | localdata.setVar('OVERRIDES', label + ':' + overrides) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 166 | |
| 167 | btypes = [ [ "", syslinux_default_console ] ] |
| 168 | if menu and syslinux_serial: |
| 169 | btypes = [ [ "Graphics console ", syslinux_default_console ], |
| 170 | [ "Serial console ", syslinux_serial_tty ] ] |
| 171 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 172 | root= d.getVar('SYSLINUX_ROOT') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 173 | if not root: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 174 | bb.fatal('SYSLINUX_ROOT not defined') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 175 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 176 | kernel = localdata.getVar('KERNEL_IMAGETYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 177 | for btype in btypes: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 178 | cfgfile.write('LABEL %s%s\nKERNEL /%s\n' % (btype[0], label, kernel)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 180 | exargs = d.getVar('SYSLINUX_KERNEL_ARGS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 181 | if exargs: |
| 182 | btype[1] += " " + exargs |
| 183 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 184 | append = localdata.getVar('APPEND') |
| 185 | initrd = localdata.getVar('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 | append = root + " " + append |
| 188 | cfgfile.write('APPEND ') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 189 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 190 | if initrd: |
| 191 | cfgfile.write('initrd=/initrd ') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 192 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 193 | cfgfile.write('LABEL=%s '% (label)) |
| 194 | append = replace_rootfs_uuid(d, append) |
| 195 | cfgfile.write('%s %s\n' % (append, btype[1])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | |
| 197 | cfgfile.close() |
| 198 | } |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 199 | build_syslinux_cfg[dirs] = "${S}" |