llama.cpp on a jailbroken PS5: run any GGUF model natively on the console, starting with Qwen 3.8
Get models page: Hugging Face search, fit from the header, download
Abhiram318fdd1f5a25
diff --git a/ps5/app/dashboard.cpp b/ps5/app/dashboard.cppindex f14bc64..1aa0b8c 100644--- a/ps5/app/dashboard.cpp+++ b/ps5/app/dashboard.cpp@@ -159,11 +159,18 @@ Color state_color(ServerState s) {constexpr float kRowH = 78.0f;constexpr Rect kLibrary{ 360.0f, 150.0f, 1200.0f, 800.0f };-constexpr const char * kPageNames[Dashboard::kPages] = { "Dashboard", "Settings", "Logs" };+constexpr const char * kPageNames[Dashboard::kPages] = { "Dashboard", "Settings", "Logs", "Get models" };++// The market's searches, switched with L2/R2: Hugging Face's most downloaded+// GGUF repositories, then the families the presets know.+constexpr const char * kMarketChips[] = { "Popular", "Qwen", "Gemma", "Llama", "Mistral", "Phi", "Granite" };+constexpr int kMarketChipCount = 7;+constexpr float kMarketRowH = 66.0f;+constexpr int kMarketRows = 9;// ---- Settings: categories of rows, after the kit's "Control Room" ----------------enum class Setting : int { auto_load, default_model, ctx_cap, kv_type, sounds, tools, scratch_limit, clear_scratch };+enum class Setting : int { auto_load, default_model, ctx_cap, kv_type, sounds, tools, scratch_limit, clear_scratch, download_dir };struct SettingRow {Setting id;@@ -193,8 +200,9 @@ constexpr SettingCategory kCategories[] = {{ Setting::clear_scratch, "Clear the scratch folder", "Deletes everything the chat's tools wrote." } },3 },{ "App", "The app itself.",- { { Setting::sounds, "Sounds", "Interface sounds on the TV." } },- 1 },+ { { Setting::sounds, "Sounds", "Interface sounds on the TV." },+ { Setting::download_dir, "Download to", "Where Get models saves: internal storage, or PS5LM/models on the USB drive." } },+ 2 },};constexpr int kCategoryCount = 4;@@ -242,6 +250,10 @@ void Dashboard::update(const hui::InputFrame & input, float dt, ui::Feedback & fif (page_ == kLogsPage) {log_scroll_ = 0;}+ if (page_ == kMarketPage && !market_searched_) {+ market_searched_ = true;+ request_ = { Request::market_search, "" };+ }} else {feedback.play(hui::audio::Cue::error, 1.0f, 0.0f, 0.6f);}@@ -249,8 +261,10 @@ void Dashboard::update(const hui::InputFrame & input, float dt, ui::Feedback & fupdate_dashboard(input, feedback);} else if (page_ == 1) {update_settings(input, feedback);- } else {+ } else if (page_ == kLogsPage) {update_logs(input, feedback);+ } else {+ update_market(input, feedback);}for (int i = 0; i < kTiles; ++i) {@@ -390,6 +404,7 @@ std::string setting_text(const Settings & s, Setting id, const std::vector<Modelcase Setting::scratch_limit:std::snprintf(t, sizeof(t), "%u GiB", s.scratch_limit_gib);return t;+ case Setting::download_dir: return s.download_dir.rfind("/mnt/", 0) == 0 ? "USB drive" : "Internal storage";default: return "";}}@@ -469,6 +484,14 @@ bool step_setting(Settings & s, Setting id, int dir, const std::vector<ModelRow>case Setting::sounds: s.sounds = !s.sounds; return true;case Setting::tools: s.tools = !s.tools; return true;case Setting::clear_scratch: return false;+ case Setting::download_dir: {+ const bool usb = s.download_dir.rfind("/mnt/", 0) == 0;+ if ((dir > 0) == usb) {+ return false;+ }+ s.download_dir = usb ? "/data/PS5LM/models" : "/mnt/usb0/PS5LM/models";+ return true;+ }}return false;}@@ -566,6 +589,65 @@ int log_level(const std::string & line) {} // namespace+void Dashboard::update_market(const hui::InputFrame & input, ui::Feedback & feedback) {+ const int step = input.is_pressed(Action::jump_next) ? 1 : input.is_pressed(Action::jump_prev) ? -1 : 0;+ if (step != 0) {+ const int next = market_chip_ + step;+ if (next >= 0 && next < kMarketChipCount) {+ market_chip_ = next;+ market_repo_ = 0;+ market_files_ = false;+ request_ = { Request::market_search, next == 0 ? std::string() : std::string(kMarketChips[next]) };+ feedback.play(hui::audio::Cue::tab);+ } else {+ feedback.play(hui::audio::Cue::error, 1.0f, 0.0f, 0.6f);+ }+ return;+ }+ const int repos = (int) market_.repos.size();+ const MarketRepo * open = market_.open >= 0 && market_.open < repos ? &market_.repos[(size_t) market_.open] : nullptr;+ const int files = open ? (int) open->files.size() : 0;+ int & cursor = market_files_ ? market_file_ : market_repo_;+ const int count = market_files_ ? files : repos;+ if (input.nav == Direction::up || input.nav == Direction::down) {+ const int next = cursor + (input.nav == Direction::down ? 1 : -1);+ if (next >= 0 && next < count) {+ cursor = next;+ feedback.play(hui::audio::Cue::focus, 1.0f + 0.02f * (float) next);+ if (market_files_) {+ request_ = { Request::market_plan, "", market_.open, cursor };+ }+ } else if (!input.nav_repeat) {+ feedback.play(hui::audio::Cue::error, 1.0f, 0.0f, 0.6f);+ }+ }+ if (input.is_pressed(Action::confirm)) {+ if (!market_files_ && cursor < repos) {+ request_ = { Request::market_open, "", cursor, -1 };+ market_files_ = true;+ market_file_ = 0;+ feedback.play(hui::audio::Cue::open);+ } else if (market_files_ && open && cursor < files) {+ const MarketFile & f = open->files[(size_t) cursor];+ if (f.fits == 0 || market_.download_progress >= 0) {+ feedback.play(hui::audio::Cue::error); // too big, or one download already runs+ } else {+ request_ = { Request::market_download, "", market_.open, cursor };+ feedback.play(hui::audio::Cue::complete);+ }+ }+ }+ if (input.is_pressed(Action::back) && market_files_) {+ market_files_ = false;+ feedback.play(hui::audio::Cue::back);+ }+ // The first file of a freshly opened repository gets planned too.+ if (request_.kind == Request::none && market_files_ && files > 0 && market_file_ == 0 && open->files[0].fits == -1 &&+ !market_.busy) {+ request_ = { Request::market_plan, "", market_.open, 0 };+ }+}+void Dashboard::set_logs(std::vector<std::string> app, std::vector<std::string> llama) {app_log_ = std::move(app);llama_log_ = std::move(llama);@@ -1408,6 +1490,100 @@ void Dashboard::draw_settings(gfx::DrawList & list) const {ui::text(list, f.regular, help, kSettingsPanel.x + 48, foot + 50, 22, kInk.with_alpha(kMuted * in));}+// Two panes in the Logs page's frame: the repositories of the search on the+// left, the open one's GGUF files on the right with whether each fits.+void Dashboard::draw_market(gfx::DrawList & list) const {+ const ui::Fonts & f = fonts_;+ const Rect & p = kLogPanel;+ const MarketView & M = market_;+ draw_panel(list, p, kRadius, 0.0f, kLime);+ // The searches as chips; L2/R2 move between them.+ float x = p.x + kPad;+ for (int k = 0; k < kMarketChipCount; ++k) {+ const bool on = k == market_chip_;+ const float w = f.semibold.measure(kMarketChips[k], 18) + 40;+ const Rect chip{ x, p.y + 22, w, 38 };+ list.bordered_rect(chip, 19, on ? kLime.with_alpha(0.16f) : kClear, 1.5f, on ? kLime : kInk.with_alpha(0.16f));+ ui::text(list, on ? f.semibold : f.regular, kMarketChips[k], chip.cx(), chip.cy() + 7, 18,+ on ? kInk : kInk.with_alpha(kMuted), gfx::Align::center);+ x += w + 12;+ }+ const char * status = M.busy ? "Working" : M.status.c_str();+ ui::text(list, f.regular, f.regular.font->fit(status, 20, 420), p.x + p.w - kPad, p.y + 48, 20,+ kInk.with_alpha(kMuted), gfx::Align::right);+ list.rounded_rect({ p.x + kPad, p.y + 76, p.w - 2 * kPad, 1 }, 0, kInk.with_alpha(0.1f));++ const float lx = p.x + kPad, lw = 620, rx = lx + lw + 40, rw = p.x + p.w - kPad - rx, top = p.y + 96;+ list.rounded_rect({ rx - 20, top, 1, kMarketRows * kMarketRowH }, 0, kInk.with_alpha(0.1f));+ char text[160];+ // Repositories.+ const int repos = (int) M.repos.size();+ const int rfirst = std::max(0, market_repo_ - (kMarketRows - 1));+ for (int i = rfirst; i < repos && i < rfirst + kMarketRows; ++i) {+ const MarketRepo & r = M.repos[(size_t) i];+ const float y = top + (float) (i - rfirst) * kMarketRowH;+ const bool cur = i == market_repo_;+ if (cur) {+ const Color c = market_files_ ? kInk.with_alpha(0.08f) : kLime.with_alpha(0.12f);+ list.bordered_rect({ lx - 8, y, lw + 16, kMarketRowH - 8 }, 14, c, 2.0f,+ market_files_ ? kInk.with_alpha(0.2f) : kLime.with_alpha(0.7f));+ }+ ui::text(list, cur ? f.semibold : f.regular, f.regular.font->fit(r.id, 22, lw - 150), lx + 12, y + 37, 22,+ kInk.with_alpha(cur ? 1.0f : 0.85f));+ std::snprintf(text, sizeof(text), "%.1fk", r.downloads / 1000.0);+ ui::text(list, f.mono, text, lx + lw - 8, y + 37, 18, kInk.with_alpha(kMuted), gfx::Align::right);+ }+ if (repos == 0) {+ ui::text(list, f.regular, M.busy ? "Searching Hugging Face" : "No repositories", lx + 12, top + 40, 22,+ kInk.with_alpha(kFaint));+ }++ // The open repository's files.+ const MarketRepo * open = M.open >= 0 && M.open < repos ? &M.repos[(size_t) M.open] : nullptr;+ if (!open) {+ ui::paragraph(list, f.regular, "Cross opens a repository: its GGUF files, their sizes, and the context each would get on this console.",+ rx, top + 40, 22, rw, 32, kInk.with_alpha(kFaint), 3);+ } else {+ ui::text(list, f.semibold, f.semibold.font->fit(open->id, 22, rw), rx, top + 4, 22, kLime);+ const int files = (int) open->files.size();+ const int ffirst = std::max(0, market_file_ - (kMarketRows - 2));+ for (int i = ffirst; i < files && i < ffirst + kMarketRows - 1; ++i) {+ const MarketFile & mf = open->files[(size_t) i];+ const float y = top + 26 + (float) (i - ffirst) * kMarketRowH;+ const bool cur = market_files_ && i == market_file_;+ if (cur) {+ list.bordered_rect({ rx - 8, y, rw + 16, kMarketRowH - 8 }, 14, kLime.with_alpha(0.12f), 2.0f,+ kLime.with_alpha(0.7f));+ }+ const size_t slash = mf.name.find_last_of('/');+ const std::string short_name = mf.name.substr(slash == std::string::npos ? 0 : slash + 1);+ ui::text(list, cur ? f.semibold : f.regular, f.regular.font->fit(short_name, 20, rw - 230), rx + 12, y + 26,+ 20, kInk.with_alpha(mf.fits == 0 ? 0.45f : 1.0f));+ ui::text(list, f.regular, f.regular.font->fit(mf.plan.empty() ? "Not planned yet" : mf.plan, 16, rw - 230),+ rx + 12, y + 50, 16, kInk.with_alpha(kFaint));+ std::snprintf(text, sizeof(text), "%.1f GiB", mf.bytes / 1073741824.0);+ ui::text(list, f.mono, text, rx + rw - 110, y + 36, 18, kInk.with_alpha(0.85f), gfx::Align::right);+ const char * tag = mf.fits == 1 ? "FITS" : mf.fits == 0 ? "TOO BIG" : mf.fits == -2 ? "UNKNOWN" : "CHECK";+ const Color tc = mf.fits == 1 ? kLime : mf.fits == 0 ? kRose : kInk.with_alpha(kMuted);+ caps(list, f, tag, rx + rw - 8, y + 36, 14, tc, gfx::Align::right);+ }+ }++ // The download, under both panes.+ const float by = p.y + p.h - 64;+ list.rounded_rect({ p.x + kPad, by - 24, p.w - 2 * kPad, 1 }, 0, kInk.with_alpha(0.1f));+ if (M.download_progress >= 0) {+ std::snprintf(text, sizeof(text), "Downloading %s \xC2\xB7 %.0f%% \xC2\xB7 %.1f MB/s", M.download_file.c_str(),+ M.download_progress * 100.0f, M.download_mbps);+ ui::text(list, f.regular, f.regular.font->fit(text, 20, p.w - 2 * kPad - 420), p.x + kPad, by + 6, 20, kInk);+ bar(list, { p.x + p.w - kPad - 380, by - 4, 380, 12 }, M.download_progress, kLime);+ } else {+ const std::string note = !M.download_result.empty() ? M.download_result+ : "Downloads go to " + settings_.download_dir + " \xC2\xB7 change in Settings";+ ui::text(list, f.regular, f.regular.font->fit(note, 20, p.w - 2 * kPad), p.x + kPad, by + 6, 20, kInk.with_alpha(kMuted));+ }+}+void Dashboard::draw_logs(gfx::DrawList & list) const {const ui::Fonts & f = fonts_;const Rect & p = kLogPanel;@@ -1486,6 +1662,10 @@ void Dashboard::draw_hints(DashboardFrame & frame) const {const ui::Hint plain[] = { { ui::Button::dpad, "Change" }, { ui::Button::circle, "Back" } };ui::draw_hints(frame.scene, fonts_, style, toggle ? hints : plain, toggle ? 3 : 2, kGridX + kGridW, true);}+ } else if (page_ == kMarketPage) {+ const ui::Hint browse[] = { { ui::Button::l2, "Search" }, { ui::Button::dpad, "Choose" }, { ui::Button::cross, "Open" } };+ const ui::Hint files[] = { { ui::Button::dpad, "Choose" }, { ui::Button::cross, "Download" }, { ui::Button::circle, "Back" } };+ ui::draw_hints(frame.scene, fonts_, style, market_files_ ? files : browse, 3, kGridX + kGridW, true);} else if (page_ == kLogsPage) {const ui::Hint hints[] = { { ui::Button::dpad, "Scroll" },{ ui::Button::square, log_llama_ ? "app.log" : "llama.log" },@@ -1540,8 +1720,10 @@ void Dashboard::draw(DashboardFrame & frame) const {scene.pop_transform();} else if (page_ == 1) {draw_settings(scene);- } else {+ } else if (page_ == kLogsPage) {draw_logs(scene);+ } else {+ draw_market(scene);}scene.pop_opacity();scene.pop_transform();diff --git a/ps5/app/dashboard.hpp b/ps5/app/dashboard.hppindex 71faa3b..d7a2ee3 100644--- a/ps5/app/dashboard.hpp+++ b/ps5/app/dashboard.hpp@@ -10,6 +10,7 @@// SPDX-License-Identifier: GPL-3.0-or-later#pragma once+#include "market.hpp"#include "settings.hpp"#include "stats.hpp"@@ -37,8 +38,9 @@ struct DashboardFrame {class Dashboard {public:static constexpr int kTiles = 8;- static constexpr int kPages = 3;+ static constexpr int kPages = 4;static constexpr int kLogsPage = 2;+ static constexpr int kMarketPage = 3;explicit Dashboard(const hui::ui::Fonts & fonts) : fonts_(fonts) { ring_.snap(ring_rect()); }@@ -47,6 +49,7 @@ class Dashboard {void set_settings(const Settings & s) { settings_ = s; }const Settings & settings() const { return settings_; }void set_logs(std::vector<std::string> app, std::vector<std::string> llama);+ void set_market(MarketView view) { market_ = std::move(view); }int page() const { return page_; }void update(const hui::InputFrame & input, float dt, hui::ui::Feedback & feedback);void draw(DashboardFrame & frame) const;@@ -54,8 +57,9 @@ class Dashboard {// What the user asked for, once: load or unload a model, or the settings// changed (read them with settings()).struct Request {- enum Kind { none, load, unload, settings, clear_scratch } kind = none;- std::string path;+ enum Kind { none, load, unload, settings, clear_scratch, market_search, market_open, market_plan, market_download } kind = none;+ std::string path; // a model, or a market query+ int repo = -1, file = -1;};Request take_request() {Request r = request_;@@ -79,6 +83,8 @@ class Dashboard {void update_dashboard(const hui::InputFrame & input, hui::ui::Feedback & feedback);void update_settings(const hui::InputFrame & input, hui::ui::Feedback & feedback);void update_logs(const hui::InputFrame & input, hui::ui::Feedback & feedback);+ void update_market(const hui::InputFrame & input, hui::ui::Feedback & feedback);+ void draw_market(hui::gfx::DrawList & list) const;const std::vector<std::string> & log_view() const { return log_llama_ ? llama_view_ : app_view_; }void refilter_logs();@@ -121,6 +127,13 @@ class Dashboard {bool log_llama_ = false;bool log_errors_ = false;int log_scroll_ = 0; // lines up from the newest++ MarketView market_;+ int market_chip_ = 0; // which search the chips select+ int market_repo_ = 0; // cursor in the repositories+ int market_file_ = 0; // cursor in the open repository's files+ bool market_files_ = false; // the cursor is in the files+ bool market_searched_ = false;mutable char size_text_[64] = {};};diff --git a/ps5/app/fetch.cpp b/ps5/app/fetch.cppnew file mode 100644index 0000000..b6d855a--- /dev/null+++ b/ps5/app/fetch.cpp@@ -0,0 +1,106 @@+// SPDX-License-Identifier: GPL-3.0-or-later+#include "fetch.hpp"++#include <chrono>+#include <cstdio>+#include <mutex>+#include <vector>++extern "C" {+int sceNetInit(void);+int sceNetPoolCreate(const char * name, int size, int flags);+int sceSslInit(size_t pool);+int sceHttp2Init(int net_pool, int ssl_ctx, size_t pool, int max_requests);+int sceHttp2CreateTemplate(int ctx, const char * agent, int http_version, int auto_proxy);+int sceHttp2CreateRequestWithURL(int tmpl, const char * method, const char * url, uint64_t content_length);+int sceHttp2AddRequestHeader(int req, const char * name, const char * value, uint32_t mode);+int sceHttp2SendRequest(int req, const void * body, size_t size);+int sceHttp2GetStatusCode(int req, int * status);+int sceHttp2GetResponseContentLength(int req, int * result, uint64_t * length);+int sceHttp2ReadData(int req, void * buf, size_t size);+int sceHttp2DeleteRequest(int req);+}++namespace ps5lm {++namespace {++std::mutex g_init;+int g_template = -1;+std::string g_init_error;++// The libraries once per process; their contexts live as long as it does.+bool init(std::string * error) {+ std::lock_guard<std::mutex> lock(g_init);+ if (g_template >= 0) {+ return true;+ }+ if (!g_init_error.empty()) {+ *error = g_init_error;+ return false;+ }+ char text[96];+ int net = -1, ssl = -1, http = -1;+ if (int rc = sceNetInit(); rc < 0) {+ std::snprintf(text, sizeof(text), "sceNetInit 0x%x", rc);+ } else if ((net = sceNetPoolCreate("ps5lm-fetch", 128 * 1024, 0)) < 0) {+ std::snprintf(text, sizeof(text), "sceNetPoolCreate 0x%x", net);+ } else if ((ssl = sceSslInit(512 * 1024)) < 0) {+ std::snprintf(text, sizeof(text), "sceSslInit 0x%x", ssl);+ } else if ((http = sceHttp2Init(net, ssl, 512 * 1024, 4)) < 0) {+ std::snprintf(text, sizeof(text), "sceHttp2Init 0x%x", http);+ } else if ((g_template = sceHttp2CreateTemplate(http, "PS5LM/1.0", 3, 1)) < 0) {+ std::snprintf(text, sizeof(text), "sceHttp2CreateTemplate 0x%x", g_template);+ } else {+ return true;+ }+ g_template = -1;+ g_init_error = text;+ *error = text;+ return false;+}++} // namespace++FetchResult https_get(const std::string & url, const std::string & range,+ const std::function<bool(const char *, size_t)> & sink) {+ FetchResult r;+ const auto t0 = std::chrono::steady_clock::now();+ if (!init(&r.error)) {+ return r;+ }+ char text[96];+ const int req = sceHttp2CreateRequestWithURL(g_template, "GET", url.c_str(), 0);+ if (req < 0) {+ std::snprintf(text, sizeof(text), "sceHttp2CreateRequestWithURL 0x%x", req);+ r.error = text;+ return r;+ }+ if (!range.empty()) {+ sceHttp2AddRequestHeader(req, "Range", range.c_str(), 0);+ }+ if (int rc = sceHttp2SendRequest(req, nullptr, 0); rc < 0) {+ std::snprintf(text, sizeof(text), "sceHttp2SendRequest 0x%x", rc);+ r.error = text;+ sceHttp2DeleteRequest(req);+ return r;+ }+ sceHttp2GetStatusCode(req, &r.status);+ int has_length = 0;+ uint64_t length = 0;+ if (sceHttp2GetResponseContentLength(req, &has_length, &length) == 0 && has_length == 0) {+ r.length = (int64_t) length; // result 0: the length is known+ }+ std::vector<char> buf(1u << 20);+ for (int n; (n = sceHttp2ReadData(req, buf.data(), buf.size())) > 0;) {+ r.bytes += (uint64_t) n;+ if (!sink(buf.data(), (size_t) n)) {+ break;+ }+ }+ sceHttp2DeleteRequest(req);+ r.seconds = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();+ return r;+}++} // namespace ps5lmdiff --git a/ps5/app/fetch.hpp b/ps5/app/fetch.hppnew file mode 100644index 0000000..3628418--- /dev/null+++ b/ps5/app/fetch.hpp@@ -0,0 +1,27 @@+// HTTPS from the title through the system's own HTTP/2 and TLS libraries+// (libSceHttp2, libSceSsl), as ps5-payload-dev's http2_get sample uses them:+// no TLS library or certificates of our own.+//+// SPDX-License-Identifier: GPL-3.0-or-later+#pragma once++#include <cstdint>+#include <functional>+#include <string>++namespace ps5lm {++struct FetchResult {+ int status = -1; // HTTP status, or -1 when the request did not go out+ int64_t length = -1; // Content-Length, or -1+ uint64_t bytes = 0; // body bytes handed to the sink+ double seconds = 0;+ std::string error; // the failing call and its code, when status is -1+};++// GET `url`, optionally with a Range header ("bytes=0-16777215"). Each piece+// of the body goes to `sink`; returning false from it stops the download.+FetchResult https_get(const std::string & url, const std::string & range,+ const std::function<bool(const char *, size_t)> & sink);++} // namespace ps5lmdiff --git a/ps5/app/main.cpp b/ps5/app/main.cppindex 5b2c38b..fda2200 100644--- a/ps5/app/main.cpp+++ b/ps5/app/main.cpp@@ -13,7 +13,9 @@// SPDX-License-Identifier: GPL-3.0-or-later#include <pthread.h>+#include <fcntl.h>#include <sys/stat.h>+#include <sys/statvfs.h>#include <unistd.h>#include <algorithm>@@ -36,6 +38,8 @@#include <GL/glcorearb.h>#include "dashboard.hpp"+#include "fetch.hpp"+#include "market.hpp"#include "display.hpp"#include "ggml-backend.h"#include "model_plan.hpp"@@ -129,6 +133,73 @@ std::vector<std::string> tail_lines(const char * path) {return lines;}+// Probe: download a URL over HTTPS to /data/PS5LM/fetch.out, logging the+// status, size and speed (scripts/ps5lm-app.sh fetch <url>).+void probe_fetch(std::string url) {+ FILE * out = std::fopen("/data/PS5LM/fetch.out", "wb");+ const FetchResult r = https_get(url, "", [&](const char * p, size_t n) { return out && std::fwrite(p, 1, n, out) == n; });+ if (out) {+ std::fclose(out);+ }+ std::printf("ps5lm-app: fetch %s: status %d, length %lld, %llu bytes in %.1f s (%.2f MB/s)%s%s\n", url.c_str(),+ r.status, (long long) r.length, (unsigned long long) r.bytes, r.seconds,+ r.seconds > 0 ? r.bytes / 1e6 / r.seconds : 0.0, r.error.empty() ? "" : ", ", r.error.c_str());+}++// Probe: how fast the app can write, by method and place, fsync included+// (scripts/ps5lm-app.sh bench-write). 128 MiB each.+void probe_write() {+ const size_t total = 128u << 20;+ std::vector<char> buf(8u << 20, 'x');+ const char * dirs[] = { "/data/PS5LM", "/mnt/usb0" };+ for (const char * dir : dirs) {+ struct statvfs v = {};+ if (statvfs(dir, &v) != 0) {+ continue;+ }+ const std::string path = std::string(dir) + "/write-bench.tmp";+ struct Method {+ const char * name;+ size_t chunk;+ bool stdio;+ int flags;+ } methods[] = {+ { "stdio 8M", 8u << 20, true, 0 },+ { "write 1M", 1u << 20, false, 0 },+ { "write 8M", 8u << 20, false, 0 },+ { "write 8M direct", 8u << 20, false, O_DIRECT },+ };+ for (const auto & m : methods) {+ const auto t0 = std::chrono::steady_clock::now();+ bool ok = true;+ if (m.stdio) {+ FILE * f = std::fopen(path.c_str(), "wb");+ for (size_t done = 0; f && ok && done < total; done += m.chunk) {+ ok = std::fwrite(buf.data(), 1, m.chunk, f) == m.chunk;+ }+ ok = f && ok && std::fflush(f) == 0 && fsync(fileno(f)) == 0;+ if (f) {+ std::fclose(f);+ }+ } else {+ const int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | m.flags, 0666);+ for (size_t done = 0; fd >= 0 && ok && done < total; done += m.chunk) {+ ok = write(fd, buf.data(), m.chunk) == (ssize_t) m.chunk;+ }+ ok = fd >= 0 && ok && fsync(fd) == 0;+ if (fd >= 0) {+ close(fd);+ }+ }+ const double s = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();+ std::printf("ps5lm-app: write-bench %s %s: %s, %.1f MB/s\n", dir, m.name, ok ? "ok" : strerror(errno),+ ok ? total / 1e6 / s : 0.0);+ unlink(path.c_str());+ }+ }+ std::printf("ps5lm-app: write-bench done\n");+}+// Bytes under a folder, or 0.uint64_t folder_bytes(const char * path) {std::error_code ec;@@ -526,6 +597,9 @@ int main(int, char **) {sounds.load(std::string(kAssets) + "/audio/sfx");Dashboard dash(fonts);+ Market market;+ market.start(models.budget_gib);+ std::string last_download;dash.set_settings(models.settings);bool library_shown = false; // opened once at launch when no model is loadedbool scratch_warned = false;@@ -582,6 +656,8 @@ int main(int, char **) {{ "square", hui::Action::west, hui::Direction::none },{ "l1", hui::Action::page_prev, hui::Direction::none },{ "r1", hui::Action::page_next, hui::Direction::none },+ { "l2", hui::Action::jump_prev, hui::Direction::none },+ { "r2", hui::Action::jump_next, hui::Direction::none },};for (const auto & k : keys) {if (key == k.name) {@@ -616,6 +692,18 @@ int main(int, char **) {}scratch_warned = over;}+ if (dash.page() == Dashboard::kMarketPage && n % 10 == 0) {+ MarketView mv = market.snapshot();+ // A finished download joins the library.+ if (!mv.download_result.empty() && mv.download_result != last_download) {+ last_download = mv.download_result;+ if (mv.download_result.rfind("Saved", 0) == 0) {+ models.scan(stats);+ notify(("PS5LM: " + mv.download_result).c_str());+ }+ }+ dash.set_market(std::move(mv));+ }if (dash.page() == Dashboard::kLogsPage && n % 60 == 0) {dash.set_logs(tail_lines(kLog), tail_lines(kLlamaLog));}@@ -629,6 +717,18 @@ int main(int, char **) {models.scan(stats);std::printf("ps5lm-app: settings saved\n");}+ switch (req.kind) {+ case Dashboard::Request::market_search: market.search(req.path); break;+ case Dashboard::Request::market_open: market.open_repo(req.repo); break;+ case Dashboard::Request::market_plan: market.plan_file(req.repo, req.file); break;+ case Dashboard::Request::market_download: {+ std::error_code ec;+ std::filesystem::create_directories(models.settings.download_dir, ec);+ market.download(req.repo, req.file, models.settings.download_dir);+ break;+ }+ default: break;+ }if (req.kind == Dashboard::Request::clear_scratch) {std::error_code ec;for (const auto & e : std::filesystem::directory_iterator(kScratch, ec)) {@@ -644,6 +744,10 @@ int main(int, char **) {req = { Dashboard::Request::load, p };} else if (!take_request_file("/data/PS5LM/unload").empty()) {req = { Dashboard::Request::unload, "" };+ } else if (std::string u = take_request_file("/data/PS5LM/fetch"); !u.empty()) {+ std::thread(probe_fetch, u).detach();+ } else if (!take_request_file("/data/PS5LM/bench-write").empty()) {+ std::thread(probe_write).detach();}}if (req.kind == Dashboard::Request::unload || req.kind == Dashboard::Request::load) {diff --git a/ps5/app/market.cpp b/ps5/app/market.cppnew file mode 100644index 0000000..3660573--- /dev/null+++ b/ps5/app/market.cpp@@ -0,0 +1,265 @@+// SPDX-License-Identifier: GPL-3.0-or-later+#include "market.hpp"++#include "fetch.hpp"+#include "model_plan.hpp"++#include <nlohmann/json.hpp>++extern "C" {+#include "hash/sha256/sha256.h"+}++#include <cstdio>+#include <unistd.h>++namespace ps5lm {++namespace {++constexpr const char * kHub = "https://huggingface.co";++std::string url_encode(const std::string & s) {+ std::string out;+ char hex[4];+ for (unsigned char c : s) {+ if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {+ out += (char) c;+ } else {+ std::snprintf(hex, sizeof(hex), "%%%02X", c);+ out += hex;+ }+ }+ return out;+}++// A whole response as a string, or empty with `error` set.+std::string get_text(const std::string & url, const std::string & range, std::string * error, size_t limit = 64u << 20) {+ std::string body;+ const FetchResult r = https_get(url, range, [&](const char * p, size_t n) {+ body.append(p, n);+ return body.size() < limit;+ });+ if (r.status < 200 || r.status >= 300) {+ char text[160];+ std::snprintf(text, sizeof(text), "HTTP %d%s%s", r.status, r.error.empty() ? "" : ": ", r.error.c_str());+ *error = text;+ return {};+ }+ return body;+}++} // namespace++void Market::start(double budget_gib) {+ budget_gib_ = budget_gib;+}++MarketView Market::snapshot() {+ std::lock_guard<std::mutex> lock(mutex_);+ MarketView v = view_;+ v.busy = browsing_;+ return v;+}++void Market::run(std::atomic<bool> & flag, std::function<void()> job) {+ if (flag.exchange(true)) {+ return; // one at a time; the screen shows it is busy+ }+ std::thread([&flag, job = std::move(job)] {+ job();+ flag = false;+ }).detach();+}++void Market::search(const std::string & query) {+ {+ std::lock_guard<std::mutex> lock(mutex_);+ view_.query = query;+ view_.status = "Searching";+ }+ run(browsing_, [this, query] {+ std::string error;+ const std::string body = get_text(std::string(kHub) + "/api/models?filter=gguf&sort=downloads&direction=-1&limit=30" ++ (query.empty() ? "" : "&search=" + url_encode(query)),+ "", &error);+ const nlohmann::json j = nlohmann::json::parse(body, nullptr, false);+ std::vector<MarketRepo> repos;+ if (j.is_array()) {+ for (const auto & m : j) {+ MarketRepo r;+ r.id = m.value("id", std::string());+ r.downloads = m.value("downloads", (uint64_t) 0);+ if (!r.id.empty()) {+ repos.push_back(r);+ }+ }+ }+ std::lock_guard<std::mutex> lock(mutex_);+ if (view_.query != query) {+ return; // a newer search replaced this one+ }+ view_.repos = repos;+ view_.open = -1;+ view_.status = !error.empty() ? error : repos.empty() ? "Nothing found" : "";+ });+}++void Market::open_repo(int index) {+ std::string id;+ {+ std::lock_guard<std::mutex> lock(mutex_);+ if (index < 0 || index >= (int) view_.repos.size()) {+ return;+ }+ id = view_.repos[(size_t) index].id;+ view_.open = index;+ view_.status = "Listing files";+ }+ run(browsing_, [this, index, id] {+ std::string error;+ const std::string body = get_text(std::string(kHub) + "/api/models/" + id + "/tree/main", "", &error);+ const nlohmann::json j = nlohmann::json::parse(body, nullptr, false);+ std::vector<MarketFile> files;+ if (j.is_array()) {+ for (const auto & e : j) {+ const std::string path = e.value("path", std::string());+ const bool gguf = path.size() > 5 && path.compare(path.size() - 5, 5, ".gguf") == 0;+ // Projectors and later parts of split models are not models of their own.+ if (!gguf || path.find("mmproj") != std::string::npos ||+ (path.find("-of-") != std::string::npos && path.find("-00001-of-") == std::string::npos)) {+ continue;+ }+ MarketFile f;+ f.name = path;+ f.bytes = e.value("size", (uint64_t) 0);+ if (e.contains("lfs") && e["lfs"].is_object()) {+ f.sha256 = e["lfs"].value("oid", std::string());+ f.bytes = e["lfs"].value("size", f.bytes);+ }+ // Before the header is read: fits if the weights and the+ // planner's smallest reserve do.+ f.fits = f.bytes / 1073741824.0 + 1.0 <= budget_gib_ ? -1 : 0;+ if (f.fits == 0) {+ f.plan = "too big: the weights alone need more than is free";+ }+ files.push_back(f);+ }+ }+ std::lock_guard<std::mutex> lock(mutex_);+ if (view_.open == index && index < (int) view_.repos.size()) {+ view_.repos[(size_t) index].files = files;+ }+ view_.status = !error.empty() ? error : files.empty() ? "No GGUF files in this repository" : "";+ });+}++void Market::plan_file(int repo, int file) {+ std::string id, name;+ uint64_t bytes = 0;+ {+ std::lock_guard<std::mutex> lock(mutex_);+ if (repo < 0 || repo >= (int) view_.repos.size() || file < 0 ||+ file >= (int) view_.repos[(size_t) repo].files.size()) {+ return;+ }+ const MarketFile & f = view_.repos[(size_t) repo].files[(size_t) file];+ if (f.fits != -1) {+ return; // planned already, or too big by its size alone+ }+ id = view_.repos[(size_t) repo].id;+ name = f.name;+ bytes = f.bytes;+ }+ run(browsing_, [this, repo, file, id, name, bytes] {+ std::string error;+ const std::string head = get_text(std::string(kHub) + "/" + id + "/resolve/main/" + name, "bytes=0-16777215", &error,+ 16u << 20);+ const ModelInfo m = read_model_header(name, head, bytes);+ const Plan p = plan_model(m, budget_gib_);+ std::lock_guard<std::mutex> lock(mutex_);+ if (repo < (int) view_.repos.size() && file < (int) view_.repos[(size_t) repo].files.size()) {+ MarketFile & f = view_.repos[(size_t) repo].files[(size_t) file];+ f.fits = m.ok ? (p.fits ? 1 : 0) : -2;+ f.plan = m.ok ? p.why : (!error.empty() ? error : m.error);+ }+ });+}++void Market::download(int repo, int file, const std::string & dir) {+ std::string id, name, sha;+ uint64_t bytes = 0;+ {+ std::lock_guard<std::mutex> lock(mutex_);+ if (repo < 0 || repo >= (int) view_.repos.size() || file < 0 ||+ file >= (int) view_.repos[(size_t) repo].files.size()) {+ return;+ }+ const MarketFile & f = view_.repos[(size_t) repo].files[(size_t) file];+ id = view_.repos[(size_t) repo].id;+ name = f.name;+ sha = f.sha256;+ bytes = f.bytes;+ if (downloading_) {+ return;+ }+ view_.download_file = name;+ view_.download_progress = 0;+ view_.download_result.clear();+ }+ run(downloading_, [this, id, name, sha, bytes, dir] {+ const size_t slash = name.find_last_of('/');+ const std::string to = dir + "/" + name.substr(slash == std::string::npos ? 0 : slash + 1);+ const std::string part = to + ".part";+ FILE * out = std::fopen(part.c_str(), "wb");+ sha256_t h;+ sha256_init(&h);+ uint64_t done = 0;+ const auto t0 = std::chrono::steady_clock::now();+ const FetchResult r = https_get(std::string(kHub) + "/" + id + "/resolve/main/" + name, "", [&](const char * p, size_t n) {+ if (!out || std::fwrite(p, 1, n, out) != n) {+ return false;+ }+ sha256_update(&h, (const unsigned char *) p, n);+ done += n;+ const double s = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();+ std::lock_guard<std::mutex> lock(mutex_);+ view_.download_progress = bytes ? (float) ((double) done / (double) bytes) : 0.0f;+ view_.download_mbps = s > 0 ? done / 1e6 / s : 0;+ return true;+ });+ bool ok = out && std::fflush(out) == 0 && fsync(fileno(out)) == 0;+ if (out) {+ std::fclose(out);+ }+ unsigned char digest[32];+ sha256_final(&h, digest);+ char hex[65];+ for (int i = 0; i < 32; ++i) {+ std::snprintf(hex + 2 * i, 3, "%02x", digest[i]);+ }+ std::string result;+ if (!ok || r.status != 200 || done != bytes) {+ char text[160];+ std::snprintf(text, sizeof(text), "Failed: HTTP %d, %llu of %llu bytes%s%s", r.status,+ (unsigned long long) done, (unsigned long long) bytes, r.error.empty() ? "" : ", ",+ r.error.c_str());+ result = text;+ } else if (!sha.empty() && sha != hex) {+ result = "Failed: the checksum does not match";+ } else if (std::rename(part.c_str(), to.c_str()) != 0) {+ result = "Failed: could not rename the file";+ } else {+ result = "Saved to " + to;+ }+ if (result.rfind("Saved", 0) != 0) {+ unlink(part.c_str());+ }+ std::printf("ps5lm-app: download %s/%s: %s\n", id.c_str(), name.c_str(), result.c_str());+ std::lock_guard<std::mutex> lock(mutex_);+ view_.download_progress = -1;+ view_.download_result = result;+ });+}++} // namespace ps5lmdiff --git a/ps5/app/market.hpp b/ps5/app/market.hppnew file mode 100644index 0000000..021083e--- /dev/null+++ b/ps5/app/market.hpp@@ -0,0 +1,66 @@+// The model market: search Hugging Face for GGUF models, show which files+// fit this console, and download one into the models folder. Network work+// runs on its own thread; the screen reads a snapshot.+//+// SPDX-License-Identifier: GPL-3.0-or-later+#pragma once++#include <atomic>+#include <cstdint>+#include <functional>+#include <mutex>+#include <string>+#include <thread>+#include <vector>++namespace ps5lm {++struct MarketFile {+ std::string name; // "Qwen3.8-27B-UD-Q2_K_XL.gguf"+ std::string sha256; // from the repository's LFS pointer+ uint64_t bytes = 0;+ std::string plan; // the planner's line, once its header was read+ int fits = -1; // 1 fits, 0 too big, -1 not planned yet+};++struct MarketRepo {+ std::string id; // "unsloth/Qwen3.8-27B-GGUF"+ uint64_t downloads = 0;+ std::vector<MarketFile> files; // filled when the repository is opened+};++struct MarketView {+ std::string query;+ bool busy = false; // a search, listing or plan is running+ std::string status; // the last error or note, for the screen+ std::vector<MarketRepo> repos;+ int open = -1; // the repository whose files are listed+ // The download in progress, or the last one.+ std::string download_file;+ float download_progress = -1; // 0..1 while it runs+ double download_mbps = 0;+ std::string download_result; // "Saved to …" or the error+};++class Market {+ public:+ // budget_gib: GPU memory free before any model, for the fit column.+ void start(double budget_gib);+ MarketView snapshot();++ void search(const std::string & query);+ void open_repo(int index);+ void plan_file(int repo, int file); // reads its header (16 MiB range request)+ void download(int repo, int file, const std::string & dir);++ private:+ // One browse job (search, listing, plan) and one download at a time.+ void run(std::atomic<bool> & flag, std::function<void()> job);+ std::mutex mutex_;+ MarketView view_;+ double budget_gib_ = 0;+ std::atomic<bool> browsing_{ false };+ std::atomic<bool> downloading_{ false };+};++} // namespace ps5lmdiff --git a/ps5/app/model_plan.cpp b/ps5/app/model_plan.cppindex 37c21f5..b58aab6 100644--- a/ps5/app/model_plan.cpp+++ b/ps5/app/model_plan.cpp@@ -19,13 +19,26 @@ constexpr double kGiB = 1073741824.0;// GGUF metadata value types.enum : uint32_t { U8, I8, U16, I16, U32, I32, F32, BOOL, STRING, ARRAY, U64, I64, F64 };+// A GGUF header from a file, or from memory (the start of a remote file);+// the PS5's libc has no fmemopen.struct Reader {- FILE * f;- bool bad = false;+ FILE * f = nullptr;+ const char * mem = nullptr;+ size_t size = 0, pos = 0;+ bool bad = false;+ size_t read(void * out, size_t n) {+ if (f) {+ return std::fread(out, 1, n, f);+ }+ const size_t k = pos + n <= size ? n : 0;+ std::memcpy(out, mem + pos, k);+ pos += k;+ return k;+ }template <typename T> T get() {T v{};- if (std::fread(&v, sizeof(v), 1, f) != 1) {+ if (read(&v, sizeof(v)) != sizeof(v)) {bad = true;}return v;@@ -37,15 +50,16 @@ struct Reader {return {};}std::string s(n, '\0');- if (n && std::fread(s.data(), 1, n, f) != n) {+ if (n && read(s.data(), n) != n) {bad = true;}return s;}void skip(uint64_t n) {- if (std::fseek(f, (long) n, SEEK_CUR) != 0) {+ if (f ? std::fseek(f, (long) n, SEEK_CUR) != 0 : pos + n > size) {bad = true;}+ pos += f ? 0 : n;}};@@ -133,19 +147,21 @@ namespace {// Reads a GGUF header from `f` (and closes it). `file_bytes` is the whole// file's size when `f` holds only its start; 0 to measure `f`.-ModelInfo parse_model_info(FILE * f, const std::string & path, uint64_t file_bytes) {+ModelInfo parse_model_info(Reader r, const std::string & path, uint64_t file_bytes) {+ FILE * f = r.f;ModelInfo m;m.path = path;m.file_name = path.substr(path.find_last_of('/') + 1);m.name = m.file_name;- if (!f) {+ if (!f && !r.mem) {m.error = "cannot open";return m;}- Reader r{ f };if (r.get<uint32_t>() != 0x46554747u) { // "GGUF"- std::fclose(f);+ if (f) {+ std::fclose(f);+ }m.error = "not a GGUF file";return m;}@@ -180,9 +196,13 @@ ModelInfo parse_model_info(FILE * f, const std::string & path, uint64_t file_bytints[key] = read_int(r, t);}}- std::fseek(f, 0, SEEK_END);- m.file_bytes = file_bytes ? file_bytes : (uint64_t) std::ftell(f);- std::fclose(f);+ if (f) {+ std::fseek(f, 0, SEEK_END);+ }+ m.file_bytes = file_bytes ? file_bytes : f ? (uint64_t) std::ftell(f) : r.size;+ if (f) {+ std::fclose(f);+ }if (r.bad) {m.error = "metadata could not be read";return m;@@ -228,7 +248,9 @@ ModelInfo parse_model_info(FILE * f, const std::string & path, uint64_t file_byt} // namespaceModelInfo read_model_info(const std::string & path) {- ModelInfo m = parse_model_info(std::fopen(path.c_str(), "rb"), path, 0);+ Reader r;+ r.f = std::fopen(path.c_str(), "rb");+ ModelInfo m = parse_model_info(r, path, 0);m.mmproj = find_mmproj(path);if (!m.mmproj.empty()) {struct stat st = {};@@ -238,9 +260,10 @@ ModelInfo read_model_info(const std::string & path) {}ModelInfo read_model_header(const std::string & name, const std::string & head, uint64_t file_bytes) {- // fmemopen does not copy: `head` outlives the parse.- FILE * f = head.empty() ? nullptr : fmemopen(const_cast<char *>(head.data()), head.size(), "rb");- return parse_model_info(f, name, file_bytes);+ Reader r;+ r.mem = head.data();+ r.size = head.size();+ return parse_model_info(r, name, file_bytes);}double kv_bytes_per_token(const ModelInfo & m, const std::string & type) {diff --git a/ps5/app/preview_main.cpp b/ps5/app/preview_main.cppindex 095c3b8..a6f94d0 100644--- a/ps5/app/preview_main.cpp+++ b/ps5/app/preview_main.cpp@@ -193,6 +193,33 @@ int main(int argc, char ** argv) {app_log.push_back("ps5lm-app: accept failed, errno 53");app_log.push_back("W srv stop: cancel task, id_task = 22182");dash.set_logs(app_log, llama_log);+ ps5lm::MarketView mv;+ const char * ids[] = { "unsloth/Qwen3.8-27B-GGUF", "unsloth/gemma-4-E4B-it-GGUF", "bartowski/Llama-3.2-3B-Instruct-GGUF",+ "ggml-org/gpt-oss-20b-GGUF", "unsloth/Qwen3.5-9B-GGUF", "bartowski/Mistral-7B-Instruct-v0.3-GGUF" };+ for (int i = 0; i < 6; ++i) {+ ps5lm::MarketRepo r;+ r.id = ids[i];+ r.downloads = 812000 / (i + 1);+ mv.repos.push_back(r);+ }+ mv.open = 0;+ const char * fnames[] = { "Qwen3.8-27B-UD-IQ2_XXS.gguf", "Qwen3.8-27B-UD-Q2_K_XL.gguf", "Qwen3.8-27B-Q3_K_M.gguf", "Qwen3.8-27B-Q4_K_M.gguf" };+ const double fsz[] = { 6.8, 9.2, 12.6, 15.4 };+ const int ffits[] = { 1, 1, 0, 0 };+ const char * fplans[] = { "64k context, q8_0 cache: 9.9 of 11.0 GiB", "32k context, q4_0 cache: 10.8 of 11.0 GiB",+ "too big: the weights alone need more than is free", "too big: the weights alone need more than is free" };+ for (int i = 0; i < 4; ++i) {+ ps5lm::MarketFile f;+ f.name = fnames[i];+ f.bytes = (uint64_t) (fsz[i] * 1073741824.0);+ f.fits = ffits[i];+ f.plan = fplans[i];+ mv.repos[0].files.push_back(f);+ }+ mv.download_file = "Qwen3.8-27B-UD-IQ2_XXS.gguf";+ mv.download_progress = 0.37f;+ mv.download_mbps = 14.2;+ dash.set_market(mv);std::vector<unsigned char> pixels((size_t) W * H * 4);stbi_flip_vertically_on_write(1);hui::ui::Feedback feedback;@@ -292,5 +319,10 @@ int main(int argc, char ** argv) {shot("09-logs");step(30, press(hui::Action::north), false);shot("10-logs-errors");+ step(40, press(hui::Action::page_next), false);+ shot("11-market");+ step(30, press(hui::Action::confirm), false);+ step(20, nav(hui::Direction::down), false);+ shot("12-market-files");return ok ? 0 : 1;}diff --git a/ps5/app/settings.cpp b/ps5/app/settings.cppindex 8bdfe81..f03ac36 100644--- a/ps5/app/settings.cpp+++ b/ps5/app/settings.cpp@@ -24,6 +24,7 @@ Settings load_settings(const char * path) {s.sounds = j.value("sounds", s.sounds);s.tools = j.value("tools", s.tools);s.scratch_limit_gib = j.value("scratch_limit_gib", s.scratch_limit_gib);+ s.download_dir = j.value("download_dir", s.download_dir);return s;}@@ -31,7 +32,7 @@ bool save_settings(const char * path, const Settings & s) {const nlohmann::json j = {{ "auto_load", s.auto_load }, { "default_model", s.default_model }, { "ctx_cap", s.ctx_cap },{ "kv_type", s.kv_type }, { "sounds", s.sounds }, { "tools", s.tools },- { "scratch_limit_gib", s.scratch_limit_gib },+ { "scratch_limit_gib", s.scratch_limit_gib }, { "download_dir", s.download_dir },};std::ofstream out(path);out << j.dump(2) << "\n";diff --git a/ps5/app/settings.hpp b/ps5/app/settings.hppindex f66deb4..3f9d4dc 100644--- a/ps5/app/settings.hpp+++ b/ps5/app/settings.hpp@@ -18,6 +18,7 @@ struct Settings {bool sounds = true;bool tools = true; // file tools in the browser chat, inside the scratch folderuint32_t scratch_limit_gib = 2; // warn when the scratch folder grows past this+ std::string download_dir = "/data/PS5LM/models"; // where the market saves modelsbool operator==(const Settings &) const = default;};diff --git a/scripts/build-app.sh b/scripts/build-app.shindex 00419a1..22b683f 100755--- a/scripts/build-app.sh+++ b/scripts/build-app.sh@@ -87,6 +87,9 @@ cxx -std=c++20 -fexceptions -fcxx-exceptions -frtti -I "$headers/include" -I "$l-c "$root/ps5/app/main.cpp" -o "$obj/main.o"cxx -fexceptions -fcxx-exceptions -c "$root/ps5/app/model_plan.cpp" -o "$obj/model_plan.o"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"+"$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"# In an archive, so --exclude-libs keeps them local: a stub module defines some# of the same names, and lld would otherwise export ours to interpose them,@@ -176,7 +179,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/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/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[@]}" \diff --git a/scripts/ps5lm-app.sh b/scripts/ps5lm-app.shindex 4b0e453..3d92f4f 100755--- a/scripts/ps5lm-app.sh+++ b/scripts/ps5lm-app.sh@@ -9,6 +9,8 @@# scripts/ps5lm-app.sh load <model path> switch the model, as the library does# scripts/ps5lm-app.sh unload unload the model# scripts/ps5lm-app.sh press <button> press a button (up, down, cross, l1, r1, ...)+# scripts/ps5lm-app.sh fetch <url> probe: download over HTTPS (system TLS), see app.log+# scripts/ps5lm-app.sh bench-write probe: write speed by method, see app.log## The app is never killed: it polls /data/PS5LM/quit and leaves through# sceSystemServiceLoadExec("exit"), since killing a title that is rendering@@ -75,11 +77,13 @@ screenshot() {case ${1:-} inload) request load "${2:?model path on the console}" ;;unload) request unload ;;- press) request press "${2:?up|down|left|right|cross|circle|triangle|square|l1|r1}" ;;+ fetch) request fetch "${2:?https URL}" ;;+ bench-write) request bench-write ;;+ press) request press "${2:?up|down|left|right|cross|circle|triangle|square|l1|r1|l2|r2}" ;;screenshot) screenshot "${2:-}" ;;close) close ;;deploy) deploy ;;launch) launch ;;cycle) close; deploy; launch ;;- *) echo "usage: $0 close|deploy|launch|cycle|screenshot|load|unload|press" >&2; exit 2 ;;+ *) echo "usage: $0 close|deploy|launch|cycle|screenshot|load|unload|press|fetch|bench-write" >&2; exit 2 ;;esac