Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

Native fan control: lord-fand service with profiles, custom curves and full-speed override; Settings and Monitor Cooling pages with drawn hardware and live curve; Argon ONE V5 case option; reduce motion

Federico Pereira860173f6aaf0
diff --git a/apps/settings/Cooling.jsx b/apps/settings/Cooling.jsx
index 660500a..1e418bb 100644
--- a/apps/settings/Cooling.jsx
+++ b/apps/settings/Cooling.jsx
@@ -56,11 +56,12 @@ export function CoolingSettings() {
const caseId = useStore(fanCase);
const [err, setErr] = useState('');
const [caseMsg, setCaseMsg] = useState(null);
- const isAdmin = admin.available();
const variant = coolingVariant(s, caseId);
const run = (code) => setErr(code ? tr(`errors.${code}`) : '');
if (s === undefined) return <Stack><Note>{tr('cooling.loading')}</Note></Stack>;
+ // lord-fand says whether this user may change the fans (an administrator); the case is an admin action
+ const isAdmin = !!s?.canChange;
const controllable = !!s && s.fans.length > 0;
const custom = s?.custom?.length ? s.custom : PRESET_CURVE;
const shown = s?.profile === 'custom' ? custom : s?.curve || [];
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index db739e5..930e0ea 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -50,6 +50,7 @@ like React Native but on top of our display server.
| `server/src/print/`, `js_print.c`, `sdk/printdialog.jsx`, `apps/scanner` | **M9** | Printing: our own IPP client against CUPS, our own mDNS, eSCL scanners, the system print dialog (see `PRINTING.md`) |
| `server/src/media/`, `js_media.c`, `sdk/media.js`, `apps/{photos,player,screenshots,camera,recorder}` | **M9** | Media: the sandboxed helper `lord-media` (FFmpeg, libva) and the Photos, Player, Screenshots, Camera and Recorder apps; `media` node, audio over shared memory with the PipeWire stream in lord-server, protected windows in screenshots, recording and remote desktop (see `MEDIA.md`) |
| `server/src/netperm/`, `server/src/fw/`, `js_fw.c` | **M8** | Per-app firewall: the root service `lord-netperm` enforces the rules with cgroup BPF in the sessions; Rule column in the Monitor and Trusted / Restricted apps in Settings (see `FIREWALL.md`) |
+| `server/src/fan/`, `js_fan.c`, `sdk/cooling.jsx` | **M8** | Fans: the root service `lord-fand` drives them by temperature; Settings → Cooling and Monitor → Cooling (see `FANS.md`) |
| `server/src/monitor/`, `js_monitor.c`, `apps/monitor/` | **M8** | Monitor: CPU, memory, network, disks, processes and per-app connections with a map; its own thread only while the app is open, sock_diag and country by IP from a local database (see `MONITOR.md`) |
| `server/src/vault/`, `js_vault.c`, `sdk/vault.js`, `apps/passwords` | **M9** | Passwords and the system keyring: the sandboxed helper `lord-vault` (Monocypher: XChaCha20-Poly1305, Argon2id), own `.lvault` format, FIDO2/CTAP2 client, session keyring opened at login, Secret Service on D-Bus with own code (see `PASSWORDS.md`) |
| `server/src/net/netd.c`, `remote/netsup.c` | **M9** | `lord-netd`: the network belongs to the system. A root service started and supervised by `lord-sessiond` at boot, serving the `net-*` actions for every session (see `NETWORK.md`) |
@@ -109,6 +110,9 @@ Since M8 there are two programs, and since M9 two helpers:
- **`lord-netperm`** (root, `lord-netperm.service`): per-app network permissions. It attaches its
cgroup BPF programs to `lordos.service` and reads each user's rules. No network of its own and no
execution. See `FIREWALL.md`.
+- **`lord-fand`** (root, `lord-fand.service`): fans by temperature from the first boot (the
+ Raspberry Pi 5 fan header and motherboard PWM chips). No capabilities, no network, executes
+ nothing; sessions pick a profile over `/run/lordos/fand.sock`. See `FANS.md`.
- **`lord-doc`** (M9): the documents helper. `lord-server` launches it when needed, with a
fixed path (next to its binary) and no arguments. It runs as the user, without network and sandboxed
diff --git a/docs/FANS.md b/docs/FANS.md
new file mode 100644
index 0000000..5793a15
--- /dev/null
+++ b/docs/FANS.md
@@ -0,0 +1,276 @@
+# Fans and cooling
+
+LordOS drives the fans by temperature from the first boot, before anyone logs in, and keeps doing
+it if a session crashes. A small root service, `lord-fand`, reads the CPU temperature every two
+seconds and writes each fan's duty from a profile. **Settings → Cooling** picks the profile, edits a
+custom curve and runs the fans at full speed for a while; **Monitor → Cooling** shows the same
+hardware live, with the curve and a temperature/fan history.
+
+![Settings → Cooling on a Raspberry Pi 5 in the Argon ONE V5 case (fake sysfs, VM 116)](fans-settings.png)
+
+| Piece | Code |
+|---|---|
+| Root service | `server/src/fan/fand.c` (`lord-fand`), unit `tools/iso/rootfs/etc/systemd/system/lord-fand.service` |
+| Curves, presets, `fan.json`, socket requests | `server/src/fan/fancurve.c` (pure, tested) |
+| Temperature and fan discovery, duty writes, giving control back | `server/src/fan/fanhw.c` |
+| Session API `lord.fan` | `server/src/ui/js_fan.c` (registered from `js_hw.c`) |
+| Shared UI: status store, illustrations, curve chart | `sdk/cooling.jsx` |
+| Settings → Cooling | `apps/settings/Cooling.jsx` |
+| Monitor → Cooling | `apps/monitor/Cooling.jsx` |
+| Case accessories (Raspberry Pi 5) | admin action `rpi-case` in `server/src/hw/hw_admin.c` |
+| Tests | `server/tests/fan_test.c` (`build/fan-test`, in `tests/run_suites.sh`) |
+
+## What it drives
+
+`lord-fand` scans sysfs once at start (`fanhw_scan`). A client never names a path or a device: it
+only picks a profile, and the daemon drives every fan it found.
+
+| Kind | Found as | How it is driven |
+|---|---|---|
+| **Board** | hwmon `pwmfan` with `pwm1` + `pwm1_enable` (the Raspberry Pi 5 fan header: the official Active Cooler, or a case fan plugged there, such as the Argon ONE V5 case's blower) | `pwm1` written directly; see "The board fan and the kernel" |
+| **Motherboard** | hwmon with `pwmN` + `pwmN_enable` from an allow-listed Super I/O or fan controller driver: names starting with `nct6`, `nct7`, `it8`, `f71`, `f8000`, `w83`, `sch5`, `emc2`, `adt7`, `amc6821`, `max6650`, `max31790` | `pwmN_enable` = 1 (manual) while we drive it, the original value back afterwards |
+| **Firmware** | any other hwmon with `fanN_input` (laptop embedded controllers, GPUs, unknown drivers) | never written; listed as "managed by the firmware" with their RPM |
+
+Temperature source, first match: a thermal zone of type `cpu-thermal`, `x86_pkg_temp` or
+`cpu_thermal`; then hwmon `k10temp`, `coretemp`, `zenpower` or `cpu_thermal` (`temp1_input`);
+then `thermal_zone0`. Without a readable temperature the fans run at 100 %.
+
+`lord-fand --detect` prints what it found. On the Raspberry Pi 5 used for testing:
+
+```
+board: Raspberry Pi 5
+temperature: cpu-thermal (/sys/class/thermal/thermal_zone0/temp) 50.1 C
+fan 0: board pwmfan pwm1 at 29 %, 2499 rpm (/sys/class/hwmon/hwmon2)
+kernel trip 1: 50000 mC (/sys/class/thermal/thermal_zone0)
+kernel trip 2: 60000 mC (/sys/class/thermal/thermal_zone0)
+kernel trip 3: 67500 mC (/sys/class/thermal/thermal_zone0)
+kernel trip 4: 75000 mC (/sys/class/thermal/thermal_zone0)
+```
+
+### PC support status
+
+- **Desktop motherboards** with `nct67xx`/`nct6687` (the `nct6775`/`nct6683` drivers) or ITE
+ `it87xx` (`it87`, often out of tree) chips expose `pwmN` + `pwmN_enable`; mode 1 is manual on all
+ of them. The driver must be loaded (some boards need `acpi_enforce_resources=lax` for `nct6775`);
+ LordOS does not load modules or change kernel parameters. Covered by the fake-sysfs test only:
+ **not tried on a real motherboard yet.**
+- Some headers drive a pump or are wired in DC mode; LordOS drives all allow-listed channels with
+ the same curve. That is why a PC starts with the **System** profile (the motherboard firmware
+ keeps control) and LordOS only takes over when the user picks a profile. The Raspberry Pi starts
+ with **Balanced**.
+- **Laptops** usually have no writable PWM (the embedded controller owns the fan), or a vendor
+ driver with its own semantics: they show "Fans managed by the firmware" with the RPM, and are
+ never written.
+- **GPU** fans (`amdgpu`, `nouveau`, `radeon`) belong to their driver and are never written.
+
+## Profiles
+
+A curve is a list of steps "from T °C, P %". Below the first step the fan is off (or at the
+profile's floor). A step is entered when the temperature reaches it and left only when it falls
+`hyst` °C (3 by default) below it, so the fan does not flap around a threshold (`fan_curve_step`).
+
+| Profile | Steps | Floor |
+|---|---|---|
+| System (`auto`) | none: the kernel or the firmware decides | — |
+| Quiet | 60 °C → 30 %, 67 °C → 60 %, 72 °C → 100 % | off |
+| **Balanced** (default on boards) | 55 °C → 30 %, 60 °C → 55 %, 65 °C → 100 % | off |
+| Performance | 45 °C → 40 %, 55 °C → 70 %, 60 °C → 100 % | off |
+| Always on | 55 °C → 60 %, 65 °C → 100 % | 40 % |
+| Custom | 1 to 8 points, 30–90 °C strictly rising, 0–100 % never falling | off |
+
+What reaches the hardware is never between 1 % and 24 % (raised to 25 %: small fans stall below
+that), and a stopped fan given less than 50 % first gets one tick at 100 % so it starts.
+
+**Full speed** ("Heavy work"): 30 minutes, 1 hour, 2 hours or until turned off. It is stored with
+its end time, survives a restart of the service, and the profile comes back by itself.
+
+## The board fan and the kernel
+
+On a Raspberry Pi 5 the kernel already drives the fan header: the device tree binds the `pwm-fan`
+cooling device to four active trip points of `cpu-thermal` (50, 60, 67.5 and 75 °C, cooling levels
+0/75/125/175/250). Two ways to run our curve were possible:
+
+1. **Rewrite the kernel's trip points** to match the curve. It survives a crash by itself, but the
+ duty of each level is fixed by the device tree (only 5 levels, not our percentages), and the
+ number of steps is fixed too.
+2. **Write `pwm1` directly** and keep the kernel out of the way.
+
+LordOS does (2), with the kernel as a **backstop**: while `lord-fand` drives the fan it moves the
+four active trips to 78, 80, 82 and 84 °C (the critical 110 °C trip is never touched). Below that
+the kernel's `step_wise` governor leaves `pwm1` alone; if `lord-fand` ever hangs and the board gets
+hot, the kernel still spins the fan up by itself (the firmware throttles at 85 °C). Each tick the
+daemon reads `pwm1` back and rewrites it if it differs, so a kernel step in between (seen for a few
+seconds after a large change, while the governor's state settles) is corrected within 2 s.
+`user_space` would be the cleaner governor, but the Raspberry Pi kernel only offers `step_wise`.
+
+**Giving control back** (`fanhw_release`): the original trip temperatures are written back and
+the cooling device's `cur_state` is set to the level the kernel would pick for the current
+temperature, so there is no gap. This happens:
+
+- on `SIGTERM`/`SIGINT` (stop, shutdown, package removal);
+- in `lord-fand --restore`, the unit's `ExecStopPost`, which also runs after `SIGKILL` or a crash.
+ Before taking a fan the daemon writes what it is about to change to `/run/lordos/fand.restore`
+ (`trip <index> <m°C>`, `enable <channel> <value> <device path>`); `--restore` rescans, applies only
+ values that match a fan the scan found (range-checked) and deletes the file;
+- at start, if that file exists (a previous run died): restore first, then scan, so the raised
+ trips are never mistaken for the originals.
+
+A motherboard channel gets its original `pwmN_enable` (usually 2 or 5, the chip's automatic mode).
+
+## Configuration and protocol
+
+`/etc/lordos/fan.json` is written only by `lord-fand` (temporary file, `fsync`, `rename`), and read
+only if it is a root-owned regular file nobody else can write. Strict reader (`sec/json.c`):
+unknown keys, wrong types or an invalid curve make it fall back to the defaults.
+
+```json
+{"version":1,"profile":"balanced","hyst":3,"custom":[[55,30],[60,55],[65,100]],"force":"off","forceUntil":0}
+```
+
+`/run/lordos/fand.sock` (0666), one line per connection, at most 255 bytes, printable ASCII:
+
+| Request | Who | Answer |
+|---|---|---|
+| `STATUS` | anyone | one JSON line: `temp`, `tempSource`, `board`, `profile`, `curve`, `custom`, `floor`, `hyst`, `step`, `target`, `force`, `forceLeft`, `fans` (`id`, `kind`, `chip`, `ch`, `pct`, `rpm`), `firmwareFans`, `canChange` |
+| `PROFILE auto\|quiet\|balanced\|performance\|always\|custom` | administrators | `OK` or `ERR <code>` |
+| `CURVE 55:30,60:55,65:100` | administrators | sets the custom curve and selects it |
+| `FORCE off\|on\|<1..1440 minutes>` | administrators | full speed |
+
+Administrators: `SO_PEERCRED` uid 0, or a user in `sudo`, `admin` or `wheel` (the same rule as the
+admin helper). Errors are codes (`fan.notAdmin`, `fan.badRequest`, `fan.saveFailed`); the UI
+translates them. A client that does not finish its line in one second is dropped; at most eight at
+a time.
+
+On the session side `lord.fan` (`js_fan.c`) validates everything again before sending, never waits
+more than 300 ms for an answer, and `sdk/cooling.jsx` only polls (every 2 s) while a Cooling view
+is on screen.
+
+## The service
+
+`lord-fand.service` starts early (`sysinit.target`, before `lordos.service`), `Restart=always`,
+and is enabled by the package's `postinst` (also in the ISO and Raspberry Pi image chroots). It is
+hardened like `lord-netperm.service`, and more:
+
+- no capabilities at all (`CapabilityBoundingSet=` empty: root owns the sysfs files it writes);
+- `RestrictAddressFamilies=AF_UNIX`, `PrivateNetwork=yes`, `IPAddressDeny=any`;
+- `ProtectSystem=strict` with only `/etc/lordos`, `/run/lordos`, `/sys/devices/platform`,
+ `/sys/devices/virtual/thermal` and `/sys/devices/pci0000:00` writable; `ProtectHome=yes`,
+ `PrivateDevices=yes` (it uses no device node);
+- `SystemCallFilter=@system-service` minus `@privileged @resources @mount @clock @debug @module
+ @reboot @swap @raw-io`, `MemoryDenyWriteExecute`, `NoNewPrivileges`.
+
+It executes nothing and links only libc. Cost: one sysfs read and at most one write every 2 s; 0.0 %
+CPU and 1.5 MB RSS on the Raspberry Pi 5.
+
+`--root DIR`, `--config FILE` and `--run DIR` exist for tests (a fake sysfs tree, a temporary
+config and socket); the unit never passes them.
+
+## Settings → Cooling and Monitor → Cooling
+
+- At the top, our own drawing of the detected hardware (views only, no product photos or
+ renders): the Argon ONE V5 case (aluminium body, fins, the blower, front ports), a Raspberry Pi 5
+ with a heatsink and fan, a PC tower with a CPU cooler and case fans, or a passive heatsink when no
+ fan can be driven. Light and dark variants (`docs/polish/fans-*.png`).
+- The fan turns at a speed proportional to the real duty (eased; still at 0 %), and the fins warm
+ from blue (40 °C) through amber (65 °C) to orange-red (80 °C). The rotors are turned with
+ `lord.setStyle` on their nodes at 20 frames per second, with no React render per frame; the timer
+ stops at 0 %, while the window is minimized and with **Appearance → Reduce motion** (a new
+ setting, `reduceMotion`). Frames: `docs/polish/fans-anim-1.png` … `-5.png`.
+- The curve chart (`FanCurveChart`) shows the steps, the hysteresis band of each step (orange,
+ stronger for the active one) and the live point (temperature, duty). In the custom profile the
+ points can be dragged (temperature between their neighbours, duty in 5 % steps, never below the
+ previous point); Add step / Remove step / Reset.
+- Monitor shows the curve next to a three-minute temperature/fan history (Monitor's own chart), the
+ profile, the step, every fan, and a **Full speed for 30 min** button (same `lord.fan.force`).
+- Controls are enabled when `lord-fand` says the user may change them (`canChange`).
+
+Measured on VM 116, headless `lord-server` with Monitor → Cooling open and the fan at 55 %, 30 s
+with nobody watching: **2.4 % CPU** with the animation, **1.9 %** with Reduce motion (the
+difference, about 0.5 % of one core, is the spinning fan). A first version that re-rendered React
+on every frame cost 8.9 %.
+
+![Monitor → Cooling](fans-monitor.png)
+
+## Argon ONE V5 case
+
+What the case is, from its printed manual (instruction manual AR1 V5, 2025-01-03) and a reading of
+the vendor's install script `argon1v5.sh` and the scripts it downloads (`argononed.py`,
+`argonregister.py`, `argonregister-v1.py`, `argonpowerbutton-libgpiod.py`, `argonone-irconfig.sh`,
+`argon-blstrdac.sh`, `argon-rpi-eeprom-config-psu.py`, `argon-shutdown.sh`). They were downloaded
+into a scratch folder and read; **none of them was executed**.
+
+- **Fan:** a 30 mm PWM blower plugged into the **Raspberry Pi 5 fan header** (manual, assembly
+ step 4: "Connect the blower FAN cable … to the exposed Raspberry Pi 5 FAN Port"; features table:
+ "actively controlled by the Raspberry Pi OS"). So it is the `pwmfan` board fan above, driven by
+ `lord-fand` like the Active Cooler. Measured on the user's case: 0 RPM stopped, about 2 700 RPM at
+ 30 %, 4 500–4 700 at 55 %, 6 700–7 400 at 100 %.
+- **No microcontroller, no HAT EEPROM.** On the user's Raspberry Pi 5 in this case there is no
+ `/proc/device-tree/hat`, and with I2C bus 1 enabled at runtime (`dtparam i2c_arm=on`, removed
+ afterwards) `i2cdetect -y 1` shows **no device at all**, and reads of 0x1a fail.
+- **The older Argon ONE protocol** (for reference; it is what the scripts still contain, for the
+ cases with a microcontroller): I2C bus 1, address 0x1a. New firmware: register 0x80 = fan duty
+ 0–100, 0x81 = firmware version, 0x82 = IR code block, 0x86 = control (1 = cut the power after
+ shutdown). Old firmware: a single byte written to 0x1a is the duty, 0xFF = power off. Their daemon
+ probes "register support" by **writing** 0x80 and reading it back, uses 30 s delays before slowing
+ down, raises any duty below 25 % to 25 %, kicks the fan at 100 % first, and its default curve is
+ 55 °C → 30 %, 60 °C → 55 %, 65 °C → 100 % (our Balanced). The power button reaches the board as
+ pulses on GPIO 4 (20–30 ms = reboot, 40–50 ms = shut down), read with libgpiod, and the IR receiver
+ uses `dtoverlay=gpio-ir,gpio_pin=23` with LIRC. LordOS implements none of this because the V5 has
+ none of it, and blindly writing to address 0x1a could hit an audio codec on another board.
+- **Its board's extras:** an HDMI-USB2-audio board adds two front USB 2.0 ports (an FE1.1s hub) and
+ a microphone and headphone DAC (HS100B, USB audio). Both sit on the Raspberry Pi 5's USB-C
+ controller, which has to run as a **host**: `dtoverlay=dwc2,dr_mode=host` (manual: "Enabling the
+ USB ports and mic in and audio out ports"). The script also adds `usb_max_current_enable=1`,
+ `dtparam=nvme`/`pciex1_gen=3`, and `PSU_MAX_CURRENT=5000` in the bootloader EEPROM.
+
+**Detection.** The case cannot be detected from software: it has no EEPROM, no I2C device, and its
+USB hub and DAC only appear after the USB-C controller is switched to host mode, and even then they
+are generic chips used by other products. So LordOS does **not** guess. Settings → Cooling on a
+Raspberry Pi 5 shows **Case: None or another case / Argon ONE V5 case**; choosing the Argon runs
+the admin action `rpi-case argon-one-v5`, which writes `/boot/firmware/lordos-case.txt` (fixed
+text, included at the end of `config.txt` by the image) and takes effect after a restart. Any other
+case gets nothing Argon-specific. The illustration shows the Argon only after it is chosen.
+
+| The vendor script | LordOS |
+|---|---|
+| Fan daemon (Python, I2C or GPIO) | `lord-fand` (C, root, hardened); the V5's fan is on the fan header |
+| Fan curve config `/etc/argononed.conf` | Settings → Cooling, `/etc/lordos/fan.json` |
+| `dtoverlay=dwc2,dr_mode=host` (front USB, audio) | `rpi-case argon-one-v5` → `lordos-case.txt` |
+| `dtparam=nvme`, `pciex1_gen=3` | already in the LordOS image's `config.txt` |
+| `usb_max_current_enable=1` | **not set**: it lets the board draw 1.6 A for USB, which is only safe with a 5 A supply; documented here instead |
+| `PSU_MAX_CURRENT=5000` in the bootloader EEPROM | **not done**: LordOS does not rewrite the EEPROM (later, if ever, as a separate admin action) |
+| Power button daemon (GPIO 4 pulses) | not needed on the V5: the Raspberry Pi 5's own power button is handled by systemd-logind (Settings → Energy) |
+| IR remote (LIRC, `gpio-ir` on GPIO 23) | not on the V5 (not in its feature list); left for a case that has it |
+| OLED module, ZigBee module (optional add-ons) | not supported |
+| Shutdown hook (`FANOFF`, power cut) | not needed: the fan header loses power with the board |
+
+## Tests
+
+- `build/fan-test` (`make test`, `tests/run_suites.sh`), 4 183 checks: curve steps and hysteresis
+ (thresholds, jumps, oscillation, clamping), presets, output clamping, `fan.json` (valid files,
+ round trip, 37 broken files, 4 000 random mutations and truncations), socket requests (28
+ refused lines), and the sysfs driver on fake trees: a Raspberry Pi 5 (trips raised and restored,
+ the kick, read-back correction, RPM, crash restore file), a PC (`nct6798` taken and given back,
+ the `amdgpu` fan never touched, a tampered restore file ignored) and a passive machine.
+ `build/fan-test mkfake DIR pi5|pc|none` builds a tree for manual runs and screenshots.
+- On the Raspberry Pi 5 in the Argon ONE V5 case (as root from the build folder, temporary config
+ and socket under `/run/lordos-test`): detection; Balanced kept the fan off at 50–53 °C during a
+ 4-thread `yes` load (the aluminium case is a large heatsink); test curves drove it to 55 % (4 500
+ RPM) and full speed (7 400 RPM); `FORCE 30` and `FORCE off`; `PROFILE turbo` and garbage refused;
+ `SIGTERM` and `kill -9` + `--restore` gave the trips back (50/60/67.5/75 °C, kernel state 1 at
+ 51 °C). The same binary under the unit's full hardening (`systemd-run` with the unit's
+ properties): trips raised, `CURVE` applied and saved, and after killing only the main process
+ `ExecStopPost` restored everything.
+- On VM 116: `make -C server test` passes; headless `lord-server` with a fake-sysfs `lord-fand`
+ for every variant, dark and light; the custom profile selected and a point dragged with the
+ pointer (the daemon logged `CURVE 55:30,60:55,72:85`).
+
+## Not done or untested
+
+- The installed `.deb` and the unit on the real Raspberry Pi (tested with the unit's properties
+ through `systemd-run`, not as the packaged `lord-fand.service`).
+- Real PC motherboards (`nct67xx`, `it87`) and laptops: fake sysfs only.
+- The `rpi-case` action on the real board (it writes the boot partition; not run on the user's
+ card) and the case's front USB ports and DAC with `dwc2` in host mode.
+- Several board fans with different curves (all fans follow one profile).
+- Temperature from disks (the vendor daemon also had an HDD curve).
diff --git a/docs/SETTINGS.md b/docs/SETTINGS.md
index 3a7b8d7..ec78816 100644
--- a/docs/SETTINGS.md
+++ b/docs/SETTINGS.md
@@ -1,4 +1,4 @@
-# Settings: Displays, Bluetooth, Energy, Notifications, Date & Time, Default Apps
+# Settings: Displays, Bluetooth, Energy, Cooling, Notifications, Date & Time, Default Apps
Six Settings pages laid out like the system settings of popular desktop systems, with the hardware side in
`server/src/hw/` (C, libc only) and the session side in `sdk/hardware.jsx`, `sdk/defaults.js` and
@@ -20,6 +20,7 @@ pairing, Sound with a Bluetooth headset, a Linux app's notification and Files' "
| Date & Time | with Language & Region | `apps/settings/DateTime.jsx`, `hw/hw.c` (timedated) |
| Default Apps | with Keyboard and Trackpad | `apps/settings/DefaultApps.jsx`, `sdk/defaults.js`, `hw/defaults.c`, `hw/mimeapps.c` |
| Energy (Battery) | with Privacy | `apps/settings/Power.jsx`, `hw/power.c`, `hw/ppd.c` |
+| Cooling | after Energy | `apps/settings/Cooling.jsx`, `sdk/cooling.jsx`, `ui/js_fan.c` → `lord-fand` (`server/src/fan/`); see `FANS.md` |
Shared pieces: `apps/settings/ui.jsx` (a row with a hint, a pop-up button, the page header) on top of
the SDK's `GroupBox` (`docs/DESIGN.md`). All text goes through `t()` in the `prefs` namespace
@@ -43,7 +44,9 @@ the time fields keep `direction: 'ltr'`.
│
▼ root work: closed admin actions (hw/hw_admin.c)
admin.c ─ display-brightness, power-profile, power-suspend, power-buttons, time-ntp, time-set,
- bt-unblock
+ bt-unblock, rpi-case
+
+ Cooling: lord.fan (ui/js_fan.c) ── /run/lordos/fand.sock ── lord-fand (root service, src/fan)
```
Nothing polls. Hotplugged displays, batteries and chargers arrive as kernel uevents (one
@@ -209,6 +212,20 @@ with real hardware** (no controller in the VMs).
`systemctl reload systemd-logind`. LordOS never grabs the ACPI power button (only keyboards, mice
and tablets are grabbed), so logind sees it. Lid rows only show with a battery.
+## Cooling
+
+![Cooling](fans-settings.png)
+
+Fans by temperature, from the first boot, by the root service `lord-fand` (all the details in
+`FANS.md`). The page draws the detected hardware (the fan turns with the real duty and the fins warm
+with the temperature), the profile (System, Quiet, Balanced, Performance, Always on, Custom), the
+curve with its hysteresis bands and the live point (the custom curve's points are dragged on it),
+**Heavy work** (full speed for 30 min, 1 h, 2 h or until turned off) and, on a Raspberry Pi 5, the
+**Case** (`rpi-case`). Without controllable fans it says so ("No controllable fans", or "Fans
+managed by the firmware" with their RPM). Only administrators change anything: `lord-fand` checks
+the peer and reports `canChange`. Monitor has the same view read-only, with a history and a
+"Full speed for 30 min" button.
+
## Notifications
![Notifications](ajustes-notificaciones-oscuro.png)
@@ -284,6 +301,7 @@ All in `server/src/hw/hw_admin.c`, in the `actions` table through `HW_ADMIN_ACTI
| `time-ntp` | `on` \| `off` | admin | `/usr/bin/timedatectl set-ntp` |
| `time-set` | `YYYY-MM-DD HH:MM:SS` | admin | `/usr/bin/timedatectl set-time` |
| `bt-unblock` | — | anyone | rfkill "unblock all Bluetooth" on `/dev/rfkill` |
+| `rpi-case` | `none` \| `argon-one-v5` | admin | Raspberry Pi 5 only: writes `/boot/firmware/lordos-case.txt` (fixed text, included from `config.txt`; see `FANS.md`) |
The validators are unit-tested in `build/settings-hw-test`.
@@ -294,6 +312,8 @@ The validators are unit-tested in `build/settings-hw-test`.
sunset in London, Buenos Aires, Tokyo and Svalbard, schedule across midnight, zone1970.tab),
mimeapps.list editing and globs2, the power_supply reader, the admin validators. 129 checks.
- `build/bt-test` (`make test`): BlueZ parsing. 32 checks.
+- `build/fan-test` (`make test`): curves, hysteresis, `fan.json`, the socket requests and the fan
+ driver on fake sysfs trees (see `FANS.md`).
- On VM 118: live mode changes with revert and keep, persistence across a session restart,
rotation, software Night Light, Bluetooth with `btvirt`, power profiles with
power-profiles-daemon (placeholder driver), the logind drop-in, NTP and manual time, Linux
diff --git a/docs/fans-monitor.png b/docs/fans-monitor.png
new file mode 100644
index 0000000..69ab67f
Binary files /dev/null and b/docs/fans-monitor.png differ
diff --git a/docs/fans-settings.png b/docs/fans-settings.png
new file mode 100644
index 0000000..078d9e7
Binary files /dev/null and b/docs/fans-settings.png differ
diff --git a/docs/polish/fans-anim-1.png b/docs/polish/fans-anim-1.png
new file mode 100644
index 0000000..c255c98
Binary files /dev/null and b/docs/polish/fans-anim-1.png differ
diff --git a/docs/polish/fans-anim-2.png b/docs/polish/fans-anim-2.png
new file mode 100644
index 0000000..c255c98
Binary files /dev/null and b/docs/polish/fans-anim-2.png differ
diff --git a/docs/polish/fans-anim-3.png b/docs/polish/fans-anim-3.png
new file mode 100644
index 0000000..63bd25c
Binary files /dev/null and b/docs/polish/fans-anim-3.png differ
diff --git a/docs/polish/fans-anim-4.png b/docs/polish/fans-anim-4.png
new file mode 100644
index 0000000..63bd25c
Binary files /dev/null and b/docs/polish/fans-anim-4.png differ
diff --git a/docs/polish/fans-anim-5.png b/docs/polish/fans-anim-5.png
new file mode 100644
index 0000000..c976761
Binary files /dev/null and b/docs/polish/fans-anim-5.png differ
diff --git a/docs/polish/fans-argon-dark.png b/docs/polish/fans-argon-dark.png
new file mode 100644
index 0000000..078d9e7
Binary files /dev/null and b/docs/polish/fans-argon-dark.png differ
diff --git a/docs/polish/fans-argon-light.png b/docs/polish/fans-argon-light.png
new file mode 100644
index 0000000..9664f54
Binary files /dev/null and b/docs/polish/fans-argon-light.png differ
diff --git a/docs/polish/fans-cooler-dark.png b/docs/polish/fans-cooler-dark.png
new file mode 100644
index 0000000..82c32a2
Binary files /dev/null and b/docs/polish/fans-cooler-dark.png differ
diff --git a/docs/polish/fans-cooler-light.png b/docs/polish/fans-cooler-light.png
new file mode 100644
index 0000000..f1743d4
Binary files /dev/null and b/docs/polish/fans-cooler-light.png differ
diff --git a/docs/polish/fans-none-dark.png b/docs/polish/fans-none-dark.png
new file mode 100644
index 0000000..6b0f3c9
Binary files /dev/null and b/docs/polish/fans-none-dark.png differ
diff --git a/docs/polish/fans-none-light.png b/docs/polish/fans-none-light.png
new file mode 100644
index 0000000..0fa6960
Binary files /dev/null and b/docs/polish/fans-none-light.png differ
diff --git a/docs/polish/fans-pc-dark.png b/docs/polish/fans-pc-dark.png
new file mode 100644
index 0000000..4469fe4
Binary files /dev/null and b/docs/polish/fans-pc-dark.png differ
diff --git a/docs/polish/fans-pc-light.png b/docs/polish/fans-pc-light.png
new file mode 100644
index 0000000..e24fe7c
Binary files /dev/null and b/docs/polish/fans-pc-light.png differ
diff --git a/sdk/cooling.jsx b/sdk/cooling.jsx
index e36ab2f..fd849fb 100644
--- a/sdk/cooling.jsx
+++ b/sdk/cooling.jsx
@@ -83,37 +83,45 @@ export function heatColor(temp, alpha = 1) {
// ---- the spinning fan ----
-// Rotation that follows the duty: up to 1.5 turns per second at 100 %, eased; stops (no timer) at
-// 0 %, while the window is minimized and with Reduce motion.
+// Rotation that follows the duty: up to 1.2 turns per second at 100 %, eased; stops (no timer) at
+// 0 %, while the window is minimized and with Reduce motion. The rotors are turned with
+// lord.setStyle on their nodes (no React render per frame): lord-server repaints a cached raster.
function useSpin(pct) {
const { id } = useAppWindow() || {};
const hidden = useStore(windows, (ws) => !!ws.find((w) => w.id === id)?.minimized);
- const effects = useStore(settings, (s) => !s.reduceMotion);
- const [angle, setAngle] = useState(0);
- const st = useRef({ v: 0, a: 0 });
- const target = effects && !hidden ? Math.max(0, Math.min(100, pct || 0)) / 100 * 1.5 : 0;
+ const motion = useStore(settings, (s) => !s.reduceMotion);
+ const st = useRef(null);
+ if (!st.current) st.current = { v: 0, a: 0, rotors: new Map() };
+ const s = st.current;
+ const target = motion && !hidden ? Math.max(0, Math.min(100, pct || 0)) / 100 * 1.2 : 0;
useEffect(() => {
- const s = st.current;
- if (!effects || hidden || (target === 0 && s.v < 0.01)) { s.v = target; return undefined; }
+ if (!motion || hidden || (target === 0 && s.v < 0.01)) { s.v = target; return undefined; }
const FPS = 20;
let tm = null;
const step = () => {
s.v += (target - s.v) * 0.12;
if (target === 0 && s.v < 0.01) { s.v = 0; return; }
s.a = (s.a + s.v * 360 / FPS) % 360;
- setAngle(s.a);
+ for (const [node, k] of s.rotors) call(() => lord.setStyle(node, 'transform', `rotate(${(s.a * k).toFixed(1)}deg)`));
tm = setTimeout(step, 1000 / FPS);
};
tm = setTimeout(step, 1000 / FPS);
return () => clearTimeout(tm);
- }, [target, effects, hidden]);
- return angle;
+ }, [target, motion, hidden]);
+ return s;
}
-function Fan({ size, pct, frame, blade, hub, angle }) {
+function Fan({ size, frame, blade, hub, spin, k = 1 }) {
const b = Math.round(size * 0.42), bh = Math.round(size * 0.2);
+ const rotor = useRef(null);
+ useEffect(() => {
+ const n = rotor.current?.id;
+ if (!spin || n == null) return undefined;
+ spin.rotors.set(n, k);
+ return () => spin.rotors.delete(n);
+ }, [spin, k]);
return h(View, { style: { width: size, height: size, borderRadius: size / 2, backgroundColor: frame, alignItems: 'center', justifyContent: 'center' } },
- h(View, { style: { position: 'absolute', left: 0, top: 0, width: size, height: size, transform: `rotate(${angle}deg)` } },
+ h(View, { ref: rotor, style: { position: 'absolute', left: 0, top: 0, width: size, height: size, transform: `rotate(${((spin?.a || 0) * k).toFixed(1)}deg)` } },
[0, 1, 2, 3, 4].map((i) => h(View, { key: i, style: { position: 'absolute', left: 0, top: 0, width: size, height: size, transform: `rotate(${i * 72}deg)` } },
h(View, { style: { position: 'absolute', left: size / 2 - 1, top: size / 2 - bh, width: b, height: bh, borderTopRightRadius: bh, borderBottomRightRadius: bh / 3,
borderTopLeftRadius: 2, backgroundColor: blade } })))),
@@ -141,7 +149,7 @@ function palette(dark) {
blade: '#eef1f5', hub: '#ffffff', tower: 'linear-gradient(170deg, #50545c, #33363c)', glass: 'rgba(150,180,220,0.18)' };
}
-function ArgonArt({ p, pct, temp, angle, W, H }) {
+function ArgonArt({ p, pct, temp, spin, W, H }) {
const cw = Math.round(W * 0.78), ch = Math.round(H * 0.6), x = (W - cw) / 2, y = Math.round(H * 0.16);
const glow = heatColor(temp, 0.55);
return h(View, { style: { position: 'absolute', left: x, top: y, width: cw, height: ch } },
@@ -155,7 +163,7 @@ function ArgonArt({ p, pct, temp, angle, W, H }) {
// round blower window with the fan
h(View, { style: { position: 'absolute', right: 22, top: (ch - ch * 0.62) / 2 - 4, width: ch * 0.62, height: ch * 0.62, borderRadius: ch * 0.31,
backgroundColor: p.slot, alignItems: 'center', justifyContent: 'center', border: `2px solid ${p.aluEdge}` } },
- h(Fan, { size: ch * 0.54, pct, frame: p.slot, blade: p.blade, hub: p.hub, angle })),
+ h(Fan, { size: ch * 0.54, frame: p.slot, blade: p.blade, hub: p.hub, spin })),
// front edge: two USB, the audio jacks and a light
h(View, { style: { position: 'absolute', left: 18, bottom: 9, flexDirection: 'row', alignItems: 'center', gap: 7 } },
h(View, { style: { width: 18, height: 7, borderRadius: 1.5, backgroundColor: p.slot, border: `1px solid ${p.port}` } }),
@@ -165,7 +173,7 @@ function ArgonArt({ p, pct, temp, angle, W, H }) {
h(View, { style: { width: 4, height: 4, borderRadius: 2, marginLeft: 6, backgroundColor: pct > 0 ? '#30d158' : p.port } }))));
}
-function CoolerArt({ p, pct, temp, angle, W, H }) {
+function CoolerArt({ p, temp, spin, W, H }) {
const bw = Math.round(W * 0.66), bh = Math.round(H * 0.68), x = (W - bw) / 2, y = Math.round(H * 0.14);
const glow = heatColor(temp, 0.6);
const hs = Math.round(bh * 0.66);
@@ -185,31 +193,31 @@ function CoolerArt({ p, pct, temp, angle, W, H }) {
h(View, { style: { position: 'absolute', left: 6, right: 6, top: 6, bottom: 6, flexDirection: 'row', justifyContent: 'space-between' } },
h(Fins, { n: 9, w: 3, len: hs - 12, span: hs * 1.25 - 12, color: p.fin, glow, vertical: true })),
h(View, { style: { width: hs * 0.8, height: hs * 0.8, borderRadius: hs * 0.4, backgroundColor: p.frame, alignItems: 'center', justifyContent: 'center', border: `2px solid ${p.aluEdge}` } },
- h(Fan, { size: hs * 0.72, pct, frame: p.frame, blade: p.blade, hub: p.hub, angle })))));
+ h(Fan, { size: hs * 0.72, frame: p.frame, blade: p.blade, hub: p.hub, spin })))));
}
-function PcArt({ p, pct, temp, angle, W, H }) {
- const tw = Math.round(H * 0.82), th = Math.round(H * 0.82), x = (W - tw) / 2, y = Math.round(H * 0.08);
+function PcArt({ p, temp, spin, W, H }) {
+ const tw = Math.round(H * 1.08), th = Math.round(H * 0.84), x = (W - tw) / 2, y = Math.round(H * 0.08);
const glow = heatColor(temp, 0.6);
return h(View, { style: { position: 'absolute', left: x, top: y, width: tw, height: th } },
h(View, { style: { position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, borderRadius: 12, background: p.tower, boxShadow: `0 10px 24px ${p.shadow}`, border: `1px solid ${p.aluEdge}` } },
// glass side panel with the board inside
h(View, { style: { position: 'absolute', left: 10, right: 10, top: 10, bottom: 10, borderRadius: 8, backgroundColor: p.glass, border: `1px solid rgba(255,255,255,0.12)` } },
- h(View, { style: { position: 'absolute', left: 14, top: 12, width: tw * 0.52, height: th * 0.62, borderRadius: 4, background: 'linear-gradient(160deg, #2b3340, #1b2029)' } },
+ h(View, { style: { position: 'absolute', left: 12, top: 12, width: tw * 0.5, height: th * 0.66, borderRadius: 4, background: 'linear-gradient(160deg, #2b3340, #1b2029)' } },
// CPU tower cooler
- h(View, { style: { position: 'absolute', left: tw * 0.08, top: th * 0.08, width: tw * 0.3, height: th * 0.3, borderRadius: 4, background: p.alu, alignItems: 'center', justifyContent: 'center' } },
+ h(View, { style: { position: 'absolute', left: tw * 0.06, top: th * 0.08, width: tw * 0.26, height: tw * 0.26, borderRadius: 4, background: p.alu, alignItems: 'center', justifyContent: 'center' } },
h(View, { style: { position: 'absolute', left: 4, right: 4, top: 4, bottom: 4, flexDirection: 'row', justifyContent: 'space-between' } },
- h(Fins, { n: 7, w: 2, len: th * 0.3 - 8, span: tw * 0.3 - 8, color: p.fin, glow, vertical: true })),
- h(Fan, { size: tw * 0.24, pct, frame: p.frame, blade: p.blade, hub: p.hub, angle })),
+ h(Fins, { n: 7, w: 2, len: tw * 0.26 - 8, span: tw * 0.26 - 8, color: p.fin, glow, vertical: true })),
+ h(Fan, { size: tw * 0.21, frame: p.frame, blade: p.blade, hub: p.hub, spin })),
// memory and a card
- h(View, { style: { position: 'absolute', left: tw * 0.41, top: th * 0.08, width: 5, height: th * 0.3, borderRadius: 1, backgroundColor: '#5e6878' } }),
- h(View, { style: { position: 'absolute', left: tw * 0.43, top: th * 0.08, width: 5, height: th * 0.3, borderRadius: 1, backgroundColor: '#5e6878' } }),
- h(View, { style: { position: 'absolute', left: tw * 0.06, top: th * 0.46, width: tw * 0.4, height: 9, borderRadius: 2, backgroundColor: '#3c4554' } })),
+ h(View, { style: { position: 'absolute', left: tw * 0.35, top: th * 0.08, width: 5, height: th * 0.3, borderRadius: 1, backgroundColor: '#5e6878' } }),
+ h(View, { style: { position: 'absolute', left: tw * 0.38, top: th * 0.08, width: 5, height: th * 0.3, borderRadius: 1, backgroundColor: '#5e6878' } }),
+ h(View, { style: { position: 'absolute', left: tw * 0.06, top: th * 0.5, width: tw * 0.36, height: 9, borderRadius: 2, backgroundColor: '#3c4554' } })),
// rear and front case fans
- h(View, { style: { position: 'absolute', right: 10, top: 14, width: tw * 0.24, height: tw * 0.24, borderRadius: 4, backgroundColor: p.frame, alignItems: 'center', justifyContent: 'center' } },
- h(Fan, { size: tw * 0.22, pct, frame: p.frame, blade: p.blade, hub: p.hub, angle: -angle })),
- h(View, { style: { position: 'absolute', right: 10, bottom: 14, width: tw * 0.24, height: tw * 0.24, borderRadius: 4, backgroundColor: p.frame, alignItems: 'center', justifyContent: 'center' } },
- h(Fan, { size: tw * 0.22, pct, frame: p.frame, blade: p.blade, hub: p.hub, angle: angle * 0.9 })))));
+ h(View, { style: { position: 'absolute', right: 12, top: 12, width: tw * 0.26, height: tw * 0.26, borderRadius: 6, backgroundColor: p.frame, alignItems: 'center', justifyContent: 'center' } },
+ h(Fan, { size: tw * 0.24, frame: p.frame, blade: p.blade, hub: p.hub, spin, k: -1 })),
+ h(View, { style: { position: 'absolute', right: 12, bottom: 12, width: tw * 0.26, height: tw * 0.26, borderRadius: 6, backgroundColor: p.frame, alignItems: 'center', justifyContent: 'center' } },
+ h(Fan, { size: tw * 0.24, frame: p.frame, blade: p.blade, hub: p.hub, spin, k: 0.9 })))));
}
function PassiveArt({ p, temp, W, H }) {
@@ -229,9 +237,9 @@ function PassiveArt({ p, temp, W, H }) {
export function CoolingArt({ variant, pct = 0, temp = null, width = 320, height = 168 }) {
const th = useTheme();
const p = palette(th.mode === 'dark');
- const angle = useSpin(variant === 'none' ? 0 : pct);
+ const spin = useSpin(variant === 'none' ? 0 : pct);
const W = width, H = height;
- const props = { p, pct, temp, angle, W, H };
+ const props = { p, pct, temp, spin, W, H };
const Art = variant === 'argon' ? ArgonArt : variant === 'cooler' ? CoolerArt : variant === 'pc' ? PcArt : PassiveArt;
return h(View, { style: { width: W, height: H, borderRadius: 14, background: p.stage, overflow: 'hidden', direction: 'ltr' } },
h(View, { style: { position: 'absolute', left: W * 0.15, right: W * 0.15, top: H * 0.1, bottom: H * 0.1, borderRadius: H, backgroundColor: heatColor(temp, th.mode === 'dark' ? 0.08 : 0.1) } }),
diff --git a/server/src/fan/fand.c b/server/src/fan/fand.c
index 36da431..517911a 100644
--- a/server/src/fan/fand.c
+++ b/server/src/fan/fand.c
@@ -5,7 +5,8 @@
* - reads the CPU temperature every FAND_TICK_MS and writes each fan's duty (fan/fanhw.c);
* - its configuration is /etc/lordos/fan.json, written only here, after validating;
* - talks to sessions over /run/lordos/fand.sock (0666) with one line per connection:
- * STATUS anyone: a JSON line with temperature, fans, profile and step
+ * STATUS anyone: a JSON line with temperature, fans, profile, step and
+ * whether this peer may change them ("canChange")
* PROFILE <name> / CURVE <t:p,...> / FORCE off|on|<minutes>
* administrators only (SO_PEERCRED: root, or a member of
* sudo, admin or wheel): "OK" or "ERR <code>"
@@ -139,10 +140,10 @@ static void tick(void) {
/* ---- status ---- */
-static size_t status_json(char *o, size_t n) {
+static size_t status_json(char *o, size_t n, int can_change) {
size_t k = 0;
#define PUT(...) do { if (k < n) { int r_ = snprintf(o + k, n - k, __VA_ARGS__); if (r_ > 0) k += (size_t)r_; } } while (0)
- PUT("{\"ok\":true,\"board\":\"%s\",\"tempSource\":\"%s\",", S.hw.board ? "pi5" : "", S.hw.temp_src);
+ PUT("{\"ok\":true,\"canChange\":%s,\"board\":\"%s\",\"tempSource\":\"%s\",", can_change ? "true" : "false", S.hw.board ? "pi5" : "", S.hw.temp_src);
if (S.temp > -1000000) PUT("\"temp\":%d.%d,", S.temp / 1000, (S.temp < 0 ? -S.temp : S.temp) % 1000 / 100);
else PUT("\"temp\":null,");
PUT("\"profile\":\"%s\",\"hyst\":%d,\"controlling\":%s,\"step\":%d,\"target\":%d,",
@@ -204,7 +205,7 @@ static void handle(Client *c) {
if (fan_req_parse(c->buf, (size_t)(nl - c->buf), &r)) { reply(c->fd, "ERR fan.badRequest\n", 19); return; }
if (r.type == FR_STATUS) {
char o[FAND_STATUS_MAX];
- size_t n = status_json(o, sizeof o);
+ size_t n = status_json(o, sizeof o, peer_is_admin(c->fd));
reply(c->fd, o, n);
return;
}
diff --git a/server/tests/settings_hw_test.c b/server/tests/settings_hw_test.c
index 0a290ff..05b039e 100644
--- a/server/tests/settings_hw_test.c
+++ b/server/tests/settings_hw_test.c
@@ -357,6 +357,10 @@ static void test_admin(void) {
CHECK(!hw_time_valid("2026-10-18 03:15:0;") && !hw_time_valid("") && !hw_time_valid(NULL));
CHECK(hw_button_action_valid("suspend", 1) && hw_button_action_valid("poweroff", 0) && hw_button_action_valid("ignore", 1));
CHECK(!hw_button_action_valid("lock", 1) && !hw_button_action_valid("kexec", 0) && !hw_button_action_valid("suspend\n", 0));
+ /* rpi-case: only the known cases, fixed text with the host-mode USB line for the Argon ONE V5 */
+ CHECK(hw_rpi_case_text("none") && !strstr(hw_rpi_case_text("none"), "dtoverlay"));
+ CHECK(hw_rpi_case_text("argon-one-v5") && strstr(hw_rpi_case_text("argon-one-v5"), "\n[pi5]\ndtoverlay=dwc2,dr_mode=host\n[all]\n"));
+ CHECK(!hw_rpi_case_text("") && !hw_rpi_case_text("argon") && !hw_rpi_case_text("none ") && !hw_rpi_case_text("../x"));
CHECK(hw_backlight_name_valid("intel_backlight") && hw_backlight_name_valid("amdgpu_bl1") && hw_backlight_name_valid("acpi_video0"));
CHECK(!hw_backlight_name_valid("../x") && !hw_backlight_name_valid(".x") && !hw_backlight_name_valid("a/b") && !hw_backlight_name_valid(""));
}
diff --git a/tools/iso/build.sh b/tools/iso/build.sh
index 3af9901..14f9478 100755
--- a/tools/iso/build.sh
+++ b/tools/iso/build.sh
@@ -137,6 +137,7 @@ in_ch systemctl --global enable pipewire.socket pipewire-pulse.socket wireplumbe
# LordOS on tty1 instead of the text login; the other consoles remain (Ctrl+Alt+F2)
in_ch systemctl enable lordos.service > /dev/null
in_ch systemctl enable lord-netperm.service > /dev/null
+in_ch systemctl enable lord-fand.service > /dev/null # fans by temperature (docs/FANS.md)
in_ch systemctl mask [email protected] > /dev/null
# quiet and faster boot
in_ch systemctl mask systemd-networkd-wait-online.service > /dev/null 2>&1 || true
diff --git a/tools/iso/mkdeb.sh b/tools/iso/mkdeb.sh
index 0eeec51..403502b 100755
--- a/tools/iso/mkdeb.sh
+++ b/tools/iso/mkdeb.sh
@@ -6,6 +6,7 @@
# /usr/lib/lordos/bin/lord-sessiond sessions, login screen and remote desktop (root)
# /usr/lib/lordos/bin/lord-netperm per-app network permissions with cgroup BPF (root, own service)
# /usr/lib/lordos/bin/lord-netd system networking (root; launched and watched by lord-sessiond)
+# /usr/lib/lordos/bin/lord-fand fan control by temperature (root, own service, enabled)
# /usr/lib/lordos/bin/lord-server each session's server (looks for ../themes and ../assets)
# /usr/lib/lordos/themes/<theme>/ theme.json, theme.bundle.js and their resources (greeter: the
# login screen)
@@ -20,6 +21,7 @@ VERSION=$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' package.json | head -1)
[ -x server/build/lord-server ] || { echo "missing server/build/lord-server (make -C server)" >&2; exit 1; }
[ -x server/build/lord-netperm ] || { echo "missing server/build/lord-netperm (make -C server; clang for BPF)" >&2; exit 1; }
[ -x server/build/lord-netd ] || { echo "missing server/build/lord-netd (make -C server)" >&2; exit 1; }
+[ -x server/build/lord-fand ] || { echo "missing server/build/lord-fand (make -C server)" >&2; exit 1; }
[ -x server/build/lord-sessiond ] || { echo "missing server/build/lord-sessiond (make -C server, with libssl-dev)" >&2; exit 1; }
[ -f themes/greeter/theme.bundle.js ] || { echo "missing the login screen (npm run build)" >&2; exit 1; }
for t in themes/*/theme.bundle.js; do [ -f "$t" ] || { echo "built themes missing (npm run build)" >&2; exit 1; }; done
@@ -32,10 +34,11 @@ install -m 755 server/build/lord-server "$L/bin/lord-server"
install -m 755 server/build/lord-sessiond "$L/bin/lord-sessiond"
install -m 755 server/build/lord-netd "$L/bin/lord-netd"
install -m 755 server/build/lord-netperm "$L/bin/lord-netperm"
+install -m 755 server/build/lord-fand "$L/bin/lord-fand"
# isolated PDF and archive helper (optional: make skips it without libpoppler-glib-dev/libarchive-dev);
# lord-server only launches the lord-doc in its own folder
[ -x server/build/lord-doc ] && install -m 755 server/build/lord-doc "$L/bin/lord-doc"
-strip --strip-unneeded "$L/bin/lord-server" "$L/bin/lord-sessiond" "$L/bin/lord-netd" "$L/bin/lord-netperm" 2>/dev/null || true
+strip --strip-unneeded "$L/bin/lord-server" "$L/bin/lord-sessiond" "$L/bin/lord-netd" "$L/bin/lord-netperm" "$L/bin/lord-fand" 2>/dev/null || true
[ -x "$L/bin/lord-doc" ] && { strip --strip-unneeded "$L/bin/lord-doc" 2>/dev/null || true; }
# lord-server only launches the lord-media in its own folder (media: video, photos, camera, recorder)
[ -x server/build/lord-media ] && install -m 755 server/build/lord-media "$L/bin/lord-media"
@@ -70,6 +73,8 @@ install -d "$PKG/usr/share/themes"
cp -r assets/gtk/LordOS assets/gtk/LordOS-dark "$PKG/usr/share/themes/"
find "$PKG/usr/share/themes" -type d -exec chmod 755 {} +; find "$PKG/usr/share/themes" -type f -exec chmod 644 {} +
install -m 644 tools/iso/rootfs/etc/systemd/system/lord-netperm.service "$PKG/usr/lib/systemd/system/lord-netperm.service"
+# fans by temperature from the first boot (docs/FANS.md): enabled by postinst, also in a chroot
+install -m 644 tools/iso/rootfs/etc/systemd/system/lord-fand.service "$PKG/usr/lib/systemd/system/lord-fand.service"
find "$L" -type d -exec chmod 755 {} +
find "$L/themes" "$L/assets" -type f -exec chmod 644 {} +
@@ -136,15 +141,28 @@ Description: desktop environment with its own display server
lordos.service service (lord-sessiond) that starts it on tty1. Remote desktop
(browser, port 5673) ships turned off.
C
-# lordos.service is enabled by hand (the ISO does it; on an installed system the user decides)
+# lordos.service is enabled by hand (the ISO does it; on an installed system the user decides).
+# lord-fand.service is always enabled (and started on a running system): fans need no choice.
cat > "$PKG/DEBIAN/postinst" <<'C'
#!/bin/sh
set -e
if [ "$1" = configure ] && command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload >/dev/null 2>&1 || true
+ systemctl enable lord-fand.service >/dev/null 2>&1 || true
+ if [ -d /run/systemd/system ]; then systemctl restart lord-fand.service >/dev/null 2>&1 || true; fi
fi
C
chmod 755 "$PKG/DEBIAN/postinst"
+# removing the package gives the fans back first (ExecStopPost restores the kernel's control)
+cat > "$PKG/DEBIAN/prerm" <<'C'
+#!/bin/sh
+set -e
+if [ "$1" = remove ] && command -v systemctl >/dev/null 2>&1; then
+ if [ -d /run/systemd/system ]; then systemctl stop lord-fand.service >/dev/null 2>&1 || true; fi
+ systemctl disable lord-fand.service >/dev/null 2>&1 || true
+fi
+C
+chmod 755 "$PKG/DEBIAN/prerm"
# files under /etc are conffiles (lintian: file-in-etc-not-marked-as-conffile)
( cd "$PKG" && find etc -type f | sed 's|^|/|' ) > "$PKG/DEBIAN/conffiles"
chmod 644 "$PKG/DEBIAN/conffiles"
diff --git a/tools/iso/rootfs/etc/systemd/system/lord-fand.service b/tools/iso/rootfs/etc/systemd/system/lord-fand.service
new file mode 100644
index 0000000..4073d62
--- /dev/null
+++ b/tools/iso/rootfs/etc/systemd/system/lord-fand.service
@@ -0,0 +1,54 @@
+[Unit]
+Description=LordOS: fan control by temperature (lord-fand)
+Documentation=file:///usr/share/doc/lordos/README.md
+# early: the fans follow the temperature before anyone logs in
+DefaultDependencies=no
+After=local-fs.target systemd-udevd.service
+Before=lordos.service shutdown.target
+Conflicts=shutdown.target
+
+[Service]
+Type=simple
+ExecStart=/usr/lib/lordos/bin/lord-fand
+# after a stop or a crash the fans go back to the kernel (trip points) or the firmware
+ExecStopPost=/usr/lib/lordos/bin/lord-fand --restore
+Restart=always
+RestartSec=1
+StandardOutput=journal
+StandardError=journal
+RuntimeDirectory=lordos
+RuntimeDirectoryPreserve=yes
+ConfigurationDirectory=lordos
+ConfigurationDirectoryMode=0755
+# root only for sysfs writes: no capabilities beyond reading other users' groups is needed
+CapabilityBoundingSet=
+AmbientCapabilities=
+NoNewPrivileges=yes
+RestrictAddressFamilies=AF_UNIX
+IPAddressDeny=any
+ProtectSystem=strict
+ReadWritePaths=/etc/lordos /run/lordos
+# the only sysfs files it writes: pwmN/pwmN_enable of fan controllers and the board fan, thermal
+# trip points and the fan's cooling state
+ReadWritePaths=-/sys/devices/platform -/sys/devices/virtual/thermal -/sys/devices/pci0000:00
+ProtectHome=yes
+ProtectControlGroups=yes
+ProtectKernelModules=yes
+ProtectKernelLogs=yes
+ProtectClock=yes
+ProtectHostname=yes
+PrivateTmp=yes
+PrivateDevices=yes
+PrivateNetwork=yes
+RestrictNamespaces=yes
+RestrictRealtime=yes
+RestrictSUIDSGID=yes
+LockPersonality=yes
+MemoryDenyWriteExecute=yes
+SystemCallArchitectures=native
+SystemCallFilter=@system-service
+SystemCallFilter=~@privileged @resources @mount @clock @debug @module @reboot @swap @raw-io
+UMask=0022
+
+[Install]
+WantedBy=sysinit.target
diff --git a/tools/rpi/build-img.sh b/tools/rpi/build-img.sh
index 1e03e08..7cc52ff 100755
--- a/tools/rpi/build-img.sh
+++ b/tools/rpi/build-img.sh
@@ -294,6 +294,7 @@ mkdir -p "$CH/var/lib/lordos/rpi"
: > "$CH/var/lib/lordos/rpi/resize-pending"
: > "$CH/var/lib/lordos/rpi/firstboot-pending"
in_root "$CH" systemctl enable lordos-rpi-firstboot.service lordos.service > /dev/null
+in_root "$CH" systemctl enable lord-fand.service > /dev/null # fans by temperature from the first boot (docs/FANS.md)
in_root "$CH" systemctl mask [email protected] > /dev/null
in_root "$CH" systemctl mask systemd-networkd-wait-online.service > /dev/null 2>&1 || true
# no root password: the emergency console stays locked (like the installed system)
@@ -320,6 +321,8 @@ place_kernel() { # version, kernel name on the FAT, initramfs name
place_kernel "$KV2712" kernel_2712.img initramfs_2712
place_kernel "$KV8" kernel8.img initramfs8
install -m 644 "$RPI/boot/firmware/config.txt" "$CH/boot/firmware/config.txt"
+# case accessories (Settings → Cooling, admin action rpi-case); config.txt includes it
+printf '# lordos-case.txt: written by LordOS (Settings, Cooling). No case accessories.\n' > "$CH/boot/firmware/lordos-case.txt"
install -m 644 "$RPI/boot/firmware/lordos-user.txt.example" "$CH/boot/firmware/lordos-user.txt.example"
rm -f "$CH/usr/sbin/policy-rc.d" "$CH/usr/bin/qemu-aarch64-static"
diff --git a/tools/rpi/rootfs/boot/firmware/config.txt b/tools/rpi/rootfs/boot/firmware/config.txt
index 48e64de..cde93f4 100644
--- a/tools/rpi/rootfs/boot/firmware/config.txt
+++ b/tools/rpi/rootfs/boot/firmware/config.txt
@@ -22,10 +22,13 @@ dtparam=audio=on
# there are PCIe errors in `dmesg`, comment out the gen 3 line.
dtparam=pciex1
dtparam=pciex1_gen=3
-# Active Cooler fan: driven by the kernel (cooling_fan in the device tree), nothing to set
+# Fan header (Active Cooler or a case fan): lord-fand drives it by temperature (docs/FANS.md);
+# without it the kernel does (cooling_fan in the device tree)
[pi4]
# Pi 4: best effort (see docs/RASPBERRY.md)
arm_boost=1
[all]
+# the case's extras, written by Settings → Cooling (admin action rpi-case, docs/FANS.md)
+include lordos-case.txt