A new customer came to me late last week with an interesting problem. They have hundreds of Motorola/Symbol MC70 barcode scanners in the field and occasionally the flash memory on the devices gets corrupted.
The current “solution” these guys are using involves removing the flash chips from the board, reprogramming it in a separate device, re-balling the BGA pins, and re-soldering it to the board. That explains why they desperately want an application that can do it.
They know the range where the corruption occurs and wanted an application that would allow a user to read, update and rewrite the corrupted bytes in flash. They had talked with five separate developers before they found me, and all 5 had agreed that it was impossible, so naturally I took that as a challenge.
First, there are lots of things to know about how flash access works. Most importantly, it’s not like RAM. You can’t just map to it, then go about your merry way doing 32-bit reads and writes. You can read it that way, sure, but writing is a whole new game. Flash is broken up into “blocks” (which aren’t even always the same size - in the case of the MC70, the first 4 blocks are 64k long, and the rest are 256k long.) and writes must be done following this general procedure:
- Read the *entire* block that contains the byte you want to change into RAM
- Change to flash to Lock mode (a flash register write)
- Unlock the block of flash (another register write)
- Change the flash to erase mode (register write)
- Erase the *entire* block of flash (which writes all FF’s to it)
- Change the flash to write mode (register write)
- Update the RAM buffer with your changes
- Write in the *entire* block block to flash
- Tell the flash to commit (register write)
- Wait for the flash to finish (register read)
- Put the flash back into read mode (register write)
Oh, and if you get any of this wrong, you’ve made yourself an expensive brick. The only solution at that point is the de-soldering and reprogramming route, and I don’t have that kind of hardware in my office.
So I started writing the app Monday morning, using C# since I had to create a UI for the editor, and on Wednesday morning this is what I delivered:
So, in just 2 days I did what was “impossible”. I not only wrote all of the flash access code, I also wrote a hex editor control and an app UI to make use of the flash library.