Asus Transformer Prime

Installing Gentoo on the Asus Transformer Prime (TF201)

This is an initial introduction to installing gentoo on the Asus Transformer Prime (TF201). At the moment, we can get it to boot and launch X, but there are quite a few problems. Hopefully, this site will invite others to share their own experiences, and maybe even generate some solutions to these problems.

INSTRUCTIONS
The basic steps are as follows:

PRELIMINARIES
This guide assumes that you have installed the Jelly Bean update from ASUS.

CREATE A CHROOT
(Alternatively, you can do a cross-compile installation on some other box and use rsync to copy the resultant files over to the TFP. You will still need to extract our root_patch.tar.gz.)

The first step is to install gentoo on the TFP inside a chroot environment. You can follow the standard Gentoo Installation Guide here, with the following exceptions. In what follows we assume you will be placing your gentoo installation in the TFP directory /sdcard/gentoo. I found it easiest to install gentoo on the microSD card (mmcblk1p1) and mount that card in /sdcard/gentoo.

If you don't trust us, then run: # emerge linux-firmware (or just mkdir /lib/firmware) # mkdir /system && ln -s /lib /system/vendor && ln -s /lib/firmware /system/etc # (outside chroot) cp -R /system/vendor/firmware/* /system/etc/*.txt /sdcard/gentoo/lib/firmware # Also add to /etc/conf.d/modules: modules="bcm4329" module_bcm4329_args="iface_name=wlan0" # Compile your own kernel (see below) to populate /lib/modules.
 * 1) You should use the armv7a-hardfp stage3.
 * 2) Download and extract root_patch.tar.gz inside your chroot.  This will install some configuration files and the kernel modules and the (binary) firmware.
 * NB: I found that mounting /dev/pts to /sdcard/gentoo/dev/pts before you chroot allows tmux to work.
 * NB: I also found that adding -userfetch to make.conf FEATURES fixes an emerge error about being unable to fetch packages.
 * or ( thanks to AndroidSecurityUserAndGroups ) groupadd -g 3003 aid_inet && usermod -aG aid_inet portage

FEATURES="-sandbox" emerge -1 packagename
 * NB: You will also need to establish /etc/resolv.conf by hand, by adding "nameserver x.x.x.x" to it inside the chroot. You can get the nameserver in Android by running getprop.
 * NB: You must install wpa_supplicant, dhcpcd, and sshd and add them to the default run-level.
 * NB: It would be easiest to disable qt4 USE flag with respect to wpa_supplicant (for now).
 * NB: If you get a "sandbox violation" error while emerging, you have to emerge the single package that cause you this as follows:

FLASHING THE BOOT IMAGE
Download test.blob or test.LNX onto your computer (not the TFP), and flash it onto the TFP either using the 'fastboot' utility or using 'nvflash'. For instructions on how to re-generate a test.blob, see below. Once you have finished flashing the blob, you should be able to reboot the TFP and it will boot into Android (not Linux). In order to have it boot into Linux, head to the next section.

FASTBOOT METHOD
In order to do fastboot, do the following:
 * 1) WARNING: AS USUAL, FASTBOOT AND THE TFP ARE CRANKY AND SO WHAT FOLLOWS MIGHT "BRICK" YOUR DEVICE.  PLEASE RESEARCH THE FASTBOOT UTILITY BEFOREHAND.
 * 2) Add 28 bytes to the front of the test.blob by doing the following: dd if=/dev/zero bs=28 count=1 of=newtest.blob && dd if=test.blob of=newtest.blob oflag=append conv=notrunc
 * 3) Put the TFP in 'fastboot' mode: connect it to the computer via a usb cable, install ClockworkModRecovery app on the TFP, reboot the TFP and hold down VOLUMEDOWN upon reboot until some text shows up about going into recovery.  Release VOLUMEDOWN and wait, then select the USB ICON (VOLUMEDOWN to move, VOLUMEUP to select).  This is all standard, and documented elsewhere.
 * 4) Flash the blob to your TFP: fastboot -i 0x0b05 flash boot newtest.blob.
 * NB: 'flashboot devices' will claim there is no device. But it is there.

NVFLASH METHOD
IN order to do the nvflash method, do the following:
 * 1) WARNING: AS USUAL, NVFLASH AND THE TFP ARE CRANKY.  IT MIGHT "BRICK" YOUR DEVICE.  PLEASE RESEARCH WHEELIE AND NVFLASH BEFOREHAND.
 * 2) WARNING (2): wheelie is a binary with no open source (yet), and as with any binary you should be worried.
 * 3) Reboot into Wheelie mode (REBOOT + VOLUMEUP = blank screen, but dmesg will state the device is there)
 * 4) wheelie --blob mysecret.blob
 * 5) nvflash -r --download 6 test.LNX

