[Country EMBED strategy] [069] [BOOTM Command porting]

Source: Internet
Author: User

Bootloader effect

1. Initializing Hardware and software

2. Start the operating system

Kernel classification

1.zImage Core without information header

2.uImage the kernel after the information header, start with the BOOTM command

Bootm effect

1. Detection information Header: compression, operating system, magic number

2. Call the appropriate handler function according to the OS information: Get the kernel address, know the CPU model, set the startup parameters

Code writing

1. Get the start address

2. Setting the Startup parameters

2.1 Setting Core boot parameters

2.2 Setting Memory parameters

2.3 Setting command-line arguments

2.4 Set parameter end line flag

3. Start the operating system

/********************************************************************* Name: bootm.c* Author: d* Time: 2015.11.23* function: Start the Linux system *********************************************************************//******************************* Header file *********************************************************************/ #include "net.h"/********************************************************************* macro definition ********************** /#define Kernel_zero 0#define Kernel_mach 168//Development Board ID, with kernel i D Match # define KERNEL_ADDR tftp_donwload//Kernel address # ATAG_ADDR (kernel_addr-0x100)//Label address # define Atag_core 0x54      410001//Core Label # ATAG_MEM 0X54410002//Memory Label # define Atag_cmdline 0x54410009//Command Label # define Atag_none 0x00000000//END tag # define MEM_ADDR 0x30000000//memory address # define MEM_SIZE 0x04000000//Memory Size # define TAG_SIZE (Type) ((Sizeo F (struct Tag_header) +sizeof (struct type))//Calculate label size, divided by 4 for labelSize is calculated in 4 bytes for moving the label pointer # define TAG_NEXT (type) (struct tag *) ((unsigned int *) (type) + (type)->hdr.size))//Move label Pointer/******* Type definition ********************************************* /struct tag_header {unsigned int tag;unsigned int size;}; struct Tag_core {unsigned int flags;unsigned int pagesize;unsigned int rootdev;}; struct Tag_mem32 {unsigned int start;unsigned int size;}; struct Tag_cmdline {char cmdline[1];}; struct tag{struct tag_header hdr;union{struct tag_core core;struct tag_mem32 mem;struct tag_cmdline cmdline;} u;}; struct tag *params;/********************************************************************* global variable declaration ***************** /const char *cmdline = "console=ttysac0,115200 init=/init";/*** Function Prototype Declaration *************************************** /void do_bootm_linux (); void SETup_core_tag (); void Setup_memory_tag (); void Setup_cmdline_tag (); void Setup_end_tag ();/*************************** Name: do_bootm_linux* parameter: *none* return: *none* function: Start Linux system ******************** /void Do_bootm_linux () {void (*thekernel) (int zero, int arch,   unsigned int params);   Kernel function pointer//set start address Thekernel = (void (*) (int, int, unsigned int)) kernel_addr;      Convert address to function pointer//set startup parameter Setup_core_tag ();    Set the core parameter Setup_memory_tag ();   Set memory parameters Setup_cmdline_tag ();       Set command parameter Setup_end_tag ();   Set End flag//Start operating system Thekernel (Kernel_zero, Kernel_mach, atag_addr); No longer returns}/********************************************************************* name: setup_core_tag* parameter: *none* return: * none* function: Set core parameters *********************************************************************/void Setup_core_tag () {// Set Label Address params = (struct tag *) atag_addr;//set core parameter Params->hdr.tag = Atag_core;params->hdr.size = Tag_size (Tag_core) ;p arams->u.core.flags = 0;p arams->u.core.pagesize = 4096;params->u.core.rootdev = 0;//Mobile label Address params = Tag_next (params);} /********************************************************************* Name: setup_memory_tag* parameter: *none* return: *none* function : Set memory parameter *********************************************************************/void Setup_memory_tag () {// Set memory Parameters Params->hdr.tag = Atag_mem;params->hdr.size = Tag_size (tag_mem32);p arams->u.mem.start = MEM_ADDR; Params->u.mem.size = mem_size;//Mobile label Address params = Tag_next (params);} /********************************************************************* Name: setup_cmdline_tag* parameter: *none* return: *none* Function: Set command parameter *********************************************************************/void Setup_cmdline_tag () {// Set command Parameters Params->hdr.tag = Atag_cmdline;params->hdr.size = (sizeof (struct tag_header) +strlen (cmdline) +1+4) >   >2; ' +1 ' indicates that the character end flag ' \ s ', ' +4 ' represents the rounding up of the strcpy (Params->u.cmdline.cmdline, cmdline) when divided by 4, and//Mobile label Address params = Tag_next ( params);} /*************************************************Name: setup_cmdline_tag* parameter: *none* return: *none* function: Set End flag ****************************************** /void Setup_end_tag () {params->hdr.tag = Atag_none;params->hdr.size = 0;}

[Country EMBED strategy] [069] [BOOTM Command porting]

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.