Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12612 Discussions

Problem with Flash alt_flash_open_dev()

Altera_Forum
Honored Contributor II
1,814 Views

Problems with: alt_flash_open_dev() 

 

I am running the memtest.c program that Altera provides with the Nios II IDE. 

It runs as expected when testing RAM but I have problems when testing Flash. 

If I select "Test CFI Flash" from the Menu and use the default  

Flash Device "/dev/ext_flash" it always returns:  

- ERROR: Could not open /dev/ext_flash 

 

I have looked thru this Forum and found a number of entries that 

are similar to my problem. But have not isolated my problem yet. 

 

====== My System Info ==================== 

- Stratix II EP2S60 

- NiosII using the altera avalon cfi flash Interface. 

- Using QuartusII 5.1/SP 0.15 and Nios2 5.1/Patch 001 

- My system.h has: 

-# define EXT_FLASH_NAME "/dev/ext_flash" 

-# define ALT_TEXT_DEVICE EXT_SRAM 

-# define EXT_FLASH_TYPE "altera_avalon_cfi_flash" 

 

- The 'system library properties' for memtest.c do NOT have  

'small C library' or 'reduced device drivers' selected. 

=======================================  

 

I stepped thru the program and it appears that: 

 

- In the Function TestFlash:  

fd = alt_flash_open_dev(flashname); 

(flashname= "/dev/ext_flash") 

and fd is set = 0x0.  

 

- alt_flash_open_dev() calls alt_find_dev(). 

- alt_find_dev() exits with "return NULL". 

 

- I think alt_find_dev is looking thru a list (&alt_flash_dev_list) for 

the device "/dev/ext_flash". (and doesn't find it) 

Where is this list (alt_flash_dev_list) generated and how can I look at it? 

Any ideas why "/dev/ext_flash" would not be in the list? 

 

- At this point I don't think the Flash Device itself has been accessed. 

(ie: read or written ) Is this assumption correct? 

If I had a Flash H/W problem would the call to alt_find_dev() still work? 

Trying to isolate to either a S/W or a H/W problem. 

 

The Flash we are using is a CFI Flash Spansion S29GL256M. 

(replacement for a AM29LV256M) 

 

 

Any help you can provide is appreciated. 

 

Jim
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
949 Views

Jimbo, 

 

You've got a couple of debug options, though what you're trying to do should certainly work: 

 

1. Step through the initialization code for the CFI Flash (ext_flash) in your system. It's called from within alt_sys_init.c, which, in turn, is a part of your System Library project. 

 

2. Try to program your flash, using the command line tool (not through the GUI). You should be able to get a lot more information here. 

 

Best Regards, and Best of Luck. 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
949 Views

Hello Jim, 

 

Are you using the flash in 8 bit mode? If yes take a look at: http://forum.niosforum.com/forum/index.php?showtopic=455 (http://forum.niosforum.com/forum/index.php?showtopic=455

 

 

Regards, 

niosIIuser
0 Kudos
Altera_Forum
Honored Contributor II
949 Views

 

--- Quote Start ---  

originally posted by slacker@Jan 8 2006, 01:28 AM 

jimbo, 

 

you've got a couple of debug options, though what you're trying to do should certainly work: 

 

1.  step through the initialization code for the cfi flash (ext_flash) in your system.  it's called from within alt_sys_init.c, which, in turn, is a part of your system library project. 

 

2.  try to program your flash, using the command line tool (not through the gui).  you should be able to get a lot more information here. 

 

best regards, and best of luck. 

 

- slacker 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=12038) 

--- quote end ---  

 

--- Quote End ---  

 

 

Hi slacker, thanks for your reply. 

 

1. I have not tried stepping thru the initialization code for the CFI Flash . 

I will. 

What types of things should I be looking for? 

 

2. I did try programing the Flash using the command line tool. 

In SOPC I have ext_flash at Base: 0x02000000 

Using the Flash Programmer in command line mode I tried:  

> nios2-flash-programmer --debug --base 0x2000000 

 

Using cable "USB-Blaster [USB-0]", device 1, instance 0x00 

Resetting and pausing target processor: OK 

No CFI table found at address 0x02000000 

Original contents (after writing 0xF0 and 0xFF to address 0x02000000): 

0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

10: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

Contents after writing 0x98 to address 0x020000AA: 

Same after writing 0x0098 to address 0x02000154: 

Same after writing 0x00000098 to address 0x020002A8: 

Same after writing 0x98 to address 0x02000055: 

Same after writing 0x0098 to address 0x020000AA: 

Same after writing 0x00000098 to address 0x02000154: 

Same after writing 0x98 to address 0x02000154: 

Same after writing 0x0098 to address 0x020002A8: 

Same after writing 0x00000098 to address 0x02000550: 

0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

10: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................ 

Leaving target processor paused 

 

So looks like a Hardware connection problem? 

I have double checked the FPGA pinout and Flash connections and I think 

all is OK... but this is a new card/design. 

 

In SOPC Builder, for the CFI Flash Memory Device I selected: 

AMD29LV128M (WORD Mode) Add Width: 23 bits, Data Width: 16 bits 

 

 

Back to my first post about the call to alt_find_dev() and alt_flash_dev_list. 

For alt_find_dev to work (return the device name and not 0x0) do you 

know if the Flash device is accessed? From what I have looked at it looks like 

the alt_find_dev() just searches thru the alt_flash_dev_list and doesn&#39;t 

access (wrt/rd) the Flash. From what I stepped thru in the memtest.c 

I think the problem is that alt_find_dev() returns 0x0. 

Do you know how I can look at whats in alt_flash_dev_list ? 

(to see if /dev/ext_flash is in it) 

 

Thanks for the help. 

 

Jim
0 Kudos
Altera_Forum
Honored Contributor II
949 Views

 

--- Quote Start ---  

originally posted by niosiiuser@Jan 8 2006, 05:15 AM 

hello jim, 

 

are you using the flash in 8 bit mode? if yes take a look at: http://forum.niosforum.com/forum/index.php?showtopic=455 (http://forum.niosforum.com/forum/index.php?showtopic=455

 

 

regards, 

niosiiuser 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=12042) 

--- quote end ---  

 

--- Quote End ---  

 

 

 

Hi niosIIuser, 

 

I am using a 16 bit Flash. 

In SOPC Builder, for the CFI Flash Memory Device I selected: 

AMD29LV128M (WORD Mode) Add Width: 23 bits, Data Width: 16 bits 

 

I looked at the Post you referenced and it made me question how I connected the 

Address lines. I shifted the Address lines by 1, that is address bit 1 from 

the ext_flash_bridge_address is connected to my Flash Device Address bit 0. 

 

 

Thanks for the reply. 

 

Jim
0 Kudos
Altera_Forum
Honored Contributor II
949 Views

Jim, 

 

The "/dev/..." virtual filesystem is always set in the device initialization code. The fact that it&#39;s returning 0 means that initialization is failing, which goes along with the CLI flash programming results you posted. 

 

If you were to step through the initialization code, you would see sections where it reads the flash device to determine what type of flash it&#39;s accessing. The initialization "function" can be found in <nios2_root>/components/altera_avalon_cfi_flash/HAL/src/altera_avalon_cfi_flash.c. 

 

In any case, you do have some sort of connection/hardware issue, as you&#39;ve already determined. 

 

Best of luck, 

 

- slacker
0 Kudos
Reply