uboot-extlinux-config.bbclass 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # uboot-extlinux-config.bbclass
  2. #
  3. # This class allow the extlinux.conf generation for U-Boot use. The
  4. # U-Boot support for it is given to allow the Generic Distribution
  5. # Configuration specification use by OpenEmbedded-based products.
  6. #
  7. # External variables:
  8. #
  9. # UBOOT_EXTLINUX - Set to "1" to enable generation
  10. # of extlinux.conf using this class.
  11. # UBOOT_EXTLINUX_CONSOLE - Set to "console=ttyX" to change kernel boot
  12. # default console.
  13. # UBOOT_EXTLINUX_LABELS - A list of targets for the automatic config.
  14. # UBOOT_EXTLINUX_KERNEL_ARGS - Add additional kernel arguments.
  15. # UBOOT_EXTLINUX_KERNEL_IMAGE - Kernel image name.
  16. # UBOOT_EXTLINUX_FDTDIR - Device tree directory.
  17. # UBOOT_EXTLINUX_FDT - Device tree file.
  18. # UBOOT_EXTLINUX_FDTOVERLAYS - Device tree overlay files. Space-separated list.
  19. # UBOOT_EXTLINUX_INITRD - Indicates a list of filesystem images to
  20. # concatenate and use as an initrd (optional).
  21. # UBOOT_EXTLINUX_MENU_DESCRIPTION - Name to use as description.
  22. # UBOOT_EXTLINUX_ROOT - Root kernel cmdline.
  23. # UBOOT_EXTLINUX_TIMEOUT - Timeout before DEFAULT selection is made.
  24. # Measured in 1/10 of a second.
  25. # UBOOT_EXTLINUX_DEFAULT_LABEL - Target to be selected by default after
  26. # the timeout period.
  27. # UBOOT_EXTLINUX_MENU_TITLE - Menu title. If empty, MENU TITLE entry
  28. # will not be added to the output file.
  29. # UBOOT_EXTLINUX_CONFIG - Output file.
  30. #
  31. # If there's only one label system will boot automatically and menu won't be
  32. # created. If you want to use more than one labels, e.g linux and alternate,
  33. # use overrides to set menu description, console and others variables.
  34. #
  35. # Ex:
  36. #
  37. # UBOOT_EXTLINUX_LABELS ??= "default fallback"
  38. #
  39. # UBOOT_EXTLINUX_DEFAULT_LABEL ??= "Linux Default"
  40. # UBOOT_EXTLINUX_TIMEOUT ??= "30"
  41. #
  42. # UBOOT_EXTLINUX_KERNEL_IMAGE:default ??= "../zImage"
  43. # UBOOT_EXTLINUX_MENU_DESCRIPTION:default ??= "Linux Default"
  44. #
  45. # UBOOT_EXTLINUX_KERNEL_IMAGE:fallback ??= "../zImage-fallback"
  46. # UBOOT_EXTLINUX_MENU_DESCRIPTION:fallback ??= "Linux Fallback"
  47. #
  48. # Results:
  49. #
  50. # menu title Select the boot mode
  51. # TIMEOUT 30
  52. # DEFAULT Linux Default
  53. # LABEL Linux Default
  54. # KERNEL ../zImage
  55. # FDTDIR ../
  56. # APPEND root=/dev/mmcblk2p2 rootwait rw console=${console}
  57. # LABEL Linux Fallback
  58. # KERNEL ../zImage-fallback
  59. # FDTDIR ../
  60. # APPEND root=/dev/mmcblk2p2 rootwait rw console=${console}
  61. #
  62. # Copyright (C) 2016, O.S. Systems Software LTDA. All Rights Reserved
  63. # SPDX-License-Identifier: MIT
  64. #
  65. # The kernel has an internal default console, which you can override with
  66. # a console=...some_tty...
  67. UBOOT_EXTLINUX_CONSOLE ??= "console=${console},${baudrate}"
  68. UBOOT_EXTLINUX_LABELS ??= "linux"
  69. UBOOT_EXTLINUX_FDT ??= ""
  70. UBOOT_EXTLINUX_FDTOVERLAYS ??= ""
  71. UBOOT_EXTLINUX_FDTDIR ??= "../"
  72. UBOOT_EXTLINUX_KERNEL_IMAGE ??= "../${KERNEL_IMAGETYPE}"
  73. UBOOT_EXTLINUX_KERNEL_ARGS ??= "rootwait rw"
  74. UBOOT_EXTLINUX_MENU_DESCRIPTION:linux ??= "${DISTRO_NAME}"
  75. UBOOT_EXTLINUX_MENU_TITLE ??= "Select the boot mode"
  76. UBOOT_EXTLINUX_CONFIG = "${B}/extlinux.conf"
  77. python do_create_extlinux_config() {
  78. if d.getVar("UBOOT_EXTLINUX") != "1":
  79. return
  80. if not d.getVar('WORKDIR'):
  81. bb.error("WORKDIR not defined, unable to package")
  82. labels = d.getVar('UBOOT_EXTLINUX_LABELS')
  83. if not labels:
  84. bb.fatal("UBOOT_EXTLINUX_LABELS not defined, nothing to do")
  85. if not labels.strip():
  86. bb.fatal("No labels, nothing to do")
  87. cfile = d.getVar('UBOOT_EXTLINUX_CONFIG')
  88. if not cfile:
  89. bb.fatal('Unable to read UBOOT_EXTLINUX_CONFIG')
  90. localdata = bb.data.createCopy(d)
  91. try:
  92. with open(cfile, 'w') as cfgfile:
  93. cfgfile.write('# Generic Distro Configuration file generated by OpenEmbedded\n')
  94. menu_title = localdata.getVar('UBOOT_EXTLINUX_MENU_TITLE')
  95. if len(labels.split()) > 1 and menu_title:
  96. cfgfile.write('MENU TITLE %s\n' % (menu_title))
  97. timeout = localdata.getVar('UBOOT_EXTLINUX_TIMEOUT')
  98. if timeout:
  99. cfgfile.write('TIMEOUT %s\n' % (timeout))
  100. if len(labels.split()) > 1:
  101. default = localdata.getVar('UBOOT_EXTLINUX_DEFAULT_LABEL')
  102. if default:
  103. cfgfile.write('DEFAULT %s\n' % (default))
  104. # Need to deconflict the labels with existing overrides
  105. label_overrides = labels.split()
  106. default_overrides = localdata.getVar('OVERRIDES').split(':')
  107. # We're keeping all the existing overrides that aren't used as a label
  108. # an override for that label will be added back in while we're processing that label
  109. keep_overrides = list(filter(lambda x: x not in label_overrides, default_overrides))
  110. for label in labels.split():
  111. localdata.setVar('OVERRIDES', ':'.join(keep_overrides + [label]))
  112. extlinux_console = localdata.getVar('UBOOT_EXTLINUX_CONSOLE')
  113. menu_description = localdata.getVar('UBOOT_EXTLINUX_MENU_DESCRIPTION')
  114. if not menu_description:
  115. menu_description = label
  116. root = localdata.getVar('UBOOT_EXTLINUX_ROOT')
  117. if not root:
  118. bb.fatal('UBOOT_EXTLINUX_ROOT not defined')
  119. kernel_image = localdata.getVar('UBOOT_EXTLINUX_KERNEL_IMAGE')
  120. fdtdir = localdata.getVar('UBOOT_EXTLINUX_FDTDIR')
  121. fdt = localdata.getVar('UBOOT_EXTLINUX_FDT')
  122. fdtoverlays = localdata.getVar('UBOOT_EXTLINUX_FDTOVERLAYS')
  123. cfgfile.write('LABEL %s\n\tKERNEL %s\n' % (menu_description, kernel_image))
  124. if fdt:
  125. cfgfile.write('\tFDT %s\n' % (fdt))
  126. elif fdtdir:
  127. cfgfile.write('\tFDTDIR %s\n' % (fdtdir))
  128. if fdtoverlays:
  129. cfgfile.write('\tFDTOVERLAYS %s\n' % (' '.join(fdtoverlays.split())))
  130. kernel_args = localdata.getVar('UBOOT_EXTLINUX_KERNEL_ARGS')
  131. initrd = localdata.getVar('UBOOT_EXTLINUX_INITRD')
  132. if initrd:
  133. cfgfile.write('\tINITRD %s\n'% initrd)
  134. kernel_args = root + " " + kernel_args
  135. cfgfile.write('\tAPPEND %s %s\n' % (kernel_args, extlinux_console))
  136. except OSError:
  137. bb.fatal('Unable to open %s' % (cfile))
  138. }
  139. UBOOT_EXTLINUX_VARS = "CONSOLE MENU_DESCRIPTION ROOT KERNEL_IMAGE FDTDIR FDT FDTOVERLAYS KERNEL_ARGS INITRD"
  140. do_create_extlinux_config[vardeps] += "${@' '.join(['UBOOT_EXTLINUX_%s:%s' % (v, l) for v in d.getVar('UBOOT_EXTLINUX_VARS').split() for l in d.getVar('UBOOT_EXTLINUX_LABELS').split()])}"
  141. do_create_extlinux_config[vardepsexclude] += "OVERRIDES"
  142. addtask create_extlinux_config before do_install do_deploy after do_compile