├── Linux └── flash_all.sh ├── README.md └── Windows └── flash_all.bat /Linux/flash_all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "#############################################################################" 4 | echo "# Pacman Fastboot ROM Flasher #" 5 | echo "# Developed/Tested By #" 6 | echo "# HELLBOY017, viralbanda, spike0en, PHATwalrus, arter97, AntoninoScordino #" 7 | echo "# [Nothing Phone (2a) Telegram Dev Team] #" 8 | echo "#############################################################################" 9 | 10 | ##----------------------------------------------------------## 11 | if ! command -v wget && ! command -v unzip; then 12 | echo "Required utilities not found." 13 | if command -v apt; then 14 | sudo apt install -y wget unzip 15 | elif command -v pacman; then 16 | sudo pacman -S --noconfirm wget unzip 17 | elif command -v dnf; then 18 | sudo dnf install -y wget unzip 19 | else 20 | echo "Please, install 'wget' and 'unzip' before executing this script." 21 | exit 0 22 | fi 23 | fi 24 | 25 | if [ ! -d platform-tools ]; then 26 | wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip -O "${PWD}"/platform-tools-latest.zip 27 | unzip "${PWD}"/platform-tools-latest.zip 28 | rm "${PWD}"/platform-tools-latest.zip 29 | fi 30 | 31 | fastboot=${PWD}/platform-tools/fastboot 32 | 33 | if [ ! -f "$fastboot" ] || [ ! -x "$fastboot" ]; then 34 | echo "Fastboot cannot be executed, exiting" 35 | exit 1 36 | fi 37 | 38 | # Partition Variables 39 | boot_partitions="boot dtbo init_boot vendor_boot" 40 | firmware_partitions="apusys audio_dsp ccu connsys_bt connsys_gnss connsys_wifi dpm gpueb gz lk logo mcf_ota mcupm md1img mvpu_algo pi_img scp spmfw sspm tee vcp" 41 | logical_partitions="odm odm_dlkm product vendor vendor_dlkm system_ext system system_dlkm" 42 | vbmeta_partitions="vbmeta vbmeta_system vbmeta_vendor" 43 | 44 | function SetActiveSlot { 45 | if ! $fastboot --set-active=a; then 46 | echo "Error occured while switching to slot A. Aborting" 47 | exit 1 48 | fi 49 | } 50 | 51 | function handle_fastboot_error { 52 | if [ ! "$FASTBOOT_ERROR" = "n" ] || [ ! "$FASTBOOT_ERROR" = "N" ] || [ ! "$FASTBOOT_ERROR" = "" ]; then 53 | exit 1 54 | fi 55 | } 56 | 57 | function ErasePartition { 58 | if ! $fastboot erase "$1"; then 59 | read -rp "Erasing $1 partition failed, Continue? If unsure say N, Pressing Enter key without any input will continue the script. (Y/N)" FASTBOOT_ERROR 60 | handle_fastboot_error 61 | fi 62 | } 63 | 64 | function FlashImage { 65 | if ! $fastboot flash "$1" "$2"; then 66 | read -rp "Flashing$2 failed, Continue? If unsure say N, Pressing Enter key without any input will continue the script. (Y/N)" FASTBOOT_ERROR 67 | handle_fastboot_error 68 | fi 69 | } 70 | 71 | function DeleteLogicalPartition { 72 | if ! $fastboot delete-logical-partition "$1"; then 73 | read -rp "Deleting $1 partition failed, Continue? If unsure say N, Pressing Enter key without any input will continue the script. (Y/N)" FASTBOOT_ERROR 74 | handle_fastboot_error 75 | fi 76 | } 77 | 78 | function CreateLogicalPartition { 79 | if ! $fastboot create-logical-partition "$1" "$2"; then 80 | read -rp "Creating $1 partition failed, Continue? If unsure say N, Pressing Enter key without any input will continue the script. (Y/N)" FASTBOOT_ERROR 81 | handle_fastboot_error 82 | fi 83 | } 84 | 85 | function ResizeLogicalPartition { 86 | for i in $logical_partitions; do 87 | for s in a b; do 88 | DeleteLogicalPartition "${i}_${s}-cow" 89 | DeleteLogicalPartition "${i}_${s}" 90 | done 91 | CreateLogicalPartition "${i}_${curSlot}" \ "1" 92 | done 93 | } 94 | 95 | function WipeSuperPartition { 96 | if ! $fastboot wipe-super super_empty.img; then 97 | echo "Wiping super partition failed. Fallback to deleting and creating logical partitions" 98 | ResizeLogicalPartition 99 | fi 100 | } 101 | ##----------------------------------------------------------## 102 | 103 | echo "#############################" 104 | echo "# CHECKING FASTBOOT DEVICES #" 105 | echo "#############################" 106 | $fastboot devices 107 | 108 | ACTIVE_SLOT=$($fastboot getvar current-slot 2>&1 | awk 'NR==1{print $2}') 109 | if [ ! "$ACTIVE_SLOT" = "waiting" ] && [ ! "$ACTIVE_SLOT" = "a" ]; then 110 | echo "#############################" 111 | echo "# CHANGING ACTIVE SLOT TO A #" 112 | echo "#############################" 113 | SetActiveSlot 114 | fi 115 | curSlot="a" 116 | 117 | echo "###################" 118 | echo "# FORMATTING DATA #" 119 | echo "###################" 120 | read -rp "Wipe Data? (Y/N) " DATA_RESP 121 | case $DATA_RESP in 122 | [yY] ) 123 | echo 'Please ignore "Did you mean to format this partition?" warnings.' 124 | ErasePartition userdata 125 | ErasePartition metadata 126 | ;; 127 | esac 128 | 129 | echo "############################" 130 | echo "# FLASHING BOOT PARTITIONS #" 131 | echo "############################" 132 | read -rp "Flash images on both slots? If unsure, say N. (Y/N) " SLOT_RESP 133 | case $SLOT_RESP in 134 | [yY] ) 135 | SLOT="all" 136 | ;; 137 | *) 138 | SLOT="a" 139 | ;; 140 | esac 141 | 142 | if [ $SLOT = "all" ]; then 143 | for i in $boot_partitions; do 144 | for s in a b; do 145 | FlashImage "${i}_${s}" \ "$i.img" 146 | done 147 | done 148 | else 149 | for i in $boot_partitions; do 150 | FlashImage "${i}_${SLOT}" \ "$i.img" 151 | done 152 | fi 153 | 154 | echo "#####################" 155 | echo "# FLASHING FIRMWARE #" 156 | echo "#####################" 157 | if [ $SLOT = "all" ]; then 158 | for i in $firmware_partitions; do 159 | for s in a b; do 160 | FlashImage "${i}_${s}" \ "$i.img" 161 | done 162 | done 163 | else 164 | for i in $firmware_partitions; do 165 | FlashImage "${i}_${SLOT}" \ "$i.img" 166 | done 167 | fi 168 | 169 | # 'preloader_raw.img' must be flashed at a different partition name 170 | if [ $SLOT = "--slot=all" ]; then 171 | for s in a b; do 172 | FlashImage "preloader_${s}" \ "preloader_raw.img" 173 | done 174 | else 175 | FlashImage "preloader_${SLOT}" \ "preloader_raw.img" 176 | fi 177 | 178 | echo "###################" 179 | echo "# FLASHING VBMETA #" 180 | echo "###################" 181 | read -rp "Disable android verified boot?, If unsure, say N. Bootloader won't be lockable if you select Y. (Y/N) " VBMETA_RESP 182 | case $VBMETA_RESP in 183 | [yY] ) 184 | if [ $SLOT = "all" ]; then 185 | for i in $vbmeta_partitions; do 186 | for s in a b; do 187 | FlashImage "${i}_${s} --disable-verity --disable-verification" \ "$i.img" 188 | done 189 | done 190 | else 191 | for i in $vbmeta_partitions; do 192 | FlashImage "${i}_${SLOT} --disable-verity --disable-verification" \ "$i.img" 193 | done 194 | fi 195 | ;; 196 | *) 197 | avb_enabled=1 198 | if [ $SLOT = "all" ]; then 199 | for i in $vbmeta_partitions; do 200 | for s in a b; do 201 | FlashImage "${i}_${s}" \ "$i.img" 202 | done 203 | done 204 | else 205 | for i in $vbmeta_partitions; do 206 | FlashImage "${i}_${SLOT}" \ "$i.img" 207 | done 208 | fi 209 | ;; 210 | esac 211 | 212 | echo "##########################" 213 | echo "# REBOOTING TO FASTBOOTD #" 214 | echo "##########################" 215 | if ! $fastboot reboot fastboot; then 216 | echo "Error occured while rebooting to fastbootd. Aborting" 217 | exit 1 218 | fi 219 | 220 | echo "###############################" 221 | echo "# FLASHING LOGICAL PARTITIONS #" 222 | echo "###############################" 223 | echo "Flash logical partition images?" 224 | echo "If you're about to install a custom ROM that distributes its own logical partitions, say N." 225 | read -rp "If unsure, say Y. (Y/N) " LOGICAL_RESP 226 | case $LOGICAL_RESP in 227 | [yY] ) 228 | if [ ! -f super.img ]; then 229 | if [ -f super_empty.img ]; then 230 | WipeSuperPartition 231 | else 232 | ResizeLogicalPartition 233 | fi 234 | for s in a b; do 235 | FlashImage "${i}_${curSlot}" \ "$i.img" 236 | done 237 | else 238 | FlashImage "super" \ "super.img" 239 | fi 240 | ;; 241 | esac 242 | 243 | echo "##########################" 244 | echo "# LOCKING THE BOOTLOADER #" 245 | echo "##########################" 246 | if [ "${avb_enabled}" -eq 1 ]; then 247 | read -rp "Lock the bootloader? If unsure, say N (Y/N) " LOCK_RESP 248 | case $LOCK_RESP in 249 | [yY] ) 250 | if ! $fastboot reboot bootloader; then 251 | echo "Error occured while rebooting to bootloader. Aborting" 252 | exit 1 253 | else 254 | $fastboot flashing lock 255 | fi 256 | ;; 257 | esac 258 | fi 259 | 260 | echo "#############" 261 | echo "# REBOOTING #" 262 | echo "#############" 263 | read -rp "Reboot to system? If unsure, say Y. (Y/N) " REBOOT_RESP 264 | case $REBOOT_RESP in 265 | [yY] ) 266 | $fastboot reboot 267 | ;; 268 | esac 269 | 270 | echo "########" 271 | echo "# DONE #" 272 | echo "########" 273 | echo "Stock firmware restored." 274 | echo "You may now optionally re-lock the bootloader if you haven't disabled android verified boot." 275 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nothing Phone (2a) Fastboot ROM Flasher 2 | 3 | ### Getting Started 4 | - This is a script to make it convenient for the user to return back to the stock rom or unbrick their device under any circumstances where the super partition size has not been changed (If the rom flashed is using the same super partition size as the stock rom then this script will always work, which is supposedly followed by all the custom roms). This script is quite helpful when the custom recoveries fail to flash the stock rom where they usually face errors due to messed up partitioning under the super partition. This script can be modified to flash custom roms as well and can be used on roms shipping the stock firmware. 5 | 6 | ### Usage 7 | - Make sure you unpack the full stock ota zip and then unpack the `payload.bin` using [payload_dumper_go](https://github.com/ssut/payload-dumper-go) and then place the script suited to your operating system to the directory where the `*.img` files from `payload.bin` have been extracted. Finally reboot your device to the bootloader and then 8 | 9 | execute the script by double clicking the `flash_all.bat` file on windows 10 | 11 | or by doing this on a linux operating system in terminal after opening the terminal in the directory where the `*.img` files from `payload.bin` have been extracted : 12 | 13 | ```bash 14 | chmod +x flash_all.sh && bash flash_all.sh 15 | ``` 16 | 17 | ### Notes 18 | - The script flashes the rom on slot A and it destroys the partitions on slot B to create space for the partitions which are being flashed on slot A. This is the reason why we are not including the ability to switch slots as the partitions would get destroyed on the inactive slot which is why the script flashes the partitions on the primary slot which is slot A. 19 | 20 | -------------------------------------------------------------------------------- /Windows/flash_all.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | title Nothing Phone 2a Fastboot ROM Flasher (t.me/NothingPhone2a) 3 | 4 | echo ############################################################################# 5 | echo # Pacman Fastboot ROM Flasher # 6 | echo # Developed/Tested By # 7 | echo # HELLBOY017, viralbanda, spike0en, PHATwalrus, arter97, AntoninoScordino # 8 | echo # [Nothing Phone (2a) Telegram Dev Team] # 9 | echo ############################################################################# 10 | 11 | cd %~dp0 12 | 13 | if not exist platform-tools-latest ( 14 | curl -L https://dl.google.com/android/repository/platform-tools-latest-windows.zip -o platform-tools-latest.zip 15 | Call :UnZipFile "%~dp0platform-tools-latest", "%~dp0platform-tools-latest.zip" 16 | del /f /q platform-tools-latest.zip 17 | ) 18 | 19 | set fastboot=.\platform-tools-latest\platform-tools\fastboot.exe 20 | if not exist %fastboot% ( 21 | echo Fastboot cannot be executed. Aborting 22 | pause 23 | exit 24 | ) 25 | 26 | set boot_partitions=boot dtbo init_boot vendor_boot 27 | set main_partitions=odm_dlkm product system_dlkm vendor_dlkm 28 | set firmware_partitions=apusys audio_dsp ccu connsys_bt connsys_gnss connsys_wifi dpm gpueb gz lk logo mcf_ota mcupm md1img mvpu_algo pi_img scp spmfw sspm tee vcp 29 | set logical_partitions=odm_dlkm odm vendor_dlkm product vendor system_dlkm system_ext system 30 | set vbmeta_partitions=vbmeta vbmeta_system vbmeta_vendor 31 | 32 | echo ############################# 33 | echo # CHECKING FASTBOOT DEVICES # 34 | echo ############################# 35 | %fastboot% devices 36 | 37 | %fastboot% getvar current-slot 2>&1 | find /c "current-slot: a" > tmpFile.txt 38 | set /p active_slot= < tmpFile.txt 39 | del /f /q tmpFile.txt 40 | if %active_slot% equ 0 ( 41 | echo ############################# 42 | echo # CHANGING ACTIVE SLOT TO A # 43 | echo ############################# 44 | call :SetActiveSlot 45 | ) 46 | set curSlot=a 47 | 48 | echo ################### 49 | echo # FORMATTING DATA # 50 | echo ################### 51 | choice /m "Wipe Data?" 52 | if %errorlevel% equ 1 ( 53 | echo Please ignore "Did you mean to format this partition?" warnings. 54 | call :ErasePartition userdata 55 | call :ErasePartition metadata 56 | ) 57 | 58 | echo ############################ 59 | echo # FLASHING BOOT PARTITIONS # 60 | echo ############################ 61 | choice /m "Flash images on both slots? If unsure, say N." 62 | if %errorlevel% equ 1 ( 63 | set slot=all 64 | ) else ( 65 | set slot=a 66 | ) 67 | 68 | if %slot% equ all ( 69 | for %%i in (%boot_partitions%) do ( 70 | for %%s in (a b) do ( 71 | call :FlashImage %%i_%%s, %%i.img 72 | ) 73 | ) 74 | ) else ( 75 | for %%i in (%boot_partitions%) do ( 76 | call :FlashImage %%i_%slot%, %%i.img 77 | ) 78 | ) 79 | 80 | echo ##################### 81 | echo # FLASHING FIRMWARE # 82 | echo ##################### 83 | if %slot% equ all ( 84 | for %%i in (%firmware_partitions%) do ( 85 | for %%s in (a b) do ( 86 | call :FlashImage %%i_%%s, %%i.img 87 | ) 88 | ) 89 | ) else ( 90 | for %%i in (%firmware_partitions%) do ( 91 | call :FlashImage %%i_%slot%, %%i.img 92 | ) 93 | ) 94 | 95 | :: 'preloader_raw.img' must be flashed at a different partition name 96 | if %slot% equ all ( 97 | for %%s in (a b) do ( 98 | call :FlashImage preloader_%%s, preloader_raw.img 99 | ) 100 | ) else ( 101 | call :FlashImage preloader_%slot%, preloader_raw.img 102 | ) 103 | 104 | echo ################### 105 | echo # FLASHING VBMETA # 106 | echo ################### 107 | choice /m "Disable android verified boot?, If unsure, say N. Bootloader won't be lockable if you select Y." 108 | if %errorlevel% equ 1 ( 109 | if %slot% equ all ( 110 | for %%i in (%vbmeta_partitions%) do ( 111 | for %%s in (a b) do ( 112 | call :FlashImage "%%i_%%s --disable-verity --disable-verification", %%i.img 113 | ) 114 | ) 115 | ) else ( 116 | for %%i in (%vbmeta_partitions%) do ( 117 | call :FlashImage "%%i_%slot% --disable-verity --disable-verification", %%i.img 118 | ) 119 | ) 120 | ) else ( 121 | set avb_enabled=1 122 | if %slot% equ all ( 123 | for %%i in (%vbmeta_partitions%) do ( 124 | for %%s in (a b) do ( 125 | call :FlashImage "%%i_%%s", %%i.img 126 | ) 127 | ) 128 | ) else ( 129 | for %%i in (%vbmeta_partitions%) do ( 130 | call :FlashImage "%%i_%slot%", %%i.img 131 | ) 132 | ) 133 | ) 134 | 135 | echo ########################## 136 | echo # REBOOTING TO FASTBOOTD # 137 | echo ########################## 138 | %fastboot% reboot fastboot 139 | if %errorlevel% neq 0 ( 140 | echo Error occured while rebooting to fastbootd. Aborting 141 | pause 142 | exit 143 | ) 144 | 145 | echo ############################### 146 | echo # FLASHING LOGICAL PARTITIONS # 147 | echo ############################### 148 | echo Flash logical partition images? 149 | echo If you're about to install a custom ROM that distributes its own logical partitions, say N. 150 | choice /m "If unsure, say Y." 151 | if %errorlevel% equ 1 ( 152 | if not exist super.img ( 153 | if exist super_empty.img ( 154 | call :WipeSuperPartition 155 | ) else ( 156 | call :ResizeLogicalPartition 157 | ) 158 | for %%i in (%logical_partitions%) do ( 159 | call :FlashImage %%i_%curSlot%, %%i.img 160 | ) 161 | ) else ( 162 | call :FlashImage super, super.img 163 | ) 164 | ) 165 | 166 | echo ########################## 167 | echo # LOCKING THE BOOTLOADER # 168 | echo ########################## 169 | if %avb_enabled% equ 1 ( 170 | choice /m "Lock the bootloader? If unsure, say N." 171 | if %errorlevel% equ 1 ( 172 | %fastboot% reboot bootloader 173 | if %errorlevel% neq 0 ( 174 | echo Error occured while rebooting to bootloader. Aborting 175 | pause 176 | exit 177 | ) else ( 178 | %fastboot% flashing lock 179 | ) 180 | ) 181 | ) 182 | 183 | echo ############# 184 | echo # REBOOTING # 185 | echo ############# 186 | choice /m "Reboot to system? If unsure, say Y." 187 | if %errorlevel% equ 1 ( 188 | %fastboot% reboot 189 | ) 190 | 191 | echo ######## 192 | echo # DONE # 193 | echo ######## 194 | echo Stock firmware restored. 195 | echo You may now optionally re-lock the bootloader if you haven't disabled android verified boot. 196 | 197 | pause 198 | exit 199 | 200 | :UnZipFile 201 | if not exist "%~dp0platform-tools-latest" ( 202 | powershell -command "Expand-Archive -Path '%~dp0platform-tools-latest.zip' -DestinationPath '%~dp0platform-tools-latest' -Force" 203 | ) 204 | exit /b 205 | 206 | :ErasePartition 207 | %fastboot% erase %~1 208 | if %errorlevel% neq 0 ( 209 | call :Choice "Erasing %~1 partition failed" 210 | ) 211 | exit /b 212 | 213 | :SetActiveSlot 214 | %fastboot% --set-active=a 215 | if %errorlevel% neq 0 ( 216 | echo Error occured while switching to slot A. Aborting 217 | pause 218 | exit 219 | ) 220 | exit /b 221 | 222 | :WipeSuperPartition 223 | %fastboot% wipe-super super_empty.img 224 | if %errorlevel% neq 0 ( 225 | echo Wiping super partition failed. Fallback to deleting and creating logical partitions 226 | call :ResizeLogicalPartition 227 | ) 228 | exit /b 229 | 230 | :ResizeLogicalPartition 231 | for %%i in (%logical_partitions%) do ( 232 | for %%s in (a b) do ( 233 | call :DeleteLogicalPartition %%i_%%s-cow 234 | call :DeleteLogicalPartition %%i_%%s 235 | ) 236 | call :CreateLogicalPartition %%i_%curSlot%, 1 237 | ) 238 | exit /b 239 | 240 | :DeleteLogicalPartition 241 | %fastboot% delete-logical-partition %~1 242 | if %errorlevel% neq 0 ( 243 | call :Choice "Deleting %~1 partition failed" 244 | ) 245 | exit /b 246 | 247 | :CreateLogicalPartition 248 | %fastboot% create-logical-partition %~1 %~2 249 | if %errorlevel% neq 0 ( 250 | call :Choice "Creating %~1 partition failed" 251 | ) 252 | exit /b 253 | 254 | :FlashImage 255 | %fastboot% flash %~1 %~2 256 | if %errorlevel% neq 0 ( 257 | call :Choice "Flashing %~2 failed" 258 | ) 259 | exit /b 260 | 261 | :Choice 262 | choice /m "%~1 continue? If unsure say N" 263 | if %errorlevel% equ 2 ( 264 | exit 265 | ) 266 | exit /b 267 | --------------------------------------------------------------------------------