From e0853a0b487ef275b6e32029897db0fab477a22c Mon Sep 17 00:00:00 2001 From: caiohamamura Date: Mon, 1 Sep 2025 20:38:42 -0300 Subject: [PATCH 1/7] Makefile: correctly handle windows x linux toolchains --- Makefile | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 97bc530f1..a773b58de 100644 --- a/Makefile +++ b/Makefile @@ -85,16 +85,7 @@ endif # then please raise a GitHub issue on this work. # -ifndef $(OS) - # Assume Windows if MAKE_HOST contains "indows" and Linux otherwise - ifneq (,$(findstring indows,$(MAKE_HOST))) - OS := windows - else - OS := linux - endif -endif - -ifneq (,$(findstring indows,$(OS))) +ifeq ($(OS),Windows_NT) #------------ BEGIN UNTESTED ------------ We are not under Linux, e.g.under windows. ifeq ($(XTENSA_CORE),lx106) # It is xcc @@ -116,6 +107,14 @@ ifneq (,$(findstring indows,$(OS))) NM = xtensa-lx106-elf-nm CPP = xtensa-lx106-elf-cpp OBJCOPY = xtensa-lx106-elf-objcopy + TOOLCHAIN_VERSION = 2020r3 + GCCTOOLCHAIN = xtensa-lx106-elf-gcc8_4_0-esp-$(TOOLCHAIN_VERSION)-win32 + TOOLCHAIN_ROOT = $(TOP_DIR)/tools/toolchains/esp8266-$(GCCTOOLCHAIN) + ESPRESSIF_URL = https://dl.espressif.com/dl + TOOLCHAIN_EXT = zip + TOOLCHAIN_URL = $(ESPRESSIF_URL)/$(GCCTOOLCHAIN).$(TOOLCHAIN_EXT) + WGET = wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused + export PATH := $(PATH):$(TOOLCHAIN_ROOT)/bin endif FIRMWAREDIR = ..\\bin\\ ifndef COMPORT @@ -123,24 +122,21 @@ ifneq (,$(findstring indows,$(OS))) else ESPPORT = $(COMPORT) endif - ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) -# ->AMD64 - endif - ifeq ($(PROCESSOR_ARCHITECTURE),x86) -# ->IA32 - endif + #---------------- END UNTESTED ---------------- We are under windows. else # We are under other system, may be Linux. Assume using gcc. UNAME_S := $(shell uname -s) UNAME_P := $(shell uname -p) - ifeq ($(OS),linux) + ifeq ($(UNAME_S),Linux) ifndef TOOLCHAIN_ROOT TOOLCHAIN_VERSION = 20190731.0 GCCTOOLCHAIN = linux-x86_64-$(TOOLCHAIN_VERSION) TOOLCHAIN_ROOT = $(TOP_DIR)/tools/toolchains/esp8266-$(GCCTOOLCHAIN) GITHUB_TOOLCHAIN = https://github.com/jmattsson/esp-toolchains + TOOLCHAIN_EXT = tar.xz + TOOLCHAIN_URL = $(GITHUB_TOOLCHAIN)/releases/download/$(GCCTOOLCHAIN)/toolchain-esp8266-$(GCCTOOLCHAIN).$(TOOLCHAIN_EXT) export PATH:=$(PATH):$(TOOLCHAIN_ROOT)/bin endif endif @@ -286,21 +282,24 @@ endif sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_VER) sdk_pruned: sdk_extracted toolchain $(TOP_DIR)/sdk/.pruned-$(SDK_VER) -ifdef GITHUB_TOOLCHAIN - TOOLCHAIN_ROOT := $(TOP_DIR)/tools/toolchains/esp8266-linux-x86_64-$(TOOLCHAIN_VERSION) - +ifdef TOOLCHAIN_URL toolchain: $(TOOLCHAIN_ROOT)/bin $(ESPTOOL) -$(TOOLCHAIN_ROOT)/bin: $(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz +$(TOOLCHAIN_ROOT)/bin: $(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).$(TOOLCHAIN_EXT) mkdir -p $(TOP_DIR)/tools/toolchains/ $(summary) EXTRACT $(patsubst $(TOP_DIR)/%,%,$<) - tar -xJf $< -C $(TOP_DIR)/tools/toolchains/ + ifeq ($(TOOLCHAIN_EXT),tar.xz) + tar -xJf $< -C $(TOP_DIR)/tools/toolchains/ + else ifeq ($(TOOLCHAIN_EXT),zip) + unzip -q $< -d $(TOP_DIR)/tools/toolchains/ + mv $(TOP_DIR)/tools/toolchains/xtensa-lx106-elf $(TOOLCHAIN_ROOT) + endif touch $@ -$(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz: +$(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).$(TOOLCHAIN_EXT): mkdir -p $(TOP_DIR)/cache $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) - $(WGET) $(GITHUB_TOOLCHAIN)/releases/download/$(GCCTOOLCHAIN)/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz -O $@ \ + $(WGET) $(TOOLCHAIN_URL) -O $@ \ || { rm -f "$@"; exit 1; } else toolchain: $(ESPTOOL) From 0f733562e5c03f749b4bd39946656aea7308763a Mon Sep 17 00:00:00 2001 From: caiohamamura Date: Mon, 1 Sep 2025 20:49:54 -0300 Subject: [PATCH 2/7] Handle missing function declarations and undefined/divergence of function names in windows. - Makefile: allow implicit functions warnings, define stricmp as macro for strcasecmp, define WIN32. - cc.h: check if BYTE_ORDER is not already defined (which is in windows toolchain) - socket.h: Check if timeval.h hasn't already been included before defining the timeval struct - Define __locale_c_type_ptr function, locale/ctype support is not enabled in windows toolchain. --- Makefile | 2 +- app/include/arch/cc.h | 2 ++ app/include/sys/socket.h | 3 +++ app/libc/stdlib.c | 9 +++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a773b58de..2ea622dae 100644 --- a/Makefile +++ b/Makefile @@ -100,7 +100,7 @@ ifeq ($(OS),Windows_NT) else # It is gcc, may be cygwin # Can we use -fdata-sections? - CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections -fpack-struct=4 + CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections -fpack-struct=4 -Wno-error=implicit-function-declaration -Dstricmp=strcasecmp -DWIN32 AR = xtensa-lx106-elf-ar CC = xtensa-lx106-elf-gcc CXX = xtensa-lx106-elf-g++ diff --git a/app/include/arch/cc.h b/app/include/arch/cc.h index 6fbff3efd..fc71af2c8 100644 --- a/app/include/arch/cc.h +++ b/app/include/arch/cc.h @@ -42,11 +42,13 @@ //#define LWIP_PROVIDE_ERRNO +#ifndef BYTE_ORDER #if (1) #define BYTE_ORDER LITTLE_ENDIAN #else #define BYTE_ORDER BIG_ENDIAN #endif +#endif typedef uint8_t u8_t; diff --git a/app/include/sys/socket.h b/app/include/sys/socket.h index 937cacc04..0ef61b8e7 100644 --- a/app/include/sys/socket.h +++ b/app/include/sys/socket.h @@ -242,10 +242,13 @@ typedef uint32 socklen_t; #define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */ #endif +#ifndef _SYS__TIMEVAL_H_ struct timeval { long tv_sec; /* seconds */ long tv_usec; /* and microseconds */ }; +#endif + /* Flags for struct netconn.flags (u8_t) */ /** TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores whether to wake up the original application task diff --git a/app/libc/stdlib.c b/app/libc/stdlib.c index 08fbda0b0..c2f54ed30 100644 --- a/app/libc/stdlib.c +++ b/app/libc/stdlib.c @@ -10,6 +10,15 @@ #define TRUE 1 #define FALSE 0 #endif + +#ifdef WIN32 +// locale/ctype support not enabled for windows +__attribute__((weak)) +const char* __locale_ctype_ptr(void) { + return NULL; +} +#endif + double powersOf10[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = /* Table giving binary powers of 10. Entry */ { 10., /* is 10^2^i. Used to convert decimal */ From 7e5242d22e11913c7886032f0470b7d4393f047b Mon Sep 17 00:00:00 2001 From: caiohamamura Date: Mon, 1 Sep 2025 20:50:21 -0300 Subject: [PATCH 3/7] windows compilation: add missing headers from windows toolchain --- app/include/xtensa/config/specreg.h | 80 ++++++++++++++ app/include/xtensa/corebits.h | 164 ++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 app/include/xtensa/config/specreg.h create mode 100644 app/include/xtensa/corebits.h diff --git a/app/include/xtensa/config/specreg.h b/app/include/xtensa/config/specreg.h new file mode 100644 index 000000000..3a601353e --- /dev/null +++ b/app/include/xtensa/config/specreg.h @@ -0,0 +1,80 @@ +/* + * Xtensa Special Register symbolic names + */ + +/* $Id: //depot/rel/Boreal/Xtensa/SWConfig/hal/specreg.h.tpp#2 $ */ + +/* Copyright (c) 1998-2002 Tensilica Inc. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef XTENSA_SPECREG_H +#define XTENSA_SPECREG_H + +/* Include these special register bitfield definitions, for historical reasons: */ +#include + + +/* Special registers: */ +#define SAR 3 +#define LITBASE 5 +#define IBREAKENABLE 96 +#define DDR 104 +#define IBREAKA_0 128 +#define DBREAKA_0 144 +#define DBREAKC_0 160 +#define EPC_1 177 +#define EPC_2 178 +#define EPC_3 179 +#define DEPC 192 +#define EPS_2 194 +#define EPS_3 195 +#define EXCSAVE_1 209 +#define EXCSAVE_2 210 +#define EXCSAVE_3 211 +#define INTERRUPT 226 +#define INTENABLE 228 +#define PS 230 +#define VECBASE 231 +#define EXCCAUSE 232 +#define DEBUGCAUSE 233 +#define CCOUNT 234 +#define PRID 235 +#define ICOUNT 236 +#define ICOUNTLEVEL 237 +#define EXCVADDR 238 +#define CCOMPARE_0 240 + +/* Special cases (bases of special register series): */ +#define IBREAKA 128 +#define DBREAKA 144 +#define DBREAKC 160 +#define EPC 176 +#define EPS 192 +#define EXCSAVE 208 +#define CCOMPARE 240 + +/* Special names for read-only and write-only interrupt registers: */ +#define INTREAD 226 +#define INTSET 226 +#define INTCLEAR 227 + +#endif /* XTENSA_SPECREG_H */ + diff --git a/app/include/xtensa/corebits.h b/app/include/xtensa/corebits.h new file mode 100644 index 000000000..762bc6091 --- /dev/null +++ b/app/include/xtensa/corebits.h @@ -0,0 +1,164 @@ +/* + * xtensa/corebits.h - Xtensa Special Register field positions, masks, values. + * + * (In previous releases, these were defined in specreg.h, a generated file. + * This file is not generated, ie. it is processor configuration independent.) + */ + +/* $Id: //depot/rel/Boreal/Xtensa/OS/include/xtensa/corebits.h#2 $ */ + +/* + * Copyright (c) 2005-2007 Tensilica Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef XTENSA_COREBITS_H +#define XTENSA_COREBITS_H + +/* EXCCAUSE register fields: */ +#define EXCCAUSE_EXCCAUSE_SHIFT 0 +#define EXCCAUSE_EXCCAUSE_MASK 0x3F +/* EXCCAUSE register values: */ +/* + * General Exception Causes + * (values of EXCCAUSE special register set by general exceptions, + * which vector to the user, kernel, or double-exception vectors). + */ +#define EXCCAUSE_ILLEGAL 0 /* Illegal Instruction */ +#define EXCCAUSE_SYSCALL 1 /* System Call (SYSCALL instruction) */ +#define EXCCAUSE_INSTR_ERROR 2 /* Instruction Fetch Error */ +# define EXCCAUSE_IFETCHERROR 2 /* (backward compatibility macro, deprecated, avoid) */ +#define EXCCAUSE_LOAD_STORE_ERROR 3 /* Load Store Error */ +# define EXCCAUSE_LOADSTOREERROR 3 /* (backward compatibility macro, deprecated, avoid) */ +#define EXCCAUSE_LEVEL1_INTERRUPT 4 /* Level 1 Interrupt */ +# define EXCCAUSE_LEVEL1INTERRUPT 4 /* (backward compatibility macro, deprecated, avoid) */ +#define EXCCAUSE_ALLOCA 5 /* Stack Extension Assist (MOVSP instruction) for alloca */ +#define EXCCAUSE_DIVIDE_BY_ZERO 6 /* Integer Divide by Zero */ +#define EXCCAUSE_SPECULATION 7 /* Use of Failed Speculative Access (not implemented) */ +#define EXCCAUSE_PRIVILEGED 8 /* Privileged Instruction */ +#define EXCCAUSE_UNALIGNED 9 /* Unaligned Load or Store */ +/* Reserved 10..11 */ +#define EXCCAUSE_INSTR_DATA_ERROR 12 /* PIF Data Error on Instruction Fetch (RB-200x and later) */ +#define EXCCAUSE_LOAD_STORE_DATA_ERROR 13 /* PIF Data Error on Load or Store (RB-200x and later) */ +#define EXCCAUSE_INSTR_ADDR_ERROR 14 /* PIF Address Error on Instruction Fetch (RB-200x and later) */ +#define EXCCAUSE_LOAD_STORE_ADDR_ERROR 15 /* PIF Address Error on Load or Store (RB-200x and later) */ +#define EXCCAUSE_ITLB_MISS 16 /* ITLB Miss (no ITLB entry matches, hw refill also missed) */ +#define EXCCAUSE_ITLB_MULTIHIT 17 /* ITLB Multihit (multiple ITLB entries match) */ +#define EXCCAUSE_INSTR_RING 18 /* Ring Privilege Violation on Instruction Fetch */ +/* Reserved 19 */ /* Size Restriction on IFetch (not implemented) */ +#define EXCCAUSE_INSTR_PROHIBITED 20 /* Cache Attribute does not allow Instruction Fetch */ +/* Reserved 21..23 */ +#define EXCCAUSE_DTLB_MISS 24 /* DTLB Miss (no DTLB entry matches, hw refill also missed) */ +#define EXCCAUSE_DTLB_MULTIHIT 25 /* DTLB Multihit (multiple DTLB entries match) */ +#define EXCCAUSE_LOAD_STORE_RING 26 /* Ring Privilege Violation on Load or Store */ +/* Reserved 27 */ /* Size Restriction on Load/Store (not implemented) */ +#define EXCCAUSE_LOAD_PROHIBITED 28 /* Cache Attribute does not allow Load */ +#define EXCCAUSE_STORE_PROHIBITED 29 /* Cache Attribute does not allow Store */ +/* Reserved 30..31 */ +#define EXCCAUSE_CP_DISABLED(n) (32+(n)) /* Access to Coprocessor 'n' when disabled */ +#define EXCCAUSE_CP0_DISABLED 32 /* Access to Coprocessor 0 when disabled */ +#define EXCCAUSE_CP1_DISABLED 33 /* Access to Coprocessor 1 when disabled */ +#define EXCCAUSE_CP2_DISABLED 34 /* Access to Coprocessor 2 when disabled */ +#define EXCCAUSE_CP3_DISABLED 35 /* Access to Coprocessor 3 when disabled */ +#define EXCCAUSE_CP4_DISABLED 36 /* Access to Coprocessor 4 when disabled */ +#define EXCCAUSE_CP5_DISABLED 37 /* Access to Coprocessor 5 when disabled */ +#define EXCCAUSE_CP6_DISABLED 38 /* Access to Coprocessor 6 when disabled */ +#define EXCCAUSE_CP7_DISABLED 39 /* Access to Coprocessor 7 when disabled */ +/*#define EXCCAUSE_FLOATING_POINT 40*/ /* Floating Point Exception (not implemented) */ +/* Reserved 40..63 */ + +/* PS register fields: */ +#define PS_WOE_SHIFT 18 +#define PS_WOE_MASK 0x00040000 +#define PS_WOE PS_WOE_MASK +#define PS_CALLINC_SHIFT 16 +#define PS_CALLINC_MASK 0x00030000 +#define PS_CALLINC(n) (((n)&3)< Date: Mon, 1 Sep 2025 20:59:30 -0300 Subject: [PATCH 4/7] Fix empty returns in non-void functions - Previously lwIP_ASSERT expanded to `return;`, which breaks when used inside functions with non-void return types (causing -Werror failures): this patch updates the macro to allow specifying an appropriate return value. - nodemcu_mdns.c: `send_packet`, also had empty returns. While these could be bypassed with `-Wno-error=return-type`, explicitly returning a value is safer and more correct. --- app/lwip/app/espconn_buf.c | 22 +++++++++++++--------- app/net/nodemcu_mdns.c | 6 +++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/lwip/app/espconn_buf.c b/app/lwip/app/espconn_buf.c index f91d1d23e..bdc68a5e8 100644 --- a/app/lwip/app/espconn_buf.c +++ b/app/lwip/app/espconn_buf.c @@ -20,7 +20,11 @@ static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__; #define lwIP_unlikely(Expression) !!(Expression) #endif -#define lwIP_ASSERT(Expression) do{if(!(Expression)) {os_printf("%s %d\n", __func__, __LINE__);return;}}while(0) +#define lwIP_ASSERT(Expression) \ + do { if(!(Expression)) { os_printf("%s %d\n", __func__, __LINE__); return; }} while(0) + +#define lwIP_ASSERT_RET(Expression, Retval) \ + do { if(!(Expression)) { os_printf("%s %d\n", __func__, __LINE__); return (Retval); }} while(0) ringbuf_t ringbuf_new(size_t capacity) { @@ -101,7 +105,7 @@ const void* ringbuf_head(const struct ringbuf_t *rb) static uint8_t *ringbuf_nextp(ringbuf_t rb, const uint8_t *p) { - lwIP_ASSERT((p >= rb->buf) && (p < ringbuf_end(rb))); + lwIP_ASSERT_RET((p >= rb->buf) && (p < ringbuf_end(rb)), 0); return rb->buf + ((++p -rb->buf) % ringbuf_buffer_size(rb)); } @@ -113,7 +117,7 @@ size_t ringbuf_findchr(const struct ringbuf_t *rb, int c, size_t offset) return bytes_used; const uint8_t *start = rb ->buf + (((rb->tail - rb->buf) + offset) % ringbuf_buffer_size(rb)); - lwIP_ASSERT(bufend > start); + lwIP_ASSERT_RET(bufend > start, 0); size_t n = LWIP_MIN(bufend - start, bytes_used - offset); const uint8_t *found = (const uint8_t *)memchr(start, c, n); if (found) @@ -131,7 +135,7 @@ size_t ringbuf_memset(ringbuf_t dst, int c, size_t len) while (nwritten != count){ - lwIP_ASSERT(bufend > dst->head); + lwIP_ASSERT_RET(bufend > dst->head, 0); size_t n = LWIP_MIN(bufend - dst->head, count - nwritten); os_memset(dst->head, c, n); dst->head += n; @@ -143,7 +147,7 @@ size_t ringbuf_memset(ringbuf_t dst, int c, size_t len) if (overflow){ dst->tail = ringbuf_nextp(dst, dst->head); - lwIP_ASSERT(ringbuf_is_full(dst)); + lwIP_ASSERT_RET(ringbuf_is_full(dst), 0); } return nwritten; @@ -157,7 +161,7 @@ void *ringbuf_memcpy_into(ringbuf_t dst,const void *src, size_t count) size_t nread = 0; while (nread != count){ - lwIP_ASSERT(bufend > dst->head); + lwIP_ASSERT_RET(bufend > dst->head, NULL); size_t n = LWIP_MIN(bufend - dst->head, count - nread); os_memcpy(dst->head, u8src + nread, n); dst->head += n; @@ -169,7 +173,7 @@ void *ringbuf_memcpy_into(ringbuf_t dst,const void *src, size_t count) if (overflow) { dst->tail = ringbuf_nextp(dst, dst->head); - lwIP_ASSERT(ringbuf_is_full(dst)); + lwIP_ASSERT_RET(ringbuf_is_full(dst), NULL); } return dst->head; @@ -187,7 +191,7 @@ void *ringbuf_memcpy_from(void *dst,ringbuf_t src, size_t count) size_t nwritten = 0; while (nwritten != count){ - lwIP_ASSERT(bufend > src->tail); + lwIP_ASSERT_RET(bufend > src->tail, NULL); size_t n = LWIP_MIN(bufend - src->tail, count - nwritten); os_memcpy((uint8_t*)u8dst + nwritten, src->tail, n); src->tail += n; @@ -197,7 +201,7 @@ void *ringbuf_memcpy_from(void *dst,ringbuf_t src, size_t count) src->tail = src->buf; } - lwIP_ASSERT(count + ringbuf_bytes_used(src) == bytes_used); + lwIP_ASSERT_RET(count + ringbuf_bytes_used(src) == bytes_used, NULL); return src->tail; } diff --git a/app/net/nodemcu_mdns.c b/app/net/nodemcu_mdns.c index 119d7a38f..a880955e7 100644 --- a/app/net/nodemcu_mdns.c +++ b/app/net/nodemcu_mdns.c @@ -317,16 +317,16 @@ static err_t send_packet(struct pbuf *p, struct ip_addr *dst_addr, u16_t dst_por if (addr_ptr) { if (wifi_get_opmode() == 0x02) { if (!ap_netif) { - return; + return 0; } memcpy(addr_ptr, &ap_netif->ip_addr, sizeof(ap_netif->ip_addr)); } else { if (!sta_netif) { - return; + return 0; } memcpy(addr_ptr, &sta_netif->ip_addr, sizeof(sta_netif->ip_addr)); } - } + } if (dst_addr) { err = udp_sendto(mdns_pcb, p, dst_addr, dst_port); From ff4cdae113c78ca893bdfa02111cc69ebefe274e Mon Sep 17 00:00:00 2001 From: caiohamamura Date: Tue, 2 Sep 2025 21:58:40 -0300 Subject: [PATCH 5/7] Minor fixes in Makefiles: - Project Makefile: Fallback $OS in linux to $(UNAME_S) which uses `uname -s` in linux, since $(OS) is specific to windows. - Luac Cross: add .exe when compiling for windows. --- app/lua/luac_cross/Makefile | 4 ++++ app/lua53/host/Makefile | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/lua/luac_cross/Makefile b/app/lua/luac_cross/Makefile index 19021ac94..2a1438bbf 100644 --- a/app/lua/luac_cross/Makefile +++ b/app/lua/luac_cross/Makefile @@ -88,6 +88,10 @@ else IMAGE := ../../../luac.cross.int endif +ifeq ($(OS),Windows_NT) + IMAGE := $(IMAGE).exe +endif + .PHONY: test clean all all: $(DEPS) $(IMAGE) diff --git a/app/lua53/host/Makefile b/app/lua53/host/Makefile index 5b3ffc062..e7d21a985 100644 --- a/app/lua53/host/Makefile +++ b/app/lua53/host/Makefile @@ -90,6 +90,10 @@ else IMAGE := ../../../luac.cross.int endif +ifeq ($(OS),Windows_NT) + IMAGE := $(IMAGE).exe +endif + .PHONY: test clean all all: $(DEPS) $(IMAGE) From f57fc3fd29dd64ea0ff1a4eca08735104bc70d41 Mon Sep 17 00:00:00 2001 From: caiohamamura Date: Wed, 3 Sep 2025 01:01:07 -0300 Subject: [PATCH 6/7] Windows support: added building and testing github actions --- .github/workflows/build.yml | 129 ++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d9aff497c..b27025040 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,6 +55,87 @@ jobs: name: luac.cross_${{ matrix.lua_ver }}_${{ matrix.numbers }} path: luac.cross + build_win_msys2: + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + include: + - lua_ver: 51 + numbers: float + - lua_ver: 51 + numbers: integral + - lua_ver: 53 + numbers: float + - lua_ver: 53 + numbers: 64bit + + env: + LUA: ${{ matrix.lua_ver }} + MSYSTEM: MINGW32 + CHERE_INVOKING: 1 + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - uses: msys2/setup-msys2@v2 + with: + update: true + cache: true + install: >- + make + gcc + python + python-pip + unzip + + - name: Setup Python venv + shell: msys2 {0} + run: | + python -m venv .venv + . .venv/bin/activate + python -m pip install --upgrade pip + pip install pyserial + + - name: Build firmware + shell: msys2 {0} + run: | + . .venv/bin/activate + + EXTRA_FLAGS="" + if [ "${{ matrix.numbers }}" = "integral" ]; then + EXTRA_FLAGS="-DLUA_NUMBER_INTEGRAL" + elif [ "${{ matrix.numbers }}" = "64bit" ]; then + EXTRA_FLAGS="-DLUA_NUMBER_64BITS" + fi + make EXTRA_CCFLAGS=$EXTRA_FLAGS + + if [ "${{ matrix.numbers }}" = "integral" ]; then + mv -f luac.cross.int.exe luac.cross.exe + fi + + - name: Copy required DLLs + shell: msys2 {0} + run: | + ldd luac.cross.exe | awk '{print $3}' | grep -vi "/c/windows" | xargs -I{} cp -v {} . || true + ls *.dll + + - name: Check build items + shell: msys2 {0} + run: | + ls -ll bin/0x00000.bin bin/0x10000.bin luac.cross.exe + + - name: Upload luac.cross + if: ${{ success() }} + uses: actions/upload-artifact@v4 + with: + name: luac.cross_${{ matrix.lua_ver }}_${{ matrix.numbers }}_win + path: | + luac.cross.exe + *.dll + # The files in the 'msvc' folder would need to be updated to be compatible with VS 2022. # Sample job (that failed): https://github.com/nodemcu/nodemcu-firmware/actions/runs/17306868602/job/49131917376#step:3:153 # => disable the Windows jobs for now @@ -225,6 +306,54 @@ jobs: # (if grep " ==> " log ; then exit 1 ; fi) # shell: bash + NTest_win_msys2: + + strategy: + fail-fast: false + matrix: + include: + - lua_ver: 51 + numbers: 'float' + - lua_ver: 53 + numbers: 'float' + - lua_ver: 51 + numbers: 'integral' + - lua_ver: 53 + numbers: '64bit' + + needs: build_win_msys2 + runs-on: windows-latest + env: + MSYSTEM: MINGW32 + CHERE_INVOKING: 1 + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + submodules: false + - name: Download luac.cross + uses: actions/download-artifact@v4 + with: + name: luac.cross_${{ matrix.lua_ver }}_${{ matrix.numbers }}_win + path: ./ + - name: NTest selfcheck + run: | + cd tests/NTest + ../../luac.cross.exe -e ../NTest/NTest_NTest.lua | tee log + if ((gc log | Select-String "failed: 0") -eq $null) { + Throw "Errors were found during tests"; + } + shell: pwsh + + - name: NTest hosttests + run: | + cd tests + cp NTest/NTest.lua . + ../luac.cross.exe -e NTest_lua.lua | tee log + if ((gc log | Select-String " ==> ") -ne $null) { + Throw "Errors were found during tests"; + } luacheck: From 3ddf1727b2d13c6f81da26ae30e4d9a04b6d2ff4 Mon Sep 17 00:00:00 2001 From: caiohamamura Date: Wed, 3 Sep 2025 17:12:55 -0300 Subject: [PATCH 7/7] Use nodemcu/espressif-sdk-archive toolchains urls for windows --- .github/workflows/build.yml | 25 +++++++++++-------------- Makefile | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b27025040..21653cd3d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -80,19 +80,16 @@ jobs: with: submodules: true - - uses: msys2/setup-msys2@v2 - with: - update: true - cache: true - install: >- - make - gcc - python - python-pip - unzip + - name: Download ESP32 MSYS2 Toolchain + run: | + Invoke-WebRequest -Uri "https://media.githubusercontent.com/media/nodemcu/espressif-sdk-archive/refs/heads/master/esp32_win32_msys2_environment_and_toolchain-20181001.zip" -OutFile "esp32_toolchain.zip" + - name: Extract Toolchain + run: | + Expand-Archive -Path "esp32_toolchain.zip" -DestinationPath "D:\" -Force + - name: Setup Python venv - shell: msys2 {0} + shell: D:\msys32\usr\bin\bash.exe --login {0} run: | python -m venv .venv . .venv/bin/activate @@ -100,7 +97,7 @@ jobs: pip install pyserial - name: Build firmware - shell: msys2 {0} + shell: D:\msys32\usr\bin\bash.exe --login {0} run: | . .venv/bin/activate @@ -117,13 +114,13 @@ jobs: fi - name: Copy required DLLs - shell: msys2 {0} + shell: D:\msys32\usr\bin\bash.exe --login {0} run: | ldd luac.cross.exe | awk '{print $3}' | grep -vi "/c/windows" | xargs -I{} cp -v {} . || true ls *.dll - name: Check build items - shell: msys2 {0} + shell: D:\msys32\usr\bin\bash.exe --login {0} run: | ls -ll bin/0x00000.bin bin/0x10000.bin luac.cross.exe diff --git a/Makefile b/Makefile index 2ea622dae..8b0fde21c 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,7 @@ ifeq ($(OS),Windows_NT) TOOLCHAIN_VERSION = 2020r3 GCCTOOLCHAIN = xtensa-lx106-elf-gcc8_4_0-esp-$(TOOLCHAIN_VERSION)-win32 TOOLCHAIN_ROOT = $(TOP_DIR)/tools/toolchains/esp8266-$(GCCTOOLCHAIN) - ESPRESSIF_URL = https://dl.espressif.com/dl + ESPRESSIF_URL = https://media.githubusercontent.com/media/nodemcu/espressif-sdk-archive/refs/heads/master TOOLCHAIN_EXT = zip TOOLCHAIN_URL = $(ESPRESSIF_URL)/$(GCCTOOLCHAIN).$(TOOLCHAIN_EXT) WGET = wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused