uboot-extlinux-config.bbclass 6.3 KB

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