Jump to content


Photo

CM9 for Lg Optimus L3 (E400)

* * * * * 2 votes

  • Please log in to reply
848 replies to this topic

#681
hecatae

hecatae

    Hardcore

  • Moderator Team
  • PipPipPipPipPipPip
  • 3,239 posts
  • Gender:Male
  • Location:northampton
  • Devices:Samsung i9305
  • Twitter:@meritez

Some notes on battery bug. The irberserk's overclocked-no-battery-bug kernel solves this bug but adds a much more annoying one. If the phone is turned off (i.e shutdown) and the charger cord is plugged, the bootsplash1 logo (LG) appears but the kernel does not boot. To turn off the phine one needs to pull the battery off the box, which is fairly unacceptable. So I digged inside the sources of https://github.com/C...ics/init/init.c and https://github.com/C.../BoardConfig.mk and found out that the root of all evil here is the string in kernel cmdline:

lge.reboot=pwroff

In init.c, the is_charger trigger can be activated ever if bootmode is charger, or

COMMON_GLOBAL_CFLAGS += -DBOARD_CHARGING_CMDLINE_NAME='"lge.reboot"' -DBOARD_CHARGING_CMDLINE_VALUE='"pwroff"'

if (!strcmp(name,BOARD_CHARGING_CMDLINE_NAME)) {
            strlcpy(battchg_pause, value, sizeof(battchg_pause));

if (strcmp(bootmode, "charger") == 0 || strcmp(battchg_pause, BOARD_CHARGING_CMDLINE_VALUE) == 0)
         charging_mode = 1;

By series of sequential patches I determined that the bootmode does not affect the charger trigger on our device, and the trigger activation relies solely on that pwroff parameter. This is a actually a hack created on xda-developers http://forum.xda-dev...&postcount=4113 and it looks like it does not work on e400. If omitting the pwroff check inside init, the phone boots into CM after the first tap, and boots in CM when you plug the cord. To step further, I am investigating which kernel parameters are passed to stock GB e400 kernel, assuming the firmware is the same and there is a "boot-pause" trigger equal to "charger" trigger in CM's init code.

UPD1: In stock e400 Gingerbread V10F_00 init the same pwroff check leads to trigger "boot-pause" that is declared in init.e0.rc as:

on boot-pause
#    exec system/bin/battery_charging
## enable adbd in chargerlogo mode
#   start adbd
    exec /sbin/chargerlogo

so it is time to inspect LG's chargerlogo.


wow, it's a deep bug then,

  • 0

#682
gellmar

gellmar

    Enthusiast

  • Members
  • PipPipPip
  • 189 posts
  • Devices:LG Optimus L3 E400
Update #2 on battery bug. Strucked by insomnia after previous debugging, I re-read my post again and started looking for commits related to bootmodes and charger modes. In several minutes I found a CM repo https://github.com/p...ore/commits/ics by pershoot and arcee, where the series of commits explained me the history of that string inside init.c:

The filesystem exclusion logic before the Samsung lpm stuff was
merged was completely broken and always returned true. (i.e.,
fs hooks always ran)

--------
if (strcmp(bootmode, "charger") != 0 || strcmp(battchg_pause, "true") != 0)
--------
These 2 conditions are never false simultaneously (they're alternative
charger mode flags), so the filesystem mount hooks always happened.

The LPM support patch fixed that logic, but broke other devices in
the process, since some implementations use stuff from /system (or even
link with bionic) for charger mode.

This patch makes the exclusion logic apply _only_ to Samsung LPM
devices or those supported by the original AOSP code
(androidboot.mode=charger), and lets every other device run the
fs hooks


From https://github.com/p...dd250c5fdcf0122

That and the doubt on LG stock init / chargerlogo together made an assumption that LG does not rely on pwroff to detect charger mode in their stock Gingerbreads, neither relies on selective "charger-or-normal" booting like in CM, nor operates charger as a service.

If you examine the LGE400 stock init, you will find the following pseudocode:

action_for_each_trigger("init", action_add_queue_tail);
action_for_each_trigger("early-fs", action_add_queue_tail);
action_for_each_trigger("fs", action_add_queue_tail);
action_for_each_trigger("post-fs", action_add_queue_tail);
queue_builtin_action(property_service_init_action, "property_service_init");
queue_builtin_action(signal_init_action, "signal_init");
queue_builtin_action(check_startup_action, "check_startup");
/* pause if necessary */
if (battchg_pause) {
	 action_for_each_trigger("boot-pause", action_add_queue_tail);
}
/* execute all the boot actions to get us started */
action_for_each_trigger("early-boot", action_add_queue_tail);
action_for_each_trigger("boot", action_add_queue_tail);

From https://github.com/C...ead/init/init.c

That means NO conditional fs hooks exist in LG stock init, and the 'boot-pause' trigger fires BEFORE the boot starts. In combination with

exec /sbin/chargerlogo

it allows the charger application to start and freeze a boot process, if the battery is being charged, or to exit gracefully and continue normal booting if not. In Cyanogen ICS, the charger runs as a service - i.e in parallel, so it is necessary to strip off fs hooks.

Examining the code of chargerlogo, I found that it can reboot android itself or turn the power off, so if the battery is
charged and no OS is loaded, the chargerlogo binary shuts the phone down as expected.

After several tests I managed to find that the charger actually shuts down after 2*UNPLUGGED_SHUTDOWN_TIME = 20 seconds, so it is not a bug.

The second very interesting behavior with CM9 init is that in charger mode, a long power key press boots to normal. The code is responsible for that:

static void process_key(struct charger *charger, int code, int64_t now)
{
struct key_state *key = &charger->keys[code];
int64_t next_key_check;
if (code == KEY_POWER) {
	 if (key->down) {
		 int64_t reboot_timeout = key->timestamp + POWER_ON_KEY_TIME;
		 if (now >= reboot_timeout) {
			 LOGI("[%lld] rebooting\n", now);
			 android_reboot(ANDROID_RB_RESTART, 0, 0);
		 } else {
			 /* if the key is pressed but timeout hasn't expired,
* make sure we wake up at the right-ish time to check
*/
			 set_next_key_check(charger, key, POWER_ON_KEY_TIME);
		 }
	 } else {
		 /* if the power key got released, force screen state cycle */
		 if (key->pending)
			 kick_animation(charger->batt_anim);
	 }
}
key->pending = false;
}
[/CODE]

and it looks like the ANDROID_RB_RESTART reason chanes lge.reboot to reboot instead of pwroff and that's why it works.

[CODE]
lge.reboot=reboot

The charger has to determine somehow what was the reason of boot, or we need a code implementing a scenario - if lge.reboot == pwroff state AND there is an active usb charger, assume user plugged in charger so we have to enter charging mode otherwise boot normally.

Edited by gellmar, 07 March 2013 - 03:16 PM.

  • 0

#683
Swaggzo

Swaggzo

    Regular

  • Members
  • PipPip
  • 83 posts

are there any fixes to my problem of connecting to mobile network... and i wud like the network name to be EE and not T-mobile/orange if possible...




Look here everyone!

I used to have many problems after updating to CM9. I swear, the phone was like hell to me. I almost threw it into a lake.
But i solved all the problems you all are having right now because i had similar problems too.
Like
*frequent rebooting.
*blurry screen
*network disconnection and others.

All i did was update to another nightly on my LG-E400-V10b baseband version.
If you're having problems, just try the ==> 20130120 nightly. It's awesome!

  • 0

#684
gellmar

gellmar

    Enthusiast

  • Members
  • PipPipPip
  • 189 posts
  • Devices:LG Optimus L3 E400
I finally managed to get the battery and the charger module working and released a flashable zip for users and a diff for developers. The patch is for CM android-system-core repository, branch ics. You can build it however you will have to check the presence of compiler cflags related to constants "lge.reboot" and "pwroff".

The flashable zip e400-chargerfixed-gellmar.zip can be obtained
here

The patch:

diff --git a/charger/charger.c b/charger/charger.c
index 589a6bf..3f90312 100644
--- a/charger/charger.c
+++ b/charger/charger.c
@@ -57,7 +57,7 @@

#define BATTERY_UNKNOWN_TIME    (2 * MSEC_PER_SEC)
#define POWER_ON_KEY_TIME       (2 * MSEC_PER_SEC)
-#define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC)
+#define UNPLUGGED_SHUTDOWN_TIME (5 * MSEC_PER_SEC)

#define BATTERY_FULL_THRESH     95

@@ -855,6 +855,16 @@ static void handle_input_state(struct charger *charger, int64_t now)

static void handle_power_supply_state(struct charger *charger, int64_t now)
{
+    /* fixing battery charger bug on LG Opimus L3 E-400 */
+
+    int ac_online = 0;
+    int usb_online = 0;
+
+    read_file_int("/sys/class/power_supply/ac/online",&ac_online);
+    read_file_int("/sys/class/power_supply/usb/online",&usb_online);
+
+    charger->num_supplies_online = ((ac_online == 0) && (usb_online == 0)) ? 0 : 1;
+
     if (charger->num_supplies_online == 0) {
         if (charger->next_pwr_check == -1) {
             charger->next_pwr_check = now + UNPLUGGED_SHUTDOWN_TIME;
diff --git a/init/init.c b/init/init.c
index 010e19f..6d27245 100644
--- a/init/init.c
+++ b/init/init.c
@@ -720,6 +720,57 @@ static int bootchart_init_action(int nargs, char **args)
}
#endif

+static int read_charger_file(const char *path, char *buf, size_t sz)
+{
+    int fd;
+    size_t cnt;
+
+    fd = open(path, O_RDONLY, 0);
+    if (fd < 0)
+        goto err;
+
+    cnt = read(fd, buf, sz - 1);
+    if (cnt <= 0)
+        goto err;
+    buf[cnt] = '\0';
+    if (buf[cnt - 1] == '\n') {
+        cnt--;
+        buf[cnt] = '\0';
+    }
+
+    close(fd);
+    return cnt;
+
+err:
+    if (fd >= 0)
+        close(fd);
+    return -1;
+}
+
+static int read_file_int(const char *path, int *val)
+{
+    char buf[32];
+    int ret;
+    int tmp;
+    char *end;
+
+    ret = read_charger_file(path, buf, sizeof(buf));
+    if (ret < 0)
+        return -1;
+
+    tmp = strtol(buf, &end, 0);
+    if (end == buf ||
+        ((end < buf+sizeof(buf)) && (*end != '\n' && *end != '\0')))
+        goto err;
+
+    *val = tmp;
+    return 0;
+
+err:
+    return -1;
+}
+
+
int main(int argc, char **argv)
{
     int fd_count = 0;
@@ -778,7 +829,13 @@ int main(int argc, char **argv)

     get_hardware_name(hardware, &revision);

-    if (strcmp(bootmode, "charger") == 0 || strcmp(battchg_pause, BOARD_CHARGING_CMDLINE_VALUE) == 0)
+    int ac_online = 0;
+    int usb_online = 0;
+
+    read_file_int("/sys/class/power_supply/ac/online",&ac_online);
+    read_file_int("/sys/class/power_supply/usb/online",&usb_online);
+
+    if ((strcmp(battchg_pause, BOARD_CHARGING_CMDLINE_VALUE) == 0) && (ac_online == 1 || usb_online == 1))
         charging_mode = 1;

     if (!charging_mode_booting()) {

Edited by gellmar, 08 March 2013 - 10:42 PM.

  • 1

#685
yayakuya

yayakuya

    Enthusiast

  • Members
  • PipPipPip
  • 178 posts
  • Gender:Male
  • Location:Indonesia
  • Devices:Sony Xperia E, HTC Desire VC
good job.... :) :thumbsup:
one quick question; is it overclocked already?
btw, thanks for your contribute

  • 0

#686
ajeeshvijayan

ajeeshvijayan

    Newbie

  • Members
  • Pip
  • 34 posts
  • Devices:LG optimus L3 e400
is it overclocked and swap enabled?

  • 0

#687
ajeeshvijayan

ajeeshvijayan

    Newbie

  • Members
  • Pip
  • 34 posts
  • Devices:LG optimus L3 e400
nice work

  • 0

#688
gellmar

gellmar

    Enthusiast

  • Members
  • PipPipPip
  • 189 posts
  • Devices:LG Optimus L3 E400
No, it is not overclocked. The changelog:
  • Stock cm-9-20130224-NIGHTLY-e400 zImage with initramfs re-packed
  • new /init and /charger (see post)
  • fixed /init.rc for ICS encryption enabled
Hope somebody will make overclocked/swap/tun kernel with my patch. The patch is free-to-use unless the credits are there =)

  • 0

#689
Ygreck

Ygreck

    Regular

  • Members
  • PipPip
  • 133 posts
swap bricked many devices... is this a good idea ;P?

thx for your brilliand work gellmar
specially your "notes on E-400 development" is a gift to all upcoming dev's!

  • 0

#690
ajeeshvijayan

ajeeshvijayan

    Newbie

  • Members
  • Pip
  • 34 posts
  • Devices:LG optimus L3 e400
swap partition works on my L3..more ram..it will be use full I think

Edited by ajeeshvijayan, 10 March 2013 - 12:58 AM.

  • 0

#691
nikufellow

nikufellow

    Regular

  • Members
  • PipPip
  • 61 posts
Any way to reduce ram consumption in cm9 i tried purging of assets in settings but that doesn't do much good

  • 0

#692
ajeeshvijayan

ajeeshvijayan

    Newbie

  • Members
  • Pip
  • 34 posts
  • Devices:LG optimus L3 e400
use greenify

  • 0

#693
herseon

herseon

    Newbie

  • Members
  • Pip
  • 16 posts
  • Devices:LG Optimus L3
Hi, I'm new on this and I've a question. I installed the CM9's version of 24/2 of this phone and when I connect to the Internet via Wifi, the connection takes 10 or 15 seconds and then the pages don't load but the Wifi still on. Any solutions?

  • 0

#694
gellmar

gellmar

    Enthusiast

  • Members
  • PipPipPip
  • 189 posts
  • Devices:LG Optimus L3 E400
So I managed to fix USB Mass Storage for Optimus L3. The flashable zip can be found here: http://sendfile.su/776758

How to install:

1. Install latest CM9 nightly via clockworkmod
2. Do a cache wipe
3. Apply cm9-20130311-charger-mass-encryption-update-gellmar.zip
4. Reboot phone

Fixed issues in this update:

1. Charger fix [e400-charger-fix]
2. USB mass storage fix [e400-mass-storage-kernel-fix + e400-mass-storage-device-fix + e400-mass-storage-vold-fix]
3. ICS native encryption fix [e400-ics-encryption-enable-fix]
4. ADB suppress on charging fix [e400-disable-adb-on-charger-fix]

Attached Files


Edited by gellmar, 11 March 2013 - 08:29 PM.

  • 2

#695
viking_kong

viking_kong

    Newbie

  • Members
  • Pip
  • 31 posts
  • Devices:LG Optimus L3
this is great!just great!thanks!

  • 0

#696
ajeeshvijayan

ajeeshvijayan

    Newbie

  • Members
  • Pip
  • 34 posts
  • Devices:LG optimus L3 e400
good work.. now someone should overclock it and include swap/tun

  • 0

#697
herseon

herseon

    Newbie

  • Members
  • Pip
  • 16 posts
  • Devices:LG Optimus L3
Why my phone can't connect to Internet by Wifi? Please, help me!

  • 0

#698
gellmar

gellmar

    Enthusiast

  • Members
  • PipPipPip
  • 189 posts
  • Devices:LG Optimus L3 E400
turn adb on... install drivers for usb adb, do adb logcat > logcat.txt and try to wifi. Post the log here.

  • 0

#699
herseon

herseon

    Newbie

  • Members
  • Pip
  • 16 posts
  • Devices:LG Optimus L3
This is the report. Thank you very much:

Spoiler


If anyone who can help need the complete report, he lets me say it and I sent it him by PM.

  • 0

#700
gellmar

gellmar

    Enthusiast

  • Members
  • PipPipPip
  • 189 posts
  • Devices:LG Optimus L3 E400
herseon,

adb shell dmesg > dmesg.bad

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users