linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] scripts/dev-needs: Add script to list device dependencies
@ 2020-09-01 22:48 Saravana Kannan
  2020-10-27 10:11 ` Geert Uytterhoeven
  0 siblings, 1 reply; 5+ messages in thread
From: Saravana Kannan @ 2020-09-01 22:48 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Saravana Kannan
  Cc: Rob Herring, Nicolas Saenz Julienne, kernel-team, linux-kernel

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.

Signed-off-by: Saravana Kannan <saravanak@google.com>
---
 MAINTAINERS          |   6 +
 scripts/dev-needs.sh | 315 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 321 insertions(+)
 create mode 100755 scripts/dev-needs.sh

diff --git a/MAINTAINERS b/MAINTAINERS
index 7119165796c7..0edde5b4b032 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4995,6 +4995,12 @@ S:	Maintained
 F:	drivers/base/devcoredump.c
 F:	include/linux/devcoredump.h
 
+DEVICE DEPENDENCY HELPER SCRIPT
+M:	Saravana Kannan <saravanak@google.com>
+L:	linux-kernel@vger.kernel.org
+S:	Maintained
+F:	scripts/dev-needs.sh
+
 DEVICE DIRECT ACCESS (DAX)
 M:	Dan Williams <dan.j.williams@intel.com>
 M:	Vishal Verma <vishal.l.verma@intel.com>
diff --git a/scripts/dev-needs.sh b/scripts/dev-needs.sh
new file mode 100755
index 000000000000..454cc304fb44
--- /dev/null
+++ b/scripts/dev-needs.sh
@@ -0,0 +1,315 @@
+#! /bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020, Google LLC. All rights reserved.
+# Author: Saravana Kannan <saravanak@google.com>
+
+function help() {
+	cat << EOF
+Usage: $(basename $0) [-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.
+
+EOF
+}
+
+function dev_to_detail() {
+	local i=0
+	while [ $i -lt ${#OUT_LIST[@]} ]
+	do
+		local C=${OUT_LIST[i]}
+		local S=${OUT_LIST[i+1]}
+		local D="'$(detail_chosen $C $S)'"
+		if [ ! -z "$D" ]
+		then
+			# This weirdness is needed to work with toybox when
+			# using the -t option.
+			printf '%05u\t%s\n' ${i} "$D" | tr -d \'
+		fi
+		i=$((i+2))
+	done
+}
+
+function already_seen() {
+	local i=0
+	while [ $i -lt ${#OUT_LIST[@]} ]
+	do
+		if [ "$1" = "${OUT_LIST[$i]}" ]
+		then
+			# if-statement treats 0 (no-error) as true
+			return 0
+		fi
+		i=$(($i+2))
+	done
+
+	# if-statement treats 1 (error) as false
+	return 1
+}
+
+# Return 0 (no-error/true) if parent was added
+function add_parent() {
+
+	if [ ${ALLOW_PARENTS} -eq 0 ]
+	then
+		return 1
+	fi
+
+	local CON=$1
+	# $CON could be a symlink path. So, we need to find the real path and
+	# then go up one level to find the real parent.
+	local PARENT=$(realpath $CON/..)
+
+	while [ ! -e ${PARENT}/driver ]
+	do
+		if [ "$PARENT" = "/sys/devices" ]
+		then
+			return 1
+		fi
+		PARENT=$(realpath $PARENT/..)
+	done
+
+	CONSUMERS+=($PARENT)
+	OUT_LIST+=(${CON} ${PARENT})
+	return 0
+}
+
+# Return 0 (no-error/true) if one or more suppliers were added
+function add_suppliers() {
+	local CON=$1
+	local RET=1
+
+	if [ ${ALLOW_DEVLINKS} -eq 0 ]
+	then
+		return 1
+	fi
+
+	SUPPLIER_LINKS=$(ls -1d $CON/supplier:* 2>/dev/null)
+	for SL in $SUPPLIER_LINKS;
+	do
+		SYNC_STATE=$(cat $SL/sync_state_only)
+
+		# sync_state_only links are proxy dependencies.
+		# They can also have cycles. So, don't follow them.
+		if [ "$SYNC_STATE" != '0' ]
+		then
+			continue
+		fi
+
+		SUPPLIER=$(realpath $SL/supplier)
+
+		if [ ! -e $SUPPLIER/driver -a ${ALLOW_NO_DRIVER} -eq 0 ]
+		then
+			continue
+		fi
+
+		CONSUMERS+=($SUPPLIER)
+		OUT_LIST+=(${CON} ${SUPPLIER})
+		RET=0
+	done
+
+	return $RET
+}
+
+function detail_compat() {
+	f=$1/of_node/compatible
+	if [ -e $f ]
+	then
+		echo -n $(cat $f)
+	else
+		echo -n $1
+	fi
+}
+
+function detail_module() {
+	f=$1/driver/module
+	if [ -e $f ]
+	then
+		echo -n $(basename $(realpath $f))
+	else
+		echo -n $1
+	fi
+}
+
+function detail_driver() {
+	f=$1/driver
+	if [ -e $f ]
+	then
+		echo -n $(basename $(realpath $f))
+	else
+		echo -n $1
+	fi
+}
+
+function detail_fwnode() {
+	f=$1/firmware_node
+	if [ ! -e $f ]
+	then
+		f=$1/of_node
+	fi
+
+	if [ -e $f ]
+	then
+		echo -n $(realpath $f)
+	else
+		echo -n $1
+	fi
+}
+
+function detail_graphviz() {
+	if [ "$2" != "ROOT" ]
+	then
+		echo -n "\"$(basename $2)\"->\"$(basename $1)\""
+	else
+		echo -n "\"$(basename $1)\""
+	fi
+}
+
+function detail_tsort() {
+	echo -n "\"$2\" \"$1\""
+}
+
+function detail_device() { echo -n $1; }
+
+alias detail=detail_device
+ALLOW_NO_DRIVER=0
+ALLOW_DEVLINKS=1
+ALLOW_PARENTS=1
+
+while [ $# -gt 0 ]
+do
+	ARG=$1
+	case $ARG in
+		--help)
+			help
+			exit 0
+			;;
+		-c)
+			alias detail=detail_compat
+			;;
+		-m)
+			alias detail=detail_module
+			;;
+		-d)
+			alias detail=detail_driver
+			;;
+		-f)
+			alias detail=detail_fwnode
+			;;
+		-g)
+			alias detail=detail_graphviz
+			;;
+		-t)
+			alias detail=detail_tsort
+			;;
+		--allow-no-driver)
+			ALLOW_NO_DRIVER=1
+			;;
+		--exclude-devlinks)
+			ALLOW_DEVLINKS=0
+			;;
+		--exclude-parents)
+			ALLOW_PARENTS=0
+			;;
+		*)
+			# Stop at the first argument that's not an option.
+			break
+			;;
+	esac
+	shift
+done
+
+function detail_chosen() {
+	detail $1 $2
+}
+
+if [ $# -eq 0 ]
+then
+	help
+	exit 1
+fi
+
+CONSUMERS=($@)
+OUT_LIST=()
+
+# Do a breadth first, non-recursive tracking of suppliers. The parent is also
+# considered a "supplier" as a device can't probe without its parent.
+i=0
+while [ $i -lt ${#CONSUMERS[@]} ]
+do
+	CONSUMER=$(realpath ${CONSUMERS[$i]})
+	i=$(($i+1))
+
+	if already_seen ${CONSUMER}
+	then
+		continue
+	fi
+
+	# If this is not a device with a driver, we don't care about its
+	# suppliers.
+	if [ ! -e ${CONSUMER}/driver -a ${ALLOW_NO_DRIVER} -eq 0 ]
+	then
+		continue
+	fi
+
+	ROOT=1
+
+	# Add suppliers to CONSUMERS list and output the consumer details.
+	#
+	# We don't need to worry about a cycle in the dependency chain causing
+	# infinite loops. That's because the kernel doesn't allow cycles in
+	# device links unless it's a sync_state_only device link. And we ignore
+	# sync_state_only device links inside add_suppliers.
+	if add_suppliers ${CONSUMER}
+	then
+		ROOT=0
+	fi
+
+	if add_parent ${CONSUMER}
+	then
+		ROOT=0
+	fi
+
+	if [ $ROOT -eq 1 ]
+	then
+		OUT_LIST+=(${CONSUMER} "ROOT")
+	fi
+done
+
+# Can NOT combine sort and uniq using sort -suk2 because stable sort in toybox
+# isn't really stable.
+dev_to_detail | sort -k2 -k1 | uniq -f 1 | sort | cut -f2-
+
+exit 0
-- 
2.28.0.402.g5ffc5be6b7-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] scripts/dev-needs: Add script to list device dependencies
  2020-09-01 22:48 [PATCH v1] scripts/dev-needs: Add script to list device dependencies Saravana Kannan
@ 2020-10-27 10:11 ` Geert Uytterhoeven
  2020-10-27 17:30   ` Saravana Kannan
  0 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2020-10-27 10:11 UTC (permalink / raw)
  To: Saravana Kannan
  Cc: Greg Kroah-Hartman, Rob Herring, Nicolas Saenz Julienne,
	Android Kernel Team, Linux Kernel Mailing List

Hi Saravana,

On Wed, Sep 2, 2020 at 12:51 AM Saravana Kannan <saravanak@google.com> 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

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

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] scripts/dev-needs: Add script to list device dependencies
  2020-10-27 10:11 ` Geert Uytterhoeven
