BuildrootでQEMUで動作するLinux MIPSイメージを作る

Buildrootを使用してQEMUで動作するLinux MIPSイメージを作成します。

Buildroot
http://buildroot.uclibc.org/

<使用環境>
CentOS 5.6
buildroot-2009.11.tar.gz

Buildroot実行環境の整備

Buildrootを実行するために必要なパッケージをインストールします。

# yum install binutils bzip2 gawk gcc gcc-c++ gettext make ncurses-devel patch unzip wget zlib-devel

Buildrootのダウンロード

Buildrootをダウンロードします。
buildroot-2009.11.tar.gz を使用します。

Buildrootダウンロードサイト
http://buildroot.uclibc.org/download.html

$ cd ~/
$ wget http://git.buildroot.net/buildroot/snapshot/buildroot-2009.11.tar.gz

Buildrootの展開

ダウンロードしたファイルbuildroot-2009.11.tar.gzを展開して、そのディレクトリに入ります。

$ tar zxvf buildroot-2009.11.tar.gz
$ cd buildroot-2009.11

ダウンロードファイル格納用ディレクトリの作成とリンク

ダウンロードファイル格納用ディレクトリを作成し、そのシンボリックリンクをbuildroot-2009.11ディレクトリに作成します。

$ mkdir ../dl
$ ln -s ../dl

[mips@localhost ~]$ pwd
/home/mips
[mips@localhost ~]$ ls -l
合計 28
drwxr-xr-x 2 mips mips 4096 10月 12 20:17 Desktop
drwxrwxr-x 9 mips mips 4096 10月 13 20:29 buildroot-2009.11
drwxrwxr-x 2 mips mips 4096 10月 18 11:20 debian
drwxrwxr-x 2 mips mips 4096 10月 13 17:19 dl
drwxr-xr-x 2 mips mips 4096 10月 14 09:00 mips-test
-rwxr-xr-x 1 mips mips  338 10月 18 00:19 qemu_start.sh
-rwxr-xr-x 1 mips mips  254 10月 17 23:15 qemu_start.sh.org
[mips@localhost ~]$ 

[mips@localhost buildroot-2009.11]$ pwd
/home/mips/buildroot-2009.11
[mips@localhost buildroot-2009.11]$ ls -l
合計 104
-rw-rw-r--   1 mips mips 11458 12月  1  2009 CHANGES
-rw-rw-r--   1 mips mips 17987 12月  1  2009 COPYING
-rw-rw-r--   1 mips mips 10130 12月  1  2009 Config.in
-rw-rw-r--   1 mips mips 19497 12月  1  2009 Makefile
-rw-rw-r--   1 mips mips   806 12月  1  2009 TODO
drwxrwxr-x   2 mips mips  4096 12月  1  2009 configs
lrwxrwxrwx   1 mips mips     5 10月 12 20:24 dl -> ../dl
drwxrwxr-x   3 mips mips  4096 12月  1  2009 docs
drwxrwxr-x   9 mips mips  4096 10月 13 19:14 output
drwxrwxr-x 306 mips mips 12288 12月  1  2009 package
drwxrwxr-x   3 mips mips  4096 12月  1  2009 scripts
drwxrwxr-x  21 mips mips  4096 12月  1  2009 target
drwxrwxr-x  13 mips mips  4096 12月  1  2009 toolchain
[mips@localhost buildroot-2009.11]$ 

Buildrootのコンフィギュレーション

Buildroot ConfigurationでBuildrootのコンフィギュレーションを行います。

$ make menuconfig

.config - buildroot v2009.11 Configuration

Target Architecture (mips) --->
Target Architecture Variant (mips I (generic)) --->
Target ABI (o32) --->
Target options --->
Build options --->
Toolchain --->
Package Selection for the target --->
Target filesystem options --->
Kernel --->
---
Load an Alternate Configuration File
Save an Alternate Configuration File

Linux Kernelのコンフィギュレーション

BuildrootでLinux Kernel 2.6のコンフィギュレーションを行います。

$ make linux26-menuconfig

Machine selection で
MIPS Malta board (MIPS_MALTA)
を指定します。

Buildrootのコンパイル

Buildrootをコンパイルします。

$ make

コンパイル中に、Linux Kernelのコンフィギュレーションが必要になります。

コンパイル後、 buildroot-2009.11/output/images ディレクトリに、
Linux image:
 vmlinux
root file system:
 rootfs.mips.ext2
 rootfs.mips.cpio
 rootfs.mips.cramfs
が作成されます。

 [mips@localhost images]$ pwd
