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 | |
| 23 | SYSLINUXCFG = "${S}/syslinux.cfg" |
| 24 | |
| 25 | ISOLINUXDIR = "/isolinux" |
| 26 | SYSLINUXDIR = "/" |
| 27 | # The kernel has an internal default console, which you can override with |
| 28 | # a console=...some_tty... |
| 29 | SYSLINUX_DEFAULT_CONSOLE ?= "" |
| 30 | SYSLINUX_SERIAL ?= "0 115200" |
| 31 | SYSLINUX_SERIAL_TTY ?= "console=ttyS0,115200" |
| 32 | ISO_BOOTIMG = "isolinux/isolinux.bin" |
| 33 | ISO_BOOTCAT = "isolinux/boot.cat" |
| 34 | MKISOFS_OPTIONS = "-no-emul-boot -boot-load-size 4 -boot-info-table" |
| 35 | APPEND_prepend = " ${SYSLINUX_ROOT} " |
| 36 | |
| 37 | # Need UUID utility code. |
| 38 | inherit fs-uuid |
| 39 | |
| 40 | syslinux_populate() { |
| 41 | DEST=$1 |
| 42 | BOOTDIR=$2 |
| 43 | CFGNAME=$3 |
| 44 | |
| 45 | install -d ${DEST}${BOOTDIR} |
| 46 | |
| 47 | # Install the config files |
| 48 | install -m 0644 ${SYSLINUXCFG} ${DEST}${BOOTDIR}/${CFGNAME} |
| 49 | if [ "${AUTO_SYSLINUXMENU}" = 1 ] ; then |
| 50 | install -m 0644 ${STAGING_DATADIR}/syslinux/vesamenu.c32 ${DEST}${BOOTDIR}/vesamenu.c32 |
| 51 | install -m 0444 ${STAGING_DATADIR}/syslinux/libcom32.c32 ${DEST}${BOOTDIR}/libcom32.c32 |
| 52 | install -m 0444 ${STAGING_DATADIR}/syslinux/libutil.c32 ${DEST}${BOOTDIR}/libutil.c32 |
| 53 | if [ "${SYSLINUX_SPLASH}" != "" ] ; then |
| 54 | install -m 0644 ${SYSLINUX_SPLASH} ${DEST}${BOOTDIR}/splash.lss |
| 55 | fi |
| 56 | fi |
| 57 | } |
| 58 | |
| 59 | syslinux_iso_populate() { |
| 60 | iso_dir=$1 |
| 61 | syslinux_populate $iso_dir ${ISOLINUXDIR} isolinux.cfg |
| 62 | install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin $iso_dir${ISOLINUXDIR} |
| 63 | install -m 0644 ${STAGING_DATADIR}/syslinux/ldlinux.c32 $iso_dir${ISOLINUXDIR} |
| 64 | } |
| 65 | |
| 66 | syslinux_hddimg_populate() { |
| 67 | hdd_dir=$1 |
| 68 | syslinux_populate $hdd_dir ${SYSLINUXDIR} syslinux.cfg |
| 69 | install -m 0444 ${STAGING_DATADIR}/syslinux/ldlinux.sys $hdd_dir${SYSLINUXDIR}/ldlinux.sys |
| 70 | } |
| 71 | |
| 72 | syslinux_hddimg_install() { |
| 73 | syslinux ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg |
| 74 | } |
| 75 | |
| 76 | syslinux_hdddirect_install() { |
| 77 | DEST=$1 |
| 78 | syslinux $DEST |
| 79 | } |
| 80 | |
| 81 | python build_syslinux_cfg () { |
| 82 | import copy |
| 83 | import sys |
| 84 | |
| 85 | workdir = d.getVar('WORKDIR', True) |
| 86 | if not workdir: |
| 87 | bb.error("WORKDIR not defined, unable to package") |
| 88 | return |
| 89 | |
| 90 | labels = d.getVar('LABELS', True) |
| 91 | if not labels: |
| 92 | bb.debug(1, "LABELS not defined, nothing to do") |
| 93 | return |
| 94 | |
| 95 | if labels == []: |
| 96 | bb.debug(1, "No labels, nothing to do") |
| 97 | return |
| 98 | |
| 99 | cfile = d.getVar('SYSLINUXCFG', True) |
| 100 | if not cfile: |
| 101 | raise bb.build.FuncFailed('Unable to read SYSLINUXCFG') |
| 102 | |
| 103 | try: |
| 104 | cfgfile = file(cfile, 'w') |
| 105 | except OSError: |
| 106 | raise bb.build.funcFailed('Unable to open %s' % (cfile)) |
| 107 | |
| 108 | cfgfile.write('# Automatically created by OE\n') |
| 109 | |
| 110 | opts = d.getVar('SYSLINUX_OPTS', True) |
| 111 | |
| 112 | if opts: |
| 113 | for opt in opts.split(';'): |
| 114 | cfgfile.write('%s\n' % opt) |
| 115 | |
| 116 | cfgfile.write('ALLOWOPTIONS 1\n'); |
| 117 | syslinux_default_console = d.getVar('SYSLINUX_DEFAULT_CONSOLE', True) |
| 118 | syslinux_serial_tty = d.getVar('SYSLINUX_SERIAL_TTY', True) |
| 119 | syslinux_serial = d.getVar('SYSLINUX_SERIAL', True) |
| 120 | if syslinux_serial: |
| 121 | cfgfile.write('SERIAL %s\n' % syslinux_serial) |
| 122 | |
| 123 | menu = d.getVar('AUTO_SYSLINUXMENU', True) |
| 124 | |
| 125 | if menu and syslinux_serial: |
| 126 | cfgfile.write('DEFAULT Graphics console %s\n' % (labels.split()[0])) |
| 127 | else: |
| 128 | cfgfile.write('DEFAULT %s\n' % (labels.split()[0])) |
| 129 | |
| 130 | timeout = d.getVar('SYSLINUX_TIMEOUT', True) |
| 131 | |
| 132 | if timeout: |
| 133 | cfgfile.write('TIMEOUT %s\n' % timeout) |
| 134 | else: |
| 135 | cfgfile.write('TIMEOUT 50\n') |
| 136 | |
| 137 | prompt = d.getVar('SYSLINUX_PROMPT', True) |
| 138 | if prompt: |
| 139 | cfgfile.write('PROMPT %s\n' % prompt) |
| 140 | else: |
| 141 | cfgfile.write('PROMPT 1\n') |
| 142 | |
| 143 | if menu: |
| 144 | cfgfile.write('ui vesamenu.c32\n') |
| 145 | cfgfile.write('menu title Select kernel options and boot kernel\n') |
| 146 | cfgfile.write('menu tabmsg Press [Tab] to edit, [Return] to select\n') |
| 147 | splash = d.getVar('SYSLINUX_SPLASH', True) |
| 148 | if splash: |
| 149 | cfgfile.write('menu background splash.lss\n') |
| 150 | |
| 151 | for label in labels.split(): |
| 152 | localdata = bb.data.createCopy(d) |
| 153 | |
| 154 | overrides = localdata.getVar('OVERRIDES', True) |
| 155 | if not overrides: |
| 156 | raise bb.build.FuncFailed('OVERRIDES not defined') |
| 157 | |
| 158 | localdata.setVar('OVERRIDES', label + ':' + overrides) |
| 159 | bb.data.update_data(localdata) |
| 160 | |
| 161 | btypes = [ [ "", syslinux_default_console ] ] |
| 162 | if menu and syslinux_serial: |
| 163 | btypes = [ [ "Graphics console ", syslinux_default_console ], |
| 164 | [ "Serial console ", syslinux_serial_tty ] ] |
| 165 | |
| 166 | for btype in btypes: |
| 167 | cfgfile.write('LABEL %s%s\nKERNEL /vmlinuz\n' % (btype[0], label)) |
| 168 | |
| 169 | exargs = d.getVar('SYSLINUX_KERNEL_ARGS', True) |
| 170 | if exargs: |
| 171 | btype[1] += " " + exargs |
| 172 | |
| 173 | append = localdata.getVar('APPEND', True) |
| 174 | initrd = localdata.getVar('INITRD', True) |
| 175 | |
| 176 | if append: |
| 177 | cfgfile.write('APPEND ') |
| 178 | |
| 179 | if initrd: |
| 180 | cfgfile.write('initrd=/initrd ') |
| 181 | |
| 182 | cfgfile.write('LABEL=%s '% (label)) |
| 183 | append = replace_rootfs_uuid(d, append) |
| 184 | cfgfile.write('%s %s\n' % (append, btype[1])) |
| 185 | else: |
| 186 | cfgfile.write('APPEND %s\n' % btype[1]) |
| 187 | |
| 188 | cfgfile.close() |
| 189 | } |
| 190 | build_syslinux_cfg[vardeps] += "APPEND" |