bbb_setup.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <style type="text/css">
  7. @import url('../css/main.css');
  8. </style>
  9. <title>How to program an SPI flash chip with the BeagleBone Black</title>
  10. </head>
  11. <body>
  12. <div class="section">
  13. <h1 id="pagetop">How to program an SPI flash chip with the BeagleBone Black</h1>
  14. <p>
  15. This document exists as a guide for reading from or writing to an SPI flash chip with the BeagleBone Black,
  16. using the <a href="http://flashrom.org/Flashrom">flashrom</a> software.
  17. BeagleBone Black rev. C was used when creating this guide, but earlier revisions
  18. may also work.
  19. </p>
  20. <p><a href="index.html">Back to previous index</a></p>
  21. </div>
  22. <div class="section" id="hardware_requirements">
  23. <h1>Hardware requirements</h1>
  24. <p>
  25. Shopping list (pictures of this hardware is shown later):
  26. </p>
  27. <ul>
  28. <li>
  29. External SPI programmer: <b>BeagleBone Black</b> (rev. C)
  30. is highly recommended. Sometimes referred to as 'BBB'.
  31. <a href="http://beagleboard.org/black">This page</a> contains a list of distributors.
  32. farnell sells them - <a href="http://farnell.com/">http://farnell.com/</a>
  33. - If you can't get a BBB, there are other programmers listed on flashrom.org, but
  34. not all of them will be suitable for libreboot's purpose. (some may also require blobs. all BBs and BBBs though can be used without blobs).
  35. There are also some programmers not listed on flashrom.org, that can also work.
  36. A BB (original beaglebone) should work as well, though you might have to replace the distro
  37. that it came with.
  38. </li>
  39. <li>
  40. Electrical/insulative tape: cover the entire bottom surface of the BBB (the part that
  41. rests on a surface). This is important, when placing the BBB on top of a board
  42. so that nothing shorts. - easy to find in most hardware/electronics stores
  43. </li>
  44. <li>
  45. Clip for connecting to the flash chip: if you have a SOIC-16
  46. flash chip (16 pins), you will need the <b>Pomona 5252</b>
  47. or equivalent. For SOIC-8 flash chips (8 pins), you will
  48. need the <b>Pomona 5250</b> or equivalent. Do check which chip you have,
  49. before ordering a clip. Also, make sure to buy at least two clips
  50. (they break easily).
  51. - Farnell sells these, and ships to many countries. <a href="http://farnell.com/">http://farnell.com/</a>
  52. - Some people find these difficult to get, especially in South America. If you have more links to suppliers,
  53. please contact the libreboot project with the relevant information.
  54. - <b>if you can't get a pomona clip, some other clips might work (eg 3M) but are not always reliable. You can also
  55. directly solder the wires to the chip, if that suits you. The clip is just for convenience, really.</b>
  56. </li>
  57. <li>
  58. <b>External 3.3V DC power supply</b>, for powering the flash chip.
  59. An ATX power supply / PSU (common on Intel/AMD desktop computers) will work for this.
  60. A lab PSU (DC) will also work (adjusted to 3.3V). Etc.
  61. <ul>
  62. <li>Getting a multimeter might be worthwhile, to verify that it's supplying 3.3V</li>
  63. </ul>
  64. </li>
  65. <li>
  66. <b>External 5V DC power supply</b> (barrel connector), for powering the BBB.
  67. The BeagleBone can have power supplied via USB, but a
  68. dedicated power supply is recommended. These should be easy to find in most places
  69. that sell electronics. - <b>OPTIONAL. Only needed if not powering with the USB cable, or if you want
  70. to use <a href="bbb_ehci.html">EHCI debug</a></b>
  71. </li>
  72. <li>
  73. <b>Pin header / jumper cables</b> (2.54mm / 0.1&quot; headers)
  74. You should get male-male, male-female and female-female
  75. cables in 10cm size. Just get a load of them.
  76. other possible names for these cables:
  77. <ul>
  78. <li>flying leads</li>
  79. <li>dupont (this is just one possible brand name)</li>
  80. <li>Often used on breadboards, so they might be called breadboard cables</li>
  81. <li>Maybe they are called <b>wires</b> instead of cables or leads</li>
  82. <li>They are also the same cables used on the GPIOs on the RPi</li>
  83. <li><b>adafruit.com</b> sells them, and there are others</li>
  84. <li><b>Some people find these difficult to buy. Contact the libreboot project if you have more links to sellers.</b></li>
  85. <li>You might also be able to make these cables yourself.</li>
  86. </ul>
  87. For PSU connections, long cables (e.g. 20cm) is fine, and you can extend it longer than that if needed.
  88. </li>
  89. <li>
  90. <b>Mini USB A-B cable</b> (the BeagleBone probably already comes
  91. with one.) - <b>OPTIONAL - only needed for <a href="bbb_ehci.html">EHCI debug</a> or for serial/ssh access without ethernet cable (g_multi kernel module)</b>
  92. </li>
  93. <li>
  94. <b>FTDI TTL cable or debug board</b>, for accessing the serial console on your BBB.
  95. <a href="http://elinux.org/Beagleboard:BeagleBone_Black_Serial">This page</a> contains
  96. a list. - <b>OPTIONAL - only needed for serial console on the BBB, if not using SSH via ethernet cable</b>
  97. </li>
  98. </ul>
  99. <p>
  100. <a href="#pagetop">Back to top of page.</a>
  101. </p>
  102. </div>
  103. <div class="section" id="psu33">
  104. <h1>Setting up the 3.3V DC PSU</h1>
  105. <p>
  106. ATX PSU pinouts are on <a href="https://en.wikipedia.org/wiki/Power_supply_unit_%28computer%29#Wiring_diagrams">wikipedia</a>
  107. </p>
  108. <p>
  109. You can use pin 1 or 2 (orange wire) on a 20-pin or 24-pin ATX PSU for 3.3V,
  110. and any of the ground/earth sources (black cables) for ground.
  111. Short PS_ON# / Power on (green wire. pin 16 on 24-pin ATX PSU, or pin 14 on a 20-pin ATX PSU) to a ground
  112. (black. there is one right next to it) using a wire/paperclip/jumper then
  113. power on the PSU by grounding PS_ON# (this is also how an ATX motherboard turns on a PSU).
  114. </p>
  115. <p>
  116. <b>DO **NOT** use pin 4, 6, do **NOT** use pin 19 or 20 (on a 20-pin ATX PSU), and
  117. DO **NOT** use pin 21, 22 or 23 (on a 24-pin ATX PSU). Those wires (the red ones) are 5V, and they **WILL**
  118. kill your flash chip. ***NEVER*** supply more than 3.3V to your flash chip.
  119. (that is, if it's a 3.3V flash chip. 5V and 1.8V SPI flash chips do exist, but they are rare. always
  120. check what voltage your chip takes. most take 3.3V)</b>
  121. </p>
  122. <p>
  123. You only need one 3.3V supply and one ground for the flash chip, after grounding PS_ON#.
  124. </p>
  125. <p>
  126. The male end of a 0.1&quot; or 2.54mm header cable is not thick enough to remain permanently
  127. connected to the ATX PSU on its own.
  128. When connecting header cables to the connector on the ATX PSU, use a female end attached to
  129. a thicker piece of wire (you could use a paper clip), or wedge the male end of the jumper cable
  130. into the sides of the hole in the connector, instead of going through the centre.
  131. </p>
  132. <p>
  133. Here is an example set up:<br/>
  134. <img src="images/x200/psu33.jpg" alt="" title="Copyright &copy; 2015 Patrick &quot;P. J.&quot; McDermott &lt;pj@pehjota.net&gt; see license notice at the end of this document" />
  135. </p>
  136. </div>
  137. <div class="section" id="bbb_access">
  138. <h1>Accessing the operating system on the BBB</h1>
  139. <p>
  140. The operating system on your BBB will probably have an SSH daemon
  141. running where the root account has no password. Use SSH to access
  142. the operating system and set a root password. By default, the OS
  143. on your BBB will most likely use DHCP, so it should already have an IP
  144. address.
  145. </p>
  146. <p>
  147. You will also be using the OS on your BBB for programming an SPI flash chip.
  148. </p>
  149. <h2>Alternatives to SSH (in case SSH fails)</h2>
  150. <p>
  151. You can also use a serial FTDI debug board with GNU Screen, to access the serial console.<br/>
  152. # <b>screen /dev/ttyUSB0 115200</b><br/>
  153. Here are some example photos:<br/>
  154. <img src="images/x200/ftdi.jpg" alt="" />
  155. <img src="images/x200/ftdi_port.jpg" alt="" /><br/>
  156. </p>
  157. <p>
  158. You can also connect the USB cable from the BBB to another computer and a new network interface will appear,
  159. with its own IP address. This is directly accessible from SSH, or screen:<br/>
  160. # <b>screen /dev/ttyACM0 115200</b>
  161. </p>
  162. <p>
  163. You can also access the uboot console, using the serial method
  164. instead of SSH.
  165. </p>
  166. </div>
  167. <div class="section" id="spidev">
  168. <h1>Setting up spidev on the BBB</h1>
  169. <p>
  170. Log on as root on the BBB, using either SSH or a serial console as defined in
  171. <a href="#bbb_access">#bbb_access</a>. Make sure that you have internet access
  172. on your BBB.
  173. </p>
  174. <p>
  175. Follow the instructions at <a href="http://elinux.org/BeagleBone_Black_Enable_SPIDEV#SPI0">http://elinux.org/BeagleBone_Black_Enable_SPIDEV#SPI0</a>
  176. up to (and excluding) the point where it tells you to modify uEnv.txt
  177. </p>
  178. <p>
  179. You need to update the software on the BBB first. If you have an
  180. element14 brand BBB (sold by Premier Farnell plc. stores like
  181. Farnell element14, Newark element14, and Embest), you may need
  182. to <a href="https://groups.google.com/forum/?_escaped_fragment_=msg/beagleboard/LPjCn4LEY2I/alozBGsbTJMJ#!msg/beagleboard/LPjCn4LEY2I/alozBGsbTJMJ">work around a bug</a>
  183. in the LED aging init script before you can update your
  184. software. If you don't have a file named
  185. /etc/init.d/led_aging.sh, you can skip this step and update your
  186. software as described below. Otherwise, replace the contents of
  187. this file with:
  188. </p>
  189. <pre>
  190. #!/bin/sh -e
  191. ### BEGIN INIT INFO
  192. # Provides: led_aging.sh
  193. # Required-Start: $local_fs
  194. # Required-Stop: $local_fs
  195. # Default-Start: 2 3 4 5
  196. # Default-Stop: 0 1 6
  197. # Short-Description: Start LED aging
  198. # Description: Starts LED aging (whatever that is)
  199. ### END INIT INFO
  200. x=$(/bin/ps -ef | /bin/grep "[l]ed_acc")
  201. if [ ! -n "$x" -a -x /usr/bin/led_acc ]; then
  202. /usr/bin/led_acc &amp;
  203. fi
  204. </pre>
  205. </p>
  206. Run <b>apt-get update</b> and <b>apt-get upgrade</b> then reboot the BBB, before continuing.
  207. </p>
  208. <p>
  209. Check that the firmware exists:<br/>
  210. # <b>ls /lib/firmware/BB-SPI0-01-00A0.*</b><br/>
  211. Output:
  212. </p>
  213. <pre>
  214. /lib/firmware/BB-SPI0-01-00A0.dtbo
  215. </pre>
  216. <p>
  217. Then:<br/>
  218. # <b>echo BB-SPI0-01 &gt; /sys/devices/bone_capemgr.*/slots</b><br/>
  219. # <b>cat /sys/devices/bone_capemgr.*/slots</b><br/>
  220. Output:
  221. </p>
  222. <pre>
  223. 0: 54:PF---
  224. 1: 55:PF---
  225. 2: 56:PF---
  226. 3: 57:PF---
  227. 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
  228. 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
  229. 7: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-SPI0-01
  230. </pre>
  231. <p>
  232. Verify that the spidev device now exists:<br/>
  233. # <b>ls -al /dev/spid*</b><br/>
  234. Output:
  235. </p>
  236. <pre>
  237. crw-rw---T 1 root spi 153, 0 Nov 19 21:07 /dev/spidev1.0
  238. </pre>
  239. <p>
  240. Now the BBB is ready to be used for flashing. Make this persist
  241. across reboots:<br/>
  242. In /etc/default/capemgr add <b>CAPE=BB-SPI0-01</b> at the end
  243. (or change the existing <b>CAPE=</b> entry to say that, if an
  244. entry already exists.
  245. </p>
  246. <p>
  247. Get flashrom from the libreboot_util release archive, or build it from libreboot_src/git if you need to.
  248. An ARM binary (statically compiled) for flashrom exists in libreboot_util releases. Put the flashrom binary
  249. on your BBB.
  250. </p>
  251. <p>
  252. You may also need ich9gen, if you will be flashing an ICH9-M laptop (such as the X200). Get it from libreboot_util,
  253. or build it from libreboot_src, and put the ARM binary for it on your BBB.
  254. </p>
  255. <p>
  256. Finally, get the ROM image that you would like to flash and put that on your BBB.
  257. </p>
  258. <p>
  259. Now test flashrom:<br/>
  260. # <b>./flashrom -p linux_spi:dev=/dev/spidev1.0,spispeed=512</b><br/>
  261. Output:
  262. </p>
  263. <pre>
  264. Calibrating delay loop... OK.
  265. No EEPROM/flash device found.
  266. Note: flashrom can never write if the flash chip isn't found automatically.
  267. </pre>
  268. <p>
  269. This means that it's working (the clip isn't connected to any flash chip,
  270. so the error is fine).
  271. </p>
  272. </div>
  273. <div class="section" id="clip">
  274. <h1>
  275. Connecting the Pomona 5250/5252
  276. </h1>
  277. <p>
  278. Use this image for reference when connecting the pomona to the BBB:
  279. <a href="http://beagleboard.org/Support/bone101#headers">http://beagleboard.org/Support/bone101#headers</a>
  280. (D0 = MISO or connects to MISO).
  281. </p>
  282. <p>
  283. The following shows how to connect clip to the BBB (on the P9 header), for SOIC-16 (clip: Pomona 5252):
  284. </p>
  285. <pre>
  286. NC - - 21
  287. 1 - - 17
  288. NC - - NC
  289. NC - - NC
  290. NC - - NC
  291. NC - - NC
  292. 18 - - 3.3V (PSU)
  293. 22 - - NC - this is pin 1 on the flash chip
  294. <i>This is how you will connect. Numbers refer to pin numbers on the BBB, on the plugs near the DC jack.</i>
  295. You may also need to connect pins 1 and 9 (tie to 3.3V supply). These are HOLD# and WP#.
  296. On some systems they are held high, if the flash chip is attached to the board.
  297. If you're flashing a chip that isn't connected to a board, you'll almost certainly
  298. have to connect them.
  299. SOIC16 pinout (more info available online, or in the datasheet for your flash chip):
  300. HOLD 1-16 SCK
  301. VDD 2-15 MOSI
  302. N/C 3-14 N/C
  303. N/C 4-13 N/C
  304. N/C 5-12 N/C
  305. N/C 6-11 N/C
  306. SS 7-10 GND
  307. MISO 8-9 WP
  308. </pre>
  309. <p>
  310. The following shows how to connect clip to the BBB (on the P9 header), for SOIC-8 (clip: Pomona 5250):
  311. </p>
  312. <pre>
  313. 18 - - 1
  314. 22 - - NC
  315. NC - - 21
  316. 3.3V (PSU) - - 17 - this is pin 1 on the flash chip
  317. <i>This is how you will connect. Numbers refer to pin numbers on the BBB, on the plugs near the DC jack.</i>
  318. You may also need to connect pins 3 and 7 (tie to 3.3V supply). These are HOLD# and WP#.
  319. On some systems they are held high, if the flash chip is attached to the board.
  320. If you're flashing a chip that isn't connected to a board, you'll almost certainly
  321. have to connect them.
  322. SOIC8 pinout (more info available online, or in the datasheet for your flash chip):
  323. SS 1-8 VDD
  324. MISO 2-7 HOLD
  325. WP 3-6 SCK
  326. GND 4-5 MOSI
  327. </pre>
  328. <p>
  329. <b>NC = no connection</b>
  330. </p>
  331. <p>
  332. <b><u>DO NOT</u> connect 3.3V (PSU) yet. ONLY connect this once the pomona is connected to the flash chip.</b>
  333. </p>
  334. <p>
  335. <b>You also need to connect the BLACK wire (ground/earth) from the 3.3V PSU to pin 2 on the BBB (P9 header).
  336. It is safe to install this now
  337. (that is, before you connect the pomona to the flash chip); in fact, you should.</b>
  338. </p>
  339. <p>
  340. if you need to extend the 3.3v psu leads, just use the same colour M-F leads, <b>but</b> keep all other
  341. leads short (10cm or less)
  342. </p>
  343. <p>
  344. You should now have something that looks like this:<br/>
  345. <img src="images/x200/5252_bbb0.jpg" alt="" />
  346. <img src="images/x200/5252_bbb1.jpg" alt="" />
  347. </p>
  348. <p>
  349. <a href="#pagetop">Back to top of page.</a>
  350. </p>
  351. </div>
  352. <div class="section">
  353. <h1 id="stability">Notes about stability</h1>
  354. <p>
  355. <a href="http://flashrom.org/ISP">http://flashrom.org/ISP</a>
  356. is what we typically do in libreboot, though not always. That page
  357. has some notes about using resistors to affect stability. Currently,
  358. we use spispeed=512 (512kHz) but it is possible to use higher speeds while
  359. maintaining stability.
  360. </p>
  361. <p>
  362. tty0_ in #libreboot was able to get better flashing speeds with the following configuration:
  363. </p>
  364. <ul>
  365. <li>&quot;coax&quot; with 0.1 mm core and aluminum foley (from my kitchen), add 100 Ohm resistors (serial)</li>
  366. <li>put heatshrink above the foley, for: CS, CLK, D0, D1</li>
  367. <li>Twisted pair used as core (in case more capacitors are needed)</li>
  368. <li>
  369. See this image:
  370. <a href="http://i.imgur.com/qHGxKpj.jpg">http://i.imgur.com/qHGxKpj.jpg</a>
  371. </li>
  372. <li>He was able to flash at 50MHz (lower speeds are also fine).</li>
  373. </ul>
  374. </div>
  375. <div class="section">
  376. <p>
  377. Copyright &copy; 2014, 2015 Francis Rowe &lt;info@gluglug.org.uk&gt;<br/>
  378. Copyright &copy; 2015 Patrick &quot;P. J.&quot; McDermott &lt;pj@pehjota.net&gt;<br/>
  379. Permission is granted to copy, distribute and/or modify this document
  380. under the terms of the GNU Free Documentation License, Version 1.3
  381. or any later version published by the Free Software Foundation;
  382. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
  383. A copy of the license can be found at <a href="../gfdl-1.3.txt">../gfdl-1.3.txt</a>
  384. </p>
  385. <p>
  386. Updated versions of the license (when available) can be found at
  387. <a href="https://www.gnu.org/licenses/licenses.html">https://www.gnu.org/licenses/licenses.html</a>
  388. </p>
  389. <p>
  390. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
  391. EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
  392. AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
  393. ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
  394. IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
  395. WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
  396. PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
  397. ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
  398. KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
  399. ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
  400. </p>
  401. <p>
  402. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
  403. TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
  404. NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
  405. INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
  406. COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
  407. USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
  408. ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
  409. DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
  410. IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
  411. </p>
  412. <p>
  413. The disclaimer of warranties and limitation of liability provided
  414. above shall be interpreted in a manner that, to the extent
  415. possible, most closely approximates an absolute disclaimer and
  416. waiver of all liability.
  417. </p>
  418. </div>
  419. </body>
  420. </html>