Skip to content

Windows ujprog compile error: 'EOPNOTSUPP' undeclared, 'usleep' is deprecated #8

Closed

Description

@gojimmypi

I encountered a bunch of warnings that usleep is deprecated, and more importantly a critical error that 'EOPNOTSUPP' undeclared when compiling ujprog in MinGW32 for Windows:

cp Makefile.win Makefile
make

Output:

gcc.exe -c ujprog.c -o ujprog.o -I.

[... snip ...]

c:\mingw\include\unistd.h:100:29: note: declared here
 int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                             ^~~~~~
ujprog.c: In function 'shutdown_usb':
ujprog.c:621:2: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
  ms_sleep(10);
  ^~~~~~~~
In file included from ujprog.c:55:
c:\mingw\include\unistd.h:100:29: note: declared here
 int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                             ^~~~~~
ujprog.c: In function 'exec_svf_tokenized':
ujprog.c:1488:9: error: 'EOPNOTSUPP' undeclared (first use in this function); did you mean 'WSAEOPNOTSUPP'?
   res = EOPNOTSUPP;
         ^~~~~~~~~~
         WSAEOPNOTSUPP
ujprog.c:1488:9: note: each undeclared identifier is reported only once for each function it appears in
ujprog.c: In function 'async_read_block':
ujprog.c:2788:4: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
    ms_sleep(backoff * 4);
    ^~~~~~~~
In file included from ujprog.c:55:

[... snip ...]
gcc.exe ujprog.o  -lftd2xx -o "ujprog.exe" -s -static -L. -lftd2xx

The solution that worked for me here for the error: 'EOPNOTSUPP' undeclared was the same as nmap/nmap#183 in adding these two lines to ujprog.c:

#undef EOPNOTSUPP
#define EOPNOTSUPP      WSAEOPNOTSUPP  /* Operation not supported */

After that change, I was able to create an exe for ujprog.

