[U-Boot] Whitelist scripting

I went through my boards to look for junk #defines in the header that do nothing and/or are dead. I then created a pretty poor script that runs through and scans the whitelist and greps the code searching for C code that uses the defines.
I started isolating sections and found that in some places we have C code that does the check for a #define, but it never gets defined anywhere, and in other places, we have #defines that aren't used.
What I was hoping to do was help clean the whitelist table by first searching for #defines that are never used anywhere and/or are dead.I will be the first person to admit that I am not very good with shell scripts, so I thought I'd solicit a favor.
Does someone have any cool scripts that we can use the scan through the and look for #defines that have no #ifdef, Makefile dependancy, or linker script attachment? These seem like they'd be obvious chunks of code to eliminate.
Conversely, does anyone have any cool scripts that we can scan through the code and look for #ifdefs that are never defined? Those seem like other low-hanging fruit but possible still useful.
As people are going through and using moveconfig to migrate to Kconfig it seems like there might be a lot of work saved by eliminating a junk from the whitelist.
adam

Hi,
On Mon, 5 Mar 2018 14:08:20 -0600 Adam Ford aford173@gmail.com wrote:
...
What I was hoping to do was help clean the whitelist table by first searching for #defines that are never used anywhere and/or are dead.I will be the first person to admit that I am not very good with shell scripts, so I thought I'd solicit a favor.
Does someone have any cool scripts that we can use the scan through the and look for #defines that have no #ifdef, Makefile dependancy, or linker script attachment? These seem like they'd be obvious chunks of code to eliminate.
I personally started with a lower-hanging fruit: config symbols that are referenced exactly once. For that I use the following hacks that I just pick from the shell history with Ctrl-R every now and then :)
rm -rf grep-counts; mkdir grep-counts; for f in $(cat scripts/config_whitelist.txt); do git grep $f > grep-counts/$f; done
This just builds a "database" of occurences for each symbol in the whitelist. Then:
for f in $(wc -l grep-counts/* | awk '$1 == 2' | tr / ' ' | awk '{print $3}'); do cat grep-counts/$f; done | grep ':#define'
This lists all the symbols from the database that are only #define'd exactly once (it checks for '2' to account for the match in config_whitelist.txt).
Hope that helps. Don't try to remove the same symbols I removed in my latest 3 patches to the list though :)
- Tuomas
participants (2)
-
Adam Ford
-
Tuomas Tynkkynen