FORUMS
Remove All Ads from XDA

[FIX][KERNEL][9305][KK4.4.4] Offline charging bug fix for old bootloader and KK Stock

1,339 posts
Thanks Meter: 809
 
By scholbert, Senior Member on 17th February 2015, 01:34 PM
Post Reply Email Thread
Hi,

i'm testing my own KK ROM for a while now and i'm using AGNi PureStock kernel.
It's quite a nice combination but because i'm still using old bootloader on my device, i was annoyed by this offline charging bug.
You might have read about it or may have noticed it as well, if you use old bootloader and installed some of the KK stock ROM's.


Finally i did some research myself and thought about a permanent solution done at kernel level.
The idea was to hack the bootlader params given by old bootloader to match the requirements of the KK init and lpm binary.
Because it is done at very early stage, it is not required and not recommended to apply the JB patch for the battery driver anymore.

So as a prerequisite, please remove this part from samsung_battery.c if it still exists in your kernel:
Code:
/* For JB bootloader compatibility */
static int bootloader_get_lpm_state(char *str)
{
 if (strncmp(str, "1", 1) == 0)
 lpcharge = 1;

 pr_info("%s: Low power charging mode: %d\n", __func__, lpcharge);

 return lpcharge;
}
__setup("lpcharge=", bootloader_get_lpm_state);

Here's my patch...

Add this to the platform config file:

Code:
...
CONFIG_CMDLINE="console=ttySAC2,115200"
# CONFIG_CMDLINE_FROM_BOOTLOADER is not set
# CONFIG_CMDLINE_EXTEND is not set
# CONFIG_CMDLINE_FORCE is not set
CONFIG_CMDLINE_FIXUP=y
...

Kconfig needs this modification,
/arch/arm/Kconfig:

Code:
config CMDLINE_FIXUP
       bool "Append missing parameter to bootloader kernel arguments"
       help
         The missing parameter will be appended to the
         command-line arguments provided by the boot loader.
The fix itself is located in the function parse_tag_cmdline,
/arch/arm/kernel/setup.c:


