Programming Tools - The QNX Boot Process
By Chris McKillop, QNX Software Systems Ltd.
This series of articles will talk about how the QNX Realtime
Platform boots and how you can change the boot behavior
of your system.
This first article covers:
- the two different ways that current installs are booting
- what’s in a boot buildfile
- how to make a boot image.
Two ways to boot
In the current RTP release, there are two different ways that
QNX can be booted:
- directly from a QNX partition using the QNX boot loader
- indirectly from a FAT partition using a DOS device driver.
QNX boot loader
The QNX boot loader loads the images residing in /.boot (or
/.altboot if you hit the ESC key when prompted to boot an
alternate OS) directly from the QNX partition. So when you
make a new image, you can copy the image (.ifs) file to
/.altboot and hit ESC at boot time to try out your new
image. (If you’re already hitting ESC to boot the non-DMA
image, consider swapping your current .altboot for .boot so
you don’t have to hit ESC anymore.)
DOS device driver
The DOS device driver has a little more flexibility than the
QNX boot loader, since there’s already a set of rudimentary
I/O services provided by DOS when the driver loads. You can
also take advantage of the DOS config.sys menu system. Here’s
a sample config.sys from an installed system:
[menu]
menuitem=WIN, Windows
menudefault=WIN,30
menuitem=QNXDMA, QNX Realtime Platform
menuitem=QNX, QNX Realtime Platform (DMA Disabled)
menucolor=7,0
[QNX]
DEVICE=C:\PROGRA~1\QNX\boot\bin\loadqnx.sys
C:\PROGRA~1\QNX\boot\fs\qnxbase.ifs
[QNXDMA]
DEVICE=C:\PROGRA~1\QNX\boot\bin\loadqnx.sys
C:\PROGRA~1\QNX\boot\fs\qnxbas~1.ifs
[WIN]
[COMMON]
To add a new boot image, simply add a new menuitem line and
a properly labeled configuration block. For example, if you had a
new boot image called custom.ifs in C:\Program Files\qnx\boot\fs,
you could do the following:
[menu]
menuitem=WIN, Windows
menudefault=WIN,30
menuitem=QNXDMA, QNX Realtime Platform
menuitem=QNX, QNX Realtime Platform (DMA Disabled)
menuitem=CUST, QNX custom.ifs
menucolor=7,0
[QNX]
DEVICE=C:\PROGRA~1\QNX\boot\bin\loadqnx.sys
C:\PROGRA~1\QNX\boot\fs\qnxbase.ifs
[QNXDMA]
DEVICE=C:\PROGRA~1\QNX\boot\bin\loadqnx.m information
for the kernel, putting the kernel in the right position in memory,
and starting the execution of the kernel.
What’s in a boot buildfile?
Unlike many operating systems, the .ifs boot image is more then
just a kernel and its startup code. There are actually programs
and libraries stored in the image as well as a simple startup
shell script.
The image is built with a program called mkifs (Make Image
FileSystem), which reads in a buildfile that tells mkifs what you
want in your image and what actions the startup shell script
should perform.
You’ll find several buildfiles on every installed system in the
directory /boot/build. We’re going to examine the file
qnxbasedma.build, one of the standard buildfiles found in that
directory. Here’s a full listing of that file:
[virtual=x86,bios +compress] boot = {
startup-bios -s 64k
PATH=/proc/boot:/bin:/usr/bin LD_LIBRARY_PATH=
/proc/boot:/lib:/usr/lib:/lib/dll procnto
}
[+script] startup-script = {
slogger -l /dev/text
seedres
pci-bios
waitfor /dev/pci
[pri=10o] PATH=/proc/boot diskboot -D1
}
[type=link] /dev/console=/dev/con1
libc.so
[type=link] /usr/lib/ldqnx.so.1=/proc/boot/libc.so
libcam.so
io-blk.so
cam-disk.so
fs-qnx4.so
fs-dos.so
cam-cdrom.so
fs-cd.so
[data=c]
seedres
pci-bios
devb-eide
devb-ncr8
devb-aha8
diskboot
slogger
The full syntax of these buildfiles is covered in the online docs
for mkifs (in the Neutrino Utilities Reference).
The first section of this file tells mkifs what processor this
buildfile is for (x86) and what IPL to use (bios). It then lists the
startup program to use (startup-bios) and the kernel to use
(procnto). You’ll probably never need to change these lines
when booting on a standard x86 PC. The next section is where
things start to get interesting.
The block that starts with [+script] is a script that’s run after
the kernel has started. This script lists the programs that will
be run and actions that will be taken as the system boots.
In this buildfile, the first program is slogger, the System Logger
that logs system events and messages. After slogger has started,
seedres is run in order to populate the system resource database
with information on the hardware of the system (IRQs, I/O ranges,
etc.). The pci-bios server provides PCI services to applications
and device drivers. This is a very critical program, because nearly
everything that runs on a modern PC needs PCI to function properly.
To ensure that the PCI server is running before the rest of the
programs are started, the script waits for /dev/pci to appear in
the filesystem.
Finally, the program diskboot is run. The diskboot program detects
what kind of hard drive controller is in your system and probes
all the different partitions to look for a bootable QNX
installation.
The lines that follow after the closing } of the startup script
are libraries and binaries that will be included in the system.
Libraries are listed first, since they’re shared items. The line
[data=c] signals that the files that follow are binaries that need
unique data sections, but can share code. If you type ls -l
/proc/boot on a running system, you’ll actually see the files
that are stored in the image you booted.
How to make a boot image
To conclude this first article, let’s make a small change to
qnxbasedma.build, build an image, and try booting it.
- Make a local copy of the buildfile by copying it into your home
directory:
cp /boot/build/qnxbasedma.build $HOME
- Now, using your favorite editor, let’s add a line to this
buildfile. (Make sure if you’re using the Photon Editor (ped)
that it isn’t saving formatting data to the end of the file.) In
the startup-script block, we want to add a line to display a
message when we boot. So, make your script section look
like this:
[+script] startup-script = {
slogger -l /dev/text
seedres
pci-bios
waitfor /dev/pci
display_msg “QNX Realtime Platform - Custom Boot Image #1”
[pri=10o] PATH=/proc/boot diskboot -D1
}
We’ve added the line with display_msg. This will print a string
before diskboot starts so you’ll know you’re booting the new image
you’ve made.
3. Now we need to run mkifs and install the resulting image file.
Simply open a terminal window (pterm), go into your home
directory, and then run:
% mkifs -v qnxbasedma.build custom.ifs
You’ll see a bunch of information printed to the terminal about the
different files in the image. When it’s finished building, you’ll have
a nice custom.ifs file that you can either copy to /.altboot or into
a DOS directory (normally found in /fs/hd0-dos/Program Files/qnx
/boot/fs). If you’re using DOS to boot your image, be sure to edit
config.sys under DOS, NOT under QNX - some QNX editors will
save the config.sys file in a UNIX format that DOS won’t understand.
Now when you reboot, you should see your message displayed
on the screen as the boot script runs.
In the next article in this series, we’ll make two custom boot
scripts. One that does the work of diskboot and one that simply
starts a shell and lets you interact with the system without
mounting any hard drives!
In the third and last article in this series, you’ll see how to
make a QNX boot floppy suitable for setting up a simple network
server or as a recovery floppy.
Happy booting!