Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ PKGBUILD text eol=lf
targets/*.conf text eol=lf
bin/* text eol=lf
pkgbuilds/*/*.h text eol=lf
pkgbuilds/*/LICENSE.* text eol=lf
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
[submodule "tools/extract-xiso"]
path = tools/extract-xiso
url = https://github.com/XboxDev/extract-xiso.git
[submodule "lib/net/lwip"]
path = lib/net/lwip
url = https://github.com/lwip-tcpip/lwip.git
[submodule "lib/pdclib"]
path = lib/pdclib
url = https://github.com/XboxDev/nxdk-pdclib.git
Expand Down
4 changes: 2 additions & 2 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is used by SonarQube Cloud automatic analysis; it ignores sonar-project.properties.
# https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/automatic-analysis#additional-analysis-configuration

sonar.exclusions=lib/libcxx/**,lib/net/lwip/**,lib/pdclib/**,lib/usb/libusbohci/**,tools/extract-xiso/**
sonar.test.exclusions=lib/libcxx/**,lib/net/lwip/**,lib/pdclib/**,lib/usb/libusbohci/**,tools/extract-xiso/**
sonar.exclusions=lib/libcxx/**,lib/pdclib/**,lib/usb/libusbohci/**,tools/extract-xiso/**
sonar.test.exclusions=lib/libcxx/**,lib/pdclib/**,lib/usb/libusbohci/**,tools/extract-xiso/**
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ COPY lib/ /sdk/lib/
COPY scripts/ /sdk/scripts/
COPY targets/ /sdk/targets/
COPY pkgbuilds/zlib/ /sdk/pkgbuilds/zlib/
COPY pkgbuilds/lwip/ /sdk/pkgbuilds/lwip/
COPY pkgbuilds/libpng/ /sdk/pkgbuilds/libpng/
COPY pkgbuilds/libjpeg-turbo/ /sdk/pkgbuilds/libjpeg-turbo/
COPY pkgbuilds/freetype/ /sdk/pkgbuilds/freetype/
Expand All @@ -37,7 +38,7 @@ RUN useradd --create-home packager \
&& runuser -u packager -- env XBOX_BUILD_CONTEXT=docker MAKEFLAGS="-j$(nproc)" bash scripts/build-repo.sh xbox /build/repository \
&& printf '%s\n' '[options]' 'Architecture = xbox' 'SigLevel = Never' \
'[xbox]' 'Server = file:///build/repository' > /tmp/pacman-xbox.conf \
&& bash scripts/xbdk-pacman.sh /packages /tmp/pacman-xbox.conf -Sy --noconfirm sdl_image sdl_ttf
&& bash scripts/xbdk-pacman.sh /packages /tmp/pacman-xbox.conf -Sy --noconfirm lwip sdl_image sdl_ttf

FROM scratch AS xbox-packages
COPY --from=xbox-package-builder /packages/opt/xbfoundry/xbox/ /
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ ifneq ($(NXDK_CXX),)
include $(NXDK_DIR)/lib/libcxx/Makefile.nxdk
endif

include $(NXDK_DIR)/lib/net/Makefile

NXDK_PKG_CONFIG = NXDK_DIR="$(NXDK_DIR)" "$(NXDK_DIR)/bin/nxdk-pkg-config"
ifneq ($(XBOX_PACKAGE_PREFIX),)
# Preserve the SDK's image library defaults when these packages are installed.
NXDK_PACKAGES ?= $(foreach module,libpng libjpeg,$(shell $(NXDK_PKG_CONFIG) --exists $(module) && echo $(module)))
endif

NXDK_PACKAGE_MODULES := $(strip $(NXDK_PACKAGES) $(if $(NXDK_SDL),sdl3))
# Preserve implicit networking when lwIP is installed, and check explicit requests.
NXDK_LWIP_MODULE := lwip
ifeq ($(strip $(NXDK_NET)$(filter lwip,$(NXDK_PACKAGES))),)
NXDK_LWIP_MODULE := $(if $(XBOX_PACKAGE_PREFIX),$(shell $(NXDK_PKG_CONFIG) --exists lwip && echo lwip))
else ifeq ($(shell $(NXDK_PKG_CONFIG) --exists lwip && echo lwip),)
$(error Install the lwip Xbox package and set XBOX_PACKAGE_PREFIX to its installation prefix)
endif

NXDK_PACKAGE_MODULES := $(strip $(NXDK_PACKAGES) $(if $(NXDK_SDL),sdl3) $(filter-out $(NXDK_PACKAGES),$(NXDK_LWIP_MODULE)))
ifneq ($(NXDK_PACKAGE_MODULES),)
NXDK_PACKAGE_CFLAGS := $(shell $(NXDK_PKG_CONFIG) --cflags $(NXDK_PACKAGE_MODULES))
NXDK_CFLAGS += $(NXDK_PACKAGE_CFLAGS)
Expand Down
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ Xbox packages provide static libraries, headers, and pkg-config metadata.
For a local SDK checkout, set `XBOX_PACKAGE_PREFIX` to the installed package
prefix, such as `$PWD/.work/packages/opt/xbfoundry/xbox`. The SDK's
`nxdk-pkg-config` wrapper searches that prefix for Xbox packages. Makefile
projects can request package modules with `NXDK_PACKAGES`.
projects can request package modules with `NXDK_PACKAGES`. Install `lwip`
for networking. Makefile projects can require it with `NXDK_NET=y` or by
including `lwip` in `NXDK_PACKAGES`.
Comment on lines +108 to +110

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep lwIP installation instructions beside its recipe

Move the install and NXDK_NET=y guidance into pkgbuilds/lwip/README.md. The package descriptions in the overview work as links to the individual packages.

Suggested change
projects can request package modules with `NXDK_PACKAGES`. Install `lwip`
for networking. Makefile projects can require it with `NXDK_NET=y` or by
including `lwip` in `NXDK_PACKAGES`.
projects can request package modules with `NXDK_PACKAGES`. See the
[lwIP package documentation](pkgbuilds/lwip/README.md) for Xbox networking.

Review completed by Codex | Model: gpt-6.2-sol | Thinking: xhigh


See the [SDL package documentation](pkgbuilds/sdl/README.md) for the SDL samples and migration guidance.

Expand Down Expand Up @@ -170,24 +172,26 @@ Credits
Code Overview
-------------
* `lib/hal` - Barebones Hardware Abstraction Layer for the Xbox, from OpenXDK.
* `lib/net` - Network stack for the Xbox based on lwIP.
* `lib/net` - Xbox Ethernet driver and lwIP port configuration.
* `lib/pbkit` - A low level library for interfacing with the Xbox GPU.
* `lib/pdclib` - Xbox port of PDCLib, a CC0-licensed C standard library.
* `lib/usb` - USB support from OpenXDK. Hacked together parts of an old Linux OHCI stack.
* `lib/winapi` - Xbox specific implementations of common useful WinAPI-functions.
* `lib/xboxkrnl` - Header and import library for interfacing with the Xbox kernel.
* `lib/xboxrt` - Miscellaneous functionality for debugging etc.
* `pkgbuilds` - Recipes for Xbox packages.
* [`ffmpeg`](pkgbuilds/ffmpeg/)
* [`freetype`](pkgbuilds/freetype/)
* [`googletest`](pkgbuilds/googletest/)
* [`libjpeg-turbo`](pkgbuilds/libjpeg-turbo/)
* [`libpng`](pkgbuilds/libpng/)
* [`openssl`](pkgbuilds/openssl/)
* [`sdl`](pkgbuilds/sdl/)
* [`sdl_image`](pkgbuilds/sdl_image/)
* [`sdl_ttf`](pkgbuilds/sdl_ttf/)
* [`zlib`](pkgbuilds/zlib/)
* [`ffmpeg`](pkgbuilds/ffmpeg/) -
Decodes audio and video, reads media containers, scales video, and resamples audio for Xbox playback.
* [`freetype`](pkgbuilds/freetype/) - Rasterizes fonts for text rendering on Xbox, including through SDL_ttf.
* [`googletest`](pkgbuilds/googletest/) - Runs C++ unit tests and mocks on Xbox and in xemu.
* [`libjpeg-turbo`](pkgbuilds/libjpeg-turbo/) - Encodes and decodes JPEG images, including JPEG support for SDL_image.
* [`libpng`](pkgbuilds/libpng/) - Reads and writes PNG images, including PNG support for SDL_image.
* [`lwip`](pkgbuilds/lwip/) - Network stack for the Xbox based on lwIP.
* [`openssl`](pkgbuilds/openssl/) - Provides TLS and general-purpose cryptography for Xbox applications.
* [`sdl`](pkgbuilds/sdl/) - Xbox port of SDL3 for input, audio, and 2D graphics.
* [`sdl_image`](pkgbuilds/sdl_image/) - Loads images such as PNG and JPEG for SDL3 applications.
* [`sdl_ttf`](pkgbuilds/sdl_ttf/) - Xbox port of SDL_ttf for rendering TrueType and other fonts in SDL3 applications.
* [`zlib`](pkgbuilds/zlib/) - Compresses and decompresses DEFLATE data, including PNG image data through libpng.
* `samples/` - Sample applications to get started.
* `tools/cxbe` - Simple converter for PE executables to the Xbox executable format, from OpenXDK.
* `tools/extract-xiso` - Generates and extracts ISO images compatible with the Xbox (and XQEMU).
Expand Down
37 changes: 0 additions & 37 deletions lib/net/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion lib/net/lwip
Submodule lwip deleted from 77dcd2
1 change: 0 additions & 1 deletion lib/nxdk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ NXDK_SRCS := \
$(NXDK_DIR)/lib/nxdk/entropy.c \
$(NXDK_DIR)/lib/nxdk/format.c \
$(NXDK_DIR)/lib/nxdk/mount.c \
$(NXDK_DIR)/lib/nxdk/net.c \
$(NXDK_DIR)/lib/nxdk/path.c \
$(NXDK_DIR)/lib/nxdk/xbe.c

Expand Down
10 changes: 10 additions & 0 deletions pkgbuilds/lwip/LICENSE.xbdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MIT License

Copyright (c) 2022 Stefan Schmidt
Copyright (c) 2022 Ryan Wendland

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.
83 changes: 83 additions & 0 deletions pkgbuilds/lwip/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
pkgname=lwip
pkgver=2.2.1
pkgrel=1
pkgdesc='Lightweight TCP/IP stack with the Xbox Ethernet integration'
arch=('xbox')
url='https://savannah.nongnu.org/projects/lwip/'
license=(
'BSD-3-Clause'
'MIT'
)
makedepends=(
'clang'
'llvm'
'make'
)
options=(
'staticlibs'
'!strip'
'!debug'
'!lto'
'!buildflags'
)
_lwip_tag=STABLE-${pkgver//./_}_RELEASE
source=(
"lwip-$pkgver.tar.gz::https://codeload.github.com/lwip-tcpip/lwip/tar.gz/refs/tags/$_lwip_tag"
'lwip.mk'
'LICENSE.xbdk'
)
sha256sums=(
'ce0b7461c0ad9602c376f0bf07c5eb7253b48c7bf66f011c6bf3e2a96731c539'
'f2a457542b63bd8eca3a8400d431c3010829404bbb957168c9723d80fb46b671'
'52f4934ed1f63834fd75a846349b57022f7b7eba7ed0fbbd6ad5905231175f7b'
)

build() {
export PATH="${NXDK_DIR:?Set NXDK_DIR to the XbFoundry/xbdk checkout for this build}/bin:$PATH"
make -f "$srcdir/lwip.mk" LWIPDIR="$srcdir/lwip-$_lwip_tag/src" CFLAGS=-O2 libnxdk_net.lib
}

check() {
local symbols symbol
symbols=$(llvm-nm --defined-only --extern-only --format=posix "$srcdir/libnxdk_net.lib")
for symbol in _tcpip_init _lwip_socket _nxNetInit _nvnetif_init; do
if ! grep -q "^${symbol} " <<< "$symbols"; then
printf 'lwIP archive is missing %s\n' "$symbol" >&2
return 1
fi
done
}

package() {
local prefix=$pkgdir${XBOX_PREFIX:-/opt/xbfoundry/xbox}
local lwip_dir=$srcdir/lwip-$_lwip_tag
local xbox_net=$NXDK_DIR/lib/net
local headers=$prefix/include/lwip
local licenses=$prefix/share/licenses/$pkgname

install -Dm644 "$srcdir/libnxdk_net.lib" "$prefix/lib/libnxdk_net.lib"
install -d "$headers"
cp -R "$lwip_dir/src/include/." "$headers/"
cp -R "$xbox_net/nforceif/include/." "$headers/"
install -Dm644 -t "$headers" "$xbox_net"/nvnetdrv/*.h
install -Dm644 "$lwip_dir/COPYING" "$licenses/lwip.txt"
install -Dm644 "$srcdir/LICENSE.xbdk" "$licenses/xbdk.txt"
# Preserve the Xbox port's BSD notices for the compiled driver and sys_arch.
{
sed -n '1,/^ \*\//p' "$xbox_net/nforceif/src/sys_arch.c"
sed -n '/^\/\/ SPDX-FileCopyrightText: /p' "$xbox_net/nvnetdrv/nvnetdrv_lwip.c"
} > "$licenses/xbox-port.txt"

install -d "$prefix/lib/pkgconfig"
cat > "$prefix/lib/pkgconfig/$pkgname.pc" <<EOF
prefix=\${pcfiledir}/../..
libdir=\${prefix}/lib
includedir=\${prefix}/include/lwip

Name: lwIP
Description: $pkgdesc
Version: $pkgver
Libs: \${libdir}/libnxdk_net.lib
Cflags: -I\${includedir}
EOF
}
22 changes: 22 additions & 0 deletions pkgbuilds/lwip/lwip.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build lwIP and the SDK's Xbox network integration into one archive.
include $(LWIPDIR)/Filelists.mk

XBDK_NET := $(NXDK_DIR)/lib/net
LWIP_SOURCES := $(COREFILES) $(CORE4FILES) $(CORE6FILES) $(APIFILES) \

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Build the discovery and socket features Sunshine uses before switching it to this package

Sunshine's current Xbox build compiles the mDNS sources with IGMP and per-interface client storage. It also enables socket receive timeouts for pairing and receive-buffer sizing for streaming. This archive omits the mDNS and IGMP symbols. I linked the exact CI package in xemu and both SO_RCVTIMEO and SO_RCVBUF returned ENOPROTOOPT.

The source-list change below goes with enabling LWIP_IGMP, LWIP_MDNS_RESPONDER, LWIP_SO_RCVTIMEO, and LWIP_SO_RCVBUF and setting LWIP_NUM_NETIF_CLIENT_DATA to 1 in lib/net/nforceif/include/lwipopts.h. lwIP 2.2.1 already defaults LWIP_MDNS_SEARCH to 1. Rebuild the whole archive and install the matching headers because these options alter lwIP types also used by nxNetInit. Refresh the recipe checksum for lwip.mk.

With those changes, the local guest accepted both socket options, read back the selected receive buffer, registered the interface for mDNS, and started a discovery search. The probe checked local API behavior in xemu.

Suggested change
LWIP_SOURCES := $(COREFILES) $(CORE4FILES) $(CORE6FILES) $(APIFILES) \
LWIP_SOURCES := $(COREFILES) $(CORE4FILES) $(CORE6FILES) $(APIFILES) $(MDNSFILES) \

Review completed by Codex | Model: gpt-6.2-sol | Thinking: xhigh

$(filter-out $(LWIPDIR)/netif/slipif.c,$(NETIFFILES))
XBOX_SOURCES := $(XBDK_NET)/nforceif/src/sys_arch.c \
$(XBDK_NET)/nvnetdrv/nvnetdrv.c \
$(XBDK_NET)/nvnetdrv/nvnetdrv_lwip.c \
$(NXDK_DIR)/lib/nxdk/net.c

SOURCES := $(LWIP_SOURCES) $(XBOX_SOURCES)
OBJECTS := $(notdir $(SOURCES:.c=.obj))
vpath %.c $(sort $(dir $(SOURCES)))

CPPFLAGS += -I$(LWIPDIR)/include -I$(XBDK_NET)/nforceif/include -I$(XBDK_NET)/nvnetdrv

libnxdk_net.lib: $(OBJECTS)
llvm-lib "-out:$@" $^

%.obj: %.c
nxdk-cc $(CPPFLAGS) $(CFLAGS) -c "$<" -o "$@"
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

sonar.projectKey=XbFoundry_xbdk

sonar.exclusions=lib/libcxx/**,lib/net/lwip/**,lib/pdclib/**,lib/usb/libusbohci/**,tools/extract-xiso/**
sonar.test.exclusions=lib/libcxx/**,lib/net/lwip/**,lib/pdclib/**,lib/usb/libusbohci/**,tools/extract-xiso/**
sonar.exclusions=lib/libcxx/**,lib/pdclib/**,lib/usb/libusbohci/**,tools/extract-xiso/**
sonar.test.exclusions=lib/libcxx/**,lib/pdclib/**,lib/usb/libusbohci/**,tools/extract-xiso/**
1 change: 1 addition & 0 deletions tests/lwip/guest.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PACKAGE_MODULES += lwip
29 changes: 29 additions & 0 deletions tests/lwip/smoke.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <gtest/gtest.h>

#include <lwip/sockets.h>
#include <nxdk/net.h>

TEST(LwipPackage, InitializesXboxNetworkingAndBindsUdpSocket)
{
nx_net_parameters_t parameters{};
parameters.ipv4_mode = NX_NET_STATIC;
parameters.ipv4_ip = PP_HTONL(LWIP_MAKEU32(10, 0, 2, 15));
parameters.ipv4_netmask = PP_HTONL(LWIP_MAKEU32(255, 255, 255, 0));
ASSERT_EQ(nxNetInit(&parameters), 0);

const int socket = lwip_socket(AF_INET, SOCK_DGRAM, 0);
ASSERT_GE(socket, 0);

sockaddr_in address{};
address.sin_family = AF_INET;
address.sin_addr.s_addr = parameters.ipv4_ip;
const int bind_result = lwip_bind(socket, reinterpret_cast<const sockaddr *>(&address), sizeof(address));

socklen_t length = sizeof(address);
const int name_result = lwip_getsockname(socket, reinterpret_cast<sockaddr *>(&address), &length);
EXPECT_EQ(lwip_close(socket), 0);
ASSERT_EQ(bind_result, 0);
ASSERT_EQ(name_result, 0);
EXPECT_EQ(address.sin_addr.s_addr, parameters.ipv4_ip);
EXPECT_NE(address.sin_port, 0);
}
Loading