WebThingsIO / zwave-adapter

Z-Wave adapter add-on for WebThings Gateway
Mozilla Public License 2.0
15 stars 20 forks source link

0.11.0 fails to start: ELF load command address/offset not properly aligned #146

Open benfrancis opened 6 months ago

benfrancis commented 6 months ago

I've generated a new release of the Z-wave add-on https://github.com/WebThingsIO/zwave-adapter/releases/tag/v0.11.0 and am currently testing it with gateway 1.1 running on a Raspberry Pi.

If I manually download and extract the zwave-adapter-0.11.0-linux-arm-v10.tgz file to ~/.webthings/addons/ I get the following error on start:

ERROR : zwave-adapter: Failed to start add-on zwave-adapter: Failed to load openzwave-shared: Error: /home/pi/.webthings/addons/zwave-adapter/node_modules/openzwave-shared/build/Release/openzwave_shared.node: ELF load command address/offset not properly aligned

Anyone have any suggestions what might be causing this?

benfrancis commented 6 months ago

Some advice from Dave Hylands (thank you Dave!):

the most likely cause is that the library was compiled for 4K pages, but is being run on a system with 16K pages. This can happen when running a 32-bit executable on a 64-bit RPi5 which apparently uses 16K pages.

Apparently the default kernel for RPi OS on the RPi5 uses 16K pages because it gives a performance increase.

You can check the page size using this.

grep -ir pagesize /proc/self/smaps | head -2

On my RPi5 running Ubuntu 24.04, I get this:

KernelPageSize: 4 kB MMUPageSize: 4 kB

If I run Raspberry Pi OS I get this:

KernelPageSize: 16 kB MMUPageSize: 16 kB

Apparently, if you link with this option (it should only affect the linking stage, not the compilation stage):

LDFLAGS += "-Wl,-z,max-page-size=16384"

then it should fix it to work with 4K & 16K pages. You may need to change LDFLAGS (I don't remember what the build system uses).

benfrancis commented 4 months ago

I can still reproduce this issue.

benfrancis commented 4 months ago

I added the line @dhylands suggested to the Makefile in the WebThingsIO fork of open-zwave in https://github.com/WebThingsIO/open-zwave/commit/3845b1bb217a1bac20d5020031b202a25ce9c5f0

I then reset the tag that the zwave-adapter pulls from and triggered a new build of the add-on https://github.com/WebThingsIO/zwave-adapter/actions/runs/9907323603

You can find the built packages here https://github.com/WebThingsIO/zwave-adapter/releases/tag/v0.11.0

Unfortunately if I manually download and extract the package from https://github.com/WebThingsIO/zwave-adapter/releases/download/v0.11.0/zwave-adapter-0.11.0-linux-arm-v10.tgz onto my Raspberry Pi, I still get the same error:

ERROR : zwave-adapter: Failed to start add-on zwave-adapter: Failed to load openzwave-shared: Error: /home/pi/.webthings/addons/zwave-adapter/node_modules/openzwave-shared/build/Release/openzwave_shared.node: ELF load command address/offset not properly aligned

However, I have noticed that if I execute the command Dave suggested on the Pi I actually get a 4kB page size.

$ grep -ir pagesize /proc/self/smaps | head -2
KernelPageSize:        4 kB
MMUPageSize:           4 kB

Note that this is on Raspbian Buster running on a Raspberry 4B, not the latest Raspberry Pi OS running on Raspberry Pi 5, since this is what the gateway images are still based on (just for this last 1.x release). Raspberry 5 is not yet officially supported since I don't think Raspbian Buster supports it. The gateway is currently expected to run under Raspbian Buster on a Raspberry Pi 1 to Raspberry Pi 4.

The way I'm reproducing the error is:

  1. Download and flash the gateway 1.1 image from https://webthings.io/gateway/ onto a Raspberry Pi 4
  2. Log into the command line on the gateway (username: pi, password: raspberry)
  3. Download and extract z-wave adapter 0.11
    • $ cd ~/.webthings/addons/
    • $ wget https://github.com/WebThingsIO/zwave-adapter/releases/download/v0.11.0/zwave-adapter-0.11.0-linux-arm-v10.tgz
    • $ mv zwave-adapter zwave-adapter-backup
    • $ mv package zwave-adapter
  4. Disable then enable the ZWave adapter add-on from the web interface (or reboot the Pi)
  5. Follow the logs
    • $ tail -f ~/.webthings/log/run-app.log

This version of the add-on should include openzwave built with the LDFLAGS Dave suggested.

Does anyone have any further suggestions?