標籤:
?u-boot與linux通訊格式
?
?
如,開機時執行u-boot, u-boot引導完後,就是交給linux系統了,但是linux需要一些基本資料,如記憶體大小,啟動方式等,這就涉及到u-boot和linux通訊。
而通訊格式由linux規定了,以其中atag格式舉例,詳情查閱Documentation/arm/Setup
?
格式結構體為struct tag: 定義在 Setup.h (src\arch\arm\include\uapi\asm):147
struct tag {
struct tag_header hdr;
union {
struct tag_core core;
struct tag_mem32 mem;
struct tag_videotext videotext;
struct tag_ramdisk ramdisk;
struct tag_initrd initrd;
struct tag_serialnr serialnr;
struct tag_revision revision;
struct tag_videolfb videolfb;
struct tag_cmdline cmdline;
?
/*
* Acorn specific
*/
struct tag_acorn acorn;
?
/*
* DC21285 specific
*/
struct tag_memclk memclk;
} u;
};
?
?
u-boot會按照上述格式,在記憶體中劃分一塊atag參數地區,對該地區進行賦值。此處不對u-boot做討論,後面在專門寫文章。當賦值完成後,將cpu初始化成 MMU = off, D-cache = off, I-cache = dont care, r0 = 0, r1 = machine nr, r2 = atags or dtb pointer,跳轉到linux代碼起始處。
?
Linux atag參數解析流程
Linux代碼執行後,在第一階段(start_kernel函數之前),會驗證該地區正確性(bl __vet_atags)。
進入第二階段後(start_kernel函數之後):會開始真正解析atag參數,並賦值給相應的變數。流程:start_kernel →setup_arch→setup_machine_tags→parse_tags→parse_tag
?
Init.h (src\include\linux) :中定義了大部分的 section,比較重要的有
#define __init __section(.init.text) __cold notrace
#define __initdata __section(.init.data)
#define __initconst __constsection(.init.rodata)
#define __exitdata __section(.exit.data)
#define __exit_call __used __section(.exitcall.exit)
?
?
【linux】U-BOOT與linux kernel通訊: struct tag