loader: Make MK_LOADER_BIOS_TEXTONLY work

Select between text-only and graphical frame buffer consoles for the
BIOS boot loader. Pull one or the other in with #ifdef in conf.c. Add
gfx_bios.c for the few routines that are needed for the BIOS support of
gfx. These are stubbed out for text-only mode. Move bi_load_vbe_data
here since it's only used for the graphical frame buffer.

Note: This setup also allows us to build multiple BIOS loaders if we
have to, some with text-only and some graphical. We don't do this today.
We may be forced to turn this on in the future if ZFS keeps growing.

The size savings is 41k, which helps a lot with some of our users that
want to enable more options in the BIOS boot loader than are normally
safe to do, and they don't need graphics.

Sponsored by: 		Netflix
Differential Revision:	https://reviews.freebsd.org/D43917
This commit is contained in:
Warner Losh 2024-02-17 23:15:01 -07:00
parent e36afddf11
commit bbfc01c2d2
4 changed files with 88 additions and 20 deletions

View file

@ -36,25 +36,6 @@
#include "vbe.h"
#include "btxv86.h"
void
bi_load_vbe_data(struct preloaded_file *kfp)
{
if (!kfp->f_tg_kernel_support) {
/*
* Loaded kernel does not have vt/vbe backend,
* switch console to text mode.
*/
if (vbe_available())
bios_set_text_mode(VGA_TEXT_MODE);
return;
}
if (vbe_available()) {
file_addmetadata(kfp, MODINFOMD_VBE_FB,
sizeof(gfx_state.tg_fb), &gfx_state.tg_fb);
}
}
int
bi_getboothowto(char *kargs)
{

View file

@ -37,13 +37,27 @@ LOADERSIZE?= 560000 # Largest known safe size for loader.bin
.PATH: ${BOOTSRC}/i386/loader
# architecture-specific loader code
SRCS= main.c conf.c vers.c chain.c gfx_fb.c 8x16.c
SRCS+= chain.c
SRCS+= conf.c
SRCS+= gfx_bios.c
SRCS+= main.c
SRCS+= vers.c
.if ${MK_LOADER_BIOS_TEXTONLY} == "no"
SRCS+= gfx_fb.c
SRCS+= 8x16.c
CFLAGS.gfx_fb.c += -I${.CURDIR}/../libi386
CFLAGS.gfx_fb.c += -I$(SRCTOP)/sys/teken
CFLAGS.gfx_fb.c += -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4
CFLAGS.gfx_fb.c += -I${SRCTOP}/contrib/pnglite
CFLAGS.gfx_fb.c += -DHAVE_MEMCPY -I${SRCTOP}/sys/contrib/zlib
CFLAGS.gfx_bios.c += -I$(SRCTOP)/sys/teken
CFLAGS.gfx_bios.c += -I${SRCTOP}/contrib/pnglite
.else
CFLAGS.gfx_bios.c += -DBIOS_TEXT_ONLY
CFLAGS.conf.c += -DBIOS_TEXT_ONLY
.endif
# Include bcache code.
HAVE_BCACHE= yes

View file

@ -128,13 +128,18 @@ struct file_format *file_formats[] = {
* We don't prototype these in libi386.h because they require
* data structures from bootstrap.h as well.
*/
extern struct console textvidc;
extern struct console vidconsole;
extern struct console comconsole;
extern struct console nullconsole;
extern struct console spinconsole;
struct console *consoles[] = {
#ifdef BIOS_TEXT_ONLY
&textvidc,
#else
&vidconsole,
#endif
&comconsole,
&nullconsole,
&spinconsole,

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2024 Netflix, Inc.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
/*
* This file provides all the gfx glue, or stubs, so that we can build, if we
* want, two versions of the bios loader: one with graphics support and one
* without. This allows us to keep the calls in other places, like libraries
* that are tricky to compile twice. It also reduces the number of ifdefs we
* need to support the old text-only video console. This could also be two
* separate files, but it is short and having it all here helps to constrain
* dependency creap somewhat.
*/
#include <stand.h>
#ifndef BIOS_TEXT_ONLY
#include "bootstrap.h"
#include "libi386/libi386.h"
#include "libi386/vbe.h"
#include <gfx_fb.h>
#endif
#ifdef BIOS_TEXT_ONLY
void autoload_font(bool bios);
void
autoload_font(bool bios)
{
}
vm_offset_t build_font_module(vm_offset_t addr);
vm_offset_t
build_font_module(vm_offset_t addr)
{
return addr;
}
struct preloaded_file;
void bi_load_vbe_data(struct preloaded_file *kfp);
void bi_load_vbe_data(struct preloaded_file *kfp)
{
}
#else
void
bi_load_vbe_data(struct preloaded_file *kfp)
{
if (!kfp->f_tg_kernel_support) {
/*
* Loaded kernel does not have vt/vbe backend,
* switch console to text mode.
*/
if (vbe_available())
bios_set_text_mode(VGA_TEXT_MODE);
return;
}
if (vbe_available()) {
file_addmetadata(kfp, MODINFOMD_VBE_FB,
sizeof(gfx_state.tg_fb), &gfx_state.tg_fb);
}
}
#endif