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_VERSIONvariable is defined in the kernel recipe (linux-yocto.inc) and is only available after the kernel has been configured. - Running
bitbake -ebefore 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_VERSIONare resolved during the kernel’sdo_configuretask, not during image configuration.
Real-World Impact
- Delayed access to kernel version: Engineers cannot retrieve
KERNEL_VERSIONuntil 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 menuconfigbefore queryingKERNEL_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 -eprovides 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.