Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Scripting the kernel configuration.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
Cheesyjuggler64
n00b
n00b


Joined: 16 May 2024
Posts: 39

PostPosted: Fri Dec 27, 2024 6:38 pm    Post subject: Scripting the kernel configuration. Reply with quote

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
View user's profile Send private message
zen_desu
Tux's lil' helper
Tux's lil' helper


Joined: 25 Oct 2024
Posts: 81

PostPosted: Fri Dec 27, 2024 6:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
Cheesyjuggler64
n00b
n00b


Joined: 16 May 2024
Posts: 39

PostPosted: Fri Dec 27, 2024 11:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
Cheesyjuggler64
n00b
n00b


Joined: 16 May 2024
Posts: 39

PostPosted: Sat Dec 28, 2024 2:32 am    Post subject: Reply with quote

After doing some research, it says that there already exists an inbuilt parser for kconfig files. https://github.com/paulgazz/kmax/blob/master/kextractors/kextractor-4.12.8/README.md But I have no idea how to use it/ get its output. If anyone more experienced with this sort of thing could give me heads up that'd be great.

Moderator note: Fixed the url format. -- Banana
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2189

PostPosted: Sat Dec 28, 2024 11:31 am    Post subject: Reply with quote

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
View user's profile Send private message
zen_desu
Tux's lil' helper
Tux's lil' helper


Joined: 25 Oct 2024
Posts: 81

PostPosted: Sat Dec 28, 2024 6:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 284
Location: Pennsylvania, USA

PostPosted: Sun Dec 29, 2024 1:09 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum