Asus Transformer Infinity (TF700T)/Install

= Installing Gentoo Linux on Asus Transformer Infinity (TF700T) =

Since i bought the amazing Infinity (Asus TF700T) with the keyboard dock, i started wondering how to put a real OS on it, which is my beloved Gentoo.

Finally i managed to get to the point and achieve something usable.

In this wiki page i will be describing what i did and provide both instructions AND the final product.

Preliminary notes
A few preliminary notes.

You MUST have the keyboard dock, otherwise you must try to plugin some kind of USB keyboard, which i guess would be a pain to use. I have not tried bluetooth at the moment on Gentoo and the TF700T (it should work), but i guess getting to the point of pairing the keyboard would require the shitty on-screen keyboard, and X working, which still requires you to type a lot of stuff from command line before you can actually make it start automatically at boot.

I strongly recomand to install Gentoo on the microSD. The SD slot on the dock might work as well but do you trust yourself to never detach the dock itself? Or are you sure it will never happen by accident? If it does, well, at least a reboot + fsck is mandatory! Installing on the internal memory is also al option, but consider the wear and tear due to compilation! In this case you might want to move your portage build dir to the microSD.

The tables has only 1gb of ram. While it might seems a lot, and it surely was up to a few years ago, it's surprsingly small by today standards. Don't ask my wy Asus choose such a limited amount on a top-level device, just live with it. Couple it with the basic useless of swap space on this device: on the internal memory i strongly recomend to avoid, and on the microSD it's really a serial device, so putting swap on it causes the entire device to crawl as soon as it's being used. Given this considerations, i suggest a lightweight desktop like LXDE and memory saves wherever possible like don't run background services or memory-hogs.

Before the first linux boot
The Asus Infinity (TF700T) comes out of the box as an Android tablet, it's provided with android 4.2.1 or something similar but it is not so important because we want to install Linux on it, so these steps will provide information on how to enable dual boot on this device. You will need to do some steps on Android before starting with Linux.

Unlock and root
You must unlock your bootloader first, follow these instructions:

Go to this link: support page on Asus website, select OS Android and from utilities download the "Unlock Device App: Unlock boot loader". Now install, follow directions and enjoy your boot-unlocked tablet (yes, this will void your warranty, you have been warned).

For more directions, check this XDA thread: XDA on unlock TF700T

At this point you need root. My recomandation is to install a custom ROM which will do everything for you. Which one is on you, check this link on XDA how to root and custom ROMS for detailed instructions and a list of ROMS, but bear in mind that at the moment the multi boot has been tested only with a few ROMS: either CROMi-X, CROMBi-KK or ZOMBi-X latest versions, on insternal SD only, no rom2sd, data2sd or anything fancy. I suggest you to stick with one of these.

Making your tablet unbrickable
While there is basically no threat of briking your tablet, it's strongly advised to follow these steps here on how to make your tablet "safe" from any messing up you might do.

In short:
 * download this: flatline
 * install google's ADB and fastboot (from SDK) on oyur linux pc
 * flash the downloaded custom recovery: fastboot flash recovery flatline_device.im
 * reboot device to recovery, select "advanced" and "wheelie", select "Step 1: Flash AndroidRoot BL"
 * it will poweroff. Reboot to asndroid, let it boot, use a bit, then reboot to recovery again
 * select "Step 2: Generate wheelie blobs" from the same menu as before
 * when finished, reboot and save from the device the files it has created (check under /data or /tmp for AndroidRoot or similar)

Keep these files safe, they are your lifeline. (NOTE: these instructions are given with no warranty, use at your risk!)

Prepare the storage
As noted above, i suggest you install Gentoo on the microSD. In addition to that, since also microSD are subject to tear and wear damage, i suggest to disable logs (or put them on a ramdisk) and put the /tmp folder on ram. For additional safety you could also move the portage build dir to some other device, like an usb attached disk or network share (ok, this might be too much, i regularly build on my microSD).

