요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
=======================
The Framebuffer Console
=======================
The framebuffer console (fbcon), as its name implies, is a text
console running on top of the framebuffer device. It has the functionality of
any standard text console driver, such as the VGA console, with the added
features that can be attributed to the graphical nature of the framebuffer.
In the x86 architecture, the framebuffer console is optional, and
some even treat it as a toy. For other architectures, it is the only available
display device, text or graphical.
What are the features of fbcon? The framebuffer console supports
high resolutions, varying font types, display rotation, primitive multihead,
etc. Theoretically, multi-colored fonts, blending, aliasing, and any feature
made available by the underlying graphics card are also possible.
A. Configuration
================
The framebuffer console can be enabled by using your favorite kernel
configuration tool. It is under Device Drivers->Graphics Support->
Console display driver support->Framebuffer Console Support.
Select 'y' to compile support statically or 'm' for module support. The
module will be fbcon.
In order for fbcon to activate, at least one framebuffer driver is
required, so choose from any of the numerous drivers available. For x86
systems, they almost universally have VGA cards, so vga16fb and vesafb will
always be available. However, using a chipset-specific driver will give you
more speed and features, such as the ability to change the video mode
dynamically.
To display the penguin logo, choose any logo available in Graphics
support->Bootup logo.
Also, you will need to select at least one compiled-in font, but if
you don't do anything, the kernel configuration tool will select one for you,
usually an 8x16 font.
.. admonition:: GOTCHA
A common bug report is enabling the framebuffer without enabling the
framebuffer console. Depending on the driver, you may get a blanked or
garbled display, but the system still boots to completion. If you are
fortunate to have a driver that does not alter the graphics chip, then you
will still get a VGA console.
B. Loading
==========
Possible scenarios:
1. Driver and fbcon are compiled statically
Usually, fbcon will automatically take over your console. The notable
exception is vesafb. It needs to be explicitly activated with the
vga= boot option parameter.
2. Driver is compiled statically, fbcon is compiled as a module
Depending on the driver, you either get a standard console, or a
garbled display, as mentioned above. To get a framebuffer console,
do a 'modprobe fbcon'.
3. Driver is compiled as a module, fbcon is compiled statically
You get your standard console. Once the driver is loaded with
'modprobe xxxfb', fbcon automatically takes over the console with
the possible exception of using the fbcon=map:n option. See below.
4. Driver and fbcon are compiled as a module.
You can load them in any order. Once both are loaded, fbcon will take
over the console.
C. Boot options
===============
The framebuffer console has several, largely unknown, boot options
that can change its behavior.
1. fbcon=font:<name>
Select the initial font to use. The value 'name' can be any of the
compiled-in fonts: 10x18, 6x10, 6x8, 7x14, Acorn8x8, MINI4x6,
PEARL8x8, ProFont6x11, SUN12x22, SUN8x16, TER16x32, VGA8x16, VGA8x8.
Note, not all drivers can handle font with widths not divisible by 8,
such as vga16fb.
2. fbcon=map:<0123>
This is an interesting option. It tells which driver gets mapped to
which console. The value '0123' is a sequence that gets repeated until
the total length is 64 which is the number of consoles available. In
the above example, it is expanded to 012301230123... and the mapping
will be::
tty | 1 2 3 4 5 6 7 8 9 ...
fb | 0 1 2 3 0 1 2 3 0 ...
('cat /proc/fb' should tell you what the fb numbers are)
One side effect that may be useful is using a map value that exceeds
the number of loaded fb drivers. For example, if only one driver is
available, fb0, adding fbcon=map:1 tells fbcon not to take over the
console.
Later on, when you want to map the console the to the framebuffer
device, you can use the con2fbmap utility.
3. fbcon=vc:<n1>-<n2>
This option tells fbcon to take over only a range of consoles as
specified by the values 'n1' and 'n2'. The rest of the consoles
outside the given range will still be controlled by the standard
console driver.
.. note::
For x86 machines, the standard console is the VGA console which
is typically located on the same video card. Thus, the consoles that
are controlled by the VGA console will be garbled.
4. fbcon=rotate:<n>
This option changes the orientation angle of the console display. The
value 'n' accepts the following:
- 0 - normal orientation (0 degree)
- 1 - clockwise orientation (90 degrees)
- 2 - upside down orientation (180 degrees)
- 3 - counterclockwise orientation (270 degrees)
The angle can be changed anytime afterwards by 'echoing' the same
numbers to any one of the 2 attributes found in
/sys/class/graphics/fbcon:
- rotate - rotate the display of the active console
- rotate_all - rotate the display of all consoles
Console rotation will only become available if Framebuffer Console
Rotation support is compiled in your kernel.
.. note::
This is purely console rotation. Any other applications that
use the framebuffer will remain at their 'normal' orientation.
Actually, the underlying fb driver is totally ignorant of console
rotation.
5. fbcon=margin:<color>
This option specifies the color of the margins. The margins are the
leftover area at the right and the bottom of the screen that are not
used by text. By default, this area will be black. The 'color' value
is an integer number that depends on the framebuffer driver being used.
6. fbcon=nodefer
If the kernel is compiled with deferred fbcon takeover support, normally
the framebuffer contents, left in place by the firmware/bootloader, will
be preserved until there actually is some text is output to the console.
This option causes fbcon to bind immediately to the fbdev device.
7. fbcon=logo-pos:<location>
The only possible 'location' is 'center' (without quotes), and when
given, the bootup logo is moved from the default top-left corner
location to the center of the framebuffer. If more than one logo is
displayed due to multiple CPUs, the collected line of logos is moved
as a whole.
8. fbcon=logo-count:<n>
The value 'n' overrides the number of bootup logos. 0 disables the
logo, and -1 gives the default which is the number of online CPUs.
D. Attaching, Detaching and Unloading
=====================================
Before going on to how to attach, detach and unload the framebuffer console, an
illustration of the dependencies may help.
The console layer, as with most subsystems, needs a driver that interfaces with
the hardware. Thus, in a VGA console::
console ---> VGA driver ---> hardware.
Assuming the VGA driver can be unloaded, one must first unbind the VGA driver
from the console layer before unloading the driver. The VGA driver cannot be
unloaded if it is still bound to the console layer. (See
Documentation/driver-api/console.rst for more information).
This is more complicated in the case of the framebuffer console (fbcon),
because fbcon is an intermediate layer between the console and the drivers::
console ---> fbcon ---> fbdev drivers ---> hardware
The fbdev drivers cannot be unloaded if bound to fbcon, and fbcon cannot
be unloaded if it's bound to the console layer.
So to unload the fbdev drivers, one must first unbind fbcon from the console,
then unbind the fbdev drivers from fbcon. Fortunately, unbinding fbcon from
the console layer will automatically unbind framebuffer drivers from
fbcon. Thus, there is no need to explicitly unbind the fbdev drivers from
fbcon.
So, how do we unbind fbcon from the console? Part of the answer is in
Documentation/driver-api/console.rst. To summarize:
Echo a value to the bind file that represents the framebuffer console
driver. So assuming vtcon1 represents fbcon, then::
echo 1 > /sys/class/vtconsole/vtcon1/bind - attach framebuffer console to
console layer
echo 0 > /sys/class/vtconsole/vtcon1/bind - detach framebuffer console from
console layer
If fbcon is detached from the console layer, your boot console driver (which is
usually VGA text mode) will take over. A few drivers (rivafb and i810fb) will
restore VGA text mode for you. With the rest, before detaching fbcon, you
must take a few additional steps to make sure that your VGA text mode is
restored properly. The following is one of the several methods that you can do:
1. Download or install vbetool. This utility is included with most
distributions nowadays, and is usually part of the suspend/resume tool.
2. In your kernel configuration, ensure that CONFIG_FRAMEBUFFER_CONSOLE is set
to 'y' or 'm'. Enable one or more of your favorite framebuffer drivers.
3. Boot into text mode and as root run::
vbetool vbestate save > <vga state file>
The above command saves the register contents of your graphics
hardware to <vga state file>. You need to do this step only once as
the state file can be reused.
4. If fbcon is compiled as a module, load fbcon by doing::
modprobe fbcon
5. Now to detach fbcon::
vbetool vbestate restore < <vga state file> && \
echo 0 > /sys/class/vtconsole/vtcon1/bind
6. That's it, you're back to VGA mode. And if you compiled fbcon as a module,
you can unload it by 'rmmod fbcon'.
7. To reattach fbcon::
echo 1 > /sys/class/vtconsole/vtcon1/bind
8. Once fbcon is unbound, all drivers registered to the system will also
become unbound. This means that fbcon and individual framebuffer drivers
can be unloaded or reloaded at will. Reloading the drivers or fbcon will
automatically bind the console, fbcon and the drivers together. Unloading
all the drivers without unloading fbcon will make it impossible for the
console to bind fbcon.
Notes for vesafb users:
=======================
Unfortunately, if your bootline includes a vga=xxx parameter that sets the
hardware in graphics mode, such as when loading vesafb, vgacon will not load.
Instead, vgacon will replace the default boot console with dummycon, and you
won't get any display after detaching fbcon. Your machine is still alive, so
you can reattach vesafb. However, to reattach vesafb, you need to do one of
the following:
Variation 1:
a. Before detaching fbcon, do::
vbetool vbemode save > <vesa state file> # do once for each vesafb mode,
# the file can be reused
b. Detach fbcon as in step 5.
c. Attach fbcon::
vbetool vbestate restore < <vesa state file> && \
echo 1 > /sys/class/vtconsole/vtcon1/bind
Variation 2:
a. Before detaching fbcon, do::
echo <ID> > /sys/class/tty/console/bind
vbetool vbemode get
b. Take note of the mode number
b. Detach fbcon as in step 5.
c. Attach fbcon::
vbetool vbemode set <mode number> && \
echo 1 > /sys/class/vtconsole/vtcon1/bind
Samples:
========
Here are 2 sample bash scripts that you can use to bind or unbind the
framebuffer console driver if you are on an X86 box::
#!/bin/bash
# Unbind fbcon
# Change this to where your actual vgastate file is located
# Or Use VGASTATE=$1 to indicate the state file at runtime
VGASTATE=/tmp/vgastate
# path to vbetool
VBETOOL=/usr/local/bin
for (( i = 0; i < 16; i++))
do
if test -x /sys/class/vtconsole/vtcon$i; then
if [ `cat /sys/class/vtconsole/vtcon$i/name | grep -c "frame buffer"` \
= 1 ]; then
if test -x $VBETOOL/vbetool; then
echo Unbinding vtcon$i
$VBETOOL/vbetool vbestate restore < $VGASTATE
echo 0 > /sys/class/vtconsole/vtcon$i/bind
fi
fi
fi
done
---------------------------------------------------------------------------
::
#!/bin/bash
# Bind fbcon
for (( i = 0; i < 16; i++))
do
if test -x /sys/class/vtconsole/vtcon$i; then
if [ `cat /sys/class/vtconsole/vtcon$i/name | grep -c "frame buffer"` \
= 1 ]; then
echo Unbinding vtcon$i
echo 1 > /sys/class/vtconsole/vtcon$i/bind
fi
fi
done
Antonino Daplas <[email protected]>
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Framebuffer console 개요와 기능
1-18Framebuffer console(`fbcon`)은 framebuffer device 위에서 동작하는 text console입니다. VGA console 같은 표준 text console driver의 기능에 framebuffer의 graphics 특성을 활용한 기능을 더합니다.
x86에서는 framebuffer console이 선택 사항이고 단순한 부가 기능으로 취급되기도 하지만, 다른 architecture에서는 text와 graphics를 포함해 사용할 수 있는 유일한 display device인 경우가 있습니다.
`fbcon`은 high resolution, 다양한 font, display rotation, 기초적인 multihead 등을 지원합니다. 이론적으로는 underlying graphics card가 제공하는 multi-colored font, blending, aliasing 같은 기능도 구현할 수 있습니다.
=======================
The Framebuffer Console
=======================
The framebuffer console (fbcon), as its name implies, is a text
console running on top of the framebuffer device. It has the functionality of
any standard text console driver, such as the VGA console, with the added
features that can be attributed to the graphical nature of the framebuffer.
In the x86 architecture, the framebuffer console is optional, and
some even treat it as a toy. For other architectures, it is the only available
display device, text or graphical.
What are the features of fbcon? The framebuffer console supports
high resolutions, varying font types, display rotation, primitive multihead,
etc. Theoretically, multi-colored fonts, blending, aliasing, and any feature
made available by the underlying graphics card are also possible.
Kernel configuration과 필수 구성 요소
19-49Kernel configuration의 `Device Drivers -> Graphics Support -> Console display driver support -> Framebuffer Console Support`에서 framebuffer console을 활성화합니다. `y`는 built-in, `m`은 module이며 module 이름은 `fbcon`입니다.
`fbcon`이 활성화되려면 framebuffer driver가 최소 하나 필요합니다. x86에서는 `vga16fb`와 `vesafb`를 사용할 수 있지만 chipset-specific driver가 더 빠르고 runtime video mode 변경 같은 추가 기능을 제공합니다.
Boot penguin logo는 `Graphics support -> Bootup logo`에서 선택합니다. Built-in font도 하나 이상 필요하며 아무것도 고르지 않으면 configuration tool이 보통 8x16 font를 선택합니다.
Framebuffer만 활성화하고 framebuffer console을 빠뜨리는 것이 흔한 문제입니다. Driver에 따라 화면이 blank 또는 깨진 상태가 되더라도 system은 boot를 완료합니다. Graphics chip을 변경하지 않는 driver라면 VGA console이 계속 보일 수도 있습니다.
Console이 실제로 표시되려면 fbcon 외에도 framebuffer driver와 font가 필요합니다.
A. Configuration
================
The framebuffer console can be enabled by using your favorite kernel
configuration tool. It is under Device Drivers->Graphics Support->
Console display driver support->Framebuffer Console Support.
Select 'y' to compile support statically or 'm' for module support. The
module will be fbcon.
In order for fbcon to activate, at least one framebuffer driver is
required, so choose from any of the numerous drivers available. For x86
systems, they almost universally have VGA cards, so vga16fb and vesafb will
always be available. However, using a chipset-specific driver will give you
more speed and features, such as the ability to change the video mode
dynamically.
To display the penguin logo, choose any logo available in Graphics
support->Bootup logo.
Also, you will need to select at least one compiled-in font, but if
you don't do anything, the kernel configuration tool will select one for you,
usually an 8x16 font.
.. admonition:: GOTCHA
A common bug report is enabling the framebuffer without enabling the
framebuffer console. Depending on the driver, you may get a blanked or
garbled display, but the system still boots to completion. If you are
fortunate to have a driver that does not alter the graphics chip, then you
will still get a VGA console.
Built-in과 module 조합별 takeover
50-77Driver와 `fbcon`이 모두 built-in이면 보통 `fbcon`이 console을 자동 takeover합니다. 대표적인 예외인 `vesafb`는 `vga=` boot option으로 명시적으로 활성화해야 합니다.
Driver는 built-in이고 `fbcon`이 module이면 driver에 따라 표준 console 또는 깨진 화면이 나타납니다. `modprobe fbcon`을 실행하면 framebuffer console을 사용할 수 있습니다.
Driver가 module이고 `fbcon`이 built-in이면 처음에는 표준 console이 유지됩니다. `modprobe xxxfb`로 driver를 load하면 `fbcon=map:n`의 영향이 없는 한 `fbcon`이 자동 takeover합니다.
Driver와 `fbcon`이 모두 module이면 어느 순서로든 load할 수 있으며, 둘 다 load되는 시점에 `fbcon`이 console을 takeover합니다.
B. Loading
==========
Possible scenarios:
1. Driver and fbcon are compiled statically
Usually, fbcon will automatically take over your console. The notable
exception is vesafb. It needs to be explicitly activated with the
vga= boot option parameter.
2. Driver is compiled statically, fbcon is compiled as a module
Depending on the driver, you either get a standard console, or a
garbled display, as mentioned above. To get a framebuffer console,
do a 'modprobe fbcon'.
3. Driver is compiled as a module, fbcon is compiled statically
You get your standard console. Once the driver is loaded with
'modprobe xxxfb', fbcon automatically takes over the console with
the possible exception of using the fbcon=map:n option. See below.
4. Driver and fbcon are compiled as a module.
You can load them in any order. Once both are loaded, fbcon will take
over the console.
Font, map, VC, rotation과 logo boot option
78-179`fbcon=font:<name>`은 초기 font를 선택합니다. 사용할 수 있는 built-in font는 `10x18`, `6x10`, `6x8`, `7x14`, `Acorn8x8`, `MINI4x6`, `PEARL8x8`, `ProFont6x11`, `SUN12x22`, `SUN8x16`, `TER16x32`, `VGA8x16`, `VGA8x8`입니다. `vga16fb`처럼 width가 8의 배수가 아닌 font를 처리하지 못하는 driver도 있습니다.
`fbcon=map:<0123>`은 각 virtual console에 mapping할 framebuffer driver 번호 sequence를 지정합니다. Sequence는 사용 가능한 console 수인 64자리까지 반복됩니다. 예를 들어 `0123`은 tty1~tty4를 fb0~fb3에 대응시키고 이후 반복합니다. Framebuffer 번호는 `cat /proc/fb`로 확인합니다.
Load된 fb driver 수보다 큰 map 값을 사용하면 takeover를 막을 수 있습니다. 예를 들어 fb0만 있을 때 `fbcon=map:1`을 주면 `fbcon`이 console을 takeover하지 않습니다. 나중에 `con2fbmap` utility로 console을 framebuffer device에 mapping할 수 있습니다.
`fbcon=vc:<n1>-<n2>`는 지정된 virtual console 범위만 takeover하고 나머지는 표준 console driver에 남깁니다. x86에서 표준 VGA console이 같은 video card를 사용하면 VGA가 담당하는 console 화면이 깨질 수 있습니다.
`fbcon=rotate:<n>`은 orientation을 바꿉니다. 0은 0도, 1은 clockwise 90도, 2는 180도, 3은 counterclockwise 270도입니다. 이후 `/sys/class/graphics/fbcon/rotate`에 쓰면 active console, `rotate_all`에 쓰면 모든 console을 회전합니다.
Console rotation은 kernel에 Framebuffer Console Rotation support가 built-in된 경우만 사용할 수 있습니다. 이는 console만 회전하며 framebuffer를 사용하는 다른 application과 underlying fb driver의 orientation은 그대로입니다.
`fbcon=margin:<color>`는 text가 사용하지 않는 화면 오른쪽과 아래 margin의 색을 정합니다. 기본은 black이며 정수 color 값의 의미는 framebuffer driver에 따라 달라집니다.
Deferred fbcon takeover가 활성화된 kernel은 실제 console text가 출력될 때까지 firmware/bootloader가 남긴 framebuffer를 보존합니다. `fbcon=nodefer`는 기다리지 않고 즉시 fbdev device에 bind합니다.
`fbcon=logo-pos:center`는 boot logo 또는 여러 CPU logo의 전체 line을 기본 top-left에서 framebuffer 중앙으로 옮깁니다. `fbcon=logo-count:<n>`은 logo 수를 override하며 0은 비활성화, -1은 online CPU 수인 기본값입니다.
원문의 두 줄 ASCII mapping을 반복 pattern 표로 다시 구성했습니다.
C. Boot options
===============
The framebuffer console has several, largely unknown, boot options
that can change its behavior.
1. fbcon=font:<name>
Select the initial font to use. The value 'name' can be any of the
compiled-in fonts: 10x18, 6x10, 6x8, 7x14, Acorn8x8, MINI4x6,
PEARL8x8, ProFont6x11, SUN12x22, SUN8x16, TER16x32, VGA8x16, VGA8x8.
Note, not all drivers can handle font with widths not divisible by 8,
such as vga16fb.
2. fbcon=map:<0123>
This is an interesting option. It tells which driver gets mapped to
which console. The value '0123' is a sequence that gets repeated until
the total length is 64 which is the number of consoles available. In
the above example, it is expanded to 012301230123... and the mapping
will be::
tty | 1 2 3 4 5 6 7 8 9 ...
fb | 0 1 2 3 0 1 2 3 0 ...
('cat /proc/fb' should tell you what the fb numbers are)
One side effect that may be useful is using a map value that exceeds
the number of loaded fb drivers. For example, if only one driver is
available, fb0, adding fbcon=map:1 tells fbcon not to take over the
console.
Later on, when you want to map the console the to the framebuffer
device, you can use the con2fbmap utility.
3. fbcon=vc:<n1>-<n2>
This option tells fbcon to take over only a range of consoles as
specified by the values 'n1' and 'n2'. The rest of the consoles
outside the given range will still be controlled by the standard
console driver.
.. note::
For x86 machines, the standard console is the VGA console which
is typically located on the same video card. Thus, the consoles that
are controlled by the VGA console will be garbled.
4. fbcon=rotate:<n>
This option changes the orientation angle of the console display. The
value 'n' accepts the following:
- 0 - normal orientation (0 degree)
- 1 - clockwise orientation (90 degrees)
- 2 - upside down orientation (180 degrees)
- 3 - counterclockwise orientation (270 degrees)
The angle can be changed anytime afterwards by 'echoing' the same
numbers to any one of the 2 attributes found in
/sys/class/graphics/fbcon:
- rotate - rotate the display of the active console
- rotate_all - rotate the display of all consoles
Console rotation will only become available if Framebuffer Console
Rotation support is compiled in your kernel.
.. note::
This is purely console rotation. Any other applications that
use the framebuffer will remain at their 'normal' orientation.
Actually, the underlying fb driver is totally ignorant of console
rotation.
5. fbcon=margin:<color>
This option specifies the color of the margins. The margins are the
leftover area at the right and the bottom of the screen that are not
used by text. By default, this area will be black. The 'color' value
is an integer number that depends on the framebuffer driver being used.
6. fbcon=nodefer
If the kernel is compiled with deferred fbcon takeover support, normally
the framebuffer contents, left in place by the firmware/bootloader, will
be preserved until there actually is some text is output to the console.
This option causes fbcon to bind immediately to the fbdev device.
7. fbcon=logo-pos:<location>
The only possible 'location' is 'center' (without quotes), and when
given, the bootup logo is moved from the default top-left corner
location to the center of the framebuffer. If more than one logo is
displayed due to multiple CPUs, the collected line of logos is moved
as a whole.
8. fbcon=logo-count:<n>
The value 'n' overrides the number of bootup logos. 0 disables the
logo, and -1 gives the default which is the number of online CPUs.
Console, fbcon, fbdev 의존 관계와 bind
180-220Console layer는 hardware와 interface하는 driver가 필요합니다. VGA console의 기본 경로는 `console -> VGA driver -> hardware`입니다. VGA driver를 unload할 수 있다고 가정해도 먼저 console layer에서 unbind해야 하며, bind된 상태에서는 unload할 수 없습니다. 자세한 내용은 `Documentation/driver-api/console.rst`를 참조합니다.
Framebuffer console에서는 `fbcon`이 console과 fbdev driver 사이의 중간 layer이므로 경로가 `console -> fbcon -> fbdev drivers -> hardware`가 됩니다.
Fbdev driver는 `fbcon`에 bind된 상태에서 unload할 수 없고, `fbcon`도 console layer에 bind된 상태에서는 unload할 수 없습니다. 따라서 console에서 `fbcon`을 먼저 unbind해야 합니다. 이 작업은 fbdev driver도 `fbcon`에서 자동 unbind하므로 driver별 추가 unbind는 필요하지 않습니다.
`vtcon1`이 fbcon이라고 가정하면 `/sys/class/vtconsole/vtcon1/bind`에 1을 쓰면 console layer에 attach하고 0을 쓰면 detach합니다.
원문의 두 ASCII 의존 관계를 layer flow로 다시 구성했습니다.
D. Attaching, Detaching and Unloading
=====================================
Before going on to how to attach, detach and unload the framebuffer console, an
illustration of the dependencies may help.
The console layer, as with most subsystems, needs a driver that interfaces with
the hardware. Thus, in a VGA console::
console ---> VGA driver ---> hardware.
Assuming the VGA driver can be unloaded, one must first unbind the VGA driver
from the console layer before unloading the driver. The VGA driver cannot be
unloaded if it is still bound to the console layer. (See
Documentation/driver-api/console.rst for more information).
This is more complicated in the case of the framebuffer console (fbcon),
because fbcon is an intermediate layer between the console and the drivers::
console ---> fbcon ---> fbdev drivers ---> hardware
The fbdev drivers cannot be unloaded if bound to fbcon, and fbcon cannot
be unloaded if it's bound to the console layer.
So to unload the fbdev drivers, one must first unbind fbcon from the console,
then unbind the fbdev drivers from fbcon. Fortunately, unbinding fbcon from
the console layer will automatically unbind framebuffer drivers from
fbcon. Thus, there is no need to explicitly unbind the fbdev drivers from
fbcon.
So, how do we unbind fbcon from the console? Part of the answer is in
Documentation/driver-api/console.rst. To summarize:
Echo a value to the bind file that represents the framebuffer console
driver. So assuming vtcon1 represents fbcon, then::
echo 1 > /sys/class/vtconsole/vtcon1/bind - attach framebuffer console to
console layer
echo 0 > /sys/class/vtconsole/vtcon1/bind - detach framebuffer console from
console layer
VGA state 복원, detach와 module unload
221-263`fbcon`을 console layer에서 detach하면 보통 VGA text mode인 boot console driver가 takeover합니다. `rivafb`와 `i810fb`는 VGA text mode를 복원하지만, 다른 driver에서는 detach 전에 VGA state를 직접 복원해야 합니다.
먼저 대부분 distribution의 suspend/resume 도구에 포함된 `vbetool`을 설치합니다. Kernel에서 `CONFIG_FRAMEBUFFER_CONSOLE`을 `y` 또는 `m`으로 설정하고 framebuffer driver를 하나 이상 활성화합니다.
Text mode로 boot한 뒤 root로 `vbetool vbestate save > <vga state file>`을 한 번 실행해 graphics register를 저장합니다. State file은 재사용할 수 있습니다.
`fbcon`이 module이면 `modprobe fbcon`으로 load합니다. Detach할 때 `vbetool vbestate restore < <vga state file>`로 VGA state를 복원한 뒤 `/sys/class/vtconsole/vtcon1/bind`에 0을 씁니다. Module은 `rmmod fbcon`으로 unload할 수 있습니다.
다시 attach하려면 bind file에 1을 씁니다. `fbcon`이 unbind되면 등록된 모든 framebuffer driver도 unbind되어 자유롭게 unload/reload할 수 있습니다. Driver나 `fbcon`을 reload하면 console chain이 자동 bind됩니다. `fbcon`은 남겨 둔 채 모든 framebuffer driver를 unload하면 console이 `fbcon`에 bind할 수 없습니다.
Graphics register state를 보존한 뒤 console chain을 해제합니다.
If fbcon is detached from the console layer, your boot console driver (which is
usually VGA text mode) will take over. A few drivers (rivafb and i810fb) will
restore VGA text mode for you. With the rest, before detaching fbcon, you
must take a few additional steps to make sure that your VGA text mode is
restored properly. The following is one of the several methods that you can do:
1. Download or install vbetool. This utility is included with most
distributions nowadays, and is usually part of the suspend/resume tool.
2. In your kernel configuration, ensure that CONFIG_FRAMEBUFFER_CONSOLE is set
to 'y' or 'm'. Enable one or more of your favorite framebuffer drivers.
3. Boot into text mode and as root run::
vbetool vbestate save > <vga state file>
The above command saves the register contents of your graphics
hardware to <vga state file>. You need to do this step only once as
the state file can be reused.
4. If fbcon is compiled as a module, load fbcon by doing::
modprobe fbcon
5. Now to detach fbcon::
vbetool vbestate restore < <vga state file> && \
echo 0 > /sys/class/vtconsole/vtcon1/bind
6. That's it, you're back to VGA mode. And if you compiled fbcon as a module,
you can unload it by 'rmmod fbcon'.
7. To reattach fbcon::
echo 1 > /sys/class/vtconsole/vtcon1/bind
8. Once fbcon is unbound, all drivers registered to the system will also
become unbound. This means that fbcon and individual framebuffer drivers
can be unloaded or reloaded at will. Reloading the drivers or fbcon will
automatically bind the console, fbcon and the drivers together. Unloading
all the drivers without unloading fbcon will make it impossible for the
console to bind fbcon.
vesafb에서 detach 후 화면 복구
264-304Boot line의 `vga=xxx`가 `vesafb`를 load하면서 hardware를 graphics mode로 설정하면 `vgacon`이 load되지 않습니다. `vgacon`은 기본 boot console을 `dummycon`으로 바꾸므로 `fbcon` detach 후 display가 사라집니다. System은 계속 실행 중이므로 `vesafb`를 다시 attach할 수 있습니다.
Variation 1에서는 mode마다 한 번 `vbetool vbemode save > <vesa state file>`로 VESA state를 저장하고, 일반 절차로 `fbcon`을 detach합니다. Reattach할 때 VESA state를 복원하고 vtconsole bind에 1을 씁니다.
Variation 2에서는 detach 전에 `<ID>`를 `/sys/class/tty/console/bind`에 쓰고 `vbetool vbemode get`으로 mode number를 기록합니다. Reattach할 때 `vbetool vbemode set <mode number>`를 실행한 뒤 vtconsole bind에 1을 씁니다.
Notes for vesafb users:
=======================
Unfortunately, if your bootline includes a vga=xxx parameter that sets the
hardware in graphics mode, such as when loading vesafb, vgacon will not load.
Instead, vgacon will replace the default boot console with dummycon, and you
won't get any display after detaching fbcon. Your machine is still alive, so
you can reattach vesafb. However, to reattach vesafb, you need to do one of
the following:
Variation 1:
a. Before detaching fbcon, do::
vbetool vbemode save > <vesa state file> # do once for each vesafb mode,
# the file can be reused
b. Detach fbcon as in step 5.
c. Attach fbcon::
vbetool vbestate restore < <vesa state file> && \
echo 1 > /sys/class/vtconsole/vtcon1/bind
Variation 2:
a. Before detaching fbcon, do::
echo <ID> > /sys/class/tty/console/bind
vbetool vbemode get
b. Take note of the mode number
b. Detach fbcon as in step 5.
c. Attach fbcon::
vbetool vbemode set <mode number> && \
echo 1 > /sys/class/vtconsole/vtcon1/bind
X86 bind/unbind sample script
305-354첫 번째 bash script는 X86에서 `vtcon0`부터 `vtcon15`까지 순회하며 존재하는 vtconsole의 `name`에 `frame buffer`가 포함되는지 검사합니다. `vbetool`이 실행 가능하면 저장된 `VGASTATE`를 복원하고 해당 `bind` file에 0을 써서 framebuffer console을 unbind합니다.
`VGASTATE`는 실제 VGA state file 위치로 바꾸거나 runtime argument를 받도록 수정할 수 있고, `VBETOOL`은 `vbetool` executable 경로입니다.
두 번째 script도 같은 방식으로 framebuffer vtconsole을 찾고 `bind` file에 1을 써서 attach합니다. 원문 script의 message는 bind 동작에서도 `Unbinding vtcon$i`라고 출력하므로 code는 그대로 보존합니다.
Sysfs name으로 framebuffer console을 식별해 state 복원과 bind 값을 자동화합니다.
Samples:
========
Here are 2 sample bash scripts that you can use to bind or unbind the
framebuffer console driver if you are on an X86 box::
#!/bin/bash
# Unbind fbcon
# Change this to where your actual vgastate file is located
# Or Use VGASTATE=$1 to indicate the state file at runtime
VGASTATE=/tmp/vgastate
# path to vbetool
VBETOOL=/usr/local/bin
for (( i = 0; i < 16; i++))
do
if test -x /sys/class/vtconsole/vtcon$i; then
if [ `cat /sys/class/vtconsole/vtcon$i/name | grep -c "frame buffer"` \
= 1 ]; then
if test -x $VBETOOL/vbetool; then
echo Unbinding vtcon$i
$VBETOOL/vbetool vbestate restore < $VGASTATE
echo 0 > /sys/class/vtconsole/vtcon$i/bind
fi
fi
fi
done
---------------------------------------------------------------------------
::
#!/bin/bash
# Bind fbcon
for (( i = 0; i < 16; i++))
do
if test -x /sys/class/vtconsole/vtcon$i; then
if [ `cat /sys/class/vtconsole/vtcon$i/name | grep -c "frame buffer"` \
= 1 ]; then
echo Unbinding vtcon$i
echo 1 > /sys/class/vtconsole/vtcon$i/bind
fi
fi
done
Antonino Daplas <[email protected]>
요약·해설
fbcon.rst:1-354`fbcon`은 fbdev 위의 text console layer입니다. Kernel 구성, built-in/module load 순서, virtual console mapping, rotation과 logo option, sysfs attach/detach 및 VGA/VESA state 복원 절차를 제공합니다.
안전한 unload의 핵심은 `console -> fbcon -> fbdev -> hardware` 의존 순서를 거꾸로 해제하는 것입니다. Console에서 fbcon을 unbind하면 fbdev driver도 자동으로 풀립니다.
구성부터 안전한 detach와 재연결까지의 핵심 흐름입니다.