1

I am writing a kernel module that has two low-level options can be used. Both these 2 options can be select as M/Y/N, but at least one of them must be selected, else the module will not work. Just like below:

[*]   Enable FOO support                      
       <M>     Back-end A
       <M>     Back-end B

I write it as below, but both 2 sub-options can be unselected.

config FOO
   bool "Enable FOO support"
config BACKEND_A
   tristate "Back-end A"
   depends on FOO
   depends on SUBSYSTEM_X
config BACKEND_B
   tristate "Back-end B"
   depends on FOO
   depends on SUBSYSTEM_Y

How to write such config in kconfig?

artless noise
  • 21,212
  • 6
  • 68
  • 105
Changbin Du
  • 501
  • 5
  • 11

2 Answers2

1

Assuming both backends A and B cannot be loaded into the kernel at the same time, choice configuration entry seems to be the best there:

config FOO
    bool "Enable FOO support"

choice
    prompt "Select back-end for FOO"
    depends on FOO

    config BACKEND_A
         tristate "Back-end A"
         depends on SUBSYSTEM_X
    config BACKEND_B
         tristate "Back-end B"
         depends on SUBSYSTEM_Y
endchoice

Behaviour of choice is described in Documentation/kbuild/kconfig-language.txt:

While a boolean choice only allows a single config entry to be selected, a tristate choice also allows any number of config entries to be set to 'm'. This can be used if multiple drivers for a single hardware exists and only a single driver can be compiled/loaded into the kernel, but all drivers can be compiled as modules.

Example of usage choice with tristate: linux/scripts/kconfig/tests/choice/Kconfig.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Thanks, it works. The only one little problem is user still can unselect all backends which result in a non-useable build. But anyway, it can prompt user to select it, then its user's buinness. – Changbin Du Feb 16 '17 at 09:15
0

You can make FOO non-editable and select it using reverse dependencies:

config FOO
        tristate

menu "FOO support"

config BACKEND_A
        tristate "Back-end A"
        depends on SUBSYSTEM_X
        select FOO
config BACKEND_B
        tristate "Back-end B"
        depends on SUBSYSTEM_Y
        select FOO

endmenu
Ian Abbott
  • 15,083
  • 19
  • 33