mini2440移植uboot 2014.04(五)

时间:2023-03-09 09:08:45
mini2440移植uboot 2014.04(五)

代码上传到github上:https://github.com/qiaoyuguo/u-boot-2014.04-mini2440

前几篇博文: 《mini2440移植uboot 2014.04(一)

mini2440移植uboot 2014.04(二)

mini2440移植uboot 2014.04(三)

mini2440移植uboot 2014.04(四)

(九)修改nand flash代码错误(代码中一些错误修正):

用tftp将uboot加载到mini2440,然后nand erase擦除nand flash,然后再用nand write写入到nand flash后,重新加载uboot,结果又出现了下面的错误(前面已经出现过一次):

Flash: fwc addr  cmd f0 00f0 16bit x  bit
fwc addr 0000aaaa cmd aa 00aa 16bit x bit
fwc addr cmd 16bit x bit
fwc addr 0000aaaa cmd 16bit x bit
fwc addr cmd f0 00f0 16bit x bit
JEDEC PROBE: ID f0 ffff
fwc addr cmd ff 00ff 16bit x bit
fwc addr cmd 16bit x bit
fwc addr cmd ff 00ff 16bit x bit
JEDEC PROBE: ID ffff
*** failed ***
### ERROR ### Please RESET the board ###

如果将include/configs/mini2440.h中的#define DEBUG注释掉,显示信息如下:

U-Boot 2014.04-gb749c10-dirty (Jun   - ::)

CPUID:
FCLK: MHz
HCLK: 101.250 MHz
PCLK: 50.625 MHz
DRAM: MiB
WARNING: Caches not enabled
Flash: *** failed ***
### ERROR ### Please RESET the board ###

再次出现了无法检测nor flash的情况.

暂时先将官方uboot烧写到开发板(先擦除整个nand flash,然后烧写官方uboot)。

然后打开三个控制台,一个执行"sudo minicom",另一个执行"openocd -f interface/jlink.cfg -f board/mini2440.cfg",最后一个控制台执行下面内容:

telnet localhost 4444
reset
init_2440
nand probe 0
nand erase 0
nand write 0  /home/host/soft/mini2440/u-boot/u-boot.bin 0  
reset

在minicom所在控制台上可以正常显示和进入uboot。

执行nand write命令需要很长时间,下面是执行该命令的输出信息:

wrote file /home/host/soft/mini2440/u-boot/u-boot.bin to NAND flash  up to offset 0x00038800 in .817383s (0.320 Ki/s)

231KB的文件足足花了十多分钟,我差点以为telnet命令挂掉了。

修改下面代码(drivers/mtd/nand/s3c2410_nand.c):

#if defined(CONFIG_S3C2440)
if (ctrl & NAND_NCE)
- writel(readl(&nand->nfconf) & ~S3C2410_NFCONT_nFCE,
- &nand->nfconf);
+
+ &nand->nfcont);
else
- writel(readl(&nand->nfconf) | S3C2410_NFCONT_nFCE,
- &nand->nfconf);
+ writel(readl(&nand->nfcont) | S3C2410_NFCONT_nFCE,
+ &nand->nfcont);
}  #if defined(CONFIG_S3C2440)
-       writel(readl(&nand->nfconf) | S3C2410_NFCONT_INITECC, &nand->nfconf);
+       writel(readl(&nand->nfcont) | S3C2410_NFCONT_INITECC, &nand->nfcont);
 #endif

'-'号表示需要删除的代码行,'+'号表示需要添加的代码行。

修改代码后重新编译:

make CROSS_COMPILE=arm-linux-

执行下面命令加载uboot文件:

reset
init_2440
load_image /home/host/soft/mini2440/u-boot-2014.04/u-boot.bin 0x33e80000 bin
resume 0x33e80000

在minicom中得到下面输出信息后就重启系统了:

U-Boot 2014.04-gb749c10-dirty (Jun   - ::)

U-Boot code: 33E80000 -> 33EFA3D8  BSS: -> 33F48ED0
CPUID:
FCLK: MHz
HCLK: 101.250 MHz
PCLK: 50.625 MHz
monitor len: 000C8ED0
ramsize:
TLB table from 33ff0000 to 33ff4000
Top of RAM usable for U-Boot at: 33ff0000
Reserving 803k for U-Boot at: 33f27000
Reserving 4160k for malloc() at: 33b17000
Reserving Bytes for Board Info at: 33b16fe0
Reserving Bytes for Global Data at: 33b16f40
New Stack Pointer is: 33b16f30
RAM Configuration:
Bank #: MiB
addr=33f27000,_start=33e80000
relocation Offset is: 000a7000
WARNING: Caches not enabled
monitor flash len: 00084CF8
dram_bank_mmu_setup: bank:
Now running in RAM - U-Boot at: 33f27000

