Skip to content

Commit

Permalink
runners: jlink: win32: search for valid JLink.exe
Browse files Browse the repository at this point in the history
Since "JLink.exe" is also an executable distributed with JDK's, do an
explicit search on the standard SEGGER install directories for a JTAG
"JLink.exe" before falling back to whatever is first on PATH.

Fixes #51825.

Signed-off-by: Jordan Yates <[email protected]>
  • Loading branch information
JordanYates committed Jan 5, 2025
1 parent 4d60f0a commit 2eab62b
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion scripts/west_commands/runners/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'''Runner for debugging with J-Link.'''

import argparse
import glob
import ipaddress
import logging
import os
Expand All @@ -25,7 +26,31 @@
except ImportError:
MISSING_REQUIREMENTS = True

DEFAULT_JLINK_EXE = 'JLink.exe' if sys.platform == 'win32' else 'JLinkExe'
if sys.platform == 'win32':
# JLink.exe can collide with the JDK executable of the same name
# Look in the usual locations before falling back to $PATH
for root in [os.environ["ProgramFiles"], os.environ["ProgramFiles(x86)"]]: # noqa SIM112
# SEGGER folder can contain multiple versions such as:
# JLink_V796b
# JLink_V796t
# JLink_V798c
# Find the latest version
_versions = glob.glob(str(Path(root) / "SEGGER" / "JLink_V*"))
if len(_versions) == 0:
continue
_expected_jlink = Path(_versions[-1]) / "JLink.exe"
if not _expected_jlink.exists():
continue
DEFAULT_JLINK_EXE = str(_expected_jlink)
# Cleanup variables
del _versions
del _expected_jlink
break
else:
# Not found in the normal locations, hope that $PATH is correct
DEFAULT_JLINK_EXE = "JLink.exe"
else:
DEFAULT_JLINK_EXE = "JLinkExe"
DEFAULT_JLINK_GDB_PORT = 2331
DEFAULT_JLINK_RTT_PORT = 19021

Expand Down

0 comments on commit 2eab62b

Please sign in to comment.