Saturday, July 20, 2019

Make Something That Isn't A Computer A Computer - Episode 4: Amazon Fire TV Stick

With each passing episode of this series I can hear you screaming at your screen more and more. "BUT TUCKER!" I hear you yell. "THE AMAZON FIRE TV STICK IS BASICALLY A COMPUTER ALREADY! WhY iS iT tHe SuBjEcT oF tHiS sErIeS???" And I suppose you're right. But that's not the intent of the product. The intent was to plug it into your TV and use it like a Roku. What we're essentially going to do is change it into a compute stick.

It's also important that at times like these we remember the guidelines we set in the last post of this kind
  1. The device shall no longer be specifically what it was intended for.
  2. We must be able to get some kind of terminal access to it. Root preferred.
  3. We must be able to compile programs for it.
We'll achieve all three of these very quickly, but we'll also set one further goal: being able to use this like a regular computer. And we'll look at the processor - namely its hardware video features - to see what MediaTek hides behind its NDAs.


I have a Fire TV Stick LY73PR. I got this last year during Prime Day to see if it could be hacked. And then I did nothing with it. I've finally circled back to it. At the time of purchase, it was unrootable without having to desolder and writing directly to the memory. Now, it's much easier.

This XDA Forum post provides the firmware and the details for loading custom recovery onto the stick. Since I didn't want to solder anything, I relied on a steady hand to keep a wire contact to the CLK capacitor shown in the photo at the end of the post. I had a little trouble with the script detecting the board, but then I realized it was plugged into USB3.0. I gather from my experience and the forum post that this works much better (or at all) over a USB2.0 connection.

Once I had finished this exploit, I wanted to add SuperSU. I downloaded the SuperSU Zip File to sideload onto the stick. Sadly, I had no way of interacting with the TWRP recovery to allow modifications to the system partition and then to accept sideloads. The correct way to do this is to use a USB-OTG mouse, but as I did not have one, I had to use recovery boot commands to get it done. I shipped the ZIP to the recovery partition and using this trick was able to get it to install. After doing that, I started the stick like normal, got into an ADB shell, and typed su. After confirming on screen with the remote that I wanted to allow the ADB shell to have super user permission, I was given a root terminal. So that's objective #2 done.

Objective #3 is done by virtue of it being and Android device. I have a copy of Android Studio, ergo I can compile applications for it. With a little extra effort, I can use the Android NDK to compile anything for it.

I wanted to see the performance of this device before I moved on. So I installed Minecraft and GeekBench 4. In Minecraft, I was able to get 30FPS while moving around and 40FPS while standing still. It also worked really well with the Bluetooth Keyboard and Mouse I paired to the stick. The Geekbench results were not nearly as good as I had hoped though. Despite having a Quadcore ARM processor, it only scores 401 single core and 1050 multi-core. The RenderScript score testing the GPU was only 801. To put that number in perspective, the Samsung Galaxy S4 outperforms the GPU on this thing.

But performance is really up to the user experience, not stress test numbers. It's likely the chip thermal throttled almost immediately during these tests. This wasn't the most scientific endeavour after all.

As I mentioned earlier, I expected this device to have several hardware AV decoding aspects on board, and I was correct. Using an app that lists all available codecs, the ones provided by MediaTek (and thus the ones assumed to be hardware backed) are:
  • MP3 (audio/mpeg)
  • MPEG4 (audio/mp4v-es)
  • H.263 (video/3gpp) with encoder
  • MPEG2 (video/mpeg2)
  • AVC/H.264 (video/avc) with encoder
There were many other formats listed that were provided by Dolby or Google (like AC3, VP8, and HEVC) but I imagine that these are software implementations. I'm willing to bet that on the Amazon Fire TV Stick 4K, there are more hardware accelerated features onboard. Just as a reminder, this board uses the MediaTek MT8127D SoC.

I wanted to start on a regular launcher rather than the Amazon Fire TV screen. I decided to use the Nova launcher since it was the first launcher I tried that respected the orientation of the display without trying to rotate and squish the image. Since I had root access, I could disable and subsequently delete the Amazon Fire TV Stick application (as well as the Prime Video player) to free up some space in the system partition for other stuff. 

And then something stupid happened. It underwent a firmware update. It reinstalled the apps to the system partition and it removed SuperSu. It basically undid all of my hard work. So now I had to redo all of that and find a way to crush the auto updater. This was actually harder than I expected. I went to reinstall SuperSU, and after that completed, the thing wouldn't start up, logging these error messages:
avc: denied { module_request } for kmod="personality-8" scontext=u:r:adbscript:s0 tcontext=u:r:kernel:s0 tclass=system permissive=0
This was a SELinux issue, but I don't understand. It worked so well last time!

The answer took a while to find but it didn't shock me once I did. The system partition was, once again, too full for SuperSU to install. Isn't that horrible? So again I force removed the launcher, the Prime Video app, a new Alexa Shopping app, and com.amazon.firehomestarter which blocked the boot when it couldn't find the correct launcher. I also deleted the three apps that had the name "DeviceSoftwareOTA" in them. Even when you can't manipulate the screen in recovery without a USB-OTG mouse, you can still run mount system to mount the system partition as a writable filesystem.

Okay I'll be honest. I pulled the APK for the updater I just violently deleted as well as the TV launcher to see if it would run on other Android Devices. I then proceeded to delete a bunch of other system apps that I didn't care about. There are several scripts that you can run to make room on your system partition floating around out there, the one I used for reference (I didn't actually run it) was this one. I also recommend you pick and choose the things you want to remove. For example, if it looked like a settings app, I didn't delete it for now.

I then proceeded to install the Open GApps. They have a couple of different packages of increasing size for your device depending on how much space you have and what you want installed. The cool thing is is that you can download the full/stock installer and write a file that tells the installer to ignore some files. This is super useful because even after getting rid of a lot of bloat, you don't have much room in the system partition. So I ended up installing a smattering of applications. I didn't put the Google Play Store on there, but whatever. I can just install APKs at will.

Sometimes, apps will insist on a specific orientation, but the stick only works in one orientation, so the app will look scrunched. I had to force the orientation somehow. Luckily, there's an API and a SlackOverflow post for that.

Okay, so I could go on and on (like I have already) about the setup of the software. So now, just to see, can I run the Amazon Fire Launcher APK on any Android Device?


No. No I can't. Oh well.

I want to do one more thing. I want to see what hardware codecs are supported on the Amazon Fire Stick TV 4K. So I bought one. This device is running Android 7.1.2. No root exists for this for now, but I can still install APKs over ADB. Here's the list:
  • MPEG2 (video/mpeg2)
  • HEVC (with encoder, video/hevc)
  • MPEG4 (video/mp4v-es)
  • H263 (video/3gpp)
  • AVC (with encoder, video/avc)
  • VPX (video/x-vnd.on2.vp8)
  • VP9 (video/x-vnd.on2.vp9)
  • DVHE STN, DVHE STH, DVAV SER (video/dolby-vision)
I also ran GeekBench 4 on it. It scored 701 and 2060 on single core and multi core respectively, and got 1300 on compute. Better than the original, but still kinda dismal. It is, after all, only a quad-core.

But we've strayed very far off topic. Can the Fire TV Stick be turned into a generic compute stick? For the most part, yes. It's hit or miss on mouse cursor support as well as some other aspects (performance, space on the system partition, etc.), but for the price it isn't bad. But the goal was accomplished, but it wasn't super hard. Most of the work of it being an Android device with a root procedure really made it easier.

No comments:

Post a Comment