メッセージ欄

2012年9月の日記

一覧で表示する

Raspberry Pi で NetBSD/evbarmをブートさせる(手抜き版)
2012/09/05(水) 25:53 Raspberry Pi, NetBSD はてブ情報 はてブに登録 はてブ数

Linuxが起動するSDカードを用意しておく。

Raspberry Pi用のkernelを作るか入手する。
今回は20120820なソースからビルドしたものを使った。

kernelをbinary形式に変換。
# objcopy -O srec netbsd netbsd.srec
# objcopy -I srec -O binary netbsd.srec netbsd.bin
Linuxが起動するSDカードのMS-DOSパーティションをマウント。

FreeBSD Developer's Notebookで紹介されている
U-Bootをダウンロード、展開しておき、MS-DOSパーティションにあるファイルを全部入れ替える。

ついでに先ほど作ったnetbsd.binもコピーしておく。

Raspberyy PiにSDカードを入れて起動する。もちろん、シリアルコンソールが使える状態で。

fatloadコマンドで0x00008000にkernelをロードさせて、goコマンドでジャンプ。
U-Boot> fatload mmc 0 00008000 netbsd.bin
U-Boot> go 00008000
## Starting application at 0x00008000 ...

NetBSD/evbarm (rpi) booting ...
initarm: Configuring system ...
physmemory: 32768 pages at 0x00000000 -> 0x07ffffff
Allocating page tables
Creating L1 page table at 0x002e0000
Mapping kernel
pmap_map_chunk: pa=0x0 va=0xc0000000 size=0x23b000 resid=0x23b000 prot=0x3 cache=1
SSLLLPPPPPPPPPPP
pmap_map_chunk: pa=0x23b000 va=0xc023b000 size=0xa2000 resid=0xa2000 prot=0x3 cache=1
PPPPPLLLLLLLLLPPPPPPPPPPPPP
Constructing L2 page tables
pmap_map_chunk: pa=0x2eb000 va=0xc02eb000 size=0x1000 resid=0x1000 prot=0x3 cache=1
P
pmap_map_chunk: pa=0x2ec000 va=0xc02ec000 size=0x1000 resid=0x1000 prot=0x3 cache=1
P
pmap_map_chunk: pa=0x2ed000 va=0xc02ed000 size=0x1000 resid=0x1000 prot=0x3 cache=1
P
pmap_map_chunk: pa=0x2ee000 va=0xc02ee000 size=0x1000 resid=0x1000 prot=0x3 cache=1
P
pmap_map_chunk: pa=0x2ef000 va=0xc02ef000 size=0x2000 resid=0x2000 prot=0x3 cache=1
PP
pmap_map_chunk: pa=0x2e0000 va=0xc02e0000 size=0x4000 resid=0x4000 prot=0x3 cache=2
PPPP
pmap_map_chunk: pa=0x2dd000 va=0xc02dd000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0x2de000 va=0xc02de000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0x2df000 va=0xc02df000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0x2e4000 va=0xc02e4000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0x2e5000 va=0xc02e5000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0x2e6000 va=0xc02e6000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0x2e7000 va=0xc02e7000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0x2e8000 va=0xc02e8000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0x2e9000 va=0xc02e9000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
devmap: 20000000 -> 20ffffff @ f2000000
pmap_map_chunk: pa=0x20000000 va=0xf2000000 size=0x1000000 resid=0x1000000 prot=0x3 cache=0
SSSSSSSSSSSSSSSS
                             Physical              Virtual        Num
                       Starting    Ending    Starting    Ending   Pages
               SDRAM: 0x00000000 0x07ffffff 0xc0000000 0xc7ffffff 32768
        text section: 0x00000000 0x0023ab37 0xc0000000 0xc023ab37 571
        data section: 0x00240000 0x002c3a00 0xc0240000 0xc02c3a00 132
         bss section: 0x002c3a00 0x002dc5a0 0xc02c3a00 0xc02dc5a0 26
   L1 page directory: 0x002e0000 0x002e3fff 0xc02e0000 0xc02e3fff 4
   Exception Vectors: 0x002ea000 0x002eafff 0xffff0000 0xffff0fff 1
           FIQ stack: 0x002eb000 0x002ebfff 0xc02eb000 0xc02ebfff 1
           IRQ stack: 0x002ec000 0x002ecfff 0xc02ec000 0xc02ecfff 1
           ABT stack: 0x002ed000 0x002edfff 0xc02ed000 0xc02edfff 1
           UND stack: 0x002ee000 0x002eefff 0xc02ee000 0xc02eefff 1
           SVC stack: 0x002ef000 0x002f0fff 0xc02ef000 0xc02f0fff 2
      Message Buffer: 0x002f1000 0x002f1fff                       1
         Free Memory: 0x002f2000 0x07ffffff 0xc02f2000 0xc7ffffff 32014
switching to new L1 page table  @0x2e0000...OK.
freestart = 0x002f2000, free_pages = 32014 (0x00007d0e)
bootstrap done.
init subsystems: stacks vectors undefined page pmap done.
Loaded initial symtab at 0xc024451c, strtab at 0xc0269dd8, # entries 9534
pmap_postinit: Allocated 35 static L1 descriptor tables
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    2006, 2007, 2008, 2009, 2010, 2011, 2012
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 6.99.10 (RPI) #0: Fri Aug 24 10:18:39 UTC 2012
        root@.localdomain:/export/o/20120820/evbarm/sys/arch/evbarm/compile/RPI
