<?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>Abort, Retry, Hack? &#187; marcan</title>
	<atom:link href="http://marcansoft.com/blog/author/marcan/feed/" rel="self" type="application/rss+xml" />
	<link>http://marcansoft.com/blog</link>
	<description>[ marcan&#039;s blog ]</description>
	<lastBuildDate>Sat, 14 Jan 2012 19:32:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>OpenLase hardware and simulator</title>
		<link>http://marcansoft.com/blog/2011/01/openlase-hardware-and-simulator/</link>
		<comments>http://marcansoft.com/blog/2011/01/openlase-hardware-and-simulator/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 19:48:00 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=324</guid>
		<description><![CDATA[I apologize for taking this long to post this! I&#8217;ve been busy non-stop since 27c3 and never got a chance to get around to it. Finally, though, here it is: the description of the Mark 1 laser projector that I use with OpenLase. But wait, there&#8217;s more! If you don&#8217;t have the hardware and don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I apologize for taking this long to post this! I&#8217;ve been busy non-stop since 27c3 and never got a chance to get around to it. Finally, though, here it is: the description of the <a href="/blog/openlase/hardware-mark-1/">Mark 1 laser projector</a> that I use with OpenLase.</p>
<p>But wait, there&#8217;s more! If you don&#8217;t have the hardware and don&#8217;t want to build it, or you want to try out OpenLase, or you want to be able to mess around with it on the go, you can now do that. There&#8217;s a new OpenGL-based simulator in the OpenLase tree. It works off of the JACK data (so you still need JACK) and it tries to simulate the dynamics of my laser scanner, including brightness effects and some of the physical limitations of the galvos. Here&#8217;s a comparison of the simulator vs. the real thing:</p>
<p><iframe class="youtube-player" width="440" height="360" src="//www.youtube.com/embed/hoWCNKhZCbk" frameborder="0"><br />
</iframe></p>
<p>I&#8217;m aware that documentation on the software is still sorely lacking. Please bear with me while I get my act together and write that up <img src='http://marcansoft.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2011/01/openlase-hardware-and-simulator/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Safe Hacking</title>
		<link>http://marcansoft.com/blog/2011/01/safe-hacking/</link>
		<comments>http://marcansoft.com/blog/2011/01/safe-hacking/#comments</comments>
		<pubDate>Wed, 19 Jan 2011 01:56:03 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=275</guid>
		<description><![CDATA[Or how to practice Safe Hex Ah, the world of computers. Thanks to the wonderful world of bits and bytes, we can experiment with any application, file, driver, or even the core operating system. Rip them apart, change things, put them together, and if it doesn&#8217;t work, just try again. At worst, you&#8217;ll have to [...]]]></description>
			<content:encoded><![CDATA[<p><i>Or how to practice Safe Hex</i></p>
<p>Ah, the world of computers. Thanks to the wonderful world of bits and bytes, we can experiment with any application, file, driver, or even the core operating system. Rip them apart, change things, put them together, and if it doesn&#8217;t work, just try again. At worst, you&#8217;ll have to wipe your hard drive and start over. If you somehow manage to destroy a computer purely through bad software, that&#8217;s considered a design problem and a true feat to pull off. Just think about it: what other profession or hobby lets you experiment as much as you want and make as many mistakes as you want without having to spend a cent if you do something wrong?</p>
<p>Unfortunately, things have changed. Ever since the advent of embedded devices with upgradable firmware, people have been trying to modify and hack them. These devices are usually a lot less resilient than their bigger, older siblings. Many of the new shiny gadgets that we use every day are internally fragile and a slight software mishap can render them non-functional, a &#8220;brick&#8221;.</p>
<p>This is a guide for developers and hackers who work on system firmware for embedded devices.<br />
<span id="more-275"></span><br />
<hr />
<h2>Care About Your Users</h2>
<p>The first step towards safe hacking is to develop a deep appreciation towards your users and, especially, their hardware. Most users are clueless and entirely dependent on you to guide them towards a safe result. While everyone releases hacks with no warranty neither express nor implied, that&#8217;s just to cover their ass. Remember, users are usually completely lost if they make their devices inoperable, and, unlike you, probably won&#8217;t have a backup plan.</p>
<p>One great way to start developing an appreciation for each individual piece of hardware out there is to deeply care for your own. If you&#8217;re a hacker with a very low budget, you probably have this already, as you&#8217;ll want to keep your device functional for as long as possible to avoid having to spend your hard-earned cash on a new one. If you have to perform emergency repairs on it or flashing, take notice every time you do so. You might have had to spend a few hours wiring up a flasher to your device. An average user probably doesn&#8217;t have a chance of being able to do that in a week. And if you have the resources to purchase a few devices for testing purposes, keep in mind that most users don&#8217;t have that luxury. It might be tempting to run wild and experiment once you have a recovery plan in place, but remember, every mistake that you make is a mistake that might slip and end up affecting your users instead. If you take great pains you avoid bricking your own hardware, you&#8217;ll greatly decrease the chances of a critical mistake making its way into the release version.</p>
<p>If you still decide not to care for your users, make it plainly clear in the product documentation that they are entirely on their own, and that you don&#8217;t care about what happens when they run your tool, nor have you make any attempt to make it safe for everyone. They deserve to know.</p>
<h2>Understand the System</h2>
<p>Before you start working on software that makes permanent changes to a device, you should have a deep enough understanding of its operation. Reverse engineer the boot process. Understand what parts of the firmware depend on what. Know what components are vital for boot, and what recovery modes are available, if any. If you&#8217;re the hacker responsible for performing most of the reverse engineering work on the device, you probably already know a good deal about it. If you aren&#8217;t, read documentation, try to understand everything, and talk to the person who is. Explain your idea. They will probably have many useful safety tips for you. Work on less intrusive hacks that will deepen your understanding of the system before moving on to riskier hacks that might end up in a brick. Above all, work with other people who also work on that device. Every extra knowledgeable person working on a firmware hack multiplies its chances of being safe.</p>
<h2>Program Defensively</h2>
<p>Usually, when a program crashes, at worst users get annoyed or lose some data. However, when unstable firmware hacks can mean that devices are irreparably destroyed, entirely different standards apply. Check all error codes. Handle out of memory errors. Make sure there&#8217;s enough free disk space. Make sure headers are sane. If you&#8217;ve never written a stable app before, one that can gracefully handle most exceptional conditions without crashing or doing the wrong thing, you should seriously reconsider working on critical device firmware hacks until you do so. Learn about what kinds of problems to expect on safe ground first, before you move on to shakier terrain.</p>
<p>One great technique to use is to do as much as possible in advance. Gather all required information about the system, read any required data files, prepare any modifications, and only at the very end actually commit the changes to the device. If anything goes wrong during the preparations, you can just abort the entire operation and be certain that the device is still safe. If you don&#8217;t want (or can&#8217;t) architect your program like this, you can still tack it on as an underlying layer. Make the low-level functions that perform the actual changes (e.g. write to Flash) actually write to a temporary buffer instead, and bulk write everything at the very end. This also gives you a chance to check the result of the operation virtually, before it&#8217;s actually committed. It might even speed up your program as a side effect (bulk writes are faster than scattered ones).</p>
<h2>Fail Intelligently</h2>
<p>If you&#8217;ve followed the prior advice, you&#8217;ll have already minimized the amount of code that can fail and cause catastrophic damage to firmware. However, most of the time, there&#8217;s always something that might go wrong at just the wrong time. If a critical operation fails, the worst possible thing you can do is panic the application or otherwise halt! Then you&#8217;re guaranteed to brick the device. Instead, drop the user into some kind of failsafe mode, shell, or launcher, and direct them to keep the device powered on and seek immediate attention (e.g. on an IRC channel). If there&#8217;s a chance of saving the device, even if you have to work together with the user to develop an improvised fix, take it. He or she will be eternally grateful to you.</p>
<h2>Sanity Check</h2>
<p>Don&#8217;t assume anything about the user&#8217;s environment. Manufacturers often release dozens of firmware updates, and the number balloons to hundreds or even thousands if you start to consider the possible combinations of hacks that users might have already applied. Profile the system and ensure that everything is sane before you start. If you need to read any data from a user-supplied file or from the network, make sure it is exactly what you expect it to be. You can&#8217;t possibly have too many sanity checks.</p>
<p>Cryptographic hash algorithms (such as SHA-1) are a great tool here. Build a database of known-good firmware hashes. Include the hash of the expected result after running your program, so you can check against it before actually writing it out. If you miss an existing firmware that would&#8217;ve just worked, that only means you have to add it in and release a new version. If you don&#8217;t perform the check and that firmware turns out to be incompatible, you&#8217;ve just created a whole class of users that will be bricked by your tool. Blind patching is a recipe for disaster.</p>
<p>You should also make your application check itself, to make sure it hasn&#8217;t been corrupted (due to a bad download, bad media, or even bad memory), including any auxiliary files that it needs. Hashes also work great here. You can make this as simple or as complex as you want. You can have the executable check its readonly sections against built-in hashes in memory. Or you can just have a .txt file with hashes of all your files (including the main executable), and check them at runtime before anything else. Sometimes just packing your executable with an executable packer will give you this feature for free (but make sure the packer does, in fact, offer integrity protection).</p>
<h2>Protect Users From Themselves</h2>
<p>Users will do completely stupid things. It&#8217;s not just that they will click on things without understanding what the outcome will be; if you include a big red button that says &#8220;Brick Me!&#8221;, someone will click it too. That&#8217;s why you should at least make it hard for users to destroy their system. Sure, you can just blame them for their own incompetence, but it&#8217;s worth covering for the obvious cases. If there&#8217;s an option in your hack that will undoubtedly brick a user&#8217;s system under a conceivable set of circumstances, check for them and disable the option in that case. There&#8217;s no excuse for having a button that deletes critical system firmware, even if it&#8217;s marked &#8220;delete critical system firmware&#8221;. If such a feature makes sense as part of a longer process that will again result in a functional device, automate the process. If there&#8217;s a reason why a power user or developer might have a use for such a dangerous option, hide it behind a warning or two and make getting to it more annoying. Your software should pass the <i>cat test</i>: if a cat walks all over the keyboard (or touch panel, or game pad, or Kinect), it shouldn&#8217;t be able to cause permanent harm to the system.</p>
<p>This doesn&#8217;t mean that you have to try to envision every single possible situation. Users are extremely good at creatively breaking programs. But, at least, make sure they can&#8217;t accidentally destroy their systems without putting a moderate amount of effort into it.</p>
<h2>Back Up</h2>
<p>You should strongly consider offering a back up option to your users, or even automatically backing up critical information. Sometimes, having a backup can mean the difference between a device that can be fixed with a reasonable amount of effort (say, a hardware flasher), and a device that is forever toast and not even the manufacturer could hope to repair. If the amount of critical information is small, it&#8217;s worth putting the effort in and making sure it is automatically backed up whenever any dangerous operation is about to happen. Test it, to make sure the correct information is saved. And don&#8217;t forget to tell your users that they should keep the backup file in a safe place!</p>
<p>Even if your device is generally &#8220;brick-proof&#8221;, because it has a ROM bootloader that allows flashing, backing up can still be very important. Many devices store unique per-device data alongside the firmware, and the loss of that information can cause a messy repair process involving lots of manual guesswork, or worse, a device that, though technically alive, will never work again as intended (e.g. if critical calibration data or device private keys are lost). This information is usually very small. Back it up! You never know when a silly mistake will end up scribbling all over it.</p>
<h2>Test</h2>
<p>Ideally, you&#8217;ve put enough effort into making sure your application is safe. However, the unexpected can and does happen, and sometimes you will not have the resources to perform a comprehensive enough test. So gather up a few people that you can trust and who are willing to risk it, and perform a closed test. Do not release a public beta! People are way too impatient, and public betas are essentially synonymous with a release; people will ignore any warnings attached. You&#8217;ll want trustworthy people, preferably with the technical knowledge and skill to spot a problem before it is fatal and to have a chance of being able to fix it, if it is. Look for people with hardware experience who can put together some kind of flasher (JTAG, NOR, whatever) if things go terribly wrong.</p>
<p>If your application errors out on some devices, but does not cause any harm, give yourself a pat in the back: congratulations, you&#8217;ve saved your tester from a brick. If it doesn&#8217;t, and you brick your tester&#8217;s device, give yourself a pat in the back: you&#8217;ve saved dozens, hundreds, or thousands of potential end-users from a brick.</p>
<p>You should also make sure you&#8217;ve covered all bases with your testing. If your device has gone through multiple hardware revisions, especially if those changes are at all related to the firmware of the device (e.g. different flash chip vendors, or an entirely different firmware storage device even), you should test on all of them. If you don&#8217;t know, look around and ask. There are plenty of people out there willing to provide you with PCB pictures and chip part numbers that will help you identify any important changes. If you didn&#8217;t consider an entire hardware revision and your hack doesn&#8217;t work as expected on it, you&#8217;re guaranteeing that a huge percentage of your users, potentially thousands or tens of thousands, will brick their devices.<br />
<br />
<hr />
<h2><!-- WTF, WordPress --></h2>
<p>I hope this article convinced you to be careful when you write firmware hacks for embedded devices. If you follow the guidelines in it, you&#8217;ll save money, save your users money, and build a reputation for robust and dependable hacks. These are the previously unwritten principles that Team Twiizers followed when we developed the HackMii Installer, and we haven&#8217;t heard of a single brick out of 1.2 million installs to date. Ultimately, though, whether you follow them is entirely up to you. Is it worth it? You decide.</p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2011/01/safe-hacking/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Syncing music in new iDevices with Linux</title>
		<link>http://marcansoft.com/blog/2011/01/syncing-music-in-new-idevices-with-linux/</link>
		<comments>http://marcansoft.com/blog/2011/01/syncing-music-in-new-idevices-with-linux/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 06:34:21 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=265</guid>
		<description><![CDATA[As you probably already know, libgpod has included support for Apple&#8217;s iOS 2.x hash for a while now. With their new devices, Apple changed the hash again, but for some reason the change only applies to new devices &#8211; old devices running iOS 4.x still work. However, if you have a new device (iPad, iPhone [...]]]></description>
			<content:encoded><![CDATA[<p>As you probably already know, libgpod has included support for Apple&#8217;s iOS 2.x hash for a while now. With their new devices, Apple changed the hash again, but for some reason the change only applies to new devices &#8211; old devices running iOS 4.x still work. However, if you have a new device (iPad, iPhone 4, or iPod touch 4G), music sync does not work.</p>
<p>If your device is not jailbroken, you&#8217;ll have to wait until the new hash is reverse engineered. However, if your device is jailbroken, you&#8217;re in luck. As it turns out, <a href="/blog/2009/01/using-amarok-and-other-itunesdb-compatible-software-with-the-iphone-2x/">the old DBVersion trick</a> once again works to convince those devices to use the previous hash method.</p>
<p>In a nutshell, log in to your device via SSH, edit <code>/System/Library/Lockdown/Checkpoint.xml</code>, find the <code>DBVersion</code> key, change its value from <code>5</code> to <code>4</code>, and finally reboot your device. This has been successfully tested on an iPhone 4, but I assume it will work for the others too.</p>
<p>Caveats regarding the iOS 2.x hash still apply. Specifically, libgpod needs some information to generate the hash. It can gain this information from a prior sync with iTunes, though this probably won&#8217;t work unless you sync again after changing DBVersion, and this hasn&#8217;t been tested. Alternatively, you can use <a href="http://ihash.marcansoft.com/">this page</a> to generate a HashInfo file for your device and manually copy it; this should always work.</p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2011/01/syncing-music-in-new-idevices-with-linux/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>OpenLase: open realtime laser graphics</title>
		<link>http://marcansoft.com/blog/2010/11/openlase-open-realtime-laser-graphics/</link>
		<comments>http://marcansoft.com/blog/2010/11/openlase-open-realtime-laser-graphics/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 02:25:52 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=241</guid>
		<description><![CDATA[Update: see this post for hardware info and also a new GL laser simulator for those without hardware. First of all, as I&#8217;m sure everyone knows by now, I&#8217;ve been working on hacking the Kinect and writing open drivers for it. There&#8217;s a website for the community and a Git repo with the code, and [...]]]></description>
			<content:encoded><![CDATA[<p><b>Update</b>: see <a href="/blog/2011/01/openlase-hardware-and-simulator/">this post</a> for hardware info and also a new GL laser simulator for those without hardware.</p>
<p>First of all, as I&#8217;m sure everyone knows by now, I&#8217;ve been working on hacking the Kinect and writing open drivers for it. There&#8217;s a <a href="http://openkinect.org">website</a> for the community and a <a href="https://github.com/OpenKinect/libfreenect">Git repo</a> with the code, and it&#8217;s working fairly nicely by now.</p>
<p>With that out of the way, here&#8217;s a project that I&#8217;ve been working on on-and-off for the past year or so. I&#8217;ve been interested in laser scanning and DIY laser projectors, but I couldn&#8217;t find any good open source software to drive them. Specifically, I was interested in the realtime aspect: rendering and showing dynamically generated images and responding to events, not just making and preprocessing laser shows. So I set out to write my own set of software to do real-time rendering. This was the result:</p>
<p><iframe class="youtube-player" width="440" height="360" src="//www.youtube.com/embed/m_CHXwXvWvs" frameborder="0"><br />
</iframe><br />
<span id="more-241"></span><br />
DIY laser projectors commonly use sound cards as DACs. This shifts most of the processing over to the PC, but also lets us get very fine control over the realtime aspects of projection, which is what I want. Thus, my laser projector is based on a bog-standard USB soundcard, modified to pass DC. I&#8217;ll probably write a detailed article on the hardware later, but suffice it to say that it&#8217;s a galvo kit, a hacked chinese laser pointer, my own laser driver and monitoring circuitry, and some other minor parts. Total cost is about €200, if you play your cards right.</p>
<p>Since we&#8217;re converting laser images to audio data, why not just treat the laser data as audio in the first place? After all, laser samples are audio-rate data, and 16-bit multichannel 48kHz fits the requirements for laser projection very well. So that is what I did. OpenLase isn&#8217;t really a monolithic framework. Instead, it&#8217;s a series of stand-alone applications and chunks built on the excellent <a href="http://jackaudio.org/">JACK audio connection kit</a>, which serves to pipe realtime laser data around the different bits.</p>
<p>On a typical setup, you&#8217;d have two processes running on top of JACK. On one hand, there&#8217;s the output processor, which is responsible for formatting the idealized laser data to suit the peculiarities of the hardware. This includes things like brightness scaling, the obvious X/Y inversion settings, the final output perspective transform (to fit the screen), and minor filters to try to compensate for hardware imperfections. It also generates a 1kHz square wave on one channel &#8211; this is a peculiar safety feature of my laser hardware. I have a microcontroller monitoring this signal, such that if the software hangs or crashes for some reason, the laser shuts down immediately (to avoid having a static dot which would be a serious eye hazard). The OpenLase output processor has a simple <a href="http://marcansoft.com/transf/laser_output.png">Qt GUI</a> that lets you tweak these settings on the fly.</p>
<p>On the other hand, you have whatever picture source you want to use. You can have bare JACK applications, such as two examples: &#8216;<a href="http://git.marcansoft.com/?p=openlase.git;a=blob;f=examples/circlescope.c;hb=master">circlescope</a>&#8216;, a circular oscilloscope that takes realtime audio data from a media player, and &#8216;<a href="http://git.marcansoft.com/?p=openlase.git;a=blob;f=tools/playilda.c;hb=master">playilda</a>&#8216;, a bare-bones ILDA file player (ILDA / .ild is the standard file format for laser graphics). The circlescope is particularly good for showing off the real-time aspect (note that the input can come from the laser DAC&#8217;s line-in with only the small JACK buffering delay):</p>
<p><iframe class="youtube-player" width="440" height="360" src="//www.youtube.com/embed/teJAOHFj1E4" frameborder="0"><br />
</iframe></p>
<p>However, the other big part of OpenLase is <a href="http://git.marcansoft.com/?p=openlase.git;a=blob;f=include/libol.h;hb=master">libol</a>, a realtime rendering library loosely modeled on OpenGL which lets you produce 2D and 3D graphics on the fly. This is what I used for the LASE demo above. The demo itself isn&#8217;t currently open source (and the code is utterly horrid &#8211; I wrote half of it at Euskal Encounter and finished it mere minutes before the deadline), but if there&#8217;s demand I might open source it too, just please don&#8217;t expect pretty code! However, keep in mind that most features used by the demo (text rendering, 3D, &#8220;shaders&#8221;, ILDA file loading, etc.) were implemented as part of libol, so you aren&#8217;t missing out on much. There are two libol-based examples: <a href="http://git.marcansoft.com/?p=openlase.git;a=blob;f=examples/simple.c;hb=master">some rotating cubes</a>, and <a href="http://git.marcansoft.com/?p=openlase.git;a=blob;f=examples/pong.c;hb=master">Pong</a>.</p>
<p>There&#8217;s one part of the demo made it into the OpenLase distribution as a separate example: <a href="http://git.marcansoft.com/?p=openlase.git;a=blob;f=tools/trace.c;hb=master">tools/trace.c</a>. This used to be some tracing code that I used for the metaballs and fire effects (I kind of cheated there, as those are rendered as bitmaps and then traced in realtime into laser vectors). It&#8217;s a terribly naive algorithm (check the source out for details), but it worked surprisingly well for certain kinds of video, so I hacked it and tacked on more heuristics in order to attempt to make it work better. It now lives next to <a href="http://git.marcansoft.com/?p=openlase.git;a=blob;f=tools/playvid.c;hb=master">tools/playvid.c</a>, which is a simple video player using libavcodec. <a href="http://www.youtube.com/watch?v=uJaAYD0YT44">Here&#8217;s</a> what it looks like (<a href="http://marcansoft.com/transf/badapple4.mkv">improved version (mkv)</a>, <a href="http://www.youtube.com/watch?v=G3C-VevI36s">original YouTube video</a>). More complex videos are hit and miss, but some things turn out <a href="http://marcansoft.com/transf/laser_minami_kiss.mkv">surprisingly well</a> for such a silly algorithm.</p>
<p>You can also add filters between the output and the image generator. This is what I did for my <a href="http://www.youtube.com/watch?v=Q1heqFVrQGU">Kinect + OpenCV + OpenLase</a> demo, which projects anything projectable by OpenLase onto a moving screen, with a dynamic perspective transform (in this case the perspective transform happens in the filter, not in the output processor). That code currently doesn&#8217;t even build with current libfreenect, but again, if someone is interested, drop me a line and I&#8217;ll make it work again and publish it.</p>
<p>OpenLase doesn&#8217;t have any facilities to patch together these JACK apps. Instead, you should just use existing JACK tools, such as QJackCtl, to connect all the input and output ports together. QJackCtl has a patchbay feature that automagically connects the ports when applications start up, so it&#8217;s quite seamless.</p>
<p>Right now there is pretty much no documentation, but I&#8217;d like to know if people are interested. If you have (or want to build) this kind of DIY hardware, you run Linux or some other UNIX that can run JACK, and you&#8217;re interested in hacking on the code or using it for something, please let me know! <a href="http://git.marcansoft.com/?p=openlase.git">Here&#8217;s</a> the git repo.</p>
<p><b>Update</b>: Three more videos, musically themed. A laser visualization of MIDI data (MIDI to laser):<br />
<iframe class="youtube-player" width="440" height="360" src="//www.youtube.com/embed/qDNNFM9ghIY" frameborder="0"><br />
</iframe></p>
<p>And the other way around, a laser harp (laser to MIDI):<br />
<iframe class="youtube-player" width="440" height="360" src="//www.youtube.com/embed/24lQ-736viw" frameborder="0"><br />
</iframe><br />
<iframe class="youtube-player" width="440" height="360" src="//www.youtube.com/embed/iY6927rSBdQ" frameborder="0"><br />
</iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2010/11/openlase-open-realtime-laser-graphics/feed/</wfw:commentRss>
		<slash:comments>60</slash:comments>
<enclosure url="http://marcansoft.com/transf/laser_minami_kiss.mkv" length="24651242" type="video/x-matroska" />
<enclosure url="http://marcansoft.com/transf/badapple4.mkv" length="30073105" type="video/x-matroska" />
		</item>
		<item>
		<title>AsbestOS: Running Linux as GameOS</title>
		<link>http://marcansoft.com/blog/2010/10/asbestos-running-linux-as-gameos/</link>
		<comments>http://marcansoft.com/blog/2010/10/asbestos-running-linux-as-gameos/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 23:31:19 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PS3]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=222</guid>
		<description><![CDATA[As most of you will probably already know, I&#8217;ve been working on a project recently which aims to run Linux on the PS3 (including the PS3 Slim) using the PSJailbreak exploit, effectively replacing GameOS on the fly. I think it&#8217;s gotten to the point where it&#8217;s useful enough for other people to be interested, so [...]]]></description>
			<content:encoded><![CDATA[<p>As most of you will probably already know, I&#8217;ve been working on a project recently which aims to run Linux on the PS3 (<b>including the PS3 Slim</b>) using the PSJailbreak exploit, effectively replacing GameOS on the fly. I think it&#8217;s gotten to the point where it&#8217;s useful enough for other people to be interested, so here&#8217;s something resembling an official announcement.</p>
<p>Obligatory demo video:<br />
<iframe class="youtube-player" width="440" height="360" src="//www.youtube.com/embed/zQ4Q_mqwxpA" frameborder="0"><br />
</iframe><br />
<span id="more-222"></span><br />
AsbestOS (a <a href="http://en.wikipedia.org/wiki/Asbestos">mineral</a>, and meaning &#8220;inextinguishable&#8221; in Greek) is a bootloader to run PS3 Linux without OtherOS. It runs using the USB GameOS exploit (on PS3 version 3.41) from any compatible device, and any reprogrammable devices currently running the PS3 exploit can be used as long as they have enough free internal or external storage (40kB or so) to hold the loader. It is general enough that it should be useful to boot Linux given any other GameOS exploit in the future. It has been tested to work on the PS3 Slim too.</p>
<p>Currently, it only supports netbooting a kernel and no initrd (mostly due to bootmem limitations). This is enough to run a Linux system booting from an NFS share or from USB storage media. Almost everything that works under OtherOS is working. As additional perks of running as GameOS, you also get access to a seventh SPE (needs a <a href="http://git.marcansoft.com/?p=ps3-linux.git;a=commitdiff;h=d4b9d3b8a61cc0f89d92cd8151839f30c1bdd6ee">kernel patch</a> to enable) and there is clearly full access to the RSX including 3D support, although we still need to learn a few details about how that works to be able to use it.</p>
<p>AsbestOS is a fully independent open source payload and does not contain any code from the original PSJailbreak payload or derivatives. It is licensed under the GPLv2. Compiling it does not require any SDK tools, and it includes a script to build a fully vanilla GNU toolchain for the PS3.</p>
<p>If you&#8217;re interested, check out the <a href="http://git.marcansoft.com/?p=asbestos.git">git repository</a>. The <a href="http://git.marcansoft.com/?p=asbestos.git;a=blob;f=README">README file</a> contains information on how to run AsbestOS and how to set up kernels. Currently, ports exist for software USB AVRs (Arduino etc.), iPods, and the reference implementation for devices with a TI OMAP3, but anything currently running PSGroove or similar can be adapted with only a few lines of new code.</p>
<p>For the impatient or lazy folks, here&#8217;s a <a href="http://marcansoft.com/transf/dtbImage-20101020.bin">kernel</a> that you can use <i><b>Update:</b> and a <a href="http://marcansoft.com/transf/stage1-20101020.bin">stage1 binary</a> and a <a href="http://marcansoft.com/transf/stage2-20101020.bin">stage2 binary</a></i>. You&#8217;ll probably want to change the kernel commandline options to set up your NFS root partition. This will eventually be handled by AsbestOS, but for now, open it up in a hex editor, search for HEXEDIT_THIS, and change the commandline to suit your needs (without changing the total length, of course). Do note that this kernel does not have built-in USB support, so it can only be used for NFS booting (the USB stuff is built as a module).</p>
<p>You can use <a href="http://marcansoft.com/transf/gentoo-ps3-20101020.tar.bz2">this</a> filesystem as a starting point. It&#8217;s a Gentoo stage3 updated to date and with PS3-specific tools installed. Keep in mind that there&#8217;s no Portage tree included, so be sure to either <code>emerge --sync</code> or NFS mount your server&#8217;s Portage tree (which is what I do). At the very minimum, you&#8217;ll want to edit the following files to configure your NFS and networking settings (or to specify USB device partitions, if you want to go that route &#8211; but you need to compile your own kernel then): <code>/etc/fstab</code>, <code>/etc/hosts</code>, <code>/etc/resolv.conf</code>, and quite likely a few others. This filesystem includes kernel modules for the above kernel. The root password is &#8216;ps3&#8242;.</p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2010/10/asbestos-running-linux-as-gameos/feed/</wfw:commentRss>
		<slash:comments>118</slash:comments>
		</item>
		<item>
		<title>Making Firefox play nicely with Laptop Mode</title>
		<link>http://marcansoft.com/blog/2009/12/making-firefox-play-nicely-with-laptop-mode/</link>
		<comments>http://marcansoft.com/blog/2009/12/making-firefox-play-nicely-with-laptop-mode/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 04:58:08 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=202</guid>
		<description><![CDATA[Linux has a tweakable knob called laptop_mode which is meant as an energy saving tool for laptop users on battery: it basically says &#8220;try not to touch the disk for X minutes at a time, unless you really need to, and once you do, do everything that you&#8217;ve been piling up all at once&#8221;. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Linux has a tweakable knob called <a href="http://samwel.tk/laptop_mode/">laptop_mode</a> which is meant as an energy saving tool for laptop users on battery: it basically says &#8220;try not to touch the disk for X minutes at a time, unless you really need to, and once you do, do everything that you&#8217;ve been piling up all at once&#8221;. It&#8217;s great for laptop users, and doubly so for things like my <a href="http://marcansoft.com/transf/eee_vs_aspire.jpg">huge</a> laptop with two 7200RPM HDDs. Seriously.</p>
<p>Now, there are two things that mean you &#8220;really need to&#8221; hit the disc: reading data that isn&#8217;t already cached (duh), and the fsync() and fdatasync() calls. The latter are requests by an application to ensure that all of the data written to far has hit the disc, and they cause the disk to spin up in laptop mode.</p>
<p>Unfortunately, Firefox has a habit of randomly issuing fdatasync() calls. It does this as part of the SQLite backend for its various databases (especially places.sqlite), in order to avoid data corruption. Now, data corruption isn&#8217;t terribly likely on a laptop with a battery (which is essentially a built-in UPS), so this is a terrible annoyance with little benefit anyway. There has been <a href="https://bugs.launchpad.net/ubuntu/+source/firefox-3.0/+bug/221009">talk</a> about this problem, but apparently it&#8217;s still around (and the toolkit.storage.synchronous about:config property didn&#8217;t work for me). Most of the reports appear to claim that this happens while browsing, but I&#8217;ve seen it happen periodically even when Firefox is left idle. Maybe it&#8217;s caused by some extension or AJAX webapp? Who knows.</p>
<p><span id="more-202"></span><br />
Ideally this problem would be <a href="http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/">fixed in laptop_mode itself</a>, but that doesn&#8217;t appear to be the case and I&#8217;m not going to poke this part of my kernel just yet, so here&#8217;s a simpler userspace solution: we can preload a library into Firefox that intercepts fsync() and fdatasync() and ignores them. Even better, we can make it do that only if we&#8217;re in laptop_mode. All it takes is a little C code:</p>
<pre>#define _GNU_SOURCE
#include &lt;unistd.h&gt;
#include &lt;dlfcn.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;fcntl.h&gt;

static int in_laptop_mode(void)
{
	char buf[2];
	int fd;
	int l;
	fd = open("/proc/sys/vm/laptop_mode", O_RDONLY);
	if (fd &lt; 0)
		return 0;
	l = read(fd, buf, 2);
	close(fd);
	if (l == 2 &#038;&#038; buf[0] == '0' &#038;&#038; buf[1] == '\n')
		return 0;
	else
		return 1;
}

int fsync(int fd)
{
	static int (*_fsync)(int);
	if (!_fsync)
		_fsync = dlsym(RTLD_NEXT, "fsync");
	if (!in_laptop_mode())
		return _fsync(fd);
	else
		return 0;
}

int fdatasync(int fd)
{
	static int (*_fdatasync)(int);
	if (!_fdatasync)
		_fdatasync = dlsym(RTLD_NEXT, "fdatasync");
	if (!in_laptop_mode())
		return _fdatasync(fd);
	else
		return 0;
}
</pre>
<p>To compile and use it:</p>
<pre>$ gcc -O2 -Wall -shared -fPIC -o killsync.so killsync.c -ldl
$ LD_PRELOAD=`pwd`/killsync.so firefox</pre>
<p>Et voilà, firefox no longer wakes up the hard drive(s). You can confirm that the fsync/fdatasync calls no longer make it to the kernel by running <code>strace -f -p `pidof firefox`</code>, but only in laptop_mode.</p>
<p>I&#8217;ve been typing this blog post with this hack applied and so far HDD spinups have been few, far in between, and fairly short. I still have a few offenders to nail (mostly KDE related), but Firefox was one of the worst ones and it&#8217;s now history. <a href="www.lesswatts.org/projects/powertop">PowerTOP</a> says I&#8217;m saving 3-4W of power. Huzzah! Now I just need to get a kernel with timer stats built so I can fix my insane wakeups-from-idle per second&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2009/12/making-firefox-play-nicely-with-laptop-mode/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>iPhone syncing on Linux, part 2</title>
		<link>http://marcansoft.com/blog/2009/10/iphone-syncing-on-linux-part-2/</link>
		<comments>http://marcansoft.com/blog/2009/10/iphone-syncing-on-linux-part-2/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 06:16:07 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[iPhone on Linux]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[herebedragons]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=145</guid>
		<description><![CDATA[Last post was more along the lines of an announcement, so here&#8217;s a more concrete guide. There have been new releases of most parts of the software stack in the past few days, so now is the time to grab them if you&#8217;re interested. Libgpod is the exception, since it&#8217;s still being worked on to [...]]]></description>
			<content:encoded><![CDATA[<p>Last post was more along the lines of an announcement, so here&#8217;s a more concrete guide. There have been new releases of most parts of the software stack in the past few days, so now is the time to grab them if you&#8217;re interested. Libgpod is the exception, since it&#8217;s still being worked on to get proper support for the iPhone OS 3.x database. That said, if you&#8217;re interested in being an early adopter of iPhone sync support and helping us test it, here&#8217;s how.<br />
<span id="more-145"></span><br />
<b>If you are a new or inexperienced user, or you are not used to compiling things from source, editing configuration files, and doing some basic troubleshooting, stop here</b>. This isn&#8217;t ready for you. In the not too distant future, distros will package this, it will be delivered with your usual dose of healthy and working open source software, and it will all work automagically as soon as you plug in your device.</p>
<p>A few notes:</p>
<ul>
<li>Keep in mind that if you&#8217;re using distro packages for anything I&#8217;m going to mention here, you&#8217;ll need the development headers too (<code>-dev</code> package or similar).</li>
<li>When linking to packages below, I&#8217;ll link the name to the homepage and the version to a download link or something close to it: if you&#8217;re reading this post soon after it was posted, then the versions should be up to date. If it&#8217;s been more than a few days, you should check for newer versions.
<li>You&#8217;ll also need <a href="http://cmake.org/">cmake</a> to build some things (2.6 or newer); your distro should provide a package for it.</li>
<li>Most packages will install to <code>/usr/local</code> by default. This should be fine, but you may have to uninstall any older distro packages that live at <code>/usr</code>, and apps may or may not pick up libraries on <code>/usr/local</code>. If you want, you can change the prefix to /usr. You should already know how to do this for autotools-based packages. For CMake-based ones, pass something like <code>-DCMAKE_INSTALL_PREFIX=/usr</code> when calling cmake.</li>
<li>The libiphone/ifuse page has links to distro repositories with packaged versions of everything <a href="http://matt.colyer.name/projects/iphone-linux/index.php?title=Main_Page#Ubuntu_Intrepid.2FJaunty">here</a>. Yay, you&#8217;ve just saved a bunch of time! Do follow the steps below, but you can use these packages instead of building from source.</li>
</ul>
<p><b>Possible pitfalls</b>:</p>
<ul>
<li>If you&#8217;ve had prior versions of usbmuxd/libiphone/etc, make sure they&#8217;re gone, especially any udev rules files in <code>/etc/udev/rules.d</code>.</li>
<li>If you&#8217;ve been syncing via SSH, and you log in as root, your permissions might be messed up. Run <code>chown -R mobile /var/mobile/Media</code> on the phone, and make sure you don&#8217;t get any permission errors when changing files via an ifuse mount.</li>
<li>There&#8217;s a udev bug that causes usbmuxd not to respond to signals, which means it will never quit if you remove all devices, and it might not detect any new devices after you&#8217;ve plugged in the one that caused it to start up. As a workaround, <code>kill -9</code> it, and run it from the console. A workaround for this bug is also in the usbmuxd Git repo.</li>
</ul>
<h3>Step 1</h3>
<p>Install <a href="http://www.libusb.org/wiki/Libusb1.0">libusb</a>-<a href="http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.3/libusb-1.0.3.tar.bz2/download">1.0.3</a> (or newer). This should be straightforward. If your distro carries it, that&#8217;s fine, just make sure it&#8217;s 1.0.3 at least (if it isn&#8217;t, the repos I mentioned above probably have it).</p>
<h3>Step 2</h3>
<p>Install <a href="/blog/iphonelinux/usbmuxd/">usbmuxd</a>-<a href="http://marcansoft.com/uploads/usbmuxd/usbmuxd-1.0.0.tar.bz2">1.0.0</a>. Make sure you read the <code>README</code> file, especially the part about creating a user named <code>usbmux</code> with USB access permissions (does not apply if you&#8217;re using distro packages, hopefully). After installing usbmuxd, you should increase the syslog debug level by editing <code>/lib/udev/rules.d/85-usbmuxd.rules</code> and adding <code>-v -v</code> flags to the end of both <code>RUN</code> statements, like this: <code>RUN+="/usr/sbin/usbmuxd -u -U -v -v"</code> (and similarly for the other line). This will get you useful debug information in syslog without flooding you with messages.</p>
<p>Have syslog open (<code>tail -f</code>, xconsole, whatever). Plug in (or replug) your device. You should see something like this:</p>
<pre>usb 3-4.3: new high speed USB device using ehci_hcd and address 68
[...]
usbmuxd[12705]: [3] usbmux v1.0.0 starting up
usbmuxd[12707]: [4] Creating socket
usbmuxd[12707]: [3] Successfully dropped privileges to 'usbmux'
usbmuxd[12707]: [4] Initializing USB
usbmuxd[12707]: [4] Found new device with v/p 05ac:1290 at 3-68
usbmuxd[12707]: [4] Using wMaxPacketSize=512 for device 3-68
usbmuxd[12707]: [3] Connecting to new device on location 0x30044 as ID 1
usbmuxd[12707]: [4] 1 device detected
usbmuxd[12707]: [3] Initialization complete
usbmuxd[12707]: [3] Connected to v1.0 device 1 on location 0x30044 with serial number be2975afb30b6db9025f95261b9e0a7041044661</pre>
<p>If you don&#8217;t see anything related to usbmuxd, either you forgot the <code>-v -v</code> or you need to reload your udev rules: <code>$ sudo udevadm control --reload-rules</code>. As a last resort, try rebooting. If it still doesn&#8217;t work, something&#8217;s wrong. You can continue by running usbmuxd manually as explained in the README, but you should report a bug.</p>
<p>If you have a jailbroken phone with SSH, try running <code>$ iproxy 2222 22</code> and then SSH to localhost, port 2222 on another console. You should be able to SSH into your phone.</p>
<p>Unplug your phone. If usbmuxd was started via udev (not manually), it should quit. If it doesn&#8217;t, report a bug.</p>
<h3>Step 3</h3>
<p>Install <a href="http://github.com/JonathanBeck/libplist">libplist-<a href="http://cloud.github.com/downloads/JonathanBeck/libplist/libplist-0.16.tar.bz2">0.16</a> and then <a href="http://matt.colyer.name/projects/iphone-linux/index.php?title=Main_Page">libiphone</a>-<a href="http://cloud.github.com/downloads/MattColyer/libiphone/libiphone-0.9.4.tar.bz2">0.9.4</a> and <a href="http://matt.colyer.name/projects/iphone-linux/index.php?title=Main_Page">ifuse</a>-<a href="http://cloud.github.com/downloads/MattColyer/ifuse/ifuse-0.9.4.tar.bz2">0.9.4</a>.</p>
<p>Now you should be able to mount your phone by simply running <code>$ ifuse &lt;mountpoint&gt;</code>. You should be able to see the media folder structure and even grab photos and other stuff. If you have a jailbroken phone, you can use the <code>--root</code> option to mount the root filesystem with root privileges (I usually prefer ssh/sshfs for this, though). <b>Do NOT use the <code>--root</code> option to sync music, it will not work and may mess up your permissions.</b></p>
<p><b>If you have access to more than one iPhone or iPod Touch</b>, we could use some multiple-device testing! Usbmuxd should happily start up when you plug in the first device, keep running while you plug in any other devices, and stop once all devices have been removed. Usbmuxd will report the device UUIDs (it calls them &#8220;serial numbers&#8221;) as they are connected (if you&#8217;re using <code>-v -v</code>). You should be able to pass the <code>--uuid=&lt;uuid&gt;</code> option to ifuse to mount a specific device. Please test this for us!</p>
<h3>Intermission</h3>
<p><b>If you are not used to alpha software, checking out development sources, testing patches, and working with developers, stop here</b>. Now you&#8217;ve got all the underlying stuff working, so you&#8217;re probably better off waiting for some time until libgpod stabilizes some and things are merged and tested.</p>
<p>If you are a developer willing to help, a very enthusiastic power user, or simply a masochist, feel free to read on. Be warned: pain lies ahead, don&#8217;t even think about using the following for day-to-day use at this point in time. From here on there are no distro packages and no nice source tarballs. Experiments and feedback only. This Will Eat Your Music Collection For Dinner And Replace It With Hours And Hours Of &lt;insert terrible music&gt;.</p>
<h3 style="color: #d00">Step 4</h3>
<p>Clone <del datetime="2009-12-22T16:21:48+00:00"><a href="http://gitorious.org/~teuf/libgpod/teuf-sandbox">teuf&#8217;s sandbox</a> Git repository for libgpod, and <b>switch to the <code>iphone30</code> branch</b></del> <a href="http://gtkpod.git.sourceforge.net/git/gitweb.cgi?p=gtkpod/libgpod;a=summary">the libgpod git repository at SourceForge</a>, then compile and install it:</p>
<pre>$ git clone git://gtkpod.git.sourceforge.net/gitroot/gtkpod/libgpod
$ cd libgpod
$ CFLAGS="-g -O0" sh autogen.sh --prefix=/usr
$ make
$ sudo make install</pre>
<h3 style="color: #d00">Step 5</h3>
<p>Mount the device and create the <code>iTunes_Control/Device</code> directory. Then, get your UUID (it should be in the syslog from usbmuxd, or you can find it by running <code>$ lsusb -v | grep -i iSerial</code>). It should be 40 characters long. Then, run <code>$ tools/ipod-read-sysinfo-extended &lt;uuid&gt; &lt;mountpoint&gt;</code>. This should generate a file named <code>iTunes_Control/Device/SysInfoExtended</code>. Make sure it&#8217;s not empty and whatnot; it should be a large-ish plist (XML file) with a bunch of info.</p>
<h3 style="color: #d00">Step 6</h3>
<p>Make sure your device already contains a valid music database created by iTunes. If it doesn&#8217;t, drop me a line on IRC and we can try some cool new stuff. New databases can be created, but there might be issues and you need some way of generating the <code>HashInfo</code> file (more on this later).</p>
<h3 style="color: #d00">Step 7</h3>
<p>Open an application that uses libgpod to manage iPods. Gtkpod is recommended at this stage, as its what I use to test. Other apps (Rhythmbox, Amarok, etc) <i>theoretically</i> should work. Theoretically, because Amarok 1.4 crashes/hangs pretty badly for me, for example, and I&#8217;m not sure who is to blame. I&#8217;d like to hear any success or failure stories. Please run your app from a console so you can see any debug messages.</p>
<p>First, load your device. Once the application has accessed the music library, a new file called <code>HashInfo</code> should have popped up in the <code>iTunes_Control/Device</code> directory. If it isn&#8217;t there, you&#8217;ve got a problem: check stdout for any messages and and preferably ping me on IRC or at least e-mail me your UUID and your iTunes-created <code>iTunes_Control/iTunes/iTunesCDB</code> file (it shouldn&#8217;t have been modified yet).</p>
<p>Make some changes (add a song, make a playlist, etc), save, and cross your fingers. With any luck, you&#8217;ll get some debug spew, any songs will transfer, the iPhone/iPod will show a pretty &#8220;syncing&#8221; screen, the database will be written, the &#8220;syncing&#8221; screen will go away, and you&#8217;ll be able to launch the iPod application and see your changes and play any new songs. There will be bugs at this stage, but please do report any issues along with expected behavior.</p>
<h3 style="color: #d00">Step 8</h3>
<p>Plug your device into a computer running iTunes (unmount it on your Linux computer first!) and check that it can see the changes made with libgpod. This is very important, because <b>iTunes and the device use different databases</b>: the data managed by iTunes and libgpod is maintained in an <code>iTunesCDB</code> (a compressed version of the old, classic <code>iTunesDB</code> format), but it is converted to a new SQLite database format for the iPod app to use. So both libgpod and iTunes read the <code>iTunesCDB</code>, but they write out the <code>iTunesCDB</code> <b>and</b> the SQLite databases. You should be able to make changes in iTunes and swap your device from iTunes to libgpod and back and see them, etc.</p>
<h3>Bugs</h3>
<p>Tons. The only things tested to work are managing simple music and working with simple playlists. There&#8217;s a known annoying bug where the iTunes special playlists (Ringtones/etc) are converted to normal playlists by libgpod, and then iTunes recreates them if you use it again, creating duplicates each time you switch between using libgpod and iTunes. The DB schema is outdated (3.0 instead of 3.1), so you&#8217;ll see a (hopefully short) &#8220;Updating&#8221; step when you launch the iPod app. Please report issues, but keep in mind that they&#8217;re to be expected. This is very very very alpha code. I probably screwed up something on this post even, so chances are you&#8217;ll get stuck somewhere. Tough luck, it&#8217;s 7am and I need to catch some sleep <img src='http://marcansoft.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Hope you had fun! Keep in mind that you can usually find us on #gtkpod on freenode if you need to report an issue. Comments on this post are fine too, for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2009/10/iphone-syncing-on-linux-part-2/feed/</wfw:commentRss>
		<slash:comments>170</slash:comments>
		</item>
		<item>
		<title>iPhone syncing on Linux</title>
		<link>http://marcansoft.com/blog/2009/10/iphone-syncing-on-linux/</link>
		<comments>http://marcansoft.com/blog/2009/10/iphone-syncing-on-linux/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 18:46:11 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[iPhone on Linux]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[usbmuxd]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=104</guid>
		<description><![CDATA[Those who watch my git repos may have noticed that I&#8217;ve been working on this for a while now. iPhones and iPod Touches have never been properly supported under Linux (especially non-jailbroken devices) because they are just so different from all the previous iPod models. There was a lot of new code to write and [...]]]></description>
			<content:encoded><![CDATA[<p>Those who watch my <a href="http://git.marcansoft.com/">git repos</a> may have noticed that I&#8217;ve been working on this for a while now. iPhones and iPod Touches have never been properly supported under Linux (especially non-jailbroken devices) because they are just so different from all the previous iPod models. There was a lot of new code to write and Apple hasn&#8217;t exactly made it easy either:</p>
<ul>
<li>The iPhone uses a custom USB communications protocol, connection-oriented, which is totally different from standard mass storage devices</li>
<li>It provides multiple services over this protocol, and many have to be interacted with to complete sync</li>
<li>iPhone OS 2.x brought us a new hash (designed to lock users into iTunes) that so far had not been reverse engineered</li>
<li>iPhone OS 3.x brought us a new SQLite-based database format which, although a lot more Linux-friendly than the old proprietary format, does require a bunch of new code (and the old format still needs to be supported for compatibility).</li>
</ul>
<p>Well, I&#8217;m happy to say that all of this is coming to an end and that Linux will finally get quite complete iPhone/iPod Touch syncing support soon, thanks to the work of many dedicated people. <span id="more-104"></span>This is what the software stack looks like:</p>
<p><img src="/transf/iphonelinux-stack.png" alt=""/></p>
<ul>
<li><a href="http://www.libusb.org/wiki/Libusb1.0">libusb-1.0</a> provides an advanced API to access USB devices under Linux, replacing the old libusb-0.1 API</li>
<li><a href="/blog/iphonelinux/usbmuxd/">usbmuxd</a> coordinates application access to the device and talks the specific iPhone/iTouch USB protocol</li>
<li><a href="http://matt.colyer.name/projects/iphone-linux/index.php?title=Main_Page">libiphone</a> implements the Apple-specific protocols that are tunneled through usbmuxd: it can launch services through lockdown, retrieve device info, send notifications, and access the filesystem via AFC.</li>
<li><a href="http://matt.colyer.name/projects/iphone-linux/index.php?title=Main_Page">iFuse</a> and <a href="http://cgit.sukimashita.com/gvfs-backend-afc.git/">gvfs-backend-afc</a> both provide access to AFC to regular Linux apps. iFuse does this by mounting via FUSE, while gvfs-backend-afc is obviously a backend for gVFS.</li>
<li><a href="http://www.gtkpod.org/libgpod/">libgpod</a> (the library that traditionally has managed music databases for iPods) is being extended to support the new SQLite format, the new hash, and also to talk to libiphone to properly put the device in to and out of sync mode.</li>
<li>Theoretically, actual music players such as Amarok and Rhythmbox will need none or very few modifications to work.</li>
</ul>
<p>I originally started work on usbmuxd which I am maintaining, and I&#8217;m now helping libgpod compatibility with the new formats. The software stack needs to be working from the bottom up, so I&#8217;ve just tagged and released the first <a href="/blog/iphonelinux/usbmuxd/">Release Candidate for usbmuxd-1.0.0</a>. If you have an iPhone or an iPod Touch and you&#8217;d like to use them with Linux in the future, I encourage you to test it out. If your device is jailbroken, you get the immediate benefit of being able to SSH over USB (which is a <b>lot</b> faster than over WiFi!), and if you&#8217;re using firmware 2.x or earlier and the hacky sync-over-WiFi-with-sshfs method, you can immediately get a speed boost by doing it over USB.</p>
<p>If you&#8217;re feeling adventurous, the development versions of libiphone and iFuse are also quite good. Theoretically, if your usbmuxd is working an you&#8217;ve got iFuse installed, you can just type &#8220;ifuse &lt;mountpoint&gt;&#8221; and instantly have your device mounted. Don&#8217;t expect to get libgpod to work at this time without quite some pain though. If you&#8217;re a developer and you&#8217;re feeling <b>really</b> adventurous though, you can join us on #gtkpod on freenode and help us test and fix the new libgpod support!</p>
<p>Please report any bugs or fixes in usbmuxd either directly to <a href="mailto:hector@marcansoft.com">me</a> or to the <a href="http://lists.mattcolyer.com/listinfo.cgi/iphone-linux-dev-mattcolyer.com">iphone-linux-dev mailing list</a>. Any issues with libiphone or iFuse should also go to the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2009/10/iphone-syncing-on-linux/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Enabling Intel VT on the Aspire 8930G (and other InsydeH2O-based laptops)</title>
		<link>http://marcansoft.com/blog/2009/06/enabling-intel-vt-on-the-aspire-8930g/</link>
		<comments>http://marcansoft.com/blog/2009/06/enabling-intel-vt-on-the-aspire-8930g/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 16:30:49 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[acer]]></category>
		<category><![CDATA[bios]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[intelvt]]></category>
		<category><![CDATA[reveng]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=71</guid>
		<description><![CDATA[It seems the ongoing trend for laptops is to integrate and hide as much as possible from the user. We&#8217;re all used to minimalistic crappy BIOS setups with two or three configuration options. However, things go way too far when OEMs remove options related to features that the hardware is capable of but which are [...]]]></description>
			<content:encoded><![CDATA[<p>It seems the ongoing trend for laptops is to integrate and hide as much as possible from the user. We&#8217;re all used to minimalistic crappy BIOS setups with two or three configuration options. However, things go way too far when OEMs remove options related to features that the hardware is capable of but which are disabled by default. This happens with Intel VT on many laptops &#8211; even if the CPU supports it, you may not be able to find the BIOS setup option to turn it on. </p>
<p>I certainly wanted to use a feature that I <b>paid for</b>, so I started investigating the BIOS and here&#8217;s what I found out.</p>
<p><b>Update:</b> There&#8217;s a 1.21 BIOS floating around that seems to have VT enabled natively. See below.<br />
<span id="more-71"></span></p>
<h3>Under the hood</h3>
<p>The InsydeH2O BIOS is no ordinary old-style BIOS. Instead, it&#8217;s based around the <a href="http://www.uefi.org/">UEFI</a> platform. This goes way beyond the old BIOS paradigm and turns system firmware into practically its own separate OS, that even runs in full 64-bit mode on 64-bit machines. Unfortunately, they make no effort to expose any of this to the user. The firmware has support for booting EFI executables, there&#8217;s an EFI shell, there&#8217;s an EFI boot manager&#8230; but I haven&#8217;t been able to figure out how to access any of this.</p>
<p>If you want to reverse engineer EFI stuff, downloading <a href="https://www.tianocore.org/">TianoCore&#8217;s EDK2</a> is a must. It contains source code for a lot of Intel&#8217;s framework, which is what most vendors use as a base for their EFI support. A lot of the code is exactly the same as what&#8217;s in the Insyde BIOS (read the spec <a href="http://download.intel.com/technology/framework/docs/HII_9_2.pdf">here</a>). </p>
<p>As for the Setup tool, it does indeed have a huge Advanced menu with even more options than your average desktop. There&#8217;s also a hidden Power menu. EFI defines a &#8220;form browser&#8221; protocol and formats for user input, which is what Insyde uses for their setup utility (spec <a href="http://download.intel.com/technology/framework/docs/HII_9_2.pdf">here</a>). I found these tables when disassembling the Setup binary and wrote a little dump utility to turn them into text. The result is a complete dump of the Setup hierarchy, including the Advanced menu, which also includes the offsets in the non-volatile storage corresponding to each setting. Insyde stores this configuration blob into an EFI variable named <code>Setup</code>. <a href="/uploads/insydehacks/setup.txt">Here&#8217;s</a> my dump: the first part is the hierarchy, while at the end I added a rough auto-calculated mapping from configuration offsets to setting names (grep for <code>[0xOFFSET</code> in the top section for better context - the format is <code>[0xOFFSET&lt;FIELD_WIDTH&gt;]</code> for all references to the storage blob). You&#8217;ll find the tools I used <a href="/uploads/insydehacks">here</a>, if you&#8217;re interested, but they&#8217;re rough and need quite a bit of manual help too.</p>
<p>I wasn&#8217;t able to find out how to enable the hidden menus, other than that their form Subclass is 5 instead of 0 (but I haven&#8217;t found what, if anything, checks for this and whether its behavior can be altered). However, manually enabling VT support in the <code>Setup</code> variable is easy enough, now that we have the offset of the VT Enable byte.</p>
<h3>Enabling Intel VT</h3>
<p>The easiest way to enable the setting as far as I can see is to dump out the entire BIOS, patch the setting into the Setup variable (which is part of the data storage section &#8211; we aren&#8217;t modifying any actual BIOS code, as this is the equivalent of changing a CMOS setting on other BIOSes), and then flash the resulting image. These laptops use a weird flash-behind-EC hardware solution for which there is no open flasher, so instead we can just use the normal BIOS flashing tool. In short, we&#8217;ll flash the existing BIOS back on, but in the process also modify a Setup setting.</p>
<p><b>FAIR WARNING:</b> This might apply to other similar laptops, or it might not. It might work, it might do nothing, or it might brick your expensive laptop. Even if you own an Aspire 8930G, I take no responsiblity if your laptop dies, turns into an expensive brick, melts into a pool of slag, blows up, flicks you off, develops self-awareness, or becomes Skynet. You have been warned. I have only tested this on an Aspire 8930G with BIOS Version 1.10. If you want to try this on another system or BIOS you should make sure you understand EXACTLY what is going on and are prepared to spot any problems or fix things yourself.</p>
<p>First, dump the exiting BIOS out. It resides at the top of the 32-bit address space, and is 2MB in size. You can use dd to dump it out of /dev/mem:</p>
<pre>$ dd if=/dev/mem of=original_bios.fd bs=1024 count=2048 skip=4192256</pre>
<p>It is a <i>very</i> good idea to back up this BIOS somewhere safe outside the laptop. Note that it not only contains your existing BIOS code, but also all your settings and manufacturer data (serial number, software license if you run an OEM version of Vista, etc).</p>
<p>Next, run <a href="/uploads/insydehacks/vtenable.py">vtenable.py</a>. This will attempt to locate the <b>Setup</b> EFI variable on the non-volatile storage section and patch the VT byte to one.</p>
<pre>$ python vtenable.py original_bios.fd vt_bios.fd</pre>
<p>You can edit the source code to make other changes to the variable, but make sure you know what you&#8217;re doing. It&#8217;s worth reiterating that <b>this does not patch your BIOS code</b>. It only makes a setting change, just as if you&#8217;d turned on the VT option in the BIOS had it been there. In fact, there are two variables: <code>Setup</code> and <code>Custom</code>, and <code>Setup</code> is the one that changes are committed to when you use the setup utility. Restoring defaults should turn VT back off (untested). It also appears that <code>Custom</code> is probably what the setup defaults are, so changing that should semi-permanently enable VT.</p>
<p>I highly recommend performing a sanity diff between the original and modified images using vbindiff:</p>
<pre>$ vbindiff original_bios.fd vt_bios.fd</pre>
<p>Only two or three bytes should change: one or two adjacent bytes for the checksum (they should be decremented by one when you look at them as a 16-bit unsigned integer), and the VT enable byte should change from <code>00</code> to <code>01</code>. Right after the checksum bytes you should be able to see the <code>Setup</code> name in UTF-16 (something like <code>S.e.t.u.p.</code>).</p>
<p>Finally, flash <code>vt_bios.fd</code> using the vendor-supplied flash utility. I use the DOS version (<code>FLASHIT.EXE</code>) with FreeDOS and a grub menu option so I don&#8217;t need to mess around with external media. Grab a base image <a href="/uploads/insydehacks/freedos_flashit.img.bz2">here</a>, then you can use <a href="http://mtools.linux.lu/">mtools</a> to copy the bios into it:</p>
<pre>$ bunzip2 freedos_flashit.img.bz2
$ mcopy -i freedos_flashit.img vt_bios.fd ::/vt_bios.fd</pre>
<p>To boot it using GRUB, get <a href="http://syslinux.zytor.com/wiki/index.php/MEMDISK">MEMDISK</a>, part of <a href="http://syslinux.zytor.com/wiki/index.php/The_Syslinux_Project">SYSLINUX</a>, and put something like this in your grub.conf:</p>
<pre>title=BIOS Update
root (hd0,0)
kernel (hd0,0)/boot/memdisk
initrd (hd0,0)/boot/freedos_flashit.img</pre>
<p>Of course, copy memdisk and the boot image to your boot partition, and change <code>(hd0,0)</code> to your boot (or root) partition everywhere and remove the <code>/boot</code> part if you have a dedicated boot partition.</p>
<p>Once you&#8217;re in FreeDOS, just type <code>FLASHIT vt&lt;tab&gt;</code> and be happy that FreeDOS supports tab-completion <img src='http://marcansoft.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Caveat: by doing this, you&#8217;re flashing the entire BIOS image. The flash tool makes no attempt to flash only the parts that changed, and the &#8220;flash only variables&#8221; commandline option seems to have no effect. You&#8217;re effectively reflashing your entire BIOS back on, so the usual BIOS flashing caveats apply: don&#8217;t turn the power off, etc. This could be accomplished a lot more cleanly if we had drivers for the flash chip / EC, since then we could use the normal EFI variable store procedure to atomically update the variable, which is completely safe.</p>
<p>You can use the <a href="http://www.linux-kvm.org/page/Enable_VT-X_on_Mac_Pro_(Early_2008)">MSR Magic</a> tool to check whether VT is indeed enabled on your CPU.</p>
<p><b>Update</b>: Several people are working on improved, more general tools to perform this hack across a broader range of InsydeH2O-based BIOSes. Read the comments and check them out, they&#8217;ve done some very good work.<br />
<b>Update 2</b>: There&#8217;s a 8930G 1.21 BIOS version floating around (not on Acer&#8217;s site yet) with build date 3/3/2011. This version seems to have VT enabled without any hacking required (I&#8217;ve checked the contents and everything seems to be kosher and a real update, not some hack). I haven&#8217;t come across an official update file, but I did find a dump made by someone. I&#8217;ve manually cleaned it up to remove the variables and serial numbers so it should be identical to an official 1.21 update file (it will keep your current config and serials). You can find it <a href="http://marcansoft.com/transf/1.21-clean.fd">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2009/06/enabling-intel-vt-on-the-aspire-8930g/feed/</wfw:commentRss>
		<slash:comments>511</slash:comments>
		</item>
		<item>
		<title>iPhone OS 3.0 music: totally incompatible</title>
		<link>http://marcansoft.com/blog/2009/06/iphone-os-30-music-totally-incompatible/</link>
		<comments>http://marcansoft.com/blog/2009/06/iphone-os-30-music-totally-incompatible/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 23:30:25 +0000</pubDate>
		<dc:creator>marcan</dc:creator>
				<category><![CDATA[iPhone on Linux]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://marcansoft.com/blog/?p=63</guid>
		<description><![CDATA[With the new OS version, Apple totally changed up the database format. Now it&#8217;s based on a whole bunch of SQLite files and there are also a few files in a format similar to the old proprietary one. There are more than likely still hashes in the critical files, and there&#8217;s also a suspicious pair [...]]]></description>
			<content:encoded><![CDATA[<p>With the new OS version, Apple totally changed up the database format. Now it&#8217;s based on a whole bunch of SQLite files and there are also a few files in a format similar to the old proprietary one. There are more than likely still hashes in the critical files, and there&#8217;s also a suspicious pair of files that appear to be entirely encrypted. The SQLite format is open and certainly better than the old one, but someone still needs to interface a media player to it.</p>
<p>The upshot of this is that a whole new support library will need to be written or large changes in libgpod need to happen to support the new SQLite format. The DBVersion hack also isn&#8217;t going to work &#8211; either someone needs to reverse engineer the complete hashing algorithm (and maybe that encrypted file stuff), or the MusicLibrary binary on the phone needs to be patched. So, if you&#8217;re currently syncing music with free software, you&#8217;ll want to hold off on upgrading to 3.0.</p>
<p>Patching the check out of MusicLibrary looks trivial enough, so although it&#8217;s not as easy as the DBVersion hack, it isn&#8217;t a real showstopper. The hash algorithm looks the same as the old one, or at least quite similar (and just as badly obfuscated). Those encrypted files do scare me a bit though.</p>
]]></content:encoded>
			<wfw:commentRss>http://marcansoft.com/blog/2009/06/iphone-os-30-music-totally-incompatible/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

