BOOT LOADER BY ETHERNET CARD WITH RTL8139 CHIPSET

Contents:

Introduction
Ethernet driver
Download
Quick instructions to try the boot loader
How to install a TFTP server
Tips on the server
How to boot other OSes
Menuet Operating System
How to compile the source code
Forum
QUICK INSTRUCTIONS TO TRY THE BOOT-LOADER

These are brief instructions to try the boot-loader. These can be useful if you already know a little about TFTP server configuration and Menuet Operating System.
You must have two computers, the client that will boot MENUET and the server that will provide the files.

ON THE CLIENT

You must download a small image and put it on a floppy with the RAWRITE utility.
This floppy must be putted in the computer you want to boot.
ON THE SERVER
You must have an OS with TCP/IP networking.
I advice you to use either LINUX or WINDOWS. I have tried the boot-loader with them and it works fine.
You must have a TFTP server installed. (Not FTP, a TFTP server !).
Your server must have the 192.168.0.1 IP address.
Under LINUX  you can use the command
> ifconfig eth0 192.168.0.1
If your server will run under WINDOWS, you have to change the network settings . You have to insert the IP address 192.168.0.1.
The next step is to install  two files (img00 and img01) in the root directory.
Under LINUX you will have /img00 and /img01 while under WINDOWS you will have (if you use the C drive) C:\img00 and C:\img01.
img00 is a compiled MENUET kernel with a small modification: that is it has been added a simple jmp instruction to jump the code to load the floppy data. This modification is explained later in this page,so that you can modify your kernel.
img01 is the image of a floppy (the usual mfloppy.img). If you have got already a recent MENUET distribution you can decide to don't download this file. You have to use your mfloppy.img, rename to img01 and put it in the root directory.
Obviously you must connect the server and the client with ethernet.
Now you can try the boot-loader. Put the floppy in the driver of the client and press the RESET button.....
After 1 second, you should see MENUET OS on the client !!!
HOW TO INSTALL THE TFTP SERVER

FOR LINUX USERS

If you are not able to install a TFTP server, try to read these lines. I hope they can help you.
I hope you are already able to do it.
I'm not an expert of networking, but I will try to explain to you.
In your LINUX distribution you can have two different internet deamons: To know which is your deamon you call use this command
> ps -ax | grep -i inetd
If you see xinetd, you have got the xinetd deamon.
If you see inetd, you have got the inetd deamon.
I know that the Slackware distribution use inetd, while Mandrake uses xinetd.

INETD

If you have a file called inetd.conf in the /etc directory, you have to edit this file.
To enable the server you have to have the following line:
tftp dgram udp wait nobody /usr/sbin/tcpd in.tftpd
Note that the # character is use for commments !
Now you should kill the inetd with the command
> killall -HUP inetd
and restart it with
> inetd
Now you have got a TFTP server installed on your system.
XINETD
XINETD is a new version of INETD.
There is not only a configuration file as the INETD.
If you have understanded how configuring INETD, you will be able to configuring XINETD with a small effort.
FOR WINDOWS USERS
Setup a TFTP server under WINDOWS is very easier than under LINUX.
Here there is a link to TFTP server. It is a small and simple exe file and it doesn't require any particular installation. To run it you have to launch it at the command line. You have to set the base directory as "C:\", that is the root directory. Then you have to copy the img00 and img01 files on the root directory.
So you will have on the server the files C:\img00 and C:\img01.
ADDITIONAL ADVICES
I advice you to try to make a TFTP connection with the server by a simple tftp program.
In this way you can be sure that the server will send the images.
If it works, probably the boot-loader will work fine.

You can make a TFTP connection with
> tftp 192.168.0.1
  status
  .....
  (You can see if there is the connection or not)

  binary
  get img00
  get img01

DOWNLOAD
 
File  Description Last update
image.zip Image to copy on the client 5 Jul 2002
img00.zip Modified kernel image to copy in the root directory on the server 10 Feb 2002
img01.zip An image of the MENUET OS distribution (the usual mfloppy.img file).
You can decide to don't download this file if you have got already a recent mfloppy.img file.
10 Feb 2002
src.zip Source code to make the boot-loader (the image.zip is the compiled image from this source) 5 Jul  2002

HOW TO MODIFY A KERNEL TO BOOT BY RTL8139

At the beginning of the kernel there is the code to read the floppy.
You can delete this code, but I advice you to use a jmp instrucion to jump that block of code.
In the kernel you see
 
(about line 720)
;    read_disette to memory
     mov si,diskload
     call print

....
....
....
 

(about line 836)

readdone:
     pop ax

     mov dx,0x3f2
     mov al,0
     out dx,al

You must ADD a jmp instruction.
The new code will be
 
;    read_disette to memory
     jmp avoid_floppy_reading

     mov si,diskload
     call print

....
....
....
 

(about line 836)

readdone:
     pop ax

avoid_floppy_reading:
     mov dx,0x3f2
     mov al,0
     out dx,al

After the modification the kernel must be compiled.
The new compiled kernel must be copied in the root directory with the name img00
Now the kernel can be booted.

TIPS ON THE SERVER

