Skip to content

Commit bf9b1e4

Browse files
fjtrujyclaude
andcommitted
lwIP: upgrade to upstream 2.2.1 (STABLE-2_2_1_RELEASE)
Replace the ps2dev-patched lwIP 2.0.3 fork with upstream STABLE-2_2_1_RELEASE. No modifications to lwIP sources; PS2-specific adaptations live in lwipopts.h and ps2sdk glue code. Key changes: download_dependencies.sh; lwipopts tuned for IOP memory constraints; Makefile updates to add new lwIP sources and improve readability; API rename tcpip_callback_with_block → tcpip_callback; sys_now() implementation for lwIP 2.x timers; exports/imports sync with 2.2.1 API; minimal stdlib shim (atoi/strtol) for IOP. Co-authored-by: Claude Sonnet <noreply@anthropic.com>
1 parent f556130 commit bf9b1e4

File tree

19 files changed

+228
-26
lines changed

19 files changed

+228
-26
lines changed

download_dependencies.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ if [ "x$1" != "xlocked" ]; then
1414
fi
1515

1616
## Download LWIP
17-
LWIP_REPO_URL="https://github.com/ps2dev/lwip.git"
17+
LWIP_REPO_URL="https://github.com/lwip-tcpip/lwip.git"
1818
LWIP_REPO_FOLDER="common/external_deps/lwip"
19-
LWIP_BRANCH_NAME="ps2-v2.0.3"
19+
LWIP_BRANCH_NAME="STABLE-2_2_1_RELEASE"
2020
if test ! -d "$LWIP_REPO_FOLDER"; then
2121
git clone --depth 1 -b $LWIP_BRANCH_NAME $LWIP_REPO_URL "$LWIP_REPO_FOLDER"_inprogress || exit 1
2222
mv "$LWIP_REPO_FOLDER"_inprogress "$LWIP_REPO_FOLDER"
2323
else
24-
(cd "$LWIP_REPO_FOLDER" && git fetch origin && git reset --hard "origin/${LWIP_BRANCH_NAME}" && git checkout "$LWIP_BRANCH_NAME" && cd - )|| exit 1
24+
(cd "$LWIP_REPO_FOLDER" && git fetch origin --tags && git reset --hard "${LWIP_BRANCH_NAME}" && git checkout "$LWIP_BRANCH_NAME" && cd - )|| exit 1
2525
fi
2626

2727
## Download libsmb2

ee/network/tcpip/Makefile

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,42 @@ endif
3535

3636
EE_INCS += -I$(LWIP)/src/include -I$(LWIP)/src/include/ipv4
3737

38-
ps2api_OBJECTS = api_lib.o api_msg.o api_netbuf.o err.o sockets.o tcpip.o
39-
ps2api_IPV4 = icmp.o ip.o ip4.o ip4_addr.o ip4_frag.o inet_chksum.o
40-
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)
38+
ps2api_OBJECTS = \
39+
api_lib.o \
40+
api_msg.o \
41+
api_netbuf.o \
42+
err.o \
43+
sockets.o \
44+
tcpip.o
45+
46+
ps2api_IPV4 = \
47+
acd.o \
48+
icmp.o \
49+
ip.o \
50+
ip4.o \
51+
ip4_addr.o \
52+
ip4_frag.o \
53+
inet_chksum.o
54+
55+
ps2ip_OBJECTS = \
56+
sys.o \
57+
lwip_init.o \
58+
mem.o \
59+
netif.o \
60+
pbuf.o \
61+
stats.o \
62+
tcp_in.o \
63+
tcp_out.o \
64+
udp.o \
65+
memp.o \
66+
tcp.o \
67+
ethernet.o \
68+
etharp.o \
69+
raw.o \
70+
def.o \
71+
timeouts.o \
72+
$(ps2api_IPV4) \
73+
$(ps2api_OBJECTS)
4174

4275
ifdef PS2IP_DHCP
4376
ps2ip_OBJECTS += dhcp.o
@@ -82,6 +115,9 @@ $(EE_OBJS_DIR)api_msg.o: $(LWIP)/src/api/api_msg.c
82115
$(EE_OBJS_DIR)api_netbuf.o: $(LWIP)/src/api/netbuf.c
83116
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
84117

118+
$(EE_OBJS_DIR)acd.o: $(LWIP)/src/core/ipv4/acd.c
119+
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
120+
85121
$(EE_OBJS_DIR)icmp.o: $(LWIP)/src/core/ipv4/icmp.c
86122
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
87123

ee/network/tcpip/src/include/arch/cc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <errno.h>
55
#include <stdlib.h>
66
#include <stddef.h>
7+
#include <sys/select.h>
78

89
#define PACK_STRUCT_FIELD(x) x __attribute((packed))
910
#define PACK_STRUCT_STRUCT __attribute((packed))

ee/network/tcpip/src/include/lwipopts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@
244244
*/
245245
#define LWIP_CHECKSUM_ON_COPY 1
246246

247+
/* Define LWIP_ERRNO_STDINCLUDE if you want to include <errno.h> here */
248+
#define LWIP_ERRNO_STDINCLUDE 1
247249
/*
248250
------------------------------------
249251
---------- Socket options ----------

ee/network/tcpip/src/ps2ip_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#ifndef IOP_PS2IP_INTERNAL_H
1212
#define IOP_PS2IP_INTERNAL_H
1313

14+
#include <sys/select.h>
1415
#include "lwip/sockets.h"
1516

1617
typedef struct

ee/network/tcpip/src/sys_arch.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *sys_msg)
338338
return result;
339339
}
340340

341+
err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg)
342+
{
343+
// On PS2 EE, ISR and task level are the same, so just call trypost
344+
return sys_mbox_trypost(mbox, msg);
345+
}
346+
341347
void sys_mbox_post(sys_mbox_t *mbox, void *sys_msg)
342348
{
343349
SendMbx(mbox, alloc_msg(), sys_msg);

iop/network/smap/src/imports.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ I_inet_addr
6363
I_tcpip_input
6464
I_netif_set_link_up
6565
I_netif_set_link_down
66-
I_tcpip_callback_with_block
66+
I_tcpip_callback
6767
ps2ip_IMPORTS_end
6868
#endif
6969

iop/tcpip/tcpip-base/include/arch/cc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef __CC_H__
22
#define __CC_H__
33

4-
#include <errno.h>
54
#include <stddef.h>
5+
#include <sys/time.h>
66

77
#define BYTE_ORDER LITTLE_ENDIAN
88

@@ -47,8 +47,6 @@ typedef u32_t mem_ptr_t;
4747
#define LWIP_PLATFORM_ASSERT(args)
4848
#endif
4949

50-
#define atoi(x) strtol(x, NULL, 10)
51-
5250
#define LWIP_NO_STDINT_H 1 //stdint.h does not exist.
5351
#define LWIP_NO_INTTYPES_H 1 //inttypes.h does not exist.
5452

iop/tcpip/tcpip-base/include/lwipopts.h

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@
8686
byte alignment -> define MEM_ALIGNMENT to 2. */
8787
#define MEM_ALIGNMENT 4
8888

89+
/**
90+
* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT==1: allows mem_free() to be called
91+
* from ISR/different task context (uses SYS_ARCH_PROTECT instead of mutex).
92+
* Required on IOP because interrupt context may free pbufs.
93+
*/
94+
#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1
95+
8996
/**
9097
* MEM_SIZE: the size of the heap memory. If the application will send
9198
* a lot of data that needs to be copied, this should be set high.
@@ -94,11 +101,60 @@
94101
Up to TCP_SND_BUF * 2 segments may be transmitted at once, thanks to Nagle and Delayed Ack. */
95102
#define MEM_SIZE (TCP_SND_BUF * 2)
96103

