android lk解读

  之前看过lk但是都是零散,也记不住,这次好好记录一下,就当自己的随笔看看

lk干了哪些事情,我大概写一下:

1.根据板子的硬件信息初始化board这个结构体
2.初始化各种时钟
3.初始化中断(支持多少中断)
4.初始化uart(设置时钟,配置相应的gpio,设置各种状态)
5.初始化heap
6.初始化线程
7.建立idle 线程

8.panel的初始化还有点亮

9.shell环境的初始化准备

lk的第一个函数

void kmain(void)
{
	// 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");
	thread_resume(thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE));


	// enable interrupts
	exit_critical_section();


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


接下来一个一个看

先看第一个

void thread_init_early(void)
{
	int i;

	/* initialize the run queues */
	for (i=0; i < NUM_PRIORITIES; i++)
		list_initialize(&run_queue[i]);       //static struct list_node run_queue[NUM_PRIORITIES];

/*static inline void list_initialize(struct list_node *list)
{
	list->prev = list->next = list;
}*/

	/* initialize the thread list */
	list_initialize(&thread_list);    //static struct list_node thread_list;


	/* create a thread to cover the current running state */
	thread_t *t = &bootstrap_thread;     //static thread_t bootstrap_thread;
	init_thread_struct(t, "bootstrap");


	/* half construct this thread, since we're already running */
	t->priority = HIGHEST_PRIORITY;
	t->state = THREAD_RUNNING;
	t->saved_critical_section_count = 1;
	list_add_head(&thread_list, &t->thread_list_node);
	current_thread = t;
}
再看看

static void init_thread_struct(thread_t *t, const char *name)
{
	memset(t, 0, sizeof(thread_t));
	t->magic = THREAD_MAGIC;
	strlcpy(t->name, name, sizeof(t->name));   //把<span style="font-family: Arial, Helvetica, sans-serif;">bootstrap赋值给thread name</span>

}






  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值