Hacking the Popcorn Hour C-200
Update: A new firmware version has been released since the publication of this article. I do not know if the procedure described below will work with the new version.
The Popcorn Hour C-200 is a Linux-based media player with impressive specifications. At its heart is a Sigma Designs SMP8643 system on chip with a 667MHz MIPS 74Kf as main CPU, several co-processors, and 512MB of DRAM attached. Gigabit Ethernet, SATA, and USB provide connectivity with the world around it. With a modest $299 on the price tag, the temptation to repurpose the unit as a low-power server or cheap development board is hard to resist. This article shows how such a conversion can be achieved.
Kernel
The PCH runs a patched Linux 2.6.22.19 kernel. A source tarball is available from the manufacturer. This contains the sources with Sigma support patches, Con Kolivas’ patch set (scheduler tweaks), and assorted unrelated changes. Properly split patches are unfortunately not available. I have created a reduced patch against vanilla 2.6.22.19 with only Sigma-specific changes, available here.
The installed kernel has a number of features disabled, notably PTY support and oprofile. We will use kexec to load a more friendly one.
As might be expected, the PCH kernel does not have kexec support enabled. It does however, by virtue of using closed-source components, support module loading. This lets us turn kexec into a module and load it. A patch for this is available here. To build the module, apply the patch to the PCH sources and build using this configuration. This will produce two modules, kexec.ko and mips_kexec.ko. No other products of this build will be needed.
The replacement kernel can be built from the PCH sources or, if one prefers, from vanilla 2.6.22.19 with the Sigma-only patch. For the latter case, this config provides a minimal starting point suitable for NFS-root.
When configuring the kernel, make sure CONFIG_TANGOX_IGNORE_CMDLINE is enabled. Otherwise the command line will be overridden by a useless one stored in flash. A good command line can be set with CONFIG_CMDLINE (under “Kernel hacking” in menuconfig) or passed from kexec.
Taking control
In order to load our kexec module, we must first gain root privileges on the PCH, and here a few features of the system are working to our advantage:
- The PCH allows mounting any NFS export to access media files stored there.
- There is an HTTP server running. As root.
- This HTTP server can be readily instructed to fetch files from an NFS mount.
- Files with a name ending in .cgi are executed. As root.
All we need do to profit from this is place the kexec modules, the kexec userspace tools, and a simple script on an NFS export. Once this is done, and the mount point configured on the PCH, a simple HTTP request will send the old kernel screaming to /dev/null, our shiny new kernel taking its place.
The rootfs
A kernel is mostly useless without a root filesystem containing tools and applications. A number of tools for cross-compiling a full system exist, each with its strengths and weaknesses. The only thing to look out for is the version of kernel headers used (usually a linux-headers package). As we will be running an old kernel, chances are the default version is too recent. Other than this, everything should be by the book.
Assembling the parts
Having gathered all the pieces, it is now time to assemble the hack. The following steps are suitable for an NFS-root system. Adaptation to a disk-based system is left as an exercise.
- Build a rootfs for MIPS 74Kf little endian. Make sure kernel headers used are no more recent than 2.6.22.x. Include a recent version of the kexec userspace tools.
- Fetch and unpack the PCH kernel sources.
- Apply the modular kexec patch.
- Using this config, build the modules and install them as usual to the rootfs. The version string must be 2.6.22.19-19-4.
- From either the same kernel sources or plain 2.6.22.19 with Sigma patches, build a
vmlinuxand (optionally) modules using this config. Modify the compiled-in command line to point to the correct rootfs. Set the version string to something other than in the previous step. - Copy
vmlinuxto any directory in the rootfs. - Copy
kexec.shandkexec.cgito the same directory asvmlinux. - Export the rootfs over NFS with full read/write permissions for the PCH.
- Power on the PCH, and update to latest firmware.
- Configure an NFS mount of the rootfs.
- Navigate to the rootfs in the PCH UI. A directory listing of
bin,dev, etc. should be displayed. - On the host system, run the
kexec.shscript with the target hostname or IP address as argument. - If all goes well, the new kernel will boot and mount the rootfs.
Serial console
A serial console is indispensable for solving boot problems. The PCH board has two UART connectors. We will use the one labeled UART0. The pinout is as follows (not standard PC pinout).
+-----------+
2| * * * * * |10
1| * * * * * |9
\-----------+
J7 UART0
/---------------------/ board edge
| Pin | Function |
|---|---|
| 1 | +5V |
| 5 | Rx |
| 6 | Tx |
| 10 | GND |
The signals are 3.3V so a converter, e.g. MAX202, is required for connecting this to a PC serial port. The default port settings are 115200 bps 8n1.
May 4th, 2010 at 6:12 pm
Mind Blowing….Well Done !
May 6th, 2010 at 7:19 pm
Neat. Let me know when you need a new FATE machine ID and config ID for running FFmpeg build/test cycles on the Popcorn Hour. :-)
May 13th, 2010 at 2:10 pm
Would this work for A200 as well?
May 13th, 2010 at 2:15 pm
I suppose the A200 uses more or less the same software, and almost certainly the same kernel, so it should work on that one too.
May 24th, 2010 at 2:51 pm
Could this in theory boot the Android kernel with directfb and other goodies from the Arriba development kit ? http://99.9.168.19:3001/documents/show/12
If so one could be running Android on this bad boy soon!
May 24th, 2010 at 2:57 pm
The hack can boot any kernel. It’s up to the new kernel to provide drivers for all the hardware. Your link is dead, so I can’t tell what that kit contains.
May 24th, 2010 at 3:05 pm
It holds a full Eclipse development kit, which builds kernel & images to boot from NFS and run Android (1.6-2.1) with. I built the kernel and filesystem as a test before, but have no access to it right now (It’s a long weekend off, i am not at my home pc. I got stuck at the point where Yamon refused to boot it on production hardware since it was not signed.)
The kernel itself is mostly open, with some closed-source MRUA .ko files. An example (hardware-accelerated?) mediaplayer for the Android OS on sigma boxes is included as well.
May 26th, 2010 at 8:40 pm
The site is back up, for those that may be interested. It’s not mine, but visiosofts’. Guess they had problems this weekend on the server. There’s several bootlogs on the bug tracker and some screenshots as well. If i find some real time, i might try your work on my 865x :) Thanks for the hack!
July 21st, 2010 at 2:13 pm
There is a problem though: your config (http://hardwarebug.org/files/pch_hack/kernel_config) doesn’t work for vanilla 2.6.22.19 kernel (at least from linux-mips.org).
July 21st, 2010 at 6:02 pm
You need the Sigma patches.
July 22nd, 2010 at 12:46 pm
The problem is that Sigma patches are not applicable to 2.6.22.19 kernel sources from linux-mips.org. Patches can be applied to vanilla sources from kernel.org, but kernel config is not suitable there.
Also, I’m not sure that mips kernel can possibly be built from sources at kernel.org.
Rebuilding firmware kernel is much less preferrable for me.
So, what exact sources did you use?
July 22nd, 2010 at 9:46 pm
http://www.networkedmediatank.com/download/firmware/nmt/gpl/linux-2.6.22.19.tar.bz2
July 23rd, 2010 at 2:15 pm
Thanks, a lot, I’ve successfully built the kernel. But loading it with kexec userspace tool (latest version from kernel.org, 2.0.1) fails with
Invalid memory segment 0×4000000 – 0x42d3fff
What kexec binary did you use?
July 24th, 2010 at 12:01 am
I used latest from git. There are some MIPS fixes there which I don’t think have made it into a release yet.
August 24th, 2010 at 6:55 am
[...] list. This one reports itself as running on 74kf CPU. Googling for this processor quickly brings up Mans’ post about the Popcorn Hour device. So, congratulations to him for getting the mundane box to serve a higher purpose. Perhaps one day, [...]
October 24th, 2010 at 11:29 am
I build some software for my C-200 and documented it here:
http://code.google.com/p/popcorn-bld/wiki/Readme. I hope that others can find it useful. I added a pty module and I was able to start an ssh server (dropbear).