what is the need of second stage boot loader ? why different bootloaders like first stage and second stage?

Pradeep G picture Pradeep G · Mar 17, 2014 · Viewed 7.7k times · Source

I know the first stage boot loader will make basic hardware initializations and calls the second stage boot loader like u-boot. But I still do not understand for why we need multiple stages of boot loaders.

Why can't we have only one boot loader, where we flash a single image to initialize the hardware? What would be the disadvantages going with only one stage of boot-loaders loading the kernel image directly? to make it more clear am using ARM CORTEX A8 for beagle bone black where I place MLO,U boot and kernel image in a boot Portion,as far as my knowledge first stage boot loader initializes your external RAM, where U-boot is copied,which initializes some more peripherals,why I cannot go picking up the kernel image directly instead of second stage boot loader

Answer

Vinod Patidar picture Vinod Patidar · Mar 17, 2014

Remember that bootloaders, and bootsectors, are only 512 bytes in size. If the bootloader, within that same 512 bytes, executed the kernel directly, it is called a Single Stage Bootloader.

The problem with this, however, is that of its size. There is so little room to do alot within those 512 bytes. It will be very difficault to set up, load and execute a 32 bit kernel within a 16 bit bootloader. This does not include error handling code. This includes code for: Loading and finding 32 bit kernel, executing kernel, and error handling. Fitting all of this code within 512 bytes is impossible. Because of this, Single stage bootloaders have to load and execute a 16 bit kernel.

A Multi Stage Bootloader consists of a single 512 byte bootloader (The Single Stage Loader), however it just loads and executes another loader - A Second Stage Bootloader. the Second Stage Bootloader is normally 16 bit, however it will include all of the code (listed in the previous section), and more. It will be able to load and execute a 32 bit Kernel.

The reason this works is because the only 512 byte limitation is the bootloader. As long as the bootloader loads all of the sectors for the Second Stage loader in good manner, the Second Stage Loader has no limitation in size. This makes things much easier to set up for the Kernel.

because first-boot loader initialize required MEMORY, Hardware,and some external device so that time there is no limitation of MEMORY>>>