Problem with autostart.sh on RPI-4 Libreelec 11.95.1 Omega

  • Hallo !

    I am using RPI-4 with powerboard from msldigital.com. This powerboard use autostart.ah for shutdown script. In previos version 20.03 was working normally and good. Bud when i update to version 11.195.1 Omega autostart.sh stop working. Is look like some folder are write protected.

  • Programi is OK ! I am sure. In version 11.0.6 was working normally. I know about chmod +x autostart.sh. Via ssh also has problem. Answrear after start is something like "can not create any folder and files".

    I put bellow complet scrtipt (program), The problem is in libreelec a i´I think.

    Thanks for any idea and help!


    The first part of the instructions below adds the main shutdown script for the RemotePi Board to the autostart.sh file, which enables the script to run when the OS starts.

    • Key in (mind the . in front of config !) :
      cd .config
      nano autostart.sh
    • Copy and paste (use shift+ins to paste in nano) the following into the nano editor window. If there is already something in the file, just add the following as the last lines. If the last line is exit 0, then place the following lines before that line.
      #!/bin/bash
      (/storage/.config/irswitch.sh)&
    • Press ctrl+x to exit the editor, y to confirm, enter to save the file
    • Key in
      chmod +x autostart.sh

    The next part creates the main RemotePi Board shutdown script. This script shuts down the OS safely, when the button on the RemotePi Board or the off button on the remote is pressed :

    • Key in
      nano irswitch.sh
    • Copy and paste the following text into the editor window
      #!/bin/bash
      # this is the GPIO pin receiving the shut-down signal
      GPIOpin1=14
      echo "$GPIOpin1" > /sys/class/gpio/export
      echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction
      while true; do
      sleep 1
      power=$(cat /sys/class/gpio/gpio$GPIOpin1/value)
      if [ $power != 0 ]; then
      echo "out" > /sys/class/gpio/gpio$GPIOpin1/direction
      echo "1" > /sys/class/gpio/gpio$GPIOpin1/value
      sleep 3
      poweroff
      fi
      done
    • Press ctrl+x to exit, y to confirm, enter to save the file
    • Key in
      chmod +x irswitch.sh

    The following additional script enables the RemotePi Board to cut off the power, after OpenElec / LibreELEC has been shut down from the on-screen menu.

    • Key in :
      nano shutdown.sh
    • Copy and paste the following contents
    • #!/bin/bash
      if [ "$1" != "reboot" ]; then
      GPIOpin=15
      GPIOpin1=14
      echo "$GPIOpin" > /sys/class/gpio/export
      # execute shutdown sequence on pin
      echo "out" > /sys/class/gpio/gpio$GPIOpin/direction
      echo "1" > /sys/class/gpio/gpio$GPIOpin/value
      usleep 125000
      echo "0" > /sys/class/gpio/gpio$GPIOpin/value
      usleep 200000
      echo "1" > /sys/class/gpio/gpio$GPIOpin/value
      usleep 400000
      echo "0" > /sys/class/gpio/gpio$GPIOpin/value
      # set GPIO 14 high to feedback shutdown to RemotePi Board
      # because the irswitch.sh has already been terminated
      echo "$GPIOpin1" > /sys/class/gpio/export
      echo "out" > /sys/class/gpio/gpio$GPIOpin1/direction
      echo "1" > /sys/class/gpio/gpio$GPIOpin1/value
      usleep 4000000
      fi
    • Press ctrl+x to exit, y to confirm, enter to save the file
    • Mark the script as executable by keying in
      chmod +x shutdown.sh
    • Reboot from the OpenElec or LibreELEC OS GUI.
    • After reboot you can use the RemotePi Board to power cycle OpenElec / LibreELEC
  • Why not checked the logs (journalctl -l) to see what is going on?

    Or to run /storage/.config/irswitch.sh maualy from console? Before doing it kill already running instance.

  • Can not running script because script need do create some new folder in folder sys/class/gpio and safe same data. I previous version Nexus was works normally. But in version OMEGA looks like all folders are write protected. This is not my scriot. This script use powerbutton module from msldigital.com and must shutdown rpi4 first and than dusconnected power for all system

  • The root cause of your script is that the usage of sysfs-gpio is deprecated. Now with kernels > 6.5 it was changed. You should first inspect which gpiochips are presented in your case.
    ls -la /sys/class/gpio

    Bash
    # ls -la /sys/class/gpio/
    total 0
    drwxr-xr-x    2 root     root             0 Feb 27 18:26 .
    drwxr-xr-x   50 root     root             0 Jan  1  1970 ..
    --w-------    1 root     root          4096 Apr  9 18:16 export
    lrwxrwxrwx    1 root     root             0 Feb 27 18:26 gpiochip512 -> ../../devices/platform/soc/fe200000.gpio/gpio/gpiochip512
    lrwxrwxrwx    1 root     root             0 Feb 27 18:26 gpiochip570 -> ../../devices/platform/soc/soc:firmware/soc:firmware:gpio/gpio/gpiochip570
    --w-------    1 root     root          4096 Apr  9 18:17 unexport

    I don't know if it's a fixed value for RPi < RPi5. For the RPi4 gpiochip512 seems to be the right thing. Since it's not 0 like before, you now need to add the offset 512 to your GPIO number:

    GPIOpin=15 -> GPIOpin=527
    GPIOpin1=14 -> GPIOpin1=526

    Edit:
    Calculation is right. Locally tested with GPIO24 and checked with gpioinfo.

    Edited 2 times, last by HarryH (April 9, 2024 at 11:16 PM).

  • Yes, you must only change the value to the new digits.

    • Bash: shutdown.sh
      #!/bin/bash
      if [ "$1" != "reboot" ]; then
        GPIOpin=527
        GPIOpin1=526
    • Bash: irswitch.sh
      #!/bin/bash
      # this is the GPIO pin receiving the shut-down signal
      GPIOpin1=526
  • Your are welcome.

    Please keep in mind that this option to set the GPIO pins in this simple way may be removed in a future kernel release. If this happens, the scripts will need to be switched to using pinctrl or migrated to Python3 scripts.

  • Your are welcome.

    Please keep in mind that this option to set the GPIO pins in this simple way may be removed in a future kernel release. If this happens, the scripts will need to be switched to using pinctrl or migrated to Python3 scripts.

    Do you know if there is an adaptation of the old scripts with pinctrl instead of gpio? I have a rpi5 and I think I must use pinctrl.

    Can you help me?

  • No, I don't know anything about such an adaptation. So far it was just a thought experiment on my part as to how things could continue to keep the project alive, since I don't have such a board.

    What do you get if you look for mapped gpiochips on your RPi5 ?
    ls -la /sys/class/gpio/

  • I think it's the same as Rpi4 on libreelec 12 but it doesn't work if i use GPIOpin=527 and GPIOpin1=526

  • In the meanwhile I have played a little bit with pinctrl. But it's now your part to test if it works.


    I think it's the same as Rpi4 on libreelec 12 but it doesn't work if i use GPIOpin=527 and GPIOpin1=526

    To make it complete, please check every listed chip:

    Code
    cat /sys/class/gpio/gpiochip512/ngpio
    cat /sys/class/gpio/gpiochip512/label

    The correct one has 58 on the RPi4 (but the pin count could be split/vary on RPi5) as the return value for ngpio and I'm assuming the label is "pinctrl-bcm2712" or something similar.

    EDIT:
    Benoitone I have added pull-down for the input pin, to be ensure the pin isn't floating.

    Edited 7 times, last by HarryH: Pulldown for the input pin added. Pull-Up/Down removed from output Pin names are more specific, to prevent usage of a wrong pin. (April 17, 2024 at 12:39 PM).

  • In the meanwhile I have played a little bit with pinctrl. But it's now your part to test if it works.

    :love:
    I have to do more tests when I get home, but it seems to be ok
    Thanks a lot