Linux porting U-boot (i)--u-boot detailed + custom command combat

Source: Internet
Author: User
Tags file copy network function

Linux porting U-boot (i)--u-boot detailed + custom command combat

2015-02-07

First, Bootloader

???? Simply put: The main function of bootloader is to start execution when the system is power up, initialize the hardware and equipment, prepare the software environment, and finally call the operating system.

???? Specific include: Turn off your watchdog watchdog, change the system clock, initialize the storage controller

, copy the operating system kernel code into memory to run.

???? In order to develop convenient, can increase the network function, from the PC through the serial port or the network to download files, burn write files, flash on the kernel code to run after decompression.

The bootloader is divided into two modes:

(1): Start load mode: After power on, bootloader on the board on a solid-state storage device to load the operating system into RAM run, no user intervention

(2): Download mode: Developers can use a variety of commands, allow to switch between the various operating modes, through the serial port or network to download the kernel files, and put them directly in memory to run, this is what we call the U-boot.

?

Embedded Linux operating system from the software perspective can be divided into four levels:

    1. Boot loader bootloader
    2. Linux kernel
    3. File system
    4. User applications

?

The general U-boot is divided into single-stage, multi-stage two kinds:

Multi-stage U-boot has better portability and can be summed up in two stages.

Phase One: Use the assembly to accomplish some initialization that relies on the CPU architecture, including light ratio watchdog, off interrupts, setting CPU speed and clock frequency, and RAM initialization.

???? Hardware Device initialization = Prepare the RAM space for the second-stage code that loads bootloader = = Copy the second-stage code of the bootloader into the ram space = = Set the stack and jump to the C-entry of the second-stage code.

The second stage: using the C language, you can achieve more complex functions.

???? Initialize the hardware device to be used at this stage, and the Detect system memory map. + Read the kernel image and root file system image from Flash to ram space = = Set startup parameters for the kernel = = Call the kernel.

?

???? Bootlaoder interaction with the kernel (the way parameters are passed)

    1. Sets the tag Atag_core, which is marked as the start.
    2. Setting Kernel tags
    3. Set the command-line tag, which is a string that controls some of the kernel's behavior
    4. Set the tag Atag_none to the end of the tag list

????

Common bootloader include Lilo, GRUB, Loadlin, Rolo, Etherboot, BLOB, U-boot, Redboot, Vivi, etc., where we study u-boot;

Second, u-boot analysis and Transplant

U-boot, full name Universal Boot Loader, complies with the GPL terms of the opening code project.

U-boot There are 26 sub-directories: Divided into four categories:

    1. Platform-related or Development Board-related board, CPU, lib_i386 similar
    2. Common functions include, lib_generic, common
    3. Generic device drivers disk, drivers, DTT, FS, NAND_SPL, NET, post, RTC
    4. U-boot tools, sample programs, Docs doc, examples, tools

?

U-boot configuration, compilation, linking process

Configuration process:

???? The configuration file is mkconfig under the root directory,

???? For example, executing make Smdk2410_config actually executes the following command

????????. /mkconfig smdk2410 arm arm920t smdk2410 NULL s3c24x0

???? Results:

    1. Development Board name Board_name equals $
    2. Create a link to the related header file to the Platform/Development Board
    3. Create a file containing the top level makefile INCLUDE/CONFIG.MK
    4. Creating a Development Board-related header file Include/config.h $include <configs/$1.h>

Compiling, linking

???? Make all

Summarize the compilation process of U-boot

    1. First compile the cpu/$ (CPU)/start. S, for different CPUs, may also compile other files under cpu/$ (CPU).
    2. Then, for each directory associated with the platform/board, each common directory uses the corresponding library generated by their respective makefile
    3. The. 0,. A files generated by 1, 2 steps are linked by board/$ (boarddir)/u-boot.lds link script According to the code snippet start address established in the board/$ (boarddir)/config.mk file.
    4. The 3rd step gets the elf format of the U-boot, then makefile will also convert it into a binary format file, S-record format.

