PROGRAMMING LinuxBIOS

The LinuxBIOS project Putting on your inuxBIOS releases yet another part If you haven’t come across the LinuxBIOS project [1] yet, you may be amazed at of your PC to Open Source software L– in this case, the BIOS chip itself. what it sets out to do. BY ANTONY STONE BIOS stands for Basic Input Output System, and the BIOS chip is installed on the motherboard by the manufacturer, and which most users, no matter which they run on their , hardly ever think about. They only ever see the BIOS screen when the machine is first up, and it is usually taken for granted as simply another piece of the hardware, which hardly anyone ever considers the idea of changing. The code inside the BIOS chip (which is simply a non-volatile memory device, so that the software is available immedi- ately the computer is powered on) is responsible for starting up the machine, checking for the presence of hardware such as memory and disk drives, and then initialising them so that the real operating system can start booting. Without the BIOS, your computer would be tedious and inconvenient, to say your own is whether your motherboard do absolutely nothing when it was the least. is compatible and supported. A very turned on, because the BIOS contains LinuxBIOS also provides a good wide range of , from an the very first instructions which the CPU amount of bootup diagnostic informa- impressive list of manufacturers, are executes in order to start everything tion on the system’s , and supported by the LinuxBIOS project, and working. allows control of the bootup process your first step should be to check on the The LinuxBIOS project replaces the from a serial terminal as well. This can LinuxBIOS website to find out which normal BIOS code on your motherboard make of hardware problems, models are likely to work. The most with the Linux kernel itself, so that your or reconfiguration of a system, much important requirement for a mother- machine boots instantly into Linux easier than the usual vendor-specific board to run LinuxBIOS is that it has a within seconds of turning it on. keyboard-and-screen method. BIOS chip which is removable from its LinuxBIOS has more advantages than This article shows you how to swap socket, since this is how you change the simply very fast boot times, however. your BIOS chip for LinuxBIOS, and physical chip containing the old BIOS LinuxBIOS has been mainly developed explains the detailed steps necessary to code for a larger capacity memory chip for cluster systems, because it allows compile the kernel and program the code containing the LinuxBIOS code. far greater remote management and into a LinuxBIOS chip. Note that since This article describes the PC-Chips’ configuration than a standard BIOS chip LinuxBIOS is still very much a work in M810LMR motherboard, which is a fairly does. If you have lots of servers progress, some details might have cheap but nicely integrated board, con- configured in a cluster, and you need changed since this article was written. taining on-board VGA, ethernet and to change a (normal) BIOS setting, then sound. However, the steps needed for going around connecting a screen and Hardware installing LinuxBIOS on any other sup- keyboard to each machine, rebooting The first thing to check if you’re plan- ported motherboard are very similar to and making a manual change can ning to create a LinuxBIOS system of those shown here.

76 March 2003 www.linux-magazine.com LinuxBIOS PROGRAMMING

