-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LOKI support #11
base: master
Are you sure you want to change the base?
Add LOKI support #11
Conversation
65e0669
to
3c1b210
Compare
did you test this? |
It uses existing backup code to read aboot partition and place it dump to esp. Loki reads this file, not partition. |
oh but you're writing that temporary backup to the ESP even though the partition is not being changed(it's information is just used to patch boot/recovery). You should put the backup in the apps temporary folder instead and delete it when you're done. |
1fdcc4c
to
e67fd8e
Compare
Made a dumping bootloader to getCacheDir() and removing when installation finishes |
@@ -105,6 +105,26 @@ public boolean isMultiboot() { | |||
return false; | |||
} | |||
|
|||
public boolean isLokiAboot() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name should be 'isLokiABoot' because A is for Android and B is for Bootloader.
|
||
String file = updateDir + "/" + entry.getName() + ".img"; | ||
|
||
//if needed, apply LOKI patch to boot and recovery partitions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space after //
RootToolsEx.dd(file, entry.getBlkDevice()); | ||
} | ||
} finally { | ||
//remove bootloader dump |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space after //
@@ -161,13 +176,36 @@ private void doInstall(String updateDir) throws Exception { | |||
} | |||
} | |||
|
|||
// install | |||
//dump bootloader to temporary folder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space after //
} | ||
|
||
public static boolean flashImage(PartitionLabel label, String image) { | ||
//root required for flashing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space after //
|
||
String mLabel; | ||
PartitionLabel(String s) { | ||
mLabel=s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before and after =
private LokiTool() {} | ||
|
||
private static native int lokiPatch(String partitionLabel, String bootloaderImage, | ||
String inImage, String outImage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this linebreak looks weird
private static native int lokiFlash(String partitionLabel, String image); | ||
|
||
public static boolean patchImage(PartitionLabel label, String bootloaderImage, | ||
String inImage, String outImage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this linebreak looks weird
@@ -114,6 +118,17 @@ private String downloadUpdate(String urlString) throws Exception { | |||
return downloadDir; | |||
} | |||
|
|||
private static void lokiPatchAndFlash(LokiTool.PartitionLabel partition, | |||
String bootloaderImage, String fileToPatch) throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this linebreak looks weird
String file = updateDir + "/" + entry.getName() + ".img"; | ||
|
||
//if needed, apply LOKI patch to boot and recovery partitions | ||
if (entry.isLokiPatch() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls use nested if's to remove the duplicate condition 'isLokiPatch'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should run AndroidStudio's auto-formatting tool on all the files which would make the changes I've requested much easier.
d5bb80e
to
9e95e7f
Compare
Improved encapsulation in "partitionlabel" enum, fixed formatting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comments
// root required for flashing | ||
boolean isRootAccess = RootTools.isAccessGiven(); | ||
if (!isRootAccess) { | ||
Log.e(TAG, "flashImage: cannot get root privileges"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sry that I missed this previously, but why are you using the volley logtag here?
Also why are you checking for root in first place?
- it has already been done at this point
- the call to lokiFlash doesn't need root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About tag: autocompleted at "loge"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Root required because of native library writes new boot and recovery parts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and where does this happen? NDK-code does not run as root and cannot write to any partitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well unless your ROM uses super insecure permissions and selinux is disabled this line will always fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean I have to use RootToolsEx.dd() to flash patched parts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either that or you have to compile loki as a statically linked binary like busybox and run it as root.
So, didn't you test your change yet? Because such a mistake should have been noticed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no device to test this tool. Also, at first idea was compiling loki_tool. Now I think, maybe just place precompiled binary into "assets" and call it
Rewrote using separate binary (runs on my device) |
0ed76f6
to
57272fa
Compare
try { | ||
InputStream is = null; | ||
try { | ||
is = context.getAssets().open("armeabi-v7a/loki_tool_static"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this binary isn't statically linked. Linking it dynamically actually isn't such a bad idea because it makes the file size much smaller. But what about compatibility? we need to support 4.0+.
Also, is it possible to build binaries with gradle+ndk? The only reason I'm using busybox prebuilt is that it doesn't work that well when compiled using the ndk and still needs to be built using autoconf anyway.
Either way, we don't include the link-type in the filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find way to build and add binary to apk using gradle.
I built it with ndk-build which uses Android.mk included in sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comments
abis.add(Build.CPU_ABI2); | ||
} | ||
// do not initialize on non-arm cpu | ||
if (!abis.contains("armeabi-v7a")) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should rather make the original code for busybox reusable, also don't limit this to ARM.
If you do this you can also keep this code inside RootToolsEx since this implementation shouldn't have to care about where the binary comes from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tool is usable only for arm-based phones.
See https://github.com/efidroid/modules_loki/blob/master/loki_patch.c#L30
da42dcd
to
24cb84c
Compare
FSTabEntry: getFfMgrFlags() returns list of flags. Rewrite isMultiboot(), isUEFI(), getESP() using it Move ABIs retrieving code to separate method getABIs() in Util Add universal image patching interface Add image patching (if needed) before flashing. Add LOKI as git submodule Add LOKI image patcher using NDK
add "lokiaboot" and "lokipatch" partition properties to fstab
patch partitions marked as "lokipatch" before flashing