Flash programming with rtl8139

Markus Schlotterer <[email protected]> Thu, 14 Aug 2003 12:21:59 +0200
Newsgroups gmane.linux.drivers.realtek.devel
Message-ID <[email protected]>
Hi all,

I tried to flash an AMD Am29F010B flash rom using a noname NIC with 
RTL8139C chip. The tool provided bei Realtek (rtflash.exe) didn't work 
because the AMD flash is not know.
Then I tried the rtl8139-diag tool. At first it didn't even recognize 
the chips ids correctly. Then I found a patch by Mikkel Lauritsen 
(http://www.scyld.com/pipermail/realtek/2001-August/001070.html) and 
after applying this patch, everything worked correctly. I really wonder 
why this patch is not in the standard distribution of rtl8139-diag? 
Maybe there are different versions of the rtl8139 chip.

This flash rom needs a chip erase before programming. After programming 
first few bytes were not programmed correctly and remained 0xFF. So I 
patched libflash.c and applied the "Data Polling Algorithm" to check 
whether the flash internal chip erase algorithm has been finished and 
did succed. The "Data Polling Algorithm" has been taken form the AMD 
Am29F010B data sheet. After applying the algorithm, everything worked 
perfectly. Maybe this algorithm is used by other chips too, so i will 
provide the patch here:

333a334,335
 >         int value, old_value, passed;
 >
336c338,366
<       usleep(20000);                          /* 20 msec. */
---
 >
 >       passed = 0;
 >       value = 0;
 >       do {
 >         old_value = value;
 >         value = flash_in(addr_ioaddr, data_ioaddr, 0);
 >         if (verbose > 2)
 >           printf("Chip erasing! %X\n", value);
 >         if ((value & 0x40) == (old_value & 0x40)) {
 >           passed = 1;
 >           break;
 >         }
 >         usleep(20000);
 >       } while (!(value & 0x20));
 >       if (!passed) {
 >           old_value = value;
 >         value = flash_in(addr_ioaddr, data_ioaddr, 0);
 >         if (verbose > 2)
 >           printf("Chip erasing (last step)! %X\n", value);
 >         if ((value & 0x40) == (old_value & 0x40))
 >           passed = 1;
 >       }
 >
 >         if (verbose > 1) {
 >         if (passed)
 >             printf("Chip erase suceeded!\n");
 >         else
 >             printf("Chip erase failed, Timeout exceeded! %X\n", value);
 >       }

Here is also the data for AMD Am29F010B flash rom:

114c114
<       { 0x01, 0x20, 0, 0, 0, "AMD Am29F010B", },
---
 >       { 0x01, 0x20, ERASE_FIRST, 1024*128, 1, "AMD Am29F010B", },

Maybe anybody needs that.

Markus