<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Way of the exploding head &#187; Openmoko Lessons</title>
	<atom:link href="http://warmcat.com/_wp/category/openmoko-lessons/feed/" rel="self" type="application/rss+xml" />
	<link>http://warmcat.com/_wp</link>
	<description>Embedded and desktop Linux</description>
	<lastBuildDate>Fri, 12 Feb 2010 23:49:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Don&#8217;t let Production Test Be Special</title>
		<link>http://warmcat.com/_wp/2010/02/12/dont-let-production-test-be-special/</link>
		<comments>http://warmcat.com/_wp/2010/02/12/dont-let-production-test-be-special/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 23:49:41 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Hardware design]]></category>
		<category><![CDATA[Openmoko Lessons]]></category>
		<category><![CDATA[Software design]]></category>

		<guid isPermaLink="false">http://warmcat.com/_wp/?p=75</guid>
		<description><![CDATA[Lesson 3: Test is not special
Commonly in embedded work test is the &#8220;red-haired stepchild&#8221;, nobody wants to take care of it and by common, silent consent it is always left until last.  Eventually the need for a test plan becomes overwhelming as the date to go to the factory nears, and the task is assigned [...]]]></description>
			<content:encoded><![CDATA[<h2>Lesson 3: Test is not special</h2>
<p>Commonly in embedded work test is the &#8220;red-haired stepchild&#8221;, nobody wants to take care of it and by common, silent consent it is always left until last.  Eventually the need for a test plan becomes overwhelming as the date to go to the factory nears, and the task is assigned to the most junior engineers available, since everybody knows that test is the death knell of your career.</p>
<p>Coming cold to and excluded from being inside an already-existing project, the engineers try to create some kind of test coverage the best way they can.  At openmoko two giant test suites were created, DM1 and DM2, written by people who were learning C for the first time.  I got the job of modernizing this code so I know from experience the code was already truly terrible and bitrotted at an alarming rate.  However I had to admire the guys who wrote it, with everything against them and little experience they did manage to create something that did provide test coverage at the factory, however much it was on life-support.</p>
<h2>Totentanz</h2>
<p>Similarly, Openmoko used production test jigs, special additional PCBs that formed a kind of custom test environment for the PCB under test.  At one version of GTA03 there were so many test points added it was a serious concern that the board would break down under the overall pressure needed to mate the spring-loaded test probes to the test points.</p>
<p>Jigs and test points have an obvious advantage in terms of test throughput, but there are some big disadvantages.</p>
<p>First, you have to design and build the jig, and track changes to the actual device with it.  This effort is completely disconnected from moving your actual product on, except that it&#8217;s meant to help in production.</p>
<p>Second, test points don&#8217;t test your connectors; the test point may be connected OK but not the connector pin the user actually accesses.</p>
<p>Third, you need something else outside the device to assess what is happening on the test points, the code for that also has to be written and maintained against changes in the actual product.  It also means that it&#8217;s not possible for the tests to be casually performed outside the factory, or maybe by the original engineers if they have access to the ATE gear themselves.</p>
<h2>Pain into torture</h2>
<p>Additionally the bringup of GTA02 required special versions of U-Boot and kernel which had added &#8220;test magic&#8221; created by the test guys and unknown to anyone else.  These versions were seldom uplevelled.</p>
<p>Since GTA02 had raw NAND, it needed filling up at the factory with the rootfs.  The way to do this was via a very fragile OpenOCD using a custom USB &#8211; serial based device that was bitbanged.  It only worked with certain versions of the usb library needed to talk to it.</p>
<p>All of these quirks and requirements at the factory made production runs difficult and expensive to get right.</p>
<h2>I only hurt you because I love you</h2>
<p>I spent a lot of time thinking about how to avoid this end result next time I would design something.  The mistakes started in having anything special for test I concluded.  The jig: special, and so evil.  Test kernels or bootloader: special -&gt; evil.  Test rootfs -&gt; Evil.  test software, like Openmoko&#8217;s DM1 and DM2, evil.  The device should naturally be able to test itself with the arrangements that already exist inside it to operate at all.</p>
<p>The answer to the problem of &#8220;production test&#8221; is to completely subsume it into the rest of the design.  So it is the responsibility of Linux drivers to provide enough functionality by probe errors, or sysfs features, that one can perform test and diagnosis.  The &#8220;test suite&#8221; should boil down to a bash script that is using features exposed in a normal shipping rootfs and kernel.  Bash is ideal because most of the test action will be calling existing commandline tools like ifconfig, ping, l2ping and grepping or looking at their return code, this is what bash is best at.  It&#8217;s also easily understood and edited by anyone who has worked with Linux for a while.</p>
<p>The bootloader is required for test in only one capacity, it is the only part of the system that is capable to run the SDRAM tests; once you enter Linux you can&#8217;t perform a full SDRAM test any more.  But even that should be done by the one shipping bootloader image.</p>
<p>In many cases, device interfaces can be tested by external loopback connectors, this proves connectivity through the connectors and it leaves open the possibility of end-users being able to run the same tests on the shipping rootfs.</p>
]]></content:encoded>
			<wfw:commentRss>http://warmcat.com/_wp/2010/02/12/dont-let-production-test-be-special/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bootloader Envy</title>
		<link>http://warmcat.com/_wp/2010/02/08/bootloader_envy/</link>
		<comments>http://warmcat.com/_wp/2010/02/08/bootloader_envy/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 20:14:54 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Linux peripherals]]></category>
		<category><![CDATA[Openmoko Lessons]]></category>
		<category><![CDATA[Software design]]></category>

		<guid isPermaLink="false">http://warmcat.com/_wp/?p=67</guid>
		<description><![CDATA[Lesson #2:  A bootloader is to load and boot Linux
On the first day of FOSDEM I sat through a presentation on what could be called another &#8220;U-Boot derivative&#8221;.  One of the greatest asspains at Openmoko was the various kinds of Hell caused by the U-Boot bootloader and its philosophy, which can be summed up as [...]]]></description>
			<content:encoded><![CDATA[<h2>Lesson #2:  A bootloader is to load and boot Linux</h2>
<p><img class="alignleft" title="Qi" src="http://warmcat.com/qi.png" alt="" width="126" height="183" />On the first day of FOSDEM I sat through a presentation on what could be called another &#8220;U-Boot derivative&#8221;.  One of the greatest asspains at Openmoko was the various kinds of Hell caused by the U-Boot bootloader and its philosophy, which can be summed up as &#8220;I wanna be Linux when I grow up&#8221;.</p>
<h2>Configure system is a bad alternative to good bootloader design</h2>
<p>First, it has a config system.  That should be good though, right?  The problem with the config system is that if anything differs from your current config, you must build another incompatible binary with another config and take care of that.  When you have more than a handful of different boards, you are in a maze of incompatible bootloaders.  Openmoko took it one step further, they mandated a different bootloader binary per PCB revision, so left unchecked there would have been a continuous proliferation of incompatible bootloaders, all basically the same.</p>
<h2>All persistent bootloader private state is EVIL</h2>
<p>Second, U-Boot thinks it&#8217;s a good idea to have these environment &#8220;scripts&#8221;, because it&#8217;s &#8220;configurable&#8221;.  Actually, the job of a bootloader is to Load, then Boot Linux.  You don&#8217;t need any configurability for that if the bootloader can figure out what it&#8217;s running on and therefore where the memory is and how much there is.  These scripts expose a really deadly trap I call &#8220;private bootloader state&#8221;.  It means the bootloader stores stuff in nonvolatile memory on the PCB and acts different according to what it hides there.  The end result is that two boards from the same factory may act totally different even with the same rootfs due to &#8220;bootloader secrets&#8221;.  This is totally needless and ALL private bootloader state can be eliminated by correct design of the bootloader leading to completely deterministic boot action per rootfs.</p>
<p>A good example how that lead you to the path to hell is hardcoding in the U-Boot environment of the amount of kernel image you will copy from somewhere.  People commonly set it to 2MBytes, forget about it and one day they generate a 2.1MB kernel image and wonder why decompress blows up.  Actually, that whole procedure is insane, the kernels are uImages that report their length in a header.  The bootloader should examine the header and compute the length of image to pull.  But that doesn&#8217;t fit with this &#8220;environment&#8221; nonsense.</p>
<h2>Do Linux Stuff In Linux</h2>
<p>In any of these bloated U-Boot style bootloaders, is there even one feature they do better than the same feature in Linux?  The startup time should be better by a few 100ms.  Other than that, no, every single bloated &#8220;I will add it to the bootloader beacuse I can&#8221; feature is shittier than you get in Linux.  Every single feature!</p>
<p>If you need some advanced capability or backup / recovery boot action, check for a button held down at boot-time in the bootloader and go fetch a different Linux partition + kernel.  Use standard Linux tools and shells.  In return, get really high quality network stack, proper USB support, NAND access that&#8217;s compatible to your main Linux system access in BBT / ECC terms, and all the other advantages of Linux.</p>
<h2>Do your peripheral bringup in drivers in Linux</h2>
<p>Typically you do not need ANY bringup in the bootloader except SDRAM controller and chip init, since it&#8217;s a prerequisite to put Linux in the RAM that it&#8217;s initialized.</p>
<p>That&#8217;s right, all the megabytes of source spent in U-Boot providing support for so many kinds of peripheral is a waste of time, effort and maintenance.  I am being kind saying &#8220;maintenance&#8221;, because the drivers in U-Boot are typically &#8220;dumbed down&#8221; versions of the equivalent Linux driver that were forked irretrievably the moment all the Linux APIs were ripped, so there&#8217;s no coherent effort to keep them up to date with the Linux ones .  Lately I saw that they try to ape some Linux APIs there&#8230; why not go the whole hog and just <strong>load and boot real Linux</strong>?  After all, modern CPUs can be running your driver probes in Linux in ~2 seconds from power using a bootloader that doesn&#8217;t get in the way.</p>
<p>You typically don&#8217;t even need to talk to the PMU in the bootloader, after all, you are running code fine already, right?  Otherwise you wouldn&#8217;t be able to run the bootloader code itself.</p>
<h2>Fat girl in Ibiza</h2>
<p>At least at Openmoko, code quality inside U-Boot was awful bad.  I called U-Boot on the lists there &#8220;the fat girl in Ibiza&#8221; because you know she&#8217;s going to do anything you want.  All kinds of constant-only code, weird new scripting keywords were added for test undocumented, you name it.  Hardware guys felt up to writing such code secretly by themselves once they learned the software engineering marvel that is *((unsigned int *)0x&#8230;) = 0x&#8230;;</p>
<h2>Your bootloader just tests SDRAM</h2>
<p>There&#8217;s only one test action your bootloader is suited to do, and that is SDRAM test.  Once you are in Linux, it can&#8217;t perform a full SDRAM test while it&#8217;s running.  But the bootloader is typically starting from on-CPU SRAM, it can actually run a true SRAM test from there.  Otherwise, the bootloader should be completely absent from the test plan.  All other tests should be performed in Linux via standard driver and rootfs tools.</p>
<p>More about board and test and board bringup will feature in another report of a lesson learned.</p>
<h2>Qi</h2>
<p>While at Openmoko (mainly) I wrote a bootloader that meets these ideals, you can find it <a title="Qi git" href="http://git.warmcat.com/cgi-bin/cgit/qi/log/?h=txtr">in git here</a> One of the nicest things about it is that unlike the bloated bootloaders whose job never finishes trying to become Linux cargo cult style, Qi has been pretty much complete for a few months.  It&#8217;s a new job to support a new CPU, a much smaller job to add a new board and it doesn&#8217;t want to talk to your peripherals anyway so no problem there.</p>
<p>Qi creates one binary per CPU, that supports all boards with that CPU.  That sounds like a big job but we don&#8217;t care about your peripherals so all boards with the same CPU look almost identical.  You have to find something that can detect your particular board at runtime, for example NOR device ID read check.  So there is zero build-time config and Qi generates all CPU support when it&#8217;s buit, it takes 3 sec or so typically.</p>
<p>Typical bootloader binary size per CPU is 28-30KBytes.  That supports VFAT, ext2/3/4 typcially the SD controller as well.  The single Qi image also supports being booted from NAND, JTAG or SD Card on processors that support it just by being copied into place and without any changes.</p>
<p>There is zero bootloader private state, however Qi can look in the rootfs and append kernel commandline text from the content of a filesystem file.  This maintains the rule that boot should be completely deterministic per rootfs.</p>
]]></content:encoded>
			<wfw:commentRss>http://warmcat.com/_wp/2010/02/08/bootloader_envy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fosdem and the Linux Cross Niche</title>
		<link>http://warmcat.com/_wp/2010/02/08/fosdem-and-the-linux-cross-niche/</link>
		<comments>http://warmcat.com/_wp/2010/02/08/fosdem-and-the-linux-cross-niche/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 12:42:34 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Openmoko Lessons]]></category>
		<category><![CDATA[Software design]]></category>
		<category><![CDATA[fosdem cross build distro fedora]]></category>

		<guid isPermaLink="false">http://warmcat.com/_wp/?p=56</guid>
		<description><![CDATA[
I was at Fosdem over the weekend, there were several interesting talks I attended but the most interesting one for me was a roundtable about the future of Cross distributions.  I was invited to give a 5 minute talk there which I gave, but unfortunately it was right at the end and the people before [...]]]></description>
			<content:encoded><![CDATA[<p><img class=" alignleft" title="fosdem" src="http://warmcat.com/fosdem.png" alt="fosdem" width="121" height="116" /></p>
<p>I was at Fosdem over the weekend, there were several interesting talks I attended but the most interesting one for me was a roundtable about the future of Cross distributions.  I was invited to give a 5 minute talk there which I gave, but unfortunately it was right at the end and the people before had overrun, so there was no time to make much of a coherent case.   So I am going to write some articles covering the issues involved here.</p>
<h2>Cross as a niche</h2>
<p>Cross itself remains absolutely necessary for systems below a certain level of horsepower.  For example, 8051, ARM7, cortex M3 are not really capable to consider native build.  But processors get faster each year, a lot of things we would have used an 8051 on use an ARM7 or cortex M3 now, in a few years it is likely that baseline has moved further up and it&#8217;s an ARM9 equivalent.  What I am suggesting then is that over time, the niche where you need cross is shrinking.</p>
<p>All four of the cross distros at FOSDEM target a CPU that&#8217;s powerful enough to run Linux, but not powerful enough to build its own binaries.  That is the niche that I believe will shrink to the point that it won&#8217;t support all these cross Linux distro projects, possibly none of them in the end.</p>
<h2>My background with cross Linux</h2>
<p>A few years ago I created an RPM-based cross distro singlehanded, and used it on a product for a customer  This was AT91RM9200-based, a 200MHz ARM9 with 32MBytes of SDRAM.  The amount of effort needed to create a set of cross packages sufficient to create a workable rootfs was huge, it took me many weeks.  Some packages like perl were just so cross-unfriendly that they were basically out of reach (although I later saw other people have done the invasive magic necessary).  It did work well, and I added patches for busybox RPM support that allowed it to do more useful things like erase and keep a package database.  The packaging was valuable in itself but a nice advantage was the source RPMs it generated ensuring GPL compliance.</p>
<h2>My background with Openmoko</h2>
<p>Subsequently I spent 14 months as (mainly) the kernel maintainer for Openmoko.  Openmoko had an OpenEmbedded basis for it&#8217;s rootfs, also a cross system.  I attempted to use it for &#8220;hello world&#8221; while I was at Openmoko, but it broke because I was on a newly released Fedora.  How it broke was very revealing, the official way to get started with it was to run a huge script that wgetted and locally built 1100 packages.  It died due to some assumption somewhere breaking while it tried to build <strong>host</strong> dbus libraries.</p>
<p>What I wanted was a cross toolchain that would let me package &#8220;hello world&#8221;.  What I got was a massive host build action including host dbus libs.  I have perfectly good host dbus libs in my Fedora install, I enquired about it and was told they were the &#8220;wrong&#8221; libs for the expectation of the rest of the packages, so they had to be rebuilt.</p>
<p>I gave up on trying to use OpenEmbedded, as I guess most of Openmoko&#8217;s customers did.</p>
<p>After Openmoko imploded, I designed the software architecture (and influenced the hardware design in some aspects) for the txtr reader device.  On this device, I put into action various lessons I had learned in how not to do things from Openmoko.  I will write further about the other lessons in future articles, but here&#8217;s the first one:</p>
<h2>Lesson #1: Don&#8217;t compile your own rootfs</h2>
<p>I was told by a manager at Openmoko that Openmoko had hired most of the main devs of OpenEmbedded and were paying for that accordingly.  This was a pretty big drain on their resources over a long period.</p>
<p>In contrast, nowadays you can head over to <a title="Fedora ARM project" href="http://fedoraproject.org/wiki/Architectures/ARM" target="_blank">http://fedoraproject.org/wiki/Architectures/ARM</a> and download a generic <a title="rootfs tarball" href="http://ftp.linux.org.uk/pub/linux/arm/fedora/rootfs/rootfs-f12.tar.bz2">rootfs tarball </a>of prebuilt binaries for ARMv5 and above[1].  It&#8217;s made from unpacking prebuilt binary packages.  Once you boot into it, you can install further packages with the usual yum install type action.  You can be up in a high quality rootfs in five minutes flat.</p>
<p>You do not need to go around compiling everything personally when binary packages exist from a reputable distro already.  Normal distros provide -dev and -devel packages for you to link against too, so you do not need to recompile the universe just because you want to build &#8220;hello world&#8221; either.  That&#8217;s how we do things on desktop and server systems, as the processors involved get stronger embedded does not have to be different.</p>
<p>If you want to cross-build specific packages, you install the <a title="cross toolchain" href="http://fedoraproject.org/wiki/Architectures/ARM/CrossToolchain">Fedora ARM Cross Toolchain RPMs</a> on you host via yum and you are ready to go in a couple of minutes.  This is very useful for cooking the kernel on your host both to get started and during development; you can&#8217;t native-build the bootstrap stuff needed to boot your platform.  But that&#8217;s just a cross compiler and related pieces, it&#8217;s not a cross distro.  (The guy from emdebian at this FOSDEM talk also made this point that you do not need to get into making your own toolchain, your distro should have one you can just install).</p>
<p>Fedora ARM&#8217;s strategy is native build.  So you install gcc and other dependencies into the actual device, and use standard rpmbuild to build your package there; you can also just configure ; make ; make install for development too down there.  If something&#8217;s missing on the rootfs you can yum install it.</p>
<p><em>(1 To make the comparison fair to openmoko Fedora ARM came along too late for them to choose it from the start, and the GTA02 s3c2442 was not a v5 class processor, they would have been into a distro recook after changing the distro-level compile options.  However my worry is not repeating Openmoko&#8217;s errors and today Fedora ARM is available.)</em></p>
<h2>Quality and Quantity</h2>
<p>Another major issue is distro quality.  I was so surprised to hear at Fosdem Dr Mickey Lauer of OpenEmbedded boast about the number of devices that managed to use that distro (including the sad shape of the GTA02) and say that unlike the other cross distros, OpenEmbedded focused on &#8220;Quantity not Quality&#8221;.  From my experience I think he&#8217;s right alright about not focusing on quality, and he did go on to explain there are problems with OpenEmbedded they are trying to address.</p>
<p>In the near future, there will be a carcrash between these difficult cross distros that have relatively poor quality and strange requirements to use them and standard, &#8220;proper distros&#8221; like Fedora ARM, because on higher-end ARMv5s say 400MHz and above, it is already perfectly possible to compare the two worlds on the same device.  I think many devs currently are trained by their experience with buildroot type systems to assume they have to personally build everything Gentoo style.  However as CPUs increase in power at the same price point, the ways of working with these systems efficiently change, and desktop / server &#8220;treat it like a PC&#8221; lessons like the value of packaging start to really show their traditional advantages over rootfs tarballs.</p>
<p>Like Debian, Fedora has all kinds of rules and requirements about packaging to ensure high quality, there are a huge number of users of these two normal distributions that leads to tested and debugged basic packages and their dependencies.  OpenEmbedded&#8217;s boast about number of users is not even a blip in comparison to Fedora or Debian&#8217;s consumers and contributors.</p>
<h2>Cross distros are locked into local patch hell</h2>
<p>A worse problem against their quality even than not many users is the patch load these projects are carrying, I think all of the cross distro projects bemoaned that they were carrying huge patchsets across a large number of packages to get them to build cross at all, and that most upstreams did not care to take them (I assume they don&#8217;t want to have to get into testing them).  To uplevel packages, which distros have to daily when they have a large package universe, it can become a nightmare of breakage because of the private patchsets being dragged around.</p>
<p>(BTW I also saw in another presentation that the <a title="limo" href="http://www.limofoundation.org/">limo foundation</a> are carrying around more than 80MBytes of diff between their distro and the upstream projects, and these are the guys who sent out a <a title="limo whitepaper" href="http://www.limofoundation.org/images/stories/pdf/limo%20economic%20analysis.pdf">whitepaper</a> explaining the massive cost of delaying sending patches upstream in dollar terms.)</p>
<p>There was proposed a unified crossbuild patch promoting effort, but the effort seemed only to consist of a domain like &#8220;sends-patches.org&#8221; that you could use when sending patches instead of your own project name, which seems to just be tea and sympathy rather than a solution.</p>
<p>It&#8217;s clear that quality will tend to be higher if you are getting packages built with normal distro specfiles and no pile of local patches to get them to build cross (because they were built native).  Combined with higher quality thresholds at the project level and sheer number of users, native Fedora (or Debian) rootfs basis will provide Quantity <strong>and</strong> Quality if your processor is appropriate.</p>
<p>A couple of hours after the talk I had an interesting conversation with <a title="openinkpot" href="http://openinkpot.org">OpenInkpot</a> dev Mikhail Gusarov, who I found also <a title="openinkpot and openembedded" href="http://openinkpot.org/wiki/FAQ#Whyareyouusing.debsandIPlinux">shared my lack of enthusiasm for OpenEmbedded</a>, although he is trapped still in the cross niche generally by the weak processors he targets at the moment.</p>
<p>[update Feb 10 09:00] Mikhail has <a href="http://fossarchy.blogspot.com/2010/02/cross-build-systems-and-their-future.html">written his own response</a>, he still likes the speed of cross (and still hates OpenEmbedded).  But there&#8217;s some confusion about what Fedora ARM offers, it&#8217;s a generic ARMv5 rootfs, it doesn&#8217;t care what exact kind of CPU, vendor or peripherals available.  Build farms are less of a requirement when you are no longer building your rootfs but installing it from distro binary packages.  <a href="http://en.wikipedia.org/wiki/SheevaPlug">Sheevaplug</a> makes available a 1.2GHz Marvell ARM compatible with 512MBytes of SDRAM that Fedora ARM can work on if you need a native build machine.  Shortly fast dual processor Cortex A9 machines will become available.</p>
]]></content:encoded>
			<wfw:commentRss>http://warmcat.com/_wp/2010/02/08/fosdem-and-the-linux-cross-niche/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