104+
/*
105+
-----------------------------------------------
106+
---------- IP options -------------------------
107+
-----------------------------------------------
108+
*/
109+
/**
110+
* IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets.
111+
* Disabled: PS2 always operates on a local LAN; IP fragments never occur
112+
* with MSS=1460 and MTU=1500. Saves MEMP_NUM_REASSDATA pool entries.
113+
*/
114+
#define IP_REASSEMBLY 0
115+
116+
/**
117+
* IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU.
118+
* Disabled: TCP_MSS=1460 ensures we never exceed Ethernet MTU=1500.
119+
*/
120+
#define IP_FRAG 0
121+
97122
/*
98123
------------------------------------------------
99124
---------- Internal Memory Pool Sizes ----------
100125
------------------------------------------------
101126
*/
127+
/**
128+
* MEMP_NUM_TCP_PCB: the number of simultaneously active TCP connections.
129+
* ps2link handles at most a few simultaneous TCP connections.
130+
*/
131+
#define MEMP_NUM_TCP_PCB 4
132+
133+
/**
134+
* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections.
135+
* ps2link listens on a small number of ports.
136+
*/
137+
#define MEMP_NUM_TCP_PCB_LISTEN 4
138+
139+
/**
140+
* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks.
141+
* DNS (1) + DHCP (1) internally allocate raw UDP PCBs via udp_new(),
142+
* plus application sockets (udptty 1, ps2link 1) need their own.
143+
*/
144+
#define MEMP_NUM_UDP_PCB 4
145+
146+
/**
147+
* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments.
148+
* Must be at least TCP_SND_QUEUELEN (enforced by lwIP sanity check in init.c).
149+
*/
150+
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
151+
152+
/**
153+
* MEMP_NUM_ARP_QUEUE: the number of ARP queued packets.
154+
* ps2link communicates with a single host; 5 entries is more than enough.
155+
*/
156+
#define MEMP_NUM_ARP_QUEUE 5
157+
102158
/**
103159
* MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used
104160
* for incoming packets.
@@ -125,8 +181,15 @@
125181

126182
/**
127183
* PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
184+
* Each pool entry is ~1532 bytes (PBUF_POOL_BUFSIZE ≈ 1516 + struct pbuf).
185+
* Reduced from 32 (~49 KB) to 12 (~18 KB). Safe because
186+
* LWIP_TCPIP_CORE_LOCKING_INPUT=1 means RX is processed synchronously,
187+
* so the pool backlog stays very small.
188+
* Must satisfy: TCP_WND <= PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - 54).
189+
* With PBUF_POOL_SIZE=12 and PBUF_POOL_BUFSIZE=1516: max = 12 * 1462 = 17544.
190+
* 16384 (16 KB) fits comfortably.
128191
*/
129-
#define PBUF_POOL_SIZE 32 //SP193: should be at least ((TCP_WND/PBUF_POOL_BUFSIZE)+1). But that is too small to handle simultaneous connections.
192+
#define PBUF_POOL_SIZE 12
130193

131194
/**
132195
* LWIP_TCPIP_CORE_LOCKING_INPUT: when LWIP_TCPIP_CORE_LOCKING is enabled,
@@ -156,8 +219,11 @@
156219
/* TCP sender buffer space (bytes). */
157220
#define TCP_SND_BUF (TCP_MSS*4)
158221

159-
/* TCP receive window. */
160-
#define TCP_WND 32768
222+
/* TCP receive window.
223+
* Must satisfy: TCP_WND <= PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - 54).
224+
* With PBUF_POOL_SIZE=12 and PBUF_POOL_BUFSIZE=1516: max = 12 * 1462 = 17544.
225+
* 16384 (16 KB) fits comfortably and still gives ample throughput on LAN. */
226+
#define TCP_WND 16384
161227

162228
/* ---------- DHCP options ---------- */
163229
#ifdef PS2IP_DHCP
@@ -167,6 +233,10 @@
167233
#define LWIP_DHCP 1
168234
#endif
169235

236+
/* ---------- ACD options ---------- */
237+
#define LWIP_ACD 0
238+
#define LWIP_DHCP_DOES_ACD_CHECK 0
239+
170240
/**
171241
* DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address.
172242
*/
@@ -236,6 +306,8 @@
236306
*/
237307
#define LWIP_CHECKSUM_ON_COPY 1
238308

309+
/* Use PS2SDK's errno.h instead of lwIP's own errno definitions */
310+
#define LWIP_ERRNO_STDINCLUDE 1
239311
/*
240312
------------------------------------
241313
---------- Socket options ----------
@@ -251,6 +323,11 @@
251323
* names (read, write & close). (only used if you use sockets.c)
252324
*/
253325
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
326+
/**
327+
* LWIP_SOCKET_POLL==1: Enable poll() for sockets (new in lwIP 2.2.x, default=1).
328+
* Disabled: lwip_poll() is not exported by ps2ip; disabling saves code size.
329+
*/
330+
#define LWIP_SOCKET_POLL 0
254331

255332
/*
256333
----------------------------------
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
# _____ ___ ____ ___ ____
3+
# ____| | ____| | | |____|
4+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5+
#-----------------------------------------------------------------------
6+
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7+
# Licenced under Academic Free License version 2.0
8+
# Review ps2sdk README & LICENSE files for further details.
9+
*/
10+
11+
/**
12+
* @file
13+
* Minimal stdlib.h for IOP tcpip
14+
* Provides basic functions needed by lwIP on the IOP
15+
*/
16+
17+
#ifndef __IOP_TCPIP_STDLIB_H__
18+
#define __IOP_TCPIP_STDLIB_H__
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/* atoi - convert string to integer
25+
* Implemented as a macro using strtol from sysclib
26+
*/
27+
#define atoi(x) strtol(x, NULL, 10)
28+
29+
/* Required for strtol */
30+
long int strtol(const char *nptr, char **endptr, int base);
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
36+
#endif /* __IOP_TCPIP_STDLIB_H__ */

0 commit comments

Comments
 (0)