Wednesday, February 27, 2013

Installing Linux Mint on a Macbook Air

In late 2011 I bought the Apple Macbook Air 13" (model 4,2 with 128GB SSD) to replace my aging road-warrior Dell 420. As much as I was impressed by Apple's hardware and the Macbook Air in particular, I was never taken by their software or the OSX that comes with the Macbook Air when you buy it. So within a week or so, I started experimenting putting Ubuntu (my then favorite OS) onto it. Things may have improved by then, but it was quite a task to get Ubuntu installed and set up properly - much more difficult than setting up Linux on a non-Apple laptop. The end result was a functioning but fragile setup, where each update to Ubuntu (new kernel in particular) would require me to reboot into safe mode and manually edit various files. As chef Ramsay would say, what a f...... nightmare.

After 1 1/2 year and a dangerously outdated system (so many Java vulnerabilities), I decided it was time for a re-install. This time around however, I chose to try out the new favorite kid on the block, namely Linux Mint 14 with the Cinnamon interface (Unity on Ubuntu was OK, but at the end of the day more limiting than facilitating). I did prepare myself mentally for having to go through a week of cursing and sweating, but as it would turn out these concerns were entirely unfounded.



Installation procedure

First I booted back into OSX recovery (Command-R during boot) so that I could re-install OSX such as to have a completely fresh system and up-to-date firmware. The restore functionality build into the Apple hardware works very well, and remains a solid advantage to that OS - if only it was possible to provide alternative OS images this would be a killer feature. Anyway, after re-installing OSX I then wanted to re-partition to get some space for Linux. However, it turned out that you are not allowed to commit these actions in the recovery (at least I kept getting an error message) so I had to do it from the DiskUtil while booted normally into OSX. In here, I shrunk the OSX partition down to around 25GB, leaving just 2-3 GB of free space on OSX and a good 95GB for Linux partitions. That way, I could still occasionally boot OSX, but I knew from experience that I would never purposefully use OSX for my daily work. If you plan to actually use OSX from time to time, you should probable give it a bit more space than I did.



While still in OSX, I then downloaded the Mint 14 image I wanted as an ISO file.
Part of the trouble with the Macbook Air, is that it does not readily boot from an optical drive and it uses UEFI rather than your traditional BIOS. So one has to use a USB stick that talks UEFI, or install Windows via bootcamp (special Apple support for dual-booting Windows and OSX) and piggyback off this partition. Last time I installed Ubuntu, I used the latter method, but this time around I wanted to give the former approach a try - Windows takes an enormous amount of space after all, and I already have OSX eating up precious space. It turns out that it is pretty easy now days, I simply downloaded an application for OSX called Penguintosh specifically made for he purpose, used the tool to write my Mint image to a USB device and rebooted. While booting up, hold down the C key, so that you get to choose which device to boot from. Select the last orange USB icon and double click it.



Soon you should have a Mint live image running. From within this live image, it's trivial to start installing Linux Mint to disk, since you already prepared the partition. Once installed, GRUB will give you the option of booting into Mint or OSX.



Tweaking Linux Mint

Generally very little tweaking is necessary, in contrast to my experiences with Ubuntu. Screen, sound, trackpad, keyboard backlight, function keys etc. all just seems to work. If however you are not happy with how the trackpad operates, you may tweak it with the synclient utility. For instance, I noticed that two-finger scroll is disabled, but it can be enabled with the command:


~$ synclient VertTwoFingerScroll=1

You can explore countless settings for the trackpad this way, but it won't be permanent until you modify the xorg settings. I had some trouble succeeding with this the official way (messing with xorg settings file), so I simply ended up adding an entry in Cinnamons "Startup applications" applet.



In the same category, you may also want to change the scroll direction to match what you have been used to in OSX (I am now used to this inverse "natural scroll"). Once again, this is an xorg setting that you can also invoke on-demand:


~$ xinput set-button-map 11 1 2 3 5 4 6 7 8 9 10 11 12

As with the previous command, you can just let "Startup applications" handle this by adding "xinput set-button-map 11 1 2 3 5 4 6 7 8 9 10 11 12" as an application.

Another little detail I did not like, was how function (fn) keys were default over the classic F (F1-F12) keys - as a developer I rather depend on these and would prefer to control sound, brightness etc. with a combo using the fn keys. To change this, create a file in the path "/etc/modprobe.d/hid_apple.conf" with the content "options hid_apple fnmode=2".


~$ echo "options hid_apple fnmode=2" > /etc/modprobe.d/hid_apple.conf


Strangely, Cinnamon does not (yet) have any way to organize Linux groups, but you can just use the classic Gnome tools for this, by installing:


~$ sudo apt-get install gnome-system-tools


Then of course, there are all the applications. One of the first things I install is usually the handy plugin to Nautilus (yes it also works in Linux Mint's Nemo fork of Nautilus) which allows for image resizing directly while navigating your files:


~$ sudo apt-get install nautilus-image-converter imagemagick


Conclusion

While still not as easy as installing Linux on your average laptop, this recent experience of installing Linux Mint 14 onto my Macbook Air was a very nice experience compared to all the hoops I had to go through with Ubuntu. I've come to appreciate the responsiveness and functionality of Linux Mint 14 (and it's Cinnamon UI) so much that I also plan to replace Ubuntu with Mint on my main workstation. There may still be tweaks I need to perform, but the out-of-box experience is very usable. The only real problem I've run into, is the lack of VPNC support in the network manager. Installing "network-manager-vpnc-*" has no effect in the Cinnamon interface, so if you want to connect to Cisco VPN networks, you are going to have to do it the old-fashioned way, with a command-line.

Naturally, if you have tips or tweaks in this regard, feel free to drop a comment about it below. :)

Sunday, February 3, 2013

Rikomagic MK802IIIS (4'th gen Android-on-a-stick)


I am a bit of tinkerer... I like taking things apart, understanding how they work (to some degree) and come up with new combinations of what can be done. So when I saw the $54 MK802IIIS "Android on a stick" device with 4'th generation specs, I had to own one. Think of it as a tablet, without a display or battery, that you hook up to the TV instead.



What makes the MK802IIIS so interesting?

First and foremost, the device is obviously readily usable as a media player. It makes it possible to upgrade any TV with HDMI input, to a "smart TV". This is especially interesting these days, where TV-on-demand services like NetFlix, Hulu, HBO etc. are delivered via custom applications on a limited subset of TV's or via proprietary boxes. Since this stick is based on the popular Android platform, all you really need to do is visit the Google Play store and install the appropriate application from the content provider. Why Google hasn't pushed this cheap and simple approach rather than their vaporware Google TV is beyond me.

Secondly, and what I personally find the most interesting about the device, is the price and form factor, which makes it superior to other popular tinkering platforms such as the RaspberyPI, Beagleboard and Arduino stuff. You get dual-core 1.6GHz (no you don't, more about that later) Cortex-A9 CPU, 1GB of RAM, 2xUSB host ports, WiFi, microSD card slot and HDMI out. For all of this, you would have to pay at least $100 if you went with the more traditional tinkering kits I just mentioned - and I still don't think you would be able to get the same performance as the MK802IIIS provides. Some will rightly claim that the MK802 is much more limited when it comes to interfacing, but remember that USB-RS232 and USB-GPIO adapters can be had on ebay for about 10-15$ and that opens up a whole wide world for interfacing with your surroundings.


Initial impressions of hardware

The device feels like decent quality, with a generous amount of extra cabling/adapters coming along with it. Indeed, it does not take long before you have the unit connected to a free HDMI port and feed it power through one of the 3 USB ports (designated for power). The stick feels a little brittle sticking out from the HDMI port, so I would definitely recommend that you make use of the provided HDMI extension cord, to ensure you don't harm the TV's HDMI connector.

Taking a peak inside the device, reveals a small double-sided multi-layered board with 4 Elpida EBJ10UE8BDSO-DJ-F chips (256MB DDR3 SDRAM @ 1066MHz), a Hynex HY27UF084G2B chip (4GB NAND flash), the Rockchip RK3066 SoC (dual-core ARM Cortex-A9) and a tiny WiFi board.


One of the most interesting aspect of such a small device is its power/performance envelope, which I measured to a ridiculously low 0.7W in idle and 2W during a heavy load. To put this into perspective, your average Internet router uses up 12-15W 24x7.


Initial impressions of software

The device is surprisingly fast at booting up from a cold state, taking just some 45 sec. before it is ready for action. USB mouse and keyboard is immediately recognized, which means the USB host mode is functioning. Google Play is pre-installed, so getting access to all the software available is a breeze, as long as you set up a Google account. The device appears to pretend it's a tablet, so you will get mobile versions of webpages as you browse around, and tablet versions of applications (i.e. NetFlix). It takes a little getting used to navigating the Android UI without touch, but the experience is helped by the snappiness and responsiveness of the device, which feels a great deal better than various set-top boxes I have tried in the past.



On a 50" screen with native 1080p support and the MK802IIIS output set to 1920x1080 @ 60Hz, text and edges looks a little more pixelated than I would've liked though, leading me to suspect there's some scaling going on between Androids frame buffer and the actual display. Taking a screen dump in Android supports this theory, as the resulting image is not 1920x1080 pixels but only 1280x720 (click the image above to inspect it full-screen).

Since true 1080p is not possible, there's no reason to set the HDMI mode higher than 720p (1280x720 @ 60Hz in Screen settings). I tried to capture photographic evidence for why I think it is a bad idea to go 1080p, but it is not easy to get the lighting and focus right. The first picture below is 720p while the second one is 1080p, click the images and inspect the aliasing.




Notice the jagged edges of the 1080p (the last) image, particular visible when you look at the "home button". This leads to a disappointing conclusion; the device output is always 720p format and 1080p is a scaling after-through. The advertised 1080p is non-sense and I would argue Rikomagic's marketing department went a little too creative here.

Media playing

There is some rudimentary media software on the device, but nothing special to write home about. Luckily, we have plenty of media options on Android. Playing YouTube with Google's official app is a very nice experience, except for one major problem; there's no way to go full screen!


Once again, if you have a large physical screen, you can get away with consuming some YouTube content in a window without it being too annoying. However, there is a fix for this, which is to go download a legacy version and install the apk file manually outside of Google Play. If you do this, you will lose the latest official version and if you want this permanent it might be a good idea to ensure that the automatic update feature is disabled for YouTube.



The interface is a little different and I find it's not as easy to explore and discover content, but as you can see below, it does allow full screen mode.



NetFlix also appears to be working well, albeit the streams are definitely not HD quality. Apparently NetFlix does not allow for HD content to be decrypted in software on Android devices (except a few devices with the OMAP SoC, due to a deal between Texas Instruments and NetFlix). A little research reveals some details:
Specifically, TI's OMAP 4 platform, complete with M-Shield security technology and TI's quad-radio WiLink 7.0 connectivity combo solution, met the Netflix requirements for mobile content streaming, something that most Android phones haven't been able to do.

The speed of the UI is impressive though and the whole layout is actually superior to other set-top boxes I have seen with proprietary NetFlix software - for some reason I like this NetFlix tablet software better on my TV than I do on a tablet! One potential issue could be those relying on closed captioning, because the subtitle is rendered with a relatively small font which I was able to get used to on my 50", but people with smaller TV's or non-20/20 eyesight might find this problematic.



It's hard to judge the video quality, but my guess is that it's middle-tier non-adaptive 2-3 Mbit/s which NetFlix qualifies as "better than DVD quality". It's definitely a decent quality, but it would obviously be nice if NetFlix would allow HD playing on Android. I've heard rumors that there are unofficial NetFlix HD players available in the more shady Android hacking regions of the Internet, but I have not explored this in depth


Thankfully the very popular XBMC software has now been ported to Android and can be downloaded as a binary package as a pre-release (it will probably make it into Google Play before too long). This player works like a breeze, accessing all the media on my NAS and allows for tons of plugins for consuming online media streams. The great thing about XBMC is that it is developed in the open and there are lots of plugins for it, so consuming iTunes podcasts, live TV streams and DLNA content are just a few possibilities. The two screenshots below are taken from the popular TWiT Tech News Today show and demonstrates how cheap and easy it now is to pull this kind of high-quality Internet content onto your TV.




Playing SD content over DLNA/UPnP from a local NAS (containing my digitized DVD collection) works really well, even if the picture quality is not quite as good as what my other DLNA players achieve. You definitely don't want to watch SD content in 1080p mode, where the 480p to 720p to 1080p double up-scaling amplifies aliasing and compression artifacts quite significantly.



Trying to play some of the few full-HD (1080p) movies I have, did not turn out so well. The frame rate would be inconsistent, dropping many frames. I can not imagine this is a bandwidth issue, since I fixed the antenna and have secured a good down-link speed in other applications (continue reading section below). Perhaps the XBMC port is not yet optimized for Android. Perhaps this is an issue with the particular combination of hardware in the MK802IIIS. Perhaps a hardware driver is missing. Perhaps installing another ROM with an overclocked CPU could help. In any event, do not expect to be playing full-HD content with this device and the XBMC software it their current state!

WiFi/antenna

It did not take long to notice that the WiFi performance of the device was less than impressive. 10-15 meters away from the access-point, the connection speed remained low and would sometimes drop completely. The application WiFi Analyzer reveals the troubling news.



After Googling this for a bit, I found other people with this issue, and even people who were trying to fix the hardware itself. Apparently, the antenna ground and signal wire are shorted from the factory, and sure enough, opening it up and probing the antenna joins with a multimeter, confirmed that these were indeed shorted out!


One forum thread suggests simply to desolder the ground and mask the connector with some isolation tape. Here's the thing though; as far as I can tell, it appears that the wires are both purposely shorted out at the actual antenna as well as on the main board itself!? I am not an electronics engineer and I have no idea what's going on here, but this seems suspect to me. However, since I had a standard 5db WiFi table antenna laying around, I figured there was no harm in trying to solder this one on instead and see what happened.


Thankfully, the modification resulted in a much better signal, with signal strength going up from -65db to -40db and link quality up from 20Mbps to 65Mbps and I have never lost the connection since.



It is not for your average Joe to perform such a hack (although it's by no means hard) so this aspect is obviously disappointing and is going to cause some people headaches. I have to imagine the antenna design is some crude cost saving maneuver by the manufacturer and that there's a way to get to the actual non-shorted RF point for the WiFi chip, but that's beyond my expertise.


CPU/Performance

The MK802IIIS sports the latest and greatest cheap China SoC, the Rockchip RK3066 which is a 40nm dual-core ARM Cortex-A9 part. While the RK3066 won't break any speed records among the established ARM implementors like Qualcomm, Nvidia and Samsung; this is a worthy upgrade to the widely used AllWinner A10 and A13 (ARM Cortex A8) SoC's which could be found in previous generations of these cheap Android sticks and tablets. Examing /proc/cpuinfo reveals the following:

Processor : ARMv7 Processor rev 0 (v7l)
processor : 0
BogoMIPS : 2399.21

processor : 1
BogoMIPS : 2399.21

Features : swp half thumb fastmult vfp edsp neon vfpv3 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x3sing
CPU part : 0xc09
CPU revision : 0

BogoMIPS is just a very rough indicator of instruction performance, but it can form an interesting performance indicator for us when comparing across other ARM CPU's. I have extracted BogoMIPS numbers for the other ARM devices in my household.

Synology DS211+ NAS (Marvell Kirkwood mv6282):

Processor : Feroceon 88FR131 rev 1 (v5l)
BogoMIPS : 1589.24
Features : swp half thumb fastmult edsp

Cheap no-name china tablet (AllWinner-A10 Cortex-A8 ARM):

Processor : ARMv7 Processor rev 2 (v7l)
BogoMIPS : 1001.88
Features : swp half thumb fastmult vfp edsp neon vfpv3

Western Digital Live TV box (Version 3):

Processor               : Sigma Designs TangoX
cpu model               : MIPS 24K V7.12  FPU V0.0
Initial BogoMIPS        : 332.59

It should be noted that technically this chip is not ARM based and is specialized for video decoding.

Asus RT-N16 Internet router:

processor  : Broadcom BCM4716 chip rev 1
cpu model  : MIPS 74K V4.0
BogoMIPS  : 239.20

Once again, this is actually a MIPS design and not an ARM CPU. Unfortunately I do not own any of the tinkering boards I mentioned in the introduction, but I have tried to determine the values for these platforms by searching forums and list them here as well.

Beagleboard:

Processor       : ARMv7 Processor rev 2 (v7l)
BogoMIPS        : 851.45
Features        : swp half thumb fastmult vfp edsp thumbee neon vfpv3

RaspberyPI:

Processor : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS : 697.95
Features : swp half thumb fastmult vfp edsp java tls

I was unable to locate any info on Arduino, probably because this kit is so simple nobody got Linux running on it?! Anyway, even if we have to take these numbers with a grain of salt, it's pretty clear that none of the above listed devices comes even close to the MK802IIIS' cumulative BogoMIPS performance of a whopping 4800.

One of the frequently used Android specific benchmarking application is Quadrant, which is a much more thorough test as it includes 2D rendering, 3D rendering, floating point arithmetic etc.


A score of 3000+ is not too shabby, beating the performance of tablets 1-2 years ago. For reference purposes, the quad-core 1.4GHz Exynos 4 (4412) SoC found inside the popular Samsung Galaxy SGIII (International) Smartphone achieves 5815 points. This is actually quite impressive, suggesting scaling of the RK3066 would push a quad-core version (in the works and probably powering a 5'th generation of the MK802) beyond Samsungs current quad-core offering. Meanwhile, Samsung has now actually left the A9 arena, and is pushing the next generation ARM A15 design, which we probably won't be seeing in these cheap China devices for some time.

While playing with overclocking, it became apparent that the device actually runs at 1.2GHz rather than the claimed "up to 1.6GHz" and no overclocking option would push it above 1.2GHz. I reckon that the kernel has the frequency locked down to 1.2GHz, while the CPU itself actually is capable of going 1.6GHz. Reading various discussion forums, it appears that with a custom ROM, you are able to push the CPU up to 1.608Ghz but to be perfectly honest, I don't find that necessary - it would require more power and break the thermal design (remember there's not even a heat sink on the SoC and the USB specification states 500mA as the current ceiling which we're already close to). In any event, the clock rate is another false claim by Rikomagic!

Missing ADB-over-USB functionality

Since the dawn of time, you were able to connect a USB cable to an Android device, and use Google's SDK (specifically the Android Development Bridge, ADB) to connect to the device and perform file operations and use a shell. For some reason, this is not possible on the MK802IIIS and Google searches have led me to believe this may never have been possible. All is not lost however; the ADB tool can also work across a TCP/IP connection, it just requires a system-property on the device.

# su
# setprop service.adb.tcp.port 5555
# stop adbd
# start adbd

As you may infer from the above commands, the MK802IIIS comes fully rooted to a hackers delight. :) There are also a couple of applications that will assist you in enabling adb TCP/IP mode. The one I would recommend is adbWireless, since you can enable auto start mode, particular handy if you are going to use the MK802IIIS in an embedded scenario (as I do). You will then also want to set up the WiFi connection with a static IP-address, so that no discovery is necessary and so you can easily connect to the device with ADB etc.


Remote controlling

As mentioned previously, there's great USB keyboard and mouse support, so the easiest really is just to connect a cheap wireless keyboard/mouse. For media PC's there are even a lot of small keyboard/mouse combos that takes no more space than a remote. You may also simply download the MK802 III remote control application from Google Play and use it as a trackpad (for when you have HDMI connected and can see the display).
For remote/embedded purposes, there are several VNC servers available in Google Play. I like VNC server since you can make it start up automatically.


Ubuntu's Remote Desktop Viewer works well, but you can probably use any of the known VNC viewers, or even the HTML5 browser interface. Once again, unscaled connection reveals a frame buffer with native 1280x720 pixel resolution.


Conclusion

So there you have it, a quick walk-through of my first week with the MK802IIIS. Whether you will like this device or not, depends entirely on what you plan to do with it; so this conclusion will get divided into two distinct parts.

As a media gadget, it has great potential but image quality is not going to impress anyone with an alternative HD box (AppleTV, WD Live etc.). On a few items, Rikomagic is actually lying about the device - it is not 1.6GHz (only 1.2GHz) and it does not render 1080p full-HD (only up-scaled 720p). So unless you are willing to go through some hoops, is satisfied with SD quality (DVD content or a small TV), I would not recommend this product in its current form. Having said that, I may go ahead and order another MK802IIIS for my 32" bedroom TV, since 54$ is still dirt-cheap for these features.

As a tinkering platform, it's still a bit early for me to make sound conclusions. However, you definitely do get a *lot* of hardware and performance for your moneys worth. On top of that, the super low power consumption of the device makes it ideal for just about any embedded scenario. A rooted Android 4.1 OS means there are a ton of software readily available, so it's really just up to your imagination what can be done with it. In case you are missing Bluetooth from this review, there's also a version of the mk802 with this, for just a few $ more.

I will continue to investigate the device on my own terms, namely as a low-power embedded server for harvesting water, heat and electricity consumption in my house. In all likelihood, this entry will get a follow-up in the near future when I have had time to dig a bit deeper. Thanks for stopping by and happy hacking!

Update on the WiFi issue

Since writing this post, I have consulted an antenna engineer where I work and shown him the antenna design. It turns out, that the short I can measure with an ohm-meter is not unusual at all with small antennas destined for high-frequency (2.4GHz+) signals. What I really need to measure is induction around the high frequency and that requires special tools (which I was shown, looks like a big oscilloscope). In other words, nothing is wrong with the design of the antenna, other than the fact that performance is poor. So my recommendation would still be to mount a better antenna if you have that option, or at the very least, pull out the antenna so it sits further away from the (potentially quite noisy) CPU.