What are bootloaders?

When the computer is first turned on it has a clear state. Meaning there are no programs in it’s memory and it’s incapable of accessing its components (storage ,I/O devices etc)

So the first step that is required is to enable the computer to gain access to them. For this purpose as soon as the computer starts it runs a bootloader that bootstraps the startup process.

Bootloaders initialize the hardware and pass on the control to the kernel which proceeds to initialize the operating system. That’s all they do.

Since bootloaders sit between hardware and software they give booting choices to users. They can let us

  1. Choose from different operating systems

  2. Boot operating system into safe mode for recovery.

  3. Choose different versions of operating systems.

  4. Or boot directly into a program without starting the operating system first. (This is used for example in many game consoles,if you have a game disc inserted when you start the console.it can take you right into the game rather than a welcome screen)

For PCs the ROM contains BIOS (or EFI) that looks for a bootloader at a certain location and execute it [1]

As you might have guessed there are stages to a bootloader. The bootloader is read from a ROM and executed. At the end of this process I/O components and storage components are ready.

The computer has changed its state from passive just a powered in CPU, to active a device can use different parts. It can now use these components.

The last thing that remains for the first stage bootloader to do is find the second stage bootloader so that the control may be passed on to the operating system.

Now most of the times the second stage bootloader is located on a storage within a device itself. Some place in a hard disk. The first stage bootloader knows about this location and hence finds and executes the second stage loader.

From there on the OS kernel is loaded followed by os itself.

As it often happens at the time of a new purchase a hard disk,there may not actually be a boot record for the bootloader. Therefore the first stage bootloader allows the user to specify boot locations. Most modern bootloaders allow you to boot from

  1. CD/DVD

  2. USB stick

  3. Network disk

In case of storage medium like CD and USB, the devices are formatted so that the first stage bootloader can find the boot record on it.

For network booting a boot image is placed on a known location on a server. This image is downloaded and executed on the machine.

Most of the time the interaction with the bootloader is rather minimal. It’s only when you want to install a new operating system. Or want to diagnose problems with your existing ones/use a different os, is the time when you take the trouble of going to the boot menu.

But understanding the boot process is important if you want to learn how computers work.

All electronic devices are turned on in the same way. Whether it’s your mobile, your laptop, your gaming consoles or your PC. They all boot the same way.

But some devices use the concept of a boot image on a flash. In such devices that kernel and the bootloader is packed into a single file and written onto the flash. This approach is quite common in smart phones like Android and in devices like wifi routers. [2]

Packing the kernel and bootloader into a single image does not change the boot process in anyway however. A bootloader still initializes the hardware and then passes the control to the kernel which will initialize the operating system.

However packing the bootloader with the kernel makes it difficult for the user to make changes to the device the way he wants. ROMs need to be packaged in exactly the same way as the device expects it to. And running multiple OS is more difficult because now there is no separation between the kernel and the bootloader.

Switching an Android operating system for instance is not quite as straightforward as switching the os in PC. And impossible if the bootloader is locked (as it is in many phones)

Still because embedded systems have a lot less room than PCs it makes sense to pack things together.

Types of bootloader and UBOOT

Since there are many types of computer architectures and many operating systems it’s natural that the bootloaders are specific to architecture and operating systems. This means that are many, many bootloaders on the market. Often they are proprietary and incompatible with each other. However open source applications like DAS U Boot are standardizing the process.

https://en.m.wikipedia.org/wiki/Das_U-Boot

DAS U BOOT works on almost all the system architectures and provides both first stage and second stage bootloading. It can also be packed into an image consisting both the Linux kernel as well as a bootloader in a package.

References

[1]https://askubuntu.com/questions/173248/where-is-the-bootloader-stored-in-rom-ram-or-elsewhere

[2]https://android.stackexchange.com/questions/29706/can-somebody-explain-the-boot-process-of-an-android-device/29738#29738

[3] A presentation on the boot process

https://www.cs.tau.ac.il/telux/lin-club_files/linux-boot/slide0000.htm

workrockin@gmail.com

How is NVRAM used in a router?

NV RAM stands for non volatile random access memory. As the name suggests it’s used to store data that can be retrieved later. Unlike RAM the data is not lost after the device is powered off.

Flash is the most popular type of NV RAM. It’s used in USBs and also in “system on chips” to store firmware data. Because flash is significantly slower as compared to RAM the firmware is first loaded into the RAM before execution starts. To make it faster.

Since flash has limited write/delete cycles the on chip version is generally used for reading. Only at the time of firmware upgrades is the data written. This greatly increases the longevity of the chip. Otherwise a bad flash might render the whole thing obsolete.

[Although in some cases configuration parameters may also be stored on it]

[By the way flash is used not just in routers but also in many other devices like PCI cards, hard disks etc. Anywhere you need a boot process for a device, flash comes in handy for storing the firmware that “turns on” the device and make it ready for operation. Just like your computer needs to power on it’s components need to do the same]

How is bootloader used in a router?

The flash storage contains the bootloader that is executed every time the machine is powered on. There are many types of bootloaders both open source and proprietary and it’s execution is device specific. But all bootloader’s do three things

  1. Initialize the hardware

  2. Find the location of the kernel

  3. Execute the kernel and handover the control to it.

Once #3 is done the bootloader is no longer needed.

Because bootloader is executed before the kernel there are some special features that can be used especially in an embedded environment like a router that has no visible interface for handling errors(No monitor etc)

  1. Supporting additional boot devices. Like booting from USB or over the network.[ Networking booting is one of the most popular ways to boot embedded devices. ]

  2. Upgrading firmware “over the air”.

  3. Verifying the authenticity of the firmware.

But of course since bootloader controls the kernel execution, oftentimes manufacturers impose limitations on users ability to change it giving the excuse of security.

It’s quite common to see in Android phones in which the owner can’t change the operating system just because the bootloader is locked. Making it yet another way to control the usage after the device has been sold.

workrockin@gmail.com

Design a site like this with WordPress.com
Get started