Hi all,
我们在板子上集成了一块FPGA,通过GPMC总线,GPMC配置如下:
1. CS0: Nand flash
2. CS3: FPGA
下面的代码是配置GPMC CS3的:
void gpmc_fpga_init(void)
{
/* Perform the GPMC configurations for FPGA. */
gpmc_cs_write_reg(3, GPMC_CS_CONFIG7, 0); //CS3 disable
//burst read,single write
gpmc_cs_write_reg(3, GPMC_CS_CONFIG1, 0x69001001);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG2, 0x00030701);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG3, 0);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG4, 0x03010684);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG5, 0x02060408);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG6, 0x03000200);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG7, ((12 << 8) | ((0x4000000 >> 24) & 0x3F) | (1 << 6)));
gpmc_cs_write_reg(1, GPMC_CS_CONFIG7, 0);
gpmc_cs_write_reg(2, GPMC_CS_CONFIG7, 0);
gpmc_cs_write_reg(4, GPMC_CS_CONFIG7, 0);
gpmc_cs_write_reg(5, GPMC_CS_CONFIG7, 0);
gpmc_cs_write_reg(6, GPMC_CS_CONFIG7, 0);
gpmc_write_reg(GPMC_CONFIG, gpmc_read_reg(GPMC_CONFIG) & ~(0x2));
}
现在我们可以访问我们自己的FPGA了,但是在和Nand Flash一起使用时,发现了一些有趣的事情:
Step 1: 加载FPGA固件
Step 2: 读取FPGA版本号寄存器: __raw_readw(FPGA_BASE + 0x6);
Step 3: nandtest /dev/mtd0
Step 3总是会出错,如下:
[root@Ronds: ~]# nandtest /dev/mtd0
ECC corrections: 0
ECC failures : 128
Bad blocks : 0
BBT blocks : 0
00000000: reading (1 of 4)…[ 53.863347] omap2-nand 8000000.nand: uncorrectable bit-flips found
[ 53.871043] omap2-nand 8000000.nand: uncorrectable bit-flips found
[ 53.877252] omap2-nand 8000000.nand: uncorrectable bit-flips found
……
如果跳过Step1,那么nandtest就不会出错,也就是说如果FPGA本身没有工作,则不会出错。
经过一些测试,我找到了一个WA,如下:
Step 1: 加载FPGA固件
Step 2: 读取FPGA版本号: __raw_readw(FPGA_BASE + 0x6);
Step 3: devmem 0x50000114 –> 读取 GPMC_NAND_DATA_3 寄存器
Step 4: nandtest /dev/mtd0
在nandtest之前,读取一下GPMC_NAND_DATA_3 寄存器(必须是此寄存器,读其他的寄存器不管用),这样就不会出错了!!!
最终我把这个WA加到了nand控制器驱动里(drivers/mtd/nand/omap2.c):
void gpmc_wr_for_nand_fpga(void)
{
gpmc_cs_read_reg(3, GPMC_CS_NAND_DATA);
}
static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, int mode)
{
……
gpmc_wr_for_nand_fpga();
/* GPMC configurations for calculating ECC */
switch (ecc_opt) {
……
}
这样FPGA和Nand Flash就能和平共处了。
问题虽然解决了,但是我还是不明白,这个WA起作用的原因是什么?
希望各位有知道的烦请解个惑,谢谢了。。。
song zhang4:
有没有人知道原因啊,苦等好久了。。。
Jian Zhou:
回复 song zhang4:
加载FPGA的时候,有没有reset GPMC模块?
song zhang4:
回复 Jian Zhou:
你好,加载的时候没有reset GPMC,需要reset吗?
因为我们肯定是在系统启动完后才加载的,那个时候应该不能reset GPMC了
mines:
回复 Jian Zhou:
您好,我也遇到同样的问题外接了个FPGA。nand和FPGA共用gpmc总线。我的错误是在运行我的应用程序时出现的。有时候操作nand里面的文件没问题,但是有时候操作FPGA运行后再操作文件就会出现
[ 1039.111091] omap2-nand 8000000.nand: uncorrectable bit-flips found[ 1039.124471] omap2-nand 8000000.nand: uncorrectable bit-flips found[ 1039.145105] omap2-nand 8000000.nand: uncorrectable bit-flips found[ 1039.163469] omap2-nand 8000000.nand: uncorrectable bit-flips found[ 1039.182397] omap2-nand 8000000.nand: uncorrectable bit-flips found[ 1039.200289] omap2-nand 8000000.nand: uncorrectable bit-flips found[ 1039.214863] omap2-nand 8000000.nand: uncorrectable bit-flips found[ 1039.235743] omap2-nand 8000000.nand: uncorrectable bit-flips found[ 1039.253521] ubi0 error: ubi_io_read: error -74 (ECC error) while reading 1191 bytes from PEB 321:35984, read 1191 bytes[ 1039.281298] CPU: 0 PID: 672 Comm: mcc.out Not tainted 4.4.12 #3[ 1039.295115] Hardware name: Generic AM33XX (Flattened Device Tree)[ 1039.314365] Backtrace: [ 1039.320387] [<c00134e0>] (dump_backtrace) from [<c00136dc>] (show_stack+0x18/0x1c)[ 1039.342217] r7:00000000 r6:000004a7 r5:cf026000 r4:ffffffb6[ 1039.355764] [<c00136c4>] (show_stack) from [<c0299968>] (dump_stack+0x24/0x28)[ 1039.376998] [<c0299944>] (dump_stack) from [<c043fe98>] (ubi_io_read+0x154/0x330)[ 1039.397867] [<c043fd44>] (ubi_io_read) from [<c043d75c>] (ubi_eba_read_leb+0x160/0x414)[ 1039.419051] r10:02408040 r9:ffffe000 r8:00000dce r7:00000000 r6:cf525c00 r5:cf026000[ 1039.440249] r4:000004a7[ 1039.448823] [<c043d5fc>] (ubi_eba_read_leb) from [<c043c5c8>] (ubi_leb_read+0x78/0xd0)[ 1039.469937] r10:00007c90 r9:000004a7 r8:00000000 r7:cf026000 r6:cf525c00 r5:00007c90[ 1039.489059] r4:000004a7[ 1039.495065] [<c043c550>] (ubi_leb_read) from [<c02238d4>] (ubifs_leb_read+0x34/0xa0)[ 1039.521149] r8:00007c90 r7:00000dce r6:000004a7 r5:cf027000 r4:00000001[ 1039.537408] [<c02238a0>] (ubifs_leb_read) from [<c0226c18>] (fallible_read_node+0x6c/0x19c)[ 1039.560594] r8:cc16bcf8 r7:cf027000 r6:cc16bc88 r5:cc292000 r4:00000001[ 1039.577139] [<c0226bac>] (fallible_read_node) from [<c0228e3c>] (ubifs_tnc_locate+0xfc/0x1cc)[ 1039.601049] r10:cc292000 r9:00000000 r8:cf027250 r7:00000000 r6:cc16bcf8 r5:00000000[ 1039.619930] r4:cf027000[ 1039.625916] [<c0228d40>] (ubifs_tnc_locate) from [<c021ae04>] (do_readpage+0x174/0x450)[ 1039.650844] r10:cafd8000 r9:cc292000 r8:00003171 r7:cb360e10 r6:00000012 r5:0000005e[ 1039.669780] r4:cff38a60[ 1039.675688] [<c021ac90>] (do_readpage) from [<c021c14c>] (ubifs_readpage+0x40/0x500)[ 1039.699832] r10:0001a000 r9:cb360e10 r8:00000012 r7:00000012 r6:00000012 r5:cf027000[ 1039.719223] r4:cff38a60[ 1039.725229] [<c021c10c>] (ubifs_readpage) from [<c00aed74>] (filemap_fault+0x170/0x520)[ 1039.749970] r10:0001a000 r9:cf0ea068 r8:c09a6fc0 r7:cf716300 r6:00000012 r5:00000000[ 1039.769104] r4:cff38a60[ 1039.775100] [<c00aec04>] (filemap_fault) from [<c00d2dfc>] (__do_fault+0x44/0xac)[ 1039.799236] r10:0001a000 r9:cf0ea068 r8:c09a6fc0 r7:c0a1714c r6:cc2445d8 r5:cf0ea000[ 1039.818280] r4:00000000[ 1039.824185] [<c00d2db8>] (__do_fault) from [<c00d6a38>] (handle_mm_fault+0xabc/0x11ac)[ 1039.848456] r4:0001e000[ 1039.854486] [<c00d5f7c>] (handle_mm_fault) from [<c001b5c8>] (do_page_fault+0x288/0x358)[ 1039.877742] r10:00000054 r9:cf6e91f4 r8:0001a58c r7:00000017 r6:cf6e91c0 r5:cc3a9f80[ 1039.899856] r4:cc16bfb0[ 1039.905956] [<c001b340>] (do_page_fault) from [<c0009308>] (do_DataAbort+0x40/0xc0)[ 1039.927911] r10:00000000 r9:b3afefb0 r8:cc16bfb0 r7:0001a58c r6:c001b340 r5:00000017[ 1039.949382] r4:c09a87f4[ 1039.955367] [<c00092c8>] (do_DataAbort) from [<c0014480>] (__dabt_usr+0x40/0x60)[ 1039.976675] Exception stack(0xcc16bfb0 to 0xcc16bff8)[ 1039.991069] bfa0: 0001a58c 00000025 0001a58c b3afe600[ 1040.012964] bfc0: 00000000 00000000 00028068 25252525 0002807a b3afefb0 00000000 b6ef9d60[ 1040.034458] bfe0: 000255c8 b3afe4fc 81010100 b6e6998c 60000030 ffffffff[ 1040.052813] r8:10c5387d r7:10c5387d r6:ffffffff r5:60000030 r4:b6e6998c[ 1040.069146] UBIFS error (ubi0:0 pid 672): ubifs_leb_read: reading 1191 bytes from LEB 3534:31888 failed, error -74
我也是在系统起来之后给FPGA上电加载固件的,请问这个要reset gpmc吗?系统起来后reset gpmc如何操作呢