Skip to content

Incorrect detection of OS architecture #45

@MBradbury

Description

@MBradbury

I have an oddly setup machine in which pynrfjprog is being used to interact with nRF52840s.

I have a machine which is reported as aarch64.

Linux iris2 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux

But actually is a 32 bit OS.

sudo dpkg-architecture -l
DEB_BUILD_ARCH=armhf
DEB_BUILD_ARCH_ABI=eabihf
DEB_BUILD_ARCH_BITS=32
DEB_BUILD_ARCH_CPU=arm
DEB_BUILD_ARCH_ENDIAN=little
DEB_BUILD_ARCH_LIBC=gnu
DEB_BUILD_ARCH_OS=linux
DEB_BUILD_GNU_CPU=arm
...

This causes a problem with loading the libhighlevelnrfjprog.so.

Traceback (most recent call last):
  File "/home/mbradbury/.local/lib/python3.9/site-packages/pynrfjprog/HighLevel.py", line 84, in __init__
    self.lib = ctypes.cdll.LoadLibrary(highlevel_nrfjprog_dll_path)
  File "/usr/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/mbradbury/.local/lib/python3.9/site-packages/pynrfjprog/lib_arm64/libhighlevelnrfjprog.so: wrong ELF class: ELFCLASS64

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "...", line 242, in ...
    with pynrfjprog.HighLevel.API() as api:
  File "/home/mbradbury/.local/lib/python3.9/site-packages/pynrfjprog/HighLevel.py", line 86, in __init__
    raise APIError(
pynrfjprog.APIError.APIError: An error was reported by NRFJPROG DLL: -151 NRFJPROG_SUB_DLL_COULD_NOT_BE_OPENED. Got error OSError('/home/mbradbury/.local/lib/python3.9/site-packages/pynrfjprog/lib_arm64/libhighlevelnrfjprog.so: wrong ELF class: ELFCLASS64') for library at /home/mbradbury/.local/lib/python3.9/site-packages/pynrfjprog/lib_arm64/libhighlevelnrfjprog.s

This is because lib_armhf should be used instead of lib_arm64.

In https://github.com/NordicSemiconductor/pynrfjprog/blob/master/pynrfjprog/Parameters.py#L35 it looks like a similar check for sys.maxsize is needed in the arm and aarch branches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions