Last active
February 22, 2025 17:53
-
-
Save AdarshGrewal/a51236d5be7f5e3d6981f67321051433 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
boot_partitions=("boot" "dtbo" "init_boot" "modem" "recovery" "vbmeta" "vbmeta_system" "vbmeta_vendor" "vendor_boot") | |
fw_partitions=("abl" "aop" "aop_config" "bluetooth" "cpucp" "cpucp_dtb" "devcfg" "dsp" "engineering_cdt" "featenabler" "hyp" "imagefv" "keymaster" "oplus_sec" "oplusstanvbk" "pdp" "pdp_cdb" "pvmfw" "qupfw" "shrm" "soccp_dcd" "soccp_debug" "splash" "spuservice" "tz" "uefi" "uefisecapp" "xbl" "xbl_config" "xbl_ramdump") | |
logical_partitions=("my_bigball" "my_carrier" "my_engineering" "my_heytap" "my_manifest" "my_product" "my_region" "my_stock" "odm" "product" "system" "system_dlkm" "system_ext" "vendor" "vendor_dlkm") | |
extra_partitions=("my_company" "my_preload") # These partitions don't exist in payload but must exist for Oplus updater | |
function check_all_images_exist() { | |
for partition in "${boot_partitions[@]}" "${fw_partitions[@]}" "${logical_partitions[@]}"; do | |
if ! ls "${partition}.img" >/dev/null 2>&1; then | |
echo "Error: Image not found for $partition" | |
exit 1 | |
fi | |
done | |
for partition in "${extra_partitions[@]}"; do | |
if ! ls "${partition}.img" >/dev/null 2>&1; then | |
echo "Error: Missing extra partition image for $partition" | |
echo "Note: These images are needed to boot but are not found in payload so source them yourself" | |
exit 1 | |
fi | |
done | |
} | |
function flash_image() { | |
local partition="$1" | |
local slot_option="$2" | |
if [[ "$slot_option" == "all" ]]; then | |
fastboot flash --slot=all "$partition" "$partition.img" | |
else | |
fastboot flash "$partition" "$partition.img" | |
fi | |
} | |
function prepare_partition() { | |
local partition="$1" | |
fastboot delete-logical-partition "${partition}_a" | |
fastboot delete-logical-partition "${partition}_b" | |
fastboot delete-logical-partition "${partition}_a-cow" | |
fastboot delete-logical-partition "${partition}_b-cow" | |
fastboot create-logical-partition "${partition}_a" 1 | |
fastboot create-logical-partition "${partition}_b" 1 | |
} | |
function wipe_data() { | |
read -p "This action will wipe all data on the device. Are you sure? (y/n): " choice | |
if [[ $choice == "y" || $choice == "Y" ]]; then | |
fastboot -w | |
echo "Data wipe completed." | |
else | |
echo "Data wipe canceled." | |
fi | |
fastboot reboot | |
} | |
# Check all images before doing anything | |
check_all_images_exist | |
fastboot --set-active=a | |
# Proceed with flashing | |
for partition in "${boot_partitions[@]}"; do | |
flash_image "$partition" | |
done | |
fastboot reboot fastboot | |
for partition in "${fw_partitions[@]}"; do | |
flash_image "$partition" "all" | |
done | |
for partition in "${logical_partitions[@]}" "${extra_partitions[@]}"; do | |
prepare_partition "$partition" | |
flash_image "$partition" | |
done | |
wipe_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment