yashsingh1/xdaforums huggingface dataset:
[MeMO Pad 7 Original Android Development] lambdadroid:
Status update

Bluetooth / Battery optimization / Thermal issues

I'm kind of stuck here. All of them are quite complex and right now I'm unsure how to make them work.

Bluetooth just refuses to work, for some reason the Bluetooth chip in the tablet is just unwilling to communicate with the newer kernel version. I'm not sure why the tablet is heating up so quickly and why the thermal daemon is not successful in cooling down the tablet (causing the sound issues). Battery optimization is just extremely weird, for some weird reason (there is no log), the tablet seems to freeze every time I send it into suspend. Eventually, these are all kernel issues and the easiest way to solve them is to wait until I can do a kernel upgrade. Unfortunately, that is at least an half year from now.

I've therefore decided to put these issues aside for a while. If these problems are causing major issues, you may want to go back to the original ASUS system (either Lollipop or KitKat). Otherwise, I believe the ROM is working well for occasional usage (at least it is for me). I would also gladly accept contributions if someone else wants to invest time to improve this ROM. I would be happy to assist with instructions and/or explanations how parts of this ROM are working, too.

Near future

I've mentioned this in the description of the ROM but I'll mention it here again, for me the ROM is mostly a research project to learn about kernel development and how Android works internally. I've already learned a lot and I intend to continue that. Until now I've spent most of the time working around problems with the upstream driver that were caused by ASUS when they designed this tablet. Instead of fixing the hardware they usually just hacked workarounds into the kernel, which were obviously missing when I started porting the newer Linux kernel to this device. Debugging for hours (or even days) like I did back then in order to get the touchscreen, USB and audio working is not something I want to repeat right now. It was a great crash course to kernel development, but I want to change my focus to new things (like porting the ROM to Android Oreo).

I'm open to fix other issues or to add other features to the ROM (I enjoyed writing the driver for the smart cover for example). Since I personally value security I will try to provide security updates each month for LineageOS 14.1, at least until we can switch to LineageOS 15.0. I'm currently working on porting things over to Android 8.0.0 Oreo, and I may release an AOSP test build if I can get the majority of features working (it's already booting, but WiFi etc isn't working yet).
[MeMO Pad 7 Original Android Development] NahuelMS:
Ohhhhh, i am really sad. I understand your point anyway, i was just hoping that you can find what is wrong with these 3 things as you do so much! There is no one with knowlegde willing to help lamdadroid to fix the issues :(?

If you manage to port AOSP Oreo it will have the same issues rigth?
[MeMO Pad 7 Original Android Development] lambdadroid:
Correct. Don't get me wrong, I did not give up. I just won't have a solution within the next few months.
[MeMO Pad 7 Original Android Development] NahuelMS:
Did you try to search how the others lineage or AOSP x86 android builds manage to get the device to sleept properly, etc? The Asus rom on kitkat was sleeping ok, it is not posible to look there for help?Maybe someone has steped with the same problems and managed to get a fix? Sory if what i am talking is dumb i don't know much about rom development.
[MeMO Pad 7 Original Android Development] Ruben Craveiro:
i might try to help, but i cant currently since im in switzerland and didnt brought my tablet, but once im back, ill try to help and from the future fork ill make, if im successfull in fixing any issues ill send to your github for review so that you can merge it later on.
[MeMO Pad 7 Original Android Development] lambdadroid:
It's not that easy. I'm not aware of any other ROM where someone used a completely new kernel. All the other x86 ROMs are using the original kernel as shipped with the device, which would allow sleeping with less problems. There have been a lot of changes since then, so it's not easy to port this to the newer kernel.

There are some people (especially from Android x86) who are working on getting suspend working, but this is still a work in progress and mostly involves newer upstream kernels which is exactly the reason why I'm delaying it for a while.
[MeMO Pad 7 Original Android Development] lambdadroid:
Thanks, let me know if you need any help to get started.
[MeMO Pad 7 Original Android Development] youling257:
suspend to idle no any problem on Android x86，my 4.9 kernel suspend successful on my z3735f device has three months，my kernel also tested on others BYTCR，you impossible understand what my did，i port a lot of BYT/BYTCR/CHTBSW patches to 4.9 kernel，github.com/youling257/android-4.9

in fact，4.11 kernel include Hans patches，suspend to idle no problem on Ubuntu，since April begin.

https://github.com/burzumishi/linux-baytrail-flexx10/issues/12#issuecomment-295433542

https://github.com/burzumishi/linux-baytrail-flexx10/issues/12#issuecomment-295812054

https://github.com/burzumishi/linux-baytrail-flexx10/issues/12#issuecomment-296213670

Z3740 dell venue pro 8

http://www.studioteabag.com/science/dell-venue-pro-linux/

http://www.studioteabag.com/science/dell-venue-pro-linux/screenshots/desktop_enlightenment_412.jpg

Now testing 4.12. I can confirm suspend work as does hibernation, Audio continues to work, Desktop with touch input resumes just fine. RTC vs uSD slot bug is fixed. i2C has had love as the IIO sensors stay present regardless of cold or warm boot. Now to see how well it all works!

android_x86:/ $ su

android_x86:/ # cat /sys/power/mem_sleep

[s2idle]

android_x86:/ #

you need waiting next lts 4.14 kernel，will be better for BYT/BYTCR/CHTBSW，4.14 coming soon.
[MeMO Pad 7 Original Android Development] lambdadroid:
Getting into suspend is nice, but the actual question is if you manage to reach the low power S0i3 state that is required to properly save power when you're in suspend. Certain preconditions are required to reach it (it's not documented too well) and reaching suspend to idle does not mean it's automatically triggered.

