syslinux.bbclass 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. # Provide syslinux specific functions for building bootable images.
  5. # External variables
  6. # ${INITRD} - indicates a list of filesystem images to concatenate and use as an initrd (optional)
  7. # ${ROOTFS} - indicates a filesystem image to include as the root filesystem (optional)
  8. # ${AUTO_SYSLINUXMENU} - set this to 1 to enable creating an automatic menu
  9. # ${LABELS} - a list of targets for the automatic config
  10. # ${APPEND} - an override list of append strings for each label
  11. # ${SYSLINUX_OPTS} - additional options to add to the syslinux file ';' delimited
  12. # ${SYSLINUX_SPLASH} - A background for the vga boot menu if using the boot menu
  13. # ${SYSLINUX_DEFAULT_CONSOLE} - set to "console=ttyX" to change kernel boot default console
  14. # ${SYSLINUX_SERIAL} - Set an alternate serial port or turn off serial with empty string
  15. # ${SYSLINUX_SERIAL_TTY} - Set alternate console=tty... kernel boot argument
  16. # ${SYSLINUX_KERNEL_ARGS} - Add additional kernel arguments
  17. do_bootimg[depends] += "${MLPREFIX}syslinux:do_populate_sysroot \
  18. syslinux-native:do_populate_sysroot"
  19. ISOLINUXDIR ?= "/isolinux"
  20. SYSLINUXDIR = "/"
  21. # The kernel has an internal default console, which you can override with
  22. # a console=...some_tty...
  23. SYSLINUX_DEFAULT_CONSOLE ?= ""
  24. SYSLINUX_SERIAL ?= "0 115200"
  25. SYSLINUX_SERIAL_TTY ?= "console=ttyS0,115200"
  26. SYSLINUX_PROMPT ?= "0"
  27. SYSLINUX_TIMEOUT ?= "50"
  28. AUTO_SYSLINUXMENU ?= "1"
  29. SYSLINUX_ALLOWOPTIONS ?= "1"
  30. SYSLINUX_ROOT ?= "${ROOT}"
  31. SYSLINUX_CFG_VM ?= "${S}/syslinux_vm.cfg"
  32. SYSLINUX_CFG_LIVE ?= "${S}/syslinux_live.cfg"
  33. APPEND ?= ""
  34. # Need UUID utility code.
  35. inherit fs-uuid
  36. syslinux_populate() {
  37. DEST=$1
  38. BOOTDIR=$2
  39. CFGNAME=$3
  40. install -d ${DEST}${BOOTDIR}
  41. # Install the config files
  42. install -m 0644 ${SYSLINUX_CFG} ${DEST}${BOOTDIR}/${CFGNAME}
  43. if [ "${AUTO_SYSLINUXMENU}" = 1 ] ; then
  44. install -m 0644 ${STAGING_DATADIR}/syslinux/vesamenu.c32 ${DEST}${BOOTDIR}/vesamenu.c32
  45. install -m 0444 ${STAGING_DATADIR}/syslinux/libcom32.c32 ${DEST}${BOOTDIR}/libcom32.c32
  46. install -m 0444 ${STAGING_DATADIR}/syslinux/libutil.c32 ${DEST}${BOOTDIR}/libutil.c32
  47. if [ "${SYSLINUX_SPLASH}" != "" ] ; then
  48. install -m 0644 ${SYSLINUX_SPLASH} ${DEST}${BOOTDIR}/splash.lss
  49. fi
  50. fi
  51. }
  52. syslinux_iso_populate() {
  53. iso_dir=$1
  54. syslinux_populate $iso_dir ${ISOLINUXDIR} isolinux.cfg
  55. install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin $iso_dir${ISOLINUXDIR}
  56. install -m 0644 ${STAGING_DATADIR}/syslinux/ldlinux.c32 $iso_dir${ISOLINUXDIR}
  57. }
  58. syslinux_hddimg_populate() {
  59. hdd_dir=$1
  60. syslinux_populate $hdd_dir ${SYSLINUXDIR} syslinux.cfg
  61. install -m 0444 ${STAGING_DATADIR}/syslinux/ldlinux.sys $hdd_dir${SYSLINUXDIR}/ldlinux.sys
  62. }
  63. syslinux_hddimg_install() {
  64. syslinux ${IMGDEPLOYDIR}/${IMAGE_NAME}.hddimg
  65. }
  66. python build_syslinux_cfg () {
  67. import copy
  68. import sys
  69. workdir = d.getVar('WORKDIR')
  70. if not workdir:
  71. bb.error("WORKDIR not defined, unable to package")
  72. return
  73. labels = d.getVar('LABELS')
  74. if not labels:
  75. bb.debug(1, "LABELS not defined, nothing to do")
  76. return
  77. if labels == []:
  78. bb.debug(1, "No labels, nothing to do")
  79. return
  80. cfile = d.getVar('SYSLINUX_CFG')
  81. if not cfile:
  82. bb.fatal('Unable to read SYSLINUX_CFG')
  83. try:
  84. cfgfile = open(cfile, 'w')
  85. except OSError:
  86. bb.fatal('Unable to open %s' % cfile)
  87. cfgfile.write('# Automatically created by OE\n')
  88. opts = d.getVar('SYSLINUX_OPTS')
  89. if opts:
  90. for opt in opts.split(';'):
  91. cfgfile.write('%s\n' % opt)
  92. allowoptions = d.getVar('SYSLINUX_ALLOWOPTIONS')
  93. if allowoptions:
  94. cfgfile.write('ALLOWOPTIONS %s\n' % allowoptions)
  95. else:
  96. cfgfile.write('ALLOWOPTIONS 1\n')
  97. syslinux_default_console = d.getVar('SYSLINUX_DEFAULT_CONSOLE')
  98. syslinux_serial_tty = d.getVar('SYSLINUX_SERIAL_TTY')
  99. syslinux_serial = d.getVar('SYSLINUX_SERIAL')
  100. if syslinux_serial:
  101. cfgfile.write('SERIAL %s\n' % syslinux_serial)
  102. menu = (d.getVar('AUTO_SYSLINUXMENU') == "1")
  103. if menu and syslinux_serial:
  104. cfgfile.write('DEFAULT Graphics console %s\n' % (labels.split()[0]))
  105. else:
  106. cfgfile.write('DEFAULT %s\n' % (labels.split()[0]))
  107. timeout = d.getVar('SYSLINUX_TIMEOUT')
  108. if timeout:
  109. cfgfile.write('TIMEOUT %s\n' % timeout)
  110. else:
  111. cfgfile.write('TIMEOUT 50\n')
  112. prompt = d.getVar('SYSLINUX_PROMPT')
  113. if prompt:
  114. cfgfile.write('PROMPT %s\n' % prompt)
  115. else:
  116. cfgfile.write('PROMPT 1\n')
  117. if menu:
  118. cfgfile.write('ui vesamenu.c32\n')
  119. cfgfile.write('menu title Select kernel options and boot kernel\n')
  120. cfgfile.write('menu tabmsg Press [Tab] to edit, [Return] to select\n')
  121. splash = d.getVar('SYSLINUX_SPLASH')
  122. if splash:
  123. cfgfile.write('menu background splash.lss\n')
  124. for label in labels.split():
  125. localdata = bb.data.createCopy(d)
  126. overrides = localdata.getVar('OVERRIDES')
  127. if not overrides:
  128. bb.fatal('OVERRIDES not defined')
  129. localdata.setVar('OVERRIDES', label + ':' + overrides)
  130. btypes = [ [ "", syslinux_default_console ] ]
  131. if menu and syslinux_serial:
  132. btypes = [ [ "Graphics console ", syslinux_default_console ],
  133. [ "Serial console ", syslinux_serial_tty ] ]
  134. root= d.getVar('SYSLINUX_ROOT')
  135. if not root:
  136. bb.fatal('SYSLINUX_ROOT not defined')
  137. kernel = localdata.getVar('KERNEL_IMAGETYPE')
  138. for btype in btypes:
  139. cfgfile.write('LABEL %s%s\nKERNEL /%s\n' % (btype[0], label, kernel))
  140. exargs = d.getVar('SYSLINUX_KERNEL_ARGS')
  141. if exargs:
  142. btype[1] += " " + exargs
  143. append = localdata.getVar('APPEND')
  144. initrd = localdata.getVar('INITRD')
  145. append = root + " " + append
  146. cfgfile.write('APPEND ')
  147. if initrd:
  148. cfgfile.write('initrd=/initrd ')
  149. cfgfile.write('LABEL=%s '% (label))
  150. append = replace_rootfs_uuid(d, append)
  151. cfgfile.write('%s %s\n' % (append, btype[1]))
  152. cfgfile.close()
  153. }
  154. build_syslinux_cfg[dirs] = "${S}"