The other main item of hardware Note that, although it is possible to use required in order to create a working a “development system” for creating the LinuxBIOS system is the Disk-on-Chip LinuxBIOS code, programming this into memory device, which will be plugged the DoC, and then placing this into a into the BIOS socket on the mother- separate “target system” which will board, and which has the capacity actually run the code, it is in fact just as to contain the Linux kernel and the small simple, and more convenient, to use a amount of bootstrap code which single machine as both development and LinuxBIOS generates to initialize the target systems at the same time. It is motherboard hardware. assumed that you are already familiar Disk-on-Chip devices are memory with performing a basic Linux chips which can be “formatted” to appear installation on a machine, and that you like a hard disk device, and which can are comfortable with compiling a kernel contain a standard Linux filing system. and installing it. The steps involved in Figure 1:The ZIF socket plugged into the mother- The LinuxBIOS project uses the Disk-on- creating a LinuxBIOS machine are: board, with the original BIOS chip inserted Chip (DoC) to hold the bootup code, and •Install Linux on your target machine, also optionally a root filing system (so it including support for the flash DoC you can look underneath the ZIF socket is in fact possible to create a completely devices (which most kernels will not as you are inserting it. standalone diskless machine). have as standard) Once the ZIF socket is in place, lift the The specific DoC device used in this •Get the LinuxBIOS source code lever, insert the original BIOS chip (plac- project is the M-Systems’ MD-2800-D08 • Get the correct Linux kernel source, ing the notch or dot at the lever end of (part number MD-2802-D08 is a suitable it and build it the socket) and lower the lever to secure alternative as well). This device is an 8 • Configure and build the LinuxBIOS the chip in place. Then reassemble the megabyte flash-programmable device boot code for your motherboard motherboard into the case and power up which fits into the standard 32-pin •Get the Memory Technology Devices the system to make sure you get the socket used by the 2 megabit BIOS chip. (MTD) utilities and build the “erase” usual BIOS startup screen, confirming Note the slightly confusing contrast utility that the ZIF socket and BIOS chip are between the DoC devices, which are •Remove the BIOS chip from its socket correctly installed. measured in , and the standard (with the power on!) and put a Disk- If you don’t already have Linux Flash Rom BIOS chips, which are on-Chip in its place installed on the machine, install a basic measured in bits. The DoC has a • Burn the LinuxBIOS image containing Linux system; note that you will require capacity 32 times that of the BIOS chip it the boot code and the kernel into the the usual development tools ( is replacing; the simple reason for this Disk-on-Chip etc.) for building your own kernel, and being that it is not possible to fit the •Hit reset to start the new LinuxBIOS you will also need to install Python, as Linux kernel into 2 megabits. system. this is used to create the configuration Finally, it is highly recommended that It is a good idea to plug the ZIF socket files used for LinuxBIOS. you obtain a 32-pin Zero Insertion Force into the motherboard, and then place the The first thing you should do after (ZIF) socket in order to make removal original BIOS chip into the ZIF socket in installing the basic system is compile the and insertion of the BIOS and DoC order to start the system up (Figure 1). kernel which will be used to create the devices simple and safe. Part of the Firstly, note the orientation of the BIOS LinuxBIOS system, so that it contains process for programming the code into chip in its socket (there is a notch at one support for MTD (Memory Technology the DoC device involves removing the end, or a dot in one corner, of the chip), Devices), which is unlikely to be standard BIOS chip and replacing it with remove the chip, and plug the ZIF socket included in a standard kernel. It is the DoC device – while the power is on into the motherboard socket. Place the important that you have support for and the motherboard is running. lever of the ZIF socket at the same end of loadable modules on the development Attempting this without the use of a ZIF the socket as the notch or dot was on the machine, since for programming the DoC socket is definitely not recommended. BIOS chip. device in the BIOS socket of the mother- You may need to bend the pins of board, it is necessary to run a command Getting started connectors nearby to get the ZIF socket before loading the DoC support modules, The first thing you should do is read the to fit – on the M810LMR there is an and therefore you cannot compile this LinuxBIOS FAQ, available from the web- unused 3-pin fan connector in the way. support directly into the kernel. site [1], and also the LinuxBIOS Make sure you plug the ZIF socket If you use make menuconfig to config- documentation for your chosen mother- cleanly into all 32 holes on the socket on ure your kernel, the additional options board, which in the case of the the motherboard – it’s easy to miss a you need to select (accurate for a 2.4.19 M810LMR being used here, is based couple of pins at one end and get the kernel) in order to build LinuxBIOS into around the SiS630 . The FAQ whole thing moved along one place. You a DoC device are given in Listing 1. gives you a good idea of the overall will probably want to do this with the There is an important change needed process, and the steps involved. motherboard not installed in a case, so in one of the kernel source files in order

www.linux-magazine.com March 2003 77 PROGRAMMING LinuxBIOS

