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

Add libjaylink #28555

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9c92894
Add libjaylink
MementoRC Dec 12, 2024
a986174
(ref) don't skip win/osx!
MementoRC Dec 12, 2024
7545932
(ref) no need for libtool
MementoRC Dec 12, 2024
8eaf055
(ref) remove deprecation fails on win
MementoRC Dec 13, 2024
31ea8aa
(ref) remove deprecation fails on win
MementoRC Dec 13, 2024
77c1cd8
(ref) remove deprecation fails on win
MementoRC Dec 13, 2024
d65d735
(ref) SOCKET to int
MementoRC Dec 13, 2024
cde31bd
(ref) SOCKET to int
MementoRC Dec 13, 2024
2248d57
(ref) SOCKET to int
MementoRC Dec 13, 2024
0e51c82
(ref) size_t to unit8_t
MementoRC Dec 13, 2024
d526252
(fix) wrong patch path
MementoRC Dec 13, 2024
0cc435d
(fix) wrong patch path
MementoRC Dec 13, 2024
2446838
(fix) wrong patch path
MementoRC Dec 13, 2024
14c4513
(fix) strutil.c
MementoRC Dec 13, 2024
80a5838
(fix) wrong name in patch
MementoRC Dec 13, 2024
9c507c6
(fix) transport_tcp.c
MementoRC Dec 13, 2024
34cd38c
(fix) transport_usb.c
MementoRC Dec 13, 2024
044ff88
(fix) uninitialized
MementoRC Dec 13, 2024
0bb50d3
(fix) add binutils for strip.exe
MementoRC Dec 13, 2024
edbb05e
(fix) enable .lib creation
MementoRC Dec 13, 2024
1f7e02c
(fix) windows high-maintenance :(
MementoRC Dec 13, 2024
0627606
(fix) recipe lint?
MementoRC Dec 13, 2024
e442aa7
(fix) recipe lint?
MementoRC Dec 13, 2024
b6472a9
(fix) bad patch
MementoRC Dec 13, 2024
5adc715
(fix) bad patch
MementoRC Dec 13, 2024
bd3bf52
(fix) build both unix/win style
MementoRC Dec 13, 2024
e93fb42
(fix) bad patch
MementoRC Dec 13, 2024
5d85187
(fix) bad patch
MementoRC Dec 13, 2024
9d7f993
(fix) bad patch
MementoRC Dec 13, 2024
a05cab3
(fix) bad patch
MementoRC Dec 14, 2024
54d7a5d
(fix) install in Library
MementoRC Dec 14, 2024
b1f7d6f
(fix) install in Library
MementoRC Dec 14, 2024
589a0d1
(fix) create non-versioned .dll
MementoRC Dec 14, 2024
b9f0a85
(fix) rattler test details
MementoRC Dec 14, 2024
123a405
(ref) add run_exports
MementoRC Dec 15, 2024
b42966a
(fix) max_pin -> upper_bound
MementoRC Dec 15, 2024
609c427
(fix) add mingw .dll.a
MementoRC Dec 17, 2024
6f7921f
(fix) build DLL
MementoRC Dec 19, 2024
dcdac23
(fix) truncated patch. DLL
MementoRC Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions recipes/libjaylink/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@echo off
setlocal enabledelayedexpansion
set SRC_DIR=%SRC_DIR%
set PKG_NAME=%PKG_NAME%
set PREFIX=%PREFIX%

pushd !SRC_DIR! || exit /b 1
:: Get current and age from meson
for /f "tokens=2 delims=: " %%i in ('meson introspect build-!PKG_NAME! --projectinfo ^| findstr "current"') do set CURRENT=%%i
set CURRENT=%CURRENT:,=%
for /f "tokens=2 delims=: " %%i in ('meson introspect build-!PKG_NAME! --projectinfo ^| findstr "age"') do set AGE=%%i
set AGE=%AGE:,=%
set /a VERSION=CURRENT-AGE

meson setup build-!PKG_NAME! ^
--prefix=!PREFIX!\Library ^
--buildtype=release ^
--strip ^
--backend=ninja ^
--default-library=shared ^
-Dc_args="-D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -DBUILDING_DLL"
if errorlevel 1 exit 1

meson compile -C build-!PKG_NAME!
if errorlevel 1 exit 1

meson install -C build-!PKG_NAME!
if errorlevel 1 exit 1

:: Create non-versioned .dll
copy /Y !PREFIX!\Library\bin\libjaylink-%VERSION%.dll !PREFIX!\Library\bin\libjaylink.dll > nul
if errorlevel 1 exit 1

copy /Y !PREFIX!\Library\bin\jaylink-%VERSION%.dll !PREFIX!\Library\bin\jaylink.dll > nul
if errorlevel 1 exit 1

:: Create .dll.a file to clearly distinguish Mingw from MSVC builds
del !PREFIX!\Library\lib\libjaylink.lib

dlltool -d libjaylink\jaylink.def ^
--dllname libjaylink-%VERSION%.dll ^
--output-lib libjaylink-%VERSION%.dll.a
if errorlevel 1 exit 1

copy /Y libjaylink-%VERSION%.dll.a !PREFIX!\Library\lib\libjaylink-%VERSION%.dll.a > nul
if errorlevel 1 exit 1

:: Add non-version since it references the .dll
dlltool -d libjaylink\jaylink.def ^
--dllname libjaylink.dll ^
--output-lib libjaylink.dll.a
if errorlevel 1 exit 1

copy /Y libjaylink.dll.a !PREFIX!\Library\lib\libjaylink.dll.a > nul
if errorlevel 1 exit 1
popd || exit /b 1
14 changes: 14 additions & 0 deletions recipes/libjaylink/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euxo pipefail

pushd "${SRC_DIR}" || exit 1
meson setup build-${PKG_NAME} \
--prefix="${PREFIX}" \
--buildtype=release \
--default-library=shared \
--strip \
--backend=ninja
meson compile -C build-${PKG_NAME}
meson install -C build-${PKG_NAME}
popd || exit 1
69 changes: 69 additions & 0 deletions recipes/libjaylink/helpers/verify_dll_def.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import subprocess
import re
import sys


def get_dll_exports(dll_path):
try:
output = subprocess.check_output(['objdump', '-p', dll_path], text=True, stderr=subprocess.STDOUT)
exports = set()
in_export_section = False
for line in output.splitlines():
if '[Ordinal/Name Pointer] Table' in line:
in_export_section = True
continue
if in_export_section:
line = line.strip()
if not line:
continue
# Format: [ number] function_name
if ']' in line:
exports.add(line.split(']')[1].strip())

print("Found exports:", exports)
return exports
except subprocess.CalledProcessError as e:
print("Error running objdump:", e)
return set()

def get_def_exports(def_path):
with open(def_path) as f:
exports = set()
for line in f:
line = line.strip()
if line and not line.startswith(';') and 'EXPORTS' not in line:
exports.add(line.split()[0])
print("Found exports in .def file:", exports)
return exports


def compare_exports(dll_path, def_path):
print(f"Checking DLL: {dll_path}")
print(f"Against DEF: {def_path}")

dll_exports = get_dll_exports(dll_path)
def_exports = get_def_exports(def_path)

if not dll_exports:
print("ERROR: No exports found in DLL!")
return False

missing_in_dll = def_exports - dll_exports
# missing_in_def = dll_exports - def_exports # Don't check for extra DLL exports

if missing_in_dll:
print("ERROR: Functions in .def but not in DLL:", missing_in_dll)
return False

return True

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: verify_dll_def.py <dll_path> <def_path>")
sys.exit(1)

success = compare_exports(sys.argv[1], sys.argv[2])
if not success:
print("Validation FAILED")
sys.exit(1)
print("Validation PASSED")
117 changes: 117 additions & 0 deletions recipes/libjaylink/patches/add-jaylink.def.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
diff --git a/libjaylink/jaylink.def b/libjaylink/jaylink.def
new file mode 100644
index 0000000..f175c25
--- /dev/null
+++ b/libjaylink/jaylink.def
@@ -0,0 +1,111 @@
+EXPORTS
+ ; Core functions
+ jaylink_init
+ jaylink_exit
+ jaylink_library_has_cap
+
+ ; C2 interface functions
+ jaylink_c2_read_address
+ jaylink_c2_write_address
+ jaylink_c2_read_data
+ jaylink_c2_write_data
+
+ ; Device management functions
+ jaylink_get_devices
+ jaylink_free_devices
+ jaylink_device_get_host_interface
+ jaylink_device_get_serial_number
+ jaylink_device_get_usb_address
+ jaylink_device_get_usb_bus_ports
+ jaylink_device_get_ipv4_address
+ jaylink_device_get_mac_address
+ jaylink_device_get_hardware_version
+ jaylink_device_get_product_name
+ jaylink_device_get_nickname
+ jaylink_ref_device
+ jaylink_unref_device
+ jaylink_open
+ jaylink_close
+ jaylink_get_device
+ jaylink_get_firmware_version
+ jaylink_get_hardware_info
+ jaylink_get_counters
+ jaylink_get_hardware_version
+ jaylink_get_hardware_status
+ jaylink_get_caps
+ jaylink_get_extended_caps
+ jaylink_get_free_memory
+ jaylink_read_raw_config
+ jaylink_write_raw_config
+ jaylink_register
+ jaylink_unregister
+
+ ; Discovery functions
+ jaylink_discovery_scan
+
+ ; EMUCOM functions
+ jaylink_emucom_read
+ jaylink_emucom_write
+
+ ; Error handling functions
+ jaylink_strerror
+ jaylink_strerror_name
+
+ ; File I/O functions
+ jaylink_file_read
+ jaylink_file_write
+ jaylink_file_get_size
+ jaylink_file_delete
+
+ ; JTAG functions
+ jaylink_jtag_io
+ jaylink_jtag_clear_trst
+ jaylink_jtag_set_trst
+ jaylink_jtag_clear_tms
+ jaylink_jtag_set_tms
+ jaylink_jtag_clear_tck
+ jaylink_jtag_set_tck
+
+ ; Logging functions
+ jaylink_log_set_level
+ jaylink_log_get_level
+ jaylink_log_set_callback
+ jaylink_log_set_domain
+ jaylink_log_get_domain
+
+ ; String utility functions
+ jaylink_parse_serial_number
+ jaylink_hardware_type_string
+ jaylink_target_interface_string
+
+ ; SWD functions
+ jaylink_swd_io
+
+ ; SWO functions
+ jaylink_swo_start
+ jaylink_swo_stop
+ jaylink_swo_read
+ jaylink_swo_get_speeds
+
+ ; Target functions
+ jaylink_set_speed
+ jaylink_get_speeds
+ jaylink_select_interface
+ jaylink_get_available_interfaces
+ jaylink_get_selected_interface
+ jaylink_clear_reset
+ jaylink_set_reset
+ jaylink_set_target_power
+
+ ; Utility functions
+ jaylink_has_cap
+
+ ; Version functions
+ jaylink_version_package_get_major
+ jaylink_version_package_get_minor
+ jaylink_version_package_get_micro
+ jaylink_version_package_get_string
+ jaylink_version_library_get_current
+ jaylink_version_library_get_revision
+ jaylink_version_library_get_age
+ jaylink_version_library_get_string
26 changes: 26 additions & 0 deletions recipes/libjaylink/patches/add-jaylink.lib-meson.build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/libjaylink/meson.build
+++ b/libjaylink/meson.build
@@ -1 +1,9 @@
+if build_system == 'windows'
+ win_args = {
+ 'vs_module_defs': meson.current_source_dir() / 'jaylink.def',
+ }
+else
+ win_args = {}
+endif
+
sources = [
@@ -58,0 +67 @@
+ kwargs: win_args
@@ -60,0 +70,11 @@
+if build_system == 'windows'
+ libjaylink = shared_library(
+ 'libjaylink',
+ sources,
+ dependencies: [libusb, ws2_32],
+ version: library_version_string,
+ include_directories: include_dirs,
+ install: true,
+ vs_module_defs: meson.current_source_dir() / 'jaylink.def'
+ )
+endif
11 changes: 11 additions & 0 deletions recipes/libjaylink/patches/enable-dynamic-library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/libjaylink/libjaylink.h
+++ b/libjaylink/libjaylink.h
@@ -456,1 +456,7 @@
-#define JAYLINK_API
+ #ifdef BUILDING_DLL
+ #pragma message("BUILDING_DLL is defined")
+ #define JAYLINK_API __declspec(dllexport)
+ #else
+ #pragma message("BUILDING_DLL is NOT defined")
+ #define JAYLINK_API __declspec(dllimport)
+ #endif
5 changes: 5 additions & 0 deletions recipes/libjaylink/patches/fix-types-discovery_tcp.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--- a/libjaylink/discovery_tcp.c
+++ b/libjaylink/discovery_tcp.c
@@ -243,1 +243,1 @@
- sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ sock = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
5 changes: 5 additions & 0 deletions recipes/libjaylink/patches/fix-types-discovery_usb.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--- a/libjaylink/discovery_usb.c
+++ b/libjaylink/discovery_usb.c
@@ -268,1 +268,1 @@
- libusb_error_name(ret));
+ libusb_error_name((int)ret));
14 changes: 14 additions & 0 deletions recipes/libjaylink/patches/fix-types-fileio.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/libjaylink/fileio.c
+++ b/libjaylink/fileio.c
@@ -117,1 +117,1 @@
- buf[3] = filename_length;
+ buf[3] = (uint8_t)filename_length;
@@ -252,1 +252,1 @@
- buf[3] = filename_length;
+ buf[3] = (uint8_t)filename_length;
@@ -371,1 +371,1 @@
- buf[3] = length;
+ buf[3] = (uint8_t)length;
@@ -463,1 +463,1 @@
- buf[3] = length;
+ buf[3] = (uint8_t)length;
29 changes: 29 additions & 0 deletions recipes/libjaylink/patches/fix-types-socket.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- a/libjaylink/socket.c
+++ b/libjaylink/socket.c
@@ -67,1 +67,1 @@
- ret = connect(sock, address, address_length);
+ ret = connect(sock, address, (int)address_length);
@@ -84,1 +84,1 @@
- tv.tv_sec = timeout / 1000;
+ tv.tv_sec = (long)(timeout / 1000);
@@ -143,1 +143,1 @@
- ret = bind(sock, address, length);
+ ret = bind(sock, address, (int)length);
@@ -174,1 +174,1 @@
- ret = send(sock, buffer, *length, flags);
+ ret = send(sock, buffer, (int)*length, flags);
@@ -206,1 +206,1 @@
- ret = recv(sock, buffer, *length, flags);
+ ret = recv(sock, buffer, (int)*length, flags);
@@ -243,1 +243,1 @@
- ret = sendto(sock, buffer, *length, flags, address, address_length);
+ ret = sendto(sock, buffer, (int)*length, flags, address, (int)address_length);
@@ -287,1 +287,1 @@
- tmp = *address_length;
+ tmp = (int)*address_length;
@@ -288,1 +288,1 @@
- ret = recvfrom(sock, buffer, *length, flags, address, &tmp);
+ ret = recvfrom(sock, buffer, (int)*length, flags, address, &tmp);
@@ -342,1 +342,1 @@
- if (!setsockopt(sock, level, option, value, length))
+ if (!setsockopt(sock, level, option, value, (int)length))
5 changes: 5 additions & 0 deletions recipes/libjaylink/patches/fix-types-strutil.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--- a/libjaylink/strutil.c
+++ b/libjaylink/strutil.c
@@ -63,1 +63,1 @@
- *serial_number = tmp;
+ *serial_number = (uint32_t)tmp;
5 changes: 5 additions & 0 deletions recipes/libjaylink/patches/fix-types-transport_tcp.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--- a/libjaylink/transport_tcp.c
+++ b/libjaylink/transport_tcp.c
@@ -267,1 +267,1 @@
- sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+ sock = (int)socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
5 changes: 5 additions & 0 deletions recipes/libjaylink/patches/fix-types-transport_usb.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--- a/libjaylink/transport_usb.c
+++ b/libjaylink/transport_usb.c
@@ -412,1 +412,1 @@
- (unsigned char *)buffer, MIN(CHUNK_SIZE, length),
+ (unsigned char *)buffer, MIN(CHUNK_SIZE, (int)length),
19 changes: 19 additions & 0 deletions recipes/libjaylink/patches/fix-uninitialized.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--- a/libjaylink/discovery_usb.c
+++ b/libjaylink/discovery_usb.c
@@ -145,1 +145,1 @@
- enum jaylink_usb_address usb_address;
+ enum jaylink_usb_address usb_address = 0;
--- a/libjaylink/transport_usb.c
+++ b/libjaylink/transport_usb.c
@@ -52,1 +52,1 @@
- const struct libusb_interface_descriptor *desc;
+ const struct libusb_interface_descriptor *desc = NULL;
@@ -77,1 +77,1 @@
- desc = &interface->altsetting[0];
+ const struct libusb_interface_descriptor *curr_desc = &interface->altsetting[0];
@@ -89,1 +89,1 @@
- devh->interface_number = i;
+ devh->interface_number = i; desc = curr_desc;
@@ -93,1 +93,1 @@
- if (!found_interface) {
+ if (!found_interface || !desc) {
Loading
Loading