blob: 031dacbf7d3652c73cc3fe11c724d200cc5ef99f [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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
20do_bootimg[depends] += "${MLPREFIX}syslinux:do_populate_sysroot \
21 syslinux-native:do_populate_sysroot"
22
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050023ISOLINUXDIR ?= "/isolinux"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024SYSLINUXDIR = "/"
25# The kernel has an internal default console, which you can override with
26# a console=...some_tty...
27SYSLINUX_DEFAULT_CONSOLE ?= ""
28SYSLINUX_SERIAL ?= "0 115200"
29SYSLINUX_SERIAL_TTY ?= "console=ttyS0,115200"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050030SYSLINUX_PROMPT ?= "0"
31SYSLINUX_TIMEOUT ?= "50"
32AUTO_SYSLINUXMENU ?= "1"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033SYSLINUX_ALLOWOPTIONS ?= "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050034SYSLINUX_ROOT ?= "${ROOT}"
35SYSLINUX_CFG_VM ?= "${S}/syslinux_vm.cfg"
36SYSLINUX_CFG_LIVE ?= "${S}/syslinux_live.cfg"
37APPEND ?= ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038
39# Need UUID utility code.
40inherit fs-uuid
41
42syslinux_populate() {
43 DEST=$1
44 BOOTDIR=$2
45 CFGNAME=$3
46
47 install -d ${DEST}${BOOTDIR}
48
49 # Install the config files
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050 install -m 0644 ${SYSLINUX_CFG} ${DEST}${BOOTDIR}/${CFGNAME}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 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
61syslinux_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
68syslinux_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
74syslinux_hddimg_install() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -060075 syslinux ${IMGDEPLOYDIR}/${IMAGE_NAME}.hddimg
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076}
77
78syslinux_hdddirect_install() {
79 DEST=$1
80 syslinux $DEST
81}
82
83python build_syslinux_cfg () {
84 import copy
85 import sys
86
Brad Bishop6e60e8b2018-02-01 10:27:11 -050087 workdir = d.getVar('WORKDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088 if not workdir:
89 bb.error("WORKDIR not defined, unable to package")
90 return
91
Brad Bishop6e60e8b2018-02-01 10:27:11 -050092 labels = d.getVar('LABELS')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050093 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 Bishop6e60e8b2018-02-01 10:27:11 -0500101 cfile = d.getVar('SYSLINUX_CFG')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102 if not cfile:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600103 bb.fatal('Unable to read SYSLINUX_CFG')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104
105 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600106 cfgfile = open(cfile, 'w')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 except OSError:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108 bb.fatal('Unable to open %s' % cfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109
110 cfgfile.write('# Automatically created by OE\n')
111
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500112 opts = d.getVar('SYSLINUX_OPTS')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113
114 if opts:
115 for opt in opts.split(';'):
116 cfgfile.write('%s\n' % opt)
117
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500118 allowoptions = d.getVar('SYSLINUX_ALLOWOPTIONS')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600119 if allowoptions:
120 cfgfile.write('ALLOWOPTIONS %s\n' % allowoptions)
121 else:
122 cfgfile.write('ALLOWOPTIONS 1\n')
123
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124 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 Williamsc124f4f2015-09-15 14:41:29 -0500127 if syslinux_serial:
128 cfgfile.write('SERIAL %s\n' % syslinux_serial)
129
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500130 menu = (d.getVar('AUTO_SYSLINUXMENU') == "1")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131
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 Bishop6e60e8b2018-02-01 10:27:11 -0500137 timeout = d.getVar('SYSLINUX_TIMEOUT')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138
139 if timeout:
140 cfgfile.write('TIMEOUT %s\n' % timeout)
141 else:
142 cfgfile.write('TIMEOUT 50\n')
143
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500144 prompt = d.getVar('SYSLINUX_PROMPT')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500145 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 Bishop6e60e8b2018-02-01 10:27:11 -0500154 splash = d.getVar('SYSLINUX_SPLASH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155 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 Bishop6e60e8b2018-02-01 10:27:11 -0500161 overrides = localdata.getVar('OVERRIDES')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162 if not overrides:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600163 bb.fatal('OVERRIDES not defined')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164
165 localdata.setVar('OVERRIDES', label + ':' + overrides)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166
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 Bishop6e60e8b2018-02-01 10:27:11 -0500172 root= d.getVar('SYSLINUX_ROOT')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500173 if not root:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600174 bb.fatal('SYSLINUX_ROOT not defined')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500175
Brad Bishop316dfdd2018-06-25 12:45:53 -0400176 kernel = localdata.getVar('KERNEL_IMAGETYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500177 for btype in btypes:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400178 cfgfile.write('LABEL %s%s\nKERNEL /%s\n' % (btype[0], label, kernel))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500180 exargs = d.getVar('SYSLINUX_KERNEL_ARGS')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181 if exargs:
182 btype[1] += " " + exargs
183
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500184 append = localdata.getVar('APPEND')
185 initrd = localdata.getVar('INITRD')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500187 append = root + " " + append
188 cfgfile.write('APPEND ')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500190 if initrd:
191 cfgfile.write('initrd=/initrd ')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500192
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500193 cfgfile.write('LABEL=%s '% (label))
194 append = replace_rootfs_uuid(d, append)
195 cfgfile.write('%s %s\n' % (append, btype[1]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196
197 cfgfile.close()
198}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600199build_syslinux_cfg[dirs] = "${S}"