[Galaxy S III I9305 (4G LTE + 2GB RAM) Android Deve] scholbert:
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:

/* 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:

...
CONFIG_CMDLINE="console=ttySAC2,115200"
# CONFIG_CMDLINE_FROM_BOOTLOADER is not set
# CONFIG_CMDLINE_EXTEND is not set
# CONFIG_CMDLINE_FORCE is not set
[B]CONFIG_CMDLINE_FIXUP=y[/B]
...

Kconfig needs this modification,

/arch/arm/Kconfig:

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:

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");
[B]#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);
}[/B]
#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... :p

Anyway, hope you like it and good luck for your kernel compilation!

Enjoy offline charging in the end :laugh:

P.S.: Some technical notes about the background:

http://xdaforums.com/showpost.php?p=58760241&postcount=9

P.P.S.:

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

[MENTION=4365701]psndna88[/MENTION] & [MENTION=4731772]Hbohd[/MENTION]:

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