I suggest to plug in a very fast microSD, but be aware that the TF700T microSD slot is a bit picky. I managed to get a Sandisk 32gb Class 10 microSD to work great, while no 64gb card so far: they seems to be working, but at some random point under heavy load will drop to read-only with no warning. It seems to be an hardware issue since moving the same card to the SD slot on the dock fix the issue.

Anyway, i assume we are using the microSD slot here on at least 16gb microSD card.

You need to format it, since i am aware of no good tools on Android for doing this, put the card in to your pc and prepare two partitions:
 * the first formated as EXT4, at lest 16gb (better 32gb)
 * the second as VFAT, for data exchange (not required, just optional if you have spare space)

I will not cover it here, but you could use the Android partition to store Gentoo, but this will get rid of your Android, or install Gentoo on the internal memory data partition, this is left to you to try.

(Repartitioning the internal memory is STRONGLY NOT ADVISED. I was thinking about it but was discouraged by the fact it does not use any common partition scheme and no linux tools are able to mess with it. Plus the fact that it can really brick your tablet requiring you to grab the lifeline from last paragraph)

Setting up dual-boot
Dual-booting the tablet is done using a kexec method which is just brilliant. The full thread on XDA is here.

In short, with the changes we need for Gentoo:
 * Check you have a supported ROM and recovery (CROMBi-KK and TRWP for me worked well)
 * boot into your ROM and make sure you have terminal emulator, root and busybox installed
 * download this: scripts
 * extract in the internal memory, you should get a folder called TF700t-AKBI-v2.6.5
 * don't download any rootfs, you will be making your own with Gentoo on it soon enough.
 * become root: su bash
 * run the script: sh firstintall.sh (it will install the multiboot blob).
 * When prompted, select the proper kernel for your android from the list (a mistake here will make your Android intallation unbootable, but you can fix it from the multiboot prompt later on, left as an exercise in patience)
 * When asked for the rootfs image, just terminate the script. We will not setup a rootfs image.
 * If the script gives an error (missing rootfs image, for example) just ignore it, all you need is the kexec blob for the multiboot to be installed and the android kernel to be copied.

(rememeber you are on Android here, not linux, so things are different. For once, you must run shell script by incoking the shell itself and not by directly run the script, as tany partition you have normally access to it's mounted as no-exec)

Very well, at this point we should have the multiboot installed and the android kernel restored for the multi-boot. We now need to configure the multiboot for booting linux from the microSD card: LABEL=CROMBi-KK BOOT=3 DEVICE=/dev/mmcblk0p1 DIR=/ KERNEL=/boot/zImage INITRD=/boot/initrd.img PRIORITY=10 LABEL=Gentoo on microSD partition 1 BOOT=3 DEVICE=/dev/mmcblk1p1 DIR=/ KERNEL=/boot/zImage INITRD=/boot/initrd.img PRIORITY=110
 * prepare to mount the multiboot partition: mkdir -p /data/media/0/kexecbootcfg/
 * mount the multiboot partition: mount -t vfat /dev/block/mmcblk0p5 /data/media/0/kexecbootcfg/
 * Create the config folder: mkdir -p /data/media/0/kexecbootcfg/multiboot/
 * Create/edit the file called boot.cfg in this directory, this is mine as an example:
 * 1) Android#
 * 1) Linux ext partition image on microsd partition 1 #
 * Adapt the example to your needs!
 * Unmount the multiboot partition: umount /data/media/0/kexecbootcfg/

The linux entry will not boot until we set up the kernel for it, but at least you should be able to reboot into Android. Try it out! The tablet will boot twice, the first time will show you the menu, the second will actually boot Android.

As Workdowg himself explains on XDA:

"What happens here is by flashing the kexecboot kernel blob (to mmcblk0p4) you are given a menu to choose a rootfs to boot from, ie Android, Linux image file, Linux on a partition... So in order for the kexecboot kernel to be of any use to you, you need to install Android and Linux kernels in your rootfs. It then reboots using the kernel you chose. The config file, boot.cfg, is installed to a small 5MB vfat partition (mmcblk0p5)

''ANDROID: Android mounts root (mmcblk0p1) "/" as /system. So we install a kernel (without modules, you did that when you installed your ROM) to a directory we make called /boot which needs to be in the mount /system directory. This kernel (zImage and initrc.img) is just extracted from _that's cm112 or _that9oc+ kernel blobs and a copied to the /boot directory.''

