@echo off
color 0a
ECHO. 

rem 检查U盘是否连接
adb shell "ls /storage/sda" > nul 2>&1
if %errorlevel% neq 0 (
    ECHO 错误：请连接U盘后重新运行脚本。
    pause > NUL
    exit /b
)

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

adb ls dev/block/by-name

call :backup_partition boot "boot 分区"
call :backup_partition bootargsbak "bootargsbak 分区"
call :backup_partition recovery "recovery 分区"
call :backup_partition ctc "ctc 分区"
call :backup_partition logobak "logobak 分区"
call :backup_partition securestore "securestore 分区"
call :backup_partition fastplaybak "fastplaybak 分区"
call :backup_partition pqparam "pqparam 分区"
call :backup_partition private "private 分区"
call :backup_partition fastboot "fastboot 分区"
call :backup_partition loaderdb "loaderdb 分区"
call :backup_partition logo "logo 分区"
call :backup_partition misc "misc 分区"
call :backup_partition trustedcore "trustedcore 分区"
call :backup_partition deviceinfo "deviceinfo 分区"
call :backup_partition product "product 分区"
call :backup_partition securestore "securestore 分区"
call :backup_partition fastplay "fastplay 分区"
call :backup_partition keydata "keydata 分区"
call :backup_partition atf "atf 分区"
call :backup_partition recoverybak "recoverybak 分区"
call :backup_partition bootargs "bootargs 分区"
call :backup_partition baseparam "baseparam 分区"
call :backup_partition dtbo "dtbo 分区"
call :backup_partition stbid "stbid 分区"
call :backup_partition vendor "vendor 分区"
call :backup_partition keydata "keydata 分区"
call :backup_partition cache "cache 分区"
call :backup_partition system "system 分区"
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 备份完成，固件存放位置为U盘根目录文件！！！
ECHO 请拔出U盘，复制文件到你电脑里面。。。

pause > NUL
exit /b

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