How to find out the kernel version currently build by Yocto?

Summary

To determine the kernel version built by Yocto without deploying to the target, the KERNEL_VERSION variable is key. However, it is not directly accessible via bitbake -e because it is set during the kernel configuration phase, not the image configuration phase.

Root Cause

  • The KERNEL_VERSION variable is defined in the kernel recipe (linux-yocto.inc) and is only available after the kernel has been configured.
  • Running bitbake -e before or during the kernel build phase will not show this variable.

Why This Happens in Real Systems

  • Yocto’s deferred variable assignment ensures variables are set only when needed, optimizing build performance.
  • Kernel-specific variables like KERNEL_VERSION are resolved during the kernel’s do_configure task, not during image configuration.

Real-World Impact

  • Delayed access to kernel version: Engineers cannot retrieve KERNEL_VERSION until the kernel is fully configured.
  • Misinterpretation of documentation: The reference manual’s note about “contexts prior to configuration” applies to the kernel, not the image.

Example or Code (if necessary and relevant)

# Correct way to access KERNEL_VERSION after kernel configuration
bitbake virtual/kernel -c menuconfig  # Trigger kernel configuration
bitbake -e virtual/kernel | grep ^KERNEL_VERSION

How Senior Engineers Fix It

  • Trigger kernel configuration explicitly using bitbake virtual/kernel -c menuconfig before querying KERNEL_VERSION.
  • Use bitbake’s task-specific environment (-c) to access variables at the appropriate build stage.

Why Juniors Miss It

  • Overlooking task dependencies: Juniors assume bitbake -e provides all variables immediately, ignoring Yocto’s staged build process.
  • Misinterpreting documentation: The phrase “contexts prior to configuration” refers to the kernel’s configuration, not the image’s.

Leave a Comment