From 0de1bfc5f4b79ed4cce3078e4abcfa3a47793a59 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 25 Jun 2025 15:39:21 +0200 Subject: initial commit --- piboot.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.txt | 10 ++++++++++ 2 files changed, 68 insertions(+) create mode 100644 piboot.c create mode 100644 readme.txt diff --git a/piboot.c b/piboot.c new file mode 100644 index 0000000..0aa6326 --- /dev/null +++ b/piboot.c @@ -0,0 +1,58 @@ +/* + piboot + Copyright 2025 metamuffin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, version 3 of the License only. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + char *fbpath = "/dev/fb0"; + if (argc >= 2) + fbpath = argv[1]; + int fd = open(fbpath, O_CLOEXEC | O_WRONLY); + if (fd < 0) { + fprintf(stderr, "cannot open fb0: %s\n", strerror(errno)); + return 1; + } + + int w = 1920, h = 1080; + int sidepad = (w - h) / 2; + uint8_t *frame = malloc(w * h * 4); + memset(frame, 0, w * h * 4); + + for (int y = 0; y < h; y++) + for (int x = 0; x < w; x++) { + if (x < sidepad || x >= h + sidepad) + continue; + int base = (x + y * w) * 4; + int u = (x - sidepad) * 256 / h, v = y * 256 / h; + frame[base + 0] = v; + frame[base + 1] = u; + frame[base + 2] = 255 - v; + } + + int res = write(fd, frame, w * h * 4); + if (res < 0) { + fprintf(stderr, "cannot write to fb0: %s\n", strerror(errno)); + return 1; + } + + return 0; +} diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..3616e29 --- /dev/null +++ b/readme.txt @@ -0,0 +1,10 @@ +piboot +====== + +Program that displays the test image that is typical for Raspberry Pi's boot via fbdev. + +Compilation: `gcc piboot.c` +Installation: `install -Dm755 a.out /usr/bin/piboot` +Usage: `piboot` or `piboot /dev/fbX` + +License: AGPL-3.0-only -- cgit v1.2.3-70-g09d2