Skip to content

Commit 3a22013

Browse files
committed
os: fix config.txt overload
1 parent 9bd61b3 commit 3a22013

6 files changed

Lines changed: 385 additions & 24 deletions

File tree

os/raspberry/config.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# START PlanktoScope firmware config
12
[all]
23
bootloader_update=0
34
disable_poe_fan=1
@@ -22,4 +23,5 @@ dtparam=sd_cqe=2
2223
# Enable SPI 2 - used for display
2324
dtoverlay=spi1-1cs,cs0_pin=4
2425

26+
# STOP PlanktoScope firmware config
2527
[all]

os/raspberry/firmware.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env node
2+
3+
import { readFile, writeFile, appendFile } from "node:fs/promises"
4+
import { join } from "node:path"
5+
import { fileURLToPath } from "node:url"
6+
7+
import { $ } from "execa"
8+
9+
async function remountReadWrite(path) {
10+
const { stdout } = await $`findmnt --json --target ${path}`
11+
const result = JSON.parse(stdout)
12+
const filesystem = result.filesystems[0]
13+
const read_only = filesystem.options.split(",").includes("ro")
14+
15+
if (read_only) {
16+
await $`mount -o remount,rw ${filesystem.target}`
17+
}
18+
return [read_only, filesystem]
19+
}
20+
21+
async function remountReadWriteOnce(path, fn) {
22+
const [was_read_only, filesystem] = await remountReadWrite(path)
23+
24+
try {
25+
await fn()
26+
} finally {
27+
if (was_read_only) {
28+
await $`mount -o remount,ro ${filesystem.target}`
29+
}
30+
}
31+
}
32+
33+
const path = "/boot/firmware/"
34+
35+
// Configure firmware
36+
// https://www.raspberrypi.com/documentation/computers/config_txt.html
37+
async function process_config() {
38+
const path_config = join(path, "config.txt")
39+
40+
const content = await readFile(path_config, "utf8")
41+
const include = await readFile(
42+
fileURLToPath(import.meta.resolve("./config.ini")),
43+
"utf8",
44+
)
45+
46+
if (!content.trim().includes(include.trim())) {
47+
await appendFile(path_config, include)
48+
}
49+
}
50+
51+
async function process_cmdline(path) {
52+
// Disable the 4 Raspberry logo in the top left corner
53+
// more space for kernel and system logs
54+
const content = await readFile(path, "utf8")
55+
const args = content.trim().split(" ")
56+
if (!args.includes("logo.nologo")) {
57+
args.push("logo.nologo")
58+
}
59+
await writeFile(path, args.join(" "))
60+
}
61+
62+
if (import.meta.main) {
63+
await remountReadWriteOnce(path, async () => {
64+
await process_config()
65+
66+
for (const cmdline of ["cmdline.txt", "cmdline-A.txt", "cmdline-B.txt"]) {
67+
try {
68+
await process_cmdline(join(path, "cmdline.txt"))
69+
} catch (err) {
70+
if (err.code !== "ENOENT") throw err
71+
}
72+
}
73+
})
74+
}

os/raspberry/firmware.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

os/raspberry/justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
setup:
2-
./firmware.sh
2+
npm install
3+
sudo NODE_DEBUG=execa ./firmware.js
34
./bootloader.sh
45

56
test:

0 commit comments

Comments
 (0)