Code:
static int __init parse_tag_cmdline(const struct tag *tag)
{
#if defined(CONFIG_CMDLINE_EXTEND)
    strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
    strlcat(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
#elif defined(CONFIG_CMDLINE_FORCE)
    pr_warning("Ignoring tag cmdline (using the default kernel command line)\n");
#elif defined(CONFIG_CMDLINE_FIXUP)
    strlcpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
    if (strstr(default_command_line, "lpcharge=1") != 0) {
        strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
        strlcat(default_command_line, "androidboot.mode=charger", COMMAND_LINE_SIZE);
    }
#else
    strlcpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
#endif
    return 0;
}

As you see this it is quite simple and straight forward.
... but right now you'll need to compile your own kernel or ask the developers to integrate it for you.
It works very nice with my own test kernel compiled from AGNi pureSTOCK sources.

The patch will have no effect, if you're on new bootloader already... so it fits well

Though some kernel hardliner may not like it, because we touch general arch specific code...

Anyway, hope you like it and good luck for your kernel compilation!
Enjoy offline charging in the end

P.S.: Some technical notes about the background:
http://forum.xda-developers.com/show...41&postcount=9

P.P.S.:
I may create a simple patch file as well... for now grab the txt file to copy'n'paste.

@psndna88 & @Hbohd:
This patch could be re-worked a little bit to be even more modular.
E.g. replace the fixed strings by user defined placeholders to be defined in the config file.
Some caution is required then of course...

Have fun!

scholbert
Attached Files
File Type: txt lpmfix.txt - [Click for QR Code] (1.4 KB, 344 views)
The Following 15 Users Say Thank You to scholbert For This Useful Post: [ View ] Gift scholbert Ad-Free
22nd February 2015, 03:59 AM |#2  
Jortu's Avatar
Junior Member
Thanks Meter: 10
 
More
Question AOSP fix?
Hello,

I have been struggling with this bug on AOSP roms since I rooted my phone, will this fix work with Cyanogenmod roms?

Thanks,
Jortu
23rd February 2015, 11:57 AM |#3  
OP Senior Member
Thanks Meter: 809
 
More
Hi Jortu!
Quote:
Originally Posted by Jortu

I have been struggling with this bug on AOSP roms since I rooted my phone, will this fix work with Cyanogenmod roms?

To be honest it is not that easy to answer this question in general, as there are several versions in use.
It depends on the proprietary files used for the specific CM version, if this patch would be helpful or not.

CM10.2 uses JB proprietary files:
system/bin/lpmkey
system/bin/playlpm

These binaries should match old bootloader (don't know about init binary used in initrd).
No issues here i guess... no patch required.
Though i never used this version and can't tell about the state.


As CM11 uses system/bin/lpm only, which seems to be the proprietary file from the stock KK,
it would require the new bootloader to work properly, from the first view.

It seems there'd been some confusion about the correct initialisation for offline charging and maybe it never got fixed. Don't know if it had ever been solved in the ramdisk somehow (changes in the init process or init binary itself).
This release might be still affected from the bug, if you're on old bootloader.
I once used a version of Omnirom (based on CM11) and if i remember correctly, there'd been no issues...

So if you like to check it out, apply the patch and build your own kernel and boot.img.


CM12 then switched to opensource healthd-charger.
So in fact this is the best solution and it should be independent from bootloaders.

To sum up... if CM11 is still affected by offline charging bug, the patch may help as well.
I hope this helps!

Cheers,

scholbert
The Following 6 Users Say Thank You to scholbert For This Useful Post: [ View ] Gift scholbert Ad-Free
10th March 2015, 07:19 PM |#4  
OP Senior Member
Thanks Meter: 809
 
More
Hi again,

for thoose who like to test...
I created my own kernel based on psndna88 source branch pureSTOCK-I9305-4.4.4:
- applied offline charging patch
- removed f2fs support in config
- support for FTDI USB serial adaptors
- cleaned/shrinked down initrd
See link to the attachment in my ROM thread below!
Clean and mean... works very nice

http://forum.xda-developers.com/atta...1&d=1425985426

This is a test kernel to be considered as a proof of concept.
It may work on other stock based ROMs as well, as it is mainly based on psndna88 config for V55.
As i don't wanted to steal any of psndna88 great work i removed all init.d stuff and other things.
So my initrd is more back to stock in this case, some of the systems tweaks are in use though.

Please give huge thanks and credits to @psndna88 for his incredible hacking skills

P.S.: I will immediately remove the zip file if it's violating any official rules or personal feelings

Have fun!

scholbert
The Following 4 Users Say Thank You to scholbert For This Useful Post: [ View ] Gift scholbert Ad-Free
10th March 2015, 08:07 PM |#5  
Senior Member
Flag Santeramo in Colle (Ba)
Thanks Meter: 1,366
 
Donate to Me
More
Quote:
Originally Posted by scholbert

Hi again,

for thoose who like to test...
I created my own kernel based on psndna88 source branch pureSTOCK-I9305-4.4.4:
- applied offline charging patch
- removed f2fs support in config
- support for FTDI USB serial adaptors
- cleaned/shrinked down initrd
See link to the attachment in my ROM thread below!
Clean and mean... works very nice

http://forum.xda-developers.com/atta...1&d=1425985426

This is a test kernel to be considered as a proof of concept.
It may work on other stock based ROMs as well, as it is mainly based on psndna88 config for V55.
As i don't wanted to steal any of psndna88 great work i removed all init.d stuff and other things.
So my initrd is more back to stock in this case, some of the systems tweaks are in use though.

Please give huge thanks and credits to @psndna88 for his incredible hacking skills

P.S.: I will immediately remove the zip file if it's violating any official rules or personal feelings

Have fun!

scholbert

flashed.
seems it work fine on old bootloader.
thanks a lot for this kernel.
i'll test it for few days...if it will works well, can i add it to Amcha rom?
The Following 2 Users Say Thank You to LeoDeos For This Useful Post: [ View ] Gift LeoDeos Ad-Free
10th March 2015, 11:12 PM |#6  
OP Senior Member
Thanks Meter: 809
 
More
Hey LeoDeos,

thanks for appreciation.
Use this kernel for whatever you like, you're welcome
Though it was meant for testing, should be all o.k. with it.
If you need some more info, don't hesitate...

Cheers,

scholbert
The Following User Says Thank You to scholbert For This Useful Post: [ View ] Gift scholbert Ad-Free
11th March 2015, 04:02 PM |#7  
Senior Member
Flag Santeramo in Colle (Ba)
Thanks Meter: 1,366
 
Donate to Me
More
Quote:
Originally Posted by scholbert

Hey LeoDeos,

thanks for appreciation.
Use this kernel for whatever you like, you're welcome
Though it was meant for testing, should be all o.k. with it.
If you need some more info, don't hesitate...

Cheers,

scholbert

after one day of use i found a little issue.
it doesnt run the scripts in init.d.
i changed the busybox in it and now is ok
The Following User Says Thank You to LeoDeos For This Useful Post: [ View ] Gift LeoDeos Ad-Free
11th March 2015, 04:37 PM |#8  
OP Senior Member
Thanks Meter: 809
 
More
Hi LeoDeos,

thanks for your feedback!
Quote:
Originally Posted by LeoDeos

after one day of use i found a little issue.
it doesnt run the scripts in init.d.
i changed the busybox in it and now is ok

I did not use the init.d feature yet, so this was untested.
Though busybox is the same used in psndna88 initrd, which is Stericsons BusyBox v1.23.0.

I guess for complete init.d support, it would be best to place all symbolic links to initrd busybox in /sbin as well.
Could you be more specific, which script refused to start or was it a general issue?
Which one do you use now?

Thanks again!

scholbert
The Following User Says Thank You to scholbert For This Useful Post: [ View ] Gift scholbert Ad-Free
11th March 2015, 05:05 PM |#9  
Senior Member
Flag Santeramo in Colle (Ba)
Thanks Meter: 1,366
 
Donate to Me
More
Quote:
Originally Posted by scholbert

Hi LeoDeos,

thanks for your feedback!

I did not use the init.d feature yet, so this was untested.
Though busybox is the same used in psndna88 initrd, which is Stericsons BusyBox v1.23.0.

I guess for complete init.d support, it would be best to place all symbolic links to initrd busybox in /sbin as well.
Could you be more specific, which script refused to start or was it a general issue?
Which one do you use now?

Thanks again!

scholbert

Hi scholbert
the problem was with all scripts in init.d...it doesnt run anyone.
i always had problems with Stericsons BusyBox...in past i changed it in Amcha Rom (for example, doest works reboot command in shell) and changed also in Agni Kernel in Amcha Rom.
i use busybox 1.22.1 bionic.
The Following User Says Thank You to LeoDeos For This Useful Post: [ View ] Gift LeoDeos Ad-Free
11th March 2015, 07:04 PM |#10  
OP Senior Member
Thanks Meter: 809
 
More
Hi LeoDeos,

thanks for your immediate reply!
Quote:
Originally Posted by LeoDeos

Hi scholbert
the problem was with all scripts in init.d...it doesnt run anyone.
i always had problems with Stericsons BusyBox...in past i changed it in Amcha Rom (for example, doest works reboot command in shell) and changed also in Agni Kernel in Amcha Rom.
i use busybox 1.22.1 bionic.

AFAIK reboot command is not implemented in Stericsons BB.
I use the stock reboot binary in DLite ROM and it works as it should.
In the beginning there where some dead links created during install... but i fixed that in my ROM.
Sometimes things got lost while creating updater scripts

Anyway, luckily there are several choices and i know this bionic version of busybox as well.
Maybe i'll check it out.
Thought about creating my own BB as well

BTW, thanks for your great work and helping people out in the Amcha thread!!

EDIT:
Just as a side-note...
Please be aware which version of bionic busybox you use, some are linked dynamically.
It could be dangerous to use dynamically linked binaries in initrd!
busybox-bionic: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped

This is linusyang version (standard libc):
busybox-linusyang: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped

It got the reboot command implemented as well!

Cheers,

scholbert
The Following User Says Thank You to scholbert For This Useful Post: [ View ] Gift scholbert Ad-Free
12th March 2015, 01:13 AM |#11  
djb77's Avatar
Recognized Developer / Contributor
Flag NSW
Thanks Meter: 7,276
 
Donate to Me
More
@scholbert

Many thanks to you for fixing this issue. I have a couple of questions.

- I know you said it's the 4.4.4 version of AGNi, but is it the stock AGNi or one with modified sound?
- May I have your permission to use the zImage from your kernel to create multiple versions (No sound mod, Boeffla Mod, Wolfson Mod)

I've played around with AGNi myself a little bit too, enabling the insecure ADB and updating BusyBox, so I would be able to make this custom versions without a problem. These custom versions would be used for my ROM (TGP)

---------- Post added at 11:13 AM ---------- Previous post was at 10:47 AM ----------

UPDATE: Just done a test to put together my modded AGNi Kernels with the zImage from this kernel, and it worked.
So if I have permission I can include this in TGP where users will have the option to select either of the 3 variants of AGNi
The Following User Says Thank You to djb77 For This Useful Post: [ View ]
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes