1

I'd like to display an LED which comes on as early as possible in the Pi's boot sequence to let me know things are progressing. I'd like to switch it off when the Pi has been appropriately shut down.

So, I suppose what I need to know is what are the first and last things I can programatically tap into on a Linux computer (RPi) when they boots up or is issued with a shutdown?

...or, perhaps what I really need to know is how to make my LEDon and LEDoff processes run first and last?

1

I believe that as part of the init process, one of the first initialization schemes is systemd.

If you would like to control an LED with a GPIO output as soon as the systemd phase is initialized - well, it appears you are out of look. The GPIOs are initialized after the systemd phase. The earliest you will be able to send an output with GPIO is when it is initialized.

Alternatively, you could create an init.d script which would run as soon as the script is discovered, but that may happen even later in the process. Someone on the Raspberry Pi forums (https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=24491) attempted to turn off the GPIO LEDs with an init.d script, but it appears to have not worked.

I believe it is possible to embed commands within GRUB to run as soon as GRUB is - however I'm afraid that the Pi does not utilize GRUB.

If you have experience with modifying the kernel, you could edit it - it runs before the Init process, but after the boot process.

You can read here (What is the boot sequence?) about the entire boot sequence, and you will see that certain files execute even before the kernels. They are binary files, and modification of them could be quite a challenge.

As for the shutdown LED, the system will unmount the devices and storage, meaning that you could make a script (it would have to be loaded into the RAM alongside the system) that will check when all processes except the main system and itself are ended, and that the storage is unmounted. However, you will need to make this script survive a shutdown command until a complete power halt.

1

Probably the easiest approach is to use Device Tree gpio-poweroff to set the state of a pin. This is probably the earliest stage of the boot process which you can control.

I have not actually done this myself, but others have used it to control power to the Pi.

I include dtparam=act_led_trigger=heartbeat in config.txt as the "heartbeat" makes a good indication that the Pi is running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.