Skip to content

Commit

Permalink
helpers/kernel_config: add custom KernelConfigOption's to the logic
Browse files Browse the repository at this point in the history
Allow kernel_config to be extended by the user if this wants to check
for custom KernelConfigOption's. User might pass, through a map, all
KernelConfigOption's to be checked in kconfig, together with the
already existing ones.
  • Loading branch information
rafaeldtinoco authored and Rafael David Tinoco committed Sep 3, 2021
1 parent 3179924 commit b137715
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions helpers/kernel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ func (k *KernelConfig) GetKernelConfigFilePath() string {
return k.kConfigFilePath
}

// AddCustomKernelConfigs allows user to extend list of possible existing kconfigs to be parsed from kConfigFilePath
func (k *KernelConfig) AddCustomKernelConfigs(values map[uint32]string) error {
for key, value := range values {
// extend initial list of kconfig options: add other possible existing ones
KernelConfigKeyIDToString[KernelConfigOption(key)] = value
KernelConfigKeyStringToID[value] = KernelConfigOption(key)
}

return k.initKernelConfig(k.kConfigFilePath)
}

// initKernelConfig inits internal KernelConfig data by calling appropriate readConfigFromXXX function
func (k *KernelConfig) initKernelConfig(configFilePath string) error {
if _, err := os.Stat(configFilePath); err != nil {
Expand Down Expand Up @@ -266,8 +277,13 @@ func (k *KernelConfig) readConfigFromProcConfigGZ(filePath string) error {

// readConfigFromScanner reads all existing KernelConfigOption's and KernelConfigOptionValue's from given io.Reader
func (k *KernelConfig) readConfigFromScanner(reader io.Reader) {
k.configs = make(map[KernelConfigOption]interface{})
k.needed = make(map[KernelConfigOption]interface{})

if k.configs == nil {
k.configs = make(map[KernelConfigOption]interface{})
}
if k.needed == nil {
k.needed = make(map[KernelConfigOption]interface{})
}

scanner := bufio.NewScanner(reader)
for scanner.Scan() {
Expand All @@ -291,8 +307,17 @@ func (k *KernelConfig) readConfigFromScanner(reader io.Reader) {
}

// GetValue will return a KernelConfigOptionValue for a given KernelConfigOption when this is a BUILTIN or a MODULE
func (k *KernelConfig) GetValue(option KernelConfigOption) (KernelConfigOptionValue, error) {
value, ok := k.configs[option].(KernelConfigOptionValue)
func (k *KernelConfig) GetValue(option interface{}) (KernelConfigOptionValue, error) {
var o uint32

switch option.(type) {
case uint32:
o = uint32(option.(uint32))
case KernelConfigOption:
o = uint32(option.(KernelConfigOption))
}

value, ok := k.configs[KernelConfigOption(o)].(KernelConfigOptionValue)
if ok {
return value, nil
}
Expand Down

0 comments on commit b137715

Please sign in to comment.