total memory = 128 MB
avail memory = 122 MB
cprng kernel: WARNING insufficient entropy at creation.
mainbus0 (root)
cpu0 at mainbus0: ARM1176JZ-S r0p7 (ARM11J core)
cpu0: DC enabled IC enabled WB enabled LABT
cpu0: 16KB/32B 4-way Instruction cache
cpu0: 16KB/32B 4-way write-back-locking-C Data cache
vfp0 at cpu0: VFP11
obio0 at mainbus0
bcmicu0 at obio0
bcmmbox0 at obio0: VC mailbox
bcmtmr0 at obio0 intr 3: VC System Timer
bcmpm0 at obio0: Power management, Reset and Watchdog controller
plcom0 at obio0 intr 57
plcom0: txfifo disabled
plcom0: console
sdhc0 at obio0 intr 62: SDHC controller
sdhc0: interrupting on intr 62
sdhc0: SD Host Specification 3.0, rev.153
sdmmc0 at sdhc0 slot 0
ld0 at sdmmc0: <SD   >
ld0: 15740 MB, 7994 cyl, 64 head, 63 sec, 512 bytes/sect x 32235520 sectors
ld0: 4-bit width, bus clock 25.000 MHz
cprng sysctl: WARNING insufficient entropy at creation.
boot device: <unknown>
root on ld0a dumps on ld0b
vfs_mountroot: can't open root device
cannot mount root, error = 6
root device (default ld0a):

Raspberry Piのブートプロセスを想像する
2012/09/02(日) 20:41 Raspberry Pi はてブ情報 はてブに登録 はてブ数

Raspberry PiのLinuxイメージの中身をみて、どういう仕組みでブートしていたのかを想像していたときの記録が出てきたのでメモとして残しておきます。

disklabeはこんな感じ。MSDOSとext2パーティションが見えています。
#        size    offset     fstype [fsize bsize cpg/sgs]
 d:  32235520         0     unused      0     0        # (Cyl.      0 -  15739)
 e:    114688      8192      MSDOS                     # (Cyl.      4 -     59)
 f:   3665920    122880 Linux Ext2      0     0        # (Cyl.     60 -   1849)
MS-DOSパーティションをマウントして中を見てみます。
# ls /mnt
arm128_start.elf          cmdline.txt               kernel_emergency.img
arm192_start.elf          config.txt                loader.bin
arm224_start.elf          issue.txt                 start.elf
arm240_start.elf          kernel.img
bootcode.bin              kernel_cutdown.img
テキストファイルの中身を見ていきましょう。

cmdline.txtはLinuxカーネルに与えるパラメータを書いているようです。
# cat cmdline.txt 
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
少し見やすくしてみます。
dwc_otg.lpm_enable=0 
console=ttyAMA0,115200 
kgdboc=ttyAMA0,115200 
console=tty1 
root=/dev/mmcblk0p2 
rootfstype=ext4 
elevator=deadline 
rootwait
config.txtは何でしょうね。このファイルを変更すると、HDMIの設定やフレームバッファの設定が変更できるのでしょうか。オーバークロックの設定もあって、気になります。
# cat config.txt 
# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# for more options see http://elinux.org/RPi_config.txt
issue.txtはこのカーネルが作られたときの情報なのでしょうかね。URLを見てみると、spindleというのはRaspberry Piのイメージを作るプロジェクトのようですね。
# cat issue.txt 
Raspberry Pi reference 2012-08-16 (armhf)
Generated using spindle, http://asbradbury.org/projects/spindle/, f85b818, stage4-lxde-edu.qed
バイナリファイルはfileコマンドでさらっと。

たくさんあるarmXXX_start.elfは搭載メモリによって用意されているようなのですが良くわかりません。readelf -aしてみると、エントリポイント含めたアドレスだけが違っているようです。startっていう名前からして、いかにも最初に呼ばれそうな感じがしますが、ELFを解釈できる誰かが動いてから最初に、っていう感じですかね。
# file *.elf
arm128_start.elf: ELF 32-bit LSB executable, version 1 (SYSV), statically linked, stripped
arm192_start.elf: ELF 32-bit LSB executable, version 1 (SYSV), statically linked, stripped
arm224_start.elf: ELF 32-bit LSB executable, version 1 (SYSV), statically linked, stripped
arm240_start.elf: ELF 32-bit LSB executable, version 1 (SYSV), statically linked, stripped
start.elf:        ELF 32-bit LSB executable, version 1 (SYSV), statically linked, stripped
IMGファイルは名前のとおりカーネル本体なのでしょう。標準カーネルと軽量カーネルと緊急用カーネルといったところでしょうか。
# file *.img
kernel.img:           DBase 3 index file
kernel_cutdown.img:   DBase 3 index file
kernel_emergency.img: DBase 3 index file
BINファイルはARMのbinaryファイルなのでしょう。この二つのbinaryファイルがLinuxカーネルを呼んでいるんでしょうねぇ。さっきのstart.elfはどう絡むんでしょうか。
# file *.bin
bootcode.bin: data
loader.bin:   data