Definition
A firmware build profile is a named set of build inputs and settings that turns one source tree into one firmware image. It fixes the configuration values, the compiler and its optimization level, the hardware description, whether logging and run-time checks are compiled in, and the link and signing settings. Typical profiles are debug, for diagnosis, and release, for shipping. Two profiles of the same source can differ in size, timing, memory use and checks, so every measured result belongs to the profile that produced it.
The idea
A developer measures how long the firmware takes to handle one event and gets 3.5 ms. The image measured was the debug image: it prints a log line for each event over a serial port and checks assertions. The product ships the release image, which does neither and handles the same event in 0.05 ms. The source code is the same; the two images are not. A result is a fact about the image that was built, so it carries over to another profile only when the difference between the profiles cannot affect it.
A test car fitted with measuring equipment is a fair picture. The equipment adds weight, so fuel-consumption figures must be measured again without it, while the color of the paint is the same with or without it. The picture stops at one point. Removing equipment from a car changes nothing else, but removing logging from firmware also changes the timing of everything around it, and removing an assertion removes the check itself: a fault that the debug image would have caught passes silently through the release image.
How it works
A profile fixes these inputs, and each changes the image in its own way.
Source revision and toolchain §12.2: the exact source, and the exact versions of the compiler, the linker §12.4 and the libraries.
Optimization level: Zephyr §6.33 offers, through Kconfig §6.40 symbols,
-Os(optimize for size, its default),-O2(optimize for speed),-Og(optimize while keeping the program easy to debug) and-O0(no optimization). The level changes instruction counts, inlining, stack frame sizes and code layout.Configuration: the Kconfig values, Zephyr’s build-time settings, for logging, assertions, stack sizes, buffer counts, features and security options.
Hardware description: the devicetree §6.39 and its overlays, which fix pins, clocks and enabled devices.
Link and packaging: the memory layout, the bootloader §6.30, and the key that signs the image.
In Zephyr, a profile is usually a set of configuration fragments, for example prj.conf plus a debug.conf named in the build variable EXTRA_CONF_FILE. Projects built with CMake §12.12, a widely used generator of build scripts, name build types such as Debug and Release.
Logging. Zephyr’s logging macros, such as LOG_INF(), are filtered by a level fixed at build time; a message below the compiled level is removed by the compiler and costs nothing. A message that is kept costs time in one of two ways. In deferred mode the call only copies the message into a buffer, and a logging thread formats and sends it later, so the caller pays little, but the thread’s work and its buffer remain in the image. In immediate mode the caller formats and sends the message before the call returns. printk(), Zephyr’s simple print function, writes formatted text to the console; with CONFIG_PRINTK off it compiles to an empty function.
Assertions. An assertion is a check, written into the code, that a condition the programmer believes always true really holds.
A run-time assertion, such as Zephyr’s
__ASSERT(cond, msg)or standard C’sassert(cond), tests the condition while the program runs. In Zephyr it exists only whenCONFIG_ASSERTis on, and a failure prints the message and stops the system with a fatal error. WithCONFIG_ASSERToff, the macro expands to nothing: the condition is not even evaluated, so any side effect written inside it disappears too. Standard C’sassertdisappears in the same way whenNDEBUGis defined.A compile-time assertion, such as C11’s
_Static_assertor Zephyr’sBUILD_ASSERT(cond, msg), is checked by the compiler, so a false condition stops the build. It exists in every profile and costs nothing at run time, but it can test only facts known at compile time, such as the size of a structure or a configured constant.
Worked example
Logging changes timing. The debug profile prints one 40-character line per event through a console that sends each character over a UART §6.23 (universal asynchronous receiver-transmitter) at 115200 baud and waits for the hardware to take it. Each character is a 10-bit frame, so the line takes ms. Suppose the event’s real work takes 0.05 ms. The debug image then needs about ms per event and can handle at most events per second; the release image, at 0.05 ms, can handle . The debug latency is about times the release latency. No timing result transfers from this debug image to the release image.
Stack use changes. A thread has a 512-byte stack, and on its deepest path three functions are active at once. In the release profile each of their stack frames, the memory that one function call reserves on the stack, takes 128 bytes: bytes, leaving bytes spare. The debug profile keeps more variables in memory, adding 32 bytes per frame, and a log call at the deepest point needs another 256 bytes for formatting: bytes, which overflows the stack by bytes. The release measurement of 384 bytes does not bound the debug image. The reverse fails too: optimization can merge functions into one larger frame, so a debug measurement does not bound the release image either.
Checks disappear. The debug image handles one million events with CONFIG_ASSERT on, and an assertion that a buffer index is below 16 never fails. That shows the index stayed below 16 in those runs of the debug image. In the release image the assertion is gone. If the index can exceed 15 under some timing that the slower debug image never produced, nothing stops the out-of-bounds write §4.4. A property that must hold in the shipped product needs a check that stays in every profile and handles failure on purpose, or an argument that the condition holds for every input, or, for a fact fixed at build time, a compile-time assertion.
Stated precisely
Let a conclusion , such as “each event is handled within 1 ms” or “the message bytes follow the format”, rest on a list of premises. Each premise is a fact about one input of the build (the source, the toolchain, a configuration value, the hardware description) or about the running conditions. transfers from profile to profile when every premise holds in : either the input it concerns is identical in and , or a stated argument shows that the difference cannot change the premise. Otherwise must be established again for .
Applied to the usual differences between a debug and a release profile:
Usually transfers: the computed results of code that both profiles compile from the same source with the same configuration, provided the code has no undefined behavior §4.12, meaning no operation for which the C standard sets no requirement, and no data race §9.3, meaning no unsynchronized access to shared memory by two threads with at least one writing. The C standard lets a compiler change how code runs at any optimization level only as long as the program’s observable behavior stays the same, and that promise covers only programs without undefined behavior.
Must be re-established: execution time §9.32, latency and throughput; stack and heap peaks; code size; power use; race windows, because changed timing changes which interleavings occur; instrumentation coverage §14.35, the set of code points §12.48 that measurement probes actually observe, because inlining can remove a function that a probe was attached to; and every claim that a check catches an error, because the check may not exist in .
Never transfers without inspection: anything inside code guarded by a configuration value that differs between and .
Build parity in comparisons
A comparison between two images, such as with and without a feature, measures the feature only if everything else in the two profiles is equal: the same source apart from the feature, the same toolchain versions, the same optimization level and compiler options §12.3, the same logging and assertion settings, and the same hardware description and clock settings. This equality is called build parity. Two differences that would each invalidate a latency comparison are an -Og image compared with an -Os image, and an image with immediate-mode logging compared with one without logging; either difference alone can move latency by more than the feature does.
A difference that cannot be avoided, such as the feature’s own code shifting the addresses of other functions, is not hidden. The report names it, measures its effect separately, for example with a control image that adds the same amount of code without the feature, and states how large the effect is.
Limits and common mistakes
A profile’s name proves nothing. The resolved configuration file, the compiler command lines and a hash of the built image identify what was actually built; a build fingerprint §15.17 records them.
A debug-only check protects only the debug image. If the release image needs the protection, the check must stay in every profile.
Code with a side effect inside __ASSERT() or assert() behaves differently when assertions are off, because the whole expression vanishes.
Higher optimization can expose undefined behavior that a lower level happened to hide, so a release image can fail where the debug image worked.
Measuring changes what is measured. Instrumentation §14.24 added for a measurement is itself a profile difference, and its overhead belongs in the report.
The same source and the same profile name still give different images when the toolchain differs. A reproducible build §13.8, in which identical inputs give identical bytes, is what makes a rebuilt image the same image.
Questions answered
Which conclusions transfer between profiles, and which require revalidation?
A conclusion transfers from one firmware build profile to another only when every fact it rests on is the same in both; everything else must be checked again. A build profile is the set of settings, such as optimization level, logging, assertions and configuration values, that turns one source tree into one firmware image, so two profiles of the same source give different images.
Usually transfer: computed results of code that both profiles compile from the same source with the same configuration, provided the code has no undefined behavior and no data races, for example the bytes of a message format.
Require revalidation: timing (latency, throughput, worst-case execution time §9.33), stack and heap use, code size, power use, race windows, instrumentation coverage, and every claim that a run-time check catches an error, because assertions and logging may be compiled out.
Require inspection: anything in code guarded by a configuration value that differs between the profiles.
For a comparison between two images, both must come from the same profile apart from the factor under test. Any difference that cannot be avoided is named, measured separately and reported, not hidden.
Related entries: Compiler correctness (§3.40), Kconfig (§6.40), Measurement uncertainty (§11.33), Compiler optimization (§3.39), Reproducible build (§13.8), Build fingerprint (§15.17).