Re: [PATCH v1] scripts/dev-needs: Add script to list device dependencies

From: Saravana Kannan
Date: Tue Oct 27 2020 - 14:24:19 EST


On Tue, Oct 27, 2020 at 11:09 AM Geert Uytterhoeven
<geert@xxxxxxxxxxxxxx> wrote:
>
> Hi Saravana,
>
> On Tue, Oct 27, 2020 at 6:31 PM Saravana Kannan <saravanak@xxxxxxxxxx> wrote:
> > On Tue, Oct 27, 2020 at 3:12 AM Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> wrote:
> > > On Wed, Sep 2, 2020 at 12:51 AM Saravana Kannan <saravanak@xxxxxxxxxx> wrote:
> > > > This script can be useful for:
> > > > - Figuring out the list of modules you need to pack in initrd
> > > > - Figuring out the list of drivers you need to modularize for a device
> > > > to be fully functional without building in any dependencies.
> > > > - Figuring out which drivers to enable first, when porting drivers
> > > > between kernels (say, to upstream).
> > > > - Plotting graphs of system dependencies, etc.
> > > >
> > > > Usage: dev-needs.sh [-c|-d|-m|-f] [filter options] <list of devices>
> > > >
> > > > This script needs to be run on the target device once it has booted to a
> > > > shell.
> > > >
> > > > The script takes as input a list of one or more device directories under
> > > > /sys/devices and then lists the probe dependency chain (suppliers and
> > > > parents) of these devices. It does a breadth first search of the dependency
> > > > chain, so the last entry in the output is close to the root of the
> > > > dependency chain.
> > >
> > > Thanks for your patch!
> > >
> > > > --- /dev/null
> > > > +++ b/scripts/dev-needs.sh
> > > > @@ -0,0 +1,315 @@
> > > > +#! /bin/sh
> > >
> > > On Debian, where /bin/sh -> dash:
> > >
> > > dev-needs.sh: 6: dev-needs.sh: Syntax error: "(" unexpected
> >
> > dash doesn't like () after the function name maybe? If so, we could
> > drop it. I think it'll still work with toybox and bash.
>
> That's not sufficient:
>
> ./dev-needs.sh: 47: ./dev-needs.sh: Syntax error: "}" unexpected

Ok, let's give up on dash for now. I've never used it.

> > > When using bash, I get:
> > >
> > > # ./dev-needs.sh /sys/devices/platform/soc/feb00000.display
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > >
> > > # ./dev-needs.sh -c /sys/devices/platform/soc/feb00000.display
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> > > ./dev-needs.sh: line 255: detail: command not found
> >
> > This is odd. bash definitely works with this script on my Debian x86 machine.
> >
> > This error happens when the "detail" alias is not "seen" by the shell
> > when it interprets detail_chosen function. Sigh, every shell seems to
> > want a different order. Can you try to debug it on your end?
>
> The bash man page says:
>
> Aliases are not expanded when the shell is not interactive,
> unless the expand_aliases shell option is set using shopt
>
> And adding "shopt -s expand_aliases" at the top makes it work.

Thanks for figuring this out.

> Nevertheless, the bash man page says "... do not use alias in
> compound commands".

I'm not a bash expert in any sense and I don't have a strong opinion on this.

Aliases were just a lazy way for me to deal with the parsing the
options to allow different "output formats". If someone wants to
rewrite it to avoid aliases, I'll happily test them on my end and
accept the patches if they don't break on toybox (I need this to
continue working on Android/embedded devices).

I'm also okay with just adding "shopt -s expand_aliases" and calling
it a day for now (I'd assume it works with toybox. I haven't tested it
yet).

-Saravana