Read&Write BIOS Image using Dediprog SF100 SPI NOR Flash Programmer
Tags: uefi, bios, hardware, tutorial
Published: 2022-05-24 14:33:55

SPI flash stores most of the module executed by UEFI BIOS. If you want to extract actual UEFI module to take a look at, or modify some of the content, **SPI flash programmer** is a perfect solution. Moreover, some BIOS images are distributed as `.bin` file, and you can use SPI flash programmer to update BIOS with those image.


## Environment
I will be using followings in this article.
* Windows PC that has USB 3.0 port (Host PC)
* [UP Squared ATOM Quad Core 08/64 (UP2 board)](https://up-shop.org/up-squared-board-atom-x7-e3950-8gb-memory-64gb-emmc.html)
* [SF100 SPI NOR Flash Programmer (SF100)](https://www.dediprog.com/product/SF100)
* [ISP Testclip SO8 (TestClip)](https://www.dediprog.com/product/ISP-TC-8)


## Finding SPI Flash Chip and detecting Device ID
For UP2 board, you first have to take off heatsink like this.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ybt4lobtujykbhp0l23.png)
Most SPI flash chip is manufactured by [winbond](https://www.winbond.com/hq), so it is one way to find a chip that has a letter "winbond" written. In my UP2 board, it was located here. It first had a seal on so I had to take off the seal to find this.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/30u9z76dahzsej8n9ok3.png)
It's too small to look from above picture, but it says `winbond 25Q128JWSQ 2117` which we can tell that the device ID for this chip is `W25Q128JW`.


## Setup for using SF100
Download the following three items from [here](https://www.dediprog.com/product/SF100#download).
* Latest version of software for using SF100
  * I downloaded version `7.3.90.46`
* USB driver
* USB Driver User Guide for Win 8/8.1/10

You will be asked to enter your email and serial number when downloading. The serial number is written on the back of the SF100.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3afms425wuxgkvj95vfb.png)

Once downloaded, run `.msi` installer to install the software. If the following 4 app shortcuts are generated on the desktop (note that I have moved contents to a folder), then the installation is complete.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w49iesuncz1oemlhagj2.png)

After that, you have to setup the USB driver. 
Let's connect SF100 and TestClip like this.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhtcmqqeergfqcrm45mb.png)
You can referer to the "USB Driver User Guide" from now on, but here's what I did. First, connect the above to the Host PC (which you will be using for manipulating SF100) and check the device manager. It should be like this.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8yoi7l5d28mt27ehvan5.png)
Right click the above "SF100-ISP" and select "Update Driver Software...". Then follow the steps below.
1. Browse my computer for driver software
2. Let me pick from a list of device drivers on my computer
3. Click Next without selecting any
4. Click Have Disk
5. Browse and locate the USB driver we downloaded before `dediprog.inf` and click OK
6. Select "DediProg SF Programmer driver" and click Next
7. Installation will start and if nothing goes wrong, "Window has successfully updated your driver software" will be shown.
8. Again if you open device manager and see this, then it's a success
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrgl6bwgvyj4c3h761cg.png)


## Recognize SPI flash from Host PC
Now let's clip the SPI flash with the TestClip. Looking closely, you will see a dot on flash chip, and small white paintings on the TestClip. Make sure you clip it the right way, so that the white paint and the dot on the chip are in the same position.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4whnse1x5863ikpryxir.png)
After that, connect USB cable to the host PC and run the software "DediProg Engineering" which is one of the 4 shortcuts created after installation.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l06hs6lazxj1pizwiw1u.png)
If it recognized correctly, the software asks you to select SPI flash Chip ID. You have found out that the device ID was `W25Q128JW` so select that. If there's no error, then the recognition is success.


## Reading SPI flash
( The usage of SF100 software is written in "DediProg Help" which is one of the four desktop shortcuts created at installation )

To read the SPI flash content, click the `Edit` icon and then, press `Read...`. While reading, busy lamp glows orange on SF100, and the percentage of progress will be displayed on the place where `Read...` button was located.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uzwllffqiq0ueij56q6e.png)
After reading is complete, you can press `Chip Buffer to File` to save image as a `.bin` file.

After saving file, you might get an error message like `an unnamed file contains ...`, but you can ignore that. If you are not sure you've read the flash contents successfully, check if the contents start with the flash descriptor's magic byte `5A A5 F0 0F`.


##  Writing SPI flash
Click `Config` icon and select/check the following two items.
* `Download a whole file to chip (Without Blank Check)…`
* `Reload file each time`
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/az5vfuf3m8ehptd13p9g.png)
Then, press OK. There will be about two warning messages showing up, but you can ignore those. Next, click `File` icon and do the followings.
* click `Find` and select the BIOS image file you want to write in
* select `Raw Binary` and make sure you don't check `Trucate file to...`

After pressing OK, check if you have `Operation completed`. Finally, press the `Batch` icon and start flashing.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5anhhs5t2dhusuw713io.png)
You can check if flashing is over by seeing if busy lamp becomes pass. You will see this kind of log output if it succeeded.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5nyljo3x1rci70crssi1.png)
If you want to restore it, you can use the flash content file read in the previous section.


## Acknowledgement
Great thanks to [Satoshi Tanda](https://github.com/tandasat?tab=repositories) for the support and for introducing this wonderful topic.