Skip to content

Commit 37ae9cc

Browse files
committed
Enable copy_partitions sideloading and basic config for moto g7 power
1 parent 76b8964 commit 37ae9cc

6 files changed

Lines changed: 90 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Other phone vendors stops allowing to unlock the bootloader all together. There
130130
- The [Android SDK Platform Tools](https://developer.android.com/studio/releases/platform-tools) (such as adb and fastboot) are [Apache](https://android.googlesource.com/platform/system/adb/+/refs/heads/master/NOTICE)-licensed universal Android utilities
131131
- [Heimdall](https://gitlab.com/BenjaminDobell/Heimdall/) is an [MIT](https://gitlab.com/BenjaminDobell/Heimdall/-/blob/master/LICENSE)-licensed replacement for the leaked ODIN tool to flash Samsung devices.
132132
- [libusb-1.0](https://github.com/libusb/libusb) is a [LGPL-2.1](https://github.com/libusb/libusb/blob/master/COPYING)-licensed library for USB device access from Linux, macOS, Windows and others.
133+
- [copy-partitions-20220613-signed.zip](https://mirrorbits.lineageos.org/tools/copy-partitions-20220613-signed.zip) The copy-partitions script was created by LineageOS developer erfanoabdi and filipepferraz and released under LGPL. It is used when the partitions need to be copied before flashing.
133134

134135

135136
## Acknowledgements
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
metadata:
2+
maintainer: Tobias Sterbak (tsterbak)
3+
devicename: Moto G7 power
4+
devicecode: Ocean
5+
requirements:
6+
copy_partitions: True
7+
steps:
8+
unlock_bootloader:
9+
- type: confirm_button
10+
content: >
11+
As a first step, you need to unlock the bootloader of your device. A bootloader is the piece of software, that tells your phone
12+
how to start and run an operating system (like Android). On the device, dial *#06# to launch the service menu.
13+
- type: confirm_button
14+
content: Go to service info > configuration and check rooting status - you can only continue if it says 'Bootloader unlock allowed":" Yes.'
15+
- type: confirm_button
16+
content: >
17+
Now go to Settings 'About the phone' and then Status. Write down the IMEI of your device. You will need it in the next step.
18+
- type: link_button_with_confirm
19+
content: >
20+
Click on the button to open the instructions on Motorola's official unlocking website to generate an unlock code for your bootloader.
21+
Once you got the code write it down somewhere and continue to input the code.
22+
link: https://motorola-global-portal.custhelp.com/app/standalone/bootloader/unlock-your-device-a
23+
- type: confirm_button
24+
content: Connect the device to your PC via USB. And confirm to continue.
25+
- type: call_button
26+
content: Press the button to reboot into the bootloader now. When the notification light turns blue, confirm to continue.
27+
command: adb_reboot_bootloader
28+
- type: call_button_with_input
29+
content: >
30+
Use your code to unlock the bootloader of your device. Type in the full 18 character code starting with 0x (Example: 0x3EC4F7AD6E0B32B6).
31+
If you already did that, you can skip this step.
32+
command: fastboot_unlock_with_code
33+
- type: call_button
34+
content: >
35+
Press the button to reboot. Since the device resets completely, you will need to re-enable USB debugging to continue.
36+
Connect your device to your PC via USB. Then confirm here to continue.
37+
command: fastboot_reboot
38+
flash_recovery:
39+
- type: call_button
40+
content: >
41+
Now you need to flash a custom recovery system on the phone. A recovery is a small subsystem on your phone, that manages updating,
42+
adapting and repairing of the operating system.
43+
Make sure your device is turned on. You need to reboot into the bootloader again by pressing 'Confirm and run' here. Then continue.
44+
command: adb_reboot_bootloader
45+
- type: call_button
46+
content: Flash a custom recovery (temporarily) by pressing 'Confirm and run'. Once it's done continue.
47+
command: fastboot_flash_recovery
48+
install_os:
49+
- type: call_button
50+
content: >
51+
In the next steps, you finally flash the selected OS image.
52+
Wait until the TWRP screen appears. Then run the command.
53+
This step will format your phone and wipe all the data. It will also remove encryption and delete all files stored
54+
in the internal storage. Then the OS image will be installed. Confirm to run. This might take a while. At the end your phone will boot into the new OS.
55+
command: adb_twrp_wipe_and_install
3.95 KB
Binary file not shown.

openandroidinstaller/installer_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
self.install_os = install_os
6363
self.metadata = metadata
6464
self.requirements = requirements
65+
self.copy_partitions = requirements.get("copy_partitions", False)
6566

6667
@classmethod
6768
def from_file(cls, path):
@@ -153,6 +154,7 @@ def validate_config(config: str) -> bool:
153154
schema.Optional("requirements"): {
154155
schema.Optional("android"): schema.Or(str, int),
155156
schema.Optional("firmware"): str,
157+
schema.Optional("copy_partitions"): bool,
156158
},
157159
"steps": {
158160
"unlock_bootloader": schema.Or(None, [step_schema]),

openandroidinstaller/tooling.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,43 @@ def adb_sideload(bin_path: Path, target: str) -> bool:
101101
yield True
102102

103103

104-
def adb_twrp_wipe_and_install(bin_path: Path, target: str, config_path: Path) -> bool:
104+
def adb_twrp_wipe_and_install(
105+
bin_path: Path, target: str, config_path: Path, copy_partitions: bool = False
106+
) -> bool:
105107
"""Wipe and format data with twrp, then flash os image with adb.
106108
107109
Only works for twrp recovery.
108110
"""
109111
logger.info("Wipe and format data with twrp, then install os image.")
110112
sleep(7)
113+
# some devices like one plus 6t or motorola moto g7 power need the partitions copied to prevent a hardbrick
114+
if copy_partitions:
115+
logger.info("Sideload copy_partitions script with adb.")
116+
# activate sideload
117+
for line in run_command("adb", ["shell", "twrp", "sideload"], bin_path):
118+
yield line
119+
if (type(line) == bool) and not line:
120+
logger.error("Activating sideload failed.")
121+
yield False
122+
return
123+
# now sideload the script
124+
sleep(5)
125+
logger.info("Sideload the copy_partitions script")
126+
for line in run_command(
127+
"adb",
128+
[
129+
"sideload",
130+
str(config_path.parent) + "/copy-partitions-20220613-signed.zip",
131+
],
132+
bin_path,
133+
):
134+
yield line
135+
if (type(line) == bool) and not line:
136+
logger.error("Sideloading copy-partitions-20220613-signed.zip failed.")
137+
sleep(5)
138+
# Copy partitions end #
139+
140+
# now perform a factory reset
111141
for line in run_command("adb", ["shell", "twrp", "format", "data"], bin_path):
112142
yield line
113143
if (type(line) == bool) and not line:

openandroidinstaller/views/step_view.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def call_to_phone(self, e, command: str):
199199
adb_twrp_wipe_and_install,
200200
target=self.state.image_path,
201201
config_path=self.state.config_path,
202+
copy_partitions=self.state.config.copy_partitions,
202203
),
203204
"fastboot_unlock": fastboot_unlock,
204205
"fastboot_unlock_with_code": partial(

0 commit comments

Comments
 (0)