Page 1 of 1

How to do stuff before loading correct drivers?

Posted: Wed Jun 23, 2010 11:25 pm
by TylerH
I don't want the video/terminal driver in as part of my kernel(just doesn't seem right, not extensible), but I'd like to be able to output to the screen while I'm loading drivers and the like. How's this conventionally done? I noticed this in a log file:

Code: Select all

Jun 20 15:52:44 laptop kernel: imklog 4.2.0, log source = /proc/kmsg started.
Jun 20 15:52:44 laptop rsyslogd: [origin software="rsyslogd" swVersion="4.2.0" x-pid="883" x-info="http://www.rsyslog.com"] (re)start
Jun 20 15:52:44 laptop rsyslogd: rsyslogd's groupid changed to 103
Jun 20 15:52:44 laptop rsyslogd: rsyslogd's userid changed to 101
Jun 20 15:52:44 laptop kernel: [    0.000000] Initializing cgroup subsys cpuset
Jun 20 15:52:44 laptop kernel: [    0.000000] Initializing cgroup subsys cpu
Jun 20 15:52:44 laptop kernel: [    0.000000] Linux version 2.6.32-21-generic (buildd@yellow) (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) ) #32-Ubuntu SMP Fri Apr 16 08:09:38 UTC 2010 (Ubuntu 2.6.32-21.32-generic 2.6.32.11+drm33.2)
Jun 20 15:52:44 laptop kernel: [    0.000000] Command line: BOOT_IMAGE=/vmlinuz-2.6.32-21-generic root=UUID=2b2ffef6-a356-49e1-b679-597acde9c0ce ro quiet splash
Jun 20 15:52:44 laptop kernel: [    0.000000] KERNEL supported cpus:
Jun 20 15:52:44 laptop kernel: [    0.000000]   Intel GenuineIntel
Jun 20 15:52:44 laptop kernel: [    0.000000]   AMD AuthenticAMD
Jun 20 15:52:44 laptop kernel: [    0.000000]   Centaur CentaurHauls
Jun 20 15:52:44 laptop kernel: [    0.000000] BIOS-provided physical RAM map:
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 0000000000000000 - 000000000009e000 (usable)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 000000000009e000 - 00000000000a0000 (reserved)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 00000000000d0000 - 0000000000100000 (reserved)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 0000000000100000 - 00000000afed0000 (usable)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 00000000afed0000 - 00000000afee5000 (ACPI data)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 00000000afee5000 - 00000000afee6000 (ACPI NVS)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 00000000afee6000 - 00000000c0000000 (reserved)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 00000000e0000000 - 00000000f0000000 (reserved)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 00000000fec00000 - 00000000fec10000 (reserved)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 00000000fee00000 - 00000000fee01000 (reserved)
Jun 20 15:52:44 laptop kernel: [    0.000000]  BIOS-e820: 00000000fff80000 - 0000000100000000 (reserved)
Surely Linux isn't writing to the disk at the same time it's reading the e820, is it?

Re: How to do stuff before loading correct drivers?

Posted: Wed Jun 23, 2010 11:45 pm
by inx
In early boot, Linux is simply writing to the kernel ring buffer. Once the display is initialized, it's displayed.
If you really, really need kernel output before the display driver is loaded, I would recommend just writing
a very simple display driver to include in the kernel in, say, a separate executable section, page-aligned so
you can simply free that page when you're done with it.

Re: How to do stuff before loading correct drivers?

Posted: Thu Jun 24, 2010 7:12 am
by jal
inx wrote:I would recommend just writing a very simple display driver to include in the kernel in, say, a separate executable section, page-aligned so you can simply free that page when you're done with it.
I agree with having a simple output driver (can be output to a serial port as well), but that driver will be so small, it'll always be no more than a single 4KB page. I don't see the need to free it.


JAL

Re: How to do stuff before loading correct drivers?

Posted: Fri Jun 25, 2010 7:16 am
by TylerH
Thanks for your replies. I think I get what you're saying; that I should buffer output until the driver is loaded.

Re: How to do stuff before loading correct drivers?

Posted: Fri Jun 25, 2010 7:19 am
by jal
TylerAnon wrote:Thanks for your replies. I think I get what you're saying; that I should buffer output until the driver is loaded.
Yes, especially if you want to write the output to persistent media, e.g. in a log file. But if you want to display something on the screen while the OS is loading, a simple graphics driver (e.g. text mode only for x86) is the way to go (apart from buffering).


JAL

Re: How to do stuff before loading correct drivers?

Posted: Fri Jun 25, 2010 7:20 am
by Brendan
Hi,
TylerAnon wrote:I don't want the video/terminal driver in as part of my kernel(just doesn't seem right, not extensible), but I'd like to be able to output to the screen while I'm loading drivers and the like. How's this conventionally done?
With careful design, it's possible to start "boot modules" (that use the firmware to setup a video mode and output the contents of the Boot Log to screen, or handle serial ports to output the contents of the Boot Log to a dumb terminal, or whatever else) during boot, well before the kernel is started; and for these "boot modules" to end up looking like normal processes after the kernel is initialised (and they could even switch from direct hardware access to using the appropriate driver when drivers are started).

Before the boot module/s are running I use the firmware to display the Boot Log (e.g. "int 0x10, ah=0x0E"); and make the PC speaker beep if a serious error occurs (in case it's a headless system with no video).


Cheers,

Brendan

Re: How to do stuff before loading correct drivers?

Posted: Fri Jun 25, 2010 8:51 am
by TylerH
I'd been considering a design much like that; loading drivers as grub boot modules. But I came to the problem of how to transition those modules to processes after multitasking had been initialized. And how to connect all the things a normal process has like stdio. After multitasking, does the kernel itself need to be a normal process, or can it be it's own type of task?

Re: How to do stuff before loading correct drivers?

Posted: Fri Jun 25, 2010 10:51 am
by TylerH
I think I might go the initrd-like way. I'll have a simple file system that could be read be the kernel to find a simple port io hdd driver, a few file system drivers, and a terminal driver. Everything else could be stored on the disk and loaded when needed.