之前看过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>
}