[KERNEL] TonoKrnl for Nexus 7 (2013)

Search This thread

ShadowEO

Senior Member
Mar 15, 2012
493
136
31
Columbus, Ohio
EDIT: I want to remind everyone DO NOT FILE AN UBUNTU BUG REPORT WITH THIS KERNEL INSTALLED, ALWAYS REVERT BACK TO THE STOCK KERNEL IF YOU HAVE AN ISSUE BEFORE FILING

This is my first actual Kernel project, so please be gentle.

This kernel is ONLY for the Nexus 7 (2013) flo. I do not know if it boots on the deb, theoretically it should as I don't have any flo specific options and there are config options for Deb in the Kernel configuration. It should work for those on stable, rc or rc-proposed and may possibly work on devel (not sure) as long as devel has not released a new kernel package (3.4.0-5-flo+)

I have cherry-picked some battery optimizations from bricked-flo, elementalx-flo (4.4 branch) and some additional commits elsewhere in an attempt to not only improve battery-life but also to bring some Android features (DoubleTap2Wake) to Ubuntu Touch.

Currently it has the following:
- ROW I/O scheduler
- Beginnings of OCing (pulled from ElementalX, I think I'm missing some commits to make this relevant though)
- ElementalX's kernel thermal control
- binfmt_misc support
- CD/DVD Filesystem Support for external optical drives (ISO9660/UDF)
- Some Slimbus enhancements
- Battery life optimizations (changing default MHz, etc.)
- Default CPU governor changed from Performance to Interactive (yes, they had it set to Performance, not sure why.)
- Direct Rendering Interface/Direct Rendering Manager (XFree86 + msm_kgsl_drm)
- and more!

You can check my github for the items cherrypicked into it and there is even a current release which has seen my battery drop 4% in the last 30 minutes with the screen fully on (no autolock), WiFi on and Bluetooth.

The name of the kernel is still up for change, TonoKrnl is not going to be it's final name unless everyone likes it.

Repository is at: http://github.com/ShadowEO/TonoKrnl

Releases can be found: https://github.com/ShadowEO/TonoKrnl/releases

Status of Github Repo: It builds. It boots and it runs. I am trying my hardest not to push changes that break building.
 
Last edited:

ShadowEO

Senior Member
Mar 15, 2012
493
136
31
Columbus, Ohio
Reserved for future use. Currently the status of the kernel's updates can be found on the issue tracker: https://github.com/ShadowEO/TonoKrnl/issues/5

Be patient, if you don't see new releases right away, it's because I'm still in the process of generating them, check back later.

-- Release 1.0.3-UBports (11/19/2017): A lot was done to bring this kernel back into usable state, see below:
  1. Added OTG Charging
  2. Added initscripts for turning on features (Requires the rootfs to be mounted read/write for manual installation, see my latest post #16 I think...)
  3. Created patches to be applied against a clean UBports kernel tree for certain features (right now, only DT2W and USB Charging)
(USB Host Charging was pulled from flar2's ElementalX source code, it is not turned on by default and can be turned on with
Code:
echo 1 > /sys/module/msm_otg/parameters/usbhost_charge_mode
Feature is tested and does work.

Developers:
1.0.3 brought the kernel tree back into a buildable state and also cleaned up some problems with the previous releases. I am in the process of generating a kernel patchset which will be able to be applied to a clean kernel to bring those features to the stock UBports kernel source. After I complete generating the kernel patchset, I will be rebasing the entire kernel project onto a clean tree (As I am absolutely certain that I have problems like unfinished cherry-picks [missing commits] etc.). Be patient regarding these patches, as I am re-adding the features I pulled in originally by hand rather than cherry-picking them as I appear to have fuxxed up somewhere cherry-picking previously.


If you have any random reboots, try:
Code:
echo 1 >/sys/module/msm_watchdog/parameters/runtime_disable

If you still receive random reboots afterwards or if you received them previously but the above command fixes them, please open an issue on my project tracker with a copy of /proc/last_kmsg attached.

Kernel TODO:
  • Generate kernel patchset and then rebase onto clean kernel tree
  • Finish Kernel Feature Documentation and publish (these docs will give information on tweaking the changes to the kernel, such as readahead buffer, turning on/off DT2W, turning on/off usbhost charging, etc.)
  • Move TonoKrnl initscripts into ramdisk, should make them more robust and reliable.
  • Create ZIP installer for TWRP recoveries (this is needed for automatic installation of kernel modules, since /lib/modules is a read-only, bound mountpoint for the Android LXC container. To fix this, we just have to move /lib/modules out of the Android container.
 
Last edited:

doniks

Senior Member
Jul 15, 2014
70
12
Sony Xperia 10 III
Allow me two questions:

Which kernel repository is this branched off? Apologies if that is dumb question, my git and kernel knowledge is cursory at best, but I can't seem to figure this out looking through your github repo.

- Direct Rendering Interface/Direct Rendering Manager (XFree86 + msm_kgsl_drm)

What's the intention behind this? Does this have anything to do with enabling the freedreno driver for the GPU and would that pave a way to a setup without Mir, but with wayland or X?
 

ShadowEO

Senior Member
Mar 15, 2012
493
136
31
Columbus, Ohio
Allow me two questions:

Which kernel repository is this branched off? Apologies if that is dumb question, my git and kernel knowledge is cursory at best, but I can't seem to figure this out looking through your github repo.



What's the intention behind this? Does this have anything to do with enabling the freedreno driver for the GPU and would that pave a way to a setup without Mir, but with wayland or X?

This started off with the debian source package for linux-image-flo in the Ubuntu archives which is the kernel for our device. The reason you are having trouble with figuring it out is because I started with the base (Ubuntu's 3.4.0-5-flo+), pulled it into an empty git repo and then started cherry-picking features. It was originally going to be for my own personal consumption as I didn't know how well a custom kernel would be received by the touch community (so far, in all the communities I've posted it, you were the only one to ask any questions :D), but since I already had a git repo up, figured that I may as well share it. So here I am, an amateur working on the Linux kernel, and learning a lot.

My full intent was to improve the experience (even marginally) on Ubuntu Touch for the Nexus 7 2013, I wanted to bring the mobile kernel features previously found on the desktop that myself or others may find useful (hence binfmt support for qemu-user), there really is no reason for me to turn on DRI/DRM except to allow playing with Wayland and X, yes, that part is correct, and I have tested the freedreno driver with it (Freedreno does get the KGSL DRI device and does start X)

In addition I found some interesting choices in the kernel in terms of battery life, it would seem that the CPU governor used by the default Ubuntu Kernel is Performance, which would explain why the battery dies so fast, I tried to pull in some battery optimizations from a couple other kernels around the Android scene for the device. So far I'm pleased with the results, and recently found that both the original cherry-picking done for DT2W worked along with the code to add fast charging.

I've had to put the project on hold due to work issues, but once I'm able to work on it again, I'm reverting the last 100 changes pulled in that broke my tree and going from there since my original targets in terms of features actually worked. (I'm pretty sure it was some recent changes to the CPU hotplug driver that killed it, I can no longer compile the kernel without mpdecision on, so that's my likely suspect.)
 
  • Like
Reactions: doniks

doniks

Senior Member
Jul 15, 2014
70
12
Sony Xperia 10 III
Thanks for your explanations!

This started off with the debian source package for linux-image-flo in the Ubuntu archives which is the kernel for our device.

So something like apt source linux-image-flo? And then to build you use the instructions in the package also?

there really is no reason for me to turn on DRI/DRM except to allow playing with Wayland and X, yes, that part is correct, and I have tested the freedreno driver with it (Freedreno does get the KGSL DRI device and does start X)
Exciting!

In addition I found some interesting choices in the kernel in terms of battery life, it would seem that the CPU governor used by the default Ubuntu Kernel is Performance, which would explain why the battery dies so fast
I'm really only speculating, but my conjecture to previous mentions of odd govenor choices in android kernels was that the actual android power management magic is happening behind the backs of the governors. But, I'm really just babbling. I don't know much of anything about this. You seem to be getting impressive improvements!

I'm reverting the last 100 changes pulled in that broke my tree and going from there since my original targets in terms of features actually worked.
So, that means: "If you want to try it now, don't use v1.0.2, but use v1.0.2-alpha for now." Is that about correct?
 

ShadowEO

Senior Member
Mar 15, 2012
493
136
31
Columbus, Ohio
Thanks for your explanations!



So something like apt source linux-image-flo? And then to build you use the instructions in the package also?


there really is no reason for me to turn on DRI/DRM except to allow playing with Wayland and X, yes, that part is correct, and I have tested the freedreno driver with it (Freedreno does get the KGSL DRI device and does start X) Exciting!


In addition I found some interesting choices in the kernel in terms of battery life, it would seem that the CPU governor used by the default Ubuntu Kernel is Performance, which would explain why the battery dies so fast
I'm really only speculating, but my conjecture to previous mentions of odd govenor choices in android kernels was that the actual android power management magic is happening behind the backs of the governors. But, I'm really just babbling. I don't know much of anything about this. You seem to be getting impressive improvements!


I'm reverting the last 100 changes pulled in that broke my tree and going from there since my original targets in terms of features actually worked. So, that means: "If you want to try it now, don't use v1.0.2, but use v1.0.2-alpha for now." Is that about correct?

I removed the problem download, the only ones available are the source tree downloads and the last known good build I had, I have also tested to ensure that the last build up there works as well as it's the one I'm running on my device until I have time to go through the tree again.

As for building, essentially yes, but you have to build the image separately. Due to how Ubuntu currently has the filesystem set up and with Android's boot images, its not feasible to really package it in a traditional sense. Essentially what I did was create a chroot, apt-get source linux-image-flo and then to get a working defconfig I used the config.* files found in Debian.flo and Debian.master, from there was the tree that I used as my base.

Then run make with the following to customize:
Code:
ARCH=arm make menuconfig
ARCH=arm make -j <number of processors>

To build the image, you'll need to grab the boot image from your device and tear it apart using a abootimg them rebuild it with the Ubuntu ramdisk. If you are using MultiROM, you can just drop it in the folder for your ROM.

Edit: As for the weird choice of governors, I noticed during my investigations (via the cpufreq-info package) that while Android is managing the CPUs that are online (I found it's running it's own version of mpdecision behind the scenes inside the LXC container), it's not doing anything to the CPU governor. That's all managed in the kernel right now through CPUFreq it appears and in the stock kernel it's set to performance, as for the reason for it, I'm not sure myself.. The other governors ARE there though, just unused right now.
 
Last edited:
  • Like
Reactions: doniks

doniks

Senior Member
Jul 15, 2014
70
12
Sony Xperia 10 III
This kernel is ONLY for the Nexus 7 (2013) flo. I do not know if it boots on the deb, theoretically it should as I don't have any flo specific options and there are config options for Deb in the Kernel configuration.

Jup, it does boot on my deb! I've downloaded the .img, put the tablet in bootloader mode and did
fastboot boot TonoKrnl-1.0.2-flo.img

It booted without problems, and so far it's running for about half an hour or so without any problems. Wifi, sound, video, usb mouse, all work fine.
 

Attachments

  • tono.png
    tono.png
    249.5 KB · Views: 87
  • Like
Reactions: ShadowEO

ShadowEO

Senior Member
Mar 15, 2012
493
136
31
Columbus, Ohio
Jup, it does boot on my deb! I've downloaded the .img, put the tablet in bootloader mode and did
fastboot boot TonoKrnl-1.0.2-flo.img

It booted without problems, and so far it's running for about half an hour or so without any problems. Wifi, sound, video, usb mouse, all work fine.


Wow, that's great to hear, I wasn't sure but I was definitely curious since I had seen options for both Deb and Flo in the makeconfig page.

If you can script it in (or edit sysfs.conf) to have it write a 1 to /sys/android_touch/doubletap2wake while it's booting, you can have working DT2W and there's quite some others to mess around with under /sys :3 CPU governors are somewhere there too, just don't have it offhand.

Since you are testing it out, have you noticed any changes in the device's normal battery life? The stock kernel seems to drain 1% every 1 1/2 minutes on my Flo, not doubting that the power optimizations ARE working (I know I'm getting much better life), I'm just wanting to ensure that it's not a placebo effect that I'm experiencing.
 

doniks

Senior Member
Jul 15, 2014
70
12
Sony Xperia 10 III
If you can script it in (or edit sysfs.conf) to have it write a 1 to /sys/android_touch/doubletap2wake while it's booting, you can have working DT2W
After
Code:
echo 1 | sudo tee /sys/android_touch/doubletap2wake
I can indeed (sometimes) wake it with double tapping. I have since quite a while (with the standard kernel) the situation that its really hard to wake up. I have to press the powerbutton many many times. Feels like it is sleeping really deeply.

Since you are testing it out, have you noticed any changes in the device's normal battery life? The stock kernel seems to drain 1% every 1 1/2 minutes on my Flo, not doubting that the power optimizations ARE working (I know I'm getting much better life), I'm just wanting to ensure that it's not a placebo effect that I'm experiencing.

Well, I haven't noticed anything. I might just not be in the best position to judge. I rarely have it unplugged for more than a couple of hours at a time and I don't generally monitor the battery status closely. That being said though, I have very definitely never experienced anything remotely close to 1% per 1.5 min!

If you have a particular test/measurement you'd like to see - let me know.
 

ShadowEO

Senior Member
Mar 15, 2012
493
136
31
Columbus, Ohio
After
Code:
echo 1 | sudo tee /sys/android_touch/doubletap2wake
I can indeed (sometimes) wake it with double tapping. I have since quite a while (with the standard kernel) the situation that its really hard to wake up. I have to press the powerbutton many many times. Feels like it is sleeping really deeply.



Well, I haven't noticed anything. I might just not be in the best position to judge. I rarely have it unplugged for more than a couple of hours at a time and I don't generally monitor the battery status closely. That being said though, I have very definitely never experienced anything remotely close to 1% per 1.5 min!

If you have a particular test/measurement you'd like to see - let me know.

I may be exaggerating slightly, but normally my tablet goes from 100% to 95% in about 5 minutes while I'm using it after taking it off the charger (in Ubuntu only, may be an rc-proposed thing too). I haven't seen that behavior since changing kernels. I'm gonna see if I can go ahead and start reverting commits today or possibly reset back to the last known good commit.

As for the screen problems, I think there is a bug in the current doubletap2wake driver, if you look at dmesg after using DT2W for a while, you'll see it being spammed with error messages from the touchscreen driver.

That could possibly be related. Additionally, I think the minimum processor speed defaulted to 384MHz (I didn't touch any processor clock speeds in here) which the Performance governor would never had let the processor hit. So it's likely that the minimum processor speed will need bumped up at least one step there, I get some stuttery behavior on the command line when the screen is off which I hadn't received on the stock kernel.

Edit (07/01/16): I'm not sure what else I can really bring to the table here, mpdecision running in the android LXC container defeats any meaningful changes to the clock speed. I also noticed mention that you shouldn't have two hotplugging daemons running at the same time, effectively that is what the new developments would've brought in. I think my best option to continue this would be to wait until the Xenial transition and see if they make any changes for me to update on.

I'm also quite a novice, so besides cherry picking commits, I'm not sure what else I can do.
 
Last edited:

doniks

Senior Member
Jul 15, 2014
70
12
Sony Xperia 10 III
ShadowEO, is bluetooth working on your device? With your kernel or with the one from Canonical?

I can't seem to get anything at all to show up on my deb.
 

ShadowEO

Senior Member
Mar 15, 2012
493
136
31
Columbus, Ohio
I am so embarrassed that I didn't check this thread in so long. Ya, Bluetooth still works on my device with either kernel. Sometimes it doesn't seem to like to power on, so if you are having trouble, try this.

Open Terminal,
do sudo bluetoothctl and see if Nexus 7 (2013) shows up in there. If it does, type power on and hit enter. You should see the bluetooth indicator show up in the status bar. If it doesn't, exit bluetoothctl and do these from a root prompt:

start bluetooth-touch
start bluetooth-touch-flo

Sometimes the commands may take a little bit of time (no idea why honestly), but after those, you should see bluetooth start. At that point, if you still don't, fully power the device down and try again.

For whatever reason, the bluetooth scripts fail every so often, haven't been able to look into it much due to personal things IRL taking up all my time the last few months.
 

ShadowEO

Senior Member
Mar 15, 2012
493
136
31
Columbus, Ohio
It's been a long while since I touched this project, but I have finally cleaned up the kernel source tree and ensured that it builds properly!

Two features that must remain disabled however are GOVERNOR_ELEMENTALX and MSM_SLEEPER as they are currently broken and do not function as of right now. The defconfig for flo also has sane defaults for the UBports Ubuntu Touch distribution (installable via the UBports installer application) and has DT2W enabled (but not turned on, that requires some extra work) by default.

You should also no longer need to disable the MSM watchdog using the instructions in the OP, running the kernel now and haven't experienced near as many random reboots I used to with the previous version! (I wonder if that was a UTouch problem, because I DO get random reboots sometimes using certain apps, but they're very rare... Then again, I'm not sure if UBports made any initramfs changes for the Flo when they added it to their system-image server, which they may have, since it's in the ubports-touch/15.04 distribution instead of their ubuntu-touch mirror for older, no-longer supported devices)

To turn on DT2W, you must follow the instructions on the github page for the 1.0.2 release.

NOTE: I highly recommend building the kernel from source rather than downloading a release! I have yet to add the current stable release to the github releases page! I also have a zip file with some helper scripts and configuration that can be installed into the UBports rootfs to turn DT2W and Kernel Samepage Merging on at startup. In case that's useful, I'm adding the zip to this post. To install, simply remount your root as read/write, extract the ZIP to / and then "chmod +x /sbin/tonokrnl-init" and reboot. Upon reaching the lightdm greeter, you should be able to shut the screen off, then double tap it to wake.

The files contained in the zip are:
  • /sbin/tonokrnl-init - Helper Script to start DT2W and KSM
  • /etc/sudoers/tonokrnl - Allows the user-session upstart config to run the helper script, which requires root.
  • /home/phablet/.config/upstart/tonokrnl.conf - Upstart configuration to run /sbin/tonokrnl-init using sudo (requires the sudoers file)

Off-topic slightly: The reason this project got set aside, was due to my IRL work, and because I had stopped using Ubuntu Touch and was testing out other ways of getting Linux onto the N7 'flo'. I messed with the Sailfish distribution found in the Nexus 7 2013 forum, then went to postmarketOS and messed with that (it's cool, but rather bare, not enough desktop packages to make it useful [no osk, etc]), then attempted to boot a debian distribution with the Linaro mainline kernel from John Stultz (couldn't even get X11 to start, the system did boot though! Perhaps mesa/libdrm needed recompiling with freedreno support...) and then finally came back to Ubuntu Touch via UBports!

Back on Topic, if you decide to use this kernel (either by building it yourself, or using the new UBports-1.0.3 release that will go up soon!) and install the attached helper scripts (or even find your own solution to on-boot DT2W, KSM, and the Interactive governor) please let me know your experiences! I noticed after turning KSM on that the web browser didn't crash as much, but I'm not sure if it's a placebo effect or not.

(I wonder if @flar2 has a 3.4.0 patchset I can apply rather than attempting to cherry-pick ElementalX into the kernel... That would be amazing to have ElementalX's additions to the kernel under Ubuntu Touch. [Please don't be angry I used a mention flar, I just wanted to ask if you had a patchset for the flo's kernel [version 3.4.0])
 

Attachments

  • tonokrnl-init.zip
    1.6 KB · Views: 16
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    Allow me two questions:

    Which kernel repository is this branched off? Apologies if that is dumb question, my git and kernel knowledge is cursory at best, but I can't seem to figure this out looking through your github repo.



    What's the intention behind this? Does this have anything to do with enabling the freedreno driver for the GPU and would that pave a way to a setup without Mir, but with wayland or X?

    This started off with the debian source package for linux-image-flo in the Ubuntu archives which is the kernel for our device. The reason you are having trouble with figuring it out is because I started with the base (Ubuntu's 3.4.0-5-flo+), pulled it into an empty git repo and then started cherry-picking features. It was originally going to be for my own personal consumption as I didn't know how well a custom kernel would be received by the touch community (so far, in all the communities I've posted it, you were the only one to ask any questions :D), but since I already had a git repo up, figured that I may as well share it. So here I am, an amateur working on the Linux kernel, and learning a lot.

    My full intent was to improve the experience (even marginally) on Ubuntu Touch for the Nexus 7 2013, I wanted to bring the mobile kernel features previously found on the desktop that myself or others may find useful (hence binfmt support for qemu-user), there really is no reason for me to turn on DRI/DRM except to allow playing with Wayland and X, yes, that part is correct, and I have tested the freedreno driver with it (Freedreno does get the KGSL DRI device and does start X)

    In addition I found some interesting choices in the kernel in terms of battery life, it would seem that the CPU governor used by the default Ubuntu Kernel is Performance, which would explain why the battery dies so fast, I tried to pull in some battery optimizations from a couple other kernels around the Android scene for the device. So far I'm pleased with the results, and recently found that both the original cherry-picking done for DT2W worked along with the code to add fast charging.

    I've had to put the project on hold due to work issues, but once I'm able to work on it again, I'm reverting the last 100 changes pulled in that broke my tree and going from there since my original targets in terms of features actually worked. (I'm pretty sure it was some recent changes to the CPU hotplug driver that killed it, I can no longer compile the kernel without mpdecision on, so that's my likely suspect.)
    1
    Thanks for your explanations!



    So something like apt source linux-image-flo? And then to build you use the instructions in the package also?


    there really is no reason for me to turn on DRI/DRM except to allow playing with Wayland and X, yes, that part is correct, and I have tested the freedreno driver with it (Freedreno does get the KGSL DRI device and does start X) Exciting!


    In addition I found some interesting choices in the kernel in terms of battery life, it would seem that the CPU governor used by the default Ubuntu Kernel is Performance, which would explain why the battery dies so fast
    I'm really only speculating, but my conjecture to previous mentions of odd govenor choices in android kernels was that the actual android power management magic is happening behind the backs of the governors. But, I'm really just babbling. I don't know much of anything about this. You seem to be getting impressive improvements!


    I'm reverting the last 100 changes pulled in that broke my tree and going from there since my original targets in terms of features actually worked. So, that means: "If you want to try it now, don't use v1.0.2, but use v1.0.2-alpha for now." Is that about correct?

    I removed the problem download, the only ones available are the source tree downloads and the last known good build I had, I have also tested to ensure that the last build up there works as well as it's the one I'm running on my device until I have time to go through the tree again.

    As for building, essentially yes, but you have to build the image separately. Due to how Ubuntu currently has the filesystem set up and with Android's boot images, its not feasible to really package it in a traditional sense. Essentially what I did was create a chroot, apt-get source linux-image-flo and then to get a working defconfig I used the config.* files found in Debian.flo and Debian.master, from there was the tree that I used as my base.

    Then run make with the following to customize:
    Code:
    ARCH=arm make menuconfig
    ARCH=arm make -j <number of processors>

    To build the image, you'll need to grab the boot image from your device and tear it apart using a abootimg them rebuild it with the Ubuntu ramdisk. If you are using MultiROM, you can just drop it in the folder for your ROM.

    Edit: As for the weird choice of governors, I noticed during my investigations (via the cpufreq-info package) that while Android is managing the CPUs that are online (I found it's running it's own version of mpdecision behind the scenes inside the LXC container), it's not doing anything to the CPU governor. That's all managed in the kernel right now through CPUFreq it appears and in the stock kernel it's set to performance, as for the reason for it, I'm not sure myself.. The other governors ARE there though, just unused right now.
    1
    This kernel is ONLY for the Nexus 7 (2013) flo. I do not know if it boots on the deb, theoretically it should as I don't have any flo specific options and there are config options for Deb in the Kernel configuration.

    Jup, it does boot on my deb! I've downloaded the .img, put the tablet in bootloader mode and did
    fastboot boot TonoKrnl-1.0.2-flo.img

    It booted without problems, and so far it's running for about half an hour or so without any problems. Wifi, sound, video, usb mouse, all work fine.