rsp

Linux Kernel 起動時パラメータの渡され方

ブートローダLinux Kernel を起動するとき、パラメータを渡すことができる。

wiki.archlinux.jp

これはどうやって渡しているのか気になって*1ブートローダのソースを読んだ。

結論としては何のことはなく、C 言語上でアーキテクチャの calling convention にしたがって、適当な設定値リスト*2のポインタをレジスタに置いているようだった。

U-boot (Arm 用実装) の当該箇所

github.com

grep -r '"bootargs"' とかで grep して探した。 (ダブルクォートが大事)

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 内の構造体。実行環境に応じて、いじっていいメモリ領域なんかが渡ってくるみたいですね。

*1:具体的には、アーキテクチャごとに何番レジスタに何を渡すとか決められてるのか?等

*2:linked list ではなく、要素型が自由な配列 (各要素が tag を持っていてその中にサイズを持っている)