2007-07-21
今天把vivi編譯了一下,順便解決了幾個問題。算是初步工作吧,下一步打算讀vivi的源代碼,然後改造一下,最後爭取自己完成一個小的bootloader。
準備工作(這些都是基於EDUKIT-III教學平臺,雖然開發工具上有些不同,但是原理和流程上是相同的。相信理解了嵌入式系統開發流程之後,對這些就會有很清晰的認識):
1)下載Nand_Prog.ide.bin到nor flash。這步工作是爲燒寫nand flash做準備的。爲什麼不利用仿真器直接燒寫nand
flash呢?理解了JTAG的原理後,對這步工作不難理解。nand flash和nor flash是不同的,nand
flash的燒寫需要ECC算法等,比較複雜。現在的這個仿真器不支持,所以就不能利用JTAG來直接燒寫了。當然,如果在仿真器支持軟件中加入對nand
flash燒寫的支持,這步工作就省去了。就我所知,國內foxICE已經可以支持直接燒寫nand flash了。
2)開發環境
還是windowsXP+VMware+redhat
9。原來學習at91rm9200的時候,開發環境都已經搭建好了,開發工具也比較齊全。
3)目標
移植好的vivi能支持從nand
flash啓動,測試內置的命令正常,利用開發板原來的內核映象和文件系統能夠跑起來。vivi畢竟是一個比較小巧的bootloader,功能有限,使用上可能有不方便的地方,所以,可以考慮在此基礎上,讀源代碼,然後增加tftp下載功能。
開始工作
1)下載vivi
我使用EDUKIT-III光盤中提供的vivi-20060929.tar.gz。解壓不必細說,下面就開始修改。下面的修改方案是基於網上帖子,因爲還沒有仔細分析源代碼,所以有些地方還不能理解清晰,這裏的移植是爲了獲得直觀的印象,如果要想得到技術水平的提升,那還是得深入分析vivi源代碼,看看這一切究竟是如何完成的。
2)修改Makefile
因爲國內大部分S3C2410的設計都是抄襲smdk2410,所以vivi的移植相對來說,工作量很小,只需要更改開發工具的幾個宏就可以了。當然,如果想要增加功能,則改動可能會大一點。
只要更改如下:
LINUX_INCLUDE_DIR -- 更改爲交叉編譯器的include文件夾
CROSS_COMPILE -- 交叉編譯器的可執行文件的路徑
ARM_GCC_LIBS -- 交叉編譯器的lib庫文件的路徑
################## Modified Start #################################### # Data :
2007-07-21 #
Modified by Liu Qingmin <piaoxiangxinling@163.com>
# # change
this to point to the Linux include directory #
#
orginal setup #LINUX_INCLUDE_DIR = /opt/host/armv4l/include/
# my
setup LINUX_INCLUDE_DIR = /usr/local/arm/2.95.3/include
################# Modified End ######################################
|
################## Modified Start #################################### # Data :
2007-07-21 #
Modified by Liu Qingmin <piaoxiangxinling@163.com>
#
orginal setup #CROSS_COMPILE = /opt/host/armv4l/bin/armv4l-redhat-linux- #CROSS_COMPILE = /opt/host/armv4l/bin/armv4l-unknown-linux-
# my
setup CROSS_COMPILE = /usr/local/arm/2.95.3/bin/arm-linux-
################# Modified End ######################################
|
################## Modified Start #################################### # Data :
2007-07-21 #
Modified by Liu Qingmin <piaoxiangxinling@163.com>
# #
Location of the gcc arm libs. #
#
orginal setup #ARM_GCC_LIBS = /opt/host/armv4l/lib/gcc-lib/armv4l-unknown-linux/2.95.2 #ARM_GCC_LIBS = /opt/host/armv4l/lib/gcc-lib/armv4l-redhat-linux/2.95.3
# my
setup ARM_GCC_LIBS = /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3
################# Modified End ######################################
|
這些都比較簡單。
3)修改arch/s3c2410/smdk.c
主要是修改nand flash分區信息。
#ifdef
CONFIG_S3C2410_NAND_BOOT mtd_partition_t default_mtd_partitions[] =
{ { name: "vivi", /* 128K, 1-8
sector */ offset: 0,
size: 0x00020000, flag: 0 },
{ name: "param", /* 64K, 9-12
sector */ offset:
0x00020000, size: 0x00010000,
flag: 0 }, { name:
"kernel", /* 2M+832K, 12-192 setctor */
offset: 0x00030000, size:
0x002d0000, flag: 0 },
{ name: "root", /* 29M, 193-2048
sector */ offset:
0x00300000, size: 0x01d00000,
flag: MF_BONFS
} };
|
這裏遇到了bon分區與mtd分區的疑惑,在分析vivi源代碼時在深入分析。上面文件配置的只是mtd分區,這個可以用part show來查看。
4)編譯燒寫
寫個簡單的批處理腳本procedure。以便後續工作的方便。【後來發現,vivi本身就提供了這樣的操作,所以這個小的腳本是沒有必要編寫的。這一點會在Makefile分析時給出】
[root@lqm vivi]# cat
procedure #!/bin/sh
make myboard_config &&
make oldconfig && make vivi && cp
-f vivi /mnt/hgfs/common/
|
燒寫vivi,正常。但是蜂鳴器一直在響。於是想在vivi中添加代碼,關掉蜂鳴器,同時利用開發板上的四個指示燈做一個跑馬燈的小程序。於是修改arch/s3c2410/head.S:
@@@@@@@@@@@@@@@@@@ Modified Start
@@@@@@@@@@@@@@@@@@@@@ mov r0, #10 @ rotate 10 times loop: mov r2,
#0xdf @ D1205 led on str r2, [r1,
#oGPIO_DAT] bl delay
mov r2,
#0x7f @ D1207 led on str r2, [r1,
#oGPIO_DAT] bl delay
mov r2,
#0xef @ D1204 led on str r2, [r1,
#oGPIO_DAT] bl delay
mov r2,
#0xbf @ D1206 led on str r2, [r1,
#oGPIO_DAT] bl delay
subs r0, r0,
#1 bne loop
mov r2,
#0x0f @ all leds on str r2, [r1,
#oGPIO_DAT]
@ buzzer
off ldr r1, =0x56000010 @ GPBCON ldr r2, =0x155559 str r2, [r1] ldr r2, =0x7ff str r2, [r1, #8] orr r2, r2,
#0x01 @ buzzer off when high
voltage(PWM1) str r2, [r1, #4] @@@@@@@@@@@@@@@@@@ Modified End
@@@@@@@@@@@@@@@@@@@@@@@@@
|
/* *
subroutines */
@@@@@@@@@@@@@@@@@@ Modified Start
@@@@@@@@@@@@@@@@@@@@@ @ @ led delay @ delay: ldr r3, =0x00080000 wait: subs r3, r3,
#1 bne wait
mov pc,
lr
@@@@@@@@@@@@@@@@@@ Modified End
@@@@@@@@@@@@@@@@@@@@@
|
通過source insight查看代碼,可以分析出第一條打印信息的來源init/version.c。這樣,just for
fun,可以添加自己的啓動信息。主要的參數都是有Makefile來完成的,讀一下Makefile的代碼,不難發現。
[root@lqm init]# cat
version.c /* * vivi/lib/version.c */
#include "version.h" #include "compile.h"
const char
*vivi_banner = "/n/r/t/t^_^ Well done, boy! Go on -->
/n/r/n/r" "VIVI
version " VIVI_RELEASE " ("
VIVI_COMPILE_BY "@" VIVI_COMPILE_HOST
") (" VIVI_COMPILER ") " UTS_VERSION "/n/r";
|
【注:這裏還有個小問題。就是在這裏添加的時候,/n/r要合起來用,不能只用/n。原因如下:
計算機還沒有出現之前,有一種叫做電傳打字機(Teletype Model
33)的玩意,每秒鐘可以打10個字符。但是它有一個問題,就是打完一行換行的時候,要用去0.2秒,正好可以打兩個字符。要是在這0.2秒裏面,又有新的字符傳過來,那麼這個字符將丟失。
於是,研製人員想了個辦法解決這個問題,就是在每行後面加兩個表示結束的字符。一個叫做“回車”,告訴打字機把打印頭定位在左邊界;另一個叫做“換行”,告訴打字機把紙向下移一行。
這就是“換行”和“回車”的來歷,從它們的英語名字上也可以看出一二。
後來,計算機發明瞭,這兩個概念也就被般到了計算機上。那時,存儲器很貴,一些科學家認爲在每行結尾加兩個字符太浪費了,加一個就可以。於是,就出現了分歧。Unix
系統裏,每行結尾只有“<換行>”,即“/n”;Windows系統裏面,每行結尾是“<換行><回車>”,即“/
n/r”;Mac系統裏,每行結尾是“<回車>”。一個直接後果是,Unix/Mac系統下的文件在Windows裏打開的話,所有文字會變成一行;而Windows裏的文件在Unix/Mac下打開的話,在每行的結尾可能會多出一個^M符號。
這幾個地方我都遇到過,不過一直沒有搞清楚。現在纔算是找到根源了。】
添加完成,重新執行procedure。完成燒寫,測試如下:
^_^ Well done, Go on -->
VIVI version 0.1.4 (root@lqm)
(gcc version 2.95.3 20010315
(release)) #0.1.4 日 7月 22 10:15:15 CST
2007 MMU table base address =
0x33DFC000 Succeed memory mapping. NAND device: Manufacture ID: 0xec, Chip
ID: 0x75 (Samsung KM29U256T) Could not
found stored vivi parameters. Use default vivi parameters. Press Return to start the LINUX now, any other
key for vivi type "help" for
help. vivi> part show mtdpart info. (4
partitions) name offset size
flag ------------------------------------------------ vivi :
0x00000000 0x00020000 0 128k param :
0x00020000 0x00010000 0 64k kernel :
0x00030000 0x002d0000 0 2M+832k root
: 0x00300000 0x01d00000 4 29M vivi>
|
然後執行bon分區:
vivi> bon part 0 192K 3M doing partition offset = 0 flag =
0 offset = 196608 flag = 0 offset = 3145728 flag = 0 check bad block part = 0 end =
196608 part = 1 end = 3145728 part = 2 end =
33554432 part0: offset = 0 size = 196608 bad_block = 0 part1: offset = 196608 size = 2949120 bad_block = 0 part2: offset = 3145728 size = 30392320 bad_block = 0 vivi>
|
重新燒寫vivi,注意這個時候不要斷電。
vivi> load flash vivi x Ready for downloading using xmodem... Waiting...
正在開始 xmodem 傳輸。 按 Ctrl+C 取消。 正在傳輸 vivi... 100% 67
KB 6 KB/s 00:00:10 0
錯誤
Downloaded file at 0x30000000, size = 69376
bytes Found block size =
0x00014000 Erasing... ... done Writing... ...
done Written 69376 bytes vivi>
|
檢查分區情況:
vivi> part show mtdpart info. (4
partitions) name offset size
flag ------------------------------------------------ vivi :
0x00000000 0x00020000 0 128k param :
0x00020000 0x00010000 0 64k kernel :
0x00030000 0x002d0000 0 2M+832k root
: 0x00300000 0x01d00000 4 29M vivi> bon part show BON info. (3
partitions) No: offset size flags bad --------------------------------------------- 0:
0x00000000 0x00030000 00000000 0 192k 1:
0x00030000 0x002d0000 00000000 0 2M+832k 2:
0x00300000 0x01cfc000 00000000 0 28M+1008k vivi>
|
其中,part show顯示的是mtd分區信息,跟smdk.c文件的配置相同。bon part
show顯示的bon分區信息,注意到最後一個分區少了一個扇區16K,因爲bon命令把bon分區信息表存儲在最後一個扇區了。
燒寫內核映象和文件系統:
vivi> load flash kernel x Ready for downloading using xmodem... Waiting...
正在開始 xmodem 傳輸。 按 Ctrl+C 取消。 正在傳輸 zImage... 100%
646 KB 7 KB/s 00:01:25 0
錯誤
Downloaded file at 0x30000000, size =
661760 bytes Found block size =
0x000a4000 Erasing... ... done Writing... ...
done Written 661760 bytes vivi>
?
^_^ Well
done, Go on -->
VIVI version 0.1.4 (root@lqm)
(gcc version 2.95.3 20010315
(release)) #0.1.4 日 7月 22 10:15:15 CST
2007 MMU table base address =
0x33DFC000 Succeed memory mapping. NAND device: Manufacture ID: 0xec, Chip
ID: 0x75 (Samsung KM29U256T) Found saved vivi parameters. Press Return to start the LINUX now, any other
key for vivi Copy linux kernel from 0x00030000 to
0x30008000, size = 0x002d0000 ... done zImage magic = 0x016f2818 Setup linux parameters at
0x30000100 linux command line is: "noinitrd
root=/dev/bon/2 init=/linuxrc console=ttyS0" MACH_TYPE = 193 NOW,
Booting Linux...... Uncompressing Linux............................................... done,
booting the kernel. Linux version 2.4.18-rmk7-pxa1
(root@lqm) (gcc version
2.95.3
20010315 (release)) #1 Fri Jul 20 15:12:44 CST
2007 CPU: ARM/CIRRUS Arm920Tsid(wb) revision
0 Machine: Embest EduKit II (S3C2410x) On node 0 totalpages: 16384 zone(0): 16384 pages. zone(1): 0 pages. zone(2): 0 pages. Kernel command line: noinitrd
root=/dev/bon/2 init=/linuxrc console=ttyS0 DEBUG: timer count
15626 Console: colour dummy device
80x30 Calibrating delay loop... 99.94 BogoMIPS Memory: 64MB = 64MB
total Memory: 62880KB available (1229K code,
296K data, 60K init) Dentry-cache hash table entries: 8192 (order: 4, 65536 bytes) Inode-cache hash table entries: 4096 (order: 3, 32768 bytes) Mount-cache hash table entries: 1024 (order: 1, 8192 bytes) Buffer-cache hash table entries: 4096 (order: 2, 16384 bytes) Page-cache hash table entries: 16384 (order: 4, 65536 bytes) POSIX conformance testing by UNIFIX Linux
NET4.0 for Linux 2.4 Based upon Swansea University Computer
Society NET3.039 Initializing RT netlink
socket CPU clock =
200.000 Mhz, HCLK =
100.000 Mhz, PCLK =
50.000 Mhz Starting kswapd devfs: v1.10 (20020120)
Richard Gooch (rgooch@atnf.csiro.au) devfs:
boot_options: 0x1 ttyS%d0 at I/O
0x50000000 (irq = 52) is a
S3C2410 ttyS%d1 at I/O 0x50004000 (irq = 55) is a S3C2410 ttyS%d2 at I/O
0x50008000 (irq = 58) is a
S3C2410 Console: switching to colour
frame buffer device 30x40 Installed S3C2410 frame buffer pty: 256 Unix98 ptys configured s3c2410-ts initialized S3C2410 Real Time
Clock Driver v0.1 block:
128 slots per queue, batch=32 eth0:
cs8900 rev K(3.3 Volts)
found at 0xd0000300 cs89x0 media RJ-45, IRQ
37 NAND device: Manufacture ID: 0xec, Chip
ID: 0x75 (Samsung KM29U256T) bon0:
00000000-00030000 (00030000)
00000000 bon1: 00030000-00300000 (002d0000)
00000000 bon2: 00300000-01ffc000 (01cfc000)
00000000 NET4: Linux TCP/IP 1.0 for NET4.0 IP Protocols: ICMP,
UDP, TCP, IGMP IP:
routing cache hash table of 512 buckets,
4Kbytes TCP: Hash tables configured (established 4096 bind 4096) NET4:
Unix domain sockets 1.0/SMP for Linux
NET4.0. NetWinder Floating Point Emulator V0.95 (c) 1998-1999
Rebel.com cramfs: wrong magic FAT: bogus logical sector size 65535 Kernel
panic: VFS: Unable to mount root fs on 61:02
vivi> load flash root x Ready for downloading using xmodem... Waiting...
正在開始 xmodem 傳輸。 按 Ctrl+C 取消。 正在傳輸 root.cramfs... 100%
1104 KB 7 KB/s 00:02:22 0
錯誤
Downloaded file at 0x30000000, size =
1130496 bytes Found block size =
0x00114000 Writing... size = 1130496 bad_block = 0 ...
done Written 1130496 bytes vivi>
vivi>
^_^ Well done, Go
on -->
VIVI version 0.1.4 (root@lqm)
(gcc version 2.95.3 20010315
(release)) #0.1.4 日 7月 22 10:15:15 CST
2007 MMU table base address =
0x33DFC000 Succeed memory mapping. NAND device: Manufacture ID: 0xec, Chip
ID: 0x75 (Samsung KM29U256T) Found saved vivi parameters. Press Return to start the LINUX now, any other
key for vivi Copy linux kernel from 0x00030000 to
0x30008000, size = 0x002d0000 ... done zImage magic = 0x016f2818 Setup linux parameters at
0x30000100 linux command line is: "noinitrd
root=/dev/bon/2 init=/linuxrc console=ttyS0" MACH_TYPE = 193 NOW,
Booting Linux...... Uncompressing Linux............................................... done,
booting the kernel. Linux version 2.4.18-rmk7-pxa1
(root@lqm) (gcc version
2.95.3
20010315 (release)) #1 Fri Jul 20 15:12:44 CST
2007 CPU: ARM/CIRRUS Arm920Tsid(wb) revision
0 Machine: Embest EduKit II (S3C2410x) On node 0 totalpages: 16384 zone(0): 16384 pages. zone(1): 0 pages. zone(2): 0 pages. Kernel command line: noinitrd
root=/dev/bon/2 init=/linuxrc console=ttyS0 DEBUG: timer count
15626 Console: colour dummy device
80x30 Calibrating delay loop... 99.94 BogoMIPS Memory: 64MB = 64MB
total Memory: 62880KB available (1229K code,
296K data, 60K init) Dentry-cache hash table entries: 8192 (order: 4, 65536 bytes) Inode-cache hash table entries: 4096 (order: 3, 32768 bytes) Mount-cache hash table entries: 1024 (order: 1, 8192 bytes) Buffer-cache hash table entries: 4096 (order: 2, 16384 bytes) Page-cache hash table entries: 16384 (order: 4, 65536 bytes) POSIX conformance testing by UNIFIX Linux
NET4.0 for Linux 2.4 Based upon Swansea University Computer
Society NET3.039 Initializing RT netlink
socket CPU clock =
200.000 Mhz, HCLK =
100.000 Mhz, PCLK =
50.000 Mhz Starting kswapd devfs: v1.10 (20020120)
Richard Gooch (rgooch@atnf.csiro.au) devfs:
boot_options: 0x1 ttyS%d0 at I/O
0x50000000 (irq = 52) is a
S3C2410 ttyS%d1 at I/O 0x50004000 (irq = 55) is a S3C2410 ttyS%d2 at I/O
0x50008000 (irq = 58) is a
S3C2410 Console: switching to colour
frame buffer device 30x40 Installed S3C2410 frame buffer pty: 256 Unix98 ptys configured s3c2410-ts initialized S3C2410 Real Time
Clock Driver v0.1 block:
128 slots per queue, batch=32 eth0:
cs8900 rev K(3.3 Volts)
found at 0xd0000300 cs89x0 media RJ-45, IRQ
37 NAND device: Manufacture ID: 0xec, Chip
ID: 0x75 (Samsung KM29U256T) bon0:
00000000-00030000 (00030000)
00000000 bon1: 00030000-00300000 (002d0000)
00000000 bon2: 00300000-01ffc000 (01cfc000)
00000000 NET4: Linux TCP/IP 1.0 for NET4.0 IP Protocols: ICMP,
UDP, TCP, IGMP IP:
routing cache hash table of 512 buckets,
4Kbytes TCP: Hash tables configured (established 4096 bind 4096) NET4:
Unix domain sockets 1.0/SMP for Linux
NET4.0. NetWinder Floating Point Emulator V0.95 (c) 1998-1999
Rebel.com VFS: Mounted root (cramfs filesystem). Mounted
devfs on /dev Freeing init memory: 60K mount /etc as ramfs re-create the /etc/mtab
entries init started: BusyBox v1.00 (2005.06.09-02:02+0000)
multi-call binary Starting pid 17, console /dev/console:
'/etc/init.d/rcS' Embest Embedded
Linux Development Paltform. Default board ip: 192.192.192.190 To
change the ip addr: ifconfig eth0
new_board_ip Start the web server:
http://(board_ip)/index.htm
To connect the NFS server, please type like: mkdir /etc/var/nfs mount -t nfs nfs_server_ip:/home/app /etc/var/nfs -o nolock To use the USB disc(insert first), please type
like: mount /dev/sda /mnt/udisk
_OR_ mount /dev/sda1 /mnt/udisk
Please press Enter to activate this
console. Starting pid 42, console /dev/console:
'/bin/sh' ~ # ls bin
etc linuxrc proc tmp var dev lib mnt sbin usr ~ #
|
一切正常。
|