]> sigrok.org Git - sigrok-util.git/blob - cross-compile/mingw/libusb1_upgrade.patch
bd90d03d2cd9effe2afae670acaba334c21d60a0
[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,11 +4,11 @@ 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)_SUBDIR   := libusb-$($(PKG)_VERSION)
56 -$(PKG)_FILE     := libusb-$($(PKG)_VERSION).tar.bz2
57 -$(PKG)_URL      := https://$(SOURCEFORGE_MIRROR)/project/libusb/libusb-1.0/libusb-$($(PKG)_VERSION)/$($(PKG)_FILE)
58 +$(PKG)_VERSION  := 1.0.24
59 +$(PKG)_CHECKSUM := 7efd2685f7b327326dcfb85cee426d9b871fd70e22caa15bb68d595ce2a2b12a
60 +$(PKG)_SUBDIR   := libusb-$($(PKG)_VERSION)
61 +$(PKG)_FILE     := libusb-$($(PKG)_VERSION).tar.bz2
62 +$(PKG)_URL      := https://$(SOURCEFORGE_MIRROR)/project/libusb/libusb-1.0/libusb-$($(PKG)_VERSION)/$($(PKG)_FILE)
63  $(PKG)_DEPS     := cc
64  
65  define $(PKG)_UPDATE
66
67
68 Enable RAW_IO policy on Windows when constraints are met. This assumes
69 recent libusb1 versions, see https://github.com/libusb/libusb/pull/1069
70 for details.
71
72 diff --git a/src/libusb1-1-fixes.patch b/src/libusb1-1-fixes.patch
73 new file mode 100644
74 index 00000000..6cdeb0c4
75 --- /dev/null
76 +++ b/src/libusb1-1-fixes.patch
77 @@ -0,0 +1,31 @@
78 +commit f341e4a086edd4f45c2db4df892a52ebfd52ac5b
79 +Author:     Petteri Aimonen <jpa@git.mail.kapsi.fi>
80 +AuthorDate: 2022-02-11 12:08:01 +0200
81 +Commit:     Petteri Aimonen <jpa@git.mail.kapsi.fi>
82 +CommitDate: 2022-02-11 12:08:01 +0200
83 +
84 +    WinUSB: Use RAW_IO when transfer size is divisible by 512 bytes
85 +---
86 + libusb/os/windows_winusb.c | 9 +++++++++
87 + 1 file changed, 9 insertions(+)
88 +
89 +diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
90 +index a03d6a51216a..a0ac0c609e99 100644
91 +--- a/libusb/os/windows_winusb.c
92 ++++ b/libusb/os/windows_winusb.c
93 +@@ -3086,6 +3086,15 @@ static int winusbx_submit_bulk_transfer(int sub_api, struct usbi_transfer *itran
94 +       set_transfer_priv_handle(itransfer, handle_priv->interface_handle[current_interface].dev_handle);
95 +       overlapped = get_transfer_priv_overlapped(itransfer);
96
97 ++      if (sub_api == SUB_API_WINUSB)
98 ++      {
99 ++              // Use RAW_IO when transfer size is divisible by 512 bytes.
100 ++              UCHAR policy = (transfer->length % 512 == 0);
101 ++              if (!WinUSBX[sub_api].SetPipePolicy(winusb_handle, transfer->endpoint, RAW_IO, sizeof(UCHAR), &policy)) {
102 ++                              usbi_err(TRANSFER_CTX(transfer), "failed to set RAW_IO for endpoint %02X", transfer->endpoint);
103 ++              }
104 ++      }
105 ++
106 +       if (IS_XFERIN(transfer)) {
107 +               usbi_dbg(TRANSFER_CTX(transfer), "reading %d bytes", transfer->length);
108 +               ret = WinUSBX[sub_api].ReadPipe(winusb_handle, transfer->endpoint, transfer->buffer, transfer->length, NULL, overlapped);