[HOW-TO] How to flash a factory image / return to stock / unlock / root #

Search This thread

Mohsin1

Member
Jul 9, 2012
13
0
Rawalpindi
androidswiki.com
thanks.......

you rock man....it took me more than 2 hours to do all the steps....but the result was sweet.....thanks again.....
:p
:fingers-crossed:
:cyclops::good::good::good::good::good::good:
 

cman6453

Senior Member
Sep 29, 2007
276
15
San Diego
So when one flashes the system.img, does it typically take a long long time for that command to finish running? Mine has been stuck at "sending 'system'..." for several minutes now. I mean I guess the system.img file is much larger than all the others, but just wondering if this was normal...?

I was having the same issue and am not exactly sure what I did differently but I got it to work on my Mac. What I did do was extract the files from the OCCAM .TGZ. Extracted the .ZIP file within the .TGZ file. Unzipped the toolkit that efrant posted and placed all the files in the unzipped folder for the toolkit. I re-flashed the system.img and it worked. Took 62.xx seconds to complete. Got thru the rest of the steps flawlessly. N4 is back to stock and will be headed back to T-Mobile. :(
 

Chochiwpg

Senior Member
Feb 3, 2012
4,721
2,634
Winnipeg
Hi efrant,

I am going to attempt to flash the factory image later tonight. I have already downloaded all the necessary files and I am ready to go. I just have a couple questions regarding the instructions in the OP.

After you flash the bootloader the instructions prompt us to reboot the bootloader. Then flash the radio and reboot the bootloader afterward as well. Then it instructs us to flash the system, userdata, boot, and recovery partitions. But it does not mention to reboot the bootloader after flashing each one. Is it recommended to flash system, reboot, flash userdata reboot etc etc? Or is it not necessary to reboot the bootloader when flashing system, userdata, boot and recovery?

Thanks, just want to be thorough and make sure I do it correctly.
 
Last edited:

efrant

Retired Senior Moderator & Developers Relations
Feb 12, 2009
11,469
10,985
Montreal
Samsung Galaxy S20
Hi efrant,

I am going to attempt to flash the factory image later tonight. I have already downloaded all the necessary files and I am ready to go. I just have a couple questions regarding the instructions in the OP.

After you flash the bootloader the instructions prompt us to reboot the bootloader. Then flash the radio and reboot the bootloader afterward as well. Then it instructs us to flash the system, userdata, boot, and recovery partitions. But it does not mention to reboot the bootloader after flashing each one. Is it recommended to flash system, reboot, flash userdata reboot etc etc? Or is it not necessary to reboot the bootloader when flashing system, userdata, boot and recovery?

Thanks, just want to be thorough and make sure I do it correctly.

Unnecessary to reboot into the bootloader after flashing those images. Only after flashing the bootloader and Radio.

Sent from my Galaxy Nexus using Tapatalk 2
 
  • Like
Reactions: Chochiwpg

noobdeagle

Senior Member
Apr 5, 2010
687
88
Adelaide, SA
Can someone explain to me why all the guides on how to flash the stock images use the most convoluted and complicated way ?, Google supply a 'flash-all.bat' that does the whole process for you. :confused:
 

Chochiwpg

Senior Member
Feb 3, 2012
4,721
2,634
Winnipeg
Unnecessary to reboot into the bootloader after flashing those images. Only after flashing the bootloader and Radio.

Sent from my Galaxy Nexus using Tapatalk 2

Thanks, I will give this a try when I get home and if I have any issues I will let you know. I really enjoy these tutorials because I would much rather learn and do it long hand than using a toolkit. I respect the devs that create the toolkits to help us out and make things easier, but I want to learn something along the way and this helps greatly. Thank you.
 

efrant

Retired Senior Moderator & Developers Relations
Feb 12, 2009
11,469
10,985
Montreal
Samsung Galaxy S20
Can someone explain to me why all the guides on how to flash the stock images use the most convoluted and complicated way ?, Google supply a 'flash-all.bat' that does the whole process for you. :confused:
Sure, I can explain (although I answered this twice already).

Yes, executing the "flash-all" script certainly works. However, I think you missed the point of this thread as stated in the first post:

[snip]

Note: There are other methods that are abbreviated and/or faster, but I wanted to spell out each step in the process for the purposes of learning. I'm a big believer in doing things manually before using a "toolkit", much the same way that, in school, we are taught to do math first, before being allowed to use a calculator. See here for some further explanation.

I do not advocate using pre-made scripts until someone understands what those scripts are doing. If you fully understand, then perfect, use the script. If you don't understand, then if you use it, you remain ignorant and unable to troubleshoot your own issues. What is important is understanding the journey.
 
  • Like
Reactions: undercover

Chochiwpg

Senior Member
Feb 3, 2012
4,721
2,634
Winnipeg
One last question efrant before I give this a try:

As per the OP

Notes:
1) Yes, you will receive the OTA update notification (when it is available) for the next update.

Just want to make sure, as long as I have the stock bootloader, radio, system, userdata, boot and recovery I am safe to root and still receive OTA updates? I assume that is the case, but just want to be 100% sure.

Thanks
 

efrant

Retired Senior Moderator & Developers Relations
Feb 12, 2009
11,469
10,985
Montreal
Samsung Galaxy S20
One last question efrant before I give this a try:

As per the OP

Notes:
1) Yes, you will receive the OTA update notification (when it is available) for the next update.

Just want to make sure, as long as I have the stock bootloader, radio, system, userdata, boot and recovery I am safe to root and still receive OTA updates? I assume that is the case, but just want to be 100% sure.

Thanks

Correct.

Sent from my Galaxy Nexus using Tapatalk 2
 
  • Like
Reactions: Chochiwpg

Zealotki11er

Senior Member
Nov 4, 2010
112
8
I did all the steps. I am getting stuck @ X screen. Over 30 mins. did the same thing with my Galaxy Nexus and had not problems. What would you recommend i do?

Edit: I am going to have to learn read before posting.
 
Last edited:

Chochiwpg

Senior Member
Feb 3, 2012
4,721
2,634
Winnipeg
It happened to me the same thing... I did everything right just as suggested in every step, but my phone won't get past the X logo... I solved it by going to the stock recovery (unhide the menu by pressing POWER+VOL. UP), wipe data/factory reset, wipe cache partition. Reboot (to me it rebooted automatically after wiping the cache partition) and everything went fine, it took very few time to get past the X logo...

Hope it works for you too.

Man you are a savoir, the exact same thing happened to me and this was the only thing that allowed me to get past the X logo. Very odd indeed.

Seems to be working now, back to good old stock. Peace.
 

cue_32

Senior Member
Jun 11, 2010
739
90
Worked perfectly... the only thing that confused me was the part where you already at the Stock Recovery mode (Android with red exclamation) and you have to press the Vol+up button to activate the options. After wiping cache and data, all is well.

Thanks
 

schemeKC

Member
Nov 27, 2012
6
5
efrant, wouldn't fastboot flash zip image-occam-jop40d.zip do essentially the same job?

The flash-all.bat in the zip/tgz will accomplish the same thing (won't re-lock the bootloader, of course), but if I'm not mistaken efrant's purpose with this thread is to try to help explain why everything works like it does so people have a greater understanding of their tech. If you already know what it all does then using the bat accomplishes the same thing.
 

undercover

Senior Member
Oct 10, 2010
14,726
4,441
London, UK
The flash-all.bat in the zip/tgz will accomplish the same thing (won't re-lock the bootloader, of course), but if I'm not mistaken efrant's purpose with this thread is to try to help explain why everything works like it does so people have a greater understanding of their tech. If you already know what it all does then using the bat accomplishes the same thing.

Thanks. Yes that makes sense. Since I'm more into troubleshooting I always think of the easiest way to explain how to FIX it :)
I even missed the bat (I was only looking for system.img. :D

" One day your life will flash before your eyes. Make sure its worth watching "
 

undercover

Senior Member
Oct 10, 2010
14,726
4,441
London, UK

drdingo21

Senior Member
Jun 23, 2006
294
11
Had a custom Rom on my nexus and used this guide to get back to stock (thanks!)

But now everything sees my 16 gig nexus 4 as the 8 gig (windows and settings ->Storage) show I only have ~5 gig free. Before the custom ROM and coming back to the stock rom I had the full ~12 gig free.

Whats the deal?
 

efrant

Retired Senior Moderator & Developers Relations
Feb 12, 2009
11,469
10,985
Montreal
Samsung Galaxy S20
Had a custom Rom on my nexus and used this guide to get back to stock (thanks!)

But now everything sees my 16 gig nexus 4 as the 8 gig (windows and settings ->Storage) show I only have ~5 gig free. Before the custom ROM and coming back to the stock rom I had the full ~12 gig free.

Whats the deal?

Did you do step D6 right after doing D5?

Sent from my Galaxy Nexus using Tapatalk 2
 

Top Liked Posts

  • There are no posts matching your filters.
  • 590
    I have created this thread to give a step-by-step on how to flash a stock ROM build available on Google's developer site. (For those that are unaware, an unlocked bootloader is needed, and unlocking is part of the instructions below.)

    I've also added a section on how to root for those that want it.

    Note: There are other methods that are abbreviated and/or faster, but I wanted to spell out each step in the process for the purposes of learning. I'm a big believer in doing things manually before using a "toolkit", much the same way that, in school, we are taught to do math first, before being allowed to use a calculator. See here for some further explanation.

    So, without further ado:

    How to flash a stock ROM

    Step-by-step

    Notes:
    1) For the n00bs: read the entire post before proceeding;
    2) MacOS-specific instructions: a) no drivers needed, and b) replace fastboot in the steps below with ./fastboot-mac

    A. Install the drivers
    1) Do not install LG drivers or the PDAnet drivers, or any other driver you come across. If you have, and you are SURE they are working properly, fine, leave them. Otherwise uninstall them if you are unsure;
    2) Download the drivers from here or from here;
    3) Install the drivers. See here on how to install them. Note that the driver has to install twice: once when your device is booted normally (not required for this tutorial) with USB Debugging enabled in Settings, and once when your device is booted in fastboot (i.e., bootloader) mode (which is required for this tutorial). (To enable USB Debugging, you first need to enable Developer options by going to Settings->About phone and tapping 7 times on the build number.) If you are using Windows 8, you will need to do this before installing the drivers.

    B. Backup your data
    1) Backup all your personal data (e.g., photos, music, etc.) OFF of your device and onto your computer by using whatever method you want that works for you, e.g., MTP, ADB, email, Dropbox, Box.net, whatever.
    2) This method will wipe your entire device, including the /sdcard folder, so once you do this, you will not be able to retreive anything that was on your device previously.
    3) See here on how to backup your apps and app data if you don't have root.

    C. Download the required files to your computer and extract them
    1) All of the files that are required, need to be in one (i.e., the same) directory. It does not matter what it is called, but all the files need to be in there, with NO subfolders. EVERYTHING needs to be extracted into this one directory;
    2) Download the attachment from the end of this post and extract the contents to the directory created in step 1. (Latest version for Windows is here). Note: if all you want to do is unlock your bootloader, skip to step 7 in this section (C).
    3) Download the version of Android you want from here. Make sure you are using an occam image which is for the Nexus 4. Most old versions are not usually available on that site; however, there is a mirror on this site: Random Phantasmagoria.
    4) Download the appropriate version (for your computer) of 7-zip from here and install it.
    5) Extract the files from within the .tgz file which you downloaded in step 3 using 7-zip, not WinZip or WinRAR or whatever.
    6) Make sure you have extracted ALL the files (including extracting any files in any archives inside the .tgz file). You should have six (6) files ending with .img in the directory you created in step 1. The other files you extracted from the .tgz are not necessary;
    7) Reboot your device into bootloader mode (by turning it off, hold volume down, and press and hold power) and plug it into your computer;
    8) Open a command prompt in the same directory (i.e., make sure you are in the same directory as your files are located). You can hold the shift key when you are in the folder in Windows explorer and right-click in a blank spot and it will open a command prompt.

    D. Type in the commands into the command prompt
    1) Make sure your computer recognizes your device by typing: fastboot devices
    2) Unlock your bootloader (if you have not already done so): fastboot oem unlock
    3) You will see a prompt on your device. This will wipe your entire device (including the /sdcard folder). Accept. Note: you use the volume keys to change the option and the power button to accept. You cannot use the touch screen.
    4) Reboot by typing: fastboot reboot-bootloader
    5) Flash the bootloader: fastboot flash bootloader bootloader-mako-makoz10o.img (or whatever the name of the bootloader image that you downloaded).
    6) Reboot: fastboot reboot-bootloader
    7) Flash the radio: fastboot flash radio radio-mako-m9615a-cefwmazm-2.0.1700.48.img (or whatever the name is of the radio image that you downloaded).
    8) Reboot: fastboot reboot-bootloader
    9) Flash the system partition: fastboot flash system system.img
    10) Optional, but read note. Flash the data partition: fastboot flash userdata userdata.img Note: this command will wipe your device (including /sdcard), EVEN if your bootloader is already unlocked. See note 2 below.
    11) Flash the kernel/ramdisk: fastboot flash boot boot.img
    12) Flash the recovery partition: fastboot flash recovery recovery.img
    13) Erase the cache partition: either a) fastboot erase cache OR b) fastboot format cache <<== the second option seems to work better for most people. Thanks joostburg.
    14) Reboot: fastboot reboot
    15) Done! The first boot will likely take quite a bit longer than you are used to, as Android builds the Dalvik cache.

    Now you have a fully stock image on your device. The only thing that is different from out-of-the-box condition is that your bootloader is unlocked. See the notes section at the end of this post for information on re-locking the bootloader.

    Note that some users indicate that they can't get past the X on boot. If this happens to you, reboot into the bootloader and select recovery. Then, when you see the Android with the red exclamation mark, hold power and press volume up to take you to the menu. Wipe cache. If that still doesn't work, boot back into recovery and do a factory reset (this will obviously delete all your data & files in /sdcard...).

    If you have a 16GB device, and it now shows up as 8GB, reboot into recovery (hold power and press volume up when you are at the screen with the android and the red exclamation mark), and wipe cache. If that still doesn't work, boot back into recovery and do a factory reset (which will obviously delete all your data & files in /sdcard...). Or do this.

    E. Optional -- Root
    If you want to get root access follow the steps below. (And no, this will not flash a custom recovery, and not, it will not make you "not stock".) Unlocked bootloader required. See steps above.

    1) Download (to your computer) the latest version of CWM (from here) or TWRP (from here) for your device;
    2) Rename the file to customrecovery.img, and make sure it is in the same directory as your fastboot.exe file;
    3) Download (to /sdcard on your device) the latest version of either ChainsDD's Superuser (not currently working), or Chainfire's SuperSU or Koush's Superuser; NOTE: So far, only SuperSU v1.43 and newer currently work properly with JWR66V (i.e., 4.3). I've attached v1.51 below.
    4) Restart your device in fastboot mode and plug into computer;
    5) Open a command prompt in the directory mentioned above and type: fastboot boot customrecovery.img Note: Only if you are running the z20i bootloader: the command would be: fastboot -c "lge.kcal=0|0|0|x" boot customrecovery.img Thanks hwti & el_charlie
    6) Wait for it to boot;
    7) Navigate the menus the recovery menu on your device and select an option like "update zip from sdcard". Find the zip that you downloaded, and apply it.
    8) Reboot. Done.

    Notes:
    1) Yes, you will receive the OTA update notification (when it is available) for the next update. WHEN you get the update notification, IF you want it to install automatically, you will need to ensure that that you are using the bootloader, radio, boot, radio and recovery images for the .tgz package you downloaded. Otherwise, the update will not install automatically.
    2) There has been a lot of uncertainty and questions around stock ROMs and losing/wiping data. You CAN flash a stock ROM WITHOUT losing the data stored in /sdcard (and possibly even all apps and app data, although this depends on which apps you have installed). This can be done by skipping step 10 in part D. However, if your device goes into a boot loop, you will need to boot CWM, and wipe data <-- this will wipe your apps and app data, but not /sdcard.
    3) Do NOT re-lock your bootloader after you are finished. The is no need. 2) Having an unlocked bootloader does not affect anything related to the ROM/GoogleWallet/OTAs. Nothing at all. If your bootloader is locked, you CANNOT use fastboot commands. This is pretty much the only thing it affects. If your bootloader is locked, and you need to unlock it, it will wipe everything, including /sdcard. This is the major drawback of re-locking your bootloader. If you do want to lock your bootloader, the command is: fastboot oem lock
    85
    How to return to stock if your USB port is broken

    I am adding this how-to in case people need it, for return their device to Google, etc.

    This is NOT meant to replace going through the steps in post #1. They are there for your learning, and should be used as a primary method of returning your device to stock. However, if your USB port is indeed messed up, then you will not be able to use the instructions in post #1.

    Warning: if your USB port is indeed broken, and you complete all the steps below, you will have NO possible way at all to unlock your bootloader, or get root, or install a custom recovery. Period.

    1) Ensure that you have root, and a custom recovery (CWM or TWRP) installed;
    2) Download segv11's BootUnlocker app from the Play Store, install it and lock your bootloader with it;
    3) Download the odexed version of this file (stock JDQ39 ROM) and place it on your device;
    4) Download the JDQ39 stock boot image from here and the stock JDQ39 recovery from here.
    5) If you want, you can also download the 0.48 radio and the z10o bootloader from here.
    6) Reboot into CWM and flash the three files you downloaded in steps 3 and 4, and the file(s) you downloaded in step 5;
    5) Turn off your device and reboot into the bootloader;
    6) Go to recovery and access the stock recovery menu (i.e., when you see the android with the red triangle, hold power and press vol up) and do a factory reset and then wipe cache.
    7) Reboot your device. Do NOT install any OTA updates if they present themselves. Read and follow this post.
    8) Done. Now you are fully stock JDQ39 with a locked bootloader.
    20
    10
    No errors, I checked the MD5 of the factory image and it's fine. I even re-downloaded it. I did every step as listed in your procedure (even the optional ones). The phone is dead now, it's charging. It spent over 20 minutes on the X. Everything seems to work per your instructions. I don't get it. Could something be corrupted on my phone itself? System/Boot/Recovery images are all dated Jan 1/09, but I assume that's correct (it's from Google after all). Should I try directly flashing CWM recovery instead of stock during the initial process? I dunno...

    I will try your method from the beginning again tomorrow.

    I assume I'm not bricked if I can still do this stuff. It doesn't bode well if you don't know what's wrong either. I appreciate any further help/suggestions...

    It happened to me the same thing... I did everything right just as suggested in every step, but my phone won't get past the X logo... I solved it by going to the stock recovery (unhide the menu by pressing POWER+VOL. UP), wipe data/factory reset, wipe cache partition. Reboot (to me it rebooted automatically after wiping the cache partition) and everything went fine, it took very few time to get past the X logo...

    Hope it works for you too.
    8
    It's the bootloader.

    It happens since the 4.3 leak and the z20i bootloader.

    You can try flashing the old z10o bootloader (it boots 4.3 just fine) and then fastboot boot command will work.

    It's very annoying because I use to keep the stock recovery and only use CWM or TWRP to root. Now I have to flash a custom recovery, do my thing and reflash the stock one again.

    Cheers!

    You can still boot a recovery without flashing it, but you have to specify the kernel command line

    Solution 1 (works on my N4, not sure it will work for all hardware revisions) :
    1. fastboot boot customrecovery.img
    2. you see a blank screen
    3. get the default fastboot kernel command line : adb shell cat /proc/cmdline
    4. adb reboot-bootloader
    5. Append lge.kcal=0|0|0|x to the default fastboot kernel command line :
      fastboot -c "your_default_command_line lge.kcal=0|0|0|x" boot customrecovery.img

    Solution 2:
    1. fastboot flash recovery customrecovery.img
    2. launch the recovery from the bootloader
    3. wait until it's loaded
    4. get the bootloader kernel command line : adb shell cat /proc/cmdline
    5. adb reboot-bootloader
    6. fastboot flash recovery stockrecovery.img
    7. Use the bootloader command line to launch the recovery from fastboot :
      fastboot -c "your_bootloader_command_line" boot customrecovery.img