android lk解讀

來源:互聯網
上載者:User

  之前看過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 contextthread_init_early();// early arch stuffarch_early_init();// do any super early platform initializationplatform_early_init();// do any super early target initializationtarget_early_init();dprintf(INFO, "welcome to lk\n\n");bs_set_timestamp(BS_BL_START);// deal with any static constructorsdprintf(SPEW, "calling constructors\n");call_constructors();// bring up the kernel heapdprintf(SPEW, "initializing heap\n");heap_init();__stack_chk_guard_setup();// initialize the threading systemdprintf(SPEW, "initializing threads\n");thread_init();// initialize the dpc systemdprintf(SPEW, "initializing dpc\n");dpc_init();// initialize kernel timersdprintf(SPEW, "initializing timers\n");timer_init();#if (!ENABLE_NANDWRITE)// create a thread to complete system initializationdprintf(SPEW, "creating bootstrap completion thread\n");thread_resume(thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE));// enable interruptsexit_critical_section();// become the idle threadthread_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>}






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.