1==================== 2Arduino flasher 3.3v 3==================== 4 5Introduction 6============ 7 8This explains how to: 9 10* Easily lower the voltage of an arduino 11* Use that arduino to flash a coreboot image on a GM45 Thinkpad with a SOIC16 chip 12 13It requires: 14 15* An AVR Arduino at 5v 16* An USB<->Serial adapter capable of providing enough current to power up: 17 18 * The arduino 19 * The flash chip 20 * The circuits around the flash chip 21 22It was tested with: 23 24* An Arduino.org "nano version 3.3" 25* A Sparkfun "FTDI Basic 3v3" (Uses an FTDI FT232R) 26 27Caveats and warnings: 28 29* It requires you to to never connect an USB cable between the Arduino USB port and the computer while the flasher is connected to a flash chip. 30 This would result in the I/O voltage being 5V instead of 3.3V. If you think you may accidentally connect it this way, this flasher isn't the right solution for you. 31* You need to read the tutorial, if you don't understand it, it's probably not for you. In doubt you could ask for some help in flashrom real-time channels 32 or on the mailing list, see :doc:`/contact`. 33* For now it requires to patch frser-duino 34 35Theory 36======== 37 38In the `Atmega328/P datasheet <https://web.archive.org/web/20181004225154/ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf>`_, 39the "32.3. Speed Grades" chapter describes (pages 368 and 369) the link between maximum frequency of the microcontroller and the voltage. At 3.3v, the maximum frequency is 12Mhz. 40 41HOWTO 42======== 43 44Build the code installing it on the arduino 45------------------------------------------- 46 47Building frser-duino 48^^^^^^^^^^^^^^^^^^^^ 49 50First download frser-duino:: 51 52 $ git clone --recursive https://github.com/urjaman/frser-duino.git 53 $ cd frser-duino 54 55Then modify the ``F_CPU`` value in ``main.h`` to be 12Mhz instead of 16Mhz. ``F_CPU`` will look like that:: 56 57 #define F_CPU 16000000UL 58 59Change it to:: 60 61 #define F_CPU 12000000UL 62 63You can then build the code:: 64 65 $ make ftdi 66 67Installing the code on the arduino 68^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 69 70Before installing the code on arduino we want to make sure that we are talking to the right device. 71To do that make sure that the arduino is not connected to your computer and run:: 72 73 $ ls -l /dev/ttyUSB0 74 75If everything went fine it will output something like that:: 76 77 ls: cannot access '/dev/ttyUSB0': No such file or directory 78 79If instead it looks like that:: 80 81 crw-rw---- 1 root uucp 188, 0 27 févr. 14:30 /dev/ttyUSB0 82 83then something else is connected to your computer at ``/dev/ttyUSB0``. If you can't figure what's going on by yourself, 84it's better to try get help on the flashrom channels to fix the issue, see :doc:`/contact`. 85 86Then connect your arduino to the computer and run the same command:: 87 88 $ ls -l /dev/ttyUSB0 89 90This time it's supposed to output a line that looks more or less like that:: 91 92 crw-rw---- 1 root uucp 188, 0 27 févr. 14:30 /dev/ttyUSB0 93 94At this point we're pretty confident that ``/dev/ttyUSB0`` corresponds to the arduino, so we can install the code with:: 95 96 $ make flash-ftdi 97 98Once it is installed we can now test that everything went fine with:: 99 100 $ flashrom -p serprog:dev=/dev/ttyUSB0:2000000 101 102This will make flashrom talk to the arduino to verify if everything is fine up to this point. 103 104If everything went fine it will look more or less like that:: 105 106 $ flashrom -p serprog:dev=/dev/ttyUSB0:2000000 107 /sys/firmware/dmi/tables/smbios_entry_point: Permission denied 108 /dev/mem: Permission denied 109 /sys/firmware/dmi/tables/smbios_entry_point: Permission denied 110 /dev/mem: Permission denied 111 flashrom v1.0 on Linux 4.15.2-gnu-1 (i686) 112 flashrom is free software, get the source code at https://flashrom.org 113 114 Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns). 115 serprog: Programmer name is "frser-duino" 116 serprog: requested mapping AT45CS1282 is incompatible: 0x1080000 bytes at 0xfef80000. 117 No EEPROM/flash device found. 118 Note: flashrom can never write if the flash chip isn't found automatically. 119 120This is the important line:: 121 122 serprog: Programmer name is "frser-duino" 123 124It means that flashrom is able to talk to the flasher, which reports itself as "frser-duino" We also have the following line:: 125 126 No EEPROM/flash device found. 127 128which tells that it didn't find any flash. This is what's supposed to happen since we didn't connect any yet. 129 130Build the programmer 131-------------------- 132 133Connect the programmer to the USB<->Serial adapter 134^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 135 136To do that: 137 138* Connect the FTDI adapter RX to the TX of the arduino 139* Connect the FTDI adapter TX to the RX of the arduino 140* Connect the 3V3 of the FTDI adapter to the 5V pin of the Arduino 141* Connect the GND of the FTDI adapter to the GDN of the arduino. 142 143Here's a summary of the above: 144 145======== ========================= 146Arduino USB<->Serial port adapter 147======== ========================= 148RX TX 149TX RX 1505v 3.3v 151GND GND 152======== ========================= 153 154You can now check that the programmer is responding with:: 155 156 flashrom -p serprog:dev=/dev/ttyUSB0:2000000 157 158Since you didn't connect yet a flash chip, it will says it found no flash chips:: 159 160 $ flashrom -p serprog:dev=/dev/ttyUSB0:2000000 161 /sys/firmware/dmi/tables/smbios_entry_point: Permission denied 162 /dev/mem: Permission denied 163 /sys/firmware/dmi/tables/smbios_entry_point: Permission denied 164 /dev/mem: Permission denied 165 flashrom v1.0 on Linux 4.15.2-gnu-1 (i686) 166 flashrom is free software, get the source code at https://flashrom.org 167 168 Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns). 169 serprog: Programmer name is "frser-duino" 170 serprog: requested mapping AT45CS1282 is incompatible: 0x1080000 bytes at 0xfef80000. 171 No EEPROM/flash device found. 172 Note: flashrom can never write if the flash chip isn't found automatically. 173 174Again like before the important parts are:: 175 176 serprog: Programmer name is "frser-duino" 177 178And:: 179 180 No EEPROM/flash device found. 181 182If you made it up to this point, you successfully built the flasher. 183 184Using the programmer 185-------------------- 186 187Connect the programmer to a flash chip 188^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 189 190Since the flasher has been built, you probably want to use it. 191 192If you use a clip (Like a SOIC-8 or SOIC16 Pomona clip), connect it to the Arduino 193Connect the chip to the clip, or if you don't use a clip, the chip to the Arduino 194Here's how to connect the flash chips to the programmer: 195 196=========== ========================== =================== ===================== 197Arduino pin Function Flash chip pin name SOIC16 Flash chip pin 198=========== ========================== =================== ===================== 199D13 CLK (Clock) CLK 16 200D12 MISO (Master In Slave Out) MISO or SO 8 201D11 MOSI (Master Out Slave In) MOSI or SI 15 202D10 CS# (Chip Select) CS# or CS OR SS 7 203GND GND (Ground) GND 10 2045V 3.3V VCC 2 2055V 3.3V WP# (Write Protect) 9 2065V 3.3V HOLD# 1 207=========== ========================== =================== ===================== 208 209Then connect an USB cable between the USB<->Serial adapter and the computer. 210Never connect the cable between the Arduino USB port and the computer while the flasher is connected to a flash chip. 211That would result in the I/O voltage being 5V instead of 3.3V. 212 213Flashing 214^^^^^^^^ 215 216Run flashrom like that:: 217 218 flashrom -p serprog:dev=/dev/ttyUSB0:2000000 219 220With some models of Macronix flash chip (that are present in the Thinkpad X200) you might need to add ``spispeed=100k`` like that:: 221 222 flashrom -p serprog:dev=/dev/ttyUSB0:2000000,spispeed=100k 223 224Thanks 225======== 226 227Thanks a lot to SwiftGeek on IRC (#libreboot on Libera) for finding the first workaround to make it detect flash chips at lower voltage. 228Thanks also for telling me about the Macronix issues on the Thinkpad X200. This project would not have been possible without that. 229 230Page license 231============ 232 233This page is available under the following licenses: 234 235* `CC-BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0/legalcode>`_ 236* `CC-BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0/legalcode>`_ or later 237* `GFDL 1.3 <https://www.gnu.org/licenses/fdl-1.3.txt>`_ or later 238