Skip to contentSkip to conversation

scripts/dev-needs: Add script to list device dependencies

PATCH In review Saravana Kannan 2 participants 5 messages Sep 1, 2020 – Oct 27, 2020 Device dependency helper script

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/dev-needs: Add script to list device dependencies

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.

By default it lists the full path to the devices under /sys/devices.

It also takes an optional modifier flag as the first parameter to change what information is listed in the output. If the requested information is not available, the device name is printed.

-c lists the compatible string of the dependencies
-d lists the driver name of the dependencies that have probed
-m lists the module name of the dependencies that have a module
-f list the firmware node path of the dependencies
-g list the dependencies as edges and nodes for graphviz
-t list the dependencies as edges for tsort

The filter options provide a way to filter out some dependencies:
--allow-no-driver By default dependencies that don't have a driver
attached are ignored. This is to avoid following device links to "class" devices that are created when the consumer probes (as in, not a probe dependency). If you want to follow these links anyway, use this flag.

--exclude-devlinks Don't follow device links when tracking probe
dependencies.

--exclude-parents Don't follow parent devices when tracking probe
dependencies.

---
 MAINTAINERS          |   6 +
 scripts/dev-needs.sh | 315 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 321 insertions(+)
 create mode 100755 scripts/dev-needs.sh
MAINTAINERS +6 -0
index 7119165796c7..0edde5b4b032 100644
@@ -4995,6 +4995,12 @@ S:	Maintained
 F:	drivers/base/devcoredump.c
 F:	include/linux/devcoredump.h
 
+DEVICE DEPENDENCY HELPER SCRIPT
+M:	Saravana Kannan <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	scripts/dev-needs.sh
+
 DEVICE DIRECT ACCESS (DAX)
 M:	Dan Williams <[email protected]>
 M:	Vishal Verma <[email protected]>
scripts/dev-needs.sh new file +315 -0

315 lines not on this page · raw message

Signature · 1 line
2.28.0.402.g5ffc5be6b7-goog
#1 lore raw

Hi Saravana,

Quoted 10 lines · Saravana Kannan

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>

Quoted 8 lines

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!

scripts/dev-needs.sh line 1

Quoted 4 lines
scripts/dev-needs.sh new file +1 -0
@@ -0,0 +1,315 @@
+#! /bin/sh

On Debian, where /bin/sh -> dash:

dev-needs.sh: 6: dev-needs.sh: Syntax error: "(" unexpected

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

Which shell should I use?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#2 lore raw
Quoted 25 lines · Geert Uytterhoeven

Hi Saravana,

Quoted 10 lines · Saravana Kannan

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>

Quoted 8 lines

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!

Quoted 8 lines

scripts/dev-needs.sh line 1

Quoted 4 lines
scripts/dev-needs.sh new file +1 -0
@@ -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.

Quoted 13 lines

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
Quoted 9 lines
# ./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?

This is the version I have:
GNU bash, version 5.1.0(1)-rc1

Quoted 1 line

Which shell should I use?

I've tested with toybox and bash.

-Saravana

#3 lore raw

Hi Saravana,

Quoted 30 lines · Saravana Kannan
Quoted 29 lines · Geert Uytterhoeven
Quoted 10 lines · Saravana Kannan

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>

Quoted 8 lines

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!

scripts/dev-needs.sh line 1

Quoted 4 lines
scripts/dev-needs.sh new file +1 -0
@@ -0,0 +1,315 @@
+#! /bin/sh

On Debian, where /bin/sh -> dash:

Quoted 4 lines
Quoted 1 line

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
Quoted 22 lines
Quoted 12 lines

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
Quoted 9 lines
# ./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
Quoted 5 lines

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.

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

Quoted 2 lines

This is the version I have:
GNU bash, version 5.1.0(1)-rc1

# /bin/bash --version
GNU bash, version 5.0.3(1)-release (aarch64-unknown-linux-gnu)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#4 lore raw
Quoted 34 lines · Geert Uytterhoeven

Hi Saravana,

Quoted 30 lines · Saravana Kannan
Quoted 29 lines · Geert Uytterhoeven
Quoted 10 lines · Saravana Kannan

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>

Quoted 8 lines

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!

scripts/dev-needs.sh line 1

Quoted 4 lines
scripts/dev-needs.sh new file +1 -0
@@ -0,0 +1,315 @@
+#! /bin/sh

On Debian, where /bin/sh -> dash:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

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.

Quoted 28 lines
Quoted 22 lines
Quoted 12 lines

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
Quoted 9 lines
# ./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
Quoted 5 lines

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?

Quoted 6 lines

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.

Quoted 2 lines

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