to get MTD support working properly. If about failed to open ./cvspass for You may be able to apply the patches you do not make this change, you will reading, and even login aborted: fatal to a different kernel, but at this stage in get errors later on when you try to erase error: exiting. Carry on with: the game it’s probably better to build an or program the device, such as: old kernel strictly by the instructions, export CVS_RSH=ssh and make sure you can get LinuxBIOS /dev/mtd0: No such device cvs -d:pserver:[email protected] working at all. Then afterwards you can /dev/mtd0: Bad file descriptor freebios.sourceforge.net:U try to bring the kernel up to the version /cvsroot/freebios login you’d like it to be. The change required is in the kernel cvs -z3 -d:pserver:anonymous@U This article discusses kernel version source file /usr/src/linux/drivers/mtd/ cvs.freebios.sourceforge.net:U 2.4.19, because this was the most recent devices/docprobe.. Change the line /cvsroot/freebios co freebios kernel patch file available for the which reads: M810LMR motherboard. In this case the Note that the LinuxBIOS project has patch file is called linux-2.4.19-sis.patch #define DOC_SINGLE_DRIVER grown from an earlier project named and is found in the FreeBIOS source tree FreeBIOS, and therefore this directory under freebios/src/kernel-patches. This so that it becomes: name will appear throughout the files directory contains both the patches for used in compiling the LinuxBIOS system. the kernels, and also sample config files #undef DOC_SINGLE_DRIVER Before unpacking a fresh kernel source for building the new kernel (note that to patch with LinuxBIOS, check the Lin- not all of these are guaranteed to work in Next, get the LinuxBIOS source by CVS uxBIOS kernel patches to see which all situations – you may need to look at from sourceforge. Press [Return] at the kernel version is supported for your other config files and make some manual password prompt and ignore errors motherboard / chipset. adjustments to get your particular setup working). Listing 1: Kernel options required It is important to recognize that the kernel patches and config files are for the Loadable module support kernel you will eventually program into [*] Enable loadable module support the DoC device and boot your LinuxBIOS [] Set version information on all module symbols machine from. They may not be the best [*] Kernel module loader choice for the kernel which you use to build LinuxBIOS and burn the DoC Memory Technology Devices (MTD) before rebooting it. When you build the Memory Technology Device (MTD) support kernel, simply use make bzImage and []Debugging then leave the compiled kernel where it <> MTD partitioning support is. LinuxBIOS will later look for the file <> MTD concatenating support /usr/src/linux/ as the image to --- User Modules and Translation Layers be included in the DoC device. Direct char device access to MTD devices <> Caching block device access to MTD devices Building LinuxBIOS <> Readonly block device access to MTD devices It is recommended that you create your <> FTL (Flash Translation Layer) support own config file based on one of the <> NFTL (NAND Flash Translation Layer) support examples, and make the build images for RAM/ROM/Flash chip drivers ---> programming into the DoC device, in a Mapping drivers for chip access ---> different directory outside the FreeBIOS Self-contained MTD device drivers ---> source tree. This will ensure that they are <> Ramix PMC551 PCI Mezzanine RAM card support not deleted when you update your copy <> Uncached system RAM of the source code from the CVS reposi- <> Test driver using RAM tory. Because of the way the directory <> MTD emulation using block device names are arranged, it is recommended --- Disk-On-Chip Device Drivers that you create a new directory called <> M-Systems Disk-On-Chip 1000 linuxbios side by side with freebios, and <> M-Systems Disk-On-Chip 2000 and Millennium build the DoC images in there: M-Systems Disk-On-Chip Millennium-only alternative driver [*] Advanced detection options for DiskOnChip mkdir linuxbios (0) Physical address of DiskOnChip cd linuxbios [*] Probe high addresses cp ../freebios/util/config/U [] Probe for 0x55 0xAA BIOS Extension Signature NLBConfig.py . cp ../freebios/util/config/U NAND Flash Device Drivers ---> pcchips.config .

78 March 2003 www.linux-magazine.com LinuxBIOS PROGRAMMING

