Sunday, April 9, 2017

U-boot Porting guide

1. U-BOOT OVERVIEW
U-boot (Universal Bootloader) is an open source, multi-platform bootloader. U-boot supports interactive commands, environment variables, command scripting and booting from external media. U-boot supports a large variety of popular CPUs and CPU families used today, and a much larger collection of reference boards based on these processors.

2. DIRECTORY STRUCTURE


3. PORTING U-BOOT
The major changes required in u-boot for porting to any board, changes are related to a new processor and other peripheral devices. A common practice is to use an existing configuration for some similar board and create a new configuration for the new board. When designing a new system with the processor, follow these steps:
a. Define a physical memory map with the sections like flash memory, dram memory and peripheral memory.
b. Define a memory link map with the following sections
.text – Program executable and data sections of u-boot
.env – Reserve space for environmental variables
Global data – This data is reserved for global variables
Monitor – Reserved space in ram for the u-boot bootloader
Malloc – Reserve space for dynamically allocated memory
Bootmap – Reserve space for operating system image
c. Configure u-boot by modifying the <boardname>.h header file

First, create a new set of directories and files to mimic the existing configuration. The necessary directories and files are:
u-boot/board/<boardname>
u-boot/include/configs/<boardname>.h
u-boot/Makefile
Then copy files, and make changes to Makefile and platform specific files to retarget the code for board. include, cpu, lib_arch, and board are the directories dependent upon a particular architecture and the board. All other directories remain the same for any architecture. For porting u-boot for specific processor and board, we need to add or modify the following files:

The include directory:
The include directory contains all header files globally used by u-boot. In this directory we need to generate or change following files for a specific cpu and board:
1) Configs/<boardname>.h
This file includes hardware configuration for memory map and peripherals. It contains the chip configuration, flash boot configuration, nor and NAND flash configuration, SDRAM memory configuration, serial configuration, u-boot configuration, I2C configuration, Linux configuration, Network and Ethernet configuration etc.
2) <core>.h for example arm926ejs.h
This file contains the processor specific definitions required for u-boot to access the CPU. This includes the register definitions.

The cpu directory:
The cpu directory contains initialization routines for internal peripherals.
1) <core>/cpu.c
This file contains the cpu specific code. It performs operations like read and write to control register, reset cpu, I/D cache enable/disable, Setup the stacks for IRQ and FIQ etc.
2) <core>/interrupt.c
This file contains the function related to interrupt and timer. Like enable interrupts, disable interrupts, timer related operations etc.
3) <core>/start.S
This file contains startup code for ARM926EJS cpu core.

The lib_<arch> directory:
4) board.c
This file performs the following functions:
memory map initialization
Logical memory map configuration
dynamic memory allocation routines(malloc)
u-boot peripheral initialization
5) <arch>linux.c for example armlinux.c
This file contains Implementation of bootm command, that is used to places the kernel image into RAM. This command passes the architecture number and boot parameters to the kernel and starts the kernel execution by giving a control to kernel image.
6) div0.c
This file contains division-by zero exception handler.

The board directory:
An individual directory for each board configuration supported by u-boot is found in the board directory. This sub-directory includes board specific configuration routines.
7) < boardname >/flash.c
This file contains the function related to flash memory like flash Initialization, Reset flash, print flash information, Erase flash, Write to flash.
8) < boardname >/ < boardname >_emac.c
This file initializes EMAC and performs EMAC related operations like receive packet and send packet.
9) < boardname >/ < boardname >.c
This file contains functions like board initialization routine, Initialize Timer configuration register, Serial Port initialization, NAND flash initialization etc.
10) < boardname >/ soc.h
This file contains peripheral base addresses, Interrupt event ids etc.
11) < boardname >/ platform.S
This file contains the PLL, power domain initialization, SDRAM Memory configuration register like SDRAM control register, refresh rate control register, initialization or SDRAM etc.

Modify the top level makefile to specify the new configuration. All the configurations are listed under various titles.
<boardname>_config : unconfig
@./mkconfig $(@:_config=) <architecture> <core> <boardname>
e.g, For davinci EVM board,
davinci_config : unconfig
@./mkconfig $(@:_config=) arm arm926ejs davinci
4. U-BOOT BUILD
Toolchain: Before building and installing u-boot you need a cross-development toolchain for your target architecture. You are probably familiar with the toolchain on your desktop Linux PC. That toolchain runs on an x86 platform and generates binaries for an x86 platform. A cross-development toolchain executes particular CPU architecture, but generates binaries for a different architecture.
U-boot Build procedure: The following command sequence is used to build the u-boot for the particular board.
$ make distclean
$ make <boardname>_config
$ make
The result of these command sequence will build the following targets and there should be no compilation errors.
1. u-boot: an ELF file of the code and it can also used to generate the disassembly.
$ objdump -D u-boot > u-boot.dis
2. u-boot.bin: the binary image. (with ELF headers striped out) used for download and debugging
3. u-boot.srec: the S-Record image.
4. u-boot.map: the global addresses for symbols, etc.
Note: Header information will be added to the image for the bootROM to decide the data transfer parameters.



U-boot(Universal Bootloader)

1. The include/configs/ directory contains one configuration file for each supported board:
1.1 It defines the CPU type, the peripherals and their configuration, the memory mapping, etc.
1.2 It is a simple .h file that sets pre-processor constants. See README file for these constants.
2. U-Boot must be configured before being compiled:
2.1 make BOARDNAME_config, BOARDNAME is the name of configuration file in include/configs/.
2.2 Cross-compiler is available in PATH: export PATH=/usr/local/uclibc-0.9.29-2/arm/bin/:$PATH
2.3 Compile U-Boot, by specifying the cross-compiler prefix: make CROSS_COMPILE=arm-linux-
2.4 U-Boot must usually be installed in flash memory to be executed by the hardware.
2.4.1 Board provides some kind of specific boot monitor, allows to flash second stage bootloader.
2.4.2 U-Boot is already installed, and can be used to flash a new version of U-Boot.
2.4.3The board provides a JTAG interface, which allows to write to the flash memory remotely.

3. The kernel image that U-Boot loads and boots must be prepared, so that an U-Boot specific header is added in front of the image. This is done with a tool that comes in U-Boot, mkimage.

No comments:

Post a Comment