This post is going to be 4th part in series of making a Linux capable ARM Board at home. click First, Second and Third to go to previous Parts,so lets start.
what is a Bootloader, Why do we need it?
a boot loader is a program which is the first one to be executed by the CPU. it severs some very specific purpose "configuring few very essential things before loading the main program (may be OS) into main memory" , that is why it is called boot loader. depending on needs boot loader may do some other task(we will cover them here).
there are various shape and sizes of the bootloaders , they all serve almost same purpose.
with microcontrollers , some times it does not actually load the main program into memory but pass on the executing pointer to main program so that main program can run directly form the memory where it is.
|Board With 4.3 inch LCD running Qt5 application to display JPEG Image and Time|
Need of a bootloader in mircocontroller is different than CPU , for MCU bootloaders are generally ment to have capablity of software update. MCU are capable of executing without bootloader at all. bootloader are not required but they add some luxury.
Lets start with a simple mircontroller bootloader which updates the MCU firmware, there may be different type here also, depending on from where they receive main program and to where they write. like you may have a UART bootloader , which will come up every time CPU resets , in case of program update required or requested. Bootloader receive executable program over UART and program it into flash or just put into RAM(some Mircocontrollers have only RAM for execution like cypress CY7C68013A they always need to receive program on startup either via USB or external EEPROM , CY7C68013A has ROM based bootloader which is onchip , supplied by the cypress).another Bootloader may be USB based Bootloader will also do same , but it receive program over USB bus and program into flash or put it into RAM.
For mircontroller almost all the absolutely crucial peripherals (like RAM , Clock ,Power) are initialized by the chip in the hardware itself. microcontroller hardware know where exactly to look for program in the flash or in any other memory.with MCU everthing thing is onchip , hardware know where it what . he knows mebmory size and all the buses too. almost nothing can change or go wrong. all the peripherals on the MCU are hard-wired by the chip designer.
Need of Bootloader with CPU is different , they are responsible to configure some of hardware like external RAM parameters Size,Memory Bus width , timings , Power subsystem etc. they are also responsible to load the kernel file from a sophisticated file system rather than a fixed memory location. Bootloader is almost always required if you are trying to run some resource consuming main progam.
With CPU , hardware generally have a very basic ability "same as mircocontrollers" to load some "small" executable program from some fixed external memory (few processors have more than one option . like few CPU reads a particular sector in SD card or NAND flah. or even few processor are capable of loading the program from USB or UART. "almost" no CPU has onchip flash for customer code. after loading the program from external ROM into internal memory CPU start executing bootloader . please note that all descent CPU has large amount of RAM off Chip. but they still bootloader get into onchip RAM instead off chip RAM. because at the time of reset CPU doen't even know even the external RAM is connected , or even if it is connected then how it is connected. so the only way you can execute bootloader progam is onchip RAM , CPU start executing bootloader from onchip RAM and all the information about the hardware will be available with bootloader. Allwinner A13 has 48K SRAM onchip. all CPU are capable of running only with onchip RAM you don't need any external memory but as application demands we need to connect more RAM.
it is the same reason CPU can't just go and load OS out of external memory and start executing. because at the start-up , there is only a tiny amount of onchip RAM is considered to be usable.and you can not load comparably large size OS image into this small onchip RAM start executing.
you need some light weight program which can be loaded into limited amount of internal RAM , and configure all other stuff including Large External RAM, load OS file from some sophisticated source like , FAT or ext file system or even network into the Large RAM. and transfer the executing control to that.
u-boot is just one of many bootloader programs , the good things about this is , as then name says in it is universal bootloader , it already support many different architecture. because it is already ported by large community to may different Architecture it is very famous. it is open source.
u-boot already ported to the CPU which we are using here the Allwinner A13, u-boot already support the booting medium we need "FAT File system".
so it is always a wise choice to chose already ported U-boot rather than making your own . it is even worse to try porting some architecture specific bootloader to your platform.
but still as ever hardware is different in one way or another, some modification to u-boot required to support your new Hardware. like we have some RAM configuration changes, LCD power and Backlit controls are with the PMU and u-boot manage them. there can be many such things depending your hardware configuration.
sunxi is linux community that support allwinner procesosor
the sunxi uboot already ported to A13 CPU "not to our board" is availalb at this github repo
there are two branches there , one is "sunxi" branch which is leagcy u-boot , it support linux kernel 3.4 , and very very stable.
and there is one another branch that in repo which is underdevelopment branch , new branch support new version of kernel , but new version of kernel does not support many features like 3D graphics GPU acceleration etc. we need to stick with old version till there is stable new version of stable sunxi kernel is available.
so checkout legacy "sunxi" uboot branch ,
now we have code which already support our CPU , we just need to add some hardware configuration and u-boot configuration file , this process describe how to port or configure u-boot for the new custom linux broad you have.
u-boot has many different configuration file , board specific file and hardware configurations.
first of all you need to again look at the board from where you took reference hardware schematic. findout if u-boot already has configuration for that board . as we have Allwinner A13 processor has we have been taking reference from Oilmex A13 board , we use Olimex board's configuration file as reference.
we need mark all the changes that we have made and need to make changes in each and every file associated with those changes.
now lets look at u-boot directory where exactly these file are located in the source.