summaryrefslogtreecommitdiff
path: root/piboot.c
diff options
context:
space:
mode:
Diffstat (limited to 'piboot.c')
-rw-r--r--piboot.c15
1 files 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 <errno.h>
#include <fcntl.h>
+#include <linux/fb.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/ioctl.h>
#include <unistd.h>
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;