The first cp command copies the Python Once you have these files, and you have ZIF socket and plugged it into your program which is used to process the compiled your target kernel (which is motherboard. configuration file, so that it is in a left sitting in /usr/src/linux/vmlinux), convenient place for use later on, and you can run the makefile to build your Programming the chip the second copies the standard LinuxBIOS image: With the power on and your system run- pcchips.config file (which is the one ning, release the lever on the ZIF socket, appropriate to the motherboard used in cd pcchips remove the original BIOS chip and this article) into the newly-created make clean replace it with a Disk-on-Chip. Be very linuxbios directory, where we shall be make careful to get the orientation correct (the carrying out the work. Having copied the notch in the end of the chip goes at the pcchips.config file into the working direc- Next copy the burn_mtd utility into the lever end of the socket) and make sure tory, edit the new file and make the newly-created pcchips directory, because the pins are lined up properly – remem- following changes: by default burn_mtd looks in the current ber that the socket has power on it. •Remove single from the end of the ker- directory for the source files to burn into Secure the DoC in place with the lever on nel commandline, so that the the DoC device, so there’s a lot less typ- the ZIF socket. Run the command: LinuxBIOS machine boots into stan- ing involved if the utility is in the same dard multiuser place. ./burn_mtd •Add cpu k7 if you are using an processor cp ../../freebios/util/mtd/U and it should program a LinuxBIOS chip, •Add option ENABLE_MII=1 to get the burn_mtd . ready to run on your motherboard. The onboard ethernet working output of burn_mtd should look some- • Change option HAVE_FRAMEBUFFER The burn_mtd utility doesn’t quite thing like: to option HAVE_FRAMEBUFFER=1 match the filenames generated by the (this is simply to eliminate a warning Makefile, so it is useful to edit burn_mtd # ./burn_mtd message later on). (which is simply a shell script), in order rmmod: module docprobe is not There may also be some editing of files to use the correct names: Change the loaded needed in the LinuxBIOS source tree – first two occurrences of vmlinux (one in rmmod: module doc2001 is not for example, in the version of LinuxBIOS the comment on line 3, the other in loaded being used here, a change is needed in linux=vmlinux.bin.gz on line 16) to rmmod: module docecc is not order to get the keyboard working on linux (so that line 16 now reads loaded this particular motherboard. In the file linux=linux.bin.gz). 11+1 records in freebios/src/arch/i386/lib/hardware- The next step is to get the MTD utili- 12+0 records out main.c, uncomment the function call ties from [2] and build the “erase” utility 0+1 records in keyboard_on() around line 344. If you – simply download the current version of 1+0 records out don’t do this, then when you finally boot the kernel tools under the ChangeLog Erase Total 1024 Units your LinuxBIOS machine, you will get section, and then make erase in the util Performing Flash Erase of length several hundred error messages pc_keyb: subdirectory of the download. 8192 at offset 0x7fe000 done controller jammed (0xFF), and your key- The final utility needed for program- 1+0 records in board will not work. It will not stop your ming the DoC devices is flash_on from 1+0 records out LinuxBIOS system from working, how- the freebios/util/sis directory. This utility 1+0 records in ever – you will still be able to log in on allows you to use the BIOS socket on 1+0 records out the serial port, or ssh across the net- your motherboard as a flash 126+0 records in work. (thus saving the need for an expensive 126+0 records out After making these changes, run the separate piece of equipment specially for 1536+0 records in Python program to create the build files: this job): 1536+0 records out # python NLBConfig.py U cd ~/freebios/util/sis pcchips.config ~/freebios make flash_on If at this stage, you get the following instead: This creates a subdirectory within the Copy the “erase” and “flash_on” utilities linuxbios directory called pcchips, and which you just built into your search # ./burn_mtd creates the following files in it: path (for example /usr/local/sbin). Now rmmod: module docprobe is not comes the interesting part of program- loaded LinuxBIOSDoc.config ming LinuxBIOS – removing the BIOS rmmod: module doc2001 is not Makefile chip from a live, running motherboard, loaded Makefile.settings and replacing it with the Disk-on-Chip. rmmod: module docecc is not crt0_includes.h This is the point where you are loaded nsuperio.c grateful you got yourself a 32-pin 11+1 records in

www.linux-magazine.com March 2003 79 PROGRAMMING LinuxBIOS

12+0 records out system etc.). They can easily get sorted src/linux/vmlinux), you should be able 0+1 records in out later. The important thing at the to create and format a partition in the 1+0 records out moment is to have a running kernel at remaining capacity of the Disk-on-Chip File open error all. If you do not get a penguin on your device: : opening '/dev/mtd0': screen followed by the normal kernel No such device startup messages, and in fact get nothing nftl_format /dev/mtd0 0x100000 dd: opening '/dev/mtd0': at all, then the best way to discover what No such device is happening with LinuxBIOS is to plug a nftl_format is in the linuxbios/mtd/util dd: opening '/dev/mtd0': serial cable into the first RS232 port, con- directory. You can then use fdisk No such device nect another system running a serial /dev/nftla to create a single primary par- dd: opening '/dev/mtd0': terminal such as minicom (set tition, occupying the entire available No such device to 115200 baud, 8 bits, no parity), and device (about 7 megabytes), and then # press reset. You should get some format this with mke2fs /dev/nftla1 in debugging information and startup the usual way. You can change the then you should check the kernel run- messages displayed on the terminal, device where the LinuxBios kernel ning on your machine: ensure that you which will help to indicate how far expects to mount the root file system by edited the file /usr/src/linux/drivers/ through the startup process the system is modifying the compiled kernel image mtd/devices/docprobe.c to undefine getting. If absolutely nothing happens, (before burning it into the DoC): DOC_SINGLE_DRIVER before building then it’s possible that you haven’t got a the kernel, that you selected the MTD suitable image burned into the DoC, so rdev /usr/src/linux/vmlinux U options listed earlier, and that you power off the motherboard, remove the /dev/nftla1 rebooted the machine after building the DoC and put the original BIOS back in kernel so that it is now actually running. again, power the system back up, and For suggestions on what to place into If the burn_mtd output looks good, see what you have missed from the such a small root fs and still have a your machine to test the code pro- above instructions. working Linux system, consult one of grammed into the DoC. If your system the tiny distributions such as Tom’s Root reboots and you see a penguin in the top Silicon disk Boot [3]. corner of your screen instead of an AMI The last thing you may want to do once or Award BIOS startup message, then your system successfully boots the Linux Conclusion you have succeeded in creating a Lin- kernel directly from the Disk-on-Chip, is I found the LinuxBios project absolutely uxBIOS system, booting the Linux kernel to create a root file system in the remain- fascinating, and it is an incredible way to directly from the DoC instead of the hard der of the 8 megabyte capacity of the boot your machine directly into Linux disk as usual. DoC, so that you can dispense with the quickly, easily, and at very little expense. Do not worry if bits of the system do inside your machine alto- I hope that you have as much fun with not seem to get started properly (e.g. gether. You will need a few more MTD the system as I have. ■ hard disk, ethernet, keyboard, root filing kernel options turned on in your development system INFO (to format and write Listing 2: Kernel options for MTD support [1] LinuxBIOS website: the root fs) and this Memory Technology Devices (MTD) http://www.linuxbios.org/ time also in the kernel Memory Technology Device (MTD) support [2] Memory Technology Device (MTD) running in the target []Debugging Subsystem for Linux: (so that it can read <> MTD partitioning support http://www.linux-mtd.infradead.org/ from the MTD-based <> MTD concatenating support [3]Tom’s Root Boot:http://www.toms.net/rb/ file system). The --- User Modules and Translation Layers options you should Direct char device access to MTD devices enable during make <> Caching block device access to MTD devices Antony Stone has a menuconfig for the degree in Medical <> Readonly block device access to MTD devices kernels are shown in Electronics,and has FTL (Flash Translation Layer) support listing 2. been working with NFTL (NAND Flash Translation Layer) support Linux since 1994. He is Once you have [*] Write support for NFTL (BETA) Technical Director of recompiled the ker- HOR RAM/ROM/Flash chip drivers ---> T Rockstone Ltd,a UK nels (remember to company producing Mapping drivers for chip access ---> install the kernel Linux-based Firewalls,and is a contrac- Self-contained MTD device drivers ---> to the development tor to Hewlett-Packard Laboratories, NAND Flash Device Drivers ---> THE AU working on secure operating systems system, and reboot, NAND Device Support design. He is a part-time lecturer on then leave the kernel [*] Enable ECC correction algorithm the Information Security MSc at the image generated by University of London. [] Verify NAND page writes make bzImage in /usr/

80 March 2003 www.linux-magazine.com