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

Compile error with mingw64 / wsl (OCD-1042) #347

Closed
ddemelier-ts opened this issue Nov 22, 2024 · 4 comments
Closed

Compile error with mingw64 / wsl (OCD-1042) #347

ddemelier-ts opened this issue Nov 22, 2024 · 4 comments

Comments

@ddemelier-ts
Copy link

Development Kit

esp32c6-devkitc

Module or chip used

esp32c6

Debug Adapter

ftdi

OpenOCD version

git

Operating System

Windows

Using an IDE ?

no

OpenOCD command line

no

JTAG Clock Speed

no

ESP-IDF version

no

Problem Description

Cross-compiling openocd-esp32 under wsl with x86_64-w64-mingw32 fails with the following error:

libtool: compile:  x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -D__USE_MINGW_ANSI_STDIO -DFD_SETSIZE=128 -I./src -I./src -DPKGDATADIR=\"/usr/share/openocd\" -DBINDIR=\"/usr/bin\" -I./jimtcl -I./jimtcl -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Werror -g -O2 -MT src/target/espressif/esp_semihosting.lo -MD -MP -MF src/target/espressif/.deps/esp_semihosting.Tpo -c src/target/espressif/esp_semihosting.c -o src/target/espressif/esp_semihosting.o
src/target/espressif/esp_semihosting.c: In function ‘esp_semihosting_common’:
src/target/espressif/esp_semihosting.c:25:36: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
   25 | #define fsync(fd) FlushFileBuffers((HANDLE)fd)
      |                                    ^
src/target/espressif/esp_semihosting.c:730:26: note: in expansion of macro ‘fsync’
  730 |    semihosting->result = fsync(fd);
      |                          ^~~~~
cc1: all warnings being treated as errors

Debug Logs

No response

Expected behavior

Doesn't build.

Screenshots

No response

@github-actions github-actions bot changed the title Compile error with mingw64 / wsl Compile error with mingw64 / wsl (OCD-1042) Nov 22, 2024
@erhankur
Copy link
Collaborator

I can not try on windows now but can suggest you 2 solutions

1- Modify the fsync(fd) definition as below. esp_semihosting.c:25

#define fsync(fd) FlushFileBuffers((HANDLE)(uintptr_t)(fd))

2 - Reconfigure the project by disabling the compiler error

./configure CFLAGS="-Wno-int-to-pointer-cast"

Let me know if these solutions work for you.

@ddemelier-ts
Copy link
Author

ddemelier-ts commented Nov 22, 2024

No I think the issue comes from the fact that HANDLE is a void * while semihosting_get_field returns uint64_t. This function should return a generic fd type (like intptr_t or uintptr_t) but that's a bigger work. Would this be correct?

--- src/target/espressif/esp_semihosting.c.orig 2024-11-22 16:39:58.688979902 +0100
+++ src/target/espressif/esp_semihosting.c      2024-11-22 16:41:50.689353023 +0100
@@ -726,10 +726,10 @@
                }
                retval = semihosting_read_fields(target, 1, fields);
                if (retval == ERROR_OK) {
-                       int fd = semihosting_get_field(target, 0, fields);
-                       semihosting->result = FlushFileBuffers((uintptr_t)fd);
+                       uint64_t fd = semihosting_get_field(target, 0, fields);
+                       semihosting->result = fsync(fd);
                        semihosting->sys_errno = errno;
-                       LOG_DEBUG("fsync('%d')=%" PRId64, fd, semihosting->result);
+                       LOG_DEBUG("fsync('%'" PRIu64 "')=%" PRId64, fd, semihosting->result);
                }
                break;

By the way, really nice that Zephyr RTOS landed in the tree!

@erhankur
Copy link
Collaborator

Yes. Your solution is correct. We will fix the fd type there.

Regarding Zephyr, it is not fully supported yet, but we do have an initial code base. We plan to improve it early next year.

@erhankur
Copy link
Collaborator

erhankur commented Dec 2, 2024

Fixed id a139429

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

No branches or pull requests

3 participants