Activity

  1. gojimmypi commented on Feb 11, 2019

    @gojimmypi
    Author

    I created this PR to fix: #9

  2. gornjas commented on Feb 13, 2019

    @gornjas
    Contributor

    ujprog builds perfectly fine (no errors or warnings whatsoever) as-is from day 0 on M$ windows, using MSYS MINGW32. make -f Makefile.win is all it takes.

    I'm not inclined to accept the proposed patch, as it more likely reflects some problem in the build system (probably including a wrong errno.h) rather than a problem in ujprog.c itself.

    Note that we went to great lengths to make and keep ujprog portable across a broad range of platforms (Win32, Linux, FreeBSD, OSX), hence my reluctance to accept a windows-specific fix for a non-issue.

  3. gojimmypi commented on Feb 13, 2019

    @gojimmypi
    Author

    @gornjas - I appreciate the efforts to make it ujprog portable. Respectfully, this is what I see in mingw32 on Windows 10 1803 17134.556:

    $ gcc --version
    gcc.exe (MinGW.org GCC-8.2.0-3) 8.2.0
    Copyright (C) 2018 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    Here's the entire output:

    $ make -f Makefile.win
    gcc.exe -c ujprog.c -o ujprog.o -I.
    ujprog.c: In function 'set_port_mode':
    ujprog.c:463:4: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
        ms_sleep(20);
        ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:479:5: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
         ms_sleep(10);
         ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:483:4: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
        ms_sleep(10);
        ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c: In function 'shutdown_usb':
    ujprog.c:620:2: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
      ms_sleep(10);
      ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c: In function 'exec_svf_tokenized':
    ujprog.c:1487:9: error: 'EOPNOTSUPP' undeclared (first use in this function); did you mean 'WSAEOPNOTSUPP'?
       res = EOPNOTSUPP;
             ^~~~~~~~~~
             WSAEOPNOTSUPP
    ujprog.c:1487:9: note: each undeclared identifier is reported only once for each function it appears in
    ujprog.c: In function 'async_read_block':
    ujprog.c:2787:4: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
        ms_sleep(backoff * 4);
        ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c: In function 'txfile':
    ujprog.c:2978:3: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
       ms_sleep(50);
       ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:2994:3: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
       ms_sleep(200);
       ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:2996:3: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
       ms_sleep(100);
       ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:3008:3: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
       ms_sleep(50);
       ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:3028:4: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
        ms_sleep(txfu_ms);
        ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:3070:5: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
         ms_sleep(txfu_ms);
         ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:3073:4: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
        for(crc_retry = 4; crc_retry > 0 && res != 4; ms_sleep(10), crc_retry--)
        ^~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:3131:3: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
       ms_sleep(50);
       ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c: In function 'genbrk':
    ujprog.c:3148:3: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
       ms_sleep(BREAK_MS);
       ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:3160:3: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
       ms_sleep(BREAK_MS);
       ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:3168:2: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
      ms_sleep(20);
      ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c: In function 'debug_cmd':
    ujprog.c:3439:4: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
        ms_sleep(c / 50000);
        ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c: In function 'term_emul':
    ujprog.c:3562:4: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
        ms_sleep(50);
        ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c:3930:4: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
        ms_sleep(sleep_t);
        ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    ujprog.c: In function 'main':
    ujprog.c:4215:3: warning: 'usleep' is deprecated [-Wdeprecated-declarations]
       ms_sleep(1); // small delay for f32c to start
       ^~~~~~~~
    In file included from ujprog.c:54:
    c:\mingw\include\unistd.h:100:29: note: declared here
     int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
                                 ^~~~~~
    make: *** [ujprog.o] Error 1
    

    with these versions, fresh clone:
    git clone https://github.com/f32c/tools.git f32c_tools

    $ git log -1 -- Makefile.win
    commit 9b9fc13c59f179c4a71ab6314181984f516754bd
    Author: Marko Zec <[email protected]>
    Date:   Sun Dec 17 00:59:08 2017 +0100
    
        Unbreak build with MSYS2 MinGW 32-bit.  Dev-C++ build will no longer work.
    
        ujprog xp2.svf works out of the box.
    
        ujprog ecp5.svf still doesn't, investigating why...
    
    $ git log -1 -- ujprog.c
    commit c02dc41b925729f7edf0030e5c94eee9735b6824
    Author: gornjas <[email protected]>
    Date:   Sat Dec 29 14:24:34 2018 +0100
    
        Add -f addr specifies a base address for SPI writes using -j flash.
    
    

    Perhaps I'm still doing something wrong? I do agree that if there's a better solution such as using the proper errno.h - that's probably a better change.

  4. gojimmypi commented on Feb 15, 2019

    @gojimmypi
    Author

    heads up that I appended some other minor, non-code changes to this PR (recent FTDI lib file, add README, etc). Perhaps I should have created a separate PR, but you are welcome to cherry-pick if you find any of this useful.

  5. emard commented on Feb 15, 2019

    @emard
    Member
  6. gojimmypi commented on Feb 15, 2019

    @gojimmypi
    Author

    @emard if you let me know the destination, I can create a specific PR for you.

    regarding your comment on statically compiled windows executable - well, I am able to compile ujprog in WSL Ubuntu for the Windows target (64 bit) using mingw-w64 (see my blog here), copying the latest FTDI ftd2xx.h and ftd2xx.lib files from the FTDI zip download into the ujprog directory.

    specifically:

    sudo apt-get install mingw-w64
    
    # Get a make file if PR not yet merged
    wget https://raw.githubusercontent.com/gojimmypi/f32c_tools/master/ujprog/Makefile.ming32_64
    
    # My c:\download\ftdi\ directory...
    cp "/mnt/c/download/ftdi/CDM v2.12.28 WHQL Certified/amd64/ftd2xx.lib" ./ftd2xx.lib
    cp "/mnt/c/download/ftdi/CDM v2.12.28 WHQL Certified/ftd2xx.h" ./ftd2xx.h
    
    make clean -f Makefile.ming32_64
    make -f Makefile.ming32_64
    

    Note my Makefile.ming32_64 (also included in the PR) specifies the MinGW cross compiler:

    CPP  = x86_64-w64-mingw32-gcc
    CC   = x86_64-w64-mingw32-gcc
    

    However you specifically noted statically compiled. Well, there is a ftd2xx.lib file in the "static" download directory; this is not the one I used (I tried, it did not compile):

    CDM v2.12.28 WHQL Certified\Static\amd64\ftd2xx.lib
    

    Otherwise the executable created is portable, in that I can move it to any directory and there are no DLL's or other files needed... however Windows of course still has the DLL's installed in the system for the device (otherwise it would not work anyhow)

    C:\test>ujprog ulx3s.bit
    ULX2S / ULX3S JTAG programmer v 3.0.92 (built Feb 15 2019 14:18:16)
    Using USB cable: ULX3S FPGA 12K v3.0.3
    Programming: 100%
    Completed in 16.63 seconds.
    

    Pardon my lack of knowledge here; Sorry if I've not answered your question clearly.

  7. gojimmypi commented on Feb 15, 2019

    @gojimmypi
    Author

    One thing I'd like to add is that the @tinyfpga can be programmed without any special drivers, using only the /dev/ttySn serial devices. (see my blog here) This would be a highly desirable feature for the ULX3S - particularly in that OpenOCD (libusbK) and ujprog (FTDI) cannot be used concurrently in Windows - and in my case, libusbK cannot be used at all in WSL,

  8. emard commented on Feb 15, 2019

    @emard
    Member
  9. emard commented on Feb 15, 2019

    @emard
    Member
  10. gojimmypi commented on Feb 15, 2019

    @gojimmypi
    Author

    @emard regarding Makefile.ming32_64; ah yes, that is graceful and efficient, and not dependent on a mystery lib file from someone's repo (although when the FTDI web site gets updated, the Makefile breaks).

    yes, it works in WSL Ubuntu (the only thing missing for me was unzip):

    sudo apt-get install unzip
    mkdir temp2
    cd temp2
    git clone https://github.com/f32c/tools.git
    cd tools/ujprog
    make -f Makefile.ming32_64
    

    and the build was succcessful!

    0 $ make -f Makefile.ming32_64
    x86_64-w64-mingw32-gcc -c ujprog.c -o ujprog.o -I.
    wget -c "https://www.ftdichip.com/Drivers/CDM/CDM%20v2.12.28%20WHQL%20Certified.zip" -O ftdi.zip
    Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
    ERROR: could not open HSTS store at '/home/gojimmypi/.wget-hsts'. HSTS will be disabled.
    --2019-02-15 15:42:38--  https://www.ftdichip.com/Drivers/CDM/CDM%20v2.12.28%20WHQL%20Certified.zip
    Resolving www.ftdichip.com (www.ftdichip.com)... 217.160.0.65
    Connecting to www.ftdichip.com (www.ftdichip.com)|217.160.0.65|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1682976 (1.6M) [application/zip]
    Saving to: ‘ftdi.zip’
    
    ftdi.zip                             100%[=====================================================================>]   1.60M  1.12MB/s    in 1.4s
    
    2019-02-15 15:42:40 (1.12 MB/s) - ‘ftdi.zip’ saved [1682976/1682976]
    
    unzip ftdi.zip amd64/ftd2xx.lib
    Archive:  ftdi.zip
      inflating: amd64/ftd2xx.lib
    touch amd64/ftd2xx.lib
    x86_64-w64-mingw32-gcc ujprog.o  -o "ujprog.exe" -s -static -L. -lamd64/ftd2xx
    
    

    then copy to C:\test2 for Windows

    cp ujprog.exe /mnt/c/test2
    

    tada!

    C:\test2>ujprog ulx3s.bit
    ULX2S / ULX3S JTAG programmer v 3.0.92 (built Feb 15 2019 15:42:37)
    Using USB cable: ULX3S FPGA 12K v3.0.3
    Programming: 100%
    Completed in 16.59 seconds.
    
    

    edit: even more interesting is that yes, it compiles... specifically these lines are not in the ujprog.c - yet I also did not encounter the EOPNOTSUPP errors originally described in this issue (above):

    #undef EOPNOTSUPP
    #define EOPNOTSUPP      WSAEOPNOTSUPP  /* Operation not supported */
    
  11. gojimmypi commented on Feb 16, 2019

    @gojimmypi
    Author

    @emard regarding tinyfpga USB protocol - I recall reading something about "ValentyUSB" enhancements for the tomu board. I think some progress was made, but I cannot immediately seem to find it. Are you on twitter? perhaps ask there.

  12. emard commented on Feb 16, 2019

    @emard
    Member
  13. gojimmypi commented on Feb 16, 2019

    @gojimmypi
    Author

    the root cause of the 'EOPNOTSUPP' undeclared error message appears to be using the old header and lib file (the ones from 4 years ago in this repo) to compile.

    Using the most recent ftd2xx.h and ftd2xx.lib from the FTDI zip file resolves the error (and all the warnings) without having to make the code change suggested above.

  14. emard commented on Feb 16, 2019

    @emard
    Member

    Makefile.ming32 and Makefile.ming32_64 fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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