@ 2020-10-27 17:30   ` Saravana Kannan
  2020-10-27 18:09     ` Geert Uytterhoeven
  0 siblings, 1 reply; 5+ messages in thread
From: Saravana Kannan @ 2020-10-27 17:30 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Rob Herring, Nicolas Saenz Julienne,
	Android Kernel Team, Linux Kernel Mailing List

On Tue, Oct 27, 2020 at 3:12 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Saravana,
>
> On Wed, Sep 2, 2020 at 12:51 AM Saravana Kannan <saravanak@google.com> 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.

>
> 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?

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

> Which shell should I use?

I've tested with toybox and bash.

-Saravana

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] scripts/dev-needs: Add script to list device dependencies
  2020-10-27 17:30   ` Saravana Kannan
@ 2020-10-27 18:09     ` Geert Uytterhoeven
  2020-10-27 18:23       ` Saravana Kannan
  0 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2020-10-27 18:09 UTC (permalink / raw)
  To: Saravana Kannan
  Cc: Greg Kroah-Hartman, Rob Herring, Nicolas Saenz Julienne,
	Android Kernel Team, Linux Kernel Mailing List

Hi Saravana,

On Tue, Oct 27, 2020 at 6:31 PM Saravana Kannan <saravanak@google.com> wrote:
> On Tue, Oct 27, 2020 at 3:12 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > On Wed, Sep 2, 2020 at 12:51 AM Saravana Kannan <saravanak@google.com> 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

> > 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.

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

> 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

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] scripts/dev-needs: Add script to list device dependencies
  2020-10-27 18:09     ` Geert Uytterhoeven
@ 2020-10-27 18:23       ` Saravana Kannan
  0 siblings, 0 replies; 5+ messages in thread
From: Saravana Kannan @ 2020-10-27 18:23 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Rob Herring, Nicolas Saenz Julienne,
	Android Kernel Team, Linux Kernel Mailing List

On Tue, Oct 27, 2020 at 11:09 AM Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
>
> Hi Saravana,
>
> On Tue, Oct 27, 2020 at 6:31 PM Saravana Kannan <saravanak@google.com> wrote:
> > On Tue, Oct 27, 2020 at 3:12 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > On Wed, Sep 2, 2020 at 12:51 AM Saravana Kannan <saravanak@google.com> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-27 18:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-01 22:48 [PATCH v1] scripts/dev-needs: Add script to list device dependencies Saravana Kannan
2020-10-27 10:11 ` Geert Uytterhoeven
2020-10-27 17:30   ` Saravana Kannan
2020-10-27 18:09     ` Geert Uytterhoeven
2020-10-27 18:23       ` Saravana Kannan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).