-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathflash_oneplus6.sh
More file actions
executable file
·168 lines (143 loc) · 6.75 KB
/
Copy pathflash_oneplus6.sh
File metadata and controls
executable file
·168 lines (143 loc) · 6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env bash
set -eu
# This script is for flashing the partitions manually using images extracted
# from an official OxygenOS zip, which you can get here:
# https://www.oneplus.com/global/support/softwareupgrade
# You can use this payload dumper to extract the files from the OTA zip:
# https://github.com/tobyxdd/android-ota-payload-extractor
# Or alternatively this:
# https://github.com/vm03/payload_dumper
# It supports running directly from a pre-built Docker container.
# After you have run this script, you may want to run the additional
# script for flashing the critical partitions.
# If you get an error saying that the boot images are bigger than the corresponding
# partitions, you should first OTA update the device with official firmware,
# or flash it with MSM directly to a relatively new OxygenOS.
# (OxygenOS 10 worked, but 8 did not.)
# You can find some MSM images here:
# https://www.thecustomdroid.com/oneplus-6-6t-unbrick-guide/
# If you have issues in getting Fastboot to work, try a USB 2.0 cable or a USB 2.0 port.
# Enable factory reset if doing a clean install!
FACTORY_RESET=true
FLASH_A=true
FLASH_B=true
if [ "${EUID}" -ne 0 ]; then
echo "This script should be run as root to ensure that fastboot works correctly."
exit 1
fi
# https://stackoverflow.com/a/246128/
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REPO_DIR="$(dirname "${SCRIPT_DIR}")"
FASTBOOT="${SCRIPT_DIR}/platform-tools/fastboot"
CWD="${PWD}"
TIMESTAMP="$(date +%Y-%m-%d_%H-%M-%S)"
LOG_PATH="${REPO_DIR}/logs/flash_oneplus6_${TIMESTAMP}.txt"
echo "Starting OnePlus 6 fastboot flash script." |& tee "${LOG_PATH}"
if [ -f "${FASTBOOT}" ]; then
echo "Fastboot found."
else
echo "Fastboot was not found. Please run \"download_tools.sh\"."
exit 1
fi
# Directory checks
OTA_DIR="${CWD}/OTA"
if [ -d "${OTA_DIR}" ]; then
echo "OTA directory found."
else
echo "OTA directory was not found. Please put the img files to the subdirectory \"OTA\"."
exit 1
fi
LINEAGEOS_DIR="${CWD}/LineageOS"
if [ -d "${LINEAGEOS_DIR}" ]; then
echo "LineageOS directory found."
else
echo "LineageOS directory was not found. Please put the img files and signatures to the subdirectory \"LineageOS\"."
exit 1
fi
if [ -f "${LINEAGEOS_DIR}/imgs.sha256" ]; then
echo "LineageOS SHA256 file found."
else
echo "LineageOS SHA256 file was not found. Please create it from the SHA256 checksums on the download website."
exit 1
fi
TWRP_DIR="${CWD}/TWRP"
if [ -d "${TWRP_DIR}" ]; then
echo "TWRP directory found."
else
echo "TWRP directory was not found. Please put the TWRP img file and signatures to the subdirectory \"TWRP\"."
fi
# File checks
cd "${LINEAGEOS_DIR}"
sha256sum -c "./imgs.sha256"
# "${CWD}"
cd "${TWRP_DIR}"
TWRP_FILES=("${TWRP_DIR}"/*.img)
TWRP_IMG="${TWRP_FILES[0]}"
sha256sum -c "${TWRP_IMG}.sha256"
wget "https://eu.dl.twrp.me/public.asc" -O "${TWRP_DIR}/public.asc"
gpg --import "${TWRP_DIR}/public.asc"
gpg --verify "${TWRP_IMG}.asc" "${TWRP_IMG}"
cd "${CWD}"
# Factory reset
if [ "${FACTORY_RESET}" = true ]; then
echo "Factory resetting the device" |& tee -a "${LOG_PATH}"
$FASTBOOT -w |& tee -a "${LOG_PATH}"
fi
# The partition list below is based on these instructions
# https://forum.xda-developers.com/t/rom-stock-fastboot-op6-stock-fastboot-roms-for-oneplus-6.3796665/
# https://www.droidwin.com/restore-oneplus-6-stock-via-fastboot-commands/
if [ "${FLASH_A}" = true ]; then
echo "Flashing OTA images to slot A" |& tee -a "${LOG_PATH}"
$FASTBOOT flash aop_a "${OTA_DIR}/aop.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash bluetooth_a "${OTA_DIR}/bluetooth.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash boot_a "${OTA_DIR}/boot.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash dsp_a "${OTA_DIR}/dsp.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash dtbo_a "${OTA_DIR}/dtbo.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash fw_4j1ed_a "${OTA_DIR}/fw_4j1ed.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash fw_4u1ea_a "${OTA_DIR}/fw_4u1ea.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash modem_a "${OTA_DIR}/modem.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash oem_stanvbk "${OTA_DIR}/oem_stanvbk.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash qupfw_a "${OTA_DIR}/qupfw.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash storsec_a "${OTA_DIR}/storsec.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash system_a "${OTA_DIR}/system.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash vbmeta_a "${OTA_DIR}/vbmeta.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash vendor_a "${OTA_DIR}/vendor.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash LOGO_a "${OTA_DIR}/LOGO.img" |& tee -a "${LOG_PATH}"
fi
if [ "${FLASH_B}" = true ]; then
echo "Flashing OTA images to slot B" |& tee -a "${LOG_PATH}"
$FASTBOOT flash aop_b "${OTA_DIR}/aop.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash bluetooth_b "${OTA_DIR}/bluetooth.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash boot_b "${OTA_DIR}/boot.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash dsp_b "${OTA_DIR}/dsp.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash dtbo_b "${OTA_DIR}/dtbo.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash fw_4j1ed_b "${OTA_DIR}/fw_4j1ed.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash fw_4u1ea_b "${OTA_DIR}/fw_4u1ea.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash modem_b "${OTA_DIR}/modem.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash qupfw_b "${OTA_DIR}/qupfw.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash storsec_b "${OTA_DIR}/storsec.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash system_b "${OTA_DIR}/system.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash vbmeta_b "${OTA_DIR}/vbmeta.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash vendor_b "${OTA_DIR}/vendor.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash LOGO_b "${OTA_DIR}/LOGO.img" |& tee -a "${LOG_PATH}"
fi
if [ "${FLASH_A}" = true ]; then
echo "Flashing LineageOS to slot A"
$FASTBOOT flash boot_a "${LINEAGEOS_DIR}/boot.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash dtbo_a "${LINEAGEOS_DIR}/dtbo.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash vbmeta_a "${LINEAGEOS_DIR}/vbmeta.img" |& tee -a "${LOG_PATH}"
fi
if [ "${FLASH_B}" = true ]; then
echo "Flashing LineageOS to slot B"
$FASTBOOT flash boot_b "${LINEAGEOS_DIR}/boot.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash dtbo_b "${LINEAGEOS_DIR}/dtbo.img" |& tee -a "${LOG_PATH}"
$FASTBOOT flash vbmeta_b "${LINEAGEOS_DIR}/vbmeta.img" |& tee -a "${LOG_PATH}"
fi
# This would overwrite sensor calibrations and some other unique data
# $FASTBOOT flash persist persist.img |& tee -a "${LOG_PATH}"
# Rebooting back to the bootloader just in case to ensure that all changes have been applied
echo "Rebooting the device to the bootloader" |& tee -a "${LOG_PATH}"
$FASTBOOT reboot bootloader |& tee -a "${LOG_PATH}"
echo "Booting the device to TWRP" |& tee -a "${LOG_PATH}"
$FASTBOOT boot "${TWRP_IMG}" |& tee -a "${LOG_PATH}"
echo "Flashing script ready." |& tee -a "${LOG_PATH}"