Android 9 and Netflix for X96(W)
Published: 2021-04-25 19:38:02

This applies to Smart TV **X96 (X96W)** devices based on **Amlogic S905W**. In my case it was branded as **Emmerson STV200HD** distributed in Poland. 

**I take no responsibility if you brick or break your device.**

## Problem: ##
- Annoying notifications about crashed apps
- **Cannot install some apps from Google Play like Netflix**
- Android 7 is obsolete and no online updates are available

## Solution: ##
- Prepare **2GB empty microSD card**
- Download **[atvXv4 rom](https://mega.nz/file/xrQn2QTI#KaqWz5sCVrf0hAQ_DCZ5vgomBYkQfgDD77myCSkQ5I8)** based on **AndroidTV 9.0**
- Extract files from `atvX_s905w_4.3.zip` archive
- Create `aml-upgrade-package-extract.c` file in extracted files directory with following contents (**Windows users should use  [Amlogic USB Burning Tool](https://androidmtk.com/download-amlogic-usb-burning-tool) to create microSD with `aml_upgrade_package.img` file and skip to `Boot from microSD`**):
```c
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>

uint32_t convert(uint8_t * test, uint64_t loc) {
  return ntohl((test[loc] << 24) | (test[loc + 1] << 16) | (test[loc + 2] << 8) | test[loc + 3]);
}

void main(int argc, char ** argv) {
  FILE * fileptr;
  uint8_t * buffer;
  long filelen;

  FILE * f;
  char * filename;
  uint64_t record;
  uint64_t record_loc;
  uint64_t file_loc;
  uint64_t file_size;

  if (argc <= 1) {
    printf("Usage: %s [firmware-file-name]\n", argv[0]);
    exit(0);
  }

  fileptr = fopen(argv[1], "rb");
  fseek(fileptr, 0, SEEK_END);
  filelen = ftell(fileptr);
  rewind(fileptr);
  buffer = (uint8_t * ) malloc((filelen + 1) * sizeof(uint8_t));
  fread(buffer, filelen, 1, fileptr);
  fclose(fileptr);

  for (record = 0; record < (uint8_t) buffer[0x18]; record = record + 1) {
    record_loc = 0x40 + (record * 0x240);

    filename = (malloc(32));
    sprintf(filename, "%s.%s", (char * ) & buffer[record_loc + 0x120], (char * ) & buffer[record_loc + 0x20]);

    file_loc = convert(buffer, record_loc + 0x10);
    file_size = convert(buffer, record_loc + 0x18);

    f = fopen(filename, "wb");
    if (f == NULL) {
      printf("ERROR: could not open output\n");
      printf("the error was: %s\n", strerror(errno));
      free(filename);
      continue;
    }
    fwrite( & (buffer[file_loc]), sizeof(uint8_t), (size_t) file_size, f);
    fclose(f);
    free(filename);
  }
  free(buffer);
}
```
- Compile script:
```bash
$ gcc aml-upgrade-package-extract.c -o aml-upgrade-package-extract
```
- Use script to extract img file contents:
```bash
$ ./aml-upgrade-package-extract aml_upgrade_package.img
```
- Make sure you have **FAT32 partition** on your **microSD card** and execute following commands on **unmounted device**:
```bash
### !!! WARNING: Replace /dev/sdc with path to your card. Do not use partition path like /dev/sdc1 !!! ###

$ sudo dd if=aml_sdc_burn.UBOOT of=/dev/sdX bs=1 count=442
$ sudo dd if=aml_sdc_burn.UBOOT of=/dev/sdX seek=1 skip=1 bs=512
$ sync
```
- Mount FAT32 partition of you microSD card and **copy following files**:
 - `aml_sdc_burn.ini`
 - `aml_sdc_burn.UBOOT`
 - `aml_upgrade_package.img`
- Umount microSD card and plug it into X96
- **Boot from microSD**:
 - Take out power cable from X96
 - **Insert a match (or any kind of object that will fit) to AV port and hold the switch that is inside**
 - Plug in power cable to X96 while holding the switch
- **Do not worry if there's no signal on the screen.** If X96 won't reboot after 10-15 minutes, plug out and plug in power cable. Device should boot up with new rom.
- **Add you Google account and install/update Google Apps from Google Play**
- Install Netflix and other apps you like. Enjoy using your device!

### Used sources:
- Jean Luc Aufranc, _[How to Create a Bootable Recovery SD Card for Amlogic TV Boxes](https://www.cnx-software.com/2016/11/19/how-to-create-a-bootable-recovery-sd-card-for-amlogic-tv-boxes)_
- N'ayam Amarsh'e, _[Bringing you the latest release of atvXperience v4 - Pie for S905W!](https://forum.xda-developers.com/t/s905w-atvx-v4-androidtv-9-0.4140379/)_