You can check this in /sys/kernel/debug/pmc_atom/sleep_state if you have CONFIG_PMC_ATOM enabled in your kernel.
[MeMO Pad 7 Original Android Development] youling257:
you said sys/kernel/debug/pmc_atom/sleep_state is Android ia，ProductionKernelQuilts-master cht-m1stable patches pmc，i talk with you upstream Linux kernel and Androidx86 libsuspend.

android_x86:/ $ su

android_x86:/ # cat sys/kernel/debug/pmc_atom/sleep_state

S0IR Residency: 0us

S0I1 Residency: 0us

S0I2 Residency: 0us

S0I3 Residency: 0us

S0 Residency: 42269588576us

android_x86:/ #
[MeMO Pad 7 Original Android Development] lambdadroid:
No, /sys/kernel/debug/pmc_atom/sleep_state is available in the upstream kernel. See https://github.com/torvalds/linux/blob/master/drivers/platform/x86/pmc_atom.c#L407
[MeMO Pad 7 Original Android Development] youling257:
if you say it，i known it of course，https://github.com/youling257/android-4.9/commits/update/drivers/platform/x86/pmc_atom.c

https://github.com/torvalds/linux/commits/master/drivers/platform/x86/pmc_atom.c
[MeMO Pad 7 Original Android Development] lambdadroid:
As you can see, you did not reach the S0i3 state. This means that it's either not supported by your system (but then it should really support suspend to RAM), or one of the preconditions weren't met. I've read some posts that indicate that all devices in the North and South complex must be suspended for S0i3 to be triggered but there is no specific explanation how to make it work. Suspend in S0 will save a bit of power, but not as much as if you are in S0I3.
[MeMO Pad 7 Original Android Development] youling257:
so even you use 4.14 kernel，it still suspend to idle

https://www.dpin.de/nf/baytrail-suspend-s3-vs-s0i3/

In Linux if you look at the possible suspend states you will see this (on the TPT10):

# cat /sys/power/state

freeze disk

dell venue 8 and ThinkPad 10 can suspend to disk.
[MeMO Pad 7 Original Android Development] lambdadroid:
I've read that post before and there is a follow-up article there as well: https://www.dpin.de/nf/intel-s0ix-intel_idle-not-supported/

It suggests that it might be a problem in intel_idle, but this is not something I can confirm. I've checked the intel_idle driver from ASUS and could not find any differences that would help. I believe the reason we don't reach S0I3 is that some component isn't properly suspended by the kernel (e.g. due to a missing driver or due to incomplete suspend implementation for one of the drivers).
[MeMO Pad 7 Original Android Development] lambdadroid:
Oreo Status Update

