blob: 4fcb0c5e720f485fc16b5db2c94caf23e7607b0e [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"
33SYSLINUX_ROOT ?= "${ROOT}"
34SYSLINUX_CFG_VM ?= "${S}/syslinux_vm.cfg"
35SYSLINUX_CFG_LIVE ?= "${S}/syslinux_live.cfg"
36APPEND ?= ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
38# Need UUID utility code.
39inherit fs-uuid
40
41syslinux_populate() {
42 DEST=$1
43 BOOTDIR=$2
44 CFGNAME=$3
45
46 install -d ${DEST}${BOOTDIR}
47
48 # Install the config files
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050049 install -m 0644 ${SYSLINUX_CFG} ${DEST}${BOOTDIR}/${CFGNAME}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050 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
60syslinux_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
67syslinux_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
73syslinux_hddimg_install() {
74 syslinux ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
75}
76
77syslinux_hdddirect_install() {
78 DEST=$1
79 syslinux $DEST
80}
81
82python 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 Williamsd8c66bc2016-06-20 12:57:21 -0500100 cfile = d.getVar('SYSLINUX_CFG', True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500101 if not cfile:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500102 raise bb.build.FuncFailed('Unable to read SYSLINUX_CFG')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103
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 Williamsd8c66bc2016-06-20 12:57:21 -0500124 menu = (d.getVar('AUTO_SYSLINUXMENU', True) == "1")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125
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 Williamsd8c66bc2016-06-20 12:57:21 -0500167 root= d.getVar('SYSLINUX_ROOT', True)
168 if not root:
169 raise bb.build.FuncFailed('SYSLINUX_ROOT not defined')
170
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500171 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 Williamsd8c66bc2016-06-20 12:57:21 -0500181 append = root + " " + append
182 cfgfile.write('APPEND ')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500184 if initrd:
185 cfgfile.write('initrd=/initrd ')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500187 cfgfile.write('LABEL=%s '% (label))
188 append = replace_rootfs_uuid(d, append)
189 cfgfile.write('%s %s\n' % (append, btype[1]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190
191 cfgfile.close()
192}