Skip to content

Commit

Permalink
PIO: patch lwip1 MTU bug in travis (#1723)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr authored May 19, 2019
1 parent 55b9f2a commit c7d4671
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ install:
env:
global:
- BUILDER_TOTAL_THREADS=4
- ESPURNA_PIO_PATCH_ISSUE_1610=y
script:
- cd code && ./build.sh -p && cd ..
stages:
Expand Down
34 changes: 34 additions & 0 deletions code/extra_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,36 @@ def dummy_ets_printf(target, source, env):
env.Execute(env.VerboseAction(" ".join(cmd), "Removing ets_printf / ets_printf_P"))
env.Depends(postmortem_obj_file,"$BUILD_DIR/src/dummy_ets_printf.c.o")

def patch_lwip():
# ignore when building with lwip2
if "lwip_gcc" not in env["LIBS"]:
return

framework_dir = env["FRAMEWORK_ARDUINOESP8266_DIR"]

platform = env.PioPlatform()
toolchain_prefix = os.path.join(platform.get_package_dir("toolchain-xtensa"), "bin", "xtensa-lx106-elf-")

patch_action = env.VerboseAction(" ".join([
"-patch", "-u", "-N", "-d",
os.path.join(framework_dir, "tools", "sdk", "lwip"),
os.path.join("src", "core", "tcp_out.c"),
env.subst(os.path.join("$PROJECT_DIR", "..", "dist", "patches", "lwip_mtu_issue_1610.patch"))
]), "Patching lwip source")
build_action = env.VerboseAction(" ".join([
"make", "-C", os.path.join(framework_dir, "tools", "sdk", "lwip", "src"),
"install",
"TOOLS_PATH={}".format(toolchain_prefix),
"LWIP_LIB=liblwip_gcc.a"
]), "Rebuilding lwip")

patcher = env.Alias("patch-lwip", None, patch_action)
builder = env.Alias("build-lwip", patcher, build_action)
if os.environ.get("ESPURNA_PIO_PATCH_ISSUE_1610"):
env.Depends("$BUILD_DIR/${PROGNAME}.elf", builder)
env.AlwaysBuild(patcher)
env.AlwaysBuild(builder)

# ------------------------------------------------------------------------------
# Hooks
# ------------------------------------------------------------------------------
Expand All @@ -109,3 +139,7 @@ def dummy_ets_printf(target, source, env):
if "DISABLE_POSTMORTEM_STACKDUMP" in env["CPPFLAGS"]:
env.AddPostAction("$BUILD_DIR/FrameworkArduino/core_esp8266_postmortem.c.o", dummy_ets_printf)
env.AddPostAction("$BUILD_DIR/FrameworkArduino/core_esp8266_postmortem.cpp.o", dummy_ets_printf)

# patch lwip1 sources conditionally:
# https://github.com/xoseperez/espurna/issues/1610
patch_lwip()
13 changes: 13 additions & 0 deletions dist/patches/lwip_mtu_issue_1610.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c
index fa8d77f..a7b0595 100644
--- a/src/core/tcp_out.c
+++ b/src/core/tcp_out.c
@@ -469,7 +469,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags)
if (oversize > 0) {
LWIP_ASSERT("inconsistent oversize vs. space", oversize_used <= space);
seg = last_unsent;
- oversize_used = oversize < len ? oversize : len;
+ oversize_used = LWIP_MIN(space, LWIP_MIN(oversize, len));
pos += oversize_used;
oversize -= oversize_used;
space -= oversize_used;

0 comments on commit c7d4671

Please sign in to comment.