''LINUX: This kernel was especially compiled by JoinTheRealms from _that5 source using configs moreD_cn came up with. It needs to be installed in /boot of a Linux rootfs."''

At this point you have a working dual-boot on your tablet, we need to build gentoo so you also have something to dual-boot!

Installing Gentoo: before first boot
This is basically the standard Gentoo Handbook, so i will not bore you on the basics, but a few important things must be noted, so please keep reading.

Prepare for first Gentoo boot
I assume you want to install on the first partition of your microSD card. If not, just follow these instructions but perform them on the media you want to use (loopback image, internal memory, SD card, whatever)

These instructions will allow you to do everything from your tablet on Android, but if you prefer to make things easier, put the microSD into your linux PC and perform them there, then move the microSD to the tablet and skip to the reoot part.

I assume your microSD has already been formatted and that the first partition is the gentoo root partition. If you have a more complex partitioning scheme, have fun adapting these instructions for your case.

We need to mount the EXT4 partition, so:
 * From android, open your Android Terminal Emulator and become su: su bash
 * create a temporary folder: mkdir tmpGentoo
 * mount the microSD: mount -t ext4 /dev/mmcblk1p0 tmpGentoo (mmcblk1 is the microSD)

Download stage3 for ARM-hf
The tablet is an ARMv7 with hard floating point. The binary NVIDIA packages which we are forced to install do require you to install this architecture, so go to the gentoo ARM download page and download on your tablet the latest Stage3.

Extracting it into the mounted partition can be hard depending on your busybox, decompressing the stage3 is left to your exercise (if you are desperate, just decompress it on a linux pc then mount the microSD on the tablet).

Prepre your stage3 before first boot
(make sure to do these steps from your tablet and not from the PC) Follow the gentoo handbook to install it. In short, these are the steps:
 * cd into your gentoo mounted parttion: cd tmpGentoo
 * remount with bind dev, proc, run, sys: for i in dev proc run sys; do mount -o bind /$i $i; done
 * create your etc/resolv.conf, put inside your DNS server (Android does not have one, so you must create it from scratch)
 * chroot: chroot ./ /bin/bash
 * change the root password immediately: passwd
 * DO NOT INSTALL A KERNEL: you must use the provided that10 kernel.
 * DO NOT INSTALL GRUB OR ANY BOOTLOADER: you have multiboot already in place.
 * DO NOT INSTALL LOG MANAGERS: metalog, syslog-ng and the likes, will only slow down and add wear to your microSD.
 * Take a look at the Gentoo Handbook to see if you need something else which i clearly forgot here.
 * Don't forget to prepare your portage tree (emerge --sync) and update it as needed.

Mask and unmask packages
The provided tegra drivers works only with X up to 1.14 (which is not very stable) and since 1.13 has been masked due to security flaws, you must mask any xorg-server above or equal to 1.13. Also, many ebuilds are not yet classified as "stable" for ARM, but are nevertheless very much usable. You will need to unmask a lot of stuff, i am posting here my /etc/portage/packages.accept_keywords for you to copy: <=www-client/firefox-32 ~arm dev-libs/nss ~arm dev-libs/botan ~arm media-gfx/gimp ~arm net-analyzer/wireshark ~arm dev-libs/tinyxml ~arm x11-libs/wxGTK ~arm media-libs/babl ~arm sys-apps/texinfo ~arm net-libs/gnutls ~arm media-libs/gegl ~arm sys-devel/gettext ~arm =net-misc/networkmanager-1.0.0 ~arm =gnome-extra/nm-applet-1.0.0 =net-wireless/gnome-bluetooth-3.14.0 ~arm =x11-themes/gnome-icon-theme-symbolic-3.12.0 ~arm app-arch/p7zip ~arm
 * 1) Firefox after v.32 do not compile on ARM
 * 1) These works great:

As a rule of thumb, if a package has the ~arm keyword, try it out! They usually work very well (with Filezilla the only exception so far for me).

Then mask the packages for the NVIDIA blob to work, in your /etc/portage/package.mask: >=x11-base/xorg-server-1.13.0

Since the tablet has only WiFi, i suggest strongly to install NetworkManager and use it. Since i am going to use LXDE i have also unmasked the needed packages for the nm-applet which works great with LXDE.

This is my /etc/portage/make.conf: CFLAGS="-O2 -pipe -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard" CXXFLAGS="${CFLAGS}" CHOST="armv7a-hardfloat-linux-gnueabi" USE="bindist" PORTDIR="/usr/portage" DISTDIR="${PORTDIR}/distfiles" PKGDIR="${PORTDIR}/packages" USE="alsa opengl mp3 aacs v4l x264 consolekit neon minizip sqlite bluetooth truetype networkmanager gudev bindist X policykit jpg jpeg tiff png dbus pdf cups udev samba" MAKEOPTS="-j4" VIDEO_CARDS="v4l" INPUT_DEVICES="evdev keyboard" FEATURES="ccache -sandbox -usersandbox"

I have enabled ccache to speed up build times and help the microSD. Since we have a quad-core i have set the -j4 to speed up make. I had to disable sandbox because some packages will not build on ARM. The various useflags are just an example, adapt to your needs. Of course, you need to emerge ccache and enable it too.

Setup the kernel
No, you cannot recompile any sources provided by Gentoo nor i had any luck whatsoever with the NVIDIA provided kernel sources, since the 3.10 brach seems to work only on newer devices and the "official" branch is an obsolete 2.6 kernel.

What you have to do now is copy the same kernel your Android is using (or choose a kernel from the package which contains the multiboot loader) to the /boot folder of your Gentoo partition. I leave this as an exercise for you, you want to end up with these files: /boot/initrd.img /boot/zImage

So copy both from your Android system partition.

Since some packages needs the kernel sources to be built, we need to download the sources associated to your kernel:
 * fetch tthis URL with git (or download it and unpack) and put it under /usr/src/linux.
 * Copy your current kernel config: cp /proc/config.gz /usr/src/linux
 * decompress: cd /usr/src/linux && gunzip config.gz
 * rename: mv config .config

Install driver packages
At this moment the only way to get X to start is using the NVIDIA provided binary blob. It sucks, albeit it works, but since i am not able to recompile any 3.10 kernel and try OpenTegra, there is no other way to go.

Touch screen and trackpad works great but we need to download and install the proper drviers too.


 * Build Xorg, it will take some time, so you can sart building it while doing the rest of the steps: emerge xorg-server xorg-drivers
 * While it builds, download the package: from here
 * then unpack it into your root user home folder in the gentoo partition (i suggest to keep it there in case you need some files later on)
 * Now doenload the trackpad drivers from this link: my website(this is a patched version of the sources you can find around the web, which will not compile)
 * download the touch-screen drivers here: my website

Now wait for Xorg to be completely built and installed.


 * decompress, build and install (make install is enough) both the touchpad and the touchscreen drivers.
 * Decompress the Linux 4 Tegra package
 * Decompress the archive nvidia_drivers.tbz2 found within /root/Linux_for_Tegra/nv_tegra, it will create some folders like usr, etc and lib, DO NOT EXPAND IN YOUR ROOT FOLDER! For the following instructions i assume you will expand it into the nv_tegra folder where the archive is.
 * Copy the xorg driver from /root/Linux_for_Tegra/nv_tegra/usr/lib/xorg/modules/drivers to /usr/lib/xorg/modules/drivers. Pick the right one (the ABI12 in our case) and copy to the destination folder and rename it to tegra_drv.so.
 * Copy MOST of the libraries from /root/Linux_for_Tegra/nv_tegra/usr/lib to /usr/lib but be VERY CAREFULL not to replace libjpeg.so, you want to keep your copy of it.
 * Poke around the /root/Linux_for_Tegra/nv_tegra folder, check if there are more files you want to copy to your filesystem (probably not).

You can now reboot android and try out the dual boot, if all goes well, you will get to a grentoo login console prompt and you can login as root!