pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • PebbleOS
  • Mobile App
  • Examples
  • Index 01
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

PebbleOS

  • Overview
  • Start here
    • Getting started guide
  • Pebble Firmware
    • Overview
    • Playground
    • Application SDK
  • Development
    • The pbl CLI
    • Build system
      • CMake
      • Devicetree
      • Kconfig
      • Applications
      • Rust
    • Samples
    • Emulator and simulator
    • Testing
    • Debugging
    • Conventions
  • System
    • Architecture overview
    • Kernel
    • Drivers
    • Subsystems
    • Libraries
    • Third-party
  • Hardware
    • Boards
    • Board Add-ons
    • Programmers
  • Community
    • Contribution Guidelines
  • Reference
    • Reference
    • Kconfig options

Kconfig

Everything that can be left out of the firmware is a Kconfig symbol: SoCs, drivers, subsystems, services, debug aids and their parameters. The configuration is resolved with Kconfiglib when the build directory is configured, and the result drives both the C sources and the CMake build.

Configuration tree

The root of the tree is the application’s Kconfig, pebble/Kconfig for the firmware, or the top-level Kconfig for an application without one. Both source Kconfig.pebbleos, which sources the rest of the tree:

  • soc/*/Kconfig.defconfig and subsys/bluetooth/Kconfig.defconfig first, so their defaults win over the ones given with the definitions;

  • soc/Kconfig, with the SoC and CPU symbols, from the vendor directories (see SoCs);

  • the board’s files, only for the selected board, revision, core and board variant: boards/<board>/Kconfig, Kconfig.<revision>, Kconfig.<core>, Kconfig.<board variant>, Kconfig.<core>_<board variant>, then the same Kconfig.defconfig files;

  • lib/c, kernel, subsys, drivers and third_party, each with a Kconfig that sources its own subdirectories.

A symbol is defined next to the code it enables: a driver class’s Kconfig lives in drivers/<class>/, with one Kconfig.<driver> per driver next to it, a subsystem’s in subsys/<name>/. Kconfig options lists every option, with its dependencies, defaults and location.

SoCs

A series of SoCs has its code and its Kconfig in soc/<vendor>/<series>/, as soc/sf32lb/sf32lb52x, the QEMU machine soc/qemu/pebble and the host soc/native/posix:

File

Contents

soc/<vendor>/<series>/Kconfig.soc

The SoCs of the series, entries of the SoC choice a board picks in its defconfig. Each selects its series, and its CPU where the SoCs of a series differ in it

soc/<vendor>/<series>/Kconfig

The series symbol, what the series selects, and its options

soc/<vendor>/<series>/Kconfig.defconfig

The defaults the series gives to common symbols

soc/<vendor>/Kconfig

The family symbol, SOC_FAMILY_<VENDOR>, which its series select, and the options of every series of the family

soc/<vendor>/Kconfig.soc and soc/<vendor>/Kconfig.defconfig source those of the series, and soc/Kconfig those of every vendor directory. soc/CMakeLists.txt builds the directory of the selected family, which builds that of the selected series.

Configuration fragments

A build’s configuration is resolved from these fragments, in this order:

Fragment

Purpose

boards/<board>/defconfig

What the board is: SoC, boot chain and console

boards/<board>/defconfig.<revision>

What a revision changes

boards/<board>/defconfig.<core>

What a core (stm32h747i_disco/m4) changes

boards/<board>/defconfig.<board variant>

What a board variant (native/wasm) changes

boards/<board>/defconfig.<core>_<board variant>

What a board variant changes on one core (<board>/<core>/<board variant>)

pebble/prj.conf

Driver classes, subsystems, services and features every firmware enables

pebble/prj_<variant>.conf

What the normal or prf variant adds or removes

pebble/boards/<board>.conf

What the firmware enables or tunes on one board, and the SDK platform it offers there

pebble/boards/<board>_<variant>.conf

The same, for one variant only

<build>/menuconfig.conf

Changes made with pbl menuconfig

-DCONFIG_<SYMBOL>=<value>

Overrides given when configuring

The pebble/ fragments are the firmware’s. Another application brings the same files from its own directory instead, see Applications.

Overrides are passed to pbl configure or to CMake:

pbl configure --board obelix@pvt -DCONFIG_RELEASE=y

The variant is selected with --variant (-DVARIANT=), not by setting CONFIG_RECOVERY_FW directly; prj_prf.conf sets it, and the build stops if the two disagree.

The fragments add to each other: a symbol can be assigned in only one of them, and a later fragment cannot change what an earlier one set. To change a value for one build, override it with -D.

Configuration warnings are errors. The build stops when:

  • a fragment or an override names a symbol that does not exist;

  • a fragment assigns a symbol an earlier fragment already assigned;

  • a value cannot be applied because of the symbol’s dependencies; the error names the unsatisfied ones.

Using the configuration

Every symbol reaches all three consumers:

  • C sources: autoconf.h is force-included into every compilation, so symbols are plain macros. An enabled bool symbol is defined to 1 and a disabled one is not defined at all, so test it with #ifdef CONFIG_TOUCH.

  • CMake: config.cmake sets one variable per enabled symbol, used by the _ifdef helpers; see CMake.

  • Linker script: preprocessed with autoconf.h, so memory layout and sections can depend on the configuration.

.config in the build directory holds the resolved configuration.

Writing Kconfig

Driver classes

A class is a menuconfig symbol, with one symbol per driver inside its if block. No class is on by default: the application enables the classes it uses, drivers select the classes they use, and a SoC selects the ones its own code calls, such as its system timer. The board’s defconfig enables none. Inside an enabled class, a driver whose devices come from the board’s Devicetree defaults to the tree having one (default DT_HAS_NORDIC_NRF52832_TWIM_ENABLED). Otherwise, a driver that only exists on one SoC defaults to y there (default y if SOC_QEMU_PEBBLE).

What drivers use

A driver selects the classes it uses, such as the bus it sits on (select I2C) or the supplies it takes (select REGULATOR), so an application asks for an accelerometer without knowing how the board wires it. This is safe because only drivers inside an enabled class select, and the selected classes have no dependencies of their own. A driver that is not inside such a class, such as a regulator or a GPIO key, does not select: it sits inside the class its users select, or the one the application enables.

Capabilities

What hardware or drivers provide is a hidden symbol (no prompt) that the providers select, such as BACKLIGHT_HAS_COLOR or CPU_HAS_FPU. Code and other symbols depend on the capability, not on a list of providers.

Optional libraries

A library that is not always needed is gated behind a symbol, and its consumers select (or imply) it: BT selects MBEDTLS, and SERVICE_VOICE selects SPEEX.

Board and SoC defaults

A default that depends on the board or SoC goes in its Kconfig.defconfig, which is read before the definitions:

config FLASH_SIZE
    default 0x100000
Log levels

A module’s log level comes from a template:

module = TASK_WDT
module-str = Task watchdog
source "subsys/logging/Kconfig.template.log_level"

It defines CONFIG_TASK_WDT_LOG_LEVEL and its choice; see Logging.

Generated from PebbleOS 7416f78a1. This page is maintained in the pebbleos repository: docs/development/build_system/kconfig.md.

Overview

  • Configuration tree
  • SoCs
  • Configuration fragments
  • Using the configuration
  • Writing Kconfig