Wednesday, July 30, 2014

Flash an Android Phone

A friend got an old Android phone to use for Android development testing. It was a Nexus S 4G, Android build version was GWK74 (2.7.3 Gingerbread). So I spent some time to investigate how to do this. It worked and here is the note.

In this case, when boot into fastboot mode, it complains "Fastboot Mode No Boot or Recovery IMG". So need to download the images.

Also during the process, windows needs 2 device drivers to detect the phone:  1) when android is on, need google device driver for Nexus S 4G, which comes with ADT (in my case, it's in D:\Android\android-sdk\extras\google\usb_drive).  2) when android is in fastboot mode, need another driver called "Android Bootloader Interface driver". After a lot of search, this is available with pdaNet [1].

Next, need to download the images. This can be downloaded from Factory Images for Nexus Devices [2].  For Nexus S 4G, the corresponding section is at the end of the page: "Factory Images sojus for Nexus S 4G (d720)". 3 versions are available: 2.3.7 (GWK74), 4.0.4 (IMM76D) and 4.1.1 (JRO03R). The phone previously had 2.3.7 (GWK74), now we want a more modern version, so choose 4.1.1 (JRO03R).

Now, for actual steps to flash the phone, see [3]. Note in the last step 10, the commands are the same as in flash-all.sh and flash-all.bat of the package in [2]. The steps in [3] are copied below. In an established environment (no need to setup any drivers), the steps involved are 5, 6, 7, 9, 10, 11.

1. Install the Android SDK and Eclipse.
    Eclipse probably isn’t necessary but it is nice to have.
2. Launch the Android SDK Manager.
3. In the Android SDK manager verify that the Google USB Driver is installed and up to date.
4. Connect the target phone to the PC using USB. Make sure USB Debugging is enabled on the phone.
5. From the command line, display all adb devices
    Use the command: adb devices

    This command is in the Android SDK platform-tools folder. I have this added to my Path. ADB should list out all attached Android devices.
    If no devices are listed, make sure you have the Google Android USB driver installed.
    Windows Device Manager should show a device of “Android Composite ADB Interface”.

6. Use ADB to reboot the phone into Fastboot mode
    Use the command: adb reboot bootloader
    This command is in the Android SDK platform-tools folder.

7. Verify that fastboot can access the phone
    Use the command: fastboot devices
    This should list out all attached Android devices in Fastboot mode. Notice that the device is no longer visible to ADB. “adb devices” no longer lists the device. However, “fastboot devices” should.

8. Install the Android Bootloader Interface driver if needed
    If Fastboot Devices lists the phone, this step is not necessary. If Fastboot does not list the phone or shows
    You may need to install the Android Bootloader Interface driver. This can be from the pdaNet.

9. Download and expand the device images to use.
    For this phone, Google publishes the standard images at https://developers.google.com/android/nexus/images#sojusgwk74

10. Execute the commands from flash-all.sh to flash the device.
    Change to the folder with the expanded images and execute the fastboot commands from the flash-all.sh file.


    fastboot flash bootloader bootloader-crespo4g-d720sprlc1.img
    fastboot reboot-bootloader
    fastboot flash radio radio-crespo4g-d720sprlf2.img
    fastboot reboot-bootloader
    fastboot -w update image-sojus-jro03r.zip



Note the last step "fastboot -w update image-sojus-jro03r.zip" may fail, possible because it cannot decode the zip file for the images, so do it manually: first uncompress the zip file, which contains the images, then in DOS, use these commands (refer to the end of [4]), which I call step 11:

11. Flash the images.
    fastboot flash recovery recovery.img
    fastboot flash boot boot.img
    fastboot flash userdata userdata.img 
    fastboot flash system system.img

12. Recovery 
    In the Android screen, use sound dial to choose "Recovery", then press power button to confirm. 
    It takes a few minutes to recover from the flashed images, then automatically boot into the new Android 4.1.1 system.



The entire process can be summarized into 3 steps:

1) setup device drivers so computer can detect the phone in both normal and fastboot modes.
2) download image package for your device.
3) use Android SDK tools adb and fastboot to do the flash.


References:

[1] pdaNet
[2] Factory Images for Nexus Devices
[3] Flash Nexus S 4G
[4] http://wiki.cyanogenmod.org/w/Doc:_fastboot_intro


No comments:

Blog Archive

Followers