Saturday 28 February 2015

Reflashing an Intel Galileo

If you're the lucky owner of an Intel Galileo board then you'll probably know that the device has an 8MByte flash chip, which contains the BIOS and a Linux boot image (even the ones that MS shipped apparently). Sadly, it is possible to accidentally trash the contents of flash chip rendering the device unbootable. The good news is that it is possible to recover the device if you have hardware that talks SPI. That could be a BusPirate, a BusBlaster, a PICKit2 (Linux only) or one of the many FT2232 SPI or JTAG boards. 

Reflashing the board isn't too difficult, given that Intel kindly provided a header for access to the flash chip. On the board I have, the flash is a Winbond W25Q64.V, which is a 64MBit device. Intel recommend using a Dediprog programmer, but that's a fairly expensive tool just to reprogram a single flash chip. It's even more expensive if you already have hardware that can talk SPI!

Intel also provides a boot ROM image for the Galileo, but it's not as simple as just writing it to flash. Intel utilise PDAT to store information such as board type and MAC address, and failing to insert this information into the ROM image will result in a non-booting board! I found this out the hard way, wondering why my board wouldn't boot after flashing the image.

Pre-requisites 

There are a number of pre-requisites before you proceed too far. I'm assuming that you're using Windows, although it should make little difference if you're running under Linux.  You need to know how to work a command line window.
  • You need Python 2.7 installed. You can download ActiveState's ActivePython. Execute the MSI file to install it.
  • You also need 7Zip installed. You can download it from 7zip.
  • Download the Board_Support_Package_Sources_for_Intel_Quark_v1.0.1.7z from Intel's Download Center.
  • Download the Flash Missing PDAT Release file that has a type of ".bin" from Galileo Software Downloads
  • Download flashrom. You can find it on http://flashrom.org/Downloads under the "Windows" snapshot downloads.

Extract Files

Open the Board Support Package Sources in 7Zip. We only want the "spi-flash-tools_v1.0.1.tar.gz" archive, so double click on it to get 7Zip to extract the tar file. You can then double click on the "spi-flash-tools_v1.0.1.tar" to extract the "spi-flash-tools_v1.0.1" directory. Extract this to the filesystem (click on Extract or drag and drop the folder to where you want it).

Customise the platform data

Once you've extracted the files, you need to go into "platform-data" directory, and make a copy of the "sample-platform-data.ini" file. I called mine "myGalileo.ini". You can double click on the file to edit it. There are several areas that need to be changed in the file - I've listed the section and the change that needs to be made below
  • [Platform Type] - change "data.value=2" to read "data.value=6"
  • [Mrc Params] - change "data.value=MRC/clantonpeak.v1.bin" to "data.value=MRC/kipsbay-fabD.v1.bin"
  • [MAC address 0] - Read the MAC address off the top of the ethernet connector on your Galileo board. Change "data.value=FFFFFFFFFF00" so that the "FFFFFFFFFF00" is replaced by the MAC address you read.
Now that you've customised your data file, copy Flash-missingPDAT_Release-1.0.4.bin you downloaded earlier into the same directory. Open up a command line window and make your way to where the platform-data directory is. You then need to issue the command:

python platform-data-patch.py -p myGalileo.ini -i ..\..\Flash-missingPDAT_Release-1.0.4.bin

This will take the information in the platform data file and integrate it with the flash image you downloaded. You should end up with a "Flash+PlatformData.bin" file that contains both.

Programming the flash

The next step is to connect your programmer to your Galileo. Ensure that the power is disconnected from the Galileo, as the SPI flash can be powered by the programmer. Locate the dediprog header, highlighted in the red square in the picture below:

Image from Wikipedia

The pin at the top right is pin 1, marked by a triangle on the silkscreen. To help you out, I've enlarged the connector and put the pin numbers on it.


To ensure you've got things the right way around, the missing pin is pin 7. Now you need to connect your programmer appropriately, according to the table below. If you're using a Bus Blaster or similar, ensure the target power jumper is set to provide 3.3v.

Galileo
Bus Pirate
Bus Blaster
PICkit2
1. VCC
(10) +3.3
(1) VTG
2
2. GND
(12) GND
(4) GND
3
3. CS
(4) CS
(7) TMS
1
4. SCK
(2) CK
(9) TCK
5
5. MISO
(3) MISO
(5) TDI
4
6. MOSI
(1) MOSI
(13) TDO
6

Next, it's a good idea to check that flashrom can communicate with the flash. You can do this by specifying the programmer (and port if necessary) as such:

> flashrom -p <programmer>

The programer line would be ft2232_spi for Bus Blaster or similar, buspirate_spi if you're using a buspirate, or pickit2 for the PICkit2 programmer. For some devices, such as the Bus Pirate, you need to specify the serial port to use. This would result in a command line such as:

> flashrom -p buspirate_spi:dev=com11

If that all works, you can flash the image using flashrom. The general form is:

> flashrom -p <programmer> -w Flash+PlatformData.bin

Depending on the programmer you're using, you may find that it takes some time to complete the operation. A device such as the Bus Pirate doesn't make for the faster programmer.

No comments:

Post a Comment