If you use LINUX as server, you can use the MOUNT command to see and work on the contents of a floppy image.
To do it, you need to enable the LOOP DEVICE in the kernel configuration. This is in the menu BLOCK DEVICE.
Then you have to compile the kernel.
Now you can use this ability.
If you have a /img01 (a floppy image 1.44MB large) and an empty directory /menuet, you can use the command
> mount /img01 -o loop /menuet
Now go in the menuet directory with the command
>cd /menuet
You can see the content of the mfloppy.img image with the ls command.
You can use all the programs you usually use (GCC, NASM, vi,....).
When you have finished (for examaple you have edited a file and then compiled it) you have to unmount the device with the command
> umount /menuet
Now you have the /img01 that contains the modifications.
With this method you can write a MENUET application and try it (if it works) with the RTL8139 boot loader.

INTRODUCTION TO BOOT-LOADING

If you have tried to write your own operating system, you know that each proof require a lot of time because you have to put the kernel and other data on a floppy disk, reboot the PC with the floppy disk and verify if the changes works fine.
If you have got two computer you can save a lot of time because a PC run an operating system with all the programming tool (like a C compiler, an assembler, a linker, ...) and the other can be used for the reboot process.
If you have got two ethernet cards you can do better, that is you can use the ethernet card instead of the floppy disk. The ethernet card can transmit 1-10 MB/sec, so loading an image of 1.44MB can e done in less than a second. Loading an entire floppy disk require much more time instead.
Now I will try to explain the process of ethernet-booting.
Let imagine we have got two PC, PC-A and PC-B, connected by an ethernet card.
PC-A has got floppy drive that constains a small program. This program will try to get an image from the PC-B, put it in the RAM and execute it.
We can use the internet protocol to do it. For example we can use

This method is good because you can use different OS in PC-B, for example LINUX ,WIN ,BEOS, *BSD.
An easier way is to write a program and run it in the PC-B. You don't use the standard protocol but your own protocol. The disadvantages is that this program will be different for each OS.

ETHERNET DRIVER

I have got two PC, both with an ethernet card with the RTL8139 chip, and the code from an open source project called ETHERBOOT. The target of ETHERBOOT is similar to my boot-loader but it has been written to boot very famous OSes like WINx, Linux, *BSD but the documentation doesn't explain how booting a generic kernel-image.
Because of this reason and because I like low-level programming I have decided to write a simple boot-loader.
Probably you know that the GNU C compiler (GCC) makes 32bit code in a flat model, that is your application can use a block of memory to contain the code and the data. If you are not sure of this, you can write a simple C program and then compile it with the -S switch. It tells the compiler to produce an assembly output, so you can study the generated code.
A great advantage of the flat model is that you don't have got the classic problem of addressing maximum 64KB data bacuase you can address a memory cell with 32bit registers.
You cannot use directly a routine compiled by GCC in DOS because DOS requires that applications must work in real-mode. How is it possible execute a routine compiled with the GCC and execute it in DOS ? You have to insert a small code 16bit that

These simple tasks are carry out by the rm2pm.asm code. This is also a good example to begin to study the protected mode.

MENUET OPERATING SYSTEM

I have written the boot loader to simplify the boot process.
In this period I have worked for the MENUET OS (www.menuetos.org). This is a small OS enterely written is assembly 32 bit and now it has got a small libC library, so you can use the GCC compiler to make your programs. I hope my boot loader can help to develop both the Menuet kernel and Menuet applications.

HOW TO BOOT OTHER OS

In this page I have explained how to use te boot loader to load the MENUET OS.
But it is very easy to modify it to boot some other OSes.
You have only to change some lines in the files rm2pm.asm and main.c.
In the main.c you have to go to the end of the file.
There is the code

get_file(0x10000);
.....
writeb('1',request+34)
get_file(0x100000);
The name of the first file to download is always img00.
The get_file(0x10000) command get the img00 image and put it in the RAM at the physical address 0x10000. If  you are accustomed to think in real-mode this address is 0x1000:0x0000. Then you have to download the img01. You have to change the character '0' to '1' of the string of the filename and then call another time the command get_file. I need to save img01 image at the physical address 0x100000, so I have to  use the command get_file(0x100000).
If you need to download another image (img02), you have to add the code
writeb('2',request+34)
get_file(<physical address>);
In the rm2pm.asm you have to adjust the address of the jmp instruction.
If your kernel has been loaded at the address 0x10000, you have to use a jmp instruction to jump to that location.

HOW TO COMPILE THE SOURCE CODE

To compile you need DOS (WIN) or LINUX.
The compilers you have to use to compile the source code are GNU C (C compiler) and NASM (assembler).

FOR DOS (WINDOWS) USERS

To make the floppy you have to insert a floppy in the drive and use
> make floppy
This floppy will be used for booting the client.
If you peek the make.bat, you can see that there is also the option "dos"
that can be used by the command
> make dos
It is used only for developers and it is used for testing in DOS.
With this option, a COM file is created. This program is useful for testing
if te network works fine.
The option "dos" must not be used for normal users but only for developers.
FOR LINUX USERS
To make the floppy you have to insert a floppy in the drive and use the script
> ./make-lin
This floppy will be used for booting the client.
There is not an option "dos" as the DOS users.