bbb_setup.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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 programme an SPI flash chip with the BeagleBone Black</title>
  10. </head>
  11. <body>
  12. <div class="section">
  13. <h1 id="pagetop">How to programme 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. </li>
  33. <li>
  34. Electrical tape: cover the entire bottom surface of the BBB (the part that
  35. rests on a surface). This is important, when placing the BBB on top of a board
  36. so that nothing shorts.
  37. </li>
  38. <li>
  39. Clip for connecting to the flash chip: if you have a SOIC-16
  40. flash chip (16 pins), you will need the <b>Pomona 5252</b>
  41. or equivalent. For SOIC-8 flash chips (8 pins), you will
  42. need the <b>Pomona 5250</b> or equivalent. Do check which chip you have,
  43. before ordering a clip. Also, make sure to buy at least two clips
  44. (they break easily).
  45. </li>
  46. <li>
  47. <b>External 3.3V DC power supply</b>, for powering the flash chip.
  48. An ATX power supply / PSU (common on Intel/AMD desktop computers) will work for this.
  49. </li>
  50. <li>
  51. <b>External 5V DC power supply</b> (barrel connector), for powering the BBB.
  52. The BeagleBone can have power supplied via USB, but a
  53. dedicated power supply is recommended.
  54. </li>
  55. <li>
  56. <b>Pin header / jumper cables</b> (2.54mm / 0.1&quot; headers)
  57. You should get male-male, male-female and female-female
  58. cables in 10cm and 20cm sizes. Just get a load of them.
  59. other possible names for these cables:
  60. <ul>
  61. <li>flying leads</li>
  62. <li>dupont (this is just one possible brand name)</li>
  63. <li>Often used on breadboards, so they might be called breadboard cables</li>
  64. <li>Maybe they are called <b>wires</b> instead of cables or leads</li>
  65. </ul>
  66. </li>
  67. <li>
  68. <b>Mini USB A-B cable</b> (the BeagleBone probably already comes
  69. with one.)
  70. </li>
  71. <li>
  72. <b>FTDI TTL cable or debug board</b>, for accessing the serial console on your BBB.
  73. <a href="http://elinux.org/Beagleboard:BeagleBone_Black_Serial">This page</a> contains
  74. a list.
  75. </li>
  76. </ul>
  77. <p>
  78. <a href="#pagetop">Back to top of page.</a>
  79. </p>
  80. </div>
  81. <div class="section" id="psu33">
  82. <h1>Setting up the 3.3V DC PSU</h1>
  83. <p>
  84. ATX PSU pinouts are on <a href="https://en.wikipedia.org/wiki/Power_supply_unit_%28computer%29#Wiring_diagrams">wikipedia</a>
  85. </p>
  86. <p>
  87. You can use pin 1 or 2 (orange wire) on a 20-pin or 24-pin ATX PSU for 3.3V,
  88. and any of the ground/earth sources (black cables) for ground.
  89. 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
  90. (black. there is one right next to it) using a wire/paperclip/jumper then
  91. power on the PSU by grounding PS_ON# (this is also how an ATX motherboard turns on a PSU).
  92. </p>
  93. <p>
  94. <b>DO **NOT** use pin 4, 6, do **NOT** use pin 19 or 20 (on a 20-pin ATX PSU), and
  95. DO **NOT** use pin 21, 22 or 23 (on a 24-pin ATX PSU). Those wires (the red ones) are 5V, and they **WILL**
  96. kill your flash chip. ***NEVER*** supply more than 3.3V to your flash chip.
  97. (that is, if it's a 3.3V flash chip. 5V and 1.8V SPI flash chips do exist, but they are rare. always
  98. check what voltage your chip takes. most take 3.3V)</b>
  99. </p>
  100. <p>
  101. You only need one 3.3V supply and one ground for the flash chip, after grounding PS_ON#.
  102. </p>
  103. <p>
  104. The male end of a 0.1&quot; or 2.54mm header cable is not thick enough to remain permanently
  105. connected to the ATX PSU on its own.
  106. When connecting header cables to the connector on the ATX PSU, use a female end attached to
  107. a thicker piece of wire (you could use a paper clip), or wedge the male end of the jumper cable
  108. into the sides of the hole in the connector, instead of going through the centre.
  109. </p>
  110. <p>
  111. Here is an example set up:<br/>
  112. <img src="images/x200/psu33.jpg" alt="" title="Copyright &copy; 2015 Patrick &quot;P. J.&quot; McDermott &lt;pj@pehjota.net&gt; CC BY-SA 3.0 or later" />
  113. </p>
  114. </div>
  115. <div class="section" id="bbb_access">
  116. <h1>Accessing the operating system on the BBB</h1>
  117. <p>
  118. The operating system on your BBB will probably have an SSH daemon
  119. running where the root account has no password. Use SSH to access
  120. the operating system and set a root password. By default, the OS
  121. on your BBB will most likely use DHCP, so it should already have an IP
  122. address.
  123. </p>
  124. <p>
  125. You will also be using the OS on your BBB for programming an SPI flash chip.
  126. </p>
  127. <h2>Alternatives to SSH (in case SSH fails)</h2>
  128. <p>
  129. You can also use a serial FTDI debug board with GNU Screen, to access the serial console.<br/>
  130. # <b>screen /dev/ttyUSB0 115200</b><br/>
  131. Here are some example photos:<br/>
  132. <img src="images/x200/ftdi.jpg" alt="" />
  133. <img src="images/x200/ftdi_port.jpg" alt="" /><br/>
  134. </p>
  135. <p>
  136. You can also connect the USB cable from the BBB to another computer and a new network interface will appear,
  137. with its own IP address. This is directly accessible from SSH, or screen:<br/>
  138. # <b>screen /dev/ttyACM0 115200</b>
  139. </p>
  140. <p>
  141. You can also access the uboot console, using the serial method
  142. instead of SSH.
  143. </p>
  144. </div>
  145. <div class="section" id="spidev">
  146. <h1>Setting up spidev on the BBB</h1>
  147. <p>
  148. Log on as root on the BBB, using either SSH or a serial console as defined in
  149. <a href="#bbb_access">#bbb_access</a>. Make sure that you have internet access
  150. on your BBB.
  151. </p>
  152. <p>
  153. Follow the instructions at <a href="http://elinux.org/BeagleBone_Black_Enable_SPIDEV#SPI0">http://elinux.org/BeagleBone_Black_Enable_SPIDEV#SPI0</a>
  154. up to (and excluding) the point where it tells you to modify uEnv.txt
  155. </p>
  156. <p>
  157. You need to update the software on the BBB first. If you have an
  158. element14 brand BBB (sold by Premier Farnell plc. stores like
  159. Farnell element14, Newark element14, and Embest), you may need
  160. to <a href="https://groups.google.com/forum/?_escaped_fragment_=msg/beagleboard/LPjCn4LEY2I/alozBGsbTJMJ#!msg/beagleboard/LPjCn4LEY2I/alozBGsbTJMJ">work around a bug</a>
  161. in the LED aging init script before you can update your
  162. software. If you don't have a file named
  163. /etc/init.d/led_aging.sh, you can skip this step and update your
  164. software as described below. Otherwise, replace the contents of
  165. this file with:
  166. </p>
  167. <pre>
  168. #!/bin/sh -e
  169. ### BEGIN INIT INFO
  170. # Provides: led_aging.sh
  171. # Required-Start: $local_fs
  172. # Required-Stop: $local_fs
  173. # Default-Start: 2 3 4 5
  174. # Default-Stop: 0 1 6
  175. # Short-Description: Start LED aging
  176. # Description: Starts LED aging (whatever that is)
  177. ### END INIT INFO
  178. x=$(/bin/ps -ef | /bin/grep "[l]ed_acc")
  179. if [ ! -n "$x" -a -x /usr/bin/led_acc ]; then
  180. /usr/bin/led_acc &amp;
  181. fi
  182. </pre>
  183. </p>
  184. Run <b>apt-get update</b> and <b>apt-get upgrade</b> then reboot the BBB, before continuing.
  185. </p>
  186. <p>
  187. Check that the firmware exists:<br/>
  188. # <b>ls /lib/firmware/BB-SPI0-01-00A0.*</b><br/>
  189. Output:
  190. </p>
  191. <pre>
  192. /lib/firmware/BB-SPI0-01-00A0.dtbo
  193. </pre>
  194. <p>
  195. Then:<br/>
  196. # <b>echo BB-SPI0-01 &gt; /sys/devices/bone_capemgr.*/slots</b><br/>
  197. # <b>cat /sys/devices/bone_capemgr.*/slots</b><br/>
  198. Output:
  199. </p>
  200. <pre>
  201. 0: 54:PF---
  202. 1: 55:PF---
  203. 2: 56:PF---
  204. 3: 57:PF---
  205. 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
  206. 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
  207. 7: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-SPI0-01
  208. </pre>
  209. <p>
  210. Verify that the spidev device now exists:<br/>
  211. # <b>ls -al /dev/spid*</b><br/>
  212. Output:
  213. </p>
  214. <pre>
  215. crw-rw---T 1 root spi 153, 0 Nov 19 21:07 /dev/spidev1.0
  216. </pre>
  217. <p>
  218. Now the BBB is ready to be used for flashing. Make this persist
  219. across reboots:<br/>
  220. In /etc/default/capemgr add <b>CAPE=BB-SPI0-01</b> at the end
  221. (or change the existing <b>CAPE=</b> entry to say that, if an
  222. entry already exists.
  223. </p>
  224. <p>
  225. Get flashrom from the libreboot_util release archive, or build it from libreboot_src/git if you need to.
  226. An ARM binary (statically compiled) for flashrom exists in libreboot_util releases. Put the flashrom binary
  227. on your BBB.
  228. </p>
  229. <p>
  230. You may also need ich9gen, if you will be flashing an ICH9-M laptop (such as the X200). Get it from libreboot_util,
  231. or build it from libreboot_src, and put the ARM binary for it on your BBB.
  232. </p>
  233. <p>
  234. Finally, get the ROM image that you would like to flash and put that on your BBB.
  235. </p>
  236. <p>
  237. Now test flashrom:<br/>
  238. # <b>./flashrom -p linux_spi:dev=/dev/spidev1.0,spispeed=512</b><br/>
  239. Output:
  240. </p>
  241. <pre>
  242. Calibrating delay loop... OK.
  243. No EEPROM/flash device found.
  244. Note: flashrom can never write if the flash chip isn't found automatically.
  245. </pre>
  246. <p>
  247. This means that it's working (the clip isn't connected to any flash chip,
  248. so the error is fine).
  249. </p>
  250. </div>
  251. <div class="section" id="clip">
  252. <h1>
  253. Connecting the Pomona 5250/5252
  254. </h1>
  255. <p>
  256. Use this image for reference when connecting the pomona to the BBB:
  257. <a href="http://beagleboard.org/Support/bone101#headers">http://beagleboard.org/Support/bone101#headers</a>
  258. (D0 = MISO or connects to MISO).
  259. </p>
  260. <p>
  261. The following shows how to connect clip to the BBB (on the P9 header), for SOIC-16 (clip: Pomona 5252):
  262. </p>
  263. <pre>
  264. NC - - 21
  265. 1 - - 17
  266. NC - - NC
  267. NC - - NC
  268. NC - - NC
  269. NC - - NC
  270. 18 - - 3.3V (PSU)
  271. 22 - - NC - this is pin 1 on the flash chip
  272. <i>This is how you will connect. Numbers refer to pin numbers on the BBB, on the plugs near the DC jack.</i>
  273. You may also need to connect pins 1 and 9 (tie to 3.3V supply). These are HOLD# and WP#.
  274. On some systems they are held high, if the flash chip is attached to the board.
  275. If you're flashing a chip that isn't connected to a board, you'll almost certainly
  276. have to connect them.
  277. SOIC16 pinout (more info available online, or in the datasheet for your flash chip):
  278. HOLD 1-16 SCK
  279. VDD 2-15 MOSI
  280. N/C 3-14 N/C
  281. N/C 4-13 N/C
  282. N/C 5-12 N/C
  283. N/C 6-11 N/C
  284. SS 7-10 GND
  285. MISO 8-9 WP
  286. </pre>
  287. <p>
  288. The following shows how to connect clip to the BBB (on the P9 header), for SOIC-8 (clip: Pomona 5250):
  289. </p>
  290. <pre>
  291. 18 - - 1
  292. 22 - - NC
  293. NC - - 21
  294. 3.3V (PSU) - - 17 - this is pin 1 on the flash chip
  295. <i>This is how you will connect. Numbers refer to pin numbers on the BBB, on the plugs near the DC jack.</i>
  296. You may also need to connect pins 3 and 7 (tie to 3.3V supply). These are HOLD# and WP#.
  297. On some systems they are held high, if the flash chip is attached to the board.
  298. If you're flashing a chip that isn't connected to a board, you'll almost certainly
  299. have to connect them.
  300. SOIC8 pinout (more info available online, or in the datasheet for your flash chip):
  301. SS 1-8 VDD
  302. MISO 2-7 HOLD
  303. WP 3-6 SCK
  304. GND 4-5 MOSI
  305. </pre>
  306. <p>
  307. <b>NC = no connection</b>
  308. </p>
  309. <p>
  310. <b><u>DO NOT</u> connect 3.3V (PSU) yet. ONLY connect this once the pomona is connected to the flash chip.</b>
  311. </p>
  312. <p>
  313. <b>You also need to connect the BLACK wire (ground/earth) from the 3.3V PSU to pin 2 on the BBB (P9 header).
  314. It is safe to install this now
  315. (that is, before you connect the pomona to the flash chip); in fact, you should.</b>
  316. </p>
  317. <p>
  318. if you need to extend the 3.3v psu leads, just use the same colour M-F leads, <b>but</b> keep all other
  319. leads short (10cm or less)
  320. </p>
  321. <p>
  322. You should now have something that looks like this:<br/>
  323. <img src="images/x200/5252_bbb0.jpg" alt="" />
  324. <img src="images/x200/5252_bbb1.jpg" alt="" />
  325. </p>
  326. <p>
  327. <a href="#pagetop">Back to top of page.</a>
  328. </p>
  329. </div>
  330. <div class="section">
  331. <h1 id="stability">Notes about stability</h1>
  332. <p>
  333. <a href="http://flashrom.org/ISP">http://flashrom.org/ISP</a>
  334. is what we typically do in libreboot, though not always. That page
  335. has some notes about using resistors to affect stability. Currently,
  336. we use spispeed=512 but it is possible to use higher speeds while
  337. maintaining stability.
  338. </p>
  339. <p>
  340. tty0_ in #libreboot was able to get better flashing speeds with the following configuration:
  341. </p>
  342. <ul>
  343. <li>&quot;coax&quot; with 0.1 mm core and aluminum foley (from my kitchen), add 100 Ohm resistors (serial)</li>
  344. <li>put heatstrink above the foley, for: CS, CLK, D0, D1</li>
  345. <li>Twisted pair used as core (in case more capacitors are needed)</li>
  346. <li>
  347. See this image:
  348. <a href="http://i.imgur.com/qHGxKpj.jpg">http://i.imgur.com/qHGxKpj.jpg</a>
  349. </li>
  350. <li>He was able to flash at 50MHz (lower speeds are also fine).</li>
  351. </ul>
  352. </div>
  353. <div class="section">
  354. <h1>EHCI debugging</h1>
  355. <ol class="toc">
  356. <li><a href="#FindUSBportonthetargetthatsupportsEHCIdebug">Find
  357. USB port on the target that supports EHCI debug</a></li>
  358. <li><a href="#InitialsetupofBBBtoactasEHCIdebugdongle">Initial
  359. setup of BBB to act as EHCI debug dongle</a></li>
  360. <li><a href="#PatchBBBsgdbgpmoduleoptionalbuthighlyrecommended">Patch
  361. BBB's <tt>g_dbgp</tt> module (optional, but highly recommended)</a></li>
  362. <li><a href="#ConfigurelibrebootwithEHCIdebug">Configure
  363. libreboot with EHCI debug</a>
  364. <ol>
  365. <li><a href="#SelectingHCDIndexandUSBDebugport">Selecting
  366. <tt>HCD Index</tt> and <tt>USB Debug port</tt></a></li>
  367. </ol></li>
  368. <li><a href="#Howtogetthedebuglogs">How to get the debug
  369. logs</a></li>
  370. <li><a
  371. href="#EnebleEHCIDebugonthetargetskerneloptionalrecommended">Eneble
  372. EHCI Debug on the target's kernel (optional, recommended)</a></li>
  373. <li><a href="#References">References</a></li>
  374. </ol>
  375. <p>If your computer does not boot after installing libreboot, it is
  376. very useful to get debug logs from it, from the payload (grub) and/or
  377. the kernel (if gets to there). All of them stream debug logs on the
  378. available serial (RS-232) by default. However, most of todays laptops
  379. lack RS-232 port. The other option is to stream the logs to USB EHCI
  380. debug port.</p>
  381. <p>This section explains step-by-step how to setup BBB as a
  382. &#8220;USB EHCI debug dongle&#8221; and configure libreboot and the
  383. linux kernel to stream logs to it (TODO: grub).</p>
  384. <p>I will refer to three computers:</p>
  385. <ul>
  386. <li><b>host</b> - this is the computer you use, have
  387. tools, compiler, Internet, etc</li>
  388. <li><b>BBB</b> - Beaglebone Black (rev. B or higher, i
  389. use rev. C)</li>
  390. <li><b>target</b> - the computer you are trying to
  391. install liberboot</li>
  392. </ul>
  393. <h3 id="FindUSBportonthetargetthatsupportsEHCIdebug">Find USB port
  394. on the target that supports EHCI debug</h3>
  395. <p>
  396. Not all USB controllers support EHCI debug (see: <a
  397. href="http://www.coreboot.org/EHCI_Debug_Port#Hardware_capability">EHCI
  398. Debug Port</a> ). Even more, if a USB controller supports EHCI debug, it
  399. is available only <b>on a single port</b> that might or might
  400. not be exposed externally.
  401. </p>
  402. <ul>
  403. <li>You need running OS (GNU/Linux) on your target for this step
  404. (If you&#8217;ve flashed libreboot and it does not boot, you have to
  405. flush back the stock bios)</li>
  406. <li>You need USB memory stick (the data on it will not be
  407. touched).</li>
  408. <li>The EHCI debugging can not be done through external hub, BBB
  409. must be connected directly to the debug port of the controller (so, no
  410. hubs)</li>
  411. </ul>
  412. <ul>
  413. <li>Download<sup class="footnote"><a href="#___fn1">1</a></sup> <a
  414. href="http://www.coreboot.org/pipermail/coreboot/attachments/20080909/ae11c291/attachment.sh">this</a>
  415. shell script.
  416. </li>
  417. </ul>
  418. <ol>
  419. <li>Plug the usb stick in the first available usb port</li>
  420. <li>Run the script, you will get output similar to following:</li>
  421. <pre>The following PCI devices support a USB debug port (says lspci): 0000:00:1a.0 0000:00:1d.0
  422. The following PCI devices support a USB debug port (says the kernel): 0000:00:1a.0 0000:00:1d.0
  423. *PCI device 0000:00:1a.0, USB bus 3, USB physical port 1*
  424. *PCI device 0000:00:1d.0, USB bus 4, USB physical port 2*
  425. Currently connected high-speed devices:
  426. /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
  427. |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
  428. |__ Port 7: Dev 14, If 0, Class=Hub, Driver=hub/4p, 480M
  429. |__ Port 1: Dev 15, If 0, Class=Hub, Driver=hub/4p, 480M
  430. |__ Port 3: Dev 17, If 0, Class=Hub, Driver=hub/2p, 480M
  431. |__ Port 4: Dev 18, If 0, Class=Hub, Driver=hub/4p, 480M
  432. /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
  433. |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
  434. /: *Bus 01*.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
  435. |__ *Port 3: Dev 31, If 0, Class=Mass Storage, Driver=usb-storage, 480M*
  436. </pre>
  437. <li>The buses the support debug are Bus 3 (0000:00:1a.0) on Port 1
  438. and Bus 4 (0000:00:1d.0) on port 2. Your usb stick is plugged on Bus
  439. 1, Port 3</li>
  440. <li>Repeat the steps, plugging the USB stick in the next available
  441. port</li>
  442. <li>Go through all available ports and remember(write down) those
  443. for which bus/port of the usb stick matches one of the bus/port that
  444. support debug (bold).</li>
  445. </ol>
  446. <p>Remember (write down) for each port (external plug) you found
  447. that supports debug: <b>PCI device id, the bus id, the port number, and
  448. the physical location of the usb plug.</b></p>
  449. <p>If you do not find a match, you can not get debug over EHCI.
  450. Sorry.</p>
  451. <p id="___fn1" class="footnote">
  452. <sup>1</sup> The guys from coreboot were talking about including the
  453. script in coreboot distribution (check the status).
  454. </p>
  455. <h3 id="InitialsetupofBBBtoactasEHCIdebugdongle">Initial setup of
  456. BBB to act as EHCI debug dongle</h3>
  457. <p>BBB must be powered with a barrel power connector since the
  458. mini-B USB plug will be used for the EHCI debug stream. So you will
  459. need:</p>
  460. <ul>
  461. <li>power supply (5V, 2A(10W) is sufficient).</li>
  462. <li>an extra usb cable: A to mini-B</li>
  463. </ul>
  464. <p>
  465. (On BBB) The linux kernel includes module (g_dbgp that enables one of the usb ports on a computer to behave as EHCI
  466. debug dongle. Make sure you have this module available on your BBB
  467. (Debian 7.8 that comes with BBB should have it), if not, you should
  468. compile it yourself (see next section):
  469. </p>
  470. <pre>ls /lib/modules/3.8.13-bone70/kernel/drivers/usb/gadget/g_dbgp.ko</pre>
  471. <p>
  472. Unload all other
  473. g_*
  474. modules:
  475. </p>
  476. <pre># lsmod
  477. # rmmod g_multi
  478. ...
  479. </pre>
  480. <p>
  481. Then load
  482. g_dbgp
  483. :
  484. </p>
  485. <pre># modprobe g_dbgp
  486. # lsmod # should show that g_dbgp is loaded, and no other g_*
  487. </pre>
  488. <p>
  489. Plug the mini-B side of the USB cable in your BBB and the A side in
  490. your target. Then one of the usb devices on your target (with
  491. lsusb
  492. ) should be:
  493. </p>
  494. <pre>Bus 001 Device 024: ID 0525:c0de Netchip Technology, Inc.</pre>
  495. <p>If you see the device on the target, you are good to continue to
  496. the next step.</p>
  497. <h3 id="PatchBBBsgdbgpmoduleoptionalbuthighlyrecommended">
  498. Patch BBB&#8217;s
  499. g_dbgp
  500. module (optional, but highly recommended)
  501. </h3>
  502. <p>
  503. For the reasons why you need this, see: <a
  504. href="http://www.coreboot.org/EHCI_Gadget_Debug">EHCI Gadget Debug</a>.<br />Make
  505. sure that you have cross compiling environment for
  506. arm-linux-gnueabihf
  507. setup on your <em>host</em>.
  508. </p>
  509. <ul>
  510. <li>On BBB: uname -r - this will give you version
  511. number like 3.8.13-bone70 (I will refer to this as: $mav.$miv-$lv:
  512. where mav=3.8, miv=13, lv=bone70
  513. </li>
  514. <li>Get the BBB kernel ready on your host for cross-compiling:</li>
  515. </ul>
  516. <pre>$ cd $work_dir
  517. $ git clone https://github.com/beagleboard/kernel.git
  518. $ cd kernel
  519. $ git checkout $mav (see above)
  520. $ ./patch.sh
  521. $ wget http://arago-project.org/git/projects/?p=am33x-cm3.git\;a=blob_plain\;f=bin/am335x-pm-firmware.bin\;hb=HEAD -O kernel/firmware/am335x-pm-firmware.bin
  522. $ cp configs/beaglebone kernel/arch/arm/configs/beaglebone_defconfig
  523. </pre>
  524. <ul>
  525. <li>Download the patch from <a
  526. href="http://www.coreboot.org/images/8/88/Ehci-debug-gadget-patches.tar.gz">here</a></li>
  527. <li>tar -xf Ehci-debug-gadget-patches.tar.gz (will
  528. create dir: usbdebug-gadget)</li>
  529. <li>Note that there are two patches (patch_1 and patch_2) for each
  530. of the two different version of the kernel (3.8 and 3.10). I will use
  531. 3.8. (If using kernel 3.12 patch_1 is not needed)</li>
  532. <li>cd kernel (note that this is one more level: you
  533. should be in $work_dir/kernel/kernel)</li>
  534. <li>Apply the patches:</li>
  535. </ul>
  536. <pre>
  537. git apply ../usbdebug-gadget/v3.8-debug-gadget/0001-usb-dbgp-gadget-Fix-re-connecting-after-USB-disconne.patch
  538. git apply ../usbdebug-gadget/v3.8-debug-gadget/0002-usb-serial-gadget-no-TTY-hangup-on-USB-disconnect-WI.patch
  539. ;
  540. make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- beaglebone_defconfig -j4@
  541. </pre>
  542. <ul>
  543. <li>
  544. You should also apply the linux-libre <i>deblob</i> script to turn it into linux-libre
  545. (deletes all the blobs from the linux kernel).
  546. <a href="http://www.fsfla.org/ikiwiki/selibre/linux-libre/">fsfla website</a>
  547. - see <a href="http://www.fsfla.org/svn/fsfla/software/linux-libre/scripts/">scripts</a>.
  548. </li>
  549. <li>Get your current BBB kernel config (from: /boot/config-&lt;ver&gt;)
  550. and copy it to your host as $work_dir/kernel/kernel/.config</li>
  551. <pre>
  552. make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- oldconfig - all default answers</pre>
  553. <li>Set proper version number:
  554. <ul>
  555. <li>On your host, edit $work_dir/kernel/kernel/.config
  556. (the one you&#8217;ve just copied from BBB), find the line CONFIG_LOCALVERSION="&lt;something
  557. or empty&gt;" and change it to CONFIG_LOCALVERSION="-$lv",
  558. so it will look something like: CONFIG_LOCALVERSION="-bone70"</li>
  559. </ul>
  560. </li>
  561. <li>Also, make sure that: CONFIG_USB_G_DBGP=m (If
  562. not, make menuconfig, and set @Device Drivers-&gt; USB
  563. Support -&gt; USB Gadget Support -&gt; EHCI Debug Device Gadget=m</li>
  564. <li>Build the module:</li>
  565. </ul>
  566. <pre>
  567. $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 (is it possoble to build only the gadget modules)
  568. $ mkdir ../tmp &amp;&amp; make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../tmp modules_install
  569. </pre>
  570. <ul>
  571. <li>on BBB, backup /lib/modules/3.8.13-bone70/kernel/drivers/usb/gadget
  572. (i.e. mv
  573. /lib/modules/3.8.13-bone70/kernel/drivers/usb/gadget $HOME)
  574. </li>
  575. <li>copy the freshly compiled usb/gadget dir to /lib/modules/3.8.13-bone70/kernel/drivers/usb</li>
  576. <li>restart BBB</li>
  577. <li>Remove all g_* modules (rmmod
  578. g_&lt;&gt;)
  579. </li>
  580. <li>modprobpe g_dbgp</li>
  581. </ul>
  582. <h3 id="ConfigurelibrebootwithEHCIdebug">Configure libreboot with
  583. EHCI debug</h3>
  584. <p>
  585. Libreboot(coreboot) should be configured with debug turned on and to
  586. push debug messages to the EHCI debug port.<br />If you&#8217;ve
  587. downloaded the binary distribution, you can check if it is properly
  588. configured in the following way:
  589. </p>
  590. <ul>
  591. <li>Go to the libreboot dist root directory cd
  592. $libreboot_bin</li>
  593. <li>Locate the rom image for your target (I will call it: $img_path)
  594. </li>
  595. <li>Running the following command will extract the config in a
  596. file ./my_config:
  597. </li>
  598. </ul>
  599. <pre>
  600. ./cbfstool/i686/cbfstool $img_path extract -n config -f ./my_config
  601. </pre>
  602. <ul>
  603. <li>Make sure that the following params in the config are set as
  604. following:</li>
  605. </ul>
  606. <pre>
  607. CONFIG_USBDEBUG=y (Generic Drivers -&gt; USB 2.0 EHCI debug dongle support)
  608. CONFIG_USBDEBUG_IN_ROMSTAGE=y (Generic Drivers -&gt; Enable early (pre-RAM) usbdebug)
  609. CONFIG_USBDEBUG_HCD_INDEX=&lt;HCD Index of usb controller - see below&gt; (Generic Drivers -&gt; Index for EHCI controller to use with usbdebug)
  610. CONFIG_USBDEBUG_DEFAULT_PORT=&lt;USB Debug port - see below&gt; (Generic Drivers -&gt; Default USB port to use as Debug Port)
  611. </pre>
  612. <p>
  613. The following three are behind radio button in the menu. Only the first
  614. one<sup class="footnote"><a href="#___fn2">2</a></sup> should be = y
  615. </p>
  616. <pre>
  617. USBDEBUG_DONGLE_STD=y (Generic Drivers -&gt; Type of dongle (Net20DC or compatible) -&gt; Net20DC or compatible)
  618. CONFIG_USBDEBUG_DONGLE_BEAGLEBONE=n (Generic Drivers -&gt; Type of dongle (Net20DC or compatible) -&gt; BeagleBone)
  619. CONFIG_USBDEBUG_DONGLE_BEAGLEBONE_BLACK=n (Generic Drivers -&gt; Type of dongle (Net20DC or compatible) -&gt; BeagleBone Black)
  620. </pre>
  621. <p id="___fn2" class="footnote">
  622. <sup>2</sup> The g_dbgp module on BeagleBone Black (Rev. C) reports it self as Net20DC, the
  623. other options are for older BB(B) - ver1. This is documented <a
  624. href="https://johnlewis.ie/coreboot-ehci-debug-gadget-demonstration/">here</a>
  625. (also tested/verified).
  626. </p>
  627. <p>
  628. Then:<br />
  629. <pre>
  630. CONFIG_CONSOLE_USB=y (Console -&gt; USB dongle console output)
  631. </pre>
  632. </p>
  633. <p>
  634. Also
  635. Debugging ---&gt; Output verbose XYZ
  636. ) (<b>FIXME</b> somebody verify these):
  637. </p>
  638. <pre>
  639. CONFIG_DEBUG_CBFS=y (Output verbose CBFS debug messages )
  640. CONFIG_HAVE_DEBUG_RAM_SETUP=y (??? What/where is this)
  641. CONFIG_DEBUG_RAM_SETUP=y (Output verbose RAM init debug messages)
  642. CONFIG_DEBUG_SMI=y (Output verbose SMI debug messages)
  643. CONFIG_DEBUG_ACPI=y (Output verbose ACPI debug messages )
  644. CONFIG_DEBUG_USBDEBUG=y (Output verbose USB 2.0 EHCI debug dongle messages)
  645. </pre>
  646. <p>If some of the above mentioned configuration options are not as
  647. specified, you have to configure and compile libreboot yourself. Please
  648. refer to the doc(<b>FIXME: link</b> about compiling libreboot.</p>
  649. <h4 id="SelectingHCDIndexandUSBDebugport">
  650. Selecting
  651. HCD Index
  652. and
  653. USB Debug port
  654. </h4>
  655. <p>
  656. This applies (and works) only if the USB controller that supports debug
  657. (found in the first section) is from Intel.<br />If the PCI ID of the
  658. port you found in the first section is
  659. 0000:00:1a.0
  660. or
  661. 0000:00:1d.0
  662. , you are ok. Otherwise you have to try without guarantee that will
  663. work.
  664. </p>
  665. <p>
  666. If the externally exposed port is on a bus with
  667. PCI ID == 0000:00:1a.0
  668. then for
  669. CONFIG_USBDEBUG_HCD_INDEX
  670. choose 2, otherwise choose 0
  671. .
  672. </p>
  673. <p>
  674. For
  675. CONFIG_USBDEBUG_DEFAULT_PORT
  676. choose the port from the first section that correspond to the
  677. PCI ID
  678. </p>
  679. <p>
  680. Notes:<br />The above is based on the implementation of
  681. coreboot/src/southbridge/intel/common/usb_debug.c : pci_ehci_dbg_dev()
  682. .<br />This is enough as it applies for the supported GM45/G45
  683. Thinkpads. coreboot support some other contollers too, but they are
  684. irellevent for libreboot (for now).
  685. </p>
  686. <ul>
  687. <li>On T500 (with switchable GPU) the debug ports for both intel
  688. controllers is exposed.</li>
  689. <li>On x200t the debug ports for both intel controllers is
  690. exposed.</li>
  691. </ul>
  692. <h3 id="Howtogetthedebuglogs">How to get the debug logs</h3>
  693. <ul>
  694. <li>Plug the USB cable in the target&#8217;s debug port (the one
  695. you found in step 1) and BBB&#8217;s mini-B USB</li>
  696. <li>Make sure no other then g_dbgp of the g_*
  697. modules is loaded on your BBB
  698. </li>
  699. <li>On the BBB:</li>
  700. </ul>
  701. <pre>
  702. stty -icrnl -inlcr -F /dev/ttyGS0
  703. cat /dev/ttyGS0
  704. </pre>
  705. <ul>
  706. <li>Power on the target with libreboot</li>
  707. <li>You should see debug logs comming on your BBB console</li>
  708. </ul>
  709. <p>
  710. Note that this is not permanent on BBB, if you reboot it, you have to
  711. rmmod g_*
  712. and
  713. modprobe g_dbgp
  714. </p>
  715. <h3 id="EnebleEHCIDebugonthetargetskerneloptionalrecommended">Eneble
  716. EHCI Debug on the target&#8217;s kernel (optional, recommended)</h3>
  717. <p>You have to know how to compile kernel for your target.</p>
  718. <ol>
  719. <li>Check if early debugging is already enabled: grep
  720. CONFIG_EARLY_PRINTK_DBGP /boot/config-&lt;ver&gt;</li>
  721. <li>If enabled, you do not have to compile the kernel (skip this
  722. step). Otherwise, prepare kernel source for your distribution and
  723. select (Kernel hacking -&gt; Early printk via EHCI debug
  724. port). Compile and install the new kernel.
  725. </li>
  726. <li>Edit your grub configuration and add following to the kenel
  727. parameters<sup class="footnote"><a href="#___fn20">20</a></sup><sup
  728. class="footnote"><a href="#___fn21">21</a></sup>: earlyprintk=dbgp,keep.
  729. Also, try: earlyprintk=dbgp&lt;N&gt;,keep where N
  730. is the debug port id if the first does not work.
  731. </li>
  732. </ol>
  733. <h3 id="References">References</h3>
  734. <p id="___fn10" class="footnote">
  735. <sup>10</sup> <a href="http://www.coreboot.org/EHCI_Debug_Port">EHCI
  736. Debug Port</a>
  737. </p>
  738. <p id="___fn11" class="footnote">
  739. <sup>11</sup> <a
  740. href="https://johnlewis.ie/coreboot-ehci-debug-gadget-demonstration/">coreboot
  741. EHCI debug gadget demonstration</a>
  742. </p>
  743. <p id="___fn12" class="footnote">
  744. <sup>12</sup> <a href="http://www.coreboot.org/EHCI_Gadget_Debug">EHCI
  745. Gadget Debug</a>
  746. </p>
  747. <p id="___fn13" class="footnote">
  748. <sup>13</sup> <a
  749. href="http://www.coreboot.org/images/8/88/Ehci-debug-gadget-patches.tar.gz">Ehci-debug-gadget-patches.tar.gz</a>
  750. </p>
  751. <p id="___fn14" class="footnote">
  752. <sup>14</sup> <a
  753. href="http://wiki.beyondlogic.org/index.php/BeagleBoneBlack_Building_Kernel">Compiling
  754. the BeagleBone Black Kernel</a>
  755. </p>
  756. <p id="___fn15" class="footnote">
  757. <sup>15</sup>
  758. http://dumb-looks-free.blogspot.ca/2014/06/beaglebone-black-bbb-compile-kernel.html
  759. </p>
  760. <p id="___fn16" class="footnote">
  761. <sup>16</sup>
  762. http://dumb-looks-free.blogspot.fr/2014/06/beaglebone-black-bbb-kernal-headers.html
  763. </p>
  764. <p id="___fn17" class="footnote">
  765. <sup>17</sup> <a href="http://elinux.org/Building_BBB_Kernel">Building
  766. BBB Kernel</a>
  767. </p>
  768. <p id="___fn18" class="footnote">
  769. <sup>18</sup>
  770. http://komposter.com.ua/documents/USB-2.0-Debug-Port%28John-Keys%29.pdf
  771. </p>
  772. <p id="___fn19" class="footnote">
  773. <sup>19</sup> <a href="http://cs.usfca.edu/~cruse/cs698s10/">Exploring
  774. USB at the Hardware/Software Interface</a>
  775. </p>
  776. <p id="___fn20" class="footnote">
  777. <sup>20</sup>
  778. https://www.kernel.org/doc/Documentation/x86/earlyprintk.txt
  779. </p>
  780. <p id="___fn21" class="footnote">
  781. <sup>21</sup> https://wiki.ubuntu.com/Kernel/Debugging/USBearlyprintk
  782. </p>
  783. <p>
  784. <b>TODO</b>:
  785. </p>
  786. <ol>
  787. <li>grub does not send messages to EHCI debug. Investigate.</li>
  788. <li>The section &#8220;Configure libreboot with EHCI debug&#8221;
  789. can be skipped/simplified if a common configuration works for all
  790. relevant targets is selected as defualt</li>
  791. <li>Patch and compule g_dbgp on BBB instead cross-compile</li>
  792. <li>Find a simple way to send debug messages from targets userland</li>
  793. </ol>
  794. </div>
  795. <div class="section">
  796. <p>
  797. Copyright &copy; 2014, 2015 Francis Rowe &lt;info@gluglug.org.uk&gt;<br/>
  798. Copyright &copy; 2015 Patrick &quot;P. J.&quot; McDermott &lt;pj@pehjota.net&gt;<br/>
  799. Copyright &copy; 2015 Alex David &lt;opdecirkel@gmail.com&gt;<br/>
  800. This document is released under the Creative Commons Attribution-ShareAlike 4.0 International Public License and all future versions.
  801. A copy of the license can be found at <a href="../cc-by-sa-4.txt">../cc-by-sa-4.txt</a>.
  802. </p>
  803. <p>
  804. This document is distributed in the hope that it will be useful,
  805. but WITHOUT ANY WARRANTY; without even the implied warranty of
  806. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See <a href="../cc-by-sa-4.txt">../cc-by-sa-4.txt</a> for more information.
  807. </p>
  808. </div>
  809. </body>
  810. </html>