*************************************************
arch/arm/Makefile
//内核运行虚拟地址TEXTADDR = 0xC0008000
*************************************************
arch/arm/boot/Makefile
//内核加载地址ZRELADDR = 0x20008000
*************************************************
arch/arm/boot/compressed/Makefile
//自解压程序地址ZTEXTADDR =
0x00000000
(linux-2.4.19-rmk7内核的自解压函数gunzip位于
/lib/inflate.c中,为gzip-1.0.3版本,现在在PC上使用gzip
函数压缩出来的文件不能被gzip-1.0.3版本的gunzip识别,所以linux-2.4.19-rmk7
内核自解压的功能等于不能使用,默认值ZTEXTADDR= 0x00000000
表示不使用。(只能通过uBoot的gunzip解压加载)
)
***********************************************
//uImage存放地址 = 0x21000000
***********************************************
mkimage -A arm -O linux -C gzip -a 0x20008000 -e 0x20008000 -d
linux.bin.gz uImage
这里解释一下参数的意义:
-A ==> set architecture to
'arch'
-O ==> set
operating system to 'os'
-T ==> set
image type to 'type'
-C ==> set
compression type 'comp'
-a ==> set
load address to 'addr' (hex)
-e ==> set
entry point to 'ep' (hex)
-n ==> set
image name to 'name'
-d ==> use
image data from 'datafile'
-x ==> set
XIP (execute in place)
-A:CPU类型
-O:操作系统
-C:采用的压缩方式
-a:内核加载地址
-e:内核入口地址
***********************************************
uBoot的do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char
*argv[]);
函数将检验存放到0x21000000地址处的经过mkimage格式化的uImage数据的头部
typedef struct image_header {
uint32_t ih_magic;
uint32_t ih_hcrc;
uint32_t ih_time;
uint32_t ih_size;
uint32_t ih_load;
uint32_t ih_ep;
uint32_t ih_dcrc;
uint8_t ih_os;
uint8_t ih_arch;
uint8_t ih_type;
uint8_t ih_comp;
uint8_t ih_name[IH_NMLEN];
}image_header_t;
(ih_ep值为0x20008000,ih_load值为0x20008000)
如果头部各个域值和crc合法,那么do_bootm将调用如下gunzip解压函数对
0x21000000 +sizeof(image_header_t)地址处的压缩内核进行解压:
gunzip((void*)ntohl(hdr->ih_load),0x400000,data,(int*)&len);
1.hdr->ih_load 为输出数据地址0x20008000
2.0x400000 为gunzip解压输出数据上限值-4M
3.data 为输入数据地址data=0x21000000 +sizeof(image_header_t);
4.Len 为输入数据长度len = ntohl(hdr->ih_size );
解压完成后将会存储解压后数据的实际大小
压缩的Linux内核文件uImage,经由gunzip解压函数后,通过
do_bootm_linux (cmdtp, flag, argc, argv,addr, len_ptr, verify);
函数向Linux内核传递内核运行所需的5个参数
kernel = (void (*)(bd_t *, ulong, ulong, ulong,
ulong))hdr->ih_ep ;
1.hdr->ih_ep 为0x20008000
(*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
这样完成了Linux系统启动所需要5个参数的传递,至此uBoot的工作已经结束,Linux将在0x20008000地址处正式运行。
编译完内核之后,会产生zImage,而把它直接导入0x30008000,会出现Bad Magic Number.
查明是需要将内核加一个0x40大小的头,由mkimage工具来添加.mkimage在编译u-boot时在u-boot-1.1.6/tools下生成,可以为编译的内核添加头信息的.在bootm命令中会解析这个头,获得参数.zImage在编译内核时,在arch/arm/boot目录下生成。我们需要把zImage用mkimage工具处理一下。
mkimage参数的意义如下:
-A
== set architecture to 'arch'
-O
== set operating system to 'os'
-T
== set image type to 'type'
-C
== set compression type 'comp'
-a
== set load address to 'addr' (hex)
-e
== set entry point to 'ep' (hex)
-n
== set image name to 'name'
-d
== use image data from 'datafile'
-x
== set XIP (execute in place)
首先可以把zImage拷贝到u-boot-1.1.6/tools目录下,在此目录下,执行如下命令:
./mkimage
-n 'linux-2.6.26' -A arm -O linux -T kernel -C none -a 0x30007fc0
-e 0x30008000 -d zImage uImage
输出信息如下:
Image Name:linux-2.6.26
Created:Tue
Jul 28 18:50:26 2009
Image Type:ARM
Linux Kernel Image (uncompressed)
Data Size:1655648
Bytes = 1616.84 kB = 1.58 MB
Load Address:
0x30007FC0
Entry
Point:0x30008000
可以看出加载地址是0x30007fc0,而入口地址是0x30008000.
GEC2410 #tftp
30008000 uImage
TFTP from server 192.168.0.50; our IP
address is 192.168.0.100
Filename
'uImage'.
Load address:
0x30008000
Loading:
#################################################################
#################################################################
#################################################################
#################################################################
################################################################
done
Bytes transferred = 1655712 (1943a0
hex)
GEC2410 #bootm
30008000
## Booting image at 30008000
...
Image
Name:linux-2.6.26
Created:2009-07-2810:50:26
UTC
Image
Type:ARM
Linux Kernel Image (uncompressed)
Data
Size:1655648
Bytes =1.6
MB
Load
Address: 30007fc0
Entry
Point:30008000
Verifying
Checksum ... OK
OK
Starting kernel
...(卡死在这儿了)
GEC2410 #tftp
30008000 uImage
TFTP from server 192.168.0.50; our IP
address is 192.168.0.100
Filename
'uImage'.
Load address:
0x30008000
Loading:
#################################################################
#################################################################
#################################################################
#################################################################
################################################################
done
Bytes transferred = 1655712 (1943a0
hex)
GEC2410 #bootm
30007fc0
## Booting image at 30007fc0
...
Bad Magic Number
GEC2410 #tftp
30007fc0 uImage
TFTP from server 192.168.0.50; our IP
address is 192.168.0.100
Filename
'uImage'.
Load address:
0x30007fc0
Loading:
#################################################################
#################################################################
#################################################################
#################################################################
################################################################
done
Bytes transferred = 1655712 (1943a0
hex)
GEC2410 #bootm
30008000
## Booting image at 30008000
...
Bad Magic Number
GEC2410
#
GEC2410 # tftp 0x30007fc0
uImage
TFTP from server 192.168.0.50; our IP
address is 192.168.0.100
Filename
'uImage'.
Load address:
0x30007fc0
Loading:
#################################################################
#################################################################
#################################################################
#################################################################
################################################################
done
Bytes transferred = 1655712 (1943a0
hex)
GEC2410 #bootm
30007fc0
## Booting image at 30007fc0
...
Image
Name:linux-2.6.26
Created:2009-07-2810:50:26
UTC
Image
Type:ARM
Linux Kernel Image (uncompressed)
Data
Size:1655648
Bytes =1.6
MB
Load
Address: 30007fc0
Entry
Point:30008000
Verifying
Checksum ... OK
XIP
Kernel Image ... OK
Starting kernel
...
Uncompressing
Linux............................................................................................................
done, booting the kernel.
………………….
(一大堆信息)
从上面可以看出,tftp下载的地址和bootm引导的地址是同一个地址,且是mkimage的参数
-a 的地址,即加载地址,而不是入口地址。
./mkimage
-n 'linux-2.6.26' -A arm -O linux -T kernel -C none -a 0x30008000
-e 0x30008000 -d zImage uImage
Created:Tue
Jul 28 19:21:15 2009
Image Type:ARM
Linux Kernel Image (uncompressed)
Data Size:1655648
Bytes = 1616.84 kB = 1.58 MB
Load Address:
0x30008000
Entry
Point:0x30008000
入口地址和加载地址一样的时候,
我在做这个尝试的时候,导致开发板重启……。
现在能正确引导内核啦,但是GEC2410的网卡芯片是CS8900A的芯片,要能正确的启动Linux系统,还必须添加CS8900A的驱动……