| Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # syslinux.bbclass | 
|  | 2 | # Copyright (C) 2004-2006, Advanced Micro Devices, Inc. | 
|  | 3 | # SPDX-License-Identifier: MIT | 
|  | 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 | ISOLINUXDIR ?= "/isolinux" | 
|  | 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" | 
|  | 30 | SYSLINUX_PROMPT ?= "0" | 
|  | 31 | SYSLINUX_TIMEOUT ?= "50" | 
|  | 32 | AUTO_SYSLINUXMENU ?= "1" | 
|  | 33 | SYSLINUX_ALLOWOPTIONS ?= "1" | 
|  | 34 | SYSLINUX_ROOT ?= "${ROOT}" | 
|  | 35 | SYSLINUX_CFG_VM  ?= "${S}/syslinux_vm.cfg" | 
|  | 36 | SYSLINUX_CFG_LIVE ?= "${S}/syslinux_live.cfg" | 
|  | 37 | APPEND ?= "" | 
|  | 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 | 
|  | 50 | install -m 0644 ${SYSLINUX_CFG} ${DEST}${BOOTDIR}/${CFGNAME} | 
|  | 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() { | 
|  | 75 | syslinux ${IMGDEPLOYDIR}/${IMAGE_NAME}.hddimg | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | python build_syslinux_cfg () { | 
|  | 79 | import copy | 
|  | 80 | import sys | 
|  | 81 |  | 
|  | 82 | workdir = d.getVar('WORKDIR') | 
|  | 83 | if not workdir: | 
|  | 84 | bb.error("WORKDIR not defined, unable to package") | 
|  | 85 | return | 
|  | 86 |  | 
|  | 87 | labels = d.getVar('LABELS') | 
|  | 88 | if not labels: | 
|  | 89 | bb.debug(1, "LABELS not defined, nothing to do") | 
|  | 90 | return | 
|  | 91 |  | 
|  | 92 | if labels == []: | 
|  | 93 | bb.debug(1, "No labels, nothing to do") | 
|  | 94 | return | 
|  | 95 |  | 
|  | 96 | cfile = d.getVar('SYSLINUX_CFG') | 
|  | 97 | if not cfile: | 
|  | 98 | bb.fatal('Unable to read SYSLINUX_CFG') | 
|  | 99 |  | 
|  | 100 | try: | 
|  | 101 | cfgfile = open(cfile, 'w') | 
|  | 102 | except OSError: | 
|  | 103 | bb.fatal('Unable to open %s' % cfile) | 
|  | 104 |  | 
|  | 105 | cfgfile.write('# Automatically created by OE\n') | 
|  | 106 |  | 
|  | 107 | opts = d.getVar('SYSLINUX_OPTS') | 
|  | 108 |  | 
|  | 109 | if opts: | 
|  | 110 | for opt in opts.split(';'): | 
|  | 111 | cfgfile.write('%s\n' % opt) | 
|  | 112 |  | 
|  | 113 | allowoptions = d.getVar('SYSLINUX_ALLOWOPTIONS') | 
|  | 114 | if allowoptions: | 
|  | 115 | cfgfile.write('ALLOWOPTIONS %s\n' % allowoptions) | 
|  | 116 | else: | 
|  | 117 | cfgfile.write('ALLOWOPTIONS 1\n') | 
|  | 118 |  | 
|  | 119 | syslinux_default_console = d.getVar('SYSLINUX_DEFAULT_CONSOLE') | 
|  | 120 | syslinux_serial_tty = d.getVar('SYSLINUX_SERIAL_TTY') | 
|  | 121 | syslinux_serial = d.getVar('SYSLINUX_SERIAL') | 
|  | 122 | if syslinux_serial: | 
|  | 123 | cfgfile.write('SERIAL %s\n' % syslinux_serial) | 
|  | 124 |  | 
|  | 125 | menu = (d.getVar('AUTO_SYSLINUXMENU') == "1") | 
|  | 126 |  | 
|  | 127 | if menu and syslinux_serial: | 
|  | 128 | cfgfile.write('DEFAULT Graphics console %s\n' % (labels.split()[0])) | 
|  | 129 | else: | 
|  | 130 | cfgfile.write('DEFAULT %s\n' % (labels.split()[0])) | 
|  | 131 |  | 
|  | 132 | timeout = d.getVar('SYSLINUX_TIMEOUT') | 
|  | 133 |  | 
|  | 134 | if timeout: | 
|  | 135 | cfgfile.write('TIMEOUT %s\n' % timeout) | 
|  | 136 | else: | 
|  | 137 | cfgfile.write('TIMEOUT 50\n') | 
|  | 138 |  | 
|  | 139 | prompt = d.getVar('SYSLINUX_PROMPT') | 
|  | 140 | if prompt: | 
|  | 141 | cfgfile.write('PROMPT %s\n' % prompt) | 
|  | 142 | else: | 
|  | 143 | cfgfile.write('PROMPT 1\n') | 
|  | 144 |  | 
|  | 145 | if menu: | 
|  | 146 | cfgfile.write('ui vesamenu.c32\n') | 
|  | 147 | cfgfile.write('menu title Select kernel options and boot kernel\n') | 
|  | 148 | cfgfile.write('menu tabmsg Press [Tab] to edit, [Return] to select\n') | 
|  | 149 | splash = d.getVar('SYSLINUX_SPLASH') | 
|  | 150 | if splash: | 
|  | 151 | cfgfile.write('menu background splash.lss\n') | 
|  | 152 |  | 
|  | 153 | for label in labels.split(): | 
|  | 154 | localdata = bb.data.createCopy(d) | 
|  | 155 |  | 
|  | 156 | overrides = localdata.getVar('OVERRIDES') | 
|  | 157 | if not overrides: | 
|  | 158 | bb.fatal('OVERRIDES not defined') | 
|  | 159 |  | 
|  | 160 | localdata.setVar('OVERRIDES', label + ':' + overrides) | 
|  | 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 |  | 
|  | 167 | root= d.getVar('SYSLINUX_ROOT') | 
|  | 168 | if not root: | 
|  | 169 | bb.fatal('SYSLINUX_ROOT not defined') | 
|  | 170 |  | 
|  | 171 | kernel = localdata.getVar('KERNEL_IMAGETYPE') | 
|  | 172 | for btype in btypes: | 
|  | 173 | cfgfile.write('LABEL %s%s\nKERNEL /%s\n' % (btype[0], label, kernel)) | 
|  | 174 |  | 
|  | 175 | exargs = d.getVar('SYSLINUX_KERNEL_ARGS') | 
|  | 176 | if exargs: | 
|  | 177 | btype[1] += " " + exargs | 
|  | 178 |  | 
|  | 179 | append = localdata.getVar('APPEND') | 
|  | 180 | initrd = localdata.getVar('INITRD') | 
|  | 181 |  | 
|  | 182 | append = root + " " + append | 
|  | 183 | cfgfile.write('APPEND ') | 
|  | 184 |  | 
|  | 185 | if initrd: | 
|  | 186 | cfgfile.write('initrd=/initrd ') | 
|  | 187 |  | 
|  | 188 | cfgfile.write('LABEL=%s '% (label)) | 
|  | 189 | append = replace_rootfs_uuid(d, append) | 
|  | 190 | cfgfile.write('%s %s\n' % (append, btype[1])) | 
|  | 191 |  | 
|  | 192 | cfgfile.close() | 
|  | 193 | } | 
|  | 194 | build_syslinux_cfg[dirs] = "${S}" |