Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 4409f7d

Browse files
authored
Added auto HDMI switching (#606)
1 parent 6df566a commit 4409f7d

File tree

6 files changed

+239
-0
lines changed

6 files changed

+239
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
Status: not-sent
2+
# This supposedly does not need to be sent upstream as there's fbutils,
3+
# although its development has stagnated.
4+
5+
---
6+
con2fbmap.1 | 29 ++++++++++++++++++++++++++
7+
con2fbmap.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8+
2 files changed, 95 insertions(+)
9+
10+
--- /dev/null
11+
+++ b/con2fbmap.1
12+
@@ -0,0 +1,29 @@
13+
+.TH con2fbmap 1 2006-01-18 2.1 "Linux frame buffer utils"
14+
+.SH NAME
15+
+con2fbmap \- shows and sets mapping between consoles and framebuffer devices.
16+
+.SH SYNOPSIS
17+
+.B con2fbmap
18+
+.RI console
19+
+.RI [ framebuffer ]
20+
+.SH DESCRIPTION
21+
+.B This documentation is not finished
22+
+.PP
23+
+.B con2fbmap
24+
+is a system utility to show or change the mapping of the consoles to the
25+
+frame buffer device. The frame buffer device provides a simple and unique
26+
+interface to access different kinds of graphic displays.
27+
+.PP
28+
+Frame buffer devices are accessed via special device nodes located in the
29+
+/dev directory. The naming scheme for these nodes is always
30+
+.IR \fBfb < n >,
31+
+where
32+
+.I n
33+
+is the number of the used frame buffer device.
34+
+.PP
35+
+.SH OPTIONS
36+
+The first option must be there, and identify the console on which to work.
37+
+If the second option is not set, con2fbmap shows the current mapping of
38+
+identified console. If the second argument is given (as a number) con2fbmap
39+
+maps the identified console to said framebuffer device.
40+
+.TP
41+
+Sven LUTHER <[email protected]>
42+
--- /dev/null
43+
+++ b/con2fbmap.c
44+
@@ -0,0 +1,66 @@
45+
+#include <stdio.h>
46+
+#include <stdlib.h>
47+
+#include <unistd.h>
48+
+#include <fcntl.h>
49+
+#include <errno.h>
50+
+#include <string.h>
51+
+#include <sys/ioctl.h>
52+
+#include <sys/types.h>
53+
+#include <sys/stat.h>
54+
+#include <linux/fb.h>
55+
+
56+
+#define DEFAULT_FRAMEBUFFER "/dev/fb0"
57+
+#define DEFAULT_FRAMEBUFFER_DEVFS "/dev/fb/0"
58+
+
59+
+const char *programname;
60+
+
61+
+void Usage(void)
62+
+{
63+
+ fprintf(stderr, "\nUsage: %s console [framebuffer]\n\n", programname);
64+
+ exit(1);
65+
+}
66+
+
67+
+int main(int argc, char *argv[])
68+
+{
69+
+ int do_write = 0;
70+
+ char *fbpath; /* any frame buffer will do */
71+
+ int fd;
72+
+ struct fb_con2fbmap map;
73+
+
74+
+ programname = argv[0];
75+
+ switch (argc) {
76+
+ case 3:
77+
+ do_write = 1;
78+
+ map.framebuffer = atoi(argv[2]);
79+
+ case 2:
80+
+ map.console = atoi(argv[1]);
81+
+ break;
82+
+ default:
83+
+ Usage();
84+
+ }
85+
+
86+
+ if (access("/dev/.devfsd", F_OK) == 0) /* devfs detected */
87+
+ fbpath = DEFAULT_FRAMEBUFFER_DEVFS;
88+
+ else
89+
+ fbpath = DEFAULT_FRAMEBUFFER;
90+
+
91+
+ if ((fd = open(fbpath, O_RDONLY)) == -1) {
92+
+ fprintf(stderr, "open %s: %s\n", fbpath, strerror(errno));
93+
+ exit(1);
94+
+ }
95+
+ if (do_write) {
96+
+ if (ioctl(fd, FBIOPUT_CON2FBMAP, &map)) {
97+
+ fprintf(stderr, "ioctl FBIOPUT_CON2FBMAP: %s\n", strerror(errno));
98+
+ exit(1);
99+
+ }
100+
+ } else {
101+
+ if (ioctl(fd, FBIOGET_CON2FBMAP, &map)) {
102+
+ fprintf(stderr, "ioctl FBIOGET_CON2FBMAP: %s\n", strerror(errno));
103+
+ exit(1);
104+
+ }
105+
+ printf("console %d is mapped to framebuffer %d\n", map.console,
106+
+ map.framebuffer);
107+
+ }
108+
+ close(fd);
109+
+ exit(0);
110+
+}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
Status: sent-upstream
2+
# Sent part of it, not the indentation fixes, nor the con2fbmap.
3+
4+
---
5+
Makefile | 88 +++++++++++++++++++++++++++++++++++++--------------------------
6+
1 file changed, 53 insertions(+), 35 deletions(-)
7+
8+
--- a/Makefile
9+
+++ b/Makefile
10+
@@ -2,40 +2,58 @@
11+
# Linux Frame Buffer Device Configuration
12+
#
13+
14+
-CC = gcc -Wall -O2 -I.
15+
-BISON = bison -d
16+
-FLEX = flex
17+
-INSTALL = install
18+
-RM = rm -f
19+
-
20+
-All: fbset
21+
-
22+
-
23+
-fbset: fbset.o modes.tab.o lex.yy.o
24+
-
25+
-fbset.o: fbset.c fbset.h fb.h
26+
-modes.tab.o: modes.tab.c fbset.h fb.h
27+
-lex.yy.o: lex.yy.c fbset.h modes.tab.h
28+
-
29+
-lex.yy.c: modes.l
30+
- $(FLEX) modes.l
31+
-
32+
-modes.tab.c: modes.y
33+
- $(BISON) modes.y
34+
-
35+
-install: fbset
36+
- if [ -f /sbin/fbset ]; then rm /sbin/fbset; fi
37+
- $(INSTALL) fbset /usr/sbin
38+
- $(INSTALL) fbset.8 /usr/man/man8
39+
- $(INSTALL) fb.modes.5 /usr/man/man5
40+
- if [ ! -c /dev/fb0 ]; then mknod /dev/fb0 c 29 0; fi
41+
- if [ ! -c /dev/fb1 ]; then mknod /dev/fb1 c 29 32; fi
42+
- if [ ! -c /dev/fb2 ]; then mknod /dev/fb2 c 29 64; fi
43+
- if [ ! -c /dev/fb3 ]; then mknod /dev/fb3 c 29 96; fi
44+
- if [ ! -c /dev/fb4 ]; then mknod /dev/fb4 c 29 128; fi
45+
- if [ ! -c /dev/fb5 ]; then mknod /dev/fb5 c 29 160; fi
46+
- if [ ! -c /dev/fb6 ]; then mknod /dev/fb6 c 29 192; fi
47+
- if [ ! -c /dev/fb7 ]; then mknod /dev/fb7 c 29 224; fi
48+
+srcdir = .
49+
+
50+
+CC = gcc
51+
+CFLAGS = -Wall -O2
52+
+BISON = bison -d
53+
+FLEX = flex
54+
+INSTALL = install
55+
+INSTALL_PROGRAM = $(INSTALL) -m 755
56+
+INSTALL_DATA = $(INSTALL) -m 644
57+
+RM = rm -f
58+
+
59+
+all: fbset con2fbmap
60+
+
61+
+fbset: fbset.o modes.tab.o lex.yy.o
62+
+
63+
+fbset.o: fbset.c fbset.h fb.h
64+
+modes.tab.o: modes.tab.c fbset.h fb.h
65+
+lex.yy.o: lex.yy.c fbset.h modes.tab.h
66+
+
67+
+lex.yy.c: modes.l
68+
+ $(FLEX) $<
69+
+
70+
+modes.tab.c modes.tab.h: modes.y
71+
+ $(BISON) $<
72+
+
73+
+con2fbmap: con2fbmap.o
74+
+con2fbmap.o: con2fbmap.c
75+
+
76+
+install: fbset
77+
+ $(INSTALL) -d $(DESTDIR)/etc
78+
+ $(INSTALL) -d $(DESTDIR)/bin
79+
+ $(INSTALL) -d $(DESTDIR)/usr/share/man/man1
80+
+ $(INSTALL) -d $(DESTDIR)/usr/share/man/man5
81+
+ $(INSTALL_DATA) $(srcdir)/etc/fb.modes.ATI $(DESTDIR)/etc/fb.modes
82+
+ $(INSTALL_DATA) $(srcdir)/fb.modes.5 $(DESTDIR)/usr/share/man/man5
83+
+ $(INSTALL_PROGRAM) fbset $(DESTDIR)/bin
84+
+ $(INSTALL_DATA) $(srcdir)/fbset.8 $(DESTDIR)/usr/share/man/man1/fbset.1
85+
+ $(INSTALL_PROGRAM) $(srcdir)/modeline2fb $(DESTDIR)/bin
86+
+ $(INSTALL_DATA) $(srcdir)/modeline2fb.1 $(DESTDIR)/usr/share/man/man1
87+
+ $(INSTALL_PROGRAM) con2fbmap $(DESTDIR)/bin
88+
+ $(INSTALL_DATA) $(srcdir)/con2fbmap.1 $(DESTDIR)/usr/share/man/man1
89+
+
90+
+install-devices:
91+
+ if [ ! -c /dev/fb0 ]; then mknod $(DESTDIR)/dev/fb0 c 29 0; fi
92+
+ if [ ! -c /dev/fb1 ]; then mknod $(DESTDIR)/dev/fb1 c 29 32; fi
93+
+ if [ ! -c /dev/fb2 ]; then mknod $(DESTDIR)/dev/fb2 c 29 64; fi
94+
+ if [ ! -c /dev/fb3 ]; then mknod $(DESTDIR)/dev/fb3 c 29 96; fi
95+
+ if [ ! -c /dev/fb4 ]; then mknod $(DESTDIR)/dev/fb4 c 29 128; fi
96+
+ if [ ! -c /dev/fb5 ]; then mknod $(DESTDIR)/dev/fb5 c 29 160; fi
97+
+ if [ ! -c /dev/fb6 ]; then mknod $(DESTDIR)/dev/fb6 c 29 192; fi
98+
+ if [ ! -c /dev/fb7 ]; then mknod $(DESTDIR)/dev/fb7 c 29 224; fi
99+
100+
clean:
101+
- $(RM) *.o fbset lex.yy.c modes.tab.c modes.tab.h
102+
+ $(RM) *.o fbset con2fbmap lex.yy.c modes.tab.c modes.tab.h
103+
+

buildroot/package/fbset/fbset.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ endef
2020

2121
define FBSET_INSTALL_TARGET_CMDS
2222
$(INSTALL) -D -m 755 $(@D)/fbset $(TARGET_DIR)/usr/sbin/fbset
23+
$(INSTALL) -D -m 755 $(@D)/con2fbmap $(TARGET_DIR)/bin/con2fbmap
2324
endef
2425

2526
$(eval $(generic-package))

buildroot/package/recovery/init

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ echo 2 >/sys/module/vt/parameters/cur_default
3333
# Enable syslog
3434
/etc/init.d/S01logging start > /dev/null
3535

36+
present=$(tvservice -l | sed -n -e 's|^Display Number \(.*\),.*$|\1| p')
37+
for dev in $present; do
38+
fitted=$(tvservice -n -v "$dev" 2>/dev/null)
39+
if [[ "$fitted" != "" ]]; then
40+
case "$dev" in
41+
0) #7in Touchscreen
42+
export QWS_DISPLAY="LinuxFb:/dev/fb0"
43+
break;
44+
;;
45+
2) #normal HDMI0
46+
export QWS_DISPLAY="LinuxFb:/dev/fb0"
47+
break;
48+
;;
49+
7) #Secondary HDMI1
50+
export QWS_DISPLAY="LinuxFb:/dev/fb1"
51+
/bin/con2fbmap 2 1
52+
/bin/con2fbmap 3 1
53+
break;
54+
;;
55+
esac
56+
fi
57+
done
58+
3659
if grep -q vncinstall /proc/cmdline; then
3760
# VNC server mode. Mainly useful for making screenshots
3861
export QWS_DISPLAY="VNC:size=800x600:depth=32:0"

buildroot/package/rpi-firmware/config.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ start_file=recovery.elf
33
fixup_file=fixup_rc.dat
44

55
[pi4]
6+
max_framebuffers=2
67
start_file=recover4.elf
78
fixup_file=fixup4rc.dat

buildroot/package/rpi-userland/rpi-userland.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ endef
2222
endif
2323

2424
define RPI_USERLAND_INSTALL_TARGET_CMDS
25+
$(INSTALL) -m 0755 $(STAGING_DIR)/usr/lib/libbcm_host.so $(TARGET_DIR)/usr/lib
2526
$(INSTALL) -m 0755 $(STAGING_DIR)/usr/lib/libvchiq_arm.so $(TARGET_DIR)/usr/lib
2627
$(INSTALL) -m 0755 $(STAGING_DIR)/usr/lib/libvcos.so $(TARGET_DIR)/usr/lib
2728
$(INSTALL) -m 0755 $(STAGING_DIR)/usr/lib/libvchostif.so $(TARGET_DIR)/usr/lib

0 commit comments

Comments
 (0)