[SOLVED] [LIME2] - How to power on/off when on battery in Linux?

Started by hiol, May 12, 2016, 02:44:46 PM

Previous topic - Next topic

hiol

Hi,

I have a LIME2-4GB-rev-c and It needs to work on battery (hand held device).  I know that if I press the power button for at least 5 seconds the board will be powered on but I don't know how to turn it off properly because if I hold down the power button for at least 5 seconds when booted nothing happens and the board doesn't shutdown. ¿?

I'm using igor's debian image.

JohnS

Sounds like the software isn't doing the right thing.  Try another image / debug it.  Have a look at kernel log etc to see what event happens on pressing the button where you wish it would go off.

John

hiol

Hi JohnS,

I've been working in this issue today and how I'm a noob with this SBC I've been discovering other issues as well ... :)

1-I made a patch to make LIME2 no autostart when powered off. I need to pull request it.
2-I'm going to fix autostart when I connect the power (when battery in?).
3-Next I'll try to fix this button issue.

So there are open several issues and I just made connection with uart so I think I can fix them "easily".

Anyway I can see in the debug-tty:
...
U-Boot 2011.09-rc1-00000-gf75abad-dirty (Oct 21 2013 - 18:44:22) Allwinner Technology
CPU:   SUNXI Family
Board: A20-Cubietruck
....

That puzzles me cause I've compiled & installed several times the latest u-boot or at least that's what I think I did (using Igor lib). :P
And I'm working with a LIME2 not a Cubietruck... :S
https://github.com/igorpecovnik/lib


Cheers

hiol

What a pain!!

I thought "there is something called KGDB that I've read thousand times that works the same as gdb, so it must be a piece of cake to debug the kernel then". What a joke man.

No WAY mainly cause I can't get it to work reliable with agent-proxy/kdmx via UART ... A total pain in the a**! :S

So it seems you have to debug with printks cause Linus doesn't like debuggers. o_O

Four days struggling with igor framework, kernel compilation, u-boot enviroment, tmuxinator madness and so on and on and on and finally I have to resign and use printks. :(((

Mental health advise: Do not try to use kgdb!.

JohnS

Not much point posting that on here.  Try a more appropriate place but expect to be asked to help rather than complain.

John

hiol

Hi,

Sorry for my moaning but I was really frustrated cause I don't have much time to work in this kind of issues.

I'm trying today with the olimex official's jessie image and same issue here. I hold the power button down and nothing happens.

It's very important to me to power on/off the SBC with one button.

Cheers

hiol

Hi,

I made a quick script:


#!/bin/bash
#Read lime2 power button pressed
# pressed (+1 actual), jack power insert (+2 actual)
TMP=/dev/shm/.poweroff

read _ actual <<< $(grep count /proc/irq/32/spurious)
[[ ! -e $TMP ]] && echo $actual > $TMP
count=$(<$TMP)
(( $actual == $count + 1 )) && echo "will halt -p"
echo $actual > $TMP


The next logical step will be just use inotify.

I have tested the power button to boot after using "halt -p" or "shutdown -h now" and it works, halt alone doesn't work as I thought.


soenke

i think it powers down if you hold the power button for more than 5 seconds.



soenke

actually, i just tested it with my Lime2 and it works. I hold down the PWR-Button for about 5-6 Seconds and it switches off.

hiol

No luck here, I tested it with Igor's and Olimex's images. :D

It's working now with my solution.

powerbutton.sh:

!/bin/bash
#Monitor LIME2 power button and shutdown down the system when pressed
#count +1 -> pressed button/jack power connected
#count +2 -> jack power released

SHR=/dev/shm/.poweroff
IRQ=/proc/irq/32/spurious
BAT=/sys/class/power_supply/battery/status

#Clean env
rm -f $SHR
read status < $BAT

#Procfs doesn't work with inotify
while true; do
    read _ actual <<< $(grep count $IRQ)
    [[ ! -e $SHR ]] && echo $actual > $SHR
    count=$(<$SHR)
    read status2 < $BAT
    chk=$(( $actual == $count + 1 ))
    (( $chk )) &&  [[ $status == $status2 ]] && halt -p
    #prevent timing issue
    [[ $status != $status2 ]] && ((actual++))
    status=$status2
    echo $actual > $SHR
    sleep 2
done


And the trivial systemd unit.

powerbutton.service:


[Unit]
Description=Power button monitor

[Service]
Type=simple
ExecStart=/root/powerbutton.sh
StandardOutput=null

[Install]
WantedBy=multi-user.target


Installation routine:


cp powerbutton.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable powerbutton.service
systemctl start powerbutton.service
systemctl status powerbutton.service




Cheers

soenke

Nice soltion, thanks for sharing! I might also make use of that at some time :)

hiol

Yes I think so.

Even Olimex should include it in their images. There is no other way for now!

I think holding down the power button makes a hard power off -> bad idea .


chradev

Hi hiol,

I have also work with Lime2-eMMC rev. E but never experienced such a behavior.
I am working with my own Armbian build for months but also try with official Armbian and Olimex images.

The board is powered on and off with clicking the power button without added by me staff for that.

It is very important to me as well so did you find the reason for this wrong behavior?

Best regards
Chris