Skip to main content
Topic: Adding Bus Pirate support to flashrom? (Read 62506 times) previous topic - next topic

Re: Adding Bus Pirate support to flashrom?

Reply #30
Attached zip contains a flashrom.exe with buspiratespi support.

I took out the FTDI-SPI programmer as it requires the libusb driver which reportedly has issues on Vista or newer, and the serial programmer driver isn't portable yet.

The code is revision 831 of the flashrom repository, with my patch (http://patchwork.coreboot.org/patch/740/), which hopefully makes it into the official version.

Select the buspirate programmer with
flashrom.exe -p buspiratespi:dev=COM9
(instead of COM9, you have to use your buspirate's COM port of course)

flashrom.exe -h will tell you how to select read, write, erase, verify modes.

For example:
flashrom -r test.bin -p buspiratespi:dev=COM9
to read the flash chip's content into test.bin.

As usual with opensource software, there's no warranty. I built it, ran it (without any SPI device attached to the buspirate), my buspirate is still alive. That's all the testing flashrom had to endure here.


Have fun.

Re: Adding Bus Pirate support to flashrom?

Reply #31
[quote author="pgeorgi"]
The code is revision 831 of the flashrom repository, with my patch (http://patchwork.coreboot.org/patch/740/), which hopefully makes it into the official version.[/quote]

The patch was committed a few minutes ago.

Thanks, Patrick!
If you have any flashrom problems, please mail flashrom@flashrom.org and include "Bus Pirate" in the subject line. As an alternative, you can send me a private message.
It is recommended to use at least flashrom 0.9.2 or later, and latest flashrom from svn if you want a 3x speedup.

 

Re: Adding Bus Pirate support to flashrom?

Reply #32
There were some windows-related issues in flashrom, which are fixed in the attached version (which is upstream r881 with http://patchwork.coreboot.org/patch/834/ applied)

Re: Adding Bus Pirate support to flashrom?

Reply #33
Thanks for the update pgeorgi. Do you have a use example for windows? I'm trying to read out a AT45DB041D (programming is unfortunately unsupported) but I get this:


C:>flashrom -p buspiratespi:dev=COM10
flashrom v0.9.1-r881
Error: cannot open serial port: No error

C:>

I think I'm not entering the port name correctly. Any hints?
Got a question? Please ask in the forum for the fastest answers.

Re: Adding Bus Pirate support to flashrom?

Reply #34
Never mind, I got it. It won't take a COM port that's more than a single digit:

Code: [Select]
C:>flashrom -r dump.hex -p buspiratespi:dev=COM3
flashrom v0.9.1-r881
Calibrating delay loop... OK.
Found chip "Atmel AT45DB041D" (512 KB, SPI) at physical address 0xfff80000.
===
This flash part has status NOT WORKING for operations: READ
This flash part has status UNTESTED for operations: PROBE ERASE WRITE
Please email a report to flashrom@flashrom.org if any of the above operations
work correctly for you with this flash part. Please include the flashrom
output with the additional -V option for all operations you tested (-V, -rV,
-wV, -EV), and mention which mainboard or programmer you tested. Thanks for your
 help!
===
Reading flash... FAILED!
ERROR: flashrom has no read function for this flash chip.

C:>


Changing the Bus Pirate to COM3 worked.
Got a question? Please ask in the forum for the fastest answers.

Re: Adding Bus Pirate support to flashrom?

Reply #35
Was reading the chip successful, too?

Thanks for the report with the multidigit COM ports.
It might be a problem in the FTDI Serial driver - at least I had the same issue with another FTDI-based device, with a totally different application.

The parser in flashrom has no assumption on the length of that value. On Linux, the device name is usually much longer.

I wrote a support request to FTDI, after all, it's their driver that seems to misbehave. Let's see if they react.

Re: Adding Bus Pirate support to flashrom?

Reply #36
Thanks!

No I couldn't read the chip, but flashrom could identify the JEDEC code. I accidentally posted the wrong output earlier, but now my previous post shows the flashrom output I got.

I'm developing firmware for an open source logic analyzer project (SUMP-PUMP) that uses this chip. I'm giving the device a Bus Pirate interface so it will work with (future) versions of flashrom. I'll use a perl or python script to program it for now.

Thanks again!
Got a question? Please ask in the forum for the fastest answers.

Re: Adding Bus Pirate support to flashrom?

Reply #37
The FTDI support pointed me to http://www.ftdichip.com/Support/Knowled ... higher.htm

just fyi, if you run into such a situation again. I think I'll add specific support for that notation (so COMx will be translated to \.COMx internally) to flashrom.

Re: Adding Bus Pirate support to flashrom?

Reply #38
Attached flashrom, which is upstream version r883 without local changes, fixes the COM10 issue by rewriting the device to UNC if it starts with COM (case insensitive).

Re: Adding Bus Pirate support to flashrom?

Reply #39
[quote author="ian"]
Code: [Select]
C:>flashrom -r dump.hex -p buspiratespi:dev=COM3
flashrom v0.9.1-r881
Found chip "Atmel AT45DB041D" (512 KB, SPI) at physical address 0xfff80000.
===
This flash part has status NOT WORKING for operations: READ
This flash part has status UNTESTED for operations: PROBE ERASE WRITE
===
Reading flash... FAILED!
ERROR: flashrom has no read function for this flash chip.
[/quote]

The Atmel AT45DB041D is a very special/odd chip. It supports 256 or 264 byte sectors depending on some configuration status register. That register can be read with a command that is used as erase command on other SPI chips. Fun!

Anyway, with the current flashrom architecture you can support the 256 byte sector mode easily (at least for reading you just have to set .read=spi_chip_read, and writing is doable as well). The easiest way forward is to create a wrapper for probe_spi_rdid which reads the configuration status registers on success, and only returns success if the chip is in 256 byte mode. A separate flashchip entry (and a separate probe wrapper) would have to be created for the 264 byte mode, and then flashrom would detect the combination of chip model and sector size.

OTOH, the 264 byte sector mode has big holes in the address space (264 bytes data, 248 bytes hole, 264 bytes data, 248 bytes hole, ...) and flashrom can't cope with that yet, especially because it would have to map a contiguous hole-free ROM image to an address space with more holes than Swiss cheese.

So it all depends on the sector size.
If you have any flashrom problems, please mail flashrom@flashrom.org and include "Bus Pirate" in the subject line. As an alternative, you can send me a private message.
It is recommended to use at least flashrom 0.9.2 or later, and latest flashrom from svn if you want a 3x speedup.

Re: Adding Bus Pirate support to flashrom?

Reply #40
The holes in the address space really got me. I wrote a perl script to load/dump the ROM image, and it wrote/read funny. Turns out that was the problem, I was addressing the gaps as well. Once I compensated, it worked fine.

Is 264 non-standard? There's an operation that will give the chip a 256byte/page address space, but it's a one time fuse. That's an extra step at the factory or something we'd have to make the user/upgrade program do, so I'm sticking with 264 byte mode for now.

Thanks for the explanation, it's very enlightening.
Got a question? Please ask in the forum for the fastest answers.

Re: Adding Bus Pirate support to flashrom?

Reply #41
For NOR flash, 264 byte sectors (or any non-power-of-2 sectors) are extremely unusual.
Odd sizes (2^n+k, 2<=k<=16) are the norm on NAND flash and the k "extra" bytes are used for ECC (error-correcting code).

It is generally recommended to use the extra bytes for ECC (well, you can use them for data/code storage on some chips but that is not a good idea) so you only have 2^n (256 in your case) bytes for code/data per sector anyway.
Now the difference is just that long sectors allow error detection/correction and no direct mapping (you have to jump over the holes if you intend to map it) whereas the 2^n sized sectors have no way to perform error detection/correction but there are no holes in mapping and you can treat them as linear memory from a code POV.

Do not read below if you have a weak stomach.
-------------------------------------------------------------

There are some chips which have non-uniform sector sizes: either the topmost or bottommost sector(s) have size 2^n whereas the rest of the chip has size 2^n+k, and these variants are subdivided into those which allow linear mapping of the 2^n sized sectors and those which don't. Did I mention that the extra bytes exist even for the 2^n sized sectors on some chips, but they are readonly and explicitly not usable for ECC?
Some chips allow a one-time change (either direction) in sector size for the whole chip, some only support a change in one direction (your AT45DB041D).
Some chips have additional builtin RAM which can operate at the selected sector size (your AT45DB041D), others have RAM with fixed sector size, and finally a whole bunch of chips do not have RAM at all. Oh, and the amount of RAM (sector count) is arbitrary as well.
If you have any flashrom problems, please mail flashrom@flashrom.org and include "Bus Pirate" in the subject line. As an alternative, you can send me a private message.
It is recommended to use at least flashrom 0.9.2 or later, and latest flashrom from svn if you want a 3x speedup.

Re: Adding Bus Pirate support to flashrom?

Reply #42
New release: flashrom r905 (with no local changes)

Most notable (for Win32 users): It opens files with "rb" or "wb" for read or write, so Windows doesn't try to convert newlines. This is in upstream for quite a while already, but it seems I forgot to post a new binary.

Thanks to Danny Grander who reminded me about this.

Re: Adding Bus Pirate support to flashrom?

Reply #43
Thanks for the update, I'll do a post too.
Got a question? Please ask in the forum for the fastest answers.

Re: Adding Bus Pirate support to flashrom?

Reply #44
I'm having a problem with my EN25F16 flashrom:

Code: [Select]
>flashrom.exe -p buspiratespi:dev=COM5 -c EN25F16 -V

flashrom v0.9.1-r905
SPI speed is 8MHz
Raw bitbang mode version 1
Raw SPI mode version 1
Calibrating delay loop... 682M loops per second, 100 myus = 0 us. OK.
Probing for Eon EN25F16, 2048 KB: RDID returned 0x1f 0xff 0xff. probe_spi_rdid_g
eneric: id1 0x1f, id2 0xffff
No EEPROM/flash device found.
If you know which flash chip you have, and if this version of flashrom
supports a similar flash chip, you can try to force read your chip. Run:
flashrom -f -r -c similar_supported_flash_chip filename

Note: flashrom can never write when the flash chip isn't found automatically.
Raw bitbang mode version 1
Bus Pirate shutdown completed.

As you can see, the Flash doesn't identify correctly, only the first byte is correct, the other bytes are all high (FF).

However, if i try to read the ID using the buspirate prompt, it identifies correctly!
Code: [Select]
READ: 0x1C 0x3F 0xFF 0xFF
Using the prompt the buspirate reads the second byte correctly.

Here is the full command sequence I used:
Code: [Select]
HiZ> m
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. KEYB
9. LCD
x. exit(without change)

(1)> 5
Set speed:
 1. 30KHz
 2. 125KHz
 3. 250KHz
 4. 1MHz

(1)> 4
Clock polarity:
 1. Idle low *default
 2. Idle high

(1)> 1
Output clock edge:
 1. Idle to active
 2. Active to idle *default

(2)> 1
Input sample phase:
 1. Middle *default
 2. End

(1)> 1
Select output type:
 1. Open drain (H=Hi-Z, L=GND)
 2. Normal (H=3.3V, L=GND)

(1)> 2
Ready.
SPI> W
POWER SUPPLIES ON
SPI> [0x9f r:4]
CS ENABLED
WRITE: 0x9F
READ: 0x1C 0x3F 0xFF 0xFF
CS DISABLED
SPI>

I also tried using flashrom at 1MHz like i did on the prompt but it still fialed to read the second byte.

My conclusion is that the flashrom program has to have some bug in it. Can you help me?