Bug 261311

Summary: loader overrides console colors when not set by user
Product: Base System Reporter: Stefan B. <sblachmann>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Some People CC: emaste, grahamperrin, pauamma, sblachmann, tsoome
Priority: --- Keywords: vt
Version: Unspecified   
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263468

Description Stefan B. 2022-01-18 16:08:32 UTC
Colors set in kernel configuration file are ignored by vt, while being respected by sc.

Having only white on black is hard on the eyes.
Thus I wish colors would work.

The following kernel configuration works fine for sc, but has no effect on vt:

ident           EXAMPLE
include         GENERIC
nooptions       VESA
device		splash

device		sc
nooptions 	SC_PIXEL_MODE
options 	SC_HISTORY_SIZE=5000
options 	SC_NORM_ATTR=(FG_BLACK|BG_GREEN)
options 	SC_NORM_REV_ATTR=(FG_BLACK|BG_CYAN)
options 	SC_KERNEL_CONS_ATTR=(FG_BLACK|BG_RED)
options 	SC_KERNEL_CONS_REV_ATTR=(FG_BLACK|BG_BROWN)

According to the vt man page, these settings should be accepted by vt also.
Comment 1 Ed Maste freebsd_committer freebsd_triage 2022-01-18 20:46:36 UTC
Did you try the vt(4) options:

   Kernel Configuration Options
     These kernel options control the vt driver.

     TERMINAL_NORM_ATTR=attribute

     TERMINAL_KERN_ATTR=attribute
              These options change the default colors used for normal and
              kernel text.  Available colors are defined in <sys/terminal.h>.
              See EXAMPLES below.
Comment 2 Ed Maste freebsd_committer freebsd_triage 2022-01-18 20:55:19 UTC
The aliases were introduced here:

commit 7344ee184bebe6d1df0c60f09d4952653c47c1d8
Author: Marius Strobl <marius@FreeBSD.org>
Date:   Fri Jun 27 19:57:57 2014 +0000

    In order to get vt(4) a bit closer to the feature set provided by sc(4),
    implement options TERMINAL_{KERN,NORM}_ATTR. These are aliased to
    SC_{KERNEL_CONS,NORM}_ATTR and like these latter, allow to change the
    default colors of normal and kernel text respectively.
    Note on the naming: Although affecting the output of vt(4), technically
    kern/subr_terminal.c is primarily concerned with changing default colors
    so it would be inconsistent to term these options VT_{KERN,NORM}_ATTR.
    Actually, if the architecture and abstraction of terminal+teken+vt would
    be perfect, dev/vt/* wouldn't be touched by this commit at all.
Comment 3 Stefan B. 2022-01-24 18:53:48 UTC
Sorry for late reply.

I added the section below to the kernel configuration file and
it definitely has no effect at all.

I have tested this (and other things) on several different computers with many different graphics cards, so I am sure that the hardware used does not matter.


# Regarding PR 261311
# ( https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=261311 )
# According to `man 4 vt`, section 'BACKWARDS COMPATIBILITY',
# the above console color settings should work for vt also.
# Looking at terminal.h
# ( https://github.com/freebsd/freebsd-src/blob/main/sys/sys/terminal.h#L127 )
# it looks like that this "backwards compatibility" still is there.
# So these following two settings are just there to make sure that 
# there is something wrong with vt.
options 	TERMINAL_NORM_ATTR=(FG_BLACK|BG_GREEN)
options 	TERMINAL_KERN_ATTR=(FG_BLACK|BG_RED)
Comment 4 Stefan B. 2022-01-25 16:14:29 UTC
The alternative method described in the vt manpage which I tried as potential workaround also does not show any visible effect:

/boot/loader.conf:
kern.vt.color.0.rgb="00,10,00"
kern.vt.color.15.rgb="10,0,0"

Just to mention, this whole behavior is independent of whether vesa.ko is loaded or not.
hw.vga.textmode="YES" also does not change anything.
OS used for testing is 13.0-RELEASE-p6 on amd64.
Comment 5 Ed Maste freebsd_committer freebsd_triage 2022-03-03 20:39:38 UTC
Try setting these undocumented tunables:

teken.fg_color
teken.bg_color

It appears this is not an issue with vt, but rather an issue with the loader always setting these to provide a white-on-black console.

See commits:

3001e0c942d80 
233ab015c0d73
a536ed419e6ab
Comment 6 Ed Maste freebsd_committer freebsd_triage 2022-03-03 21:55:04 UTC
kern.vt.color.#.rgb indeed have no effect with vt_vga though, which always uses the standard VGA palette for text and graphics modes - we should note this in vt(4).

vt_vga.c configures the attribute registers to map the 16 colors to palette entries, but does not configure the palette entries themselves.
Comment 7 Stefan B. 2022-03-04 08:31:40 UTC
Thank you, this works!

Regarding the teken colors, I found this
https://git.furworks.de/opensourcemirror/opnsense-src/commit/233ab015c0d735089bd6863f8d0a0fd25b62c2a6
which indicates that, alternatively to the color numbers, there can be used the english color names, too.

Maybe this should be added to the documentation (manpage, handbook) as well.

Imho the other vt newcons configuration options mentioned here
https://lists.freebsd.org/pipermail/freebsd-current/2021-January/078090.html
also would deserve being documented.
Comment 8 Ed Maste freebsd_committer freebsd_triage 2022-03-04 15:37:42 UTC
VGA palette issue vt(4) note: https://reviews.freebsd.org/D34431

Yes all of these need to be documented in vt(4) / handbook.
Comment 9 commit-hook freebsd_committer freebsd_triage 2022-03-04 16:56:55 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=b126b79b27d479a3bd91e7f58f95ba8ce6b5655a

commit b126b79b27d479a3bd91e7f58f95ba8ce6b5655a
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-03-03 22:01:44 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-03-04 16:56:39 +0000

    vt(4): note that VGA palette configuration is not supported

    PR:             261311
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34431

 share/man/man4/vt.4 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2022-03-07 16:26:50 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e717dd3fb603d3e6ddb36ee8bddb46d84e21d384

commit e717dd3fb603d3e6ddb36ee8bddb46d84e21d384
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-03-03 22:01:44 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-03-07 16:25:21 +0000

    vt(4): note that VGA palette configuration is not supported

    PR:             261311
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34431

    (cherry picked from commit b126b79b27d479a3bd91e7f58f95ba8ce6b5655a)

 share/man/man4/vt.4 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Comment 11 commit-hook freebsd_committer freebsd_triage 2022-03-07 16:26:52 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=60743980726c83edd1cb122a98dca00d9973e9d6

commit 60743980726c83edd1cb122a98dca00d9973e9d6
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-03-03 22:01:44 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-03-07 16:25:58 +0000

    vt(4): note that VGA palette configuration is not supported

    PR:             261311
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34431

    (cherry picked from commit b126b79b27d479a3bd91e7f58f95ba8ce6b5655a)

 share/man/man4/vt.4 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Comment 12 Ed Maste freebsd_committer freebsd_triage 2022-03-09 18:47:44 UTC
I attempted to address this in https://reviews.freebsd.org/D34509, but it breaks changing the colors in the loader itself.
Comment 13 Pau Amma 2022-04-22 13:01:29 UTC
(In reply to Ed Maste from comment #8)
Opened https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263468 for doc, so this can stay in base to collect changes still pending.