/home/mips/buildroot-2009.11/output/images
[mips@localhost images]$ ls -la
合計 68596
drwxrwxr-x 2 mips mips     4096 10月 18 14:51 .
drwxrwxr-x 9 mips mips     4096 10月 18 12:52 ..
-rw-rw-r-- 1 mips mips 18800128 10月 18 21:41 rootfs.mips.cpio
-rw-rw-r-- 1 mips mips  6311936 10月 18 21:42 rootfs.mips.cramfs
-rw-rw-r-- 1 mips mips 38567936 10月 18 21:53 rootfs.mips.ext2
-rw-rw-r-- 1 mips mips   151431 10月 18 21:40 rootfs.mips.initramfs_list
-rwxrwxr-x 1 mips mips  6303215 10月 18 21:41 vmlinux
[mips@localhost images]$ 

[mips@localhost dl]$ ls -l
合計 270728
-rw-rw-r-- 1 mips mips  1313833  7月 27  2009 autoconf-2.64.tar.bz2
-rw-rw-r-- 1 mips mips   893866 10月 16  2006 automake-1.10.tar.bz2
-rw-r--r-- 1 mips mips 16306586 10月 12 20:25 binutils-2.19.1.tar.bz2
-rw-rw-r-- 1 mips mips    32657  1月  9  2008 bridge-utils-1.4.tar.gz
-rw-r--r-- 1 mips mips  1987590 10月 12 20:25 busybox-1.15.2.tar.bz2
-rwxrwxr-x 1 mips mips    24179 10月 18 14:49 cramfs-1.1.tar.gz
-rw-rw-r-- 1 mips mips   876591 10月 12 22:32 dhcp-3.0.5.tar.gz
-rw-r--r-- 1 mips mips   395829 10月 12 20:25 fakeroot_1.9.5.tar.gz
-rw-r--r-- 1 mips mips 59368714 10月 12 20:26 gcc-4.3.4.tar.bz2
-rw-r--r-- 1 mips mips   101384 10月 12 20:26 genext2fs-1.4.tar.gz
-rw-r--r-- 1 mips mips  1710660 10月 12 20:26 gmp-4.2.4.tar.bz2
-rw-rw-r-- 1 mips mips   461480  9月 15  2009 iptables-1.4.5.tar.bz2
-rw-rw-r-- 1 mips mips  2919557  6月 26  2007 libtool-1.5.24.tar.gz
-rw-r--r-- 1 mips mips 59414632 10月 12 20:26 linux-2.6.30.2.tar.bz2
-rw-r--r-- 1 mips mips 61446679 10月 12 20:26 linux-2.6.31.6.tar.bz2
-rw-rw-r-- 1 mips mips 61494822  9月 10  2009 linux-2.6.31.tar.bz2
-rw-rw-r-- 1 mips mips   609666  3月 24  2007 m4-1.4.9.tar.bz2
-rw-r--r-- 1 mips mips   169182 10月 12 20:26 module-init-tools-3.2.2.tar.bz2
-rw-r--r-- 1 mips mips    10044 10月 12 20:26 mpfr-2.4.1.patch
-rw-r--r-- 1 mips mips  1064281 10月 12 20:26 mpfr-2.4.1.tar.bz2
-rw-rw-r-- 1 mips mips  1250777  6月 26  2006 nano-1.3.12.tar.gz
-rw-rw-r-- 1 mips mips  2402592 12月 23  2006 ncurses-5.6.tar.gz
-rw-r--r-- 1 mips mips  2285137 10月 12 20:26 uClibc-0.9.30.1.tar.bz2
-rw-rw-r-- 1 mips mips   294417  9月 18  2007 wireless_tools.29.tar.gz
[mips@localhost dl]$ 

Linuxイメージの起動

QEMUでlinuxイメージを起動します。

次のような起動スクリプト mips_linux.sh を作成します。
$ nano mips_linux.sh

#!/bin/sh
LOCATION="/home/mips/buildroot-2009.11/output/images"
KERNEL="vmlinux"
DISK="rootfs.mips.ext2"
qemu-system-mips -kernel $LOCATION/$KERNEL \
-hda $LOCATION/$DISK \
-boot c \
-m 128 \
-append "root=/dev/hda rw console=ttyS0" \
-localtime \
-no-reboot \
-name Linux \
-nographic \
-k ja

mips_linux.sh に実行権限を付けておきます。
$ chmod +x mips_linux.sh

QEMUを起動します。
$ ./mips_linux.sh

root でログインします。
パスワードは必要ありません。

LinkIconbootメッセージ

ネットワークインターフェースの設定

/etc/network/interfaces を編集します。
# vi /etc/network/interfaces

eth0の設定を追加します。

auto eth0
iface eth0 inet dhcp

milk_btn_pagetop.png

bootメッセージ  