?

Burn Write kernel image file Uimage

Place the uimage on the host's TFTP or NFS directory to ensure that TFTP or NFS services are turned on.

Then run the command to download the file, erase, burn write NAND Flash

TFTP 0x80800000 Uimage

NAND Erase 0x0 0x00200000

NAND WRITE.JFFS2 0x80800000 0x0 $ (filesize)

NOTE: Nand WRITE.JFFS2 does not require the length of the file to be page aligned (512-byte aligned)

NAND Wirte can also be used, but if the length is 512 byte aligned

?

Burn Write File system image

TFTP 080800000 yaffs.img

NAND Erase 0xa00000 0x3600000

NAND write.yaffs 0x80800000 0xa00000 $ (filesize)

Use U-boot to burn programs

TFTP 0x30000000 Test.bin

Go 0x30000000

?

?

Note: Creating a U-boot file for easyarm-imx257 needs to be done as follows:

First, enter the u-boot-2009.08 directory, clear the original compilation file, its corresponding terminal command is as follows:

$ CD u-boot-2009.08

$ make Arch=arm Cross_compile=arm-none-linux-gnueabi-distclean

Next, the platform that needs to configure U-boot is Mx25_3stack_config, the corresponding terminal command is as follows:

$ make Arch=arm Cross_compile=arm-none-linux-gnueabi-mx25_3stack_config

Configuring for Mx25_3stack Board ...

Then, perform the compilation, and the corresponding terminal commands are as follows:

$ make Arch=arm cross_compile=arm-none-linux-gnueabi-

The U-boot.bin file will be obtained in the u-boot-2009.08 directory when the compilation is complete.

?

?

LOADB 0x80800000-Sends uimage from the serial port to DDR2 in 0x80800000 of DaVinci.

Protect off all-write protection removed

Erase 0x200000 0x204ffff-erase or Flash in uimage occupied space

CP.B 0x80800000 0x2050000 0x14b008-Copy DDR2 files transferred to uimage into Flash

Save-Saves the contents of Flash

Additional notes:

If you already have u-boot on your board and need to upgrade to a new version of U-boot, you can do the following:

Use the HyperTerminal to send u-boot to DaVinci board using the serial port, and then use the online Update method to complete the u-boot burning, the specific steps:

1) Protect off all-write protection removed

2) Erase 0x2000000 0x204ffff-erase or Flash in u-boot occupied space

3) loadb 0x80800000-Send u-boot file via serial port to DaVinci DDR2

4) cp.b 0x80800000 0x2000000 0x17398-will be transferred to DDR2

U-boot file Copy to Flash

5) Save-Save Flash Content

?

?

?

Iii. u-boot Adding custom command instances

We added our custom Hello command under U-boot.

    1. First we add a cmd_hello.c file under the common directory of U-boot

      Refer to the writing of other commands as follows

#include <image.h>

#include <malloc.h>

#include <u-boot/zlib.h>

#include <bzlib.h>

#include <environment.h>

#include <lmb.h>

#include <linux/ctype.h>

#include <asm/byteorder.h>

?

int Do_hello (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])

{

???? int i = 0;

???? printf ("Hello,lover Snow!!! \nthe Argcs is \ n ");

???? for (i = 0; i<argc; i++)

???????? printf ("argv[%d]:%s\n", I,argv[i]);

???? return 0;

}

?

U_boot_cmd (

???? Hello,???? Config_sys_maxargs,???? 1,???? Do_hello,

????" This is a user defined command Hello,lover snow!!! ",

????" Hello,long help ... \ n "

????);

?

    1. Modify the makefile file below common to tell U-boot to compile our custom C file

Refer to the definition of other documents in makefile, add a sentence

Cobjs-y + = cmd_hello.o

?

    1. Re-make compilation U-boot

?

?

Linux porting U-boot (i)--u-boot detailed + custom command combat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.