Arm Linux boot one: assembly boot to Start_kernel

Source: Internet
Author: User

Describes the overview process for ARM Linux boot, taking s5pv210 (Cortex A8) As an example, this article describes the first phase.

First, the guidance of ARM Linux

Uboot after booting arm Linux (Uimage Mirror) to SDRAM, the BOOTM command interprets the 64 byte headers of the uimage image to obtain the entry entry address for Linux. and assigns a value to the Thekernel function pointer (typically the value is 0x30008000), and will uboot the environment variable parameters (such as the platform's memory block area information, Linux boot command information Bootargs, etc.) is placed at the beginning of 0x30000100 in the form of tags that are required by Linux. Then turn off the MMU, clear the Icache,dcache, and finally pass control to arm Linux with this function:

Thekernel (0, Machid, bd->bi_boot_params);

Where Machid is the ID of the platform and needs to be the same as the machine ID defined in Arch/arm/tools/mach_types, otherwise it cannot be started. Bd->bi_boot_params is 0x30000100, which describes the information needed for Linux startup.

Second, the first part of ARM Linux startup

This section is a system-related assembly section, where the code is located in Arch\arm\kernel\head. S, the entrance is entry (stext), and its main completion work includes:

1) Set current arm operating mode is SVC mode, off interrupt

2) __lookup_processor_type Obtain the corresponding CPU information data structure address, mainly arm V7 architecture-related information, such as Mmu,cache flag value, data structure as follows:

struct Proc_info_list {

unsigned int cpu_val;

unsigned int cpu_mask;

unsigned long __cpu_mm_mmu_flags; /* Used by head. S */

unsigned long __cpu_io_mmu_flags; /* Used by head. S */

unsigned long __cpu_flush; /* Used by head. S */

const char *arch_name;

const char *elf_name;

unsigned int elf_hwcap;

const char *cpu_name;

struct processor *proc;

struct CPU_TLB_FNS *tlb;

struct CPU_USER_FNS *user;

struct CPU_CACHE_FNS *cache;

};

ARM Linux supports a variety of CPU architectures, described in the . Proc.info.init segment, corresponding to s5pv210, which is arch\arm\mm\proc-v7. S, Lookup_processor_type first through the coprocessor CP15 read out the CPU ID and compare with Cpu_val, can get the data structure address. The address is linked to the virtual address, and the MMU is turned off, and the address needs to be moved to physical address access.

3) __lookup_machine_type obtains the corresponding platform machine data structure address, mainly is the platform board related data information, such as the memory start address and the size, the interrupt and the timer initialization function and so on, as follows:           

struct MACHINE_DESC {

unsigned int nr; /* Architecture Number */

unsigned int phys_io; /* Start of Physicalio */

unsigned int io_pg_offst;/* byte offsetfor io * page Tabe entry */

const char *name; /* Architecture Name */

unsigned long boot_params; /*tagged List */

unsigned int video_start; /* Start of Videoram */

unsigned int video_end; /* End Ofvideo RAM */

unsigned int reserve_lp0:1; /* Never haslp0 */

unsigned int reserve_lp1:1; /* Never HASLP1 */

unsigned int reserve_lp2:1; /* Never HASLP2 */

unsigned int soft_reboot:1; /* Softreboot */

void (*fixup) (struct Machine_desc *, struct tag *, char * *, struct meminfo *);

void (*map_io) (void);/* IO mapping function */

void (*INIT_IRQ) (void);

struct Sys_timer *timer; /* System TICK Timer */

void (*init_machine) (void);

};

ARM Linux supports a variety of platform boards, which are described in the . Arch.info.init segment, corresponding to s5pv210 that is \arch\arm\mach-s5pv210\mach-smdkv210.c. The Uboot Machid is used to search for matching NR to fetch machine information.

4) Check Uboot passed the tags to meet the standards, and detect the machine data structure boot_params value is equal to Thekernel passed over the third parameter (0x30000100)

5) create_page_tables Create a temporary page table, are mapped in 1M units, so 4G space needs 16K, from 0x30004000 to 0x30008000. A total of three parts are mapped:

I. Mapping of the Linux kernel Mirror space (0xc0008*** start of kernel space mapping to 0x30008***)

Ii. Creating a page table to open the MMU there is also a section of code that needs to be run, as there is also a need to create a direct mapping for the initial 1M space of the Linux boot, at which point the 0x30008000+ address runs, so the mapping is 0x30008000+ mapped to 0x30008000+

III. Uboot passed the tags parameter also needs to be mapped (virtual 0xc** mapped to 0x3* *) for access.

6) Ldr R13, __switch_data, will __switch_data the address of the data structure into the stack.

7)Add Pc,r10, #PROCINFO_INITFUNC, the PC will be changed to arch\arm\mm\proc-v7. S of the __v7_setup to execute, before jumping __enable_mmu to the LR, that is, __v7_setup after the execution of the return to __enable_mmu. __v7_setup is mainly related to CPU system initialization, such as Icache,dcache and so on.

8)__enable_mmu open Mmu,cache and so on, finally will r13 out the stack, remove arch/arm/kernel/head-common. S __switch_data The first content of the __mmap_switched function and assigns it to a PC:

__switch_data:

. Long __mmap_switched

. long__data_loc @ R4

. long_data @ R5

The. Long __bss_start @r6

. long_end @ R7

. long processor_id @ R4

. long __machine_arch_type @ R5

The. Long __atags_pointer @r6

. Long Cr_alignment @ R7

. long init_thread_union + thread_start_sp @ SP

9)__mmap_switched initialize DATA,BSS and other related segments, save the relevant data structure address to the relevant variables. Sets the stack space after which the system starts the INIT process.

b start_kernel Jump to the second part of Linux boot, written for C language.

Arm Linux boot one: assembly boot to Start_kernel

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.