高通Qualcomm平台lk(light kernel)启动流程1——aboot_init()之前

简介: 0lk 启动总体流程1lk启动流程代码lk arch arm crt0Slk kernel mainclk app appc更多相关文章:《高通Qualcomm平台lk(light kernel)启动流程1——aboot_init()之前》: http://blog.

更多相关文章:

《高通Qualcomm平台lk(light kernel)启动流程1——aboot_init()之前》:
http://blog.csdn.net/u014134180/article/details/78133916
《高通Qualcomm平台lk(light kernel)启动流程2——aboot_init()》:
http://blog.csdn.net/u014134180/article/details/78132580
《高通Qualcomm平台lk(light kernel)启动流程3——到高通lcm屏点亮》:
http://blog.csdn.net/u014134180/article/details/78177040

《[lcm] Qualcomm Android Display Subsystem 架构》
http://blog.csdn.net/u014134180/article/details/78129502

《[lcm] Qualcomm平台的显示屏lcd驱动移植步骤》:
http://blog.csdn.net/u014134180/article/details/78129499
《[lcm] Qualcomm平台兼容多显示屏lcd的方法&并从lk传输到kernel过程》:
http://blog.csdn.net/u014134180/article/details/78166978
《[lcm] Qualcomm平台显示屏lcd添加I2C读取功能》:
http://blog.csdn.net/u014134180/article/details/78176160

0、lk 启动总体流程

这里写图片描述

1、lk启动流程代码

lk/ arch/ arm/ crt0.S

/*
 * Copyright (c) 2008 Travis Geiselbrecht
 *
 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#define DSB .byte 0x4f, 0xf0, 0x7f, 0xf5
#define ISB .byte 0x6f, 0xf0, 0x7f, 0xf5

.section ".text.boot"
.globl _start
_start:
    b   reset
    b   arm_undefined
    b   arm_syscall
    b   arm_prefetch_abort
    b   arm_data_abort
    b   arm_reserved
    b   arm_irq
    b   arm_fiq

reset:

#ifdef ENABLE_TRUSTZONE
    /*Add reference to TZ symbol so linker includes it in final image */
    ldr r7, =_binary_tzbsp_tzbsp_bin_start
#endif
    /* do some cpu setup */
#if ARM_WITH_CP15
        /* Read SCTLR */
    mrc     p15, 0, r0, c1, c0, 0
        /* XXX this is currently for arm926, revist with armv6 cores */
        /* new thumb behavior, low exception vectors, i/d cache disable, mmu disabled */
    bic     r0, r0, #(1<<15| 1<<13 | 1<<12)
    bic     r0, r0, #(1<<2 | 1<<0)
        /* disable alignment faults */
    bic     r0, r0, #(1<<1)
    /* Enable CP15 barriers by default */
#ifdef ARM_CORE_V8
    orr     r0, r0, #(1<<5)
#endif
        /* Write SCTLR */
    mcr     p15, 0, r0, c1, c0, 0
#ifdef ENABLE_TRUSTZONE
  /*nkazi: not needed ? Setting VBAR to location of new vector table : 0x80000      */
 ldr             r0, =0x00080000
 mcr             p15, 0, r0, c12, c0, 0
#endif
#endif

#if WITH_CPU_EARLY_INIT
    /* call platform/arch/etc specific init code */
#ifndef ENABLE_TRUSTZONE
    /* Not needed when TrustZone is the first bootloader that runs.*/
    bl __cpu_early_init
#endif
    /* declare return address as global to avoid using stack */
.globl _cpu_early_init_complete
    _cpu_early_init_complete:

#endif

#if (!ENABLE_NANDWRITE)
#if WITH_CPU_WARM_BOOT
    ldr     r0, warm_boot_tag
    cmp     r0, #1

    /* if set, warm boot */
    ldreq   pc, =BASE_ADDR

    mov     r0, #1
    str r0, warm_boot_tag
#endif
#endif

    /* see if we need to relocate */
    mov     r0, pc
    sub     r0, r0, #(.Laddr - _start)
.Laddr:
    ldr     r1, =_start
    cmp     r0, r1
    beq     .Lstack_setup

    /* we need to relocate ourselves to the proper spot */
    ldr     r2, =__data_end 

.Lrelocate_loop:
    ldr     r3, [r0], #4
    str     r3, [r1], #4
    cmp     r1, r2
    bne     .Lrelocate_loop

    /* we're relocated, jump to the right address */
    ldr     r0, =.Lstack_setup
    bx      r0

.ltorg
#if WITH_CPU_WARM_BOOT
warm_boot_tag:
    .word 0
#endif

.Lstack_setup:
    /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
    mrs     r0, cpsr
    bic     r0, r0, #0x1f

    ldr     r2, =abort_stack_top
    orr     r1, r0, #0x12 // irq
    msr     cpsr_c, r1
    ldr     r13, =irq_save_spot     /* save a pointer to a temporary dumping spot used during irq delivery */

    orr     r1, r0, #0x11 // fiq
    msr     cpsr_c, r1
    mov     sp, r2

    orr     r1, r0, #0x17 // abort
    msr     cpsr_c, r1
    mov     sp, r2

    orr     r1, r0, #0x1b // undefined
    msr     cpsr_c, r1
    mov     sp, r2

    orr     r1, r0, #0x1f // system
    msr     cpsr_c, r1
    mov     sp, r2

    orr     r1, r0, #0x13 // supervisor
    msr     cpsr_c, r1
    mov     sp, r2

    /* copy the initialized data segment out of rom if necessary */
    ldr     r0, =__data_start_rom
    ldr     r1, =__data_start
    ldr     r2, =__data_end

    cmp     r0, r1
    beq     .L__do_bss

.L__copy_loop:
    cmp     r1, r2
    ldrlt   r3, [r0], #4
    strlt   r3, [r1], #4
    blt     .L__copy_loop

.L__do_bss:
    /* clear out the bss */
    ldr     r0, =__bss_start
    ldr     r1, =_end
    mov     r2, #0
.L__bss_loop:
    cmp     r0, r1
    strlt   r2, [r0], #4
    blt     .L__bss_loop

#ifdef ARM_CPU_CORTEX_A8
    DSB
    ISB
#endif

    bl      kmain
    b       .

.ltorg

.bss
.align 2
    /* the abort stack is for unrecoverable errors.
     * also note the initial working stack is set to here.
     * when the threading system starts up it'll switch to a new 
     * dynamically allocated stack, so we don't need it for very long
     */
abort_stack:
    .skip 1024
abort_stack_top:

lk/ kernel/ main.c

/*
 * Copyright (c) 2008 Travis Geiselbrecht
 *
 * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#include <compiler.h>
#include <debug.h>
#include <string.h>
#include <app.h>
#include <arch.h>
#include <platform.h>
#include <target.h>
#include <lib/heap.h>
#include <kernel/thread.h>
#include <kernel/timer.h>
#include <kernel/dpc.h>
#include <boot_stats.h>

extern void *__ctor_list;
extern void *__ctor_end;
extern int __bss_start;
extern int _end;

static int bootstrap2(void *arg);

#if (ENABLE_NANDWRITE)
void bootstrap_nandwrite(void);
#endif

static void call_constructors(void)
{
    void **ctor;

    ctor = &__ctor_list;
    while(ctor != &__ctor_end) {
        void (*func)(void);

        func = (void (*)())*ctor;

        func();
        ctor++;
    }
}

/* called from crt0.S */
void kmain(void) __NO_RETURN __EXTERNALLY_VISIBLE;
void kmain(void)
{
    thread_t *thr;

    // get us into some sort of thread context
    thread_init_early();

    // early arch stuff
    arch_early_init();

    // do any super early platform initialization
    platform_early_init();

    // do any super early target initialization
    target_early_init();

    dprintf(INFO, "welcome to lk\n\n");
    bs_set_timestamp(BS_BL_START);

    // deal with any static constructors
    dprintf(SPEW, "calling constructors\n");
    call_constructors();

    // bring up the kernel heap
    dprintf(SPEW, "initializing heap\n");
    heap_init();

    __stack_chk_guard_setup();

    // initialize the threading system
    dprintf(SPEW, "initializing threads\n");
    thread_init();

    // initialize the dpc system
    dprintf(SPEW, "initializing dpc\n");
    dpc_init();

    // initialize kernel timers
    dprintf(SPEW, "initializing timers\n");
    timer_init();

#if (!ENABLE_NANDWRITE)
    // create a thread to complete system initialization
    dprintf(SPEW, "creating bootstrap completion thread\n");
    thr = thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
    if (!thr)
    {
        panic("failed to create thread bootstrap2\n");
    }
    thread_resume(thr);


    // enable interrupts
    exit_critical_section();

    // become the idle thread
    thread_become_idle();
#else
        bootstrap_nandwrite();
#endif
}

int main(void);

static int bootstrap2(void *arg)
{
    dprintf(SPEW, "top of bootstrap2()\n");

    arch_init();

    // XXX put this somewhere else
#if WITH_LIB_BIO
    bio_init();
#endif
#if WITH_LIB_FS
    fs_init();
#endif

    // initialize the rest of the platform
    dprintf(SPEW, "initializing platform\n");
    platform_init();

    // initialize the target
    dprintf(SPEW, "initializing target\n");
    target_init();

    dprintf(SPEW, "calling apps_init()\n");
    apps_init();

    return 0;
}

#if (ENABLE_NANDWRITE)
void bootstrap_nandwrite(void)
{
    dprintf(SPEW, "top of bootstrap2()\n");

    arch_init();

    // initialize the rest of the platform
    dprintf(SPEW, "initializing platform\n");
    platform_init();

    // initialize the target
    dprintf(SPEW, "initializing target\n");
    target_init();

    dprintf(SPEW, "calling nandwrite_init()\n");
    nandwrite_init();

    return 0;
}
#endif

lk/ app/ app.c

/*
 * Copyright (c) 2009 Travis Geiselbrecht
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#include <debug.h>
#include <app.h>
#include <kernel/thread.h>

extern const struct app_descriptor __apps_start;
extern const struct app_descriptor __apps_end;

static void start_app(const struct app_descriptor *app);

/* one time setup */
void apps_init(void)
{
    const struct app_descriptor *app;

    /* call all the init routines */
    for (app = &__apps_start; app != &__apps_end; app++) {
        if (app->init)
            app->init(app);
    }

    /* start any that want to start on boot */
    for (app = &__apps_start; app != &__apps_end; app++) {
        if (app->entry && (app->flags & APP_FLAG_DONT_START_ON_BOOT) == 0) {
            start_app(app);
        }
    }
}

static int app_thread_entry(void *arg)
{
    const struct app_descriptor *app = (const struct app_descriptor *)arg;

    app->entry(app, NULL);

    return 0;
}

static void start_app(const struct app_descriptor *app)
{
    thread_t *thr;
    printf("starting app %s\n", app->name);

    thr = thread_create(app->name, &app_thread_entry, (void *)app, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
    if(!thr)
    {
        return;
    }
    thread_resume(thr);
}

Wu_Being博客声明:本人博客欢迎转载,请标明博客原文和原链接!谢谢!
《高通Qualcomm平台lk(light kernel)启动流程1——aboot_init()之前》: http://blog.csdn.net/u014134180/article/details/78133916

Wu_Being 吴兵博客接受赞助费二维码

如果你看完这篇博文,觉得对你有帮助,并且愿意付赞助费,那么我会更有动力写下去。

目录
相关文章
|
10月前
|
IDE 编译器 开发工具
【NXP】LPC55S69-RT-Thread Micropython移植日志
【NXP】LPC55S69-RT-Thread Micropython移植日志
120 0
|
11月前
|
Ubuntu
野火IMX6ULL PRO移植最新buidroot根文件系统(2022.02.04)
野火IMX6ULL PRO移植最新buidroot根文件系统(2022.02.04)
179 0
ALSA驱动源码之devm_snd_soc_register_component源码分析
ALSA驱动源码之devm_snd_soc_register_component源码分析
|
物联网
ZigBee TI ZStack CC2530 3.2 官方例程00-总
(配套源代码、软件、文档等资料下载,可移步博客同名QQ群:263671349,博主24小时在线) (配套源代码、软件、文档等资料下载,可移步博客同名QQ群:263671349,博主24小时在线)
910 0
|
机器学习/深度学习
高通Qualcomm平台lk(light kernel)启动流程2——aboot_init()
0lk 启动总体流程 1lk启动流程代码 lk app aboot abootc 更多相关文章: 《高通Qualcomm平台lk(light kernel)启动流程1——aboot_init()之前》: http://blog.
3359 1
|
数据库 Android开发
高通Qualcomm平台lk(light kernel)启动流程3——到高通lcm屏点亮
0lk 启动总体流程 1lk启动流程代码 lk app aboot abootc lk target msm8953 target_displayc lk dev gcdb display gcdb_displayc 更多相关文章: 《高通Qual...
3438 0
|
Android开发
[lcm] Qualcomm平台兼容多显示屏lcd的方法&amp;并从lk传输到kernel过程
1如何兼容不同的LCD模组 1-1 通过LCD_ID的电平状态区分 1-2 通过IC的ID区分 1-3 通过LCD_ID和IC ID的结合区分 2LCD初始化过程 3读取LK屏的ID传输到kernel 3-1 LK把相关参数报存到pbuf 3-2 kernel...
3002 0
|
Android开发
[lcm] Qualcomm Android Display Subsystem 架构
更多相关文章: 《高通Qualcomm平台lk(light kernel)启动流程1——aboot_init()之前》: http://blog.csdn.net/u014134180/article/details/78133916 《高通Qualcomm平台lk(light kernel)启动流程2——aboot_init()》: http://blog.
1762 0
|
物联网
ZigBee TI ZStack CC2530 3.16 按键驱动03-移植及使用
(配套源码、软件、开发板等资源,可移步博客同名QQ群/TB店铺:拿破仑940911) 上一节中,我们详细讲述了Z-Stack中按键检测的两种机制——“轮询模式”和“中断模式”。从实现原理来看,“中断模式”比“轮询模式”更加灵敏;更重要的是,在低功耗模式下,“中断模式”功耗更低!因此,在实际应用中,我们更多的是选用“中断模式”来进行按键检测。
1782 0
MTK Keypad驱动框架
上一节,看完了http://blog.csdn.net/morixinguan/article/details/7717020,tpd驱动框架的实现。 那么这一节来分析下Keypad驱动框架的实现,其实大同小异,套路也是类似的,我们来看看:
1583 0