Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu/arm64 compatibility #433

Closed
JMLX42 opened this issue Dec 21, 2019 · 35 comments
Closed

Ubuntu/arm64 compatibility #433

JMLX42 opened this issue Dec 21, 2019 · 35 comments

Comments

@JMLX42
Copy link

JMLX42 commented Dec 21, 2019

Hi,

could you please provide some pointers/documentation on how to use the PiJuice software on Ubuntu/arm64.

All the software prebuilt/stored in this repo seams to be targeting armhf:

$ file pijuice_cli
pijuice_cli: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=6e5b1ad06aa0ad2a337fb3b585e28beac17df547, not stripped

Thank you for your help,

@JMLX42 JMLX42 changed the title Ubuntu /arm64 compatibility Ubuntup/arm64 compatibility Dec 21, 2019
@JMLX42 JMLX42 changed the title Ubuntup/arm64 compatibility Ubuntu/arm64 compatibility Dec 21, 2019
@tvoverbeek
Copy link
Contributor

@promethe42 The only problem are the setuid wrappers for pijuice_cli.py and pijuice_gui.py.
You have to recompile these for 64 bit.
See https:/PiSupply/PiJuice/tree/master/Software/Source/Setuid-Wrapper for the source and the build script.

@JMLX42
Copy link
Author

JMLX42 commented Dec 23, 2019

I ran build-setuid-progs.sh (which produced no output). The following files were built:

  • pijuice_cli
  • pijuice_gui
$ ls
build-setuid-progs.sh  pijuice_cli  pijuice_gui  setuid-prog.c

but pijuice_cli won't run:

$ ./pijuice_cli                                                                                                                                                                                            stat: No such file or directory

"No such file or directory" yet the binary file does exist and has +x.

$ file pijuice_cli                                                                                                                                                                                          
pijuice_cli: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=b1a767832e5dc248368db7b6be27473c6f2ca6ab, for GNU/Linux 3.7.0, not stripped

@JMLX42
Copy link
Author

JMLX42 commented Dec 23, 2019

Found the problem: the generated binary tries to run /usr/bin/pijuice_cli.py which was not installed.
Fixed it with sudo /usr/bin/pijuice_cli.py.

Now pijuice_cli says:

$ ./pijuice_cli 
./pijuice_cli: /usr/bin/pijuice_cli.py has the wrong owner
The script should be owned by ubuntu.

@JMLX42
Copy link
Author

JMLX42 commented Dec 23, 2019

The following works:

sudo -u pijuice ./pijuice_cli

but it's kinda weird that I can't run it directly.

@tvoverbeek
Copy link
Contributor

@promethe42
The idea is that the pijuice service (pijuice_sys.py) and the gui an cli run as a non-privileged
separate user (user pijuice). This to prevent user scripts to run as root.
Originally the service (which executes the user scripts) was running as root.
The pijuice_cli and pijuice_gui wrappers should be suid pijuice.
Look at the post-install scripts for Raspbian: https:/PiSupply/PiJuice/blob/master/Software/Source/debian-base/postinst
and
https:/PiSupply/PiJuice/blob/master/Software/Source/debian-gui/postinst

@shawaj
Copy link
Member

shawaj commented Feb 22, 2020

@promethe42 did you get this working?

@MarkusLange
Copy link
Contributor

MarkusLange commented Mar 29, 2020

This little script worked for me,

on an fresh ubuntu server 64bit.

#!/bin/bash

sudo apt update
sudo apt install -y python3-smbus python3-pip python3-stdeb dh-systemd debhelper fakeroot python3-all
sudo pip3 install stem stdeb3

sudo git clone https:/PiSupply/PiJuice.git

cd $HOME/PiJuice/Software/Source/Setuid-Wrapper
sudo ./build-setuid-progs.sh
sudo cp p* $HOME/PiJuice/Software/Source/bin

cd $HOME/PiJuice/Software/Source/
sudo ./pckg-pijuice.sh

sudo cp $HOME/PiJuice/Software/Source/deb_dist_base/pi*.deb $HOME
sudo cp $HOME/PiJuice/Software/Source/deb_dist_gui/pi*.deb $HOME

sudo rm -rf PiJuice

sudo apt install python3-urwid lua5.3

@JohnMcW
Copy link

JohnMcW commented Mar 31, 2020

This little script worked for me,

on an fresh ubuntu server 64bit.

Worked for me to, but I've no idea what to do next. I just want to be able to run pijuice_cli

Thanks!

@tvoverbeek
Copy link
Contributor

