3 # update-config.py: A program to help automate updating the
4 # kernel configuration.
6 # Copyright (C) 2018 Jason Self <j@jxself.org>
8 # You will need Python and pexpect.
10 # A file named base_config containing config options (without the
11 # leading CONFIG_) needs to live in the root level of the kernel
12 # source tree. This program will run make oldconfig, responding to
13 # prompts for config options using the information in that
14 # base_config file. If no match is found it will pause so that you
15 # can answer, unless USE_DEFAULT is to true. In that case the program
16 # will accept whatever the default answer is and continue on.
18 # SPDX-License-Identifier: AGPL-3.0-or-later
20 # This program is free software: you can redistribute it and/or
21 # modify it under the terms of the GNU Affero General Public License
22 # as published by the Free Software Foundation, either version 3 of
23 # the License, or (at your option) any later version.
25 # This program is distributed in the hope that it will be useful, but
26 # WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 # Affero General Public License for more details.
30 # You should have received a copy of the GNU Affero General Public
31 # License along with this program. If not, see
32 # <https://www.gnu.org/licenses/>.
46 def readBaseConfig(baseConfigFile):
47 f = open(baseConfigFile)
48 for l in f.readlines():
49 if len(l) < 3 or l.strip()[0] == '#':
53 key = '(' + optVal[0].strip().replace('CONFIG_', '') + ')'
54 val = optVal[1].strip().replace('"', '')
58 cmd = 'make oldconfig'
59 proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
60 fLog = open('kernelexpect.log', 'w+')
67 pollResult = select.select([proc.stdout], [], [], timeLimit)[0]
68 if len(pollResult) != 0:
69 c = proc.stdout.read(1)
74 if c == '\r' or c == '\n':
81 print '\n**** Timeout ***'
83 if b.find('Restart config') != -1:
86 print 'Waiting for valid config'
92 if l.find(k + ' [') != -1:
93 print 'Found key', k, 'in line', 'setting value', configs[k]
94 proc.stdin.write(configs[k] + '\n')
97 if l.startswith('choice'):
99 print 'Please enter your option'
100 v = sys.stdin.readline()
101 print 'Setting value', v
105 options = int(l.replace('choice[1-', '').replace('?', '').replace(']', '').replace(':', ''))
106 print 'Options', options
107 ls = b.split('\n')[-options-1:-1]
113 if configs[k] != 'y':
116 print 'Found key', k, 'in line', 'setting value', configs[k]
117 lc = lc.replace('>', '').strip()
120 print 'Using option', option
121 proc.stdin.write(option + '\n')
126 print 'Please enter your option'
127 v = sys.stdin.readline()
128 print 'Setting value', v
132 print 'Using default'
133 proc.stdin.write('\n')
135 print '****************'
139 readBaseConfig('base_config')
142 for k in configs.keys():