@echo off
color 0a
ECHO. 

rem 清理旧备份
rd /s /q backup > nul 2>&1

adb ls dev/block/platform/soc/by-name

adb shell "rm -rf /mnt/sdcard/backup"
adb shell "mkdir /mnt/sdcard/backup"

call :backup_partition bootargs "bootargs 分区"
call :backup_partition boot "boot 分区"
call :backup_partition atf "atf 分区"
call :backup_partition baseparam "baseparam 分区"
call :backup_partition fastboot "fastboot 分区"
call :backup_partition fastplay "fastplay 分区"
call :backup_partition fastplaybak "fastplaybak 分区"
call :backup_partition kernel "kernel 分区"
call :backup_partition logo "logo 分区"
call :backup_partition logobak "logobak 分区"
call :backup_partition misc "misc 分区"
call :backup_partition pqparam "pqparam 分区"
call :backup_partition private "private 分区"
call :backup_partition recovery "recovery 分区"
call :backup_partition securestore "securestore 分区"
call :backup_partition swdevinfo "swdevinfo 分区"
call :backup_partition trustedcore "trustedcore 分区"
call :backup_partition system "system 分区"
call :backup_partition cache "cache 分区"
call :backup_partition backup "内置backup 分区"
rem call :backup_partition userdata "userdata 分区"

rem 提示用户上传备份的固件可能需要一些时间
ECHO 正在上传备份的固件，可能需要较长时间......
adb pull -p /mnt/sdcard/backup backup

adb shell "rm -rf /mnt/sdcard/backup"

ECHO 备份完成，固件存放位置为工具根目录 backup 文件夹！！！

pause > NUL
goto :eof

:backup_partition
set PARTITION_NAME=%1
set PARTITION_LABEL=%2
ECHO 正在备份晶 %PARTITION_LABEL% 到 backup 文件夹...... 
adb shell "dd if=/dev/block/platform/soc/by-name/%PARTITION_NAME% of=/mnt/sdcard/backup/%PARTITION_NAME%.img"
goto :eof