[mips@localhost ~]$ ./mips_linux.sh 
[    0.000000] Linux version 2.6.31 (mips@localhost.localdomain) (gcc version 4.3.4 (GCC) ) #3 Tue Oct 18 21:41:50 JST 2011
[    0.000000] 
[    0.000000] LINUX started...
[    0.000000] console [early0] enabled
[    0.000000] CPU revision is: 00019300 (MIPS 24Kc)
[    0.000000] FPU revision is: 00000000
[    0.000000] registering PCI controller with io_map_base unset
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 00001000 @ 00000000 (reserved)
[    0.000000]  memory: 000ef000 @ 00001000 (ROM data)
[    0.000000]  memory: 0055c000 @ 000f0000 (reserved)
[    0.000000]  memory: 079b3000 @ 0064c000 (usable)
[    0.000000] Wasting 51584 bytes for tracking 1612 unused pages
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Zone PFN ranges:
[    0.000000]   DMA      0x00000000 -> 0x00001000
[    0.000000]   Normal   0x00001000 -> 0x00007fff
[    0.000000] Movable zone start PFN for each node
[    0.000000] early_node_map[1] active PFN ranges
[    0.000000]     0: 0x00000000 -> 0x00007fff
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32511
[    0.000000] Kernel command line: root=/dev/hda rw console=ttyS0
[    0.000000] PID hash table entries: 512 (order: 9, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Primary instruction cache 2kB, VIPT, 2-way, linesize 16 bytes.
[    0.000000] Primary data cache 2kB, 2-way, VIPT, no aliases, linesize 16 bytes
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] Memory: 123316k/124620k available (3918k kernel code, 1128k reserved, 1099k data, 252k init, 0k highmem)
[    0.000000] Hierarchical RCU implementation.
[    0.000000] NR_IRQS:256
[    0.000000] CPU frequency 200.13 MHz
[    0.001000] Console: colour dummy device 80x25
[    0.002000] Calibrating delay loop... 1576.96 BogoMIPS (lpj=788480)
[    0.028000] Security Framework initialized
[    0.030000] Mount-cache hash table entries: 512
[    0.041000] NET: Registered protocol family 16
[    0.045000] bio: create slab  at 0
[    0.047000] SCSI subsystem initialized
[    0.051000] pci 0000:00:0a.3: BAR 14: address space collision on of bridge [0x1100-0x110f]
[    0.052000] pci 0000:00:0a.3: quirk: region 1100-110f claimed by PIIX4 SMB
[    0.054000] pci 0000:00:0a.3: BAR 14: bogus alignment [0x1100-0x110f] flags 0x100
[    0.059000] NET: Registered protocol family 2
[    0.070000] IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.077000] TCP established hash table entries: 4096 (order: 3, 32768 bytes)
[    0.081000] TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
[    0.086000] TCP: Hash tables configured (established 4096 bind 4096)
[    0.088000] TCP reno registered
[    0.097000] NET: Registered protocol family 1
[    0.112000] VFS: Disk quotas dquot_6.5.2
[    0.119000] Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    0.124000] JFFS2 version 2.2. (NAND) c 2001-2006 Red Hat, Inc.
[    0.128000] ROMFS MTD (C) 2007 Red Hat, Inc.
[    0.130000] fuse init (API version 7.12)
[    0.132000] msgmni has been set to 241
[    0.167000] alg: No test for fcrypt (fcrypt-generic)
[    0.211000] alg: No test for stdrng (krng)
[    0.212000] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253)
[    0.215000] io scheduler noop registered
[    0.215000] io scheduler anticipatory registered (default)
[    0.301000] ipmi message handler version 39.2
[    0.304000] ipmi device interface
[    0.304000] IPMI System Interface driver.
[    0.307000] ipmi_si: Unable to find any System Interface(s)
[    0.310000] IPMI Watchdog: driver initialized
[    0.315000] Copyright (C) 2004 MontaVista Software - IPMI Powerdown via sys_reboot.
[    0.317000] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.330000] serial8250.0: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[    0.351000] console handover: boot [early0] -> real [ttyS0]
[    0.364000] serial8250.0: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
[    0.368000] serial8250.0: ttyS2 at MMIO 0x1f000900 (irq = 18) is a 16550A
[    0.379000] Floppy drive(s): fd0 is 1.44M
[    0.400000] FDC 0 is a S82078B
[    0.404000] brd: module loaded
[    0.409000] loop: module loaded
[    0.414000] Uniform Multi-Platform E-IDE driver
[    0.416000] piix 0000:00:0a.1: IDE controller (0x8086:0x7111 rev 0x00)
[    0.424000] PCI: Enabling device 0000:00:0a.1 (0000 -> 0001)
[    0.428000] piix 0000:00:0a.1: not 100% native mode: will probe irqs later
[    0.431000]     ide0: BM-DMA at 0x1040-0x1047
[    0.436000]     ide1: BM-DMA at 0x1048-0x104f
[    0.732000] hda: QEMU HARDDISK, ATA DISK drive
[    1.354000] hda: UDMA/33 mode selected
[    2.065000] hdc: QEMU DVD-ROM, ATAPI CD/DVD-ROM drive
[    2.683000] hdc: UDMA/33 mode selected
[    2.685000] ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
[    2.687000] ide1 at 0x170-0x177,0x376 on irq 15
[    2.694000] ide_generic: please use "probe_mask=0x3f" module parameter for probing all legacy ISA IDE ports
[    2.697000] ide-gd driver 1.18
[    2.699000] hda: max request size: 512KiB
[    2.700000] hda: 75328 sectors (38 MB) w/256KiB Cache, CHS=74/255/63
[    2.715000] hda: cache flushes supported
[    2.718000]  hda: unknown partition table
[    2.742000] ide-cd driver 5.00
[    2.747000] ide-cd: hdc: ATAPI 4X CD-ROM drive, 512kB Cache
[    2.750000] Uniform CD-ROM driver Revision: 3.20
[    2.757000] Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)
[    2.760000] bonding: Warning: either miimon or arp_interval and arp_ip_target module parameters must be specified, otherwise bonding will not detect link failures! see bonding.txt for details.
[    2.769000] PPP generic driver version 2.4.2
[    2.771000] PPP Deflate Compression module registered
[    2.771000] PPP BSD Compression module registered
[    2.781000] PPP MPPE Compression module registered
[    2.785000] NET: Registered protocol family 24
[    2.786000] SLIP: version 0.8.4-NET3.019-NEWTTY (dynamic channels, max=256).
[    2.789000] CSLIP: code copyright 1989 Regents of the University of California.
[    2.789000] SLIP linefill/keepalive option.
[    2.789000] tun: Universal TUN/TAP device driver, 1.6
[    2.789000] tun: (C) 1999-2004 Max Krasnyansky 
[    2.792000] Generic platform RAM MTD, (c) 2004 Simtec Electronics
[    2.792000] Ramix PMC551 PCI Mezzanine Ram Driver. (C) 1999,2000 Nortel Networks.
[    2.794000] pmc551: not detected
[    2.794000] serio: i8042 KBD port at 0x60,0x64 irq 1
[    2.796000] serio: i8042 AUX port at 0x60,0x64 irq 12
[    2.804000] mice: PS/2 mouse device common for all mice
[    2.807000] i2c /dev entries driver
[    2.808000] pc87360: PC8736x not detected, module not inserted.
[    2.810000] Software Watchdog Timer: 0.07 initialized. soft_noboot=0 soft_margin=60 sec (nowayout= 0)
[    2.810000] GACT probability on
[    2.811000] Mirror/redirect action on
[    2.811000] Simple TC action Loaded
[    2.812000] netem: version 1.2
[    2.812000] u32 classifier
[    2.812000]     input device check on 
[    2.812000]     Actions configured 
[    2.813000] Netfilter messages via NETLINK v0.30.
[    2.813000] nf_conntrack version 0.5.0 (1947 buckets, 7788 max)
[    2.815000] CONFIG_NF_CT_ACCT is deprecated and will be removed soon. Please use
[    2.815000] nf_conntrack.acct=1 kernel parameter, acct=1 nf_conntrack module option or
[    2.815000] sysctl net.netfilter.nf_conntrack_acct=1 to enable it.
[    2.823000] ctnetlink v0.93: registering with nfnetlink.
[    2.824000] IPv4 over IPv4 tunneling driver
[    2.824000] GRE over IPv4 tunneling driver
[    2.829000] ip_tables: (C) 2000-2006 Netfilter Core Team
[    2.830000] ClusterIP Version 0.8 loaded successfully
[    2.831000] arp_tables: (C) 2002 David S. Miller
[    2.833000] TCP cubic registered
[    2.833000] Initializing XFRM netlink socket
[    2.833000] NET: Registered protocol family 17
[    2.836000] NET: Registered protocol family 15
[    2.836000] Bridge firewalling registered
[    2.836000] Ebtables v2.0 registered
[    2.837000] 802.1Q VLAN Support v1.8 Ben Greear 
[    2.839000] All bugs added by David S. Miller 
[    2.839000] drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
[    2.907000] input: AT Raw Set 2 keyboard as /devices/platform/i8042/serio0/input/input0
[    3.115000] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input1
[    3.151000] EXT2-fs warning: mounting unchecked fs, running e2fsck is recommended
[    3.153000] VFS: Mounted root (ext2 filesystem) on device 3:0.
[    3.157000] Freeing prom memory: 956k freed
[    3.171000] Freeing unused kernel memory: 252k freed
Initializing random number generator... done.
Starting network...
ip: RTNETLINK answers: File exists

Welcome to Buildroot
buildroot login: 

milk_btn_pagetop.png

2011.10.18