Skip to content

Instantly share code, notes, and snippets.

@PIPIPIG233666
Last active August 3, 2024 04:48
Show Gist options
  • Save PIPIPIG233666/797d57b55fe87977d77ecba5e854b83f to your computer and use it in GitHub Desktop.
Save PIPIPIG233666/797d57b55fe87977d77ecba5e854b83f to your computer and use it in GitHub Desktop.
$filesToRemove = ".\platform-tools-latest-windows.zip", ".\platform-tools"
foreach ($fileToRemove in $filesToRemove) {
If (Test-Path $fileToRemove) {
Remove-Item -Force -Recurse $fileToRemove
}
}
wget https://dl.google.com/android/repository/platform-tools-latest-windows.zip
Get-ChildItem platform-tools-latest-windows.zip | Expand-Archive -DestinationPath .\ -Force
# Add local directory to $env
$env:Path += ";${Get-Location}\platform-tools"
#Get-Command fastboot
# Array definitions
$bootall_partitions = "boot", "modem"
$boot_partitions = "recovery", "dtbo", "vbmeta", "vbmeta_system", "vbmeta_vendor", "vendor_boot"
$fw_partitions = "abl", "splash", "aop_config", "aop", "bluetooth", "core_nhlos", "tz", "uefi", "uefisecapp", "cpucp", "devcfg", "dsp", "engineering_cdt", "oplus_sec", "featenabler", "oplusstanvbk", "xbl_config", "hyp", "qupfw", "xbl", "imagefv", "xbl_ramdump", "keymaster", "shrm", "rpm"
$logical_partitions = "my_bigball", "my_carrier", "my_engineering", "my_heytap", "my_manifest", "my_product", "my_region", "my_stock", "odm", "odm_dlkm", "product", "system", "system_ext", "vendor", "vendor_dlkm"
$blank_partitions = "my_company", "my_preload"
# only need to read in once
$global:localPartition = Get-ChildItem *.img | ForEach-Object { $_.Name.Substring(0, $_.name.Length - 4) }
function Test-Existense {
param (
[string]$partition
)
if ($partition -notin $localPartition) {
return -1
}
}
function Use-Flash-Image {
param(
[string]$partition,
[string]$slotOption = ""
)
if (Test-Existense -partition $partition -eq -1) {
return
}
if ($slotOption -eq "all") {
fastboot flash --slot $slotOption $partition "$($partition).img"
}
else {
fastboot flash $partition "$($partition).img"
}
}
function Use-Prepare-Partition {
param(
[string]$partition
)
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 Use-Wipe-Data {
$choice = Read-Host "This action will wipe all data on the device. Are you sure you want to continue? (y/n)"
if ($choice -eq "y" -or $choice -eq "Y") {
fastboot -w
Write-Host "Data wipe completed."
fastboot reboot
}
else {
Write-Host "Data wipe canceled."
fastboot reboot
}
}
# Flash boot partitions
foreach ($partition in $bootall_partitions) {
Use-Flash-Image $partition all
}
foreach ($partition in $boot_partitions) {
Use-Flash-Image $partition
}
fastboot reboot fastboot
# Flash again because now fastbootd has access
foreach ($partition in $boot_partitions) {
Use-Flash-Image $partition all
}
# Flash firmware partitions
foreach ($partition in $fw_partitions) {
Use-Flash-Image $partition all
}
# Prepare and flash logical partitions
foreach ($partition in $logical_partitions) {
Use-Prepare-Partition $partition
Use-Flash-Image $partition
}
# Prepare blank partitions
foreach ($partition in $blank_partitions) {
Use-Prepare-Partition $partition
}
Use-Wipe-Data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment