Building Nile SODP Kernels

Recently I decided to do some personal kernel work on my discovery, aka Sony Xperia XA2 Ultra, which is part of the “nile” family of devices. I use the Sony Open Device Project trees and kernel, because regardless of what they think of me, I think they do exceptionally great work.

Unfortunately, the SODP build instructions for kernel building are just a little out of date, as Google has depreciated using GCC in favor of Clang. If you built your kernel for a nile device with clang, it will actually have issues with the camera, as you can read about in the issue tracker for SODP.

So, since I walked through it, I decided I would write down what I did in case anyone else needs a little help with this. I’m writing it in the same order the SODP instructions use, so it will be very clear when reviewing with the written instructions on their website.

Step 1: Unlock the boot loader per the SODP instructions.

Step 2: Download a cross compiler.

This is the part where things go awry. If you follow the instructions, you get the version of GCC tool-chain that Google removed half of it’s contents, causing it not to work, since they are depreciating it. You need to download this version: https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/+archive/606f80986096476912e04e5c2913685a8f2c3b65.tar.gz because it is the last version to have all of the tools in it.

Also, while you are only compiling a 64 bit kernel, if you don’t have the 32 bit tool-chain, you will have to trick the compiler when compiling stand alone (e.g., outside of Android source code). So, I recommend you also download this 32 bit tool-chain to keep GCC and the scripts from trying to use your system one: https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/+/refs/tags/android-cts-10.0_r6

Both of these should be extracted into their respective folder. In my case I made the 64 bit one called android, and the 32 bit one called android32. You can name the folder anything you want.

Step 3: Export the cross compiler.

Again, this would work, except that as stated, the scripts will call for a 32 bit tool-chain version, so if you follow the steps exactly, you will be left unable to build until you either edit the arch/arm64/Makefile on line 83, or declare one from the get-go. I recommend the latter.

$ export CROSS_COMPILE_ARM32=/mnt/719a5453-f8d5-4282-b4d9-f73a127316da/SonyXA2ultraKernel/android32/bin/arm-linux-androideabi-
$ export CROSS_COMPILE=/mnt/719a5453-f8d5-4282-b4d9-f73a127316da/SonyXA2ultraKernel/android/bin/aarch64-linux-android-

Make sure you use your folder names and locations.

Steps 4 through 10 can be done per the SODP instructions.

Overall, it’s only 2 small steps that need a little tweaking, but it’s very difficult to get through it if you don’t know what to do. Hopefully this will help the next guy, and I hope the SODP will keep up their great work!

Linux – keep it simple.

Android 10 on the XA2 Ultra!

Okay, so I’ve been playing around some more with the SODP material and AOSP 10. That’s right, they decided to stop naming Android versions after deserts and just give them numbers. Seems lame to me, but, oh well.

Either way, I did a build of Android 10 with the SODP material, and it is interesting. I’m also using the new 4.14 kernel as well, which is great to keep progressing with newer kernels.

Unfortunately, it’s not quite ready for release yet, it has random crashes and many issues at present, so perhaps I’ll go back and build Android 10 with the 4.9 kernel instead.

Linux – keep it simple.

Fix for MTP/PTP crashes on the XA2 Ultra!

One of the prevailing issues with the SODP build of AOSP was that every time I hooked up my phone to the computer to transfer files, it would cause the phone to crash and reboot. Obviously that is not very productive. I was a bit stumped and decided to join the unofficial SODP telegram group and ask if the developers there had ever seen this issue.

Sure enough, they had. Not only that, but they pointed me to a bug-tacker tool that allowed me to search issues they’ve seen before! It was a huge help! In there, I found a post by a user who had similar problems with another SODP phone. More importantly, there was a helpful response from a developer who pointed out what the issue was, and how to fix it!

It appears that the problem is the buffer size for the file transfer. All one has to do to fix it was make a simple change to the buffer size in

drivers/usb/gadget/function/f_mtp.c

Once you make the edits, then MTP works. He put together a patch, if you don’t want to hand edit them. Here it is:

diff --git a/drivers/usb/gadget/function/f_mtp.c b/drivers/usb/gadget/function/f_mtp.c
index 7692b9d86633..ddf5faedc3c6 100644
--- a/drivers/usb/gadget/function/f_mtp.c
+++ b/drivers/usb/gadget/function/f_mtp.c
@@ -42,8 +42,8 @@
 
 #include "../configfs.h"
 
-#define MTP_RX_BUFFER_INIT_SIZE    1048576
-#define MTP_TX_BUFFER_INIT_SIZE    1048576
+#define MTP_RX_BUFFER_INIT_SIZE    16384
+#define MTP_TX_BUFFER_INIT_SIZE    16384
 #define MTP_BULK_BUFFER_SIZE       16384
 #define INTR_BUFFER_SIZE           28
 #define MAX_INST_NAME_LEN          40

It’s great to have that working properly now! It’s also great to work with a team of really helpful developers, for a change.

Linux – keep it simple.

Fixing Camera issues with SODP/AOSP on the XA2 Ultra

c

Well, last post I was telling you how I started using the SODP material to build AOSP on the XA2 Ultra, and how well it worked. However, there were a few issues. One notable issue was with the camera preview, and how it would look green. The pictures themselves would be fine, but the display would look green while taking them. That obviously would not do.

One thing I came to realize is that the manifest I was using downloaded the 4.9 kernel source, but also a pre-built 4.9 kernel to be used during the build. Once it was deemed stable, they start using the pre-built kernel instead of building them from source while you build Android. This saves time and resources, but isn’t (in my opinion) a good idea.

So, I decided to build the kernel from source myself, instead of using the pre-built one. Long story short, I simply had to delete the kernel/sony/4.9/common-kernel/ folder and all of it’s contents to force the build process to also build the kernel from the already available source code.

Once I did that, not only did it build the 4.9 kernel from source, but, to God be the glory, it also fixed the green camera display issue! So, it looks like some code or another was updated somewhere along the line and the older pre-built kernel did not interact well with that code, or did not take advantage of it…. Either way, I’m quite pleased to have the kernel built from source and the camera working properly!

Linux – keep it simple.

Sony Open Device Project and the Xperia XA2 Ultra….

Now that I’ve built a few ROMs for the XA2 Ultra (AOKP and Resurrection Remix), I’ve turned my attention to the Sony Open Devices Project. The SODP, as it is abbreviated, is an effort to make custom ROMs for various Sony devices that are as open source as possible. This includes reducing the amount of vendor blobs (binary large objects) by replacing them with open source code wherever possible.

While the phones in this program are not 100% vendor blob free, they are dramatically reduced and continue progressing as time goes on and developers continue their work. It’s a great idea with several volunteer and professional staff members (courtesy of Sony), and I am all for it. Here is their statement from their web page linked above:

For some of the Xperia™ devices, we provide Android™ Open Source Project (AOSP) device configurations on GitHub. This means that the software will be open for you as a developer to use and contribute to. This is a way for us to support the open Android community, and it is also a tool for us to facilitate and verify contributions to AOSP.

That said, I’ve started progressing in that direction. I’m not skilled enough to do the helpful work of breaking down blobs and coding an open source alternative, but I’m jumping in by using their material as a base for my ROMs that I build.

One of the greatest advantages I see in using this material is the newer kernels. The XA2 Ultra comes with kernel version 4.4. However, the SODP includes kernels 4.9 and 4.14! Using a newer kernel brings better performance and enhanced security, which is always a plus!

It will be interesting to see what comes of this, how functional the ROMs are, and where I can go from here….

Linux – Keep it simple.