Android Development----bootloader (LK)

Source: Internet
Author: User

What is LK?

LK is Little Kernel it is APPSBL (Applications ARM Boot Loader) Process code, Little Kernel is small kernel small operating system.

LK code under the Bootable/bootloadler/lk directory

LK Code Structure

+app//Application related

+arch//ARM system

+dev//equipment related

+include//Header file

+kernel//LK System related

+platform//Related drive

+projiect//Makefile File

+scripts//Jtag Script

+target//Specific board related

LK Process Analysis

In the Bootable/bootloadler/lk/arch/arm/ssystem-onesegment.ld connection file ENTRY (_start) specifies that LK starts with the _start function, _start in lk/arch/crt0. S in. Crt0. S mainly do some basic CPU initialization and then pass BL Kmain; jump to C code.

Kmain in the LK/KERNEL/MAIN.C.

Kmain ()

Kmain mainly do two things: 1, itself lk the initialization of the system module, 2, boot initialization action.

Kmain Source Analysis:

void Kmain ()

{

1. Initialize the process (simple process in LK) related structures.

Thread_init_early ();

2. Do some arm related work such as shutting down the cache to enable the MMU.

Arch_early_init ();

3. Early initialization of related platforms

Platform_early_init ();

4. Now a function jump, initialize the UART (board related)

Target_early_init ();

5. Constructor-related initialization

Call_constructors ();

6.lk System-related stack initialization

Heap_init ();

7. Brief initialization of Timer objects

Thread_init ();

8.LK System Controller initialization (related event initialization)

Dpc_init ();

9. Initialize the timer in LK

Timer_init ();
10. New Thread entry function bootstrap2 for boot work (emphasis)
Thread_resume (Thread_create ("Bootstrap2", &bootstrap2, NULL, Default_priority, default_stack_size));

 }

the above associated functions with boot initiation initialization are arch_early_init , Platform_early_init,bootstrap2, these are the starting points, and we look at them slowly.

Arch_early_init ()

Architecture-related initialization of our general ARM system

1. Close the cache

Arch_disable_cache (Ucache);

2. Set the vector base address (interrupt dependent)

Set_vector_base (membase);

3. Initialization of the MMU

Arm_mmu_init ();

4. Initialize the MMU map __ Platform Related

Platform_init_mmu_mappings ();

5. Turn on the cache

Arch_enable_cache (Ucache)

6. Enable CP10 and CP11

__asm__ volatile ("MRC P15, 0,%0, C1, C0, 2": "=r" (Val));

Val |= (3<<22) | (3<<20);

__asm__ volatile ("MCR P15, 0,%0, C1, C0, 2":: "R" (Val));

7. Set enable FPEXC bit (interrupt dependent)

__asm__ volatile ("MRC P10, 7,%0, C8, C0, 0": "=r" (Val));

Val |= (1<<30);

__asm__ volatile ("MCR P10, 7,%0, C8, C0, 0":: "R" (Val));

8. Enable Loop count Register

__asm__ volatile ("MRC P15, 0,%0, C9, C12, 0": "=r" (en));

en &= ~ (1<<3); /* cycle calculation per cycle * /

En |= 1;

__asm__ volatile ("MCR P15, 0,%0, C9, C12, 0":: "R" (en));

9. Enable Loop counter

En = (1<<31);
__asm__ volatile ("MCR P15, 0,%0, C9, C12, 1":: "R" (en));

Platform_early_init ()

Platform-dependent initialization of different platforms different initialization below is msm7x30

1. Initializing interrupts

platform_init_interrupts ();

2. Initializing the timer

Platform_init_timer ();

BOOTSTRAP2

The BOOTSTRAP2 is threaded at the end of the Kmain. Three main steps: Platform_init, Target_init, Apps_init.

1.platform_init

The main function of Platform_init is acpu_clock_init.

system clock settings for ARM11 on Acpu _clock_init, overclocking

2.target_init

Set up for the hardware platform. Mainly integrate ARM9 and ARM11 partition tables, initialize flash and read flash information

3.apps_init

Apps_init is the key to initializing and running the so-called app in LK, and Aboot_init will start running here, and the Android Linux kernel loading work is done in Aboot_init.

Aboot_init

1. Set nand/ emmc read information page size
if (Target_is_emmc_boot ())

{

Page_size = 2048;

Page_mask = page_size-1;

}

Else

{

Page_size = Flash_page_size ();

Page_mask = page_size-1;

}

2. Read the key information, determine whether the normal boot, or enter the FastBoot, or into the recovery mode

。。。。。。。。。

Judging by a series of if (keys_get_state () = = XXX)

。。。。。。。。。

3. Loading the kernel from the NAND

Boot_linux_from_flash ();

Partition_dump ();

SZ = Target_get_max_flash_size ();

Fastboot_init (Target_get_scratch_address (), SZ);

Udc_start (); Start USB Protocol

Boot_linux_from_flash

mainly the kernel loading process, our boot.img contains: Kernel head, kernel, RAMDisk, second stage (can not).

1. Read the boot header

Flash_read (P, offset, raw_header, 2048)

Offset + = 2048;
2. Read the kernel
MEMCMP (Hdr->magic, Boot_magic, Boot_magic_size)
n = (hdr->kernel_size + (flash_page_size-1)) & (~ (flash_page_size-1));

Flash_read (P, offset, (void*) hdr->kernel_addr, N)

offset + = n;
3. Read RAMDisk
n = (hdr->ramdisk_size + (flash_page_size-1)) & (~ (flash_page_size-1));

Flash_read (P, offset, (void*) hdr->ramdisk_addr, N)

offset + = n;

4. boot the kernel ,

boot_linux (); //Entry (0,machtype,tags) in Boot_linux, and the address from kernel loaded in the kernel starts running.


here, LK's start-up process is over.

Android Development----bootloader (LK)

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.