Skip to content

Commit a478918

Browse files
committed
Add LOKI support
add loki_tool_static precompiled binary (armeabi-v7a, position-independent) add "lokiaboot" and "lokipatch" partition properties to fstab patch partitions marked as "lokipatch" before flashing
1 parent e4b2cdc commit a478918

4 files changed

Lines changed: 95 additions & 5 deletions

File tree

22.8 KB
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.efidroid.efidroidmanager;
2+
3+
import org.efidroid.efidroidmanager.services.IntentServiceEx;
4+
5+
public class LokiTool {
6+
public enum PartitionLabel {
7+
BOOT("boot"),
8+
RECOVERY("recovery");
9+
10+
private final String mLabel;
11+
12+
PartitionLabel(String s) {
13+
mLabel = s;
14+
}
15+
16+
public String getLabel() {
17+
return mLabel;
18+
}
19+
}
20+
21+
private LokiTool() {
22+
}
23+
24+
public static void patchImage(IntentServiceEx service, PartitionLabel label, String bootloaderImage, String inImage, String outImage) throws Exception {
25+
RootToolsEx.runServiceCommand(service, String.format("loki_tool_static patch %s \"%s\" \"%s\" \"%s\"", label.getLabel(), bootloaderImage, inImage, outImage));
26+
}
27+
28+
public static void flashImage(IntentServiceEx service, PartitionLabel label, String image) throws Exception {
29+
RootToolsEx.runServiceCommand(service, String.format("loki_tool_static flash %s \"%s\"", label.getLabel(), image));
30+
}
31+
}

app/src/main/java/org/efidroid/efidroidmanager/tasks/EFIDroidInstallServiceTask.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import android.os.Bundle;
44
import android.support.annotation.Keep;
55

6+
import com.stericson.roottools.RootTools;
7+
68
import org.efidroid.efidroidmanager.AppConstants;
9+
import org.efidroid.efidroidmanager.LokiTool;
710
import org.efidroid.efidroidmanager.R;
811
import org.efidroid.efidroidmanager.RootToolsEx;
912
import org.efidroid.efidroidmanager.Util;
@@ -17,6 +20,7 @@
1720
import org.json.JSONObject;
1821

1922
import java.io.BufferedInputStream;
23+
import java.io.FileNotFoundException;
2024
import java.io.FileOutputStream;
2125
import java.io.InputStream;
2226
import java.io.OutputStream;
@@ -114,6 +118,18 @@ private String downloadUpdate(String urlString) throws Exception {
114118
return downloadDir;
115119
}
116120

121+
private void lokiPatchAndFlash(LokiTool.PartitionLabel partition, String bootloaderImage, String fileToPatch) throws Exception {
122+
if (bootloaderImage == null)
123+
throw new FileNotFoundException("Cannot find backed up bootloader");
124+
String patchedFile = fileToPatch + ".lok";
125+
try {
126+
LokiTool.patchImage(getService(), partition, bootloaderImage, fileToPatch, patchedFile);
127+
LokiTool.flashImage(getService(), partition, patchedFile);
128+
} finally {
129+
RootTools.deleteFileOrDirectory(patchedFile, false);
130+
}
131+
}
132+
117133
private void doInstall(String updateDir) throws Exception {
118134
// get esp parent directory
119135
String espParent = mDeviceInfo.getESPDir(false);
@@ -161,13 +177,36 @@ private void doInstall(String updateDir) throws Exception {
161177
}
162178
}
163179

164-
// install
180+
// dump bootloader to temporary folder
181+
String bootloaderImage = null;
165182
for (FSTabEntry entry : mDeviceInfo.getFSTab().getFSTabEntries()) {
166-
if (!entry.isUEFI())
167-
continue;
183+
if (entry.isLokiABoot()) {
184+
bootloaderImage = getService().getCacheDir().getCanonicalPath() + "/bootloader.img";
185+
RootToolsEx.createPartitionBackup(getService(), entry.getBlkDevice(), bootloaderImage, -1);
186+
}
187+
}
168188

169-
String file = updateDir + "/" + entry.getName() + ".img";
170-
RootToolsEx.dd(file, entry.getBlkDevice());
189+
// install
190+
try {
191+
for (FSTabEntry entry : mDeviceInfo.getFSTab().getFSTabEntries()) {
192+
if (!entry.isUEFI())
193+
continue;
194+
195+
String file = updateDir + "/" + entry.getName() + ".img";
196+
197+
// if needed, apply LOKI patch to boot and recovery partitions
198+
if (entry.isLokiPatch()) {
199+
if (entry.getName().equals(LokiTool.PartitionLabel.BOOT.getLabel()))
200+
lokiPatchAndFlash(LokiTool.PartitionLabel.BOOT, bootloaderImage, file);
201+
else if (entry.getName().equals(LokiTool.PartitionLabel.RECOVERY.getLabel()))
202+
lokiPatchAndFlash(LokiTool.PartitionLabel.RECOVERY, bootloaderImage, file);
203+
} else {
204+
RootToolsEx.dd(file, entry.getBlkDevice());
205+
}
206+
}
207+
} finally {
208+
// remove bootloader dump
209+
RootTools.deleteFileOrDirectory(bootloaderImage, false);
171210
}
172211
}
173212

app/src/main/java/org/efidroid/efidroidmanager/types/FSTabEntry.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ public boolean isMultiboot() {
105105
return false;
106106
}
107107

108+
public boolean isLokiABoot() {
109+
String[] parts = mFfMgrFlags.split(",");
110+
for (String part : parts) {
111+
if (part.equals("lokiaboot")) {
112+
return true;
113+
}
114+
}
115+
return false;
116+
}
117+
118+
public boolean isLokiPatch() {
119+
String[] parts = mFfMgrFlags.split(",");
120+
for (String part : parts) {
121+
if (part.equals("lokipatch")) {
122+
return true;
123+
}
124+
}
125+
return false;
126+
}
127+
108128
public boolean isUEFI() {
109129
String[] parts = mFfMgrFlags.split(",");
110130
for (String part : parts) {

0 commit comments

Comments
 (0)