まず、mini2440用に調整されているらしい、u-bootのソースを取得します。
$ mkdir uboot ; cd uboot
$ git clone git://repo.or.cz/u-boot-openmoko/mini2440.git
$ ls
mini2440
$ tar cvzof uboot-mini2440_git_orig.tar.gz mini2440
$ cd mini2440
$ export CROSS_COMPILE=arm-linux-
$ make mini2440_config 一瞬
$ make all 今時のPCでざーっと流れて2,3分
2010/07/19現在でgitで持ってきたもの.tar.gz↑
つぎにシリアルポートの実験をする。
ボードの電源を落とし、PCの(USB経由の)シリアルポートとボードのDsub9pinを接続する(クロスケーブル)。
PC側で適切なポートを開き、通信条件を 115200bps (標準:8bit 1スタート1ストップ)に設定する。
この状態で電源をいれる。
VIVI version 0.1.4 (root@russell-work-pc) (gcc version 2.95.3
20010315 (release)) #0.1.4 Tue Jun 16 15:20:37 CST 2009
MMU table base address = 0x33DFC000
Succeed memory mapping.
DIVN_UPLL0
MPLLVal [M:7fh,P:2h,S:1h]
CLKDIVN:5h
+---------------------------------------------+
| S3C2440A USB Downloader ver R0.03 2004 Jan |
+---------------------------------------------+
USB: IN_ENDPOINT:1 OUT_ENDPOINT:3
FORMAT: +++
NOTE: Power off/on or press the reset button for 1 sec
in order to get a valid USB device address.
NAND device: Manufacture ID: 0xec, Chip ID: 0x76 (Samsung K9D1208V0M)
Could not found stored vivi parameters. Use default vivi parameters.
Press Return to start the LINUX/Wince now, any other key for vivi
Copy linux kernel from 0x00050000 to 0x30008000, size = 0x00200000 ... done
zImage magic = 0x016f2818
Setup linux parameters at 0x30000100
linux command line is: "noinitrd root=/dev/mtdblock2 init=/linuxrc
console=ttySAC0"
MACH_TYPE = 782
NOW, Booting Linux......
Uncompressing Linux............................................................
Linux version 2.6.29.4-FriendlyARM (root@russell-work-pc)
(gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #4 Tue Jun 9 16:32:08 CST 2009
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: FriendlyARM Mini2440 development board
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
:
hwclock: settimeofday() failed: Invalid argument
[19/Dec/2003:06:17:30 +0000] boa: server version Boa/0.94.13
[19/Dec/2003:06:17:30 +0000] boa: server built Mar 26 2009 at 15:28:42.
[19/Dec/2003:06:17:30 +0000] boa: starting server pid=498, port 80
Try to bring eth0 interface up......eth0: link down
Done
Please press Enter to activate this console.
というような感じで、ブートシーケンスが流れる。
ここで、Enterすると、rootのシェルがひらかれる。手元のものでディスク容量は64M中50Mほど使っていて余裕の少ない状態。
シリアルポート、USBの接続を確認して電源をいれる。
USB接続が認識されて、ドライバの組み込みが行われる。
ターミナルには、
##### FriendlyARM BIOS for 2440 #####
[x] bon part 0 320k 2368k
[v] Download vivi
[k] Download linux kernel
[y] Download root_yaffs image
:
[s] Set the boot parameters
[t] Print the TOC struct of wince
[u] Backup NAND Flash to HOST through USB(upload)
[r] Restore NAND Flash from HOST through USB
[q] Goto shell of vivi
Enter your selection:
な感じで表示される。
そのままdnw.zipを展開して出てくる、dnw.exeを実行する。
バックアップを行う。
先ほどのターミナルで、「u」を入力。
Enter your selection: u
Backup Information:
Start Addr : 0x0
End Addr : 0x4000000
bBackupOOB : 1
bCheckBad : 1
dwBackupTotalLen : 0x4200000
dwReservedBlks : 20
dwEPInPktSize : 32
Use dnw.exe to receive backup.
という表示が出るので、dnw.exeのメニュー[USB Port]→[Backup Nand Flash to File]を実行すると、保存ファイルを聞かれるので、適当な名前で保存する。
なお、書き戻しは、[r]を選択の上、[USB Port]→[Transmit/Restore]
DNWで[USB Port]→[Transmit/Restore]して
ダウンロード済みのu-boot---.zipのなかの、u-boot-v132.bin を選択する。
##### FriendlyARM BIOS for 2440 #####
[x] bon part 0 320k 2368k
[v] Download vivi
:
[r] Restore NAND Flash from HOST through USB
[q] Goto shell of vivi
Enter your selection: q ※ [q]
Supervivi> load flash 0 246164 u ※ コマンド入力
USB host is connected. Waiting a download.
Now, Downloading [ADDRESS:30000000h,TOTAL:246174]
RECEIVED FILE SIZE: 246174 (240KB/S, 1S)
Downloaded file at 0x30000000, size = 246164 bytes
Found block size = 0x00040000
Erasing... ... done
Writing... ... done
Written 246164 bytes
Supervivi>
なお、load の引数は、開始番地と転送するバイト数(u-boot.binの大きさ)と推定される。
一度電源を切り、ROMスイッチを奥側に切り替え、起動し直す。
(USBの認識がされないと警告が出た)
U-Boot 1.3.2-mini2440 (May 25 2010 - 19:15:21)
I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: Bad block table not found for chip 0
Bad block table not found for chip 0
64 MiB
*** Warning - bad CRC or NAND, using default environment
USB: S3C2410 USB Deviced
In: serial
Out: serial
Err: serial
MAC: 08:08:11:18:12:27
Hit any key to stop autoboot: 0
MINI2440 #
続けて、メモリのチェックを行う。
nand scrub, nand createbbt を実行し、yで答える(エコーバック無しでEnter必要)
MINI2440 # nand scrub ※入力
NAND scrub: device 0 whole chip
Warning: scrub option will erase all factory set bad blocks!
There is no reliable way to recover them.
Use this command only for testing purposes if you
are sure of what you are doing!
Really scrub this NAND flash? ※ [y]、[Enter]を押す。
Erasing at 0x2850000 -- 63% complete.
NAND 64MiB 3,3V 8-bit: MTD Erase failure: -5
Erasing at 0x3ffc000 -- 100% complete.
Bad block table not found for chip 0
Bad block table not found for chip 0
OK
MINI2440 # nand createbbt ※入力
Create BBT and erase everything ? ※ [y]、[Enter]を押す。
Skipping bad block at 0x0287c000
Skipping bad block at 0x03ff0000
Skipping bad block at 0x03ff4000
Skipping bad block at 0x03ff8000
Skipping bad block at 0x03ffc000
Creating BBT. Please wait ...Bad block table not found for chip 0
Bad block table not found for chip 0
(2,30秒はかかるのでしばらく待つ)
Bad block table written to 0x03ffc000, version 0x01
Bad block table written to 0x03ff8000, version 0x01
MINI2440 #
スイッチを奥側に切り替えて電源投入。
依然として、"*** Warning - bad CRC or NAND, using default environment"がでる。
以下の2コマンドを実行する(dynenv set 40000, saveenv)。
MINI2440 # dynenv set 40000
device 0 offset 0x40000, size 0x3fc0000
45 4e 56 30 - 00 00 04 00
MINI2440 # saveenv
Saving Environment to NAND...
Erasing Nand...Writing to Nand... done
電源を入れ直すと、今度はWarningがでない。
U-Boot 1.3.2-mini2440 (May 25 2010 - 19:15:21)
I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 64 MiB
Found Environment offset in OOB..
USB: S3C2410 USB Deviced
In: serial
Out: serial
Err: serial
MAC: 08:08:11:18:12:27
Hit any key to stop autoboot: 0
MINI2440 #
パーティションを切る。
パーティションは
/dev/sdb1 type 0C 100M (Kernel Image 等)
/dev/sdb2 type 83 700M (main rootfs)
/dev/sdb3 type 82 128M (swap)
程度とする。2GのSDを使うと1G程度あまりがでるが、放置しておく。
あとで容量的に不足してから、/optなり/homeなりとしてパーティションを追加して使う。
最初から大きく確保しないのは、この後行う、インストール確認後の丸ごとバックアップをする際に無駄に大きくなりすぎないため。
以下、操作の例:
$ sudo fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): 【p】
Disk /dev/sdb: 1967 MB, 1967128576 bytes
57 heads, 56 sectors/track, 1203 cylinders
Units = cylinders of 3192 * 512 = 1634304 bytes
sSector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 1 1204 1920955+ 6 FAT16
Command (m for help): 【d】
Selected partition 1
Command (m for help): 【n】
Command action
e extended
p primary partition (1-4)
【p】
Partition number (1-4): 【1】
First cylinder (1-1203, default 1):【Enter】
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1203, default 1203): 【+100M】
Command (m for help): 【t】
Selected partition 1
Hex code (type L to list codes): 【0c】
Changed system type of partition 1 to c (W95 FAT32 (LBA))
Command (m for help): 【n】
Command action
e extended
p primary partition (1-4)
【p】
Partition number (1-4): 【2】
First cylinder (66-1203, default 66):【Enter】
Using default value 66
Last cylinder, +cylinders or +size{K,M,G} (66-1203, default 1203): 【+700M】
Command (m for help): 【n】
Command action
e extended
p primary partition (1-4)
【p】
Partition number (1-4): 【3】
First cylinder (516-1203, default 516):【Enter】
Using default value 516
Last cylinder, +cylinders or +size{K,M,G} (516-1203, default 1203): 【+128M】
Command (m for help): 【t】
Partition number (1-4): 【3】
Hex code (type L to list codes): 【82】
Changed system type of partition 3 to 82 (Linux swap / Solaris)
Command (m for help): 【p】
Disk /dev/sdb: 1967 MB, 1967128576 bytes
57 heads, 56 sectors/track, 1203 cylinders
Units = cylinders of 3192 * 512 = 1634304 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 1 65 103712 c W95 FAT32 (LBA)
/dev/sdb2 66 515 718200 83 Linux
/dev/sdb3 516 598 132468 82 Linux swap / Solaris
Command (m for help): 【w】
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
$
最後の【w】の入力でテーブルを書き出して終了。
もし、途中で削除を思いとどまったり、パーティションの切り分けに失敗しても w しなければ問題なし。
なお、一覧の Start, End, 操作途中で聞かれる先頭シリンダ番号は、SDカードによって(少なくともKingstonとSunDiskで)異なる。これは1シリンダ当たりの容量が異なるため
(57 heads, 56 sectors/track, 1203 cylinders // Units = cylinders of 3192 * 512 = 1634304 bytes の部分で heads,sectors/trackの違い)。
ファイルシステムを作る。
以下の手順で、FAT32(vfat), ext3 をつくる。
$ sudo mkfs.vfat /dev/sdb1
mkfs.vfat 3.0.7 (24 Dec 2009)
$ sudo mkfs.ext3 /dev/sdb2
mke2fs 1.41.11 (14-Mar-2010)
Filesystem label=
OS type: Linux
:
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
$
次に先ほどのSDカードを挿して、DHCPの可能なネットワークケーブルを繋いで、電源をいれます。
U-Boot 1.3.2-mini2440 (May 25 2010 - 19:15:21)
I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 64 MiB
Found Environment offset in OOB..
USB: S3C2410 USB Deviced
In: serial
Out: serial
Err: serial
MAC: 08:08:11:18:12:27
Hit any key to stop autoboot: 0
MINI2440 #
次に、以下のコマンドをプロンプトに入力します。
MINI2440 # setenv bootcmd 'mmcinit ; fatload mmc 0:1 0x31000000 uimage ; bootm 0x31000000'
MINI2440 # setenv bootargs (空白おいて続けて一行で)
'console=ttySAC0,115200 noinitrd root=/dev/mmcblk0p2 rootwait=4 rw ip=dhcp init=/bin/sh'
MINI2440 # boot
うまくいけば、Linuxが起動します。
MINI2440 # boot
mmc: Probing for SDHC ...
mmc: SD 2.0 or later card found
trying to detect SD Card...
Manufacturer: 0x02, OEM "TM"
Product name: "SD02G", revision 6.0
Serial number: 2716765588
Manufacturing date: 5/2010
CRC: 0x68, b0 = 1
READ_BL_LEN=15, C_SIZE_MULT=7, C_SIZE=365
size = 1642070016
SD Card detected RCA: 0xafd8 type: SD
reading uimage
2040148 bytes read
## Booting kernel from Legacy Image at 31000000 ...
Image Name:
Created: 2010-07-19 4:23:49 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2040084 Bytes = 1.9 MB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux.......................... done, booting the kernel.
Linux version 2.6.32-rc8 (kumagai@UbuntuCrossTest)
(gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #1 Mon Jul 19 00:15:15 EDT 2010
:
s3c2410-rtc s3c2410-rtc: setting system clock to 2140-01-26 12:04:30 UTC (1071898574)
s3c-sdi s3c2440-sdi: running at 398kHz (requested: 400kHz).
s3c-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz).
s3c-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz).
mmc0: new SD card at address afd8
(DHCP でIPアドレス取得を試みる)
kjournald starting. Commit interval 5 seconds
EXT3 FS on mmcblk0p2, internal journal
EXT3-fs: recovery complete.
EXT3-fs: mounted filesystem with writeback data mode.
VFS: Mounted root (ext3 filesystem) on device 179:2.
Freeing init memory: 132K
sh-3.2#
つぎに、ファイルのインストール作業の後半を行います。
sh-3.2# mount /proc /proc -t proc
sh-3.2# export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
sh-3.2# /debootstrap/debootstrap --second-stage
:
:
I: Configuring tasksel...
I: Base system installed successfully.
sh-3.2#
この、debootstrapのsecond stageはかなり時間がかかるので(手元で40分)、しばらく放置します。
なお、SDカード側にLEDが4個並んでいます。外から2番目がSDカードのアクセスランプになっていて、アクセス具合はわかります。
最後に再起動をして、自動的にU-BootからLinuxがあがるようにします。
ここではまだ 'shutdown -r now'は使えないようなので、syncしてexitあたりで。
なお、電源側にリセットスイッチがあります。
U-Bootのプロンプトで、
MINI2440 # setenv bootcmd 'mmcinit ; fatload mmc 0:1 0x31000000 uimage ; bootm 0x31000000'
MINI2440 # setenv bootargs (空白おいて続けて一行で)
'console=ttySAC0,115200n8 rootdelay=3 root=/dev/mmcblk0p2 rw rootfstype=ext3 rootwait'
MINI2440 # saveenv
Saving Environment to NAND...
Erasing Nand...Writing to Nand... done
MINI2440 # boot
先ほどに比較し、'saveenv'が増えています。
Debian GNU/Linux 5.0 mini2440 ttySAC0
mini2440 login: root (パスワード無しroot)
Linux mini2440 2.6.32-rc8 #1 Mon Jul 19 00:15:15 EDT 2010 armv4tl
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
mini2440:~#
時間がひどいことになっている場合は、設定した方がいいかもしれません。
mini2440:~# date
Sat Dec 20 06:41:58 UTC 2003
mini2440:~# date 072100432010
Wed Jul 21 00:43:00 UTC 2010
また、swapを使う場合の準備として、swapをつくっておきます。
mini2440:~# mkswap /dev/mmcblk0p3
Setting up swapspace version 1, size = 135540 kB
no label, UUID=c9b6d9d6-fb6f-4400-b28d-93557695f288
mini2440:~# swapon /dev/mmcblk0p3
Adding 132360k swap on /dev/mmcblk0p3. Priority:-1 extents:1 across:132360k SS
swapを使うのはあまり実用的ではありませんが、メモリがどうしても足りないとき(大きなコンパイルをしたい場合など)、swaponしておくと役に立つことがあります。
もう一度再起動して、今度は自動でカーネルが起動するかを確認します。
なお、まがりなりにもLinuxが動いているので、"shutdown -h now / shutdown -r now"などを使うべきでしょう。
以上で、SDカードで最低限のUbuntu Linux (armel lenny)が動くようになりました。
ここまでで、一通り、「起動するLinux環境」ができたので、このあといじることを考えて、バックアップします。
バックアップにはいろいろな手がありますが、ここでは、一番力任せな「パーティションを丸ごとバックアップ」でいきます。
なお、バックアップとリストアを行うと、カードのコピーができます。いろいろ試すときにコピーをつくるといいでしょう。
まず、SDカードをUbuntuに繋ぎます。
自動的にマウントされてファイルブラウザも開くと思うので、安全のため、umountします。
$ df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 19737268 6344636 12390036 34% /
:
/dev/sdb1 103492 3988 99504 4% /media/2165-6558
/dev/sdb2 706888 257384 413596 39% /media/9f1842b3-...
$ sudo umount /media/2165-6558/
[sudo] password for
$ sudo umount /media/9f1842b3-48ac-479d-8d5d-f5bd4e40c7ec/
$ dk -k で確認
つぎに、ddコマンドを使ってバックアップを作ります。if=とof=を間違うと(ファイルがすでにあると)上書き破壊を起こすので、気をつけて下さい。
$ mkdir image; cd image
$ sudo dd bs=1M if=/dev/sdb1 of=FASD_orig_sdb1.vfat
101+1 records in
101+1 records out
106201088 bytes (106 MB) copied, 41.7631 s, 2.5 MB/s
$ sudo dd bs=1M if=/dev/sdb2 of=FASD_orig_sdb2.ext
3
701+1 records in
701+1 records out
735436800 bytes (735 MB) copied, 80.4732 s, 9.1 MB/s
of=でファイル名を指定できます。拡張子を含め自由なので、わからなくならないように好きにつければいいです。
それぞれ、fdiskで確保したのとだいたい同じような容量のファイルができます。
なお、101+1, 701+1は、指定した(bs=1M)入出力の単位で101,701回の読み書きと半端なの1回分という表記で、SDカードの1シリンダ当たりの容量によっては、ファイルのバイト数共々異なる数字になり得ます。
もし、すっかり同じパーティション構成のSDカードがあれば、書き戻しは簡単です。
同じようにumountした上で、
$ mkdir image; cd image
$ sudo dd bs=1M if=FASD_orig_sdb1.vfat of=/dev/sdb1
$ sudo dd bs=1M if=FASD_orig_sdb2.ext of=/dev/sdb2
と、ifとofを逆にするだけです。(ファイルの側はchmod -wしておいたほうが無難か)。
書き込み後、起動確認をしてください。
コピーを作る場合などに新規のSDカードに書き込む場合は、パーティションの作成から必要です。
基本的には上のファイルシステム構築と一緒ですが、ブランドが異なるメディアを使う場合は容量の指定に注意が必要です。
$ $ ls -lk (サイズはキロバイト単位)
total 1646436
-r--r--r-- 1 root root 103712 2010-07-22 22:53 FASD_orig_sdb1.vfat
-r--r--r-- 1 root root 718200 2010-07-22 22:55 FASD_orig_sdb2.ext3
$ sudo fdisk /dev/sdb
中身を消す。
Command (m for help): p
Disk /dev/sdb: 1977 MB, 1977614336 bytes
61 heads, 62 sectors/track, 1021 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
メーカが異なるため、この数値が最初の例と異なる
※同じメーカーでも異なる場合あり
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1021, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1021, default 1021): +103712K
※ここで、前例の+100Mではなく、イメージのサイズをキロバイト表示した値、
※+103712K を指定。
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (57-1021, default 57):
Using default value 57
Last cylinder, +cylinders or +size{K,M,G} (57-1021, default 1021): +718200K
※同じく、+700Mではなく、+718200Kを使用
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (438-1021, default 438):
Using default value 438
Last cylinder, +cylinders or +size{K,M,G} (438-1021, default 1021): +128M
※swapは適当でいいので、適当に128M
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 82
Changed system type of partition 3 to 82 (Linux swap / Solaris)
※忘れずにパーティションタイプを設定
Command (m for help): p
Disk /dev/sdb: 1977 MB, 1977614336 bytes
61 heads, 62 sectors/track, 1021 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 56 105865 c W95 FAT32 (LBA)
/dev/sdb2 57 437 720471 83 Linux
/dev/sdb3 438 507 132370 82 Linux swap / Solaris
Command (m for help): w
The partition table has been altered!
ここで、以下の最初の例と比べてみます。
Disk /dev/sdb: 1967 MB, 1967128576 bytes
57 heads, 56 sectors/track, 1203 cylinders
Units = cylinders of 3192 * 512 = 1634304 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 65 103712 c W95 FAT32 (LBA)
/dev/sdb2 66 515 718200 83 Linux
/dev/sdb3 516 598 132468 82 Linux swap / Solaris
1シリンダ当たり(Units)が前より大きくなり、結果、シリンダ数(start-end)が小さくなりました。
一方、Blocks(1Kバイト単位)は前より大きくなりました。
つまり、必要な容量を確保した上で、Units単位に切り上げた領域、が確保されます。
(このバックアップ・リストアを繰り返すと、いずれはだんだん領域だけが大きくなる危険性があるので注意。
mkfsでつくったファイルシステムそのものは大きくならず、後ろにゴミがついていくだけ。)