@JohnMcW Install the pijuice-base and pijuice-gui deb packages which are in your home directory after running the script.

@MarkusLange
Copy link
Contributor

MarkusLange commented Apr 1, 2020

This little script worked for me,
on an fresh ubuntu server 64bit.

Worked for me to, but I've no idea what to do next. I just want to be able to run pijuice_cli

Thanks!

dpkg -i pijuice-base_1.6_all.deb
dpkg -i pijuice-gui_1.6_all.deb (only if you need the GUI for the desktop)

And add
dtoverlay=i2c-rtc,ds1307
in the /boot/config.txt

If you want to use the Timerfunction so sync the RTC with the System-Clock and check it

sudo hwclock -w
sudo hwclock -r

@JohnMcW
Copy link

JohnMcW commented Apr 4, 2020

Hi again,

I thought I’d check that the PiJuice works in Raspbian – it does and I also updated the firmware to 1.4

But I need to use Ubuntu 18.04.4 64bit for Arm – so starting with a clean updated install, I ran the script above OK, then:

dpkg -i pijuice-base_1.6_all.deb

This installed fine!

dpkg -i pijuice-gui_1.6_all.deb (only if you need the GUI for the desktop)

Don't need/want this.

And add
dtoverlay=i2c-rtc,ds1307
in the /boot/config.txt

Not done as firmware is 1.4

But when I run:
pijuice_cli

The GUI starts but errors with:

"No PiJuice found or Failed to use I2C bus. Check if I2C is enabled"

But:

sudo i2cdetect -y 1

Displays:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- 14 -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Any ideas?

@tvoverbeek
Copy link
Contributor

I do not know how i2c access is arranged on Ubuntu
On raspbian /dev/i2c-x has rw access for group i2c.
If a user belongs to the i2c group the user does not need to be root to access the i2c bus.
Since you use sudo to run i2cdetect it looks like normal users have no i2c access.
Have you tried with sudo pijuice-cli?

@JohnMcW
Copy link

JohnMcW commented Apr 4, 2020

Have you tried with sudo pijuice-cli?

No, but I have now and it works! Thank you!

@MarkusLange
Copy link
Contributor

And add
dtoverlay=i2c-rtc,ds1307
in the /boot/config.txt

Not done as firmware is 1.4

Firmware v1.4 is about dtoverlay=i2c-bcm2708

@JohnMcW
Copy link

JohnMcW commented Apr 8, 2020

Hi again. I'm trying to run a Python script - just using SW2 to test, but I'm getting an error (and I suspect it has something to do with permissions, so I thought I'd post here). This is the code:

#!/usr/bin/python3
import sentry_sdk
sentry_sdk.init("https://[email protected]/zzzzz")
sentry_sdk.capture_exception(Exception("Clicked button SW2 using Python3 "))

Note that I've obfuscated some parameters in the init call above.
This is using sentry.io - an error collection service
And this is the error:

Apr 08 20:25:54 ubuntu sudo[4210]:  pijuice : TTY=unknown ; PWD=/var/lib/pijuice ; USER=ubuntu ; COMMAND=/home/ubuntu/sentry/pjsentry.py SINGLE_PRESS SW2
Apr 08 20:25:54 ubuntu sudo[4210]: pam_unix(sudo:session): session opened for user ubuntu by (uid=0)
Apr 08 20:25:55 ubuntu pijuice_sys.py[1358]: Traceback (most recent call last):
Apr 08 20:25:55 ubuntu pijuice_sys.py[1358]:   File "/home/ubuntu/sentry/pjsentry.py", line 2, in <module>
Apr 08 20:25:55 ubuntu pijuice_sys.py[1358]:     import sentry_sdk
Apr 08 20:25:55 ubuntu pijuice_sys.py[1358]: ModuleNotFoundError: No module named 'sentry_sdk'
Apr 08 20:25:55 ubuntu sudo[4210]: pam_unix(sudo:session): session closed for user ubuntu

The script is executable and works fine when run manually.

Any ideas?

@tvoverbeek
Copy link
Contributor

@JohnMcW The error log shows that pijuice_sys.py (= the pijuice service) has started your user function, but the import sentry_sdk statement fails.
Remember the pijuice service is started as user pijuice by systemd.
My guess is that the entry_sdk module is not in the default python path.
Where is the module located? When you run it manually do you e.g. use environment variables to add to the python path?

@JohnMcW
Copy link

JohnMcW commented Apr 10, 2020

Hi again @tvoverbeek - a colleague helped me resolve this - all I need to do was install the sentry software as root. PiJuice is now successfully running Python scripts! However, I have a few more questions (hope it's OK to ask here).

  1. Does the PiJuice need to be powered directly for 'Min Charge'/'Wakeup on charge' to function correctly? It appears that it does:

GPIO POWERED

  • Remove power to Pi
  • “No power” is triggered
  • “Low charge” = SYS_FUNC_HALT_POW_OFF
  • This is triggered when “Min Charge” threshold is reached
  • Pi fully powers down
  • Reconnect power to Pi
  • Pi immediately powers up (undesired)
  • Pi immediately halts (but doesn’t fully power down and so get stuck here)
  • After a manual reboot, neither “Forced power off” or “Forced sys power off” are triggered

DIRECT POWERED

  • Remove power to Pi
  • “No power” is triggered
  • “Low charge” = SYS_FUNC_HALT_POW_OFF
  • This is triggered when “Min Charge” threshold is reached
  • Pi fully powers down
  • Reconnect power to Pi
  • Nothing happens immediately (desired)
  • Instead “Wakeup on charge” kicks in after the wakeup charge threshold is reached (desired)
  • However, neither “Forced power off” or “Forced sys power off” are triggered
  1. Why aren't “Forced power off” or “Forced sys power off” being triggered? Should they be and what's the difference between them.

  2. Is direct power to PiJuice required for the watchdog functionality? This post of yours suggests that it is. Also, is there an easier way to test?

Thank you

@tvoverbeek
Copy link
Contributor

Does the PiJuice need to be powered directly for 'Min Charge'/'Wakeup on charge' to function correctly? It appears that it does:

Yes, for obvious reasons. To control the 5V supply to the Pi the power has to come from the PiJuice.

Why aren't “Forced power off” or “Forced sys power off” being triggered? Should they be and what's the difference between them.

They are different from low charge and no power.
forced power off occurs when the battery cannot supply the current draw needed by the Pi.
Without anything programmed just let the Pi run on battery until it shuts off. This will be a 'forced power off'
Forced sys power off is the same thing for the extra load on the VSYS output on the P3 header and J3 connector.

.Is direct power to PiJuice required for the watchdog functionality? This post of yours suggests that it is. Also, is there an easier way to test?

As explained in that post the watchdog gets reset by each I2C transaction to the PiJuice, provided the watchdog is enabled. To test it you need to make sure that no I2C transactions are made to the PiJuice and the watchdog is enabled. My post gave a way to make this possible in a controlled way. If for some reason the Pi goes haywire (endless loop on all cores) the PiJuice watchdog would kick in (again only if enabled). For the PiJuice watchdog reboot to work powering the PiJuice is the safest way.

Note, the Pi has a built-in watchdog. See e.g. https://www.raspberrypi.org/forums/viewtopic.php?t=210974#p1458574.

@smallhacks
Copy link

Hello,

I managed to install pijujicebase on my Ubuntu 64-bit by following the script suggested by @MarkusLange.
Everything seems to work except pijuiceboot
-bash: /usr/bin/pijuiceboot: No such file or directory

It seems that the executable is still a 32-bit version:
/usr/bin/pijuiceboot: ELF 32-bit LSB executable, ARM

Do you know how to compile it for 64-bit?

Thank you!

@tvoverbeek
Copy link
Contributor

The source is here: https:/PiSupply/PiJuice/blob/master/Firmware/pijuiceboot.c
Just compile it on your 64-bit system. Ignore the comments in the header, libwebsockets is not used.

@smallhacks
Copy link

The source is here: https:/PiSupply/PiJuice/blob/master/Firmware/pijuiceboot.c
Just compile it on your 64-bit system. Ignore the comments in the header, libwebsockets is not used.

Thank you very much, it worked !

@MarkusLange
Copy link
Contributor

The source is here: https:/PiSupply/PiJuice/blob/master/Firmware/pijuiceboot.c
Just compile it on your 64-bit system. Ignore the comments in the header, libwebsockets is not used.

@tvoverbeek
May you can add
gcc pijuiceboot.c -Wall -o pijuiceboot
to the build-setuid-progs.sh so a new pijuiceboot would build anyway
and add my script nicely/some revision to

PiJuice/Software/OS Support/

as universal for all/other Pi OS

tvoverbeek added a commit that referenced this issue Aug 2, 2020
See issue #433 Make sure the executables (setuid wrappers and pijuiceboot)  are rebuild for 64-bit
@tvoverbeek
Copy link
Contributor

@MarkusLange Thanks for the suggestion. Updated the 64-bit instructions with a slightly modified version of your script.
Also used apt to install the local version, which will also install the dependencies.
Closing the issue now.

@MarkusLange
Copy link
Contributor

Thanks,

from #498 (comment) sudo apt install dh-python is missing in

Software/OS Support/ubuntu_server_64.MD

for Ubuntu 20.04

@tvoverbeek
Copy link
Contributor

@MarkusLange Added now.

@goodelyfe
Copy link

on Ubuntu 21.04 (Hirsute) the dh-systemd package has been completely removed, so it fails to compile there because of a missing dependency

@MarkusLange
Copy link
Contributor

@goodelyfe if @tvoverbeek removes the dependencies to dh-systemd there is a way, or you can try this and install an backport from dh-systemd from groovy (20.10) the last one who has it.

@goodelyfe
Copy link

@goodelyfe if @tvoverbeek removes the dependencies to dh-systemd there is a way, or you can try this and install an backport from dh-systemd from groovy (20.10) the last one who has it.

sudo apt-get install dh-systemd -t groovy ?

or would it be

sudo apt-get install dh-systemd -t groovy-backports

either way i get:

Reading package lists... Done
E: The value 'groovy-backports' is invalid for APT::Default-Release as such a release is not available in the sources

Reading package lists... Done
E: The value 'groovy' is invalid for APT::Default-Release as such a release is not available in the sources

@CybrHare
Copy link

CybrHare commented Oct 6, 2021

Has anyone happed to figure out how to get this to work on Ubuntu 21.04?

@MarkusLange
Copy link
Contributor

Has anyone happed to figure out how to get this to work on Ubuntu 21.04?

Look under this one Ubuntu 21.04 (Hirsute) the dh-systemd package has been completely removed, fails to compile there because of a missing dependency
...
The two dh-systemd-* utilities used (dh-systemd-enable, dh-systemd-start) are now included in package debhelper in Ubuntu 21.04
Before building the pijuice packages in the control file for pijuice-base (https:/PiSupply/PiJuice/blob/master/Software/Source/debian-base/control) in the Build-depends line (line 5) remove the dh-systemd (>= 1.5) entry.
Hopefully that allows you to build the packages.

New Line:
Build-Depends: python3-all (>= 3.5), debhelper (>= 9), i2c-tools, python3-smbus
...
Then the delivered script should work. May @tvoverbeek can remove it in general and we find a clue for the dh-systemd package that it only needed in Ubuntu 20.xx

@CybrHare
Copy link

CybrHare commented Oct 7, 2021

Thank you for the answer. I'll have to test it on the weekend. I have to say that I'm rather disappointed in how complicated it is to install the software for this device. For the cost of it compared to other UPS options I expected a little more robust installation process.

@MarkusLange
Copy link
Contributor

MarkusLange commented Oct 8, 2021

@CybrHare don't accuse @tvoverbeek for it the install-script for Ubuntu 64 is my fault it is not ready for 21.xx (works well for 20.xx). I don't know where the dh-systemd package went. Now I can confirm the install-script for Ubuntu 21.xx works if you change,
this:
sudo apt install -y python3-smbus python3-pip python3-stdeb dh-systemd dh-python debhelper fakeroot python3-all
to:
sudo apt install -y python3-smbus python3-pip python3-stdeb dh-python debhelper fakeroot python3-all

After you grep it from git (sudo git clone https:/PiSupply/PiJuice.git)
Change control in PiJuice/Software/Source/debian-base/control and PiJuice/Software/Source/debian-gui/control:
line 5 (remove the dh-systemd (>= 1.5) entry) to:
Build-Depends: python3-all (>= 3.5), debhelper (>= 9), i2c-tools, python3-smbus

Run the next steps unchanged.

@tvoverbeek
Copy link
Contributor

dh-systemd has been integrated into debhelper.
Already in buster dh-systemd ws a transitional package which depended on debhelper.
In bullseye this transitional package was removed.
See e.g. matrix-org/synapse#9073
I assume Ubuntu 21.xx is derived from Debian bullseye.

Anyay we will get the same problem when RaspberryPi OS moves to bullseye (with the same solution).

@tvoverbeek
Copy link
Contributor

@MarkusLange @CybrHare
Just removed the build dependency for dh-systemd.
As above the dh-systemd is an empty package in Buster just to make sure the debhelper package is installed.
dh-systemd was already superfluous in Buster.

@CybrHare
Copy link

CybrHare commented Oct 10, 2021

Thank you for the help. It's working now.

One brief note
sudo apt install ./pijuice-base_1.6_all.deb is now sudo apt install ./pijuice-base_1.7_all.deb

Same for the gui install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants