Custom kernel .config options - best practice?



  • What is the best way to maintain your own kernel .config options?

    I recently added an RTC (DS3231) which involves adding RTC support and driver to the O2+ kernel.

    Currently I hacked a couple of scripts which I can run after resetting the config files with git. These set the necessary options manually in both the kernel and package config files, but is there a better (proper?) way to do this?

    Probably the different options should be set manually after running make menuconfig? But I don't know if the resulting .config file (after make menuconfig and saving .config) will build the same kernel as the one built with the .config from the Onion source repo. I'm doubtful that it will.

    fwiw, here are the scripts I wrote in case anyone else finds them useful. I did some light testing, so use at own risk:

    set-kerneloptions-RTCds1307.sh
    #! /bin/sh
    
    setoption() {
     local loption=$1
     local lstate=$2
     local lconfigfile=$3
    
     grep "${loption}\(=\| \)" ${lconfigfile} > /dev/null
     if [ $? -eq 0 ]; then
      # set it to the required value
      echo -n Set: ${loption}
      sed -i -r "s/^(${loption}=.*|# ${loption} is not set)/${loption}=${lstate}/" ${lconfigfile}
     else
      # Add the option
      echo -n Add: ${loption}
      echo "${loption}=${lstate}" >> ${lconfigfile}
     fi
     echo " Now: `grep "${loption}\(=\| \)" ${lconfigfile}`"
    }
    
    unsetoption() {
     local loption=$1
     local lconfigfile=$2
    
     grep "${loption}\(=\| \)" ${lconfigfile} > /dev/null
     if [ $? -eq 0 ]; then
      # set it to the required value
      echo -n Unset: ${loption}
      sed -i -r "s/^(${loption}=.*)/# ${loption} is not set/" ${lconfigfile}
     else
      # Add the option
      echo -n Add: ${loption}
      echo "# ${loption} is not set" >> ${lconfigfile}
     fi
     echo " Now: `grep "${loption}\(=\| \)" ${lconfigfile}`"
    }
    
    CONFIGFILE="target/linux/ramips/mt7688/config-4.4"
    
    for configoption in CONFIG_RTC_CLASS \
                            CONFIG_RTC_DRV_DS1307 \
                            CONFIG_RTC_SUPPORT
    do
     setoption "${configoption}" "y" "${CONFIGFILE}"
    done
    
    unsetoption "CONFIG_RTC_HCTOSYS" "${CONFIGFILE}"
    

    Execution is as follows:

    root@122126d368fa:~/source# git checkout target/linux/ramips/mt7688/config-4.4
    root@122126d368fa:~/source# ./set-kerneloptions-RTCds1307.sh
    Add: CONFIG_RTC_CLASS Now: CONFIG_RTC_CLASS=y
    Add: CONFIG_RTC_DRV_DS1307 Now: CONFIG_RTC_DRV_DS1307=y
    Add: CONFIG_RTC_SUPPORT Now: CONFIG_RTC_SUPPORT=y
    Add: CONFIG_RTC_HCTOSYS Now: # CONFIG_RTC_HCTOSYS is not set
    root@122126d368fa:~/source#
    
    set-packages-RTCds1307.sh
    #! /bin/sh
    
    setoption() {
     local loption=$1
     local lstate=$2
     local lconfigfile=$3
    
     grep "${loption}\(=\| \)" ${lconfigfile} > /dev/null
     if [ $? -eq 0 ]; then
      # set it to the required value
      echo -n Set: ${loption}
      sed -i -r "s/^(${loption}=.*|# ${loption} is not set)/${loption}=${lstate}/" ${lconfigfile}
     else
      # Add the option
      echo -n Add: ${loption}
      echo "${loption}=${lstate}" >> ${lconfigfile}
     fi
     echo " Now: `grep "${loption}\(=\| \)" ${lconfigfile}`"
    }
    
    unsetoption() {
     local loption=$1
     local lconfigfile=$2
    
     grep "${loption}\(=\| \)" ${lconfigfile} > /dev/null
     if [ $? -eq 0 ]; then
      # set it to the required value
      echo -n Unset: ${loption}
      sed -i -r "s/^(${loption}=.*)/# ${loption} is not set/" ${lconfigfile}
     else
      # Add the option
      echo -n Add: ${loption}
      echo "# ${loption} is not set" >> ${lconfigfile}
     fi
     echo " Now: `grep "${loption}\(=\| \)" ${lconfigfile}`"
    }
    
    CONFIGFILE=".config"
    
    for configoption in CONFIG_PACKAGE_kmod-i2c-core \
                            CONFIG_PACKAGE_kmod-i2c-algo-bit \
                            CONFIG_PACKAGE_kmod-i2c-gpio \
                            CONFIG_PACKAGE_kmod-i2c-gpio-custom \
                            CONFIG_PACKAGE_hwclock \
                            CONFIG_PACKAGE_i2c-tools \
                            CONFIG_PACKAGE_kmod-rtc-ds1307
    do
     setoption "${configoption}" "y" "${CONFIGFILE}"
    done
    

    Execution is as follows:

    root@122126d368fa:~/source# git checkout .config
    root@122126d368fa:~/source# ./set-packages-RTCds1307.sh
    Set: CONFIG_PACKAGE_kmod-i2c-core Now: CONFIG_PACKAGE_kmod-i2c-core=y
    Set: CONFIG_PACKAGE_kmod-i2c-algo-bit Now: CONFIG_PACKAGE_kmod-i2c-algo-bit=y
    Set: CONFIG_PACKAGE_kmod-i2c-gpio Now: CONFIG_PACKAGE_kmod-i2c-gpio=y
    Set: CONFIG_PACKAGE_kmod-i2c-gpio-custom Now: CONFIG_PACKAGE_kmod-i2c-gpio-custom=y
    Set: CONFIG_PACKAGE_hwclock Now: CONFIG_PACKAGE_hwclock=y
    Set: CONFIG_PACKAGE_i2c-tools Now: CONFIG_PACKAGE_i2c-tools=y
    Add: CONFIG_PACKAGE_kmod-rtc-ds1307 Now: CONFIG_PACKAGE_kmod-rtc-ds1307=y
    root@122126d368fa:~/source#
    


Looks like your connection to Community was lost, please wait while we try to reconnect.