From 611aa4a16e1fd8976dd853d1b2f2192a20b2c067 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 27 Jun 2025 16:17:16 +0200 Subject: get fbdev size --- piboot.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/piboot.c b/piboot.c index 0aa6326..8a36739 100644 --- a/piboot.c +++ b/piboot.c @@ -16,10 +16,12 @@ */ #include #include +#include #include #include #include #include +#include #include int main(int argc, char **argv) { @@ -28,11 +30,18 @@ int main(int argc, char **argv) { fbpath = argv[1]; int fd = open(fbpath, O_CLOEXEC | O_WRONLY); if (fd < 0) { - fprintf(stderr, "cannot open fb0: %s\n", strerror(errno)); + fprintf(stderr, "cannot open fbdev %s: %s\n", fbpath, strerror(errno)); return 1; } - int w = 1920, h = 1080; + struct fb_var_screeninfo sinfo; + int res = ioctl(fd, FBIOGET_VSCREENINFO, &sinfo); + if (res < 0) { + fprintf(stderr, "cannot get fbdev info: %s\n", strerror(errno)); + return 1; + } + + int w = sinfo.xres_virtual, h = sinfo.yres_virtual; int sidepad = (w - h) / 2; uint8_t *frame = malloc(w * h * 4); memset(frame, 0, w * h * 4); @@ -48,7 +57,7 @@ int main(int argc, char **argv) { frame[base + 2] = 255 - v; } - int res = write(fd, frame, w * h * 4); + res = write(fd, frame, w * h * 4); if (res < 0) { fprintf(stderr, "cannot write to fb0: %s\n", strerror(errno)); return 1; -- cgit v1.2.3-70-g09d2