CONFIGURE BOOT_CHOOSER2
The blob we provided (the source of which will be linked below) includes a modifies initrd.img, which has instead of init a program called boot_chooser2, renamed 'init'. Boot_chooser2 will mount the 8th partition of your eMMC, and read the first line of the root-level file '.blob'. The first line of the file will be parsed as "device:directory:init" where: 'device' is the block device where you put your gentoo system. [ e.g. /dev/mmcblk0p8 or /dev/sda1 ] 'directory' is the directory inside the previous device where your gentoo lives. [ e.g. gentoo ] 'init' is the init script location in your gentoo root, usually /sbin/init. If anything goes wrong the boot_chooser2 program will just boot into Android.
 * 1) TODO: check for init existence before chrooting

So, if you have your chroot under /data/gentoo your /data/.boot file will look like: /dev/mmcblk0p8:/gentoo:/sbin/init If you bootup from a USB stick: /dev/sda1:/:/sbin/init If you bootup from microSD: /dev/mmcblk1p1:/:/sbin/init

Once you have created this file, reboot and it should boot into Linux. However, unless you have configured your gentoo to automatically start Xorg, you will see nothing but the ASUS logo. In order to verify that it worked, check /sdcard/gentoo/var/log/messages. You can debug problems by checking boot_chooser.log which is generated in the root of the Android filesystem.

GENERATE A TEST.BLOB / MODIFY INITRD / COMPILE THE KERNEL
The are not steps, but pointers:
 * 1) Unpack the blob (test.blob in git) to generate a .LNX file: blobunpack test.blob
 * 2) Extract the zImage and initrd from the .LNX file: abootimg -x test.LNX
 * 3) Extract the initrd: mkdir tmp && cd tmp && gunzip < ../initrd.img | cpio -i --make-directories
 * 4) Regenerate the initrd (from tmp): find . | cpio --create --format='newc' > ../initrd.img && gzip ../initrd.img
 * NB: Don't forget to gcc -o boot_chooser2.c init and cp that over to initrd as your init file.
 * 1) Regenerate the zImage (kernel): You will want to apply the JB15.patch in our git kernel/ directory, fixing an obvious error.  The kernel we used was the one from ASUS: kernel_v10_4_2_15.zip.  The patch also applies our .config file.
 * 2) Regenerate the .LNX file: abootimg --create test.LNX -r initrd.img -k zImage
 * 3) Reblob pack: Use blobpack and when done add 28 bytes to the front of the file (see the fastboot method section above)

KNOWN BUGS
Solution: There is none. Make sure you have sshd installed.
 * Problem: After I launch X and I kill X, the screen is blank.

Solution: Disable X blanking. xset -dpms or xset s off or xset s noblank (or all three)
 * Problem: X goes blank and won't go unblank.

Solution: Install the tegra_drv (xorg driver) from RC16.2 of their Linux For Tegra release (see below)
 * Problem: xrandr -o left/right/normal/inverted don't work

TIPS
Here are some tips:
 * 1) mount /var/tmp and /tmp as tmpfs
 * 2) /dev/mmcblk0p1,2,8 are ext4; mnt these in /mnt as system, cache, data respectively.
 * 3) xset dpms 0 0 0 in xinitrc
 * 4) sudo -u yourusername startx in /etc/local.d/mystuff.start for a quick and dirty test
 * 5) cpufreq-set -c 0 -g performance|powersave (do this for 0-3)
 * 6) In order to get your user to have access to the internet, add a group called "inet" group id of 3003 and add the user to that group.  This is because of CONFIG_ANDROID_PARANOID_NETWORK=y

TODO

 * 1) Disable the asusdec_kp_key and asusdec_keypad_processing debugging statements in /var/log/messages
 * 2) Touchpad (on the ASUS Keyboard Dock) doesn't work
 * 3) Sound doesn't work
 * 4) Compositing doesn't work due to unavailable graphics shared memory (tmux_mind: Did wart's tegra_drv installation fix this?  wart doesn't use compositing.)

UNDER DEVELOPMENT (TEGRA XORG DRIVER)
The tegra xorg driver (from L4T RC16.2) works! (notice that two files libjpeg.so and libEGL.so.1 are overwritten (TODO: test the conflicts))
 * 1) extract (using --backup!) config.tbz2 and nvidia_drivers.tgz to /
 * 1) remove /etc/wpa_supplicant.conf
 * 2) ln -s /usr//lib/xorg/modules/drivers/tegra_drv.abi13.so tegra_drv.so
 * 3) recompile your kernel with CONFIG_SYSVIPC

CONTRIBUTE
Please feel free to add new problems! Even better: new solutions!

Please contact peter period hartman at utoronto period ca a.k.a. wart_ in #gentoo-embedded (and elsewhere)

Or contact massimo period dragano at gmail period com a.k.a tux_mind all over the internet