EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
在ARM-Linux使用JPT-7模块来跑GPS应用.Nand Flash 空间太小,而且所用的板经
. W! a0 Q) D T( b常烧不了根文件系统.所以决定用SD卡来跑根文件系统。
7 W! A5 r0 _ I. \" Z7 ~2 A1.PC机上格式化SD卡 % T; L/ C7 o0 ~8 e
在桌面的PC机上用SD读卡器操作SD卡:
" S9 j* ~+ s; h& X. b 一般情况下PC机上第一个U盘整体设备结点是/dev/sda,第二个是 /dev/sdb,在RHEL5下它会被
2 Y# }/ `6 K4 y9 P" Z! T4 K+ m) v" H. L自动mount到/media/disk和 /media/disk_1 目录。! V) z0 ]) z- e: W/ x
U盘/dev/sdb上第一个分区是 /dev/sdb1,第二是/dev/sdb2 依此类推。 根文件系统采用符号链接等特性,用FAT32是不行的,这里直接采用标准的ext3的文件系统.在实测& _/ @8 r/ u1 J- q
时,把U盘整个做一个分区做ext3根文件系统.总 是出不少问题(可能步骤也不对),因此按网上推荐的,$ v# p6 f0 n1 s: z% F
做二个分区,第一个分区采用vfat格式,第二个分区才采用ext3的格式。 ; E$ q3 I3 H6 j) Z' y" @
1.1 用fdisk分区
: _( t9 d2 M: k2 V+ a 执行fdisk /dev/sdb
' a5 F! F6 a6 J h [9 J2 K fdisk有如下常用选项
! V, x: \* W4 q! z" ^% y1. 输入 m 显示所有命令列示。 6 D: m& x+ J* n4 p
2. 输入 p 显示硬盘分割情形。
3 {8 t+ s7 P1 A" j5 G. V/ t( a3. 输入 a 设定硬盘启动区。 , n+ T% t$ N/ h) N$ X
4. 输入 n 设定新的硬盘分割区。 3 |" Y7 C8 Y) T& A7 d
4.1. 输入 e 硬盘为[扩展]分割区(extend)。 9 K3 F; `, f0 @% y2 b+ P) C& \- H u
4.2. 输入 p 硬盘为[首要]分割区(primary)。
, Q. t) d3 f n6 t( O! G5. 输入 t 改变硬盘分割区属性。
. ]# `% \ G# P" B6. 输入 d 删除硬盘分割区属性。 : y0 o. `9 ?, L2 U/ \9 p
7. 输入 q 结束不存入硬盘分割区属性。
' B2 ^- B) b; u/ j, b8. 输入 w 结束并写入硬盘分割区属性$ S D; v4 Y+ {/ P
如果以前U盘有分区,需要输入d命令来依次删除分区,以下执行两次n命令创建一个 400M的FAT分, e, s; H' |( }4 ?+ k( Q
区,以及把剩下的分区设为ext3,最后用w命令把结果保存下来。# i7 J. d& U) L! |0 n6 Y
Command (m for help): n( ^; t0 t5 |2 I: Y
Command action2 p$ v" I4 F" Z0 M8 b
e extended3 ` h7 M9 w/ l( I) P% v7 Q' K' E& I6 r
p primary partition (1-4)5 e. }1 ^9 L" u8 \6 m' ^
p7 k/ i: I" W x. \! P
Partition number (1-4): 13 Z: G' D' h; d! M
First cylinder (1-1020, default 1): 0 e7 E" ~9 m* G" P2 R
Using default value 1
) t, X8 q" u4 l/ q2 kLast cylinder or +size or +sizeM or +sizeK (1-1020, default 1020): +400M+ K; [6 Y1 @7 E0 _' q' i; K
Command (m for help): n
1 F0 I* g" N9 h% Y3 S4 u0 C; oCommand action! f* w* p) k$ e8 \7 v6 o' d
e extended
9 m* w% ~4 U/ x p primary partition (1-4)
( T- R. `1 {5 Y: P4 op6 o4 [6 z- u4 _* @6 j8 _
Partition number (1-4): 2' q3 v# k* ~, c B6 i% s$ E
First cylinder (202-1020, default 202): 0 T' a; j3 s* V8 a9 @0 i/ ~
Using default value 202
0 `- j$ ~/ x: ^1 C6 W9 e6 ]Last cylinder or +size or +sizeM or +sizeK (202-1020, default 1020): % c# q4 U* Y5 H) N9 t* }
Using default value 10200 }3 b' Q2 ~) c6 j4 O+ m* V% N8 E
Command (m for help): p" F M: x! ] k( Z
Disk /dev/sdb: 2041 MB, 2041577472 bytes + Z1 s \/ o/ ?; ?/ }& F( M
63 heads, 62 sectors/track, 1020 cylinders4 q* L! m. Z+ H: J
Units = cylinders of 3906 * 512 = 1999872 bytes) X. ~4 N" t- A" K) v
Device Boot Start End Blocks Id System7 v, O" \: n9 [8 x" q
/dev/sdb1 1 201 392522 b W95 FAT32) Z" W* S1 ?3 f, n, J
/dev/sdb2 202 1020 1599507 83 Linux* Q4 q6 ^" ~" ?/ y3 i2 l; ~, W
Command (m for help): w( L) u9 d" L* Y) S
The partition table has been altered!* R, h/ ]9 B. s# ~; | V9 K% ]) y
Calling ioctl() to re-read partition table.
" C6 U2 S# @' U7 X" `WARNING: Re-reading the partition table failed with error 16: 设备或资源9 R" U2 Q9 ^' h: B( W4 h8 T/ ?
忙." z) l$ o( W9 _
The kernel still uses the old table.6 |0 ~$ b# e5 _7 K7 y! e
The new table will be used at the next reboot.
: q. A E2 z+ @* z) L) A$ CWARNING: If you have created or modified any DOS 6.x2 h @5 t$ o& J$ H$ W. I! S9 K0 X7 J
partitions, please see the fdisk manual page for additional
7 z1 z( _/ [4 pinformation.: w* I, C# l3 L8 u6 ?' E7 y
Syncing disks. ( |$ d/ l: s1 r t- |) Y5 Q( @8 t
1.2 格式化分区
+ f5 P S' ]2 s0 N7 t7 H% W mkfs.vfat /dev/sda1 #第一个分区格式化成fat32
4 @4 {7 l) }; [4 g% L% K( h mkfs.ext3 /dev/sda2 #第二个分区格式化成fat32
7 M, I! {3 P, \! u2 y1 @ 可以用
. B" K5 ~! h' A" {( C5 l tune2fs -l /dev/sda2 来检验分区类型
* U5 N0 h ?8 h1.3 拷贝根文件系统* [) g' f+ z* [& y( u+ P
mount /dev/sda2 /mnt/sdcard #挂载SD卡
; ]$ {' J' f+ Z6 V cp -ra /home/hxy/rootfs/* /mnt/sdcard #把根文件系统拷到SD卡
% X' ^# F. D( {, q# t2. 编译 ARM Linux 内核
1 f/ g0 P# m& R3 T3 K 2.1 修改内核配置
5 \9 J% E5 k3 b4 c# S$ f& s 确保ext3的文件系统支持,和SD卡驱动都被静态编译到内核,我使用的是Linux 2.6.29.
4 G! I6 s5 s- H1 Q+ f 在内核源码目录执行 make menuconfig* Z3 S) e U; R- w- Y4 u" h* u- T
其中ext3在File system下.成功的配置如下。- F( K f( G- B J: |
<*> Ext3 journalling file system support ; E0 |1 n8 f" x0 i0 }4 N
Ext3 extended attributes ! l; S% R' [7 o
Ext3 POSIX Access Control Lists Ext3 Security Labels
' @9 p% K" C4 @: A: @SD卡驱动支持在Device Drivers ->MMC/SD/SDIO card support 下,成功的配置如下
4 \/ I+ z7 c1 A --- MMC/SD/SDIO card support ( g1 \8 d1 R1 k; \% f; C
MMC debugging
* a, q/ z5 g& h& w7 A8 X! @ [ ] Allow unsafe resume (DANGEROUS) + \) ~5 D6 d7 }9 D F4 X
*** MMC/SD/SDIO Card Drivers ***
2 N7 p9 ~" q1 u5 n! l& G) L <*> MMC block device driver ( s, |- Z! v5 x% Z6 \2 d
Use bounce buffer for simple hosts : g! W9 U: V; L1 L& R/ U6 ?, N
<*> SDIO UART/GPS class support
9 T- Q- w. f! b& m# W <*> MMC host test driver
* ?2 s4 a( t U. ~6 f3 x4 q *** MMC/SD/SDIO Host Controller Drivers *** ( s* m" e* _2 `7 R& t, P
<*> Secure Digital Host Controller InteRFace support ( R+ p+ T! S6 w' W
<*> Samsung S3C SD/MMC Card Interface 4 Y% ^) M7 e O& _9 _
support 6 F3 Q Q8 Z% k. H' N1 B6 k
编译内核 make zImage
! U# @* x+ g1 G; l6 D, T; p2.2 在ARM-linux下的测试./ j4 Y3 ^# g* Z0 ^. {3 _5 {
在一个已经正常启动的ARM-LINUX下,插入SD卡.出现如下提示,表示SD卡已经安装上
( e. @5 c+ R4 C( i" S; k7 Z[root: /]# s3c2440-sdi s3c2440-sdi: running at 0kHz (requested: 0kHz).
2 l( e& S# h7 E/ x# m, zs3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz). $ w1 f% p& W9 M$ h" h- Y
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz). . i' E# F, B& K: t3 T( p1 l
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
$ T! F! G- W0 d) f: ^/ J0 i6 ys3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz). ' R* G0 p2 |$ r& }3 c2 p* h/ J, X
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
# }" C8 m$ C, Ns3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz). ' k2 U) C) e3 D9 J; N8 A
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz). $ a2 o& U! g% A K2 y
s3c2440-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz). . ~+ H& a0 y; Z7 Y& U- N
s3c2440-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz). 6 c' v% ^( t8 b* I) T j
mmc0: new SD card at address 0002
7 F& Z$ O3 `2 G8 C* B5 ]7 Mmmcblk0: mmc0:0002 00000 1.90 GiB
4 y3 l! G# f3 N, E/ R. Y0 [ mmcblk0: p1 p2
( J6 W7 g; ?: a fFAT: utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case/ [. R- m5 L8 k0 M
sensitive! 6 R0 L7 ~. O+ n3 z+ A
但是最后一句在提示FAT有不识别的IO字符集,导致第一个VFAT分区没有自动创建设备结点.用如! i5 G, R# G! c1 ~" {2 D
下命令只看到mmcblk0p2的结点.(以下操作均是在开发板上进行)7 T' c& x8 F5 p' F& U8 ~% h
[root: /]# ls -l /dev/mmc* 0 K( [ E! |$ W% k- V
brw-rw---- 1 root root 179, 0 Sep 22 10:48 /dev/mmcblk0 3 Z4 `1 E; ~& H( z; ?
brw-rw---- 1 root root 179, 2 Sep 22 10:48 /dev/mmcblk0p2 % |5 H7 L: V. m5 A3 R
测试ext3分区9 C. e. C3 G9 I1 o' g
mount -t ext3 /dev/mmcblk0p2 /mnt
) u4 Q- |; L( G. Q7 o% ]在/mnt上可以读写文件.表示ext3分区正常.
# Q8 G: P. M$ ~/ b: w7 m手动建立第一个分区的结点./ X+ ?9 ]8 z, e. ?
mknod /dev/mmcblk0p1 b 179 1 " @+ z# {: c L: P/ [
测试vfat 分区1 j7 l' W/ t1 L" i' ]
mount -t vfat /dev/mmcblk0p1 /mnt
6 i/ O$ h6 g; z% l! ~在/mnt上可以读写文件.表示vfat分区正常.如果想自动创建个设备结点,可以修改/etc/fstat来使用; S6 R) l5 i g" K
这个分区
1 a8 `2 U8 K- \% H7 Y3. 使用 SD 卡分区作为根文件 / i7 V1 Q! C4 R
修改LINUX启动参数.我用的是u-boot .因此在u-boot shell用set bootargs命令来设置Linux启动# K; L( x, L, ^7 b. l
参数。* ~/ B) _% z5 N( q/ P
成功的启动参数是 noinitrd root=179:2 rw console=ttySAC0 # z$ w5 c/ V' ~ ^% g F: }
其中179和2是sd卡上ext3分区的主设备和从设备号。. c! P5 H. ^; t$ b- d4 @8 h
用set bootargs "noinitrd root=179:2 rw console=ttySAC0 "设置后.重启内核,即可用ext3分区作
3 K4 r4 N3 i; g" U为根文件系统。 ( f3 y s. R) u. |
PS:如果根文件系统不能正常加载,并且报错信息和下面类似:
& h* F5 a' N+ X.......
+ E4 p( {0 t: \3 W VFS: Cannot open root device "179:2" or unknown-block(179,2)
t. ^: I5 w/ u! b- jPlease append a correct "root=" boot option7 u9 I& Y# X0 I3 p- @, \7 V
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2)
0 k1 t. t* w F% d+ k( M |