ブートローダが Linux Kernel を起動するとき、パラメータを渡すことができる。
これはどうやって渡しているのか気になって*1、ブートローダのソースを読んだ。
結論としては何のことはなく、C 言語上でアーキテクチャの calling convention にしたがって、適当な設定値リスト*2のポインタをレジスタに置いているようだった。
U-boot (Arm 用実装) の当該箇所
grep -r '"bootargs"'
とかで grep して探した。 (ダブルクォートが大事)
- 設定値リストのポインタが
bd->bi_boot_params
で、これを翻訳単位スコープのparams
にコピーしていじっている - コマンドラインの文字列をparamsに繋げている
- カーネルのエントリポイントアドレスを関数ポインタと読み替えて、引数に bi_boot_params を渡してジャンプしている
struct bd_info* bd って何
u-boot/u-boot.h at 2ae80437fbe0181184ae4b188b89629b902702c6 · u-boot/u-boot · GitHub
struct bd_info { unsigned long bi_flashstart; /* start of FLASH memory */ unsigned long bi_flashsize; /* size of FLASH memory */ unsigned long bi_flashoffset; /* reserved area for startup monitor */ unsigned long bi_sramstart; /* start of SRAM memory */ unsigned long bi_sramsize; /* size of SRAM memory */ #ifdef CONFIG_ARM unsigned long bi_arm_freq; /* arm frequency */ unsigned long bi_dsp_freq; /* dsp core frequency */ unsigned long bi_ddr_freq; /* ddr frequency */ #endif /* SNIPPED */ ulong bi_arch_number; /* unique id for this board */ ulong bi_boot_params; /* where this board expects params */ struct { /* RAM configuration */ phys_addr_t start; phys_size_t size; } bi_dram[CONFIG_NR_DRAM_BANKS]; };
U-boot 内の構造体。実行環境に応じて、いじっていいメモリ領域なんかが渡ってくるみたいですね。