johnshearing
Posts: 13
Joined: Sun Jun 11, 2017 6:12 am

Loading Overlays Before GDM3 Login Screen

Tue Oct 10, 2017 6:43 am

Hi All,
I am using a custom overlay such that the pi will halt when gpio-5 is shorted to gpio-6. Then a second overlay (gpio-poweroff) lets my UPS know it is safe to remove power. Config.txt calls the overlays. The overlays work great except if the user doesn't log in - in other words, when the GDM3 login screen is showing. In that case shorting pin 5 to pin 6 does nothing. Is there a way to make the overlays work before login the way they do after login has been accomplished? Or in the alternative, is there another way to use a gpio pin to initiate a system halt at the GDM3 login?
Thanks, John

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1417
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Loading Overlays Before GDM3 Login Screen

Wed Oct 11, 2017 9:38 am

Overlays requested in config.txt are applied before the ARMs run their first instructions, so your problem lies elsewhere.

Have you tried the gpio-shutdown overlay?

Code: Select all

pi@raspberrypi ~ $ dtoverlay -h gpio-shutdown
Name:   gpio-shutdown

Info:   Initiates a shutdown when GPIO pin changes. The given GPIO pin
        is configured as an input key that generates KEY_POWER events.
        This event is handled by systemd-logind by initiating a
        shutdown. Systemd versions older than 225 need an udev rule
        enable listening to the input device:

                ACTION!="REMOVE", SUBSYSTEM=="input", KERNEL=="event*", \
                        SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", \
                        ATTRS{keys}=="116", TAG+="power-switch"

        This overlay only handles shutdown. After shutdown, the system
        can be powered up again by driving GPIO3 low. The default
        configuration uses GPIO3 with a pullup, so if you connect a
        button between GPIO3 and GND (pin 5 and 6 on the 40-pin header),
        you get a shutdown and power-up button.

Usage:  dtoverlay=gpio-shutdown,<param>=<val>

Params: gpio_pin                GPIO pin to trigger on (default 3)

        active_low              When this is 1 (active low), a falling
                                edge generates a key down event and a
                                rising edge generates a key up event.
                                When this is 0 (active high), this is
                                reversed. The default is 1 (active low).

        gpio_pull               Desired pull-up/down state (off, down, up)
                                Default is "up".

                                Note that the default pin (GPIO3) has an
                                external pullup.
Because Raspbian system is at version 215 you will need to follow the advice and create the udev rule:

Code: Select all

pi@raspberrypi ~ $ cat > 98-power-switch.rules
ACTION!="REMOVE", SUBSYSTEM=="input", KERNEL=="event*", \
                        SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", \
                        ATTRS{keys}=="116", TAG+="power-switch"
pi@raspberrypi ~ $ sudo mv 98-power-switch.rules /etc/udev/rules.d/
Then add the following to config.txt:

Code: Select all

dtoverlay gpio-shutdown
Finally, reboot the system and try the power button. It should work for GUI and console logins, whether or not they are set to auto-login.

johnshearing
Posts: 13
Joined: Sun Jun 11, 2017 6:12 am

Re: Loading Overlays Before GDM3 Login Screen

Thu Oct 12, 2017 2:24 am

Hi PhilE ,

>Have you tried the gpio-shutdown overlay?<

I think so. I didn't realize it was probably sitting on the pi already so I downloaded it as follows:

Code: Select all

$ wget http://www.stderr.nl/static/files/Hardware/RaspberryPi/gpio-shutdown-overlay.dts

This is the contents of the download:

Code: Select all

// Definitions for gpio-poweroff module
/dts-v1/;
/plugin/;

// This overlay sets up an input device that generates KEY_POWER events
// when a given GPIO pin changes. It defaults to using GPIO3, which can
// also be used to wake up (start) the Rpi again after shutdown. Since
// wakeup is active-low, this defaults to active-low with a pullup
// enabled, but all of this can be changed using overlay parameters (but
// note that GPIO3 has an external pullup on at least some boards).

