Tuesday, June 10, 2014

Minix Neo X8H HW tinkering first impressions

I just got my hands on a Minix Neo X8-H TV Box, along with an M1 airmouse, courtesy of Minix, with the aim of porting Linux to it (Amlogic Quad-Core processor this time).

First impressions

I won't bother you with the specs, which you can review at Minix' X8-H product page. However, from a subjective point of view I can say Android 4.4 Kitkat feels pretty fast and stable and, despite the youth of this processor, I haven't run into any problems while using it.

However nobody should be surprised here, since Minix was the one that honestly repudiated releasing for its devices the embarrassingly fake "Android Kitkat Betas" that plagged chinese Rockchip sticks at the beginning of this year.

One thing that I found immature though was the H/W video decoding, since using MX Player I was absolutely unable to avoid seeing the subtitles in MKV movies, no matter how many forced/unforced subtitles checkmarks I removed. This does not happen when using a Rockchip TV box, so a newer Amlogic firmware should have to fix this.

The M1 airmouse is small, looks slick, and has an accurate response, I really like it.

However, when I removed the USB receiver from the X8-H, I found myself with the plastic cap in one hand and the electronic PCB still connected to the USB port... so better handle it with care.

The serial console

That said and, after fellow developer Omegamoon dared open it first and find the UART pins, I went about to do the same since, as you may already know, the UART (or serial console) is necessary for first tinkering with ROMs/Linux, due to being the place where all debug output is dumped to, way before you get anything on screen. And, of course, no kernel compilation works the first time, at least not for me :P

Apart from that, and until flash reading/writing through USB from a PC Linux is provided with tools by Amlogic, the best way to flash and reflash this device is to use the "u-boot" bootloader, through the serial console. U-boot is what runs after power-on but just before any kernel, Android or Linux, is loaded. In fact, u-boot is in charge of loading the kernel.

Hitting Enter on the serial console while the X8-H boots is enough to get a u-boot prompt instead of booting to Android.

PCB inside Neo X8-H

Just as its smaller brother, the Neo X7, the internals of this device boasts quality. And you may say: Why?

Well, let me recount a few items that you will NOT find on other cheap TV boxes that usually suffer from reboots in the middle of your favorite movie:

- The processor has a large heatsink of quality metal on it (instead of crappy tapes)
- The memory has that large heatsink also over it. What? The memory also has a heatsink!
- The large heatsink has another heatsink on top of it! What? Yes, attached to the top of the box!

Minix Neo X8-H PCB

Not enough?
- There is an embedded battery to keep the RTC time while powered off
- Count the number of capacitors, coarsely that's a major plus for stability.
- They even soldered pins for the UART serial console!! (bottom left)

Yes, the UART pins are right there for us tinkerers:

UART RX/TX pins plus power pins

So, with just a 3 pin [low-profile] connector broken in two, I was able to get them out:

Black for Ground, Red for X8H's TX, Blue for RX.

With a rather ugly cutout at the back of the box (upssss):

And, finally, connecting it to my PC through a Serial2USB board, the full boot log was available, including access to the u-boot console (boot log here).

Quick tests

The u-boot version is reported as this bizarrerie: U-boot-00001-g473771c-dirty
As far as I know it should be the year followed by the version within that year, so I guess somebody must have changed it, obscuring the source code it's based on.

u-boot log on Minix Neo X8-H

Once booted, Android reports kernel version 3.10.33, which is the latest one openly provided by Amlogic, and which, after some comparisons I believe is based on Linaro Stable Kernel tree for Android, which currently has the same version.

Unfortunately, I have found a few of the same device-specific kernel source modifications by Amlogic people, so typical of Rockchip kernels. That is ugly, prevents mainlining (using the official kernel and easily updating it), and is really badly looked upon.

On the bright side, this kernel is very modern and, magnificently, it is device-tree based.

What's that you say? Well, a device-tree file would allow you to use the very same kernel (no recompiling ever!) among all devices using, at least, the same Amlogic processor.
You just need to flash a different device-tree file! It's like an index telling the kernel what does the box in question have inside and where to find it.

Previously, on the dark ages that Rockchip sent us to, every vendor wildly modified the kernel source with its own, often buggy, little specifics, which caused an explosion of RK kernels everywhere, a chaos where you used a different kernel for each device and went crazy to keep them all up to date.

I have done some quick tests like extracting the device-tree file. Here you can see the device-tree of Minix Neo X8-H, which you can compare to the one posted by CNX-Software for the Tronsmart Vega S89 device-tree, it's interesting!

Another thing I've done is test the capabilities of u-boot, like being a client for a TFTP server on my PC, where I plan to place my kernel compilations, to download and flash to the Neo X8-H, like in this example:

u-boot getting new file for the X8-H from a TFTP server

I have been told that Minix may soon be releasing the source code its TV box is using, which is again one of the nice things we can expect from Minix, who has already released it before.

Once that is done I'll go on to recompiling and trying to get Linux into this beast! Stay tuned for the instructions!

Friday, January 3, 2014

Hacking into the Minix Neo X7

       Recently, just in time for the holiday season, I have been testing and developing with a Minix Neo X7 and its very handy A2 airmouse.
Minix NEO X7 TV box with RK3188 Quad-Core CPU and 2GB RAM

    This TV box is remarkable to me on the outside for the quality of its finishes, that do make it sturdy and good looking. On the inside there are some probably good choices on the design, namely:

- A quality Audio CODEC (RT5616 that afaik is a Realtek ALC5616) instead of the usual cheap RK1000 shipped on most TV boxes.

- A well suited on-board Ethernet MAC (Realtek RTL8152) as opposed to using the internal MAC of the RK3188, as is done by most other TV boxes, which are riddled with bugs (to list a just few of RK MAC's problems: quirks when connecting Ethernet directly to a PC, stops working on TV-box Linux restart, CPU shut-down upon serving heavy files over SAMBA, ...).

- An on-board battery for the RTC chip (real-time clock HYM8563 to keep the time even without network), which may be interesting for embedded projects with a Linux OS.

    Also, as a less precisely statement, though based on my electronics background, just by looking at the X7 PCB one can find many more capacitors than on most other devices. This is maybe one of the most important good points of this box, since having those capacitors means much more stability, so that it is far less likely for it to hang/reboot while doing heavy duty stuff.

Next time your Android stick/tablet/phone reboots, hangs, or throws you out of an app, think that more than half the times this is due to trimmed down capacitor count, while the rest of the times it's just buggy SW.

Apart from that, Minix has already released twice their kernel sources:

- In September 2013, to well known developer phjanderson (here)

- And then again in December 2013, for the MINIX Developer Challenge, which by the way may be of interest to Android hackers and artists, since they offer well rewarded prizes for the best UI (up until Feb. 9, 2014).

    The practice of respecting the GPL license is something we, as an open source community, value most and certainly distinguishes one vendor from another.

    Think that, even for Android, having kernel sources means an "explosion" of ROMs, developers, and, generally, features such as safer overclocking, updates, fixes (i.e. Vsync screen fix), etc, without the irksome binary patching.

     However, if I could make a wish, that would be the schematics of this TV box, so we can know which CPU pins are connected to which pins of the many ICs on the board, so as to give an even better support for all its components.
     Please note that plain schematics are like the blueprint on hotel room doors, they don't disclose how the hotel was built, just how the rooms are set up.

Hacking the machine

1) First things first, you may want to backup your recovery partition (no need to backup the others, unless you have your data on it, since MINIX offers the latest stock ROMs on their site). For that we do the following:
- Coonect the X7 to the power outlet (but don't press the power button yet)
- Connect the X7 to the PC through its USB OTG MicroUSB connector
- Carefully insert a clip into the "Recovery" pin hole (near the HDMI connector) until a pushbutton clicks, and keep it pushed.
- Press the X7's Power button

Then, upon doing a "lsusb" on the PC you'll see the X7 in bootloader mode, listed as a nameless USB device.

You can check the partition table (as a list formatted like: partition_size@partition_offset(partition_name)) by issuing this command:

sudo ./rkflashtool r 0 1 | head -n 11

The partition parameters is what follows after mtdparts. On my X7's revision this looks like:


So backing up recovery partition becomes (swapping size <=> offset):

sudo ./rkflashtool r 0x20000 0x10000 > NEO_X7_recovery.img

2) Second step would be to root Android, so you can reboot to recovery (i.e. Linux) anytime. Rooting the X7 is done as described in this post.

3) Now you want to compile your kernel with the options (.config) you prefer, just remember to use the latest kernel source, at the last line of the MINIX Developer Challenge announcement.

As a base for any hacking, the stock Neo X7 config is: /arch/arm/configs/box_3188_r2_defconfig

To compile your own kernel you can follow this post: Generic Linux Kernel building for RK devices.

4) Last step is flashing your shiny new kernel to the recovery partition of the X7. This is done with the following two commands:

sudo ./rkflashtool w 0x20000 0x10000 < recovery.img
sudo ./rkflashtool b

5) In order to boot to Linux, you just need to insert an SD card with your Linux RFS (you can create your own RFS as described here) and then, you can either use this excellent "Autorun Linux" app, or install "Android Terminal Emulator" get inside it, type "su" and then "reboot recovery" every time.

That's it, happy hacking!

Regarding Android 4.4 KitKat

Yesterday Minix issued a brief message regarding the recently announced, supposed, Android 4.4 support on some RK3188 devices from other vendors [that do not release their kernel sources].

Since I have been myself, along with other well known developers in the RK Linux community, doing work on upgrading the RK kernel to newer versions (3.0.36+ is tremendously outdated), I can confirm Minix' point of view, that the supposed 4.4 support by those other vendors is indeed FAKE.

The leaked 4.4-supporting kernel is the same old 3.0.36+ kernel with just some drivers in different structures/places and the bare minimum to trick Android 4.4 into believing it is running a newer kernel.
Naturally this is a recipe for bad outcomes, instability and developer support dispersion.

It kinda feels like those MicroSD cards that are labelled 8 GB but are internally just 4 GB...

So, I really look forward to the official release of a real Android 4.4 and its kernel sources. Until then I think we are better off with a nice theme in our current and more stable Android Jelly Bean.