Tuesday, September 23, 2014

Recovering My Chromebook

The Experiment


I bought a samsung ARM chromebook a year back and after 3 weeks of using chromeos, i got bored. So, i went ahead and did what any sane person would do, try installing Linux on it. Also the lure towards linux on chromebook is specially irresistible if you have to carry a heavy Dell laptop on your back while cycling to college every day.
My initial thoughts were that the installation process would be very similar to installing new ROM's on Android devices. But boy was I wrong.
My goal was to install a flavor of Linux to completely replace the chromeos. That is no chrooted xfce or dual booted ubuntu.

There are number of options out there that would allow installation of Linux on chromebook.
1. Installing Debian : https://wiki.debian.org/InstallingDebianOn/Samsung/ARMChromebook
2. Installing Arch :  https://wiki.archlinux.org/index.php/Samsung_Chromebook_(ARM)
3. Installing Kali Linux: http://docs.kali.org/armel-armhf/install-kali-samsung-chromebook

And I am pretty sure there are many more. Options 1 and 3 provide you with a SD card and a USB stick image that can be written onto the devices. After that the USB can be plugged into the USB-1 of the chromebook and rebooted to enter the OS of your choice. But the idea of a USB sticking out of my device never found favor with my heart(and also the fact that those images failed to boot my chromebook).

Installation of Arch Linux on the other hand proved very helpful. Creating a boot-able image using the tutorial work well on USB's, but there seems to be problems when I used it with a SanDisk 8gb and 16gb SDHC(some comments online suggested that the Kingston SDHC's were good for the task.). Now after we created a boot-able SDHC, the rest of the instructions are on moving the contents of the SDHC to the eMMC. But this is the step where things get really sketchy in terms of instructions that we can find on the internet. I tried a few sites for weeks with partial or no results.
1. You need to flash your chromebook's 'rw' SPI with nv_uboot.
2. Create boot/u-boot partition in eMMC
3. Create root partition in eMMC
4. update settings in the new nv-boot to boot the eMMC.

Better read the arch link shared above as it covers these steps in detail.

Anyways, if the steps above do not work out, you will most probably be in a state of frustration with you device not being able to recover to chromeos. So steps below will describe how to recover back to chromeos.


Way Back To Recovery

This is a solution for people who are stuck with nv-uboot(non verified u boot) and cannot seem to get their system recovered using the recovery USB. This is because nv-uboot is not signed by google and the recovery USB checks if the flash on the chromebook contains original google verfied flash. So reverting the SPI flash image to a google signed uboot image will allow recovery of the system.

This is the solution to write back the 'rw' region of SPI with the original chromeos firmware. If you already have a backup of you old SPI flash then you can go ahead and write it down already and boot with the recovery stick to get back your chromeos.

If you have lost the SPI flash backup(like i did) that you were supposed to take, then you need to do the following to obtain it.

Download the linux_recovery.sh for linux and run it.
     a. Type in 'SNOW' at the image prompt. This will list the list of devices with their market names.
     b. For samsung chromebook select 'Samsung ARM Chromebook'.
     c. The recovery tool will then go ahead and download the image(mostly to /tmp/tmp.somevarcharstring). You can stop the recovery process as soon as the download is over as all we need is the image.
     d. Now we need to load the image

           losetup -P /dev/loop0 <bin file>

            WARNING: If it says that -P options is not recognized, then chances are that you are on a ubuntu derivative and need to update utils-linux. But downloading the utils-linux source code and installing it could make break your installation, so better do it on a virtual machine.
     e. Once the losetup executes without error mount the partition 3 of the chromeos image using the command

           mount -o ro /dev/loop0p3 /mnt/somewhere

     f. Then run the command

           /mnt/somewhere/usr/sbin/chromeos-firmwareupdate --sb_extract /tmp/placetoextract

      g. In the extract location you will find the extracted blob files, search for a file ending with rw.bin. This is the SPI flash image that we want.
     h. As long as you can boot into chromebook using a bootable usb, you can flash the SPI using flashroom-google. Use the command.
          flashrom.google -p linux_spi:dev=/dev/spidev1.0 -r origial_image-snow.bin

            Replace origial_image-snow.bin with the *.rw.bin that we extracted above.


After the above work, you can reboot chromebook with the recovery USB and follow the steps to complete the recovery.