移植u-boot-2010.03 --- 内核烧写到NandFlash

在成功编译u-boot后,可以把uboot烧写到NandFlash中,这样在每次开机后u-boot会自动运行,接下来就是要完成它的主要使命了---启动linux内核。可以使用tftp服务下载内核,并直接在内存中运行,但最重要的流程还是要烧写到NandFlash中,以免掉电后丢失。

这里我移植的u-boot还有个bug,就是nand erase 100000 500000 命令总是提示完成90%,导致我写入内核时,无法从NandFlash启动内核。这里做一个标记,日后发现解决方法后补充。先用ok6410自带的sd卡uboot烧写我编译的uboot和uImage实现。

1,通过SD卡启动方式,启动u-boot(飞凌公司提供的mmc)

2,通过dnw下载我们自己的u-boot.bin(飞凌提供的uboot网卡驱动不对,不能使用tftp)

板子操作:SMDK6410 # dnw 50008000 
主机操作:sudo dnw u-boot.bin

3,烧写u-boot.bin到NandFlash中

SMDK6410 # nand erase 0 100000
SMDK6410 # nand write.uboot 50008000 0 100000

4,通过dnw下载我们自己的u-boot.bin

板子操作:SMDK6410 # dnw 50008000 
主机操作:sudo dnw uImage

5,烧写kernel到NandFlash中

SMDK6410 # nand erase 100000 500000
SMDK6410 # nand write.e 50008000 100000 500000

6,将板子改为从NandFlash启动后,发现问题如下

U-Boot 2010.03 ( 1��月 22 2014 - 15:18:07) for SMDK6410


CPU:     S3C6410@533MHz
         Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode) 
Board:   SMDK6410
DRAM:  256 MB
Flash:  0 kB
NAND:  2048 MiB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0 

NAND read: device 0 offset 0x100000, size 0x500000
 5242880 bytes read: OK
## Booting kernel from Legacy Image at 50008000 ...
   Image Name:   Linux-3.12.7
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1575408 Bytes =  1.5 MB
   Load Address: 50008000
   Entry Point:  50008000
   Verifying Checksum ... OK
   XIP Kernel Image ... OK
OK

Starting kernel ...

undefined instruction
pc : [<5000800c>]          lr : [<57e249a0>]
sp : 57cffdf4  ip : 00000002     fp : 50000100
r10: 0000065a  r9 : 57d04a24     r8 : 57cfffe0
r7 : 50008000  r6 : 57e37c3c     r5 : 00000000  r4 : 57cfffc4
r3 : 00000000  r2 : 50000100     r1 : 0000065a  r0 : 50000144
Flags: nzCv  IRQs off  FIQs off  Mode SVC_32
Resetting CPU ...

resetting ...

问题是发生了未定义的异常,undefined instruction,导致无限重启。

于是开始拍错,因为内核在前篇文章中可以通过tftp下载并运行,所以内核应该没问题,后来发现我这里少了一部,由于uboot只支持uImage,起初我是在linux下直接make uImage生成的内核镜像,其实并不能让uboot识别。这里需要使用uboot/tools下的mkimage来制作uImage。

 wu@wu-VirtualBox:/opt/u-boot-2010.03-3/tools$ mkimage -A arm -O linux -T kernel -C none -a 50008000 -e 50008040 -n "linux-3.12.7" -d /opt/linux-3.12.7-2/arch/arm/boot/zImage uImage

生成的uImage在/opt/u-boot-2010.03-3/tools下。

 

查找了多方资料后发现问题出现在uboot和kernel的对接处:

仔细看上面打印的信息 Load Address: 50008000 Entry Point: 50008000,而我们刚才的命令是-a 50008000 -e 50008040,Load Address是内核的载入地址,Entry Point是内核的入口地址,50008040要加上x40(换算过来是64byte)是因为:uImage是uboot专用的映像文件,它是在zImage之前加上一个长度为64字节的“头”,说明这个内核的版本、加载位置、生成时间、大小等信息;

具体可以看下这篇文章:http://kmoving.blog.163.com/blog/static/20504919720123151533819/

重复步骤:1-5后成功启动

U-Boot 2010.03 ( 1��月 22 2014 - 15:18:07) for SMDK6410


CPU:     S3C6410@533MHz
         Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode) 
Board:   SMDK6410
DRAM:  256 MB
Flash:  0 kB
NAND:  2048 MiB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0 

NAND read: device 0 offset 0x100000, size 0x500000
 5242880 bytes read: OK
## Booting kernel from Legacy Image at 50008000 ...
   Image Name:   linux-3.12.7
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1575408 Bytes =  1.5 MB
   Load Address: 50008000
   Entry Point:  50008040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Booting Linux on physical CPU 0x0
Linux version 3.12.7 (wu@wu-VirtualBox) (gcc version 4.4.3 (ctng-1.6.1) ) #1 Tue Jan 21 17:10:55 CST 2014
CPU: ARMv6-compatible processor [410fb766] revision 6 (ARMv7), cr=00c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
Machine: OK6410
Memory policy: ECC disabled, Data cache writeback
CPU S3C6410 (id 0x36410101)
........省略.......

 

 

 

 

posted on 2014-01-23 17:23  lucky_tom  阅读(1333)  评论(0编辑  收藏  举报