将include/configs/mini2440.h中CONFIG_SYS_TEXT_BASE修改为0x33E00000:

#define CONFIG_SYS_TEXT_BASE   0x33E00000

重新编译后,加载到系统中:

reset
init_2440
load_image /home/host/soft/mini2440/u-boot-2014.04/u-boot.bin 0x33e00000 bin
resume 0x33e00000

可以正常进入uboot(输出信息太长了,不再列出)。

在uboot下执行下面命令(需要查看md和nand dump输出内容是否一致):

nand read   0x100
nand dump 0x100
md

查看二者输出可以看到,二者输出信息是一致的(只是md的输出信息使用小端法表示,会有点难以比对)

再执行下面命令:

nand erase 0x100000 0x100000
nand dump 0x100000 0x100
nand write 0 0x100000 0x100
nand dump 0x100000 0x100

两次dump的信息一致,但是都是ff,这说明nand write并没有真正把数据写入到nand flash中。

参考《u-boot移植到mini2440,u-boot版本2008.10 》默认不会对写入进行校验,需要添加CONFIG_MTD_NAND_VERIFY_WRITE才能进行校验

在include/configs/mini2440中添加一行代码:

#define CONFIG_MTD_NAND_VERIFY_WRITE

重新编译uboot,并按照上面步骤载入并进入uboot.

然后执行nand write命令:

MINI2440 # nand write  0x100000 0x100

NAND write: device  offset 0x100000, size 0x100
hwcontrol(): 0x70 0x83
hwcontrol(): 0xffffffff 0x81
hwcontrol(): 0x80 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0x00 0x05
hwcontrol(): 0x200 0x05
hwcontrol(): 0x02 0x05
hwcontrol(): 0xffffffff 0x81
hwcontrol(): 0x10 0x83
hwcontrol(): 0xffffffff 0x81
hwcontrol(): 0x70 0x83
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x00 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0x00 0x05
hwcontrol(): 0x200 0x05
hwcontrol(): 0x02 0x05
hwcontrol(): 0xffffffff 0x81
hwcontrol(): 0x30 0x83
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0xffffffff 0x80
NAND write to offset failed -
bytes written: ERROR

nand write执行失败。

修改drivers/mtd/nand/s3c2410_nand.c:

添加一行代码:
ulong IO_ADDR_W = CONFIG_SYS_NAND_BASE;
删除两行代码:
// struct nand_chip *chip = mtd->priv;
// chip->IO_ADDR_W = (void *)IO_ADDR_W; 修改下面一行代码(chip->替换成(void *):
writeb(cmd, chip->IO_ADDR_W);
还有一行代码中ulong需要删除掉:
ulong IO_ADDR_W = (ulong)nand;

然后再次编译、加载、运行uboot,

在uboot下执行下面命令:

md
nand erase 0x100000 0x100
nand write 0x100000 0x100
nand dump 0x100000 0x100

最后一条命令显示信息如下:

hwcontrol(): 0x00 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0x00 0x05
hwcontrol(): 0x200 0x05
hwcontrol(): 0x02 0x05
hwcontrol(): 0xffffffff 0x81
hwcontrol(): 0x30 0x83
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0xffffffff 0x80
Page dump:
f0 ea f0 9f e5 f0 9f e5 f0 9f e5
f0 9f e5 f0 9f e5 f0 9f e5 f0 9f e5
f8 c0 f8 f8 f8
e0 f8 f8 f8 ef be ad de
f8 f8 cc fb 9c b5 ff
de c0 ad 0b de c0 ad 0b 0f e1 1f c0 e3
d3 e3 f0 e1 a0 e3 a0 e3
e5 e0 e3 9f e5 e5
1c 9f e5 1c 9f e5 e5 9f e5
a0 e3 e5 1f ee e3
1f ee a0 e3 7f 2a a0 e3 e2
e5 5b eb c0 4f e2 1f e5
e1 0a f1 a0 e3 a0 e3
e5 3c a0 e3 e5 e3
2c 1a c4 9f e5 f1 a0 e3 e5
4e a0 e3 b8 9f e5 e5 e5
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
.......................

后面还有一些输出信息,都是ff,此处我都将其省略了。