[HOWTO] ✏ Compiling Fairphone Open OS / Rooting

Hi vivia,
If you want you can send the Makefile via pm. I will have a look, then. Probably will be tomorrow, as this evening I’m away

I realized that the system/xbin/su file showed as empty from Amaze. I noticed that this is because of SELinux. Seems that it restricts access for nearly everything, except ADB shell. ADB doesn’t work for me, don’t know why. Works without problems with my FP1.
Anyway I found a hint here Disabling SELinux in Android 5.0.1 - Stack Overflow
So I added

BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive

to device/fairphone_devices/FP2/BoardConfig.mk. This requires to flash boot.img as the kernel cmdline changed.
With that change Amaze can see correct details of xbin/su. SuperSU tries to copy new su at least, unfortunately without success.

OpenGApps can be integrated quiet easily using this: https://github.com/opengapps/aosp_build
Only some lib files need to be moved or alternatively make files modified.
I tried with nano variant:

I also tried koush’s Superuser today (https://github.com/koush/Superuser). Integration was no problem, but didn’t work either. It looks like that SELinux stuff makes it complicated. There is a fork of that abandoned project: https://github.com/phhusson/Superuser
It states that it has most of SuperSU’s functionality. And its open source. That is what we want, right? :wink:

5 Likes

I’ve fooled a bit with Superuser a week ago, but SELinux prevented me from making it work (or at least I think so). I’ve tried installing their su binary by hand but it’s inaccessible from apps (trying to access it with a terminal emulator returned an error saying something like this : "access forbidden for pid ").

I hope you can find a workaround :wink:

Sorry for the spam but I think this deserves a separate post. Has anyone else had huge battery drains during sleep mode because of the AOSM “mail” app ? I went from 80% to 46% battery overnight because of it.

Using K-9 only brought me from 98% to 96% overnight…

I don’t know, I only use K-9, but maybe you can ask here instead? FP2 battery saving challenge

EDIT: @Arvil I was seeing K-9 Mail use around 33% of my CPU in the stats. Then I was looking for something else and enabled “Background Sync” in Settings -> Accounts -> three dots. K-9 Mail disappeared from the statistics. Of course I have set it to poll every 30 minutes and use push normally, but it might give you a clue.

1 Like

OK, this is how to root an existing image (which might be the stock image with Google stuff):

  1. Follow the instructions on the top of this thread, but stop right before the “make -j8” command.
  2. Download Busybox from here: https://drive.google.com/file/d/0B-9cNi0ys0CMeGdhTXFlMW9qaUk/view?usp=docslist_api (One-shot compilation by @lklaus )
  3. Put rcbins.tar inside your fairphone_os directory and extract it.
  4. Download SuperSU from here: https://download.chainfire.eu/696/supersu/
  5. Put SuperSU inside your fairphone_os directory, but don’t extract it.
  6. Apply this patch: https://gist.github.com/vivia/410a8647e0273405fd77
    You can either open it and apply it manually (just a few lines to be added) or look at this: https://groups.google.com/forum/#!topic/repo-discuss/43juvD1qGIQ
  7. Now start compiling: make -j8
    If the compilation is successful:
  8. Reboot into bootloader (adb reboot bootloader or turn on by down arrow + power)
  9. Connect your phone to the computer if you haven’t done so
  10. Wait for the device to appear (fastboot devices)
  11. Flash the recovery image (fastboot flash recovery out/target/product/FP2/recovery.img)
    If this is successful:
  12. Reboot into recovery mode (up arrow + power)
  13. From the menu on the phone, select “Apply update from ADB”
  14. adb sideload UPDATE-SuperSU-v2.46.zip
  15. Reboot and you’re ready!

Note that I haven’t been able to compile a pre-rooted image, but this does the trick. :smile:
Many thanks to @lklaus !

5 Likes

I added it roughly to the Wiki. @lklaus/@vivia, please correct/beautify!

2 Likes

I just removed the “untested” warning. I tested it myself on two devices (both with unofficial images) and it worked, and @lklaus tested it on a device with the official image. :slight_smile:

Ideally I’d like to create an already rooted image, but I can’t figure out how on earth to do it :frowning:

1 Like

Great, I was hoping you would report something like that, thanks! I guess I will include the repo apply script in the wiki, it’s useful.

1 Like

I just had an idea, there should be no blobs involved in the recovery image, right? So in theory we could make a blob-free recovery.img and distribute it? :slight_smile:

2 Likes

Good question/idea. I’m not an expert. If a clean build without the blobs is successful? I think so :smile:

The recovery is Android Open Source Project/Apache 2. I’m sure there are nicer recoveries out there, but this one is as good as any to start with. A few checksums here (if a build without blobs is successful) will help as well.

I don’t think checksums are usable, the build contains information about your username, computer name, date/time, kernel on your computer etc. But I might try a clean build without blobs just for the sake of it. It’s just a hassle to have one more directory of a clean repo sync :frowning:

Docker might help while experimenting? (make clean and clean out /vendor/qcom/proprietary) fp2-sibon-2.0.0-blobs.sh is just a zipped tar file cp’ing stuff to ./vendor/qcom/proprietary/. The rest of the magic (that should not be used) is in ./vendor/qcom/proprietary/vendorsetup.sh

(Update, my time to look into this is up, but I’m sure most of it can be found in build/core/Makefile)

What’s the problem with that? Isn’t everything in the repo supposed to be in git repositories? It should be fairly easy to store your changes (in a different branch or you can git stash your changes). Or you checkout to a different working directory which uses almost no additional disk space because everything is stored in git anyway and only hard-links are checked out.

1 Like

I understood that you might publish the hash of your compiled open source recovery IMG here before sharing it. To verify the downloaded IMG is OK.

A build without the blobs probably won’t work (because compilation will fail on one or several make targets). It’s also unlikely the recovery system will be free from licensed stuff since there are several sh files with “qcom” in them in the recovery “root” dir.

1 Like

I did a quick “make -j8” here, looked okay, just a few standard unix tools getting complied. But maybe I’m missing a lot here, it was just a small random test without really looking into it. :frowning:

Recovery image (in build/core/Makefile, search for # Recovery imag) and (bootable/recovery/Android.mk) or is there more? But @lklaus is our recovery expert, so I just wait for his answer. :slight_smile:

Heyho,

I’ve same problems compiling the source.
I’m using Debian Jessie (8.2). I installed gcc-4.8 and tried to use update-alternatives. But I get this error: “update-alternatives: Fehler: keine Alternativen für gcc”.
I don’t konw wether this is a problem or not.

Why I’m writing is, that make ends very soon with the following error:
> Export includes file: external/openssl/Android.mk – out/host/linux-x86/obj32/STATIC_LIBRARIES/libcrypto_static_intermediates/export_includes
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:30: error: package org.antlr.runtime.tree does not exist
> import org.antlr.runtime.tree.*;
> ^
> Export includes file: external/zlib/Android.mk – out/host/linux-x86/obj32/STATIC_LIBRARIES/libunz_intermediates/export_includes
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/MismatchedTreeNodeException.java:30: error: package org.antlr.runtime.tree does not exist
> import org.antlr.runtime.tree.TreeNodeStream;
> ^
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/MismatchedTreeNodeException.java:31: error: package org.antlr.runtime.tree does not exist
> import org.antlr.runtime.tree.Tree;
> ^
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/MismatchedTreeNodeException.java:41: error: cannot find symbol
> public MismatchedTreeNodeException(int expecting, TreeNodeStream input) {
> ^
> symbol: class TreeNodeStream
> location: class MismatchedTreeNodeException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/Parser.java:30: error: package org.antlr.runtime.debug does not exist
> import org.antlr.runtime.debug.DebugTokenStream;
> ^
> Import includes file: out/host/linux-x86/obj32/STATIC_LIBRARIES/libunz_intermediates/import_includes
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/ParserRuleReturnScope.java:30: error: package org.antlr.runtime.tree does not exist
> import org.antlr.runtime.tree.CommonTree;
> ^
> Import includes file: out/host/linux-x86/obj32/STATIC_LIBRARIES/libcrypto_static_intermediates/import_includes
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/UnbufferedTokenStream.java:30: error: package org.antlr.runtime.misc does not exist
> import org.antlr.runtime.misc.LookaheadStream;
> ^
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/UnbufferedTokenStream.java:50: error: cannot find symbol
> public class UnbufferedTokenStream extends LookaheadStream implements TokenStream {
> ^
> symbol: class LookaheadStream
> Export includes file: system/core/adb/Android.mk – out/host/linux-x86/obj32/EXECUTABLES/adb_intermediates/export_includes
> Notice file: system/core/adb/NOTICE – out/host/linux-x86/obj/NOTICE_FILES/src//bin/adb.txt
> Notice file: system/core/libzipfile/NOTICE – out/host/linux-x86/obj/NOTICE_FILES/src//lib64/libzipfile.a.txt
> Notice file: system/core/libzipfile/NOTICE – out/host/linux-x86/obj/NOTICE_FILES/src//lib/libzipfile.a.txt
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:110: error: cannot find symbol
> if ( input instanceof TreeNodeStream ) {
> ^
> symbol: class TreeNodeStream
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:124: error: cannot find symbol
> TreeNodeStream nodes = (TreeNodeStream)input;
> ^
> symbol: class TreeNodeStream
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:124: error: cannot find symbol
> Notice file: external/zlib/NOTICE – out/host/linux-x86/obj/NOTICE_FILES/src//lib64/libunz.a.txt
> TreeNodeStream nodes = (TreeNodeStream)input;
> ^
> symbol: class TreeNodeStream
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:126: error: cannot find symbol
> TreeAdaptor adaptor = nodes.getTreeAdaptor();
> ^
> symbol: class TreeAdaptor
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:152: error: cannot find symbol
> else if ( this.node instanceof Tree) {
> ^
> symbol: class Tree
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:153: error: cannot find symbol
> this.line = ((Tree)this.node).getLine();
> ^
> symbol: class Tree
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:154: error: cannot find symbol
> this.charPositionInLine = ((Tree)this.node).getCharPositionInLine();
> ^
> symbol: class Tree
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:155: error: cannot find symbol
> if ( this.node instanceof CommonTree) {
> ^
> symbol: class CommonTree
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:156: error: cannot find symbol
> this.token = ((CommonTree)this.node).token;
> ^
> symbol: class CommonTree
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:171: error: cannot find symbol
> else if ( input instanceof TreeNodeStream ) {
> ^
> symbol: class TreeNodeStream
> location: class RecognitionException
> Notice file: external/zlib/NOTICE – out/host/linux-x86/obj/NOTICE_FILES/src//lib/libunz.a.txt
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:172: error: cannot find symbol
> TreeNodeStream nodes = (TreeNodeStream)input;
> ^
> symbol: class TreeNodeStream
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:172: error: cannot find symbol
> TreeNodeStream nodes = (TreeNodeStream)input;
> ^
> symbol: class TreeNodeStream
> location: class RecognitionException
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/RecognitionException.java:173: error: cannot find symbol
> TreeAdaptor adaptor = nodes.getTreeAdaptor();
> ^
> symbol: class TreeAdaptor
> location: class RecognitionException
> Notice file: external/openssl/NOTICE – out/host/linux-x86/obj/NOTICE_FILES/src//lib/libcrypto_static.a.txt
> Export includes file: system/core/libbacktrace/Android.mk – out/host/linux-x86/obj32/SHARED_LIBRARIES/libbacktrace_intermediates/export_includes
> Export includes file: system/core/libbacktrace/Android.mk – out/host/linux-x86/obj32/SHARED_LIBRARIES/libbacktrace_test_intermediates/export_includes
> Export includes file: external/gtest/src/Android.mk – out/host/linux-x86/obj32/STATIC_LIBRARIES/libgtest_host_intermediates/export_includes
> Export includes file: external/gtest/src/Android.mk – out/host/linux-x86/obj32/STATIC_LIBRARIES/libgtest_main_host_intermediates/export_includes
> Export includes file: external/libunwind/Android.mk – out/host/linux-x86/obj32/SHARED_LIBRARIES/libunwind_intermediates/export_includes
> Export includes file: system/core/liblog/Android.mk – out/host/linux-x86/obj32/SHARED_LIBRARIES/liblog_intermediates/export_includes
> Export includes file: external/libunwind/Android.mk – out/host/linux-x86/obj32/SHARED_LIBRARIES/libunwind-ptrace_intermediates/export_includes
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/UnbufferedTokenStream.java:50: error: UnbufferedTokenStream is not abstract and does not override abstract method range() in TokenStream
> public class UnbufferedTokenStream extends LookaheadStream implements TokenStream {
> ^
> Import includes file: out/host/linux-x86/obj32/SHARED_LIBRARIES/libunwind_intermediates/import_includes
> external/antlr/antlr-3.4/runtime/Java/src/main/java/org/antlr/runtime/UnbufferedTokenStream.java:75: error: cannot find symbol
> public int LA(int i) { return LT(i).getType(); }
> ^
> symbol: method LT(int)
> location: class UnbufferedTokenStream
> Note: Some input files use unchecked or unsafe operations.
> Note: Recompile with -Xlint:unchecked for details.
> 23 errors
> build/core/host_java_library.mk:84: recipe for target ‘out/host/common/obj/JAVA_LIBRARIES/antlr-runtime_intermediates/javalib.jar’ failed
> make: *** [out/host/common/obj/JAVA_LIBRARIES/antlr-runtime_intermediates/javalib.jar] Error 41
> make: *** Warte auf noch nicht beendete Prozesse…
> Note: Some input files use unchecked or unsafe operations.
> Note: Recompile with -Xlint:unchecked for details.
> Note: Some input files use or override a deprecated API.
> Note: Recompile with -Xlint:deprecation for details.
> Note: Some input files use unchecked or unsafe operations.
> Note: Recompile with -Xlint:unchecked for details.

> #### make failed to build some targets (01:45 (mm:ss)) ####

The whole output can be found here: http://pastebin.com/03QG3qvv.

Thank you and best wishes, berta

Hi,
I’m a bit at a loss here, I don’t know what the question is…

The concept behind my modifications to the stock recovery:

  • deactivate zip file verification (in install.cpp in recovery)
  • at least SuperSu in its install script mounts partition,so it needs an fstab, and does not look for recovery.fstab. I work around this by making a link from recovery.fstab to fstab (in the Makefile)
  • As the install skript is a shell skript, we need an sh interpreter in the recovery. I had a compiled busybox left over from some tests with TWRP. I saved the executables and libraries and made the rcbins.tar. This has to be untarred at some place (preferably $HOME) and will also be copied to the sbin from the recovery
  • as the busybox binaries from TWRP are dynamically compiled, the system needs to know where the libraries are. This is done by the modification to init.rc after “on init”

edit: just checked the wiki. As vivia specifies a location for rcbins.tar and delivers the Makefile, follow the wiki post and leave my remarks here as a general explanation to know whats happening

1 Like