From 15165ee9feabb930ec70362308635294d641cdb9 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 27 Nov 2025 20:29:24 +0100 Subject: [PATCH] Upgrade to mainstream lwip 2.2.1 --- download_dependencies.sh | 6 ++-- ee/network/tcpip/Makefile | 42 +++++++++++++++++++++++-- ee/network/tcpip/src/include/arch/cc.h | 1 + ee/network/tcpip/src/include/lwipopts.h | 2 ++ ee/network/tcpip/src/ps2ip_internal.h | 1 + ee/network/tcpip/src/sys_arch.c | 6 ++++ iop/network/smap/src/imports.lst | 2 +- iop/system/sysclib/include/ctype.h | 2 ++ iop/tcpip/tcpip-base/include/arch/cc.h | 4 +-- iop/tcpip/tcpip-base/include/lwipopts.h | 2 ++ iop/tcpip/tcpip-base/include/stdlib.h | 36 +++++++++++++++++++++ iop/tcpip/tcpip-base/sys_arch.c | 6 ++++ iop/tcpip/tcpip-netman/src/exports.tab | 2 +- iop/tcpip/tcpip-netman/src/imports.lst | 3 ++ iop/tcpip/tcpip-netman/src/ps2ip.c | 3 ++ iop/tcpip/tcpip/Makefile | 42 +++++++++++++++++++++++-- iop/tcpip/tcpip/include/ps2ip.h | 10 ++---- iop/tcpip/tcpip/src/exports.tab | 17 +++++----- iop/tcpip/tcpip/src/imports.lst | 3 ++ iop/tcpip/tcpip/src/ps2ip.c | 4 +++ 20 files changed, 165 insertions(+), 29 deletions(-) create mode 100644 iop/tcpip/tcpip-base/include/stdlib.h diff --git a/download_dependencies.sh b/download_dependencies.sh index 8a62f92901b..0a046a0226e 100755 --- a/download_dependencies.sh +++ b/download_dependencies.sh @@ -14,14 +14,14 @@ if [ "x$1" != "xlocked" ]; then fi ## Download LWIP -LWIP_REPO_URL="https://github.com/ps2dev/lwip.git" +LWIP_REPO_URL="https://github.com/lwip-tcpip/lwip.git" LWIP_REPO_FOLDER="common/external_deps/lwip" -LWIP_BRANCH_NAME="ps2-v2.0.3" +LWIP_BRANCH_NAME="STABLE-2_2_1_RELEASE" if test ! -d "$LWIP_REPO_FOLDER"; then git clone --depth 1 -b $LWIP_BRANCH_NAME $LWIP_REPO_URL "$LWIP_REPO_FOLDER"_inprogress || exit 1 mv "$LWIP_REPO_FOLDER"_inprogress "$LWIP_REPO_FOLDER" else - (cd "$LWIP_REPO_FOLDER" && git fetch origin && git reset --hard "origin/${LWIP_BRANCH_NAME}" && git checkout "$LWIP_BRANCH_NAME" && cd - )|| exit 1 + (cd "$LWIP_REPO_FOLDER" && git fetch origin --tags && git reset --hard "${LWIP_BRANCH_NAME}" && git checkout "$LWIP_BRANCH_NAME" && cd - )|| exit 1 fi ## Download libsmb2 diff --git a/ee/network/tcpip/Makefile b/ee/network/tcpip/Makefile index 4ac9ef2e972..cae15eb6bf7 100644 --- a/ee/network/tcpip/Makefile +++ b/ee/network/tcpip/Makefile @@ -35,9 +35,42 @@ endif EE_INCS += -I$(LWIP)/src/include -I$(LWIP)/src/include/ipv4 -ps2api_OBJECTS = api_lib.o api_msg.o api_netbuf.o err.o sockets.o tcpip.o -ps2api_IPV4 = icmp.o ip.o ip4.o ip4_addr.o ip4_frag.o inet_chksum.o -ps2ip_OBJECTS = sys.o lwip_init.o mem.o netif.o pbuf.o stats.o tcp_in.o tcp_out.o udp.o memp.o tcp.o ethernet.o etharp.o raw.o def.o timeouts.o $(ps2api_IPV4) $(ps2api_OBJECTS) +ps2api_OBJECTS = \ + api_lib.o \ + api_msg.o \ + api_netbuf.o \ + err.o \ + sockets.o \ + tcpip.o + +ps2api_IPV4 = \ + acd.o \ + icmp.o \ + ip.o \ + ip4.o \ + ip4_addr.o \ + ip4_frag.o \ + inet_chksum.o + +ps2ip_OBJECTS = \ + sys.o \ + lwip_init.o \ + mem.o \ + netif.o \ + pbuf.o \ + stats.o \ + tcp_in.o \ + tcp_out.o \ + udp.o \ + memp.o \ + tcp.o \ + ethernet.o \ + etharp.o \ + raw.o \ + def.o \ + timeouts.o \ + $(ps2api_IPV4) \ + $(ps2api_OBJECTS) ifdef PS2IP_DHCP ps2ip_OBJECTS += dhcp.o @@ -82,6 +115,9 @@ $(EE_OBJS_DIR)api_msg.o: $(LWIP)/src/api/api_msg.c $(EE_OBJS_DIR)api_netbuf.o: $(LWIP)/src/api/netbuf.c $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ +$(EE_OBJS_DIR)acd.o: $(LWIP)/src/core/ipv4/acd.c + $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ + $(EE_OBJS_DIR)icmp.o: $(LWIP)/src/core/ipv4/icmp.c $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ diff --git a/ee/network/tcpip/src/include/arch/cc.h b/ee/network/tcpip/src/include/arch/cc.h index a8ef6c6abb6..c3be57d3271 100644 --- a/ee/network/tcpip/src/include/arch/cc.h +++ b/ee/network/tcpip/src/include/arch/cc.h @@ -4,6 +4,7 @@ #include #include #include +#include #define PACK_STRUCT_FIELD(x) x __attribute((packed)) #define PACK_STRUCT_STRUCT __attribute((packed)) diff --git a/ee/network/tcpip/src/include/lwipopts.h b/ee/network/tcpip/src/include/lwipopts.h index 6b2fd7b79a5..90c45afcfd8 100644 --- a/ee/network/tcpip/src/include/lwipopts.h +++ b/ee/network/tcpip/src/include/lwipopts.h @@ -244,6 +244,8 @@ */ #define LWIP_CHECKSUM_ON_COPY 1 +/* Define LWIP_ERRNO_STDINCLUDE if you want to include here */ +#define LWIP_ERRNO_STDINCLUDE 1 /* ------------------------------------ ---------- Socket options ---------- diff --git a/ee/network/tcpip/src/ps2ip_internal.h b/ee/network/tcpip/src/ps2ip_internal.h index 59d333b7399..bcdd1b9fb9b 100644 --- a/ee/network/tcpip/src/ps2ip_internal.h +++ b/ee/network/tcpip/src/ps2ip_internal.h @@ -11,6 +11,7 @@ #ifndef IOP_PS2IP_INTERNAL_H #define IOP_PS2IP_INTERNAL_H +#include #include "lwip/sockets.h" typedef struct diff --git a/ee/network/tcpip/src/sys_arch.c b/ee/network/tcpip/src/sys_arch.c index 3b2371591da..f67b8070048 100644 --- a/ee/network/tcpip/src/sys_arch.c +++ b/ee/network/tcpip/src/sys_arch.c @@ -338,6 +338,12 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *sys_msg) return result; } +err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg) +{ + // On PS2 EE, ISR and task level are the same, so just call trypost + return sys_mbox_trypost(mbox, msg); +} + void sys_mbox_post(sys_mbox_t *mbox, void *sys_msg) { SendMbx(mbox, alloc_msg(), sys_msg); diff --git a/iop/network/smap/src/imports.lst b/iop/network/smap/src/imports.lst index ac17ea7e16d..f4247410f15 100644 --- a/iop/network/smap/src/imports.lst +++ b/iop/network/smap/src/imports.lst @@ -63,7 +63,7 @@ I_inet_addr I_tcpip_input I_netif_set_link_up I_netif_set_link_down -I_tcpip_callback_with_block +I_tcpip_callback ps2ip_IMPORTS_end #endif diff --git a/iop/system/sysclib/include/ctype.h b/iop/system/sysclib/include/ctype.h index 08330f29745..d8d2df80176 100644 --- a/iop/system/sysclib/include/ctype.h +++ b/iop/system/sysclib/include/ctype.h @@ -63,6 +63,8 @@ extern "C" { /** Blank (space) */ #define _B 0x80 +extern unsigned char look_ctype_table(char character); + #define isalpha(c) (look_ctype_table((unsigned int)(c)) & (_U|_L)) #define isupper(c) (look_ctype_table((unsigned int)(c)) & (_U)) #define islower(c) (look_ctype_table((unsigned int)(c)) & (_L)) diff --git a/iop/tcpip/tcpip-base/include/arch/cc.h b/iop/tcpip/tcpip-base/include/arch/cc.h index f3b915b0a13..a1b0d7c02e6 100644 --- a/iop/tcpip/tcpip-base/include/arch/cc.h +++ b/iop/tcpip/tcpip-base/include/arch/cc.h @@ -1,8 +1,8 @@ #ifndef __CC_H__ #define __CC_H__ -#include #include +#include #define BYTE_ORDER LITTLE_ENDIAN @@ -47,8 +47,6 @@ typedef u32_t mem_ptr_t; #define LWIP_PLATFORM_ASSERT(args) #endif -#define atoi(x) strtol(x, NULL, 10) - #define LWIP_NO_STDINT_H 1 //stdint.h does not exist. #define LWIP_NO_INTTYPES_H 1 //inttypes.h does not exist. diff --git a/iop/tcpip/tcpip-base/include/lwipopts.h b/iop/tcpip/tcpip-base/include/lwipopts.h index f3781cc2a7f..fd7fe19b1dc 100644 --- a/iop/tcpip/tcpip-base/include/lwipopts.h +++ b/iop/tcpip/tcpip-base/include/lwipopts.h @@ -236,6 +236,8 @@ */ #define LWIP_CHECKSUM_ON_COPY 1 +/* Use PS2SDK's errno.h instead of lwIP's own errno definitions */ +#define LWIP_ERRNO_STDINCLUDE 1 /* ------------------------------------ ---------- Socket options ---------- diff --git a/iop/tcpip/tcpip-base/include/stdlib.h b/iop/tcpip/tcpip-base/include/stdlib.h new file mode 100644 index 00000000000..7f0cb395570 --- /dev/null +++ b/iop/tcpip/tcpip-base/include/stdlib.h @@ -0,0 +1,36 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +*/ + +/** + * @file + * Minimal stdlib.h for IOP tcpip + * Provides basic functions needed by lwIP on the IOP + */ + +#ifndef __IOP_TCPIP_STDLIB_H__ +#define __IOP_TCPIP_STDLIB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* atoi - convert string to integer + * Implemented as a macro using strtol from sysclib + */ +#define atoi(x) strtol(x, NULL, 10) + +/* Required for strtol */ +long int strtol(const char *nptr, char **endptr, int base); + +#ifdef __cplusplus +} +#endif + +#endif /* __IOP_TCPIP_STDLIB_H__ */ diff --git a/iop/tcpip/tcpip-base/sys_arch.c b/iop/tcpip/tcpip-base/sys_arch.c index adf8bf3cec5..9cca38af782 100644 --- a/iop/tcpip/tcpip-base/sys_arch.c +++ b/iop/tcpip/tcpip-base/sys_arch.c @@ -182,6 +182,12 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg){ return result; } +err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg) +{ + // On PS2 IOP, ISR and task level are the same, so just call trypost + return sys_mbox_trypost(mbox, msg); +} + void sys_mbox_post(sys_mbox_t *mbox, void *msg) { arch_message *MsgPkt; diff --git a/iop/tcpip/tcpip-netman/src/exports.tab b/iop/tcpip/tcpip-netman/src/exports.tab index 470bc1fcd03..f04f753ad27 100644 --- a/iop/tcpip/tcpip-netman/src/exports.tab +++ b/iop/tcpip/tcpip-netman/src/exports.tab @@ -67,6 +67,6 @@ DECLARE_EXPORT_TABLE(ps2ip, 2, 6) #endif DECLARE_EXPORT(netif_set_link_up) DECLARE_EXPORT(netif_set_link_down) //55 - DECLARE_EXPORT(tcpip_callback_with_block) + DECLARE_EXPORT(tcpip_callback) DECLARE_EXPORT(pbuf_coalesce) END_EXPORT_TABLE diff --git a/iop/tcpip/tcpip-netman/src/imports.lst b/iop/tcpip/tcpip-netman/src/imports.lst index 5237c25a572..20e7d2b753b 100644 --- a/iop/tcpip/tcpip-netman/src/imports.lst +++ b/iop/tcpip/tcpip-netman/src/imports.lst @@ -50,6 +50,7 @@ I_ReceiveMbx thmsgbx_IMPORTS_end sysclib_IMPORTS_start +I_look_ctype_table I_memset I_strcpy I_strncpy @@ -59,8 +60,10 @@ I_strncmp I_strtok I_strtoul I_memcmp +I_memmove I_strtol I_strcmp +I_tolower sysclib_IMPORTS_end sysmem_IMPORTS_start diff --git a/iop/tcpip/tcpip-netman/src/ps2ip.c b/iop/tcpip/tcpip-netman/src/ps2ip.c index da3fefb3fad..547aec16713 100644 --- a/iop/tcpip/tcpip-netman/src/ps2ip.c +++ b/iop/tcpip/tcpip-netman/src/ps2ip.c @@ -35,6 +35,9 @@ #include "ps2ip_internal.h" +/* Define errno for IOP module */ +int errno __attribute__((section("data"))); + typedef struct pbuf PBuf; typedef struct netif NetIF; typedef struct ip4_addr IPAddr; diff --git a/iop/tcpip/tcpip/Makefile b/iop/tcpip/tcpip/Makefile index fada0932d84..88f0e59567b 100644 --- a/iop/tcpip/tcpip/Makefile +++ b/iop/tcpip/tcpip/Makefile @@ -45,9 +45,42 @@ IOP_INCS += \ -I$(LWIP)/src/include/ipv4 \ -I$(PS2IP_BASE)/include -ps2api_OBJECTS = api_lib.o api_msg.o api_netbuf.o err.o sockets.o tcpip.o -ps2api_IPV4 = icmp.o ip.o ip4.o ip4_addr.o ip4_frag.o inet_chksum.o -ps2ip_OBJECTS = sys.o lwip_init.o mem.o netif.o pbuf.o stats.o tcp_in.o tcp_out.o udp.o memp.o tcp.o ethernet.o etharp.o raw.o def.o timeouts.o $(ps2api_IPV4) $(ps2api_OBJECTS) +ps2api_OBJECTS = \ + api_lib.o \ + api_msg.o \ + api_netbuf.o \ + err.o \ + sockets.o \ + tcpip.o + +ps2api_IPV4 = \ + acd.o \ + icmp.o \ + ip.o \ + ip4.o \ + ip4_addr.o \ + ip4_frag.o \ + inet_chksum.o + +ps2ip_OBJECTS = \ + sys.o \ + lwip_init.o \ + mem.o \ + netif.o \ + pbuf.o \ + stats.o \ + tcp_in.o \ + tcp_out.o \ + udp.o \ + memp.o \ + tcp.o \ + ethernet.o \ + etharp.o \ + raw.o \ + def.o \ + timeouts.o \ + $(ps2api_IPV4) \ + $(ps2api_OBJECTS) ifdef PS2IP_DHCP ps2ip_OBJECTS += dhcp.o @@ -92,6 +125,9 @@ $(IOP_OBJS_DIR)api_msg.o: $(LWIP)/src/api/api_msg.c $(IOP_OBJS_DIR)api_netbuf.o: $(LWIP)/src/api/netbuf.c $(IOP_CC) $(IOP_CFLAGS) -c $< -o $@ +$(IOP_OBJS_DIR)acd.o: $(LWIP)/src/core/ipv4/acd.c + $(IOP_CC) $(IOP_CFLAGS) -c $< -o $@ + $(IOP_OBJS_DIR)icmp.o: $(LWIP)/src/core/ipv4/icmp.c $(IOP_CC) $(IOP_CFLAGS) -c $< -o $@ diff --git a/iop/tcpip/tcpip/include/ps2ip.h b/iop/tcpip/tcpip/include/ps2ip.h index 02897051ddf..46f0ceb2bc8 100644 --- a/iop/tcpip/tcpip/include/ps2ip.h +++ b/iop/tcpip/tcpip/include/ps2ip.h @@ -61,13 +61,7 @@ extern err_t tcpip_input(struct pbuf *p, struct netif *inp); /** Function prototype for functions passed to tcpip_callback() */ typedef void (*tcpip_callback_fn)(void *ctx); -extern err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8 block); - -/** - * @ingroup lwip_os - * @see tcpip_callback_with_block - */ -#define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1) +extern err_t tcpip_callback(tcpip_callback_fn function, void *ctx); /* From include/lwip/netif.h: */ extern struct netif *netif_add(struct netif *netif, @@ -188,7 +182,7 @@ extern const ip_addr_t* dns_getserver(u8 numdns); #define I_lwip_fcntl DECLARE_IMPORT(47, lwip_fcntl) #define I_etharp_output DECLARE_IMPORT(23, etharp_output) #define I_tcpip_input DECLARE_IMPORT(25, tcpip_input) -#define I_tcpip_callback_with_block DECLARE_IMPORT(56, tcpip_callback_with_block) +#define I_tcpip_callback DECLARE_IMPORT(56, tcpip_callback) #define I_netif_add DECLARE_IMPORT(26, netif_add) #define I_netif_find DECLARE_IMPORT(27, netif_find) #define I_netif_set_default DECLARE_IMPORT(28, netif_set_default) diff --git a/iop/tcpip/tcpip/src/exports.tab b/iop/tcpip/tcpip/src/exports.tab index 470bc1fcd03..2596c86a6e4 100644 --- a/iop/tcpip/tcpip/src/exports.tab +++ b/iop/tcpip/tcpip/src/exports.tab @@ -50,23 +50,26 @@ DECLARE_EXPORT_TABLE(ps2ip, 2, 6) DECLARE_EXPORT(ip4addr_ntoa_r) //45 DECLARE_EXPORT(lwip_shutdown) DECLARE_EXPORT(lwip_fcntl) + DECLARE_EXPORT(acd_netif_ip_addr_changed) + DECLARE_EXPORT(acd_network_changed_link_down) + DECLARE_EXPORT(acd_arp_reply) //50 #ifdef PS2IP_DNS DECLARE_EXPORT(lwip_gethostbyname) DECLARE_EXPORT(lwip_gethostbyname_r) - DECLARE_EXPORT(lwip_freeaddrinfo) //50 + DECLARE_EXPORT(lwip_freeaddrinfo) DECLARE_EXPORT(lwip_getaddrinfo) DECLARE_EXPORT(dns_setserver) - DECLARE_EXPORT(dns_getserver) + DECLARE_EXPORT(dns_getserver) //50 #else DECLARE_EXPORT(_retonly) DECLARE_EXPORT(_retonly) - DECLARE_EXPORT(_retonly) //50 - DECLARE_EXPORT(_retonly) + DECLARE_EXPORT(_retonly) DECLARE_EXPORT(_retonly) + DECLARE_EXPORT(_retonly) //55 DECLARE_EXPORT(_retonly) #endif DECLARE_EXPORT(netif_set_link_up) - DECLARE_EXPORT(netif_set_link_down) //55 - DECLARE_EXPORT(tcpip_callback_with_block) - DECLARE_EXPORT(pbuf_coalesce) + DECLARE_EXPORT(netif_set_link_down) + DECLARE_EXPORT(tcpip_callback) + DECLARE_EXPORT(pbuf_coalesce) //60 END_EXPORT_TABLE diff --git a/iop/tcpip/tcpip/src/imports.lst b/iop/tcpip/tcpip/src/imports.lst index 8a09318f5a6..a20a3b47af0 100644 --- a/iop/tcpip/tcpip/src/imports.lst +++ b/iop/tcpip/tcpip/src/imports.lst @@ -43,6 +43,7 @@ I_ReceiveMbx thmsgbx_IMPORTS_end sysclib_IMPORTS_start +I_look_ctype_table I_memset I_strcpy I_strncpy @@ -52,8 +53,10 @@ I_strncmp I_strtok I_strtoul I_memcmp +I_memmove I_strtol I_strcmp +I_tolower sysclib_IMPORTS_end sysmem_IMPORTS_start diff --git a/iop/tcpip/tcpip/src/ps2ip.c b/iop/tcpip/tcpip/src/ps2ip.c index 141de1903e5..1dc8f9ca493 100644 --- a/iop/tcpip/tcpip/src/ps2ip.c +++ b/iop/tcpip/tcpip/src/ps2ip.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -34,6 +35,9 @@ #include "ps2ip_internal.h" +/* Define errno for IOP module */ +int errno __attribute__((section("data"))); + typedef struct pbuf PBuf; typedef struct netif NetIF; typedef struct ip4_addr IPAddr;