View previous topic :: View next topic |
Author |
Message |
Cheesyjuggler64 n00b
Joined: 16 May 2024 Posts: 39
|
Posted: Fri Dec 27, 2024 6:38 pm Post subject: Scripting the kernel configuration. |
|
|
I've been trying to understand how interact with the kconfig system that the Linux kernel operates on to script it and I've got no idea how. Is there anyway to programmatically traverse the kconfig structure like menu config does but instead save it is some sort of custom data structure or do you have to individually read the kconfig and set up the structure yourself. Is there no way to hook into some preexisting configuration scripts which all ready have to read all this data like make menuconfig and work from there? |
|
Back to top |
|
|
zen_desu Tux's lil' helper
Joined: 25 Oct 2024 Posts: 81
|
Posted: Fri Dec 27, 2024 6:42 pm Post subject: |
|
|
I'd like to be wrong, but I think you have to read the kconfig files in each dir and handle the includes in them.
that being said, you could use the parser from an existing script, and i think there are libraries for this. _________________ µgRD dev
Wiki writer |
|
Back to top |
|
|
Cheesyjuggler64 n00b
Joined: 16 May 2024 Posts: 39
|
Posted: Fri Dec 27, 2024 11:04 pm Post subject: |
|
|
So if I were to try and build one is the best way to just read in all the kconfig files and assimilate a structure from there? |
|
Back to top |
|
|
Cheesyjuggler64 n00b
Joined: 16 May 2024 Posts: 39
|
|
Back to top |
|
|
Goverp Advocate
Joined: 07 Mar 2007 Posts: 2189
|
Posted: Sat Dec 28, 2024 11:31 am Post subject: |
|
|
Cheesyjuggler,
If you're into python, you might like https://pypi.org/project/kconfiglib/.
My experience writing an awk parser for Kconfig files is that their syntax is pretty horrible - basically an agglomeration of ad-hoc rules, resulting in such horrors as parsing producing different results depending on tab settings. Also, there are a heck of a lot of them in the kernel tree, not all of which will be relevant to any particular enquiry.
Net of that is, if someone's already gone through the pain and written a parser, then use it, don't reinvent the wheel! _________________ Greybeard |
|
Back to top |
|
|
zen_desu Tux's lil' helper
Joined: 25 Oct 2024 Posts: 81
|
Posted: Sat Dec 28, 2024 6:04 pm Post subject: |
|
|
Goverp wrote: |
My experience writing an awk parser for Kconfig files is that their syntax is pretty horrible - basically an agglomeration of ad-hoc rules, resulting in such horrors as parsing producing different results depending on tab settings. Also, there are a heck of a lot of them in the kernel tree, not all of which will be relevant to any particular enquiry.
Net of that is, if someone's already gone through the pain and written a parser, then use it, don't reinvent the wheel! |
This was my experience. I got started writing a parser then noped out and ended up using dist-kernel.
Maybe it was made worse by me doing it wrong, but I started to hit rules where things didn't have all depends listed, etc, and it made it feel like i couldn't use that data as a real reference point _________________ µgRD dev
Wiki writer |
|
Back to top |
|
|
sublogic Apprentice
Joined: 21 Mar 2022 Posts: 284 Location: Pennsylvania, USA
|
Posted: Sun Dec 29, 2024 1:09 am Post subject: |
|
|
For the adventurous, Kconfig is documented in the source tree's Documentation/kbuild subdirectory.
There is even a yacc grammar in scripts/kconfig/, if you can grok the yacc.
Finally, there is a self-contained script, scripts/kconfig/streamline_config.pl , that parses all the Kconfig files and the Makefiles. You could use it as a template of sorts, except that 1) it is written in perl, a language that looks like shell, awk and sed thrown into a blender with some gravel, and 2) perl scripts look like text files that passed through a communication channel with a large bit error rate. On the plus side, if you know awk, sed and shell, you almost know perl ! Start with man perlintro .
Have fun. Or be wise.
(To be fair, perl is pretty cool once you get the hang of it. IMHO It is the best glue language when it comes time to read files in a weird format and convert them to another weird format. It may be cryptic but it is also very concise, and the concision helps to focus on the task --like algebra compared to words.) |
|
Back to top |
|
|
|