Skip to content

armgit / PS5LM

Public Imported from GitHub
0

llama.cpp on a jailbroken PS5: run any GGUF model natively on the console, starting with Qwen 3.8

Downloads: write through a loopback ftpsrv (#41) (#46)

Darkatek70d1b70403086
diff --git a/.gitmodules b/.gitmodules
index 3cc0e1a..86d4964 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,3 +4,6 @@
[submodule "third_party/ps5-homebrew-ui"]
path = third_party/ps5-homebrew-ui
url = https://github.com/Phononenom/ps5-homebrew-ui
+[submodule "third_party/ftpsrv"]
+ path = third_party/ftpsrv
+ url = https://github.com/drakmor/ftpsrv
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3e9b620..e020aef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,14 @@ v0.1.x are the upstream payload releases by cobanov.
request pays for it unless it asks.
### Fixed
+- **Downloads keep their speed past 2 GB.** The console slows a title's own writes to about
+ 1.2 MB/s after the first ~2.2 GB, while a payload's keep going, so the app now writes each piece
+ through a loopback ftpsrv: in file order, with `REST`/`STOR` at its place, done once ftpsrv answers
+ `226`. It uses the user's ftpsrv on 2121 when a test write through it works, else its own copy,
+ `ps5lm-ftpsrv` on `127.0.0.1:2123`, which it sends to elfldr when needed and which leaves other
+ ftpsrv copies on 2121 and 2122 running. With an ftpsrv that has no `EPSV` it uses `PASV`. When
+ no ftpsrv answers, the app writes the file itself as before. Ported from
+ [PS5SD](https://github.com/Darkatek7/PS5SD) (#41).
- Models saved to an M.2 or USB drive show up in the library wherever that drive is mounted. The
library looked only in `/mnt/ext0`, `/mnt/usb0` and `/mnt/usb1`, while downloads can go to any
drive the exporter reports; it now also reads the download folder and every mounted drive's
diff --git a/README.md b/README.md
index 199add8..aa30ce8 100644
--- a/README.md
+++ b/README.md
@@ -96,8 +96,8 @@ You need a PS5 on firmware 7.00 to 13.60, jailbroken, with these payloads loaded
| [kstuff-lite](https://github.com/EchoStretch/kstuff-lite) | the kernel patches homebrew runs on | required |
| [etaHEN](https://github.com/etaHEN/etaHEN) | homebrew support | required |
| [ShadowMountPlus](https://github.com/drakmor/ShadowMountPlus) | puts PS5LM on the home screen from `/data/homebrew` | required |
-| [elfldr](https://github.com/ps5-payload-dev/elfldr) (port 9021) | temperature, power and real free space, through ps5-exporter | recommended |
-| [ftpsrv](https://github.com/ps5-payload-dev/ftpsrv) (port 2121) | installing the app, copying models from a PC | recommended |
+| [elfldr](https://github.com/ps5-payload-dev/elfldr) (port 9021) | temperature, power and real free space, through ps5-exporter; full-speed downloads, through the app's own ftpsrv | recommended |
+| [ftpsrv](https://github.com/ps5-payload-dev/ftpsrv) (port 2121) | installing the app, copying models from a PC; downloads write through it when it runs | recommended |
1. Download `ps5lm-app-vX.Y.Z.zip` from the [latest release](https://github.com/cobanov/PS5LM/releases/latest) and unzip it.
2. Copy the `PPSA99575` folder to `/data/homebrew` over FTP. ShadowMountPlus adds **PS5LM** to the
diff --git a/docs/BUILDING.md b/docs/BUILDING.md
index f7fde78..4f00eea 100644
--- a/docs/BUILDING.md
+++ b/docs/BUILDING.md
@@ -24,6 +24,11 @@ works too.
- **HTTPS.** Downloads use the system's libSceHttp2 and libSceSsl, so the app carries no TLS library.
- **What a title cannot do.** Read sensors, see real free space, or start processes. ps5-exporter, a
payload the app sends to elfldr, covers the first two.
+- **Downloads write through ftpsrv.** A title's writes slow to about 1.2 MB/s after 2.2 GB, a
+ payload's do not, so `Market::fetch` sends each piece to a loopback ftpsrv with `REST`/`STOR`
+ (`ps5/app/ftp_writer.cpp`): the user's on 2121, else the app's own copy on 2123, which
+ `build-app.sh` builds from `third_party/ftpsrv` with `patches/ftpsrv` and bundles as
+ `payloads/ps5lm-ftpsrv.elf` ([CONSOLE.md](CONSOLE.md#the-titles-writes-slow-down-after-about-2-gb-41)).
## Build
@@ -98,7 +103,8 @@ PS5_HOST=<console IP> scripts/ps5lm-app.sh screenshot out.bmp
| `ps5/app` | the app: dashboard, planner, suggestions, downloads, the request feed, llama-server on the GPU |
| `third_party/llama.cpp` | upstream llama.cpp, pinned as a submodule |
| `third_party/ps5-homebrew-ui` | the UI toolkit |
+| `third_party/ftpsrv` | drakmor's ftpsrv at 1.16-ng-stable, the app's loopback copy for downloads |
| `third_party/fonts` | Manrope (OFL) |
-| `patches/` | PS5 changes to llama.cpp, kept small; `patches/mesa` the driver's |
+| `patches/` | PS5 changes to llama.cpp, kept small; `patches/mesa` the driver's, `patches/ftpsrv` ftpsrv's |
| `ps5/compat`, `probes/` | the payload build's libc additions and memory probes ([PAYLOAD.md](PAYLOAD.md)) |
| `scripts/` | build, release, artwork, deploy and console tools |
diff --git a/docs/CONSOLE.md b/docs/CONSOLE.md
index d453341..efac549 100644
--- a/docs/CONSOLE.md
+++ b/docs/CONSOLE.md
@@ -67,6 +67,37 @@ Locking the weights (`-lm mlock`) fixes it: Qwen3.5 2B went from 0.9 to **8.5 to
- The kernel caps `SO_RCVBUF` at 64 KB, whatever is asked for. With the Hugging Face CDN ~150 ms away, one connection tops out at 0.9 MB/s.
- 16 connections fetching 8 MiB pieces in parallel: **about 12.5 MB/s** (Qwen3.5 4B, 2.6 GB, in 217 s).
+### The title's writes slow down after about 2 GB (#41)
+
+The app (a title) wrote downloads at 15 to 18 MB/s, then at about 1.2 MB/s after the first ~2.2 GB.
+The limit is on the title's process, not the disk: in PS5SD's measurements, while the title's writes
+were down to 1 to 2 MB/s, ftpsrv (a payload) wrote to `/data` at 78 to 89 MB/s in the same minute.
+
+So `Market::fetch` has ftpsrv write the file (`ps5/app/ftp_writer.cpp`, ported from
+[PS5SD](https://github.com/Darkatek7/PS5SD)). Each 32 MiB piece is held in memory until the ones
+before it are written, then sent at its place with `REST <offset>` and `STOR <part path>` over one
+loopback FTP connection. ftpsrv's `REST n` + `STOR` cuts the file at n and writes from there; a
+`REST` past the end is refused (`551 Restart point beyond EOF`). A piece counts as done once ftpsrv
+answers `226`, so `resume` only ever covers bytes in the file, and the first `STOR` of a resumed
+download, at `resume`, cuts off whatever lies past it. For an ftpsrv without `EPSV` (up to 0.15, which
+answers `502`) the data connection falls back to `PASV`. The SHA-256 check and the rename stay the
+title's own; it can read, rename and unlink the files ftpsrv makes (uid 0, mode 0666).
+
+Which ftpsrv:
+
+- **2121**, the user's, once one test write of a byte to `/data/PS5LM/.ps5lm-ftp-check` through it
+ worked (once per run of the app).
+- Else **2123**, PS5LM's own copy (`/app0/payloads/ps5lm-ftpsrv.elf`, from `third_party/ftpsrv` at
+ 1.16-ng-stable with `patches/ftpsrv`). It listens on `127.0.0.1` only, for control and passive data
+ connections, and runs as `ps5lm-ftpsrv`. Stock ftpsrv kills every process with its own name when it
+ starts; with a name of its own this copy leaves the user's `ftpsrv.elf` on 2121 and PS5SD's
+ `ps5sd-ftpsrv` on 2122 alone. When nothing listens on 2123, the app sends the ELF to elfldr on 9021,
+ at most once per run, and waits up to 5 s for it. It shows "PS5LM: writing through ftpsrv on
+ 127.0.0.1:2123" and stays up until the console restarts. Something that listens on 2123 but does not
+ answer is taken as busy and not started again.
+- Else the app writes the file itself, as before, and the download line says "written without
+ ftpsrv".
+
At exit, Sony's libc prints `[SceLibc] A heap error is detected` (SceLibcInternalHeap) after all work is done. After `main`, the SDK's start code unloads the modules the payload loaded and calls Sony's `exit()`, which runs the C++ static destructors while other threads may still run; the tools now leave through `_Exit` instead (`ps5/compat/exit.cpp`). Not yet checked on the console (#3).
## shsrv quirks
diff --git a/patches/ftpsrv/0001-loopback-only-for-ps5lm.patch b/patches/ftpsrv/0001-loopback-only-for-ps5lm.patch
new file mode 100644
index 0000000..d083871
--- /dev/null
+++ b/patches/ftpsrv/0001-loopback-only-for-ps5lm.patch
@@ -0,0 +1,100 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: ps5lm <ps5lm@localhost>
+Date: Wed, 28 Oct 2026 12:00:00 +0100
+Subject: [PATCH] PS5LM's copy: 127.0.0.1:2123 only, a process name of its own
+
+The title starts this copy (ps5/app/ftp_writer.cpp, connect_ftp_writer) when no
+ftpsrv answers on 2121, to write model downloads at payload speed. It listens on
+loopback only, for control and passive data connections, so it opens nothing
+on the LAN. Port 2123 and the name ps5lm-ftpsrv keep it apart from a user's
+own ftpsrv on 2121 and PS5SD's ps5sd-ftpsrv on 2122: none fails to bind, and
+none kills another at start.
+
+Ported from PS5SD's patches/ftpsrv/0001-loopback-only-for-ps5sd.patch.
+
+---
+ cmd.c | 2 +-
+ main-prospero.c | 8 +++++---
+ srv.c | 11 ++++++-----
+ 3 files changed, 12 insertions(+), 9 deletions(-)
+
+diff --git a/cmd.c b/cmd.c
+index ca95db9..a282169 100644
+--- a/cmd.c
++++ b/cmd.c
+@@ -543,7 +543,7 @@ ftp_listen_passive(ftp_env_t *env, uint16_t *port_out) {
+
+ memset(&sockaddr, 0, sockaddr_len);
+ sockaddr.sin_family = AF_INET;
+- sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
++ sockaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ sockaddr.sin_port = htons(0);
+
+ if(bind(env->passive_fd, (struct sockaddr *)&sockaddr, sockaddr_len) != 0) {
+diff --git a/main-prospero.c b/main-prospero.c
+index ff4da9d..68dd2ce 100644
+--- a/main-prospero.c
++++ b/main-prospero.c
+@@ -78,13 +78,15 @@ find_pid(const char* name) {
+ **/
+ int
+ main(int argc, char* argv[]) {
+- uint16_t port = 2121;
++ uint16_t port = 2123;
+ int notify_user = 1;
+ int rc;
+ pid_t pid;
+ int c;
+
+- syscall(SYS_thr_set_name, -1, "ftpsrv.elf");
++ // PS5LM: a name of its own, so this copy and a user's ftpsrv.elf on
++ // 2121 never kill each other at start (find_pid below).
++ syscall(SYS_thr_set_name, -1, "ps5lm-ftpsrv");
+
+ while((c=getopt(argc, argv, "p:h")) != -1) {
+ switch(c) {
+@@ -105,7 +107,7 @@ main(int argc, char* argv[]) {
+ }
+ }
+
+- while((pid=find_pid("ftpsrv.elf")) > 0) {
++ while((pid=find_pid("ps5lm-ftpsrv")) > 0) {
+ if(kill(pid, SIGKILL)) {
+ FTP_LOG_PERROR("kill");
+ return EXIT_FAILURE;
+diff --git a/srv.c b/srv.c
+index 9753016..e0c0e27 100644
+--- a/srv.c
++++ b/srv.c
+@@ -481,10 +481,6 @@ ftp_serve(uint16_t port, int notify_user) {
+ continue;
+ }
+
+- if(notify_user) {
+- notify("Serving FTP on %s:%d (%s)", ip, port, ifa->ifa_name);
+- }
+-
+ ifaddr_wait = 0;
+ }
+
+@@ -494,6 +490,11 @@ ftp_serve(uint16_t port, int notify_user) {
+ return 0;
+ }
+
++ // PS5LM: for the title's own writes only, so on loopback.
++ if(notify_user) {
++ notify("PS5LM: writing through ftpsrv on 127.0.0.1:%d", port);
++ }
++
+ if((srvfd=socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+ FTP_LOG_PERROR("socket");
+ return -1;
+@@ -507,7 +508,7 @@ ftp_serve(uint16_t port, int notify_user) {
+
+ memset(&server_addr, 0, sizeof(server_addr));
+ server_addr.sin_family = AF_INET;
+- server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
++ server_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ server_addr.sin_port = htons(port);
+
+ if(bind(srvfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) != 0) {
diff --git a/ps5/app/dashboard.cpp b/ps5/app/dashboard.cpp
index 96376d9..efc8785 100644
--- a/ps5/app/dashboard.cpp
+++ b/ps5/app/dashboard.cpp
@@ -361,7 +361,7 @@ std::string download_line(const Download & d) {
} else {
std::snprintf(t, sizeof(t), "%.1f of %.1f GB, %.1f MB/s, %.0f min left", done, all, d.mbps, std::ceil(left_s / 60));
}
- return t;
+ return d.note.empty() ? std::string(t) : std::string(t) + ", " + d.note; // the note: written without ftpsrv
}
std::snprintf(t, sizeof(t), "%.1f of %.1f GB", done, all);
if (d.state == DownloadState::running) {
diff --git a/ps5/app/ftp_writer.cpp b/ps5/app/ftp_writer.cpp
new file mode 100644
index 0000000..1d008f8
--- /dev/null
+++ b/ps5/app/ftp_writer.cpp
@@ -0,0 +1,424 @@
+// FtpWriter (ftp_writer.hpp): a minimal FTP client for the console's ftpsrv.
+// Ported from PS5SD (Darkatek7/PS5SD, ps5/app/ftp_writer.cpp).
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+#include "ftp_writer.hpp"
+
+#include "stats.hpp"
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#include <cerrno>
+#include <chrono>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <mutex>
+#include <thread>
+
+namespace ps5lm {
+
+namespace {
+
+#ifdef MSG_NOSIGNAL
+constexpr int kSendFlags = MSG_NOSIGNAL;
+#else
+constexpr int kSendFlags = 0;
+#endif
+
+} // namespace
+
+int FtpWriter::dial(int port, std::string & error) {
+ const int fd = ::socket(AF_INET, SOCK_STREAM, 0);
+ if (fd < 0) {
+ error = std::string("socket: ") + std::strerror(errno);
+ return -1;
+ }
+ const int one = 1;
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
+#ifdef SO_NOSIGPIPE
+ setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one));
+#endif
+ timeval tv{};
+ tv.tv_sec = timeout_;
+ setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+ setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
+ sockaddr_in sa{};
+#ifdef __FreeBSD__
+ sa.sin_len = sizeof(sa);
+#endif
+ sa.sin_family = AF_INET;
+ sa.sin_port = htons(static_cast<uint16_t>(port));
+ if (inet_pton(AF_INET, host_.c_str(), &sa.sin_addr) != 1) {
+ error = "bad address " + host_;
+ ::close(fd);
+ return -1;
+ }
+ if (::connect(fd, reinterpret_cast<sockaddr *>(&sa), sizeof(sa)) != 0) {
+ error = "connect to " + host_ + ":" + std::to_string(port) + ": " + std::strerror(errno);
+ ::close(fd);
+ return -1;
+ }
+ return fd;
+}
+
+bool FtpWriter::send_all(int fd, const char * data, size_t n, std::string & error) {
+ while (n > 0) {
+ const ssize_t k = ::send(fd, data, n, kSendFlags);
+ if (k < 0 && errno == EINTR) {
+ continue;
+ }
+ if (k <= 0) {
+ error = std::string("send: ") + (k < 0 ? std::strerror(errno) : "connection closed");
+ return false;
+ }
+ data += k;
+ n -= static_cast<size_t>(k);
+ }
+ return true;
+}
+
+// One reply: "ddd text", or "ddd-" lines up to the "ddd " that ends them.
+bool FtpWriter::reply(int & code, std::string & text, std::string & error) {
+ std::string first;
+ for (;;) {
+ size_t eol;
+ while ((eol = inbox_.find('\n')) == std::string::npos) {
+ char buf[512];
+ const ssize_t k = ::recv(ctrl_, buf, sizeof(buf), 0);
+ if (k < 0 && errno == EINTR) {
+ continue;
+ }
+ if (k <= 0) {
+ error = std::string("ftpsrv: ") + (k < 0 ? std::strerror(errno) : "connection closed");
+ return false;
+ }
+ inbox_.append(buf, static_cast<size_t>(k));
+ }
+ std::string line = inbox_.substr(0, eol);
+ inbox_.erase(0, eol + 1);
+ if (!line.empty() && line.back() == '\r') {
+ line.pop_back();
+ }
+ if (first.empty()) {
+ if (line.size() < 3) {
+ error = "ftpsrv: bad reply '" + line + "'";
+ return false;
+ }
+ first = line;
+ }
+ // The last line of a reply repeats the code with a space after it.
+ if (line.size() >= 4 && line.compare(0, 3, first, 0, 3) == 0 && line[3] == ' ') {
+ code = std::atoi(first.substr(0, 3).c_str());
+ text = line;
+ return true;
+ }
+ if (line.size() == 3 && line == first.substr(0, 3)) {
+ code = std::atoi(line.c_str());
+ text = line;
+ return true;
+ }
+ }
+}
+
+namespace {
+// A path comes from a Hugging Face repo, and a git path may hold a line break:
+// "x\r\nDELE ..." would be a second command to a payload that can write
+// anywhere on the console.
+bool refuse_line_break(const std::string & text, std::string & error) {
+ if (text.find_first_of(std::string("\r\n\0", 3)) == std::string::npos) {
+ return false;
+ }
+ error = "ftpsrv: refused a path with a line break in it";
+ return true;
+}
+} // namespace
+
+bool FtpWriter::command(const std::string & line, int & code, std::string & text, std::string & error) {
+ if (refuse_line_break(line, error)) {
+ return false;
+ }
+ if (!send_all(ctrl_, (line + "\r\n").data(), line.size() + 2, error)) {
+ error = "ftpsrv: " + error;
+ return false;
+ }
+ return reply(code, text, error);
+}
+
+void FtpWriter::close() {
+ if (data_ >= 0) {
+ ::close(data_);
+ data_ = -1;
+ }
+ if (ctrl_ >= 0) {
+ ::close(ctrl_);
+ ctrl_ = -1;
+ }
+ inbox_.clear();
+}
+
+bool FtpWriter::connect(std::string & error) {
+ if (ctrl_ >= 0) {
+ return true;
+ }
+ ctrl_ = dial(port_, error);
+ refused_ = ctrl_ < 0;
+ if (ctrl_ < 0) {
+ return false;
+ }
+ int code = 0;
+ std::string text;
+ if (!reply(code, text, error) || code != 220) {
+ if (error.empty()) {
+ error = "ftpsrv: " + text;
+ }
+ close();
+ return false;
+ }
+ if (!command("USER anonymous", code, text, error)) {
+ close();
+ return false;
+ }
+ if (code == 331 && !command("PASS ps5lm", code, text, error)) {
+ close();
+ return false;
+ }
+ if (code != 230) {
+ error = "ftpsrv: " + text;
+ close();
+ return false;
+ }
+ if (!command("TYPE I", code, text, error) || code != 200) {
+ if (error.empty()) {
+ error = "ftpsrv: " + text;
+ }
+ close();
+ return false;
+ }
+ return true;
+}
+
+// EPSV: "229 Entering Extended Passive Mode (|||port|)"; or, for a server
+// that does not know it (500, 502, 504), PASV: "227 Entering Passive Mode
+// (h1,h2,h3,h4,p1,p2)". The address is the server's own, so only the port is
+// taken.
+bool FtpWriter::open_data(std::string & error) {
+ int code = 0;
+ std::string text;
+ if (!pasv_) {
+ if (!command("EPSV", code, text, error)) {
+ return false;
+ }
+ const size_t a = text.find("(|||");
+ const size_t b = a == std::string::npos ? a : text.find('|', a + 4);
+ if (code == 229 && b != std::string::npos) {
+ data_ = dial(std::atoi(text.substr(a + 4, b - a - 4).c_str()), error);
+ return data_ >= 0;
+ }
+ if (code != 500 && code != 502 && code != 504) {
+ error = "ftpsrv: " + text;
+ return false;
+ }
+ pasv_ = true;
+ }
+ if (!command("PASV", code, text, error)) {
+ return false;
+ }
+ const size_t a = text.find('(');
+ const size_t b = a == std::string::npos ? a : text.find(')', a);
+ int h[6];
+ if (code != 227 || b == std::string::npos ||
+ std::sscanf(text.c_str() + a + 1, "%d,%d,%d,%d,%d,%d", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5]) != 6) {
+ error = "ftpsrv: " + text;
+ return false;
+ }
+ data_ = dial(h[4] * 256 + h[5], error);
+ return data_ >= 0;
+}
+
+bool FtpWriter::begin(const std::string & path, uint64_t offset, std::string & error) {
+ if (!connect(error)) {
+ return false;
+ }
+ int code = 0;
+ std::string text;
+ const auto fail = [&] {
+ if (error.empty()) {
+ error = "ftpsrv: " + text;
+ }
+ close(); // the control connection may be out of step now
+ return false;
+ };
+ if (!command("REST " + std::to_string(offset), code, text, error) || code != 350) {
+ return fail();
+ }
+ if (!open_data(error)) {
+ return fail();
+ }
+ if (!command("STOR " + path, code, text, error) || (code != 150 && code != 125)) {
+ return fail();
+ }
+ return true;
+}
+
+bool FtpWriter::send(const char * data, size_t n, std::string & error) {
+ if (data_ < 0) {
+ error = "ftpsrv: no transfer";
+ return false;
+ }
+ if (!send_all(data_, data, n, error)) {
+ error = "ftpsrv: " + error;
+ close();
+ return false;
+ }
+ return true;
+}
+
+bool FtpWriter::end(std::string & error) {
+ if (data_ < 0) {
+ error = "ftpsrv: no transfer";
+ return false;
+ }
+ ::close(data_);
+ data_ = -1;
+ int code = 0;
+ std::string text;
+ if (!reply(code, text, error) || code != 226) {
+ if (error.empty()) {
+ error = "ftpsrv: " + text;
+ }
+ close();
+ return false;
+ }
+ return true;
+}
+
+bool FtpWriter::write_at(const std::string & path, uint64_t offset, const char * data, size_t n,
+ std::string & error) {
+ return !refuse_line_break(path, error) && begin(path, offset, error) && send(data, n, error) && end(error);
+}
+
+bool FtpWriter::rename(const std::string & from, const std::string & to, std::string & error) {
+ if (!connect(error)) {
+ return false;
+ }
+ int code = 0;
+ std::string text;
+ // RNTO: 250, or 226 from ftpsrv up to 0.15
+ if (!command("RNFR " + from, code, text, error) || code != 350 || !command("RNTO " + to, code, text, error) ||
+ code / 100 != 2) {
+ if (error.empty()) {
+ error = "ftpsrv: " + text;
+ }
+ return false;
+ }
+ return true;
+}
+
+bool FtpWriter::size(const std::string & path, uint64_t & out, std::string & error) {
+ if (refuse_line_break(path, error) || !connect(error)) {
+ return false;
+ }
+ int code = 0;
+ std::string text;
+ if (!command("SIZE " + path, code, text, error)) {
+ close();
+ return false;
+ }
+ if (code != 213 || text.size() < 5) {
+ error = "ftpsrv: " + text;
+ return false;
+ }
+ out = std::strtoull(text.c_str() + 4, nullptr, 10);
+ return true;
+}
+
+namespace {
+
+// One byte through the user's ftpsrv, once per run: a server without a command
+// PS5LM needs (an old ftpsrv answers 502) fails here instead of in every piece
+// of a download.
+bool user_ftpsrv_works(FtpWriter & ftp, std::string & error) {
+ static std::mutex m;
+ static int works = -1; // not checked yet
+ std::lock_guard<std::mutex> lock(m);
+ if (works < 0) {
+ std::string check_error;
+ works = ftp.write_at(kFtpCheckFile, 0, "x", 1, check_error) ? 1 : 0;
+ ::unlink(kFtpCheckFile);
+ if (works) {
+ std::printf("ps5lm-app: ftpsrv: the one on %d works\n", kFtpsrvPort);
+ } else {
+ error = check_error;
+ std::printf("ps5lm-app: ftpsrv: the one on %d cannot write for PS5LM (%s); using PS5LM's own copy on %d\n",
+ kFtpsrvPort, check_error.c_str(), kOwnFtpsrvPort);
+ }
+ }
+ if (!works && error.empty()) {
+ error = "it failed a test write";
+ }
+ return works == 1;
+}
+
+} // namespace
+
+bool connect_ftp_writer(FtpWriter & ftp, std::string & error) {
+ static std::mutex m;
+ static bool sent = false;
+ std::string error_2121, error_2123;
+ ftp.set_port(kFtpsrvPort);
+ if (ftp.connect(error_2121)) {
+ if (user_ftpsrv_works(ftp, error_2121) && ftp.connect(error_2121)) {
+ return true;
+ }
+ ftp.close();
+ }
+ ftp.set_port(kOwnFtpsrvPort);
+ if (ftp.connect(error_2123)) {
+ return true;
+ }
+ const auto none = [&](const std::string & why) {
+ error = "no ftpsrv on 2121 (" + error_2121 + ") or 2123 (" + why + ")";
+ return false;
+ };
+ std::lock_guard<std::mutex> lock(m);
+ if (sent) {
+ // Sent by this run already, maybe by another thread a moment ago.
+ return ftp.connect(error_2123) || none(error_2123);
+ }
+ if (!ftp.refused()) {
+ // Something listens on 2123 and does not answer: a copy that is busy,
+ // not one to start again on top of it.
+ return none(error_2123);
+ }
+ sent = true;
+ // The ELF loader runs what it read once the connection ends.
+ if (!send_payload(kOwnFtpsrvElf, kElfLoaderPort)) {
+ std::printf("ps5lm-app: ftpsrv: could not send %s to elfldr on %d\n", kOwnFtpsrvElf, kElfLoaderPort);
+ return none(error_2123 + "; not started: no elfldr on " + std::to_string(kElfLoaderPort) + " took it");
+ }
+ std::printf("ps5lm-app: ftpsrv: sent %s to the ELF loader on %d\n", kOwnFtpsrvElf, kElfLoaderPort);
+ const auto t0 = std::chrono::steady_clock::now();
+ for (int i = 0; i < 25; i++) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(200));
+ if (ftp.connect(error_2123)) {
+ std::printf("ps5lm-app: ftpsrv: PS5LM's own copy answers on %d after %.1f s\n", kOwnFtpsrvPort,
+ std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count());
+ return true;
+ }
+ }
+ std::printf("ps5lm-app: ftpsrv: PS5LM's own copy does not answer on %d: %s\n", kOwnFtpsrvPort, error_2123.c_str());
+ return none(error_2123 + "; sent to the ELF loader, but it did not start within 5 s");
+}
+
+bool ftp_disk_full(const std::string & error) {
+ return error.find(" 552 ") != std::string::npos || error.find(" 452 ") != std::string::npos ||
+ error.find("No space") != std::string::npos;
+}
+
+} // namespace ps5lm
diff --git a/ps5/app/ftp_writer.hpp b/ps5/app/ftp_writer.hpp
new file mode 100644
index 0000000..8c232f0
--- /dev/null
+++ b/ps5/app/ftp_writer.hpp
@@ -0,0 +1,97 @@
+// Writes downloads through an FTP server on this console (ftpsrv, a
+// payload) instead of the title's own write(). The console slows a title's
+// writes to /data: after about 2.2 GB they drop to about 1.2 MB/s, while
+// ftpsrv keeps writing at 80 MB/s and more in the same moment (#41,
+// docs/CONSOLE.md).
+//
+// ftpsrv's REST n + STOR cuts the file at n and writes from there; a REST past
+// the end is refused (551). So a file is written from its start, in order: one
+// STOR per piece, at the end of what is already there.
+//
+// The data connection is passive: EPSV, or PASV for a server without it
+// (ftpsrv up to 0.15 answers EPSV with 502).
+//
+// connect_ftp_writer finds the server: the user's ftpsrv on 2121 when a test
+// write through it works, else PS5LM's own copy on 2123 (third_party/ftpsrv
+// with patches/ftpsrv, loopback only), which the title sends to the ELF loader
+// itself when nothing answers there.
+//
+// Ported from PS5SD (Darkatek7/PS5SD, ps5/app/ftp_writer.*).
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <string>
+#include <utility>
+
+namespace ps5lm {
+
+class FtpWriter {
+public:
+ explicit FtpWriter(std::string host = "127.0.0.1", int port = 2121) : host_(std::move(host)), port_(port) {}
+ ~FtpWriter() { close(); }
+ FtpWriter(const FtpWriter &) = delete;
+ FtpWriter & operator=(const FtpWriter &) = delete;
+
+ // The control connection: connects and logs in, unless it already is.
+ bool connect(std::string & error);
+ // Writes n bytes to path at offset, which must not lie past the file's end;
+ // the file is cut to offset + n. True once the server confirmed (226), so
+ // the bytes are in the file.
+ bool write_at(const std::string & path, uint64_t offset, const char * data, size_t n, std::string & error);
+ // One long transfer, for a file in one stream: begin at offset, send, end.
+ // end() is true once the server confirmed the whole transfer.
+ bool begin(const std::string & path, uint64_t offset, std::string & error);
+ bool send(const char * data, size_t n, std::string & error);
+ bool end(std::string & error);
+ bool rename(const std::string & from, const std::string & to, std::string & error);
+ // The file's size; false if it is not there (550) or the server is gone.
+ bool size(const std::string & path, uint64_t & out, std::string & error);
+ void close();
+
+ void set_timeout(int seconds) { timeout_ = seconds; }
+ // Only while not connected.
+ void set_port(int port) { port_ = port; }
+ int port() const { return port_; }
+ // The last connect() found nothing listening (the TCP connect itself failed).
+ bool refused() const { return refused_; }
+
+private:
+ bool command(const std::string & line, int & code, std::string & reply, std::string & error);
+ bool reply(int & code, std::string & text, std::string & error);
+ bool open_data(std::string & error);
+ int dial(int port, std::string & error);
+ bool send_all(int fd, const char * data, size_t n, std::string & error);
+
+ std::string host_;
+ int port_;
+ int timeout_ = 30;
+ bool refused_ = false;
+ bool pasv_ = false; // the server does not know EPSV
+ int ctrl_ = -1;
+ int data_ = -1;
+ std::string inbox_; // control bytes read past the last reply line
+};
+
+constexpr int kFtpsrvPort = 2121; // the user's ftpsrv
+constexpr int kOwnFtpsrvPort = 2123; // PS5LM's copy (patches/ftpsrv)
+constexpr int kElfLoaderPort = 9021;
+constexpr const char * kOwnFtpsrvElf = "/app0/payloads/ps5lm-ftpsrv.elf";
+constexpr const char * kFtpCheckFile = "/data/PS5LM/.ps5lm-ftp-check";
+
+// Connects ftp (not connected yet) to 2121, else 2123. The first time 2121
+// answers, one byte is written to kFtpCheckFile through it; when that fails
+// (an ftpsrv without a command PS5LM needs), 2121 is left alone for the rest
+// of the run. When nothing listens on 2123, the first call that needs it sends
+// kOwnFtpsrvElf to the ELF loader on 9021 and waits up to 5 s for it; that
+// happens at most once per app run, also when several threads get here at
+// once. False with error when no server answers: the caller writes the file
+// itself then.
+bool connect_ftp_writer(FtpWriter & ftp, std::string & error);
+
+// ftpsrv's answer when the disk is full (552, or 451/452 with errno's text).
+bool ftp_disk_full(const std::string & error);
+
+} // namespace ps5lm
diff --git a/ps5/app/ftp_writer_test.cpp b/ps5/app/ftp_writer_test.cpp
new file mode 100644
index 0000000..1a912ac
--- /dev/null
+++ b/ps5/app/ftp_writer_test.cpp
@@ -0,0 +1,43 @@
+// Host check for ftp_writer.cpp:
+// c++ -std=c++17 -O1 ps5/app/ftp_writer_test.cpp ps5/app/ftp_writer.cpp -o build/ftp_writer_test
+// (scripts/test-native-build.sh runs it in CI)
+// build/ftp_writer_test
+// A path with a line break is refused before anything connects, so no server
+// is needed: a path that got past the check would fail to connect instead.
+// SPDX-License-Identifier: GPL-3.0-or-later
+#include "ftp_writer.hpp"
+
+#include <cassert>
+#include <cstdint>
+#include <cstdio>
+#include <string>
+
+namespace ps5lm {
+// ftp_writer.cpp starts PS5LM's own ftpsrv with it; nothing here gets that far.
+bool send_payload(const char *, int) {
+ return false;
+}
+} // namespace ps5lm
+
+namespace {
+
+bool refused(bool ok, const std::string & error) {
+ return !ok && error.find("line break") != std::string::npos;
+}
+
+} // namespace
+
+int main() {
+ ps5lm::FtpWriter w;
+ uint64_t size = 0;
+ for (const std::string & path : { std::string("x.gguf\r\nDELE /data/a"), std::string("x\n.gguf"),
+ std::string("x\0.gguf", 7) }) {
+ std::string error;
+ assert(refused(w.write_at(path, 0, "x", 1, error), error));
+ error.clear();
+ assert(refused(w.size(path, size, error), error));
+ }
+ std::string error;
+ assert(!refused(w.size("/data/PS5LM/models/x.gguf.part", size, error), error));
+ std::puts("ftp_writer_test: ok");
+}
diff --git a/ps5/app/market.cpp b/ps5/app/market.cpp
index c6ea6d3..dc32494 100644
--- a/ps5/app/market.cpp
+++ b/ps5/app/market.cpp
@@ -2,6 +2,7 @@
#include "market.hpp"
#include "fetch.hpp"
+#include "ftp_writer.hpp"
#include "model_plan.hpp"
#include <nlohmann/json.hpp>
@@ -13,6 +14,7 @@ extern "C" {
#include <cstdio>
#include <algorithm>
#include <chrono>
+#include <condition_variable>
#include <fcntl.h>
#include <filesystem>
#include <fstream>
@@ -420,6 +422,12 @@ void Market::worker() {
// the line's speed. What is done from the start of the file (`resume`) is
// saved with the queue, so a dropped connection, a pause or a restart costs
// at most the pieces in flight. The SHA-256 is checked once it is whole.
+//
+// The pieces go through ftpsrv when one answers (ftp_writer.hpp): the
+// title's own writes slow to about 1.2 MB/s after 2.2 GB, a payload's do not
+// (#41). Each piece is then held in memory until the ones before it are
+// written, and is written with REST/STOR at its place, so the file only
+// grows at its end; the first STOR, at `resume`, cuts off what lies past it.
bool Market::fetch(Download & d) {
constexpr uint64_t kPiece = 32ull << 20;
const std::string part = part_path(d);
@@ -452,6 +460,14 @@ bool Market::fetch(Download & d) {
if (d.resume > d.bytes || d.resume > file_size(part)) {
d.resume = 0; // not this file, or the partial file is gone
}
+ FtpWriter ftp;
+ std::string ftp_error;
+ const bool via_ftp = connect_ftp_writer(ftp, ftp_error);
+ const std::string direct_note = via_ftp ? "" : "written without ftpsrv, slower after about 2 GB";
+ if (!via_ftp) {
+ std::printf("ps5lm-app: download %s: the app writes the file itself, which gets slow after about 2.2 GB (%s)\n",
+ d.file.c_str(), ftp_error.c_str());
+ }
const int fd = open(part.c_str(), O_WRONLY | O_CREAT, 0666);
if (fd < 0) {
d.state = DownloadState::failed;
@@ -463,12 +479,41 @@ bool Market::fetch(Download & d) {
const size_t pieces = (size_t) ((d.bytes - base + kPiece - 1) / kPiece);
std::vector<uint8_t> state(pieces, 0); // 0 to fetch, 1 in flight, 2 written
std::mutex m;
+ std::mutex write_mutex; // one STOR at a time
+ std::condition_variable written; // a piece became 2
std::atomic<uint64_t> received{ base };
std::atomic<int> failures{ 0 }; // in a row, across connections
std::atomic<int> waiting{ 0 }; // connections waiting to try again
std::atomic<bool> fatal{ false };
std::string last_error;
+ // Through ftpsrv: once the pieces before k are written, k at its place. A
+ // piece counts once ftpsrv confirmed it (226); a failed one is cut off by
+ // the next STOR at its start. One more try on a new connection (ftpsrv
+ // may have dropped an idle one), unless the disk is full.
+ const auto write_piece = [&](size_t k, uint64_t off, const std::vector<char> & buf, std::string & error) {
+ {
+ std::unique_lock<std::mutex> lock(m);
+ while (!std::all_of(state.begin(), state.begin() + (long) k, [](uint8_t s) { return s == 2; })) {
+ if (stop_ != 0 || fatal) {
+ return false;
+ }
+ written.wait_for(lock, std::chrono::milliseconds(250));
+ }
+ }
+ std::lock_guard<std::mutex> lock(write_mutex);
+ if (ftp.write_at(part, off, buf.data(), buf.size(), error)) {
+ return true;
+ }
+ if (ftp_disk_full(error)) {
+ return false;
+ }
+ std::printf("ps5lm-app: download %s: piece at %llu: %s, writing it again\n", d.file.c_str(),
+ (unsigned long long) off, error.c_str());
+ error.clear();
+ return ftp.write_at(part, off, buf.data(), buf.size(), error);
+ };
const auto worker = [&](int id) {
+ std::vector<char> buf; // the piece, until ftpsrv has it
for (;;) {
size_t k = pieces;
{
@@ -488,34 +533,52 @@ bool Market::fetch(Download & d) {
char range[64];
std::snprintf(range, sizeof(range), "bytes=%llu-%llu", (unsigned long long) off, (unsigned long long) (off + len - 1));
uint64_t got = 0;
+ buf.clear();
+ if (via_ftp) {
+ buf.reserve(len);
+ }
const FetchResult r = kGet(id, url, range, [&](const char * p, size_t n) {
- if (stop_ != 0 || got + n > len || pwrite(fd, p, n, (off_t) (off + got)) != (ssize_t) n) {
+ if (stop_ != 0 || got + n > len) {
+ return false;
+ }
+ if (via_ftp) {
+ buf.insert(buf.end(), p, p + n);
+ } else if (pwrite(fd, p, n, (off_t) (off + got)) != (ssize_t) n) {
return false;
}
got += n;
received += n;
return true;
});
+ std::string write_error;
+ const bool fetched = got == len && r.status == 206;
+ const bool wrote = fetched && (!via_ftp || write_piece(k, off, buf, write_error));
std::lock_guard<std::mutex> lock(m);
- if (got == len && r.status == 206) {
+ if (wrote) {
state[k] = 2;
failures = 0;
+ written.notify_all();
continue;
}
state[k] = 0; // again, from its start
received -= got;
- if (stop_ != 0) {
+ if (stop_ != 0 || fatal) {
return;
}
char text[200];
- std::snprintf(text, sizeof(text), "%s%s%s", r.status > 0 ? ("HTTP " + std::to_string(r.status)).c_str() : "",
- r.status > 0 && !r.error.empty() ? ", " : "", r.error.c_str());
+ if (fetched) {
+ std::snprintf(text, sizeof(text), "%s", write_error.c_str());
+ } else {
+ std::snprintf(text, sizeof(text), "%s%s%s", r.status > 0 ? ("HTTP " + std::to_string(r.status)).c_str() : "",
+ r.status > 0 && !r.error.empty() ? ", " : "", r.error.c_str());
+ }
last_error = text;
const int f = ++failures;
std::printf("ps5lm-app: download %s: piece at %llu stopped after %llu bytes: %s\n", d.file.c_str(),
(unsigned long long) off, (unsigned long long) got, text);
// A 4xx other than 408/429 will not get better by asking again.
- if ((r.status >= 400 && r.status < 500 && r.status != 408 && r.status != 429) || r.status == 200 || f > 20) {
+ if ((r.status >= 400 && r.status < 500 && r.status != 408 && r.status != 429) || r.status == 200 || f > 20 ||
+ (fetched && ftp_disk_full(write_error))) {
fatal = true;
return;
}
@@ -556,7 +619,7 @@ bool Market::fetch(Download & d) {
d.note = "Connection lost (" + last_error + "); trying again, attempt " + std::to_string((int) failures);
} else {
d.state = DownloadState::running;
- d.note.clear();
+ d.note = direct_note;
}
}
const auto now = std::chrono::steady_clock::now();
@@ -577,6 +640,7 @@ bool Market::fetch(Download & d) {
}
fsync(fd);
close(fd);
+ ftp.close();
d.mbps = 0;
if (stop_ != 0 || fatal) {
d.state = stop_ == 1 ? DownloadState::paused : DownloadState::failed;
diff --git a/scripts/build-app.sh b/scripts/build-app.sh
index 70c66a7..cb9fecb 100755
--- a/scripts/build-app.sh
+++ b/scripts/build-app.sh
@@ -20,6 +20,7 @@ radv="$vk/.deps/native/radv-release"
archive="$radv/lib/libvulkan_radeon.ps5.a"
tool="$vk/build/host/ps5-native-tool"
llama="$root/third_party/llama.cpp"
+ftpsrv="$root/third_party/ftpsrv"
out="$root/build/app-ps5"
headers="$root/.deps/ps5-vk-headers"
# ps5-opengl comes pinned and sha256-checked through the submodule's own script.
@@ -62,6 +63,17 @@ for p in "$root"/patches/*.patch; do
git -C "$llama" apply --reverse --check "$p" 2>/dev/null || git -C "$llama" apply "$p"
done
+# ftpsrv (drakmor's 1.16-ng-stable), PS5LM's copy: a payload the app sends to
+# elfldr when no ftpsrv answers (connect_ftp_writer in ps5/app/ftp_writer.hpp).
+# Payloads write to /data at full speed, the title does not after 2.2 GB.
+# patches/ftpsrv puts it on 127.0.0.1:2123 only, as ps5lm-ftpsrv.
+for p in "$root"/patches/ftpsrv/*.patch; do
+ git -C "$ftpsrv" apply --reverse --check "$p" 2>/dev/null || git -C "$ftpsrv" apply "$p"
+done
+mkdir -p "$out/ftpsrv"
+make -C "$ftpsrv" -f Makefile.ps5 PS5_PAYLOAD_SDK="$sdk" ELF="$out/ftpsrv/ps5lm-ftpsrv.elf" > "$out/ftpsrv.build.log" 2>&1 ||
+ { tail -30 "$out/ftpsrv.build.log" >&2; exit 1; }
+
flags="-DSUBPROCESS_HAVE_CWD=0 -I$headers/include"
# llama.cpp throws, catches and uses dynamic_cast; the PS5 target turns
# exceptions and RTTI off by default.
@@ -95,6 +107,7 @@ cxx -fexceptions -fcxx-exceptions -c "$root/ps5/app/model_plan.cpp" -o "$obj/mod
cxx -std=c++20 -fexceptions -fcxx-exceptions -I "$llama/vendor" -c "$root/ps5/app/settings.cpp" -o "$obj/settings.o"
cxx -std=c++20 -fexceptions -fcxx-exceptions -c "$root/ps5/app/fetch.cpp" -o "$obj/fetch.o"
cxx -std=c++20 -fexceptions -fcxx-exceptions -I "$llama/vendor" -c "$root/ps5/app/market.cpp" -o "$obj/market.o"
+cxx -std=c++20 -fexceptions -fcxx-exceptions -c "$root/ps5/app/ftp_writer.cpp" -o "$obj/ftp_writer.o"
cxx -std=c++20 -fexceptions -fcxx-exceptions -I "$llama/vendor" -I "$root/ps5/app" -I "$root/third_party/ps5-homebrew-ui/src" -c "$root/ps5/app/activity.cpp" -o "$obj/activity.o"
"$root/ps5/app/ps5cc" -O2 -I "$llama/vendor/hash" -c "$llama/vendor/hash/sha256/sha256.c" -o "$obj/sha256.o"
"$root/ps5/app/ps5cc" -O2 -c "$root/ps5/app/compat_app.c" -o "$obj/compat_app.o"
@@ -194,7 +207,7 @@ mapfile -t libs < <(find "$out/llama" -name '*.a' | sort)
"$sdk/bin/prospero-lld" "${radv_linker_script[@]}" --eh-frame-hdr "${radv_link_flags[@]}" \
--version-script "$vk/tooling/native/app-symbols.map" --exclude-libs=ALL \
-e _start -o "$out/llvm-pie.elf" \
- "$obj/app_crt.o" "$obj/app_cpp_runtime.o" "$obj/main.o" "$obj/display.o" "$obj/model_plan.o" "$obj/settings.o" "$obj/fetch.o" "$obj/market.o" "$obj/activity.o" "$obj/sha256.o" "$obj/dashboard.o" "$obj/stats.o" \
+ "$obj/app_crt.o" "$obj/app_cpp_runtime.o" "$obj/main.o" "$obj/display.o" "$obj/model_plan.o" "$obj/settings.o" "$obj/fetch.o" "$obj/market.o" "$obj/ftp_writer.o" "$obj/activity.o" "$obj/sha256.o" "$obj/dashboard.o" "$obj/stats.o" \
--start-group "${libs[@]}" "$obj/libps5lm_kit.a" "$obj/libps5app_compat.a" "$out/gl/libps5lm_gl.a" --end-group \
"$out/stubs/libSceAgc.so" "$out/stubs/libSceAgcDriver.so" \
"${radv_link_inputs[@]}" \
@@ -246,5 +259,12 @@ mkdir -p "$app/payloads"
cp "$exporter" "$app/payloads/ps5-exporter.elf"
printf '%s\n' "ps5-exporter v0.2.0 by Marice, GPL-3.0-or-later: https://github.com/Marice/ps5-exporter" \
"Source: https://github.com/Marice/ps5-exporter/tree/v0.2.0" > "$app/payloads/ps5-exporter-NOTICE.txt"
+# ftpsrv (GPL-3.0-or-later), built above, with its licence and where its source is.
+cp "$out/ftpsrv/ps5lm-ftpsrv.elf" "$app/payloads/ps5lm-ftpsrv.elf"
+cp "$ftpsrv/LICENSE" "$app/payloads/ps5lm-ftpsrv-LICENSE.txt"
+printf '%s\n' "ftpsrv by John Törnblom and drakmor, GPL-3.0-or-later: https://github.com/drakmor/ftpsrv" \
+ "Source: https://github.com/drakmor/ftpsrv/tree/$(git -C "$ftpsrv" rev-parse HEAD) (1.16-ng-stable)," \
+ "with PS5LM's patches/ftpsrv/0001-loopback-only-for-ps5lm.patch: 127.0.0.1:2123 only, as ps5lm-ftpsrv." \
+ > "$app/payloads/ps5lm-ftpsrv-NOTICE.txt"
"$tool" self --inspect --file "$app/eboot.bin" > /dev/null
echo "build-app: $app ($(stat -c %s "$app/eboot.bin") bytes)"
diff --git a/scripts/test-native-build.sh b/scripts/test-native-build.sh
index a656ec6..cc3be5d 100755
--- a/scripts/test-native-build.sh
+++ b/scripts/test-native-build.sh
@@ -19,6 +19,9 @@ export LLVM_CONFIG="$llvm_config"
for tool in git clang clang++ make wget unzip sha256sum timeout python3 cmake ninja meson rsync glslangValidator glslc pkg-config curl ffmpeg; do
command -v "$tool" >/dev/null || { echo "title-check: missing $tool" >&2; exit 2; }
done
+# Host check, no console or server: FtpWriter refuses a path with a line break.
+clang++ -std=c++17 -O1 ps5/app/ftp_writer_test.cpp ps5/app/ftp_writer.cpp -o "$output/tools/ftp_writer_test"
+"$output/tools/ftp_writer_test"
ui="$root/third_party/ps5-homebrew-ui"
ui_revision=$(git ls-tree HEAD third_party/ps5-homebrew-ui | awk '{print $3}')
[[ -f "$ui/tools/fetch-opengl-sdk.sh" && $(git -C "$ui" rev-parse HEAD) == "$ui_revision" ]] || {
@@ -29,6 +32,10 @@ llama_revision=$(git ls-tree HEAD third_party/llama.cpp | awk '{print $3}')
[[ -f "$llama/CMakeLists.txt" && $(git -C "$llama" rev-parse HEAD) == "$llama_revision" ]] || {
echo 'title-check: initialize the pinned llama.cpp submodule first' >&2; exit 2;
}
+ftpsrv_revision=$(git ls-tree HEAD third_party/ftpsrv | awk '{print $3}')
+[[ -f "$root/third_party/ftpsrv/Makefile.ps5" && $(git -C "$root/third_party/ftpsrv" rev-parse HEAD) == "$ftpsrv_revision" ]] || {
+ echo 'title-check: initialize the pinned ftpsrv submodule first' >&2; exit 2;
+}
vk="$PS5LM_NATIVE_SOURCES/PS5_Vulkan"
sdk_fork="$PS5LM_NATIVE_SOURCES/PS5_PayloadSDK"
vk_revision=f410e67a0241b3e8edcdbcd2a9b285dfc4a412ed
@@ -132,7 +139,7 @@ from pathlib import Path
import sys
output, app = map(Path, sys.argv[1:3])
-files = ('eboot.bin', 'sce_module/libc.prx', 'sce_sys/param.json', 'sce_sys/icon0.png', 'sce_sys/pic0.dds', 'sce_sys/pic1.dds')
+files = ('eboot.bin', 'payloads/ps5lm-ftpsrv.elf', 'sce_module/libc.prx', 'sce_sys/param.json', 'sce_sys/icon0.png', 'sce_sys/pic0.dds', 'sce_sys/pic1.dds')
result = {
'status': 'passed',
'scope': 'Complete native title cross-build and static ELF/FSELF validation; NOT console/Vulkan execution',
diff --git a/third_party/ftpsrv b/third_party/ftpsrv
new file mode 160000
index 0000000..dc45a49
--- /dev/null
+++ b/third_party/ftpsrv
@@ -0,0 +1 @@
+Subproject commit dc45a4924789eb67905d5934eed3227b16e3dce8