I managed to get almost everything working that is working on LineageOS 14.1 (see below), except for hardware accelerated video decoding (which means we will have even more heat when watching videos, yay!). I'm unsure how to fix that right now but I'm convinced I will find a solution. AOSP seems quite unstable currently, I had quite a few crashes when opening certain menu in the settings and even when using the keyboard. I'm quite sure these are not caused by me. Open GApps isn't available yet either so I might wait at least until that is available and maybe until the base of LineageOS is updated too (they're already working on it). In any case, the device is now prepared for Oreo!

Tested and now working on Oreo:

Graphics

WiFi

Sound

Sensors

Backlight control

SD card

Currently incompatible:

Hardware accelerated video decoding
[MeMO Pad 7 Original Android Development] lambdadroid:
Oreo Status Update (2)

I tried a workaround for the hardware accelerated video codecs and it fixed the original problem; however it's still not working for some reason (with really weird errors). Since this is pretty much the only proprietary component (except firmware) in this ROM, I have no way to investigate further. However, according to Android-IA they will update to Android Oreo soon™, so it should be just a matter of time until we can fix it.

AOSP is quite unstable and I don't want to spent too much time replacing the horrible browser, music and gallery app if we're going to switch back to LineageOS later anyway. I'm going to wait with a first build until LineageOS 15.0 is in a semi-stable build. However, if you'd like to test Android Oreo anyway, together with its many crashes and horrible apps, you can send me a private message. I can send you a build together with instructions how to install them. I won't fix any bugs in AOSP though, and there is honestly not much you can do with Oreo currently. LineageOS 14.1 is much nicer until most of the issues have been sorted out.
[MeMO Pad 7 Original Android Development] lambdadroid:
Can someone with a ME176CX (NOT a ME176C) and root run this command for me on LineageOS 14.1. I'm trying to figure out if there is any difference in the BIOS between the ME176C and the ME176CX. I have the ME176C so I just need the same from the ME176CX.

Open a terminal using ADB shell.

Make sure you are running as root. (Run su)

Run the following command:

mkdir -p /data/acpi && for table in /sys/firmware/acpi/tables/*; do [[ -d $table ]] || cat $table > /data/acpi/$(basename $table).dat; done && zip -r /sdcard/acpi.zip /data/acpi

Get /sdcard/acpi.zip from your device (e.g. using adb pull /sdcard/acpi.zip)

Upload acpi.zip somewhere so I can download it.
[MeMO Pad 7 Original Android Development] Nexive:
I have a me176cx, I will try it when I'm home. :)
[MeMO Pad 7 Original Android Development] jerbear294:
I have done this, however my tablet's bootloader is a bit out of date (versioned as WW_K013-12.10.1.24).

If this doesn't matter (if the UEFI itself wasn't actually updated) I can go ahead and upload the resulting acpi.zip.
[MeMO Pad 7 Original Android Development] lambdadroid:
Sure, I'll just compare it with the one [MENTION=4491111]Nexive[/MENTION] is going to upload and then we'll see if there are any differences. Is there a special reason why you haven't updated it?
[MeMO Pad 7 Original Android Development] jerbear294:
Back when ASUS was updating the tablet regularly, systemless root wasn't really a thing, so installing SuperSU compromised the integrity of the stock ROM, and as such the update would fail. Rather than reflashing a full stock ROM every time there was an update, I updated from .24 to .33 (and subsequently to .36) using Nandroids taken from my brother's ME176CX via tethered TWRP, which didn't update the bootloader. I haven't since tried manually updating to the .36 bootloader because I don't know how safe it would be.

Sadly my brother's tablet is broken and as such I can't compare the UEFI myself.

I have attached the acpi.zip from my tablet to this post.
[MeMO Pad 7 Original Android Development] lambdadroid:
I've recently installed the stock package again for testing and it worked without any issues. If you want to do the update (but I doubt it's worth it), I'd suggest that you only install it after restoring most of the original system. What I did is the following:

Restore the original bootloader. The tablet then automatically booted into Fastboot due to the invalid boot partition.

Start the temp recovery session with that ancient TWRP version. Wipe everything and install the original stock package from http://dlcdnet.asus.com/pub/ASUS/EeePAD/ME176C/UL-K013-WW-12.10.1.36-user.zip

After the reboot, it will do that weird UEFI update that is really creepy (and hopefully it will succeed).
[MeMO Pad 7 Original Android Development] Nexive:
Here is the zip file :)

https://www.dropbox.com/s/7oahpkmj5lq9k6w/acpi.zip?dl=0
[MeMO Pad 7 Original Android Development] jerbear294:
A recursive md5sum between my files and Nexive's show that the files DSDT.dat, FACP.dat, PIDV.dat, and RSCI.dat differ between the two revisions.
[MeMO Pad 7 Original Android Development] lambdadroid:
[MENTION=5479482]jerbear294[/MENTION] [MENTION=4491111]Nexive[/MENTION]

Thanks again for sending the files.

I'm mostly looking at DSDT.dat because that's where the hardware components (e.g. WiFi chip, sound, etc etc) are defined. I'm not sure what's the purpose of the other tables. A closer look at the differences in DSDT.dat shows that they're basically the same on all 3 devices. The only difference is some kind of system memory pointer, which is different on all 3 devices. I suspect that this is different for each device, but I'm not sure.

The configuration for the hardware components is identical for both devices, so the different camera modules seem to be handled elsewhere (probably hacked right into the kernel, meh). Not that I care about getting the camera working, that's not going to happen. DSDT.dat is where ASUS made tons of mistakes and fixed them using hacks in the kernel instead of updating the BIOS. Until now, for most components (e.g. touchscreen, USB, sound, ...) I managed to workaround these problems in the kernel, but this is difficult for something else I'm working on right now. Now that I know that they're mostly equal for both device types I might be able to override the broken version by ASUS with a fixed one (the Linux kernel has a special feature for this).

Anyway, thanks again for now. Will report later when I get something working.
[MeMO Pad 7 Original Android Development] jerbear294:
For what it's worth, when I manually updated past .24 my camera and Bluetooth ceased to function, but I didn't care enough about those two features to try and fix it.

If the DSDT.dat is different between every device, I suppose that would explain why they stopped working.
[MeMO Pad 7 Original Android Development] lambdadroid:
I don't think that this value affects any hardware components. It might be some other problem that caused Bluetooth and Camera to malfunction.
[MeMO Pad 7 Original Android Development] lambdadroid:
OK, I've spent the last few days finding a solution to reduce the number of kernel hacks required to make things work on our tablet. Since the BIOS configuration (or more accurately: the ACPI tables) seem to be equal on ME176C/ME176CX despite the different camera sensors I now override the part of the configuration that describes how to interact with the hardware components (e.g. touchscreen, USB, sound, ...). That allows me to fix the mistakes ASUS has made directly instead of having to work around them with hacks in the kernel. I was able to remove the majority of my kernel hacks.

So far everything is working great on my device, but overriding the configuration like I do now can potentially break a lot of things, so I'd appreciate if someone else could take the time and test if it's working properly.

Checklist:

Device boots

Touchscreen, USB (e.g. ADB), WiFi, Sound, and Headphone detection is working

Upload a copy of the kernel log. The command below writes the kernel log to a file called "dmesg.txt".

adb shell dmesg > dmesg.txt

Installation instructions:

Only do this if you know what you're doing!

Download the attached ZIP and unpack it.

Use ADB or a root explorer to copy new files. (Note: The location for the kernel modules was changed and is now at /system/vendor/lib/modules/, the old version has them at /system/lib/modules. Make sure you copy it to the new location. You can keep the old modules in /system/lib/modules, they will be deleted with the next full update.)

me176c-audio.rc, me176c-wifi.rc -> /system/etc/init/
modules/* -> /system/vendor/lib/modules/

Flash the new boot partition, either using Fastboot or using dd.

fastboot flash boot boot.img

adb push boot.img /sdcard/
dd if=/sdcard/boot.img of=/dev/block/by-name/boot

Reboot the device and test the checklist above.

Thanks! :)
[MeMO Pad 7 Original Android Development] Nexive:
Replaced the files to the correct location and flashed the boot.img via TWRP. Device booted but wifi, sound (and headphone detection) doesn't work now.

Can't post the log because I have no PC at the moment to upload the log file. Will post it when I have a PC.
[MeMO Pad 7 Original Android Development] lambdadroid:
Weird. Looking forward to the log file. It sounds a lot like it's either not using the correct kernel or not the correct kernel modules, because WiFi, Sound (and headphone detection) are kernel modules, while touchscreen and USB are directly included in boot.img.
[MeMO Pad 7 Original Android Development] Nexive:
Did a clean install and tried it again but still the same.

Touchscreen and ADB works but WiFi and sound doesn't.

Kernel build date in settings is 3 september.

I ran the command for the kernel log but I got this:

/system/bin/sh: can't create dmesg.txt: Read-only file system
[MeMO Pad 7 Original Android Development] lambdadroid:
You need to run "adb shell dmesg" in one command not separately. If you want to do it separately, you need to do it like this:

adb shell
dmesg > /sdcard/dmesg.txt
exit
adb pull /sdcard/dmesg.txt
[MeMO Pad 7 Original Android Development] Nexive:
Got the log, thanks!

View attachment dmesg.txt
[MeMO Pad 7 Original Android Development] lambdadroid:
Now that's weird. It seems like the kernel modules aren't loaded at all. It doesn't even attempt to load them. Are you sure you copied the two *.rc files to /system/etc/init/ correctly?
[MeMO Pad 7 Original Android Development] Nexive:
Yes, they are in the right directory. (/system/etc/init/)

What are the right permissions for these files? (It shows rw-rx-rx)
[MeMO Pad 7 Original Android Development] lambdadroid:
It's probably not worth investigating this for hours to figure out if all files are correct, so let me just upload a full build. Can you make a backup of your data and then do a factory reset? The full build is a developer build so your existing data is not compatible with it.
[MeMO Pad 7 Original Android Development] lambdadroid:
[MENTION=4491111]Nexive[/MENTION]

Here's the build: https://drive.google.com/uc?id=0BwH-OucNx9gBVGNUWThuSVBpaVU&export=download

Make sure you do a factory reset before flashing it.
[MeMO Pad 7 Original Android Development] Nexive:
Wiped everything, did a factory reset and flashed the developer build.

Device booted, touchscreen works, wifi works, sound works, headphone detection works, ADB works! :)

Here is the log. :)

View attachment dmesg.txt
[MeMO Pad 7 Original Android Development] lambdadroid:
Awesome, everything looks correct now! Thanks for testing, seems like it's working fine.
[MeMO Pad 7 Original Android Development] lambdadroid:
I somehow managed to mess up my last post, so let me post my fantastic homescreen this time ;)
[MeMO Pad 7 Original Android Development] Nexive:
Nice you got bluetooth working. :D

Great job! :good:
[MeMO Pad 7 Original Android Development] lambdadroid:
I used GIMP to add the icon
[MeMO Pad 7 Original Android Development] Naecken:
Any possibility to port camera drivers for CX?

How hard is step back to official LP?
[MeMO Pad 7 Original Android Development] lambdadroid:
That's not going to happen (or at least I won't work on it). It's just too much work with 4 separate camera drivers that need to be ported to the newer kernel, together with a mess of proprietary Android components. I also think that the cameras in this device aren't quite worth the effort... That's just my personal opinion, though :)

If you make a TWRP backup of the ASUS system you can just restore it, but make sure you also do a full factory reset. Otherwise, there is a installable ZIP available directly from ASUS: http://dlcdnet.asus.com/pub/ASUS/EeePAD/ME176C/UL-K013-WW-12.10.1.36-user.zip I usually use my TWRP backup though, haven't tested if the ASUS ZIP works with my updated version of TWRP.
[MeMO Pad 7 Original Android Development] Nexive:
So, thanks to your "GIMPing" skills, we are able to get Bluetooth working? :p

Btw, I read your comment on Github about your progress with the Bluetooth driver. You are really doing a great job! :D
[MeMO Pad 7 Original Android Development] lambdadroid:
Indeed. In fact, I write all my code in GIMP. It's definitely the best tool for writing code.
[MeMO Pad 7 Original Android Development] Nexive:
Today I tried to cast my screen to my TV which runs on Android TV.

It gets connected but 1 second after it connects (got black screen on my tv) it disconnects.

It's not a big thing but I'm just saying this. :)
[MeMO Pad 7 Original Android Development] lambdadroid:
Pretty sure casting to Android TV uses Miracast which requires Wi-Fi Direct. I literally tried to get it working yesterday and this morning without success, seems to be a problem with the firmware that is used by the upstream Linux driver. Also see https://github.com/me176c-dev/device_asus_me176c/issues/38

I don't think there is much I can do to fix this, sorry! :)
[MeMO Pad 7 Original Android Development] NahuelMS:
How much battery %/hr is drainning in stand by? The device is always awake or just ony can't doze?

Sory but i get lost, the bluetooth is working now? This new progress are for the lineage 7.1.2 or the 8.0?

Thanks!
[MeMO Pad 7 Original Android Development] Nexive:
I don't know for sure how many % per hour it drains but it's a lot.

The battery is completely empty within 9~10 hours, something like that because the processor goes not to idle when the screen goes off so the device is always awake.

In the current build bluetooth isn't working but Lambdadroid is working on it.

The changes he's doing right now is for LineageOS 14.1 (7.1.2) as far as I know.
[MeMO Pad 7 Original Android Development] lambdadroid:
[MENTION=4491111]Nexive[/MENTION] (or anyone else)

Can you send me a copy of /oemcfg/upi_gg and /oemcfg/upi_bo (put it into a ZIP). I'd like to know if these files (somehow related to battery, but not sure) differ between devices. Thanks :)
[MeMO Pad 7 Original Android Development] Nexive:
Here they are. :) (I'm on the sep. 3 developers build)

View attachment upi.zip
[MeMO Pad 7 Original Android Development] lambdadroid:
Hmm, seems like they are different on each device. I think they're somehow related to battery calibration but the code is really confusing, and I don't have the full source code... Anyway, thanks a lot :)