{"id":526,"date":"2012-11-28T09:31:45","date_gmt":"2012-11-28T08:31:45","guid":{"rendered":"http:\/\/blogs.igalia.com\/berto\/?p=526"},"modified":"2017-01-25T17:22:48","modified_gmt":"2017-01-25T16:22:48","slug":"qemu-and-open-hardware-spec-and-fmc-tdc","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/berto\/2012\/11\/28\/qemu-and-open-hardware-spec-and-fmc-tdc\/","title":{"rendered":"QEMU and open hardware: SPEC and FMC TDC"},"content":{"rendered":"<h4>Working with open hardware<\/h4>\n<p>Some weeks ago at LinuxCon EU in Barcelona I <a href=\"http:\/\/linuxconeurope2012.sched.org\/event\/8ca6b77fbc685213c79f7ff6c1def202\">talked<\/a> about how to use QEMU to improve the reliability of device drivers.<\/p>\n<p>At Igalia we have been using this for some projects. One of them is the <a href=\"http:\/\/blog.samuelig.es\/2012\/05\/23\/ipack-drivers-in-linux-3-5\/\">Linux IndustryPack driver<\/a>. For this project I <a href=\"http:\/\/blogs.igalia.com\/berto\/2012\/10\/03\/industrypack-qemu-and-linuxcon\/\">virtualized<\/a> two boards: the <em>TEWS TPCI200 PCI carrier<\/em> and the <em>GE IP-Octal 232<\/em> module. This work helped us find some bugs in the device driver and improve its quality.<\/p>\n<p>Now, those two boards are examples of products available in the market. But fortunately we can use the same approach to develop for hardware that doesn&#8217;t exist yet, or is still in a prototype phase.<\/p>\n<p>Such is the case of a project we are working on: adding Linux support for this <a href=\"http:\/\/www.ohwr.org\/projects\/fmc-tdc\/wiki\">FMC Time-to-digital converter<\/a>.<\/p>\n<table align=\"center\" width=\"100%\">\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blogs.igalia.com\/berto\/files\/2012\/11\/tdc.jpg\" alt=\"FMC TDC\" width=\"321\" height=\"286\" class=\"alignnone size-full wp-image-530\" srcset=\"https:\/\/blogs.igalia.com\/berto\/files\/2012\/11\/tdc.jpg 321w, https:\/\/blogs.igalia.com\/berto\/files\/2012\/11\/tdc-300x267.jpg 300w\" sizes=\"auto, (max-width: 321px) 100vw, 321px\" \/><\/td>\n<\/tr>\n<\/table>\n<p>This piece of hardware is designed by <a href=\"http:\/\/www.cern.ch\/\">CERN<\/a> and is published under the <a href=\"http:\/\/www.ohwr.org\/projects\/cernohl\/wiki\">CERN Open Hardware Licence<\/a>, which, in their own words <em>\u201cis to hardware what the General Public Licence (GPL) is to software\u201d<\/em>.<\/p>\n<p>The <a href=\"http:\/\/www.ohwr.org\/\">Open Hardware repository<\/a> hosts a number of projects that have been published under this license.<\/p>\n<h4>Why we use QEMU<\/h4>\n<p>So we are developing the device driver for this hardware, as my colleague Samuel <a href=\"http:\/\/blog.samuelig.es\/2012\/11\/23\/fmc-tdc-driver\/\">explains in his blog<\/a>. I&#8217;m the responsible of virtualizing it using QEMU. There are two main reasons why we want to do this:<\/p>\n<ol>\n<li>Limited availability of the hardware: although the specification is pretty much ready, <em>this is still a prototype<\/em>. The board is not (yet) commercially available. With virtual hardware, the whole development team can have as many \u201cboards\u201d as it needs.<\/li>\n<li>Testing: we can test the software against the virtual driver, force all kinds of conditions and scenarios, including the ones that would probably require us to <em>physically damage the board<\/em>.<\/li>\n<\/ol>\n<p>While the first point might be the most obvious one, <em>testing the software<\/em> is actually the one we&#8217;re more interested in.<\/p>\n<p>My colleague Miguel wrote <a href=\"http:\/\/blogs.igalia.com\/magomez\/?p=252\">a detailed blog post<\/a> on how we have been using QEMU to do testing.<\/p>\n<h4>Writing the virtual hardware<\/h4>\n<p>Writing a virtual version of a particular piece of hardware for this purpose is not as hard as it might look.<\/p>\n<p>First, the point is not to reproduce accurately how the hardware <em>works<\/em>, but rather how it <em>behaves<\/em> from the operating system point of view: the hardware is a black box that the OS talks to.<\/p>\n<p>Second, it&#8217;s not necessary to have a complete emulation of the hardware, there&#8217;s no need to support every single feature, particularly if your software is not going to use it. The emulation can start with the basic functionality and then grow as needed.<\/p>\n<p>The <a href=\"http:\/\/www.ohwr.org\/projects\/fmc-tdc\/wiki\">FMC TDC<\/a>, for example, is an <a href=\"http:\/\/en.wikipedia.org\/wiki\/FMC_-_FPGA_Mezzanine_Card\">FMC<\/a> card which is in our case connected to a PCIe bridge called <a href=\"http:\/\/www.ohwr.org\/projects\/spec\/wiki\">SPEC<\/a> (also available in the <em>Open Hardware repository<\/em>).<\/p>\n<p>We need to emulate both cards in order to have a working system, but the emulation is, at the moment, treating both as if they were just one, which makes it a bit easier to have a prototype and from the device driver point of view doesn&#8217;t really make a difference. Later the emulation can be split in two as I did with with <a href=\"http:\/\/blogs.igalia.com\/berto\/2012\/10\/03\/industrypack-qemu-and-linuxcon\/\">TPCI200 and IP-Octal 232<\/a>. This would allow us to support more FMC hardware without having to rewrite the bridging code.<\/p>\n<p>There&#8217;s also code in the emulation to force different kind of scenarios that we are using to test if the driver behaves as expected and handles errors correctly. Those tests include the simulation of input in the any of the lines, simulation of <em>noise<\/em>, DMA errors, etc.<\/p>\n<table width=\"100%\" align=\"center\">\n<tr>\n<td><a href=\"http:\/\/blogs.igalia.com\/berto\/files\/2012\/11\/tests.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blogs.igalia.com\/berto\/files\/2012\/11\/tests-300x244.png\" alt=\"Tests\" width=\"300\" height=\"244\" class=\"alignnone size-medium wp-image-551\" srcset=\"https:\/\/blogs.igalia.com\/berto\/files\/2012\/11\/tests-300x244.png 300w, https:\/\/blogs.igalia.com\/berto\/files\/2012\/11\/tests.png 665w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/td>\n<\/tr>\n<\/table>\n<p>And we have written a set of test cases and a continuous integration system, so the driver is automatically tested every time the code is updated. If you want details on this I recommend you again to read <a href=\"http:\/\/blogs.igalia.com\/magomez\/?p=252\">Miguel&#8217;s post<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working with open hardware Some weeks ago at LinuxCon EU in Barcelona I talked about how to use QEMU to improve the reliability of device drivers. At Igalia we have been using this for some projects. One of them is the Linux IndustryPack driver. For this project I virtualized two boards: the TEWS TPCI200 PCI [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,3,8,9,10,11,12,20],"tags":[],"class_list":["post-526","post","type-post","status-publish","format-standard","hentry","category-debian","category-english","category-gnome","category-gpul","category-igalia","category-maemo","category-free-software","category-virt"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/posts\/526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/comments?post=526"}],"version-history":[{"count":35,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/posts\/526\/revisions"}],"predecessor-version":[{"id":634,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/posts\/526\/revisions\/634"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/media?parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/categories?post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/tags?post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}