/ {
	compatible = "brcm,bcm2708";

	fragment@0 {
		// Configure the gpio pin controller
		target = <&gpio>;
		__overlay__ {
			// Define a pinctrl state, that sets up the gpio
			// as an input with a pullup enabled. This does
			// not take effect by itself, only when referenced
			// by a "pinctrl client", as is done below. See:
			//   https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
			//   https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
			pin_state: shutdown_button_pins {
				brcm,pins = <3>; // gpio number
				brcm,function = <0>; // 0 = input, 1 = output
				brcm,pull = <2>; // 0 = none, 1 = pull down, 2 = pull up
			};
		};
	};
	fragment@1 {
		// Add a new device to the /soc devicetree node
		target-path = "/soc";
		__overlay__ {
			shutdown_button {
				// Let the gpio-keys driver handle this device. See:
				// https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt
				compatible = "gpio-keys";

				// Declare a single pinctrl state (referencing the one declared above) and name it
				// default, so it is activated automatically.
				pinctrl-names = "default";
				pinctrl-0 = <&pin_state>;

				// Enable this device
				status = "okay";

				// Define a single key, called "shutdown" that monitors the gpio and sends KEY_POWER
				// (keycode 116, see
				// https://github.com/torvalds/linux/blob/v4.12/include/uapi/linux/input-event-codes.h#L190)
				button: shutdown {
					label = "shutdown";
					linux,code = <116>; // KEY_POWER
					gpios = <&gpio 3 1>;
				};
			};
		};
	};

	// This defines parameters that can be specified when loading
	// the overlay. Each foo = line specifies one parameter, named
	// foo. The rest of the specification gives properties where the
	// parameter value is inserted into (changing the values above
	// or adding new ones).
	__overrides__ {
		// Allow overriding the GPIO number.
		gpio_pin = <&button>,"gpios:4",
		           <&pin_state>,"brcm,pins:0";

		// Allow changing the internal pullup/down state. 0 = none, 1 = pulldown, 2 = pullup
		// Note that GPIO3 and GPIO2 are the I2c pins and have an external pullup (at least
                // on some boards).
		gpio_pull = <&pin_state>,"brcm,pull:0";

		// Allow setting the active_low flag. 0 = active high, 1 = active low
		active_low = <&button>,"gpios:8";
	};

};

Following the instructions at the following website:
http://www.stderr.nl/Blog/Hardware/Rasp ... utton.html


I compiled it as follows:

Code: Select all

$ dtc -@ -I dts -O dtb -o gpio-shutdown.dtbo gpio-shutdown-overlay.dts

Then I moved the compiled file to the appropriate directory as follows:

Code: Select all

$ sudo cp gpio-shutdown.dtbo /boot/overlays/

Next the following line was added to /boot/config.txt:

Code: Select all

dtoverlay=gpio-shutdown

Then a file called: /etc/udev/rules.d/99-gpio-power.rules was created with the following text:

Code: Select all

ACTION!="REMOVE", SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", \
    DRIVERS=="gpio-keys", ATTRS{keys}=="116", TAG+="power-switch"
Now when the pi is running and I short pins 5 and 6 on the pi2 40 pin header, the system halts.
But at the GDM3 login screen nothing happens.


Now I want to try it following your instructions exactly.

Can you please tell me were I can find the source code for the overlay gpio-shutdown?
Or in the alternative can you please tell me where to find the compiled version?
Remembering that I overwrote the original overlay with a custom overlay of the same name - getting a clean copy is a precaution in case the code above is the problem.

Other than that, I think I have enough information to follow your instructions exactly.

Thanks so much for your help,
John

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1417
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Loading Overlays Before GDM3 Login Screen

Thu Oct 12, 2017 9:17 am

By the looks of it your overlay is the same, but you can download the official dtbo here.

I now think everything is working as it ought to except that GDM3 is blocking the power button in some way, but you could test it using Raspbian. I found this blog post - does it help?

johnshearing
Posts: 13
Joined: Sun Jun 11, 2017 6:12 am

Re: Loading Overlays Before GDM3 Login Screen

Sat Oct 14, 2017 1:05 am

Hi PhilE

I followed your lead to the dconf database and tried different settings that I thought might cause GDM3 to release the GPIO pins.
The post at the following link was very helpful
https://askubuntu.com/questions/22313/w ... o-i-use-it

Unfortunatly, none of the changes made a difference.

I see that you would have me change the following file:
sudo mv 98-power-switch.rules /etc/udev/rules.d/
whereas I previously I had put modified the following file:
/etc/udev/rules.d/99-gpio-power.rules

If following that recommendation doesn't work then the circuitry I have in place disables the power button when the GDM3 login screen is active. This will force the user to halt the machine at the menu before removing power. It's an extra step for the user but I will have to live with that unless perhaps I can get a hold of the source code for GDM3 and modify it for this situation.

I wonder if that is an option. I think it's open source.

Anyway, the information you provided has kept me from chasing my tail.
Thanks so much

Return to “Device Tree”

Who is online

Users browsing this forum: No registered users and 2 guests