<?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>Barr Code &#187; ethics</title>
	<atom:link href="http://embeddedgurus.com/barr-code/tag/ethics/feed/" rel="self" type="application/rss+xml" />
	<link>http://embeddedgurus.com/barr-code</link>
	<description>A Blog by Michael Barr</description>
	<lastBuildDate>Wed, 18 Apr 2012 19:33:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Building Reliable and Secure Embedded Systems</title>
		<link>http://embeddedgurus.com/barr-code/2012/03/building-reliable-and-secure-embedded-systems/</link>
		<comments>http://embeddedgurus.com/barr-code/2012/03/building-reliable-and-secure-embedded-systems/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 10:49:45 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=710</guid>
		<description><![CDATA[In this era of 140 characters or less, it has been well and concisely stated that, &#8220;RELIABILITY concerns ACCIDENTAL errors causing failures, whereas SECURITY concerns INTENTIONAL errors causing failures.&#8221; In this column I expand on this statement, especially as regards the design of embedded systems and their place in our network-connected and safety-concious modern world. [...]]]></description>
			<content:encoded><![CDATA[<p><em>In this era of 140 characters or less, it has been well and concisely stated that, &#8220;RELIABILITY concerns ACCIDENTAL errors causing failures, whereas SECURITY concerns INTENTIONAL errors causing failures.&#8221;  In this column I expand on this statement, especially as regards the design of embedded systems and their place in our network-connected and safety-concious modern world.</em></p>
<p>As the designers of embedded systems, the first thing we must accomplish on any project is to make the hardware and software work.  That is to say we need to make the system behave as it was designed to.  The first iteration of this is often flaky; certain uses or perturbations of the system by testers can easily dislodge the system into a non-working state.  In common parlance, &#8220;expect bugs.&#8221;  </p>
<p>Given time, tightening cycles of debug and test can get us past the bugs and through to a shippable product.  But is a debugged system good enough?  Neither reliability nor security can be tested into a product.  Each must be designed in from the start.  So let&#8217;s take a closer look at these two important design aspects for modern embedded systems and then I&#8217;ll bring them back together at the end.</p>
<p><strong>Reliable Embedded Systems</strong></p>
<p>A product can be stable yet lack reliability.  Consider, for example, an anti-lock braking computer installed in a car.  The software in the anti-lock brakes may be bug-free, but how does it function if a critical input sensor fails?</p>
<p>Reliable systems are robust in the face of adverse run-time environments.  Reliable systems are able to work around errors encountered as they occur to the system in the field&#8211;so that the number and impact of failures are minimized.  One key strategy for building reliable systems is to eliminate single-points-of-failure.  For example, redundancy could be added around that critical input sensor&#8211;perhaps by adding a second sensor in parallel with the first.</p>
<p>Another aspect of reliability that is under the complete control of designers (at least when they consider it from the start) are the &#8220;fail-safe&#8221; mechanisms.  Perhaps a suitable but lower-cost alternative to a redundant sensor is detection of the failed sensor with a fall back to mechanical braking.</p>
<p><a href="http://en.wikipedia.org/wiki/Failure_mode_and_effects_analysis" title="Failure Modes and Effects Analysis" target="_blank">Failure Mode and Effect Analysis</a> (FMEA) is one of the most effective and important design processes used by engineers serious about designing reliability into their systems.  Following this process, each possible failure point is traced from the root failure outward to its effects.  In an FMEA, numerical weights can be applied to the likelihoods of each failure as well as the seriousness of consequences.  An FMEA can thus help guide you to a cost effective but higher reliability design by highlighting the most valuable places to insert the redundancy, fail-safes, or other elements that reinforce the system&#8217;s overall reliability.</p>
<p>In certain industries, reliability is a key driver of product safety.  And that is why you see these techniques and FMEA and other design for reliability processes being applied by the designers of safety-critical automotive, medical, avionics, nuclear, and industrial systems.  The same techniques can, of course, be used to make any type of embedded system more reliable.</p>
<p>Regardless of your industry, it is typically difficult or impossible to make your product as reliable via patches.  There&#8217;s no way to add hardware like that redundant sensor, so your options may reduce to a fail-safe that is helpful but less reliable overall.  Reliability cannot be patched or tested or debugged into your system.  Rather, reliability must be designed in from the start.</p>
<p><strong>Secure Embedded Systems</strong></p>
<p>A product can also be stable yet lack security.  For example, an office printer is the kind of product most of us purchase and use without giving a minute of thought to security.  The software in the printer may be bug-free, but is it able to prevent a would-be eavesdropper from capturing a remote electronic copy of everything you print, including your sensitive financial documents?</p>
<p>Secure systems are robust in the face of persistent attack.  Secure systems are able to keep hackers out by design.  One key strategy for building secure systems is to validate all inputs, especially those arriving over an open network connection.  For example, security could be added to a printer by ensuring against buffer overflows and encrypting and digitally signing firmware updates.</p>
<p>One of the unfortunate facts of designing secure embedded systems is that the hackers who want to get in only need to find and exploit a single weakness.  Adding layers of security is good, but if even any one of those layers remains fundamentally weak, a sufficiently motivated attacker will eventually find and breach that defense.  But that&#8217;s not an excuse for not trying.</p>
<p>For years, the largest printer maker in the world apparently gave little thought to the security of the firmware in its home/office printers, even as it was putting tens of millions of tempting targets out into the world.  Now <a href="http://events.ccc.de/congress/2011/Fahrplan/track/Hacking/4780.en.html" title="Print Me If You Dare" target="_blank">the security of those printers has been breached by security researchers</a> with a reasonable awareness of embedded systems design.  Said one of the lead researchers, &#8220;We can actually modify the firmware of the printer as part of a legitimate document. It renders correctly, and at the end of the job there&#8217;s a firmware update. &#8230; In a super-secure environment where there&#8217;s a firewall and no access &#8212; the government, Wall Street &#8212; you could send a résumé to print out.&#8221;</p>
<p>Security is a brave new world for many embedded systems designers.  For decades we have relied on the fact that the microcontrollers and Flash memory and real-time operating systems and other less mainstream technologies we use will protect our products from attack.  Or that we can gain enough &#8220;security by obscurity&#8221; by keeping our communications protocols and firmware upgrade processes secret.  But we no longer live in that world.  You must adapt.</p>
<p>Consider the implications of an <a href="http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5504804" title="Experimental Security Analysis of a Modern Automobile" target="_blank">insecure design of an automotive safety system that is connected to another Internet-connected computer in the car via CAN</a>;  or the insecure design of an <a href="http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4531149&amp;isnumber=4531132" title="Pacemakers and Implantable Cardiac Defibrillators: Software Radio Attacks and Zero-Power Defenses" target="_blank">implanted medical device</a>; or the insecure design of <em>your</em> product.</p>
<p>Too often, the ability to upgrade a product&#8217;s firmware in the field is the very vector that&#8217;s used to attack.  This can happen even when a primary purpose for including remote firmware updates is motivated by security.  For example, as I&#8217;ve learned in my work as an <a href="http://netrino.com/images/cv-barr.pdf" title="Expert Witness Resume" target="_blank">expert witness</a> in numerous cases involving reverse engineering of the techniques and technology of satellite television piracy, much of that piracy has been empowered by the same software patching mechanism that allowed the broadcasters to perform security upgrades and electronic countermeasures.  Ironically, had the security smart cards in those set-top boxes had only masked ROM images the overall system security may have been higher.  This was certainly not what the designers of the system had in mind.  But security is also an arms race.</p>
<p>Like reliability, security must be designed in from the start.  Security can&#8217;t be patched or tested or debugged in.  You simply can&#8217;t add security as effectively once the product ships.  For example, an attacker who wished to exploit a current weakness in your office printer or smart card might download his hack software into your device and write-protect his sectors of the flash today so that his code could remain resident even as you applied security patches.</p>
<p><strong>Reliable and Secure Embedded Systems</strong></p>
<p>It is important to note at this point that reliable systems are inherently more secure.  And that, vice versa, secure systems are inherently more reliable.  So, although, design for reliability and design for security will often individually yield different results&#8211;there is also an overlap between them.  </p>
<p>An investment in reliability, for example, generally pays off in security.  Why?  Well, because a more reliable system is more robust in its handling of all errors, whether they are accidental or intentional.  An anti-lock braking system with a fall back to mechanical braking for increased reliability is also more secure against an attack against that critical hardware input sensor.  Similarly, those printers wouldn&#8217;t be at risk of fuser-induced fire in the case of a security breach if they were never at risk of fire in the case of any misbehavior of the software.</p>
<p>Consider, importantly, that one of the first things a hacker intent on breaching the security of your embedded device might do is to perform a (mental, at least) <a href="http://www.fault-tree.net/papers/ericson-fta-tutorial.pdf" title="Fault Tree Analysis" target="_blank">fault tree analysis</a> of your system.  This attacker would then target her time, talents, and other resources at one or more single points of failure she considers most likely to fail in a useful way.  </p>
<p>Because a fault tree analysis starts from the general goal and works inward deductively toward the identification of one or more choke points that might produce the desired erroneous outcome, attention paid to increasing reliability such as via FMEA usually reduces choke points and makes the attacker&#8217;s job considerably more difficult.  Where security can break down even in a reliable system is where the possibility of an attacker&#8217;s intentionally induced failure is ignored in the FMEA weighting and thus possible layers of protection are omitted.</p>
<p>Similarly, an investment in security may pay off in greater reliability&#8211;even without a directed focus on reliability.  For example, if you secure your firmware upgrade process to accept only encrypted and digitally signed binary images you&#8217;ll be adding a layer of protection against an inadvertently corrupted binary causing an accidental error and product failure.  Anything you do to improve the security of communications (i.e., checksums, prevention of buffer overflows, etc.) can have a similar effect on reliability.</p>
<p><strong>The Only Way Forward</strong></p>
<p>Each year it becomes increasingly important for all of us in the embedded systems design community to learn to design reliable and secure products.  If you don&#8217;t, it might be your product making the wrong kind of headlines and your source code and design documents being poured over by lawyers.  It is no longer acceptable to stick your head in the sand on these issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2012/03/building-reliable-and-secure-embedded-systems/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Enforce Coding Standards (Automatically)</title>
		<link>http://embeddedgurus.com/barr-code/2011/05/how-to-enforce-coding-standards-automatically/</link>
		<comments>http://embeddedgurus.com/barr-code/2011/05/how-to-enforce-coding-standards-automatically/#comments</comments>
		<pubDate>Wed, 25 May 2011 15:01:34 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=623</guid>
		<description><![CDATA[Coding standards can be an important tool in the fight to keep bugs out of embedded software. Unfortunately, too many well-intentioned (especially, corporate) coding standards are ineffective and gather more dust than followers. The hard truth is that enforcement of coding standards too often depends on programmers already under deadline pressure to be disciplined while [...]]]></description>
			<content:encoded><![CDATA[<p>Coding standards can be an important tool in the fight to <a href="http://www.eetimes.com/discussion/other/4008255/Bug-killing-standards-for-firmware-coding">keep bugs out of embedded software</a>. Unfortunately, too many well-intentioned (especially, corporate) coding standards are ineffective and gather more dust than followers. The hard truth is that enforcement of coding standards too often depends on programmers already under deadline pressure to be disciplined while they code and/or to make time to perform peer code reviews. And when peer reviews are done in this scenario, they too easily devolve into compliance discussions that miss the forest for the trees.</p>
<p>To ensure your selected coding standard is followed and thus effective, your team should find as many automated ways to enforce as many of its rules as possible. And you should make such automated rule checking part of the everyday software build process. Ideally, you would also restrict version control check-ins to just code that has passed all the automated checks. No code that breaks any of these automatable rules should be allowed in peer code reviews. That way, code reviewers can focus their limited hours on (1) what the code is supposed to do, (2) whether it does so correctly, and (3) whether the code and comments together are easily understood by all involved.</p>
<p>One of the ways <a href="http://netrino.com">Netrino</a> has found to increase compliance with its <a href="http://netrino.com/Coding-Standard">Embedded C Coding Standard</a> is by configuring static analysis tools we already use to automatically enforce individual rules.</p>
<p>Perhaps the best option is to use a static analysis tool that includes built-in support for your chosen coding standard and/or the ability to be customized to proprietary rules. <a href="http://ldra.com">LDRA</a>&#8216;s static analysis engine, a screenshot from which is shown in the image below, comes preconfigured to check about 80% of the &#8220;<a href="http://www.ldra.com/netrino.asp">NETRINO</a>&#8221; coding standard rules, as well as a number of other widely used coding standards.</p>
<p align="center"><a href="http://www.ldra.com/images/integrations/Figure1_Netrino_300.JPG"><img width="700" src="http://www.ldra.com/images/integrations/Figure1_Netrino_300.JPG" alt="The LDRA Tool Suite Enforces Netrino's Embedded C Coding Standard" /></a></p>
<p>But there are other, less expensive, options available as well. Two tools that we have used are <a href="http://msquaredtechnologies.com/m2rsm/index.htm">RSM</a> and <a href="http://gimpel.com/">PC-Lint</a> from M Squared Technologies and Gimpel Software, respectively. Neither can easily and independently enforce all of our <a href="http://netrino.com/Coding-Standard">Embedded C Coding Standard</a> rules. But used together and properly configured, these two tools offer a low-cost automated coding standards enforcement mechanism that covers a large percentage of the rules.</p>
<p><strong>Configuring RSM</strong></p>
<p>The following <a href="http://msquaredtechnologies.com/m2rsm/index.htm">RSM</a> outputs can be examined and configuration options set (in version 7.75) to assist in the automated enforcement of the identified rules from the <a href="http://netrino.com/Coding-Standard">Embedded C Coding Standard</a>. Pricing for the RSM tool, which runs on Windows, Linux, and other versions of Unix (including Mac OS X), is online at <a href="http://msquaredtechnologies.com/m2rsm/order/">http://msquaredtechnologies.com/m2rsm/order/</a>.</p>
<table>
<tr>
<td><strong>Rule #</strong></td>
<td><strong>Brief Description</strong></td>
<td><strong>Tool Configuration Notes</strong></td>
</tr>
<tr>
<td>1.2.a</td>
<td>Line length limited to 80 characters.</td>
<td>Quality Notice 1</td>
</tr>
<tr>
<td>1.3.a</td>
<td>Braces surround all blocks of code.</td>
<td>Quality Notice 22</td>
</tr>
<tr>
<td>1.7.c</td>
<td>Keyword goto not used.</td>
<td>Quality Notice 9</td>
</tr>
<tr>
<td>1.7.d</td>
<td>Keyword continue not used.</td>
<td>Quality Notice 43</td>
</tr>
<tr>
<td>1.7.e</td>
<td>Keyword break not used outside switch.</td>
<td>Quality Notice 44</td>
</tr>
<tr>
<td>2.2</td>
<td>Location and content of comments.</td>
<td>Quality Notices 17, 20, 51; Options -Es -Ec -EC</td>
</tr>
<tr>
<td>3.1</td>
<td>Use of white space.</td>
<td>Quality Notices 16, 19</td>
</tr>
<tr>
<td>3.5.a</td>
<td>No tab characters.</td>
<td>Quality Notice 30; Option -Dt</td>
</tr>
<tr>
<td>3.6.a</td>
<td>UNIX-style (single-character) linefeeds.</td>
<td>Option -Du</td>
</tr>
<tr>
<td>4.1.a-d</td>
<td>Module naming conventions.</td>
<td>Option -Rn</td>
</tr>
<tr>
<td>4.2.a</td>
<td>Precisely one header file per source file.</td>
<td>Option -Rn</td>
</tr>
<tr>
<td>6.1.a-e</td>
<td>Precisely one header file per source file.</td>
<td>Quality Notice 2; Option -l</td>
</tr>
<tr>
<td>6.2</td>
<td>Cyclomatic complexity of functions.</td>
<td>Quality Notices 10, 18, 27; Option -c</td>
</tr>
<tr>
<td>6.3.b.i-iii</td>
<td>Preprocessor macro safety mechanisms.</td>
<td>Option -m</td>
</tr>
<tr>
<td>8.2.d</td>
<td>If-else if statements always have else.</td>
<td>Quality Notice 22</td>
</tr>
<tr>
<td>8.3.b</td>
<td>Switch statements always have default.</td>
<td>Quality Notices 13, 14, 56</td>
</tr>
<tr>
<td>8.5.a</td>
<td>No unconditional jumps.</td>
<td>Quality Notices 9, 43, 444</td>
</tr>
</table>
<p></p>
<p><strong>Configuring PC-Lint</strong></p>
<p>In a <a href="/barr-code/2011/06/how-to-enforce-coding-standards-using-pc-lint/">future blog post</a>, I will similarly identify <a href="http://gimpel.com">PC-Lint</a> configurations that can be used (in version 9.0) to assist in the automated enforcement of specific rules from the <a href="http://netrino.com/Coding-Standard">Embedded C Coding Standard</a>. Pricing for the PC-Lint tool, which runs on Windows, Linux, and other versions of Unix (including Mac OS X), is online at <a href="http://gimpel.com/html/order.htm">http://gimpel.com/html/order.htm</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2011/05/how-to-enforce-coding-standards-automatically/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>What NHTSA/NASA Didn&#8217;t Consider re: Toyota&#8217;s Firmware</title>
		<link>http://embeddedgurus.com/barr-code/2011/03/what-nhtsanasa-didnt-consider-re-toyotas-firmware/</link>
		<comments>http://embeddedgurus.com/barr-code/2011/03/what-nhtsanasa-didnt-consider-re-toyotas-firmware/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 23:10:54 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[engineering]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=548</guid>
		<description><![CDATA[In a blog post yesterday (Unintended Acceleration and Other Embedded Software Bugs), I wrote extensively on the report from NASA&#8217;s technical team regarding their analysis of the embedded software in Toyota&#8217;s ETCS-i system. My overall point was that it is hard to judge the quality of their analysis (and thereby the overall conclusion that the [...]]]></description>
			<content:encoded><![CDATA[<p>In a blog post yesterday (<a href="/barr-code/2011/03/unintended-acceleration-and-other-embedded-software-bugs/">Unintended Acceleration and Other Embedded Software Bugs</a>), I wrote extensively on the report from NASA&#8217;s technical team regarding their analysis of the embedded software in Toyota&#8217;s ETCS-i system. My overall point was that it is hard to judge the quality of their analysis (and thereby the overall conclusion that the software isn&#8217;t to blame for unintended accelerations) given the large number of redactions.</p>
<p>I need to put the report down and do some other work at this point, but I have a few other thoughts and observations worth writing down.</p>
<p><strong>Insufficient Explanations</strong></p>
<p>First, some of the explanations offered by Toyota, and apparently accepted by NASA, strike me as insufficent.  For example, at pages 129-132 of <a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NASA_FR_Appendix_A_Software.pdf">Appendix A</a> to the NASA Report there is a discussion of <a href="http://en.wikipedia.org/wiki/Recursion">recursion</a> in the Toyota firmware. &#8220;The question then is how to verify that the indirect recursion in the ETCS-i does in fact terminate (i.e., has no infinite recursion) and does not cause a stack overflow.&#8221; </p>
<blockquote><p>
&#8220;For the case of stack overflow, [redacted phrase], and therefore a stack overflow condition cannot be detected precisely. It is likely, however, that overflow would cause some form of memory corruption, which would in turn cause some <strong>bad behavior</strong> that would then cause a watchdog timer reset. Toyota relies on this assumption to claim that stack overflow does not occur because no reset occurred during testing.&#8221; (emphasis added)
</p></blockquote>
<p>I have written about what really happens during stack overflow before (<a href="http://embeddedgurus.com/barr-code/2010/03/firmware-specific-bug-4-stack-overflow/">Firmware-Specific Bug #4: Stack Overflow</a>) and this explains why a reset may not result and also why it is so hard to trace a stack overflow back to that root cause. (From page 20, in NASA&#8217;s words: &#8220;The system stack is limited to just 4096 bytes, it is therefore important to secure that no execution can exceed the stack limit. This type of check is normally simple to perform in the absence of recursive procedures, which is standard in safety critical embedded software.&#8221;)</p>
<p>Similarly, &#8220;Toyota designed the software with a high margin of safety with respect to deadlines and timeliness. &#8230; [but] documented no formal verification that all tasks actually meet this deadline requirement.&#8221; and &#8220;All verification of timely behavior is accomplished with CPU load measurements and other measurement-based techniques.&#8221; It&#8217;s not clear to me if the NASA team is saying it buys those Toyota explanations or merely wanted to write them down. However, I do not see a sufficient explanation in this wording from page 132:</p>
<blockquote><p>
&#8220;The [worst case execution time] analysis and recursion analysis involve two distinctly different problems, but they have one thing in common: Both of their failure modes would result in a CPU reset. &#8230; These potential malfunctions, and many others such as concurrency deadlocks and CPU starvation, would <strong>eventually</strong> manifest as a spontaneous system reset.&#8221; (emphasis added)
</p></blockquote>
<p>Might not a <a href="http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-7-deadlock/">deadlock</a>, starvation, <a href="http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-8-priority-inversion/">priority inversion</a>, or infinite recursion be capable of producing a bit of &#8220;bad behavior&#8221; (perhaps even unintended acceleration) before that &#8220;eventual&#8221; reset? Or might not a stack overflow just corrupt one or a few important variables a little bit and that result in bad behavior rather than or before a result? These kinds of possibilities, even at very low probabilities, are important to consider in light of NASA&#8217;s calculation that the U.S.-owned Camry 2002-2007 fleet alone is running this software a cumulative one billion hours per year.</p>
<p><strong>Paths Not Taken</strong></p>
<p>My second observation is based upon reflection on the steps NASA might have taken in its review of Toyota&#8217;s ETCS-i firmware, but apparently did not. Specifically, there is no mention anywhere (unless it was entirely redacted) of: </p>
<ul>
<li><a href="http://www.netrino.com/Embedded-Systems/How-To/RMA-Rate-Monotonic-Algorithm">rate monotonic analysis</a>, which is a technique that Toyota could have used to validate the critical set of tasks with deadlines and higher priority ISRs (and that NASA could have applied in its review),</li>
<li><a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity">cyclomatic complexity</a>, which NASA might have used as an additional winnowing tool to focus its limited time on particularly complex and hard to test routines,</li>
<li><a href="http://www.fda.gov/MedicalDevices/DeviceRegulationandGuidance/GuidanceDocuments/ucm089543.htm">hazard analysis and mitigation</a>, as those terms are defined by FDA guidelines regarding software contained in medical devices, nor</li>
<li>any discussion or review of Toyota&#8217;s specific software testing regimen and bug tracking system.
</ul>
<p>Importantly, there is also a complete absence of discussion of how Toyota&#8217;s ETCS-i firmware versions evolved over time. Which makes and models (and model years) had which versions of that firmware? (Presumably there were also hardware changes worthy of note.) Were updates or patches ever made to cars once they were sold, say while at the dealer during official recalls or other types of service?</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2011/03/what-nhtsanasa-didnt-consider-re-toyotas-firmware/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Unintended Acceleration and Other Embedded Software Bugs</title>
		<link>http://embeddedgurus.com/barr-code/2011/03/unintended-acceleration-and-other-embedded-software-bugs/</link>
		<comments>http://embeddedgurus.com/barr-code/2011/03/unintended-acceleration-and-other-embedded-software-bugs/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 19:09:54 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[outsourcing]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=517</guid>
		<description><![CDATA[Last month, NHTSA and the NASA Engineering and Safety Center (NESC) published reports of their joint investigation into the causes of unintended acceleration in Toyota vehicles. NASA&#8217;s multi-disciplinary NESC technical team was asked, by Congress, to assist NHTSA by performing a review of Toyota&#8217;s electronic throttle control and the associated embedded software. In carefully worded [...]]]></description>
			<content:encoded><![CDATA[<p>Last month, <a href="http://www.nhtsa.dot.gov">NHTSA</a> and the <a href="http://www.nasa.gov/offices/nesc/home/index.html">NASA Engineering and Safety Center (NESC)</a> published reports of their joint investigation into the causes of unintended acceleration in Toyota vehicles. NASA&#8217;s multi-disciplinary NESC technical team was asked, by Congress, to assist NHTSA by performing a review of Toyota&#8217;s electronic throttle control and the associated embedded software. In carefully worded concluding statement, NASA stated that it &#8220;found no electronic flaws in Toyota vehicles capable of producing the large throttle openings required to create dangerous high-speed unintended acceleration incidents.&#8221; (The official reports and a number of supporting files are available for download at <a href="http://www.nhtsa.gov/UA">http://www.nhtsa.gov/UA</a>.)</p>
<p>The first thing you will notice if you join me in trying to judge the technical issues for yourself are the redactions: pages and pages of them. In parts and entirely for unexplained reasons, this report on automotive electronics reads like the public version of a CIA Training Manual. I&#8217;ve observed that approximately 193 of the 1,061 pages released so far feature some level of redaction (via black boxes, which obscure from a single number, word, or phrase to a full table, page, or section). The redactions are at their worst in NASA&#8217;s <a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NASA_FR_Appendix_A_Software.pdf">Appendix A</a>, which describes NASA&#8217;s review of Toyota&#8217;s embedded software in detail. More than half of all the pages with redactions (including the vast majority of fully redacted tables, pages, and sections) are in that Appendix.</p>
<p>Despite the redactions, we can still learn some interesting facts about Toyota&#8217;s embedded software and NASA&#8217;s technical review of the same.  The bulk of the below outlines what I&#8217;ve been able to make sense of in about two days of reading.  Throughout, my focus is on embedded software inside the electronic throttle control, so I&#8217;m leaving out considerations of other potential causes, including EMI (which NASA also investigated).  First a little background on the investigation.</p>
<p><strong>Background</strong></p>
<p>Although the inquiry was taken to examine unintended acceleration reports across all Toyota, Scion, and Lexus models, NASA focused its technical inquiry almost entirely on Toyota Camry models equipped with the <em>Electronic Throttle Control System, Intelligent</em> (ETCS-i). The Camry has long been among the top cars bought in the U.S., so this choice probably made finding relevant complaint data and affected vehicles easier for NHTSA. (BTW, NASA says the voluntary complaint database shows both that unintended accelerations were reported before the introduction of electronic throttle control and that press coverage and Congressional hearings can increase the volume of complaints.)</p>
<p>According to a press release by the company made upon publication of the NHTSA and NASA reports, Toyota&#8217;s ETCS-i has been installed in &#8220;more than 40 million cars and trucks sold around the world, including more than 16 million in the United States.&#8221; Undoubtedly, ETCS-i has also &#8220;made possible significant safety advances such as vehicle stability control and traction control.&#8221; But as with any other embedded system there have been refinements made through the years to both the electronics and the embedded software. </p>
<p>Though Toyota apparently made available, under agreed terms and via its attorneys, schematics, design documents, and source code &#8220;for multiple Camry years and versions&#8221; (Appendix A, p. 9) as well as many of the Japanese engineers involved in its design and evolution, NASA only closely examined one version. In NASA&#8217;s words, &#8220;The area of emphasis will be the 2005 Toyota Camry because this vehicle has a consistently high rate of reported &#8216;UA events&#8217; over all Toyota models and all years, when normalized to the number of each model and year, according to NHTSA data.&#8221; (p. 7) Except as otherwise stated, everything else in this column concerns the electronics and firmware found in that year, make, and model.</p>
<p><strong>Event Data Recorders</strong></p>
<p>Event Data Recorder (EDR) is the generic term for the automotive equivalent of an aircraft black box <a href="http://en.wikipedia.org/wiki/Flight_data_recorder">flight data recorder</a>. EDRs were first installed in cars in the early 1990s and have increased in use as well as sophistication in the years since. Generally speaking, the event data recorder is an embedded system residing within the airbag control module located in the front center of the engine compartment. The event data recorder is connected to other parts of the car&#8217;s electronics via the CAN bus and is always monitoring vehicle speed, the position of the brake and accelerator pedals, and other key parameters. </p>
<p>In the event of an impossibly high (for the vehicle operating normally) acceleration or deceleration sensor reading, Toyota&#8217;s latest event data recorders save the prior five 1Hz samples of these parameters in a non-volatile memory area. Once saved, an event record can be read over the car&#8217;s On-Board Diagnostics (OBD) port (or, in the event of a more severe accident, directly from the airbag control module) via a special cable and PC software. If the airbag actually deploys, the event record will be permanently locked. The last 2 or 3 (depending on version) lesser &#8220;bump&#8221; records are also stored, but may be overwritten in a FIFO manner.</p>
<p>This investigation of Toyota&#8217;s unintended acceleration marked the first time that anyone from NHTSA had ever read data from a Toyota event data recorder. (Toyota representatives apparently testified in Congress that there had previously just been one copy of the necessary PC software in the U.S.) As part of this study, NHTSA validated and used tools provided by Toyota to extract historical data from 52 vehicles involved in incidents of unintended acceleration, with acknowledged bias toward geographically reachable recent events. After reviewing driver and other witness statements and examining said black box data, NHTSA concluded that 39 of these 52 events were explainable as &#8220;pedal misapplications.&#8221; That&#8217;s a very nice way of saying that whenever the driver reported &#8220;stepping on the brake&#8221; he or she had pressed the accelerator pedal by mistake. Figure 5 of a <a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NHTSA-Toyota_EDR_field_inspection.pdf">supplemental report describing these facts</a> portrays an increasing likelihood of such incidents with driver age vs. the bell curve of Camry ownership by age.</p>
<p>Note that no record is apparently ever made, in the event data recorder or elsewhere, of any events or state changes within the ETCS-i firmware. So-called &#8220;Diagnostic Trouble Codes&#8221; concerning sensor and other hardware failures are recorded in non-volatile memory and the presence of one or more such codes enables the &#8220;Check Engine&#8221; light on the dashboard. But no logging is done of significant software faults, including but not limited to watchdog-initiated resets. </p>
<p><strong>Engine Control Module</strong></p>
<p>ETCS-i is a collection of components and features that was changed in the basic engine design when Toyota switched from mechanical to electronic throttle control. (Electronic throttle control is also known as &#8220;throttle-by-wire&#8221;.) Toyota has used two different types of pedal sensors in the ETCS-i system, always in a redundant fashion. The earlier design, pre-2007, using potentiometers was susceptible to current leakage via growth of <a href="http://nepp.nasa.gov/whisker/">tin whiskers</a>. Though this type of failure was not known to cause sudden high-speed behaviors, it did seem to be associated with a higher number of warranty claims. The newer pedal sensor design uses <a href="http://en.wikipedia.org/wiki/Hall_effect_sensor">Hall effect sensors</a>.</p>
<p>Importantly, the brakes are not a part of the ETCS-i system. In the 2005 Camry, Toyota&#8217;s brake pedal was mechanically controlled. (It may still be.) It appears this is one of the reasons the NASA team felt comfortable with their conclusion that driver reports of wide open throttle behavior that could not be stopped with the brakes were not caused by software failures (alone). &#8220;The NESC team did not find an electrical path from the ETCS-i that could disable braking.&#8221; (<a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NASA-UA_report.pdf">NASA Report</a>, p. 15) It is clear, though, that power assisted brakes lose the enabling vacuum pressure when the throttle is wide open and the driver subsequently pumps the brakes; thus any system failure that opened the throttle could indirectly make bringing the vehicle to a stop considerably harder.</p>
<p>The Engine Control Module at the heart of the ETCS-i consists of a Main-CPU and a Sub-CPU located within a pair of ASICs. The Sub-CPU contains a set of A/D converters that translates raw sensor inputs, such as voltages VPA and VPA1 from the accelerator pedal, into digital position values and sends them to the Main-CPU via a serial interface. In addition, the Sub-CPU monitors the outputs of the Main-CPU and is able to reset (in the manner of a watchdog timer) the Main-CPU.</p>
<p>The Main-CPU is reported to be a <a href="http://america2.renesas.com/docs/files/U14559EJ2V0UM00.pdf">V850E1</a> microcontroller, which is &#8220;a 32-bit RISC CPU core for ASIC&#8221; designed by Renesas (nee NEC). The V850E1 processor has a 64MB program address space, which is part of an overall 4GB linear address space. The Main-CPU also keeps tabs on the Sub-CPU and can reset it if anything is found wrong.</p>
<p>NASA reports that the embedded software in the Main-CPU is written (mostly) in ANSI C and compiled using a <a href="http://www.ghs.com">GreenHills</a> C compiler (Appendix A, p. 14). Furthermore, an <a href="http://en.wikipedia.org/wiki/OSEK">OSEK</a>-compliant real-time operating system with fixed-priority preemptive scheduling is used to manage a redacted (but apparently larger than ten, based on the size of the redaction) number of real-time tasks. The actual firmware development (design, coding and unit testing) was outsourced to <a href="http://www.globaldenso.com/en/">Denso</a> (p. 19). Toyota apparently performed integration testing and ran several commercial and in-house static analysis tools, including <a href="http://www.programmingresearch.com/qac_main.html">QAC</a> (p. 20). The code was written in English, with Japanese comments and design documents, and follows a proprietary Toyota naming convention/coding standard that predates but half overlaps with the 1998 version of <a href="http://www.misra-c.com/Activities/MISRAC/tabid/160/Default.aspx">MISRA-C</a>.</p>
<p><strong>Are There Bugs in Toyota&#8217;s Firmware?</strong></p>
<p>In the NASA Report&#8217;s executive summary it is made clear that &#8220;because proof that the ETCS-i caused the reported UAs was not found does not mean it could not occur.&#8221; (NASA Report, p. 17) The report also states that NASA&#8217;s analysis was time-limited and top-down, remarking &#8220;The Toyota Electronic Throttle Control (ETC) was far more complex than expected involving hundreds of thousands of lines of software code&#8221; and that this <a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NHTSA-Toyota_peer_review.pdf">affected the quality of a planned peer review</a>.</p>
<p>It&#8217;s stated that &#8220;Reported [Unintended Accelerations (UAs)] are rare events. Typically, the reporting of UAs is about 1/100,000 vehicles/year.&#8221; But there are millions of cars on the road, and so NHTSA has collected some &#8220;831 UA reports for Camry&#8221; alone. &#8220;Over one-half of the reported events described large (greater than 25 degrees) high-throttle opening UAs of unknown cause&#8221; (NASA Report, p. 14), the causes of which are never fully explained in these reports.</p>
<p>The NASA apparently identified some lesser firmware bugs themselves, saying &#8220;[our] logic model verifications identified a number of potential issues. All of these issues involved unrealistic timing delays in the multiprocessing, asynchronous software control flow.&#8221; (Appendix A, p. 11)  NASA also spent time simulating possible <a href="http://embeddedgurus.com/barr-code/2010/02/firmware-specific-bug-1-race-condition/">race conditions</a> due to worrisome &#8220;recursively nested interrupt masking&#8221; (pp, 44-46); note, though, that simulation success is not a sufficient proof of lack of races. As well, the NASA team seems to recommend &#8220;reducing the amount of global data&#8221; (p. 38) and eliminating &#8220;dead code&#8221; (p. 40). </p>
<p>Additionally, the redacted text in other parts of Appendix A seems to be obscuring that:</p>
<ul>
<li>&#8220;<a href="http://gcc.gnu.org/">The standard gcc compiler</a> version 4&#8243; generated a redacted number of warnings (probably larger than 100) about the code, in 11 different warning categories. (p. 25)</li>
<li>&#8220;<a href="http://www.coverity.com/">Coverity</a> version 4.2&#8243; generated a redacted number of warnings (probably larger than 154) about the code, in 10 different warning categories. (p. 27)</li>
<li>&#8220;<a href="http://www.grammatech.com/products/codesonar/">Codesonar</a> version 3.6p1&#8243; generated a redacted number of warnings (probably larger than 136) about the code, in 10 different warning categories.</li>
<li>&#8220;<a href="http://spinroot.com/uno/">Uno</a> version 2.12&#8243; generated a redacted number of warnings (probably larger than 72) about the code, in 9 different warning categories.</li>
<li>The code contained at least 347 deviations from a subset of 14 of the <a href="http://www.misra-c.com/Activities/MISRAC/tabid/160/Default.aspx">MISRA-C rules</a>.</li>
<li>The code contained at least 243 violations of a subset of 9 of the 10 &#8220;<a href="http://spinroot.com/p10">Power of 10&#8211;Rules for Developing Safety Critical Code</a>,&#8221; which was published in IEEE Computer in 2006 by NASA team member Gerard Holzmann.</li>
</ul>
<p>It looks to me like Figure 6.2.3-1 of the NASA Report (p. 30) shows that UA complaints filed with NHTSA increased in the year of introduction of electronic throttle control for the vast majority of Toyota, Scion, and Lexus models&#8211;and that complaint counts have remained higher but generally declined over time since those transitions years. Such a complaint data pattern is perhaps consistent with firmware bugs. (Note to NHTSA: It would be helpful to see this same chart normalized by number of vehicles sold by model year and with the rows sorted by the year of ETC introduction. It would also be nice to see a chart of ETCS-i firmware versions and updates, which vehicles they apply to, and the dates on which each was put into new production vehicles or distributed through dealers.)</p>
<p><strong>Final Thoughts</strong></p>
<p>I am not privy to all of the facts considered by the NHTSA or NASA review teams and thus cannot say if I agree or disagree with their overall conclusion that embedded software bugs are not to blame for reports of unintended acceleration in Toyota vehicles. How about you? If you&#8217;ve spotted something I missed in the reports from NHTSA or NASA, please send me an e-mail or leave a comment below. Let&#8217;s keep the conversation going.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2011/03/unintended-acceleration-and-other-embedded-software-bugs/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Embedded Software is the Future of Product Quality and Safety</title>
		<link>http://embeddedgurus.com/barr-code/2010/02/embedded-software-is-the-future-of-product-quality-and-safety/</link>
		<comments>http://embeddedgurus.com/barr-code/2010/02/embedded-software-is-the-future-of-product-quality-and-safety/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 18:18:00 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[embedded]]></category>
		<category><![CDATA[engineering]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/08/embedded-software-is-the-future-of-product-quality-and-safety/</guid>
		<description><![CDATA[Last year a friend had a St. Jude pacemaker attached to his heart. When he reported an unexpected low battery reading (displayed on an associated digital watch) to his doctor a month later, he learned this was the result of a firmware bug known to the manufacturer. The battery was fine and would last on [...]]]></description>
			<content:encoded><![CDATA[<p>Last year a friend had a <a href="http://www.sjmprofessional.com/en/Products/US/Pacing-Systems/Accent-Pacemaker.aspx">St. Jude pacemaker</a> attached to his heart.  When he reported an unexpected low battery reading (displayed on an associated digital watch) to his doctor a month later, he learned this was the result of a firmware bug known to the manufacturer.  The battery was fine and would last on the order of a decade more.  His new-model pacemaker&#8217;s firmware didn&#8217;t include a bug fix that was provided the year before to wearers of old-model.</p>
<p>Another friend owns a <a href="http://www.landroverusa.com/us/en/Vehicles/new-LR2/overview.htm">Land Rover LR2</a> SUV with back-up sensors.  When the car is in reverse and nearing an obstacle or another car, the driver is alerted via a beeping sound.  Except that the back-up sensors don&#8217;t always work.  Some &#8220;reboots&#8221; of the SUV don&#8217;t seem to have this feature enabled.  He suspects there is a &#8220;<a href="http://www.netrino.com/Embedded-Systems/Glossary-R#race_condition">race condition</a>&#8221; during the software startup sequence.</p>
<p>Yet another friend has driven a <a href="http://www.toyota.com/prius-hybrid/">Toyota Prius</a> hybrid over 100,000 miles.  He reports that the brakes very occasionally have an odd/different feel.  But his older model Prius is not expected to be subject to <a href="http://www.huffingtonpost.com/2010/02/08/toyota-recall-prius-hybri_n_453188.html">the 2010 model year recall</a>.</p>
<p>These are just a few of the personal anecdotes behind the headlines.  Embedded software is everywhere now, with <a href="http://www.embeddedgurus.net/barr-code/2008/03/vdc-counts-4-billion-embedded-products.html">over 4 billion new devices manufactured each year</a>.  Increasingly the quality and safety of products is a side-effect of the quality and safety of the software embedded inside.</p>
<p>One important question is, can we trust future software updates any more than we can trust the existing firmware?  How do we know that the Toyota Prius hybrids with upgraded braking firmware will be safer than those with the factory firmware?</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2010/02/embedded-software-is-the-future-of-product-quality-and-safety/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Embedded Programmers Worldwide Earn Failing Grades in C and C++</title>
		<link>http://embeddedgurus.com/barr-code/2009/11/embedded-programmers-worldwide-earn-failing-grades-in-c-and-c/</link>
		<comments>http://embeddedgurus.com/barr-code/2009/11/embedded-programmers-worldwide-earn-failing-grades-in-c-and-c/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 15:30:00 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[education]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[outsourcing]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/11/24/embedded-programmers-worldwide-earn-failing-grades-in-c-and-c/</guid>
		<description><![CDATA[In industry surveys, over 80% of embedded software developers report using C or C++ as their primary programming language. Yet as a group, these programmers earned a failing grade on a multiple-choice quiz testing firmware-related C programming skills. A scary result, considering that embedded software inside medical devices, industrial controls, anti-lock brakes, and cockpits place [...]]]></description>
			<content:encoded><![CDATA[<p>In industry surveys, <a href="http://i.cmpnet.com/embedded/2009/0709_July2009/0709esdBarr01.gif">over 80% of embedded software developers report using C or C++</a> as their primary programming language.  Yet as a group, these programmers earned a failing grade on a multiple-choice quiz testing firmware-related C programming skills.  A scary result, considering that embedded software inside medical devices, industrial controls, anti-lock brakes, and cockpits place human lives at risk every day.</p>
<p>In a <a href="http://www.embeddedgurus.net/barr-code/2008/02/embedded-c-quiz-results.html">February 2008 blog post</a>, I examined the first few hundred results from the &#8220;<a href="http://www.netrino.com/Embedded-Systems/Embedded-C-Quiz">Embedded C Quiz</a>&#8221; on the <a href="http://www.netrino.com/">Netrino</a> website.  That analysis compared the performance of programmers in the U.S. and India with the rest of the world (the only three data sets large enough for meaningful analysis).  I concluded that the average embedded programmers in the U.S. and India don&#8217;t know C very well, but do know it better than programmers in the rest of the world.</p>
<p>Two years now since launching the quiz, we have collected thousands of data points, so it&#8217;s time for an update on programmer performance.  In total, 3,870 programmers have taken the <a href="http://www.netrino.com/Embedded-Systems/Embedded-C-Quiz">short 10-question multiple-choice C skills test</a>.  A few (a bit less than 3%) didn&#8217;t answer all of the questions; the analysis below is based on just the 3,755 completed quizzes.  (Note that each website user can only take the quiz once.)</p>
<p>Across all countries, the mean result was 60.8%&#8211;a grade of &#8216;D-&#8217; at best.   That is to say that the average embedded programmer answered just 6 out of 10 multiple-choice questions correctly.  A rather scary fact, given that C is the language of choice for most embedded projects and that C++ is even harder to master.</p>
<p>Programmers in the United States scored slightly above average.  But they still earned a failing grade of 61.8%.  Programmers in India scored slightly below the worldwide average, at 58.9%.  Together, programmers from these two large English-speaking countries accounted for the majority of all quiz takers.</p>
<p>The number of completed quizzes, mean scores, and standard deviations for all countries with more than 20 completed quizzes are shown in the table below, sorted by average score.  In general, programmers from European countries scored best.</p>
<table>
<tbody>
<tr>
<td>Country</td>
<td>Completed</td>
<td>Mean</td>
<td>Std Dev</td>
</tr>
<tr>
<td>Poland</td>
<td>23</td>
<td>68.7</td>
<td>19.2</td>
</tr>
<tr>
<td>Sweden</td>
<td>26</td>
<td>67.7</td>
<td>15.8</td>
</tr>
<tr>
<td>Australia</td>
<td>45</td>
<td>67.3</td>
<td>22.3</td>
</tr>
<tr>
<td>Germany</td>
<td>57</td>
<td>67.2</td>
<td>17.2</td>
</tr>
<tr>
<td>France</td>
<td>35</td>
<td>66.9</td>
<td>24.0</td>
</tr>
<tr>
<td>United Kingdom</td>
<td>109</td>
<td>66.1</td>
<td>22.8</td>
</tr>
<tr>
<td>Spain</td>
<td>24</td>
<td>65.0</td>
<td>18.3</td>
</tr>
<tr>
<td>Canada</td>
<td>114</td>
<td>64.5</td>
<td>19.3</td>
</tr>
<tr>
<td>China</td>
<td>51</td>
<td>64.1</td>
<td>23.4</td>
</tr>
<tr>
<td>Israel</td>
<td>22</td>
<td>62.3</td>
<td>21.7</td>
</tr>
<tr>
<td>United States</td>
<td>1346</td>
<td>61.8</td>
<td>20.4</td>
</tr>
<tr>
<td>Egypt</td>
<td>28</td>
<td>59.3</td>
<td>22.8</td>
</tr>
<tr>
<td>India</td>
<td>1288</td>
<td>58.9</td>
<td>22.4</td>
</tr>
<tr>
<td>Romania</td>
<td>45</td>
<td>58.9</td>
<td>23.0</td>
</tr>
<tr>
<td>Singapore</td>
<td>24</td>
<td>58.3</td>
<td>20.1</td>
</tr>
<tr>
<td>Italy</td>
<td>44</td>
<td>56.4</td>
<td>20.8</td>
</tr>
<tr>
<td>Turkey</td>
<td>57</td>
<td>55.6</td>
<td>23.3</td>
</tr>
<tr>
<td>Brazil</td>
<td>47</td>
<td>55.1</td>
<td>24.1</td>
</tr>
<tr>
<td>Pakistan</td>
<td>25</td>
<td>44.0</td>
<td>21.7</td>
</tr>
</tbody>
</table>
<p>How are your embedded C programming skills?  Test them by taking the Embedded C Quiz yourself now at <a href="http://www.netrino.com/Embedded-Systems/Embedded-C-Quiz">http://www.netrino.com/Embedded-Systems/Embedded-C-Quiz</a>?</p>
<p>P.S. &nbsp;We recently launched an <a href="http://www.netrino.com/Embedded-Systems/Embedded-C++-Quiz">Embedded C++ Quiz</a> and the results so far look downright abysmal. &nbsp;I&#8217;ll write something about that in a future post. &nbsp;Do you have a few minutes to <a href="http://www.netrino.com/Embedded-Systems/Embedded-C++-Quiz">take that one too</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2009/11/embedded-programmers-worldwide-earn-failing-grades-in-c-and-c/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Breathalyzer Source Code Analysis</title>
		<link>http://embeddedgurus.com/barr-code/2009/11/breathalyzer-source-code-analysis/</link>
		<comments>http://embeddedgurus.com/barr-code/2009/11/breathalyzer-source-code-analysis/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 21:59:00 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/11/05/breathalyzer-source-code-analysis/</guid>
		<description><![CDATA[Firmware bugs seem to be everywhere these days. So much so that firmware source code analysis is even entering the courtroom in criminal cases involving data collection devices with software inside. Consider the precedent-setting case of the Alcotest 7110. After a two-year legal fight, seven defendants in New Jersey DUI cases successfully won the right [...]]]></description>
			<content:encoded><![CDATA[<p>Firmware bugs seem to be everywhere these days.  So much so that firmware source code analysis is even entering the courtroom in criminal cases involving data collection devices with software inside.  Consider the precedent-setting case of the Alcotest 7110.  After a two-year legal fight, <a href="http://www.dwi.com/new-jersey/state-v-chun">seven defendants in New Jersey DUI cases</a> successfully won the right to have their experts review the source code for the Alcotest firmware.</p>
<p>The state and the defendants both ultimately produced expert reports evaluating the quality of the firmware source code.  Though each side’s experts reached divergent opinions as to the overall code quality, several facts seem to have emerged as a result of the analysis:</p>
<p>- Of the available 12-bits of A/D precision, just 4-bits (most-significant) are used in the actual calculation.  This sorts each raw blood-alcohol reading into one of 16 buckets.  (I wonder how they biased the rounding on that.)<br />- Out of range A/D readings are forced to the high or low limit.  This must happen with at least 32 consecutive readings before any flags are raised.<br />- There is no feedback mechanism for the software to ensure that actuated devices, such as an air pump and infrared sensor, are actually on or off when they are supposed to be.<br />- The software first averages the initial two readings.  Then it averages the third reading with that average.  Then the fourth reading is averaged in, etc.  No comments or documentation explains the use of this formula, which causes the final reading to have a weight of 0.5 in the final value and the one before that to have a weight of 0.25, etc.<br />- Out of range averages are forced to the high or low limit too.<br />- Static analysis with <a href="http://www.gimpel.com">lint</a> produced over 19,000 warnings about the code (that’s about three errors for ever five lines of source code).</p>
<p>What would you infer about the reliability of a defendant’s blood-alcohol level if you were on that jury?  If you’re so inclined you can read the full expert reports for yourself: at <a href="http://www.dwi.com/new-jersey/base-one-findings">defendants</a> and <a href="http://www.dwi.com/new-jersey/new-jersey/code-review">state</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2009/11/breathalyzer-source-code-analysis/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>This Code Stinks! The Worst Embedded Code Ever</title>
		<link>http://embeddedgurus.com/barr-code/2009/11/this-code-stinks-the-worst-embedded-code-ever/</link>
		<comments>http://embeddedgurus.com/barr-code/2009/11/this-code-stinks-the-worst-embedded-code-ever/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 16:19:00 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[education]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/11/05/this-code-stinks-the-worst-embedded-code-ever/</guid>
		<description><![CDATA[At the Embedded Systems Conference Boston in September, I gave a popular ESC Theater talk titled “This Code Stinks! The Worst Embedded Code Ever” that used lousy code from real products as a teaching tool. The example code was gathered by a number of engineers from a broad swath of companies over several years. (Minor [...]]]></description>
			<content:encoded><![CDATA[<p>At the <a href="http://www.esconline.com">Embedded Systems Conference Boston</a> in September, I gave a popular ESC Theater talk titled “This Code Stinks!  The Worst Embedded Code Ever” that used lousy code from real products as a teaching tool.  The example code was gathered by a number of engineers from a broad swath of companies over several years.  (Minor details, including variable names and function names, were changed as needed to hide the specifics of applications, companies, or programmers.)</p>
<p>Here’s just one example of the bad code in that presentation:<br /><code><br />y = (x + 305) / 146097 * 400 + (x + 305) % 146097 / 36524 * 100 + (x + 305) % 146097 % 36524 / 1461 * 4 + (x + 305) % 146097 % 36524 % 1461 / 365;<br /></code><br />I don’t know if the above snippet contains any bugs, as most of the other examples were found to.  And that’s a problem.  Where are we supposed to begin an analysis of the above?  What is this code supposed to do when it works?  What range of input values is appropriate to test?  What are the correct output values for a given input?  Is this code responsible for handling out of range inputs gracefully?  In the original listing, there were no comments on or around this line to help.</p>
<p>I eventually learned that this code computes the year, with accounting for extra days in leap years, given the number of days since a known reference date (e.g., January 1, 1970).  But I note that we still don’t know if it works in all cases; despite it being present in an <a href="http://www.fda.gov">FDA</a>-regulated medical device.  I note too that the <a href="http://bit.ly/39Ubz8">Microsoft Zune Bug</a> was buried in a much better formatted snippet of code that performed a very similar calculation. </p>
<p>Here’s another example, this time in C++, with the bug finding left as an exercise for the reader:<br /><code><br />bool Probe::getParam(uint32_t param_id, int32_t idx)<br />{<br />int32_t  val  = 0;<br />int32_t  ret  = 0;</p>
<p>ret = m_pParam-&gt;readParam(param_id, idx, &amp;val);</p>
<p>if (!ret)<br />{<br />logMsg(“attempt to read parameter failed\n”);<br />exit(1);<br />}<br />else …<br /></code><br />Hint: This code was embedded in a piece of factory automation equipment.</p>
<p>I&#8217;ve placed the full set of slides online at <a href="http://bit.ly/badcode">http://bit.ly/badcode</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2009/11/this-code-stinks-the-worst-embedded-code-ever/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Firmware Disasters</title>
		<link>http://embeddedgurus.com/barr-code/2009/06/firmware-disasters/</link>
		<comments>http://embeddedgurus.com/barr-code/2009/06/firmware-disasters/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 11:00:00 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/06/23/firmware-disasters/</guid>
		<description><![CDATA[First, an Airbus A330 fell out of the sky. Then two D.C. Metro trains collided. Several hundred people have been killed and injured in these disastrous system failures. Did bugs in embedded software play a role in either or both disasters? An incident on an earlier (October 2006) Airbus A330 flight may offer clues to [...]]]></description>
			<content:encoded><![CDATA[<p>First, an Airbus A330 fell out of the sky.  Then two D.C. Metro trains collided.  Several hundred people have been killed and injured in these disastrous system failures.  Did bugs in embedded software play a role in either or both disasters?</p>
<p>An incident on an earlier (October 2006) Airbus A330 flight may offer clues to the crash of Air France 447:</p>
<blockquote><p>Qantas Flight 72 had been airborne for three hours, flying uneventfully on autopilot from Singapore to Perth, Australia. But as the in-flight dinner service wrapped up, the aircraft&#8217;s flight-control computer went crazy. The plane abruptly entered a smooth 650-ft. dive (which the crew sensed was not being caused by turbulence) that sent dozens of people smashing into the airplane&#8217;s luggage bins and ceiling. More than 100 of the 300 people on board were hurt, with broken bones, neck and spinal injuries, and severe lacerations splattering blood throughout the cabin.  (<a href="http://www.time.com/time/world/article/0,8599,1902421,00.html">Article, Time Magazine, June 3, 2009</a>)</p></blockquote>
<p>Authorities have blamed a pair of simultaneous computer failures for that event in the fly-by-wire A330.  First, one of three redundant air data inertial reference units (ADIRUs) began giving bad angle of attack (AOA) data.  Simultaneously, a voting algorithm intended to handle precisely such a failure in 1 of the 3 units by relying only on the other matching data failed to work as designed; the flight computer instead made decisions only on the basis of the one failed ADIRU!</p>
<p>(A later analysis by Airbus &#8220;found data fingerprints suggesting similar ADIRU problems had occurred on a total of four flights. One of the earlier instances, in fact, included a September 2006 event on the same [equipment] that entered the uncommanded dive in October [2006].&#8221;  Ibid.)</p>
<p>Much of the attention in the publicly disclosed details of the Air France 447 crash has focused on the failure of one of several air speed indicators.  Were there three of those as well?  If so, was the same flight computer to blame for failing to recognize which to trust and which was unreliable?</p>
<p>It is very early in the investigation of yesterday&#8217;s collision between two D.C. Metro red line trains, in which a stopped train was rear-ended and heavily damaged by a moving train on the same track, to place blame.  But a  WashingtonPost.com article headlined &#8220;Collision was Supposed to be Impossible&#8221; says it all:</p>
<blockquote><p>Metro was designed with a fail-safe computerized signal system that is supposed to prevent trains from colliding.</p></blockquote>
<p>and </p>
<blockquote><p>During morning and afternoon rush hours, all trains except longer eight-car trains typically operate in automatic mode, meaning their movements are controlled by computerized systems and the central Operations Control Center. Both trains in yesterday&#8217;s crash [about 5pm] were six-car trains. (<a href="http://www.washingtonpost.com/wp-dyn/content/article/2009/06/23/AR2009062300653.html?hpid=topnews">Article, Washington Post, June 23, 2009</a>)</p></blockquote>
<p>Are bugs in embedded software to blame for these two disasters?  You can bet the lawyers are already looking into it.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2009/06/firmware-disasters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Resume Inflation</title>
		<link>http://embeddedgurus.com/barr-code/2009/01/resume-inflation/</link>
		<comments>http://embeddedgurus.com/barr-code/2009/01/resume-inflation/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 21:00:00 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/01/14/resume-inflation/</guid>
		<description><![CDATA[Like many companies, Netrino is perpetually interviewing candidates for software engineering positions. However, since our work is primarily in the area of embedded systems design we tend to meet many software candidates who come originally from electrical engineering backgrounds. Among this group of candidates there is a prevalent bias toward a kind of resume inflation, [...]]]></description>
			<content:encoded><![CDATA[<p>Like many companies, <a href="http://www.netrino.com">Netrino</a> is perpetually interviewing candidates for software engineering positions.  However, since our work is primarily in the area of embedded systems design we tend to meet many software candidates who come originally from electrical engineering backgrounds.  Among this group of candidates there is a prevalent bias toward a kind of resume inflation, in the technical skills section.</p>
<p>Almost all of the resumes we receive for firmware engineering positions contain one of the strings &#8220;C, C++&#8221; or &#8220;C/C++&#8221; at or near the front of a longer list of programming language skills (e.g., &#8220;C/C++, Fortran, Assembly (various), Forth&#8221;).  C is generally at the front of that language list for good reason&#8211;because it is the one programming language with which the candidate has the most hands-on experience.  Too often, though, our interviews have revealed that C++ is listed second for no good reason.</p>
<p>C and C++ are fundamentally different languages.  Many of these &#8220;resume inflation&#8221; job candidates don&#8217;t even realize that C++ is as different as it is from C.  Often, their actual experience with C++ turns out to be that they&#8217;ve used C++ compilers to build C programs.  And when they really have used C++, their practical experience usually ends at the use of classes.</p>
<p>Object-oriented C++ has three important aspects: encapsulation, inheritance, and polymorphism.  Mere use of encapsulation is insufficient to claim you have C++ programming skills.  When we include C++ in a <a href="http://www.netrino.com/Embedded-Systems/Embedded-Software-Jobs">job listing</a> it is because the work may involve the use of every part of C++.  To get the job, you must be knowledgeable in all of C++.</p>
<p>What can you do if you are submitting your resume and know some C++ rather than a lot?  Be clear and humble.  If you merely worked with C++ in school or on a single project, list it in a separate section.  Or put C++ apart from C in your language list.</p>
<p>Interviewers (as well as resume reviewers) are impressed by modesty and clear communication.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2009/01/resume-inflation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

