Once we have understood how our device boots up, we will then cover the technical aspects of how to flash our device. As in the boot sequence, the 3 main components that need to be transferred -「flashed」- to the board, are: The Bootloader, the Kerneland the OS (Android). We will cover them in different posts, starting here with The Bootloader.php
As explained in the post explaining the boot sequence (here), the bootloader is the piece of software in charge of initializing most hardware components of our device and loading the kernel so that the system (OS) can start afterwards. The boot loader 「knows」 several things about the devices it is running on: Where to look for the different software components (kernel, OS, etc), how the partition table and the MBR look like, or how to make a diagnosis of the board -hardware test- before trying to start the booting sequence – among others. These capabilities vary from boot loader to boot loader, depending mainly on the commands and tools provided with it. In our case, we will use U-Boot. U-Boot is an universal boot loader for embedded systems, targeting different platforms including ARM. U-Boot, as any other boot loader can be installed in a boot ROM in order to carry out its labour [1] [2]. Sample features are [3]:html
Depending on the version, distribution and configuration of u-boot these features could change. The easiest way of checking which of them are available in our system is to access the u-boot console and check it. We will come back to this later in this same post. First, we will comment on how to build and flash u-boot as well as interesting files to make changes in.linux
U-Boot Source Codeandroid
One of the first things to check when we decide/have to deal with u-boot is to check which version we are running. In order to do this, check the Makefile (version and patchlevel). After this, check DENX’s documentation (here) to find out the available features.shell
Since u-boot is open source, we cane explore and modify the code to fulfil our needs. Most of the times, the features provided by u-boot are more than enough, nonetheless, here there is a list of interesting directories to check out.app
Building U-Bootless
Once we have mede the changes we intended to in the u-boot code -if we needed any at all- we need to compile it before we can flash it into our device. Prior to this step, we need to (i) initialize objects and configurations and clean previous compilation attempts, (ii) create the uboot configuration file and finally (iii) generate the executable. Please remember that, before attempting to compile for a specific platform, we need a set up our environment to cross-compile for that platform. Please readthis previous post on how to set up the system for Android development. Once our host machine is set up, we can run the following commands, which will build uboot:electron
After make has finished, we can check that the u-boot.bin file has been successfully generated. After this we can just flash it (the u-boot.bin file) into ours device boot device – ROM, SDCard, USB, etc. Depending on the board, this process -once again- might vary. Taking as a example the same board we have used for our own development -hardkernel’s ODROID-PC– this board needs of a first level boot loader that adds a checksum and a header to the original u-boot.bin, and it is generated from the u-boot.bin file itself using a tool called sd_fuse. This first stage boot loader is called U-boot_bl1.bin in the ODROID-PC community. This tool is part of the ODRIOD-PC’s boot loader used by the hardkernel team in their boards and it can be downloaded here.ide
According to the ODROID-PC documentation, in order to create the u-boot_bl1.bin file the following commands are necessary:wordpress
The u-boot_bl1.bin file is generated in the uboot directory. Please remember that this last step is platform specific and most probably does not apply to other boards.
Fusing U-Boot
The last step we need to give is to flash the boot loader in our boot device. It could be that the fabricant provides the image of the boot loader (not the code), in that case, this step is still applicable when doing recovery of the board, flashing a new boot device or similar cases.
In order to flash the boot loader in a boot device, first we need to know which name this device is given by our host machine when we connect it to it. For this, do as follows:
Once this is done, we use the dd linux commnand to flash the boot loader image in the boot device. Once more, the block in which the internal ROM of a given device might look for the boot loader varies from board to board, but it should be clearly specified in the documentation (and in the worse case, it should be traceable in code). In the case of our ODROID-PC, the specific commands to flash our boot device are (considering /dev/sdb* as our boot device): (Please notice that this step is only possible when having an extractable boot device -SDCard, USB stick, etc.-, commonly used in development boards. If dealing with a phone or a tablet that are not meant for developers, the flash chip -boot device- would be integrated, and then we would need a programming board to be able to flash it. Rooting devices is beyond the scope of this set of tutorials -and sometimes illegal- and therefore we will not cover it here. The steps to be done are not that different from the ones given here though ;))
What we do with the dd command is to copy the file u-boot.bin to the device /dev/sdb, 「seeking」 33 sectors. This means that we will skip the first 32 sectors and of the boot device and star copying the u-boot.bin in the sector 33. Similarly, we copy the first stage bootloader, u-boot_bl1.bin, in our boot device, in the sector 1. Once question here is: Why in this specific sectors? In the case of the ODROID-PC, if we check the documentation, we can find the following image, from where we can easily deduct the information provided above. Other boards should not differ much from the one we are using here as an example, being the information given here easily portable to other platforms.
Once this is done we have the first component of the boot sequence already flashed in our device. If we now open a serial connection from our host machine and restart the board (power off > power on) we should see something like this: (Please refer to this tutorial to configure your console for serial communication – coming soon)
This means that we do have a simple shell to interact with our board. Type help to see the commands you have available and… Enjoy!
Two of the most popular and useful commands you will find are: fdisk and fastboot, follow the links for a small introduction to them. (coming soon)
Next Steps
REFERENCES
[1] The DENX U-Boot (here)
[2] The U-boot boot loader – Presentation (here)
[3] U-Boot – linux-mips.org (here)
[4] ARM – TrustZone (here)
[5] ODROID – hardhernel (here)