U-Boot, a boot loader for Embedded boards based on PowerPC, ARM, MIPS and several other processors, which can be installed in a boot ROM and used to initialize and test the hardware or to download and run application code.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
• U-Boot (Universal Boot-loader) is an open source, multi platform boot-loader. • 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• Generally, U-Boot resides in the beginning area of the flash. The exact sector or
block is defined by the processor. • U-Boot initialize the CPU and several peripherals located on board, create some
critical data structures which will be used by kernel• U-Boot is under GPLv2 License• Refer below
• Look for an already supported board and SOC which is as close as possible to yours.
• Identify the On-Chip and On-board peripherals• Define physical memory map of board.• Study of ARM Application Binary Interface (EABI)• Study ARM assembly instruction
• Choose an existing board which is most similar to the new board.
Say armadillo-800eva board• Copy the ‘include/configs/armadillo-800eva.h’ to
‘include/config/loganlte.h’.• Create directory in ‘board/vendor/loganlte/’• Update boards.cfg to add new entry for loganlte• Create directory for SOC specific code ‘arch/arm/armv7/shmobile/’.• Add corresponding header files in ‘arch/arm/include/asm/arch-shmobile’• Modify the value of TEXT_BASE in ‘board/loganlte /config.mk’.
• If explicitly specified LDSCRIPT in board/cpu directory. • If CONFIG_SYS_LDSCRIPT, use that or fail if absent. • Otherwise, it search for 'u-boot.lds' sequentially in below location
typedef struct global_data { bd_t *bd; unsigned int baudrate; unsigned long cpu_clk; /* CPU clock in Hz! */ unsigned long bus_clk; unsigned long pci_clk; unsigned long mem_clk; #ifdef CONFIG_BOARD_TYPES unsigned long board_type; #endif unsigned long have_console; /* serial_init() was called */ unsigned long env_addr; /* Address of Environment struct */ unsigned long env_valid; /* Checksum of Environment valid? */ /* TODO: is this the same as relocaddr, or something else? */ unsigned long dest_addr; /* Post-relocation address of U-Boot */ unsigned long dest_addr_sp; unsigned long ram_top; /* Top address of RAM used by U-Boot */
unsigned long relocaddr; /* Start address of U-Boot in RAM */ phys_size_t ram_size; /* RAM size */ unsigned long mon_len; /* monitor len */ unsigned long irq_sp; /* irq stack pointer */ unsigned long start_addr_sp; /* start_addr_stackpointer */ unsigned long reloc_off; /* relocation offset */ struct global_data * new_gd; /* relocated global data */ const void * fdt_blob; /* Our device tree, NULL if none */ void * new_fdt; /* Relocated FDT */ unsigned long fdt_size; /* Space reserved for relocated FDT */ char env_buf[32]; /* buffer for getenv() before reloc. */ struct arch_global_data arch; /* architecture-specific data */} gd_t;
typedef struct bd_info { unsigned long bi_memstart; /* start of DRAM memory */ phys_size_t bi_memsize; /* size of DRAM memory in bytes */ unsigned long bi_flashstart; /* start of FLASH memory */ unsigned long bi_flashsize; /* size of FLASH memory */ unsigned long bi_flashoffset; /* reserved area for startup monitor */ unsigned long bi_sramstart; /* start of SRAM memory */ unsigned long bi_sramsize; /* size of SRAM memory */#ifdef CONFIG_ARM unsigned long bi_arm_freq; /* arm frequency */ unsigned long bi_ddr_freq; /* ddr frequency */#endif unsigned long bi_bootflags; /* boot / reboot flag (Unused) */ unsigned long bi_ip_addr; /* IP Address */ unsigned char bi_enetaddr[6]; /* OLD: see README.enetaddr */ unsigned short bi_ethspeed; /* Ethernet speed in Mbps */ unsigned long bi_intfreq; /* Internal Freq, in MHz */ unsigned long bi_busfreq; /* Bus Freq, in MHz */ unsigned int bi_baudrate; /* Console Baudrate */ unsigned int bi_procfreq; /* CPU (Internal) Freq, in Hz */ unsigned char bi_pci_enetaddr[6]; /* PCI Ethernet MAC address */#endif unsigned char bi_enetXaddr[6]; /* OLD: see README.enetaddr */ ulong bi_arch_number; /* unique id for this board */ ulong bi_boot_params; /* where this board expects params */#ifdef CONFIG_NR_DRAM_BANKS struct { /* RAM configuration */ ulong start; ulong size; } bi_dram[CONFIG_NR_DRAM_BANKS];#endif /* CONFIG_NR_DRAM_BANKS */} bd_t;
1. Disable all interrupts.2. Copy any initialized data from ROM to RAM.3. Zero the uninitialized data area.4. Allocate space for and initialize the stack.5. Initialize the processor’s stack pointer.6. Create and initialize the heap.7. Execute the initializers for all global data8. Enable interrupts.9. Call main loop.
U-Boot relocates itself from ROM to RAM. Divided the boot-strapping process into two phases: Pre-Relocation U-Boot Bootstrapping Post-Relocation U-Boot Bootstrapping
(gdb) symbol-fileDiscard symbol table from `/home/dzu/denx/cvs-trees/u-boot/u-boot'? (y or n) yNo symbol file now.(gdb) add-symbol-file u-boot 0xfd0000add symbol table from file "u-boot" at .text_addr = 0xfd0000(y or n) yReading symbols from u-boot...done.(gdb) b board_init_rBreakpoint 2 at 0xfd99ac: file board.c, line 533.(gdb) cContinuing.
Breakpoint 2, board_init_r (id=0xfbb1f0, dest_addr=16495088) at board.c:533533 {(gdb)
board_init_r is the first C routine running in the newly relocated C friendly RAM environment.
Use inline functions whenever possible ? it increases code size but saves u the overhead of stack push & pop operations
Code all critical / frequently used code in assembly Store frequently used variables in register Use global variables it saves you push/pop stack operation during function
call. Don't use floating point calculations / variables. Enable GCC Optimization.
-O1 = With this option the resulting executables should be smaller and faster than with -O0
-O2 = This option is generally the best choice for deployment of a program -O3 = This option may increase the speed of the resulting executable, but
can also increase its size -Os = his option selects optimizations which reduce the size of an
• Why U-boot relocate itself into RAM ?– Memory access is faster from RAM than from ROM, this will matter
particularly if target has no instruction cache.– Executing from RAM allows flash reprogramming; also (more minor) it
allows software breakpoints with "trap" instructions.– Variable cannot be modified when it is stored in ROM.
• Boot loader must copy itself to RAM to update the variables correctly.• Function calls relies on stack operation which is also should be stored in
RAM.
• Can U-Boot be configured such that it can be started in RAM?– Yes, By enabling the CONFIG_SYS_RAMBOOT. – But this feature is not tested with all the boards, refer
doc/README.mpc85xx.– For u-boot builds switch CONFIG_SYS_TEXT_BASE between flash and ram
• Can U-Boot be configured such that it can be started in RAM?– Yes, By enabling the CONFIG_SYS_RAMBOOT. – But this feature is not tested with all the boards, refer
doc/README.mpc85xx.– For u-boot builds switch CONFIG_SYS_TEXT_BASE between flash and ram
builds if MMU is disabled.
• Why Linux hangs after uncompressing the kernel ?Uncompressing Kernel Image ... OK– Bad definition of the bd_info structure . – Bad clock information
• setenv clocks_in_mhz 1; saveenv
• For more: Read U-Boot FAQ at http://www.denx.de/wiki/view/DULG/FaqUBoot