Altera_Forum
Honored Contributor
19 years agoproblems with Flash by redboot on eCos with NIOS2
Hello,
I tryed to make reboot working for StratixII Board with NIOSII Processor. Redboot permanently failed on detecting the flash device correctly. As it turns out, the flash detection routine reads out completly wrong flash ID (in file \redboot_install\include\cyg\io\flash_am29xxxxx_parts.inl, function flash_query(void* data) ) i did recognize it by inserting printouts in flash_hwr_init(void) flash_data_t id;
flash_dev_query(id);
diag_printf("My Flash ID is %.2x:%.2x:%.2x:%.2x \n", id,id,id,id); i have a AM29LV128M Flash which should return ID 01:7E:12:0 in 8 Bit mode but the flash_dev_query(..) returns something like 14:44:3A:00, differs sometimes. So i took a look to the flash_dev_query(...) Here some part of the routine where it reads out the id (all pointers are declared with volatile) *f_s1 = FLASH_Setup_Code1;
*f_s2 = FLASH_Setup_Code2;
*f_s1 = FLASH_Read_ID;
id = -1;
id = -1;
// Manufacturers' code
id = *(FLASH_P2V(ROM+FLASH_VendorID_Addr));
// Part number
id = *(FLASH_P2V(ROM+FLASH_DeviceID_Addr));
id = *(FLASH_P2V(ROM+FLASH_DeviceID_Addr2));
id = *(FLASH_P2V(ROM+FLASH_DeviceID_Addr3)); So, after many testing an trying with own test programms i took a close look to this "volatile"-pointer usage and I found this in the NIOS2 Manual, which would explain the whole problem: <div class='quotetop'>QUOTE </div> --- Quote Start --- For C programmers, note that declaring a pointer as volatile does not cause accesses using that volatile pointer to bypass the data cache. The volatile keyword only prevents the compiler from optimizing out accesses using the pointer. 1 this volatile behavior is different from the methodology for the first-generation nios processor. [/b] --- Quote End --- In this case, accessing the flash memory, which io range is memorymapped into the cpu address space, each access has to BYPASS the data cache, to success. To do this with NIOS2 Prozessor, one need to use the ldio/stio instruction instead normal memory instructions. The Altera provided HAL gives Macros like iord_directxx to do this. I tryed this out in my testprogramm, and now, id is readden correctly:
IOWR_8DIRECT(EXT_FLASH_BASE,FLASH_Setup_Addr1, FLASH_Setup_Code1);
IOWR_8DIRECT(EXT_FLASH_BASE,FLASH_Setup_Addr2, FLASH_Setup_Code2);
IOWR_8DIRECT(EXT_FLASH_BASE,FLASH_Setup_Addr1, FLASH_Read_ID);
id = -1;
id = -1;
// Manufacturers' code
id=IORD_8DIRECT(ROM,FLASH_VendorID_Addr);
// Part number
id=IORD_8DIRECT(ROM,FLASH_DeviceID_Addr);
id=IORD_8DIRECT(ROM,FLASH_DeviceID_Addr2);
id=IORD_8DIRECT(ROM,FLASH_DeviceID_Addr3); So my question now: Does anyone knows a solution to tell the compiler to automatically convert volatile pointer memory instructions to correct ldio/stio instructions? Or needs this code to be rewritten completly. I guess that there are much more volatile pointer operations in ecos/redboot source like i found here... Any solutions? Best regards, http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif Marek