Kconfig: Use the first default with a satisfied condition

Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

  1. It's inconsistent with how Kconfig works in other projects, which
     might confuse newcomers.

  2. Due to oversights, earlier 'range' properties are still preferred,
     as well as earlier 'default' properties on choices.

     In addition to being inconsistent, this makes it impossible to
     override 'range' properties and choice 'default' properties if the
     base definition of the symbol/choice already has 'range'/'default'
     properties.

     I've seen errors caused by the inconsistency, and I suspect there
     are more.

  3. A fork of Kconfiglib that adds the patch needs to be maintained.

Get rid of the patch and go back to standard Kconfig behavior, as
follows:

  1. Include the Kconfig.defconfig files first instead of last in
     Kconfig.zephyr.

  2. Include boards/Kconfig and arch/<arch>/Kconfig first instead of
     last in arch/Kconfig.

  3. Include arch/<arch>/soc/*/Kconfig first instead of last in
     arch/<arch>/Kconfig.

  4. Swap a few other 'source's to preserve behavior for some scattered
     symbols with multiple definitions.

     Swap 'source's in some no-op cases too, where it might match the
     intent.

  5. Reverse the defaults on symbol definitions that have more than one
     default.

     Skip defaults that are mutually exclusive, e.g. where each default
     has an 'if <some board>' condition. They are already safe.

  6. Remove the prefer-later-defaults patch from Kconfiglib.

Testing was done with a Python script that lists all Kconfig
symbols/choices with multiple defaults, along with a whitelist of fixed
symbols. The script also verifies that there are no "unreachable"
defaults hidden by defaults without conditions

As an additional test, zephyr/.config was generated before and after the
change for several samples and checked to be identical (after sorting).

This commit includes some default-related cleanups as well:

  - Simplify some symbol definitions, e.g. where a default has 'if FOO'
    when the symbol already has 'depends on FOO'.

  - Remove some redundant 'default ""' for string symbols. This is the
    implicit default.

Piggyback fixes for swapped ranges on BT_L2CAP_RX_MTU and
BT_L2CAP_TX_MTU (caused by confusing inconsistency).

Piggyback some fixes for style nits too, e.g. unindented help texts.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
Ulf Magnusson 2018-07-30 10:57:47 +02:00 committed by Anas Nashif
commit ec3eff57e0
37 changed files with 186 additions and 194 deletions

View file

@ -25,8 +25,8 @@ config BT_HCI_CMD_COUNT
config BT_RX_BUF_COUNT
int "Number of HCI RX buffers"
default 10
default 3 if BT_RECV_IS_RX_THREAD
default 10
range 2 255
help
Number of buffers available for incoming ACL packets or HCI events
@ -34,9 +34,9 @@ config BT_RX_BUF_COUNT
config BT_RX_BUF_LEN
int "Maximum supported HCI RX buffer length"
default 76
default 77 if BT_MESH_PROXY
default 264 if BT_BREDR
default 77 if BT_MESH_PROXY
default 76
range 73 2000
help
Maximum data size for each HCI RX buffer. This size includes
@ -48,16 +48,17 @@ config BT_RX_BUF_LEN
(4 bytes) and the ACL header (also 4 bytes) which yields 73 bytes.
config BT_HCI_TX_STACK_SIZE
# Stack size needed for executing bt_send with specified driver
int
# Even if no driver is selected the following default is still
# needed e.g. for unit tests.
default 256
default 256 if BT_H4
default 256 if BT_H5
default 416 if BT_SPI
default 640 if BT_CTLR
default 256 if BT_USERCHAN
# Even if no driver is selected the following default is still
# needed e.g. for unit tests.
default 256
help
Stack size needed for executing bt_send with specified driver
config BT_HCI_TX_PRIO
# Hidden option for Co-Operative Tx thread priority
@ -73,17 +74,18 @@ config BT_WAIT_NOP
This option should be selected if the controller used
exhibits such behavior.
# Headroom that the driver needs for sending and receiving buffers.
# Add a new 'default' entry for each new driver.
config BT_HCI_RESERVE
int
# Even if no driver is selected the following default is still
# needed e.g. for unit tests.
default 0
default 0 if BT_H4
default 1 if BT_H5
default 1 if BT_SPI
default 1 if BT_USERCHAN
# Even if no driver is selected the following default is still
# needed e.g. for unit tests.
default 0
help
Headroom that the driver needs for sending and receiving buffers. Add a
new 'default' entry for each new driver.
config BT_RECV_IS_RX_THREAD
# Hidden option set by the HCI driver to indicate that there's
@ -97,10 +99,10 @@ config BT_RECV_IS_RX_THREAD
config BT_RX_STACK_SIZE
int "Size of the receiving thread stack"
depends on BT_HCI_HOST || BT_RECV_IS_RX_THREAD
default 1024
default 2048 if BT_SETTINGS
default 2048 if BT_MESH
default 512 if BT_HCI_RAW
default 2048 if BT_MESH
default 2048 if BT_SETTINGS
default 1024
range 512 65536 if BT_HCI_RAW
range 1100 65536 if BT_MESH
range 1024 65536
@ -156,19 +158,19 @@ if BT_CONN
if BT_HCI_ACL_FLOW_CONTROL
config BT_ACL_RX_COUNT
int "Number of incoming ACL data buffers"
default 6
default BT_CTLR_RX_BUFFERS if BT_CTLR
default 6
range 1 64
help
Number of buffers available for incoming ACL data.
config BT_L2CAP_RX_MTU
int "Maximum supported L2CAP MTU for incoming data"
default 23
default 65 if BT_SMP
default 200 if BT_BREDR
range 23 1300
default 65 if BT_SMP
default 23
range 65 1300 if BT_SMP
range 23 1300
help
Maximum size of each incoming L2CAP PDU.
endif # BT_HCI_ACL_FLOW_CONTROL
@ -194,18 +196,18 @@ config BT_L2CAP_TX_FRAG_COUNT
config BT_L2CAP_TX_MTU
int "Maximum supported L2CAP MTU for L2CAP TX buffers"
default 23
default 65 if BT_SMP
default 253 if BT_BREDR
range 23 2000
default 65 if BT_SMP
default 23
range 65 2000 if BT_SMP
range 23 2000
help
Maximum L2CAP MTU for L2CAP TX buffers.
config BT_CONN_TX_MAX
int "Maximum number of pending TX buffers"
default 7
default BT_CTLR_TX_BUFFERS if BT_CTLR
default 7
range 1 128
help
Maximum number of pending TX buffers that have not yet
@ -322,8 +324,8 @@ config BT_GATT_READ_MULTIPLE
config BT_MAX_PAIRED
int "Maximum number of paired devices"
default 1
default 0 if !BT_SMP
default 1
range 0 128
help
Maximum number of paired Bluetooth devices. The minimum (and
@ -540,8 +542,8 @@ config BT_RFCOMM
config BT_RFCOMM_L2CAP_MTU
int "L2CAP MTU for RFCOMM frames"
default BT_RX_BUF_LEN
default BT_L2CAP_RX_MTU if BT_HCI_ACL_FLOW_CONTROL
default BT_RX_BUF_LEN
depends on BT_RFCOMM
range BT_L2CAP_RX_MTU 32767 if BT_HCI_ACL_FLOW_CONTROL
range BT_RX_BUF_LEN 32767