Sample Header Ad - 728x90

How to successfully erase cache during the flashing process of a stock Android ROM?

1 vote
0 answers
115 views
Following Google's guide for flashing/restoring the stock Android ROM, and initially using the default *flash-all.sh* shell script to flash the stock Android ROM to my device, I noticed that I am not able to do this successfully on the second consecutive attempt. When flashing the stock Android ROM the first time (usually when flashing the stock over a custom ROM or flashing the stock recovery over the existing TWRP recovery), the first attempt successfully flashes the stock Android ROM to the device and I am presented with the Android setup wizard. However, if I repeat the same flashing process once more, the device is stuck on the Android logo boot animation. I read that this is caused by the cache partition not being erased before flashing. Several tutorials have claimed that the cache needs to be wiped from within the recovery, and although I have tested this to be successful, I would prefer a method that can erase the cache during the flashing process (or an adb or fastboot alternative) without having to re-enter recovery. I have tried adding the fastboot commands to the *flash-all.sh* shell script to erase cache and erase userdata, either before or after flashing all of the partitions with those of the stock image, but it does not solve the issue. My device is the Huawei Nexus 6p and I am using the latest stock Android ROM for Angler (8.1.0 (OPM7.181205.001, Dec 2018)), which does not contain a *cache.img* file (removed since Android 8.0). I am aware that I could extract the *cache.img* file from an earlier stock image (e.g. Android 7.0) and flash that with fastboot, but I'd prefer not to have to rely on two different stock images, and one just for the archived *cache.img*. My customised *flash-all.sh* shell script, inspired by examples here and here , is as follows:
fastboot flash bootloader bootloader-angler-angler-03.84.img
fastboot reboot-bootloader
sleep 2
fastboot flash radio radio-angler-angler-03.88.img
fastboot reboot-bootloader
sleep 2
fastboot flash recovery recovery.img
fastboot reboot-bootloader
sleep 2

# no cache image (cache.img) in Android 8.0+, instead:
fastboot erase userdata
fastboot erase cache

# does not seem to flash images, even if extraced into the PWD
fastboot -w update image-angler-opm7.181205.001.zip

# ... which is the equivalent to (in the correct order) 
fastboot flash boot boot.img
sleep 2
fastboot flash system system.img
sleep 2
fastboot flash vendor vendor.img
sleep 2

fastboot erase userdata
fastboot erase cache
sleep 2
fastboot reboot
Q: What command(s) can I use during the flashing process (i.e within the bootloader) to successfully erase the cache partition so that I am not stuck on the boot animation logo upon startup?
Asked by jimjamz (11 rep)
Jun 18, 2024, 02:00 PM