]> sigrok.org Git - sigrok-util.git/blob - cross-compile/mingw/libusb1_upgrade.patch
sigrok-cross-mingw: upgrade libusb1 to version 1.0.25 for MXE builds
[sigrok-util.git] / cross-compile / mingw / libusb1_upgrade.patch
1 The sigrok build references an older libusb1 library version, which
2 addresses two specific aspects:
3
4   - Presence of an "event abstraction" is desired. Which once was
5     available as a branch on top of 1.0.20-rc3, but has gone away
6     in the meantime and got archived locally. -- Library versions
7     1.0.24 and above may provide that feature under the common API
8     but are yet to get verified.
9
10   - For performance reasons the RAW_IO feature is enabled. libusb1
11     mainline may provide such an approach later (automatically, after
12     checking more conditions for improved reliability), but does not
13     in versions up to and including 1.0.25 yet.
14
15 Manipulation of the libusb1 configuration in the MXE setup avoids the
16 necessity for a custom libusb1 build as a step in the sigrok procedure.
17
18 Ideally the sigrok build would use libusb1 version 1.0.25+ to benefit
19 from the many portability and robustness and feature set improvements.
20 Regardless of which libusb1 version ships with mainline MXE. That is
21 why this file is called "libusb1_upgrade.patch". Until then it patches
22 the local archive of the older library version.
23
24
25 Explicitly prepare autotools use between checkout and configuration.
26
27 diff --git a/src/libusb1.mk b/src/libusb1.mk
28 index ab01bf69..53aed36e 100644
29 --- a/src/libusb1.mk
30 +++ b/src/libusb1.mk
31 @@ -19,7 +19,7 @@ define $(PKG)_UPDATE
32  endef
33  
34  define $(PKG)_BUILD
35 -    cd '$(1)' && ./configure \
36 +    cd '$(1)' && autoreconf -i && ./configure \
37          $(MXE_CONFIGURE_OPTS) \
38          CFLAGS=-D_WIN32_WINNT=0x0500
39      $(MAKE) -C '$(1)' -j '$(JOBS)' install
40
41
42 Don't use MXE's provided 1.0.24 version. Use an "event abstraction"
43 enabled older version instead.
44
45 diff --git a/src/libusb1.mk b/src/libusb1.mk
46 index ab01bf69..53aed36e 100644
47 --- a/src/libusb1.mk
48 +++ b/src/libusb1.mk
49 @@ -4,8 +4,8 @@ PKG             := libusb1
50  $(PKG)_WEBSITE  := https://libusb.info/
51  $(PKG)_DESCR    := LibUsb-1.0
52  $(PKG)_IGNORE   :=
53 -$(PKG)_VERSION  := 1.0.24
54 -$(PKG)_CHECKSUM := 7efd2685f7b327326dcfb85cee426d9b871fd70e22caa15bb68d595ce2a2b12a
55 +$(PKG)_VERSION  := 1.0.25
56 +$(PKG)_CHECKSUM := 8a28ef197a797ebac2702f095e81975e2b02b2eeff2774fa909c78a74ef50849
57  $(PKG)_SUBDIR   := libusb-$($(PKG)_VERSION)
58  $(PKG)_FILE     := libusb-$($(PKG)_VERSION).tar.bz2
59  $(PKG)_URL      := https://$(SOURCEFORGE_MIRROR)/project/libusb/libusb-1.0/libusb-$($(PKG)_VERSION)/$($(PKG)_FILE)
60
61
62 Enable RAW_IO policy on Windows when constraints are met. This assumes
63 recent libusb1 versions, see https://github.com/libusb/libusb/pull/1069
64 for details.
65
66 diff --git a/src/libusb1-1-fixes.patch b/src/libusb1-1-fixes.patch
67 new file mode 100644
68 index 00000000..6cdeb0c4
69 --- /dev/null
70 +++ b/src/libusb1-1-fixes.patch
71 @@ -0,0 +1,31 @@
72 +commit f341e4a086edd4f45c2db4df892a52ebfd52ac5b
73 +Author:     Petteri Aimonen <jpa@git.mail.kapsi.fi>
74 +AuthorDate: 2022-02-11 12:08:01 +0200
75 +Commit:     Petteri Aimonen <jpa@git.mail.kapsi.fi>
76 +CommitDate: 2022-02-11 12:08:01 +0200
77 +
78 +    WinUSB: Use RAW_IO when transfer size is divisible by 512 bytes
79 +---
80 + libusb/os/windows_winusb.c | 9 +++++++++
81 + 1 file changed, 9 insertions(+)
82 +
83 +diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
84 +index a03d6a51216a..a0ac0c609e99 100644
85 +--- a/libusb/os/windows_winusb.c
86 ++++ b/libusb/os/windows_winusb.c
87 +@@ -3086,6 +3086,15 @@ static int winusbx_submit_bulk_transfer(int sub_api, struct usbi_transfer *itran
88 +       set_transfer_priv_handle(itransfer, handle_priv->interface_handle[current_interface].dev_handle);
89 +       overlapped = get_transfer_priv_overlapped(itransfer);
90
91 ++      if (sub_api == SUB_API_WINUSB)
92 ++      {
93 ++              // Use RAW_IO when transfer size is divisible by 512 bytes.
94 ++              UCHAR policy = (transfer->length % 512 == 0);
95 ++              if (!WinUSBX[sub_api].SetPipePolicy(winusb_handle, transfer->endpoint, RAW_IO, sizeof(UCHAR), &policy)) {
96 ++                              usbi_err(TRANSFER_CTX(transfer), "failed to set RAW_IO for endpoint %02X", transfer->endpoint);
97 ++              }
98 ++      }
99 ++
100 +       if (IS_XFERIN(transfer)) {
101 +               usbi_dbg(TRANSFER_CTX(transfer), "reading %d bytes", transfer->length);
102 +               ret = WinUSBX[sub_api].ReadPipe(winusb_handle, transfer->endpoint, transfer->buffer, transfer->length, NULL, overlapped);