Pmbootstrap: aport for LG K7

Created on 8 Mar 2018  Â·  19Comments  Â·  Source: postmarketOS/pmbootstrap

I'm trying to port pmOS to an LG-K330 (AT&T LG-K7), which I believe is codenamed m1 (I think it has the same kernel as the MetroPCS variant MS330).

I found kernel source here, removed the default patches added by pmbootstrap and added 00_fix_return_address.patch which I got from other aports I was able to menuconfig and kconfig, but I'm unable to successfully build. I keep getting these errors:

drivers/soc/qcom/lge/lge_boot_mode.c:197:9: error: 'LGEUSB_FACTORY_56K' undeclared (first use in this function)
   res = LGEUSB_FACTORY_56K;
...
drivers/soc/qcom/lge/lge_boot_mode.c:218:8: error: variable 'lge_android_usb_pdata' has initializer but incomplete type
 struct lge_android_usb_platform_data lge_android_usb_pdata = {

I'm getting the same issue with LGEUSB_FACTORY_130K / 910K. I looked and LGEUSB_FACTORY_56K and lge_android_usb_platform_data are both defined in include/linux/platform_data/lge_android_usb.h, is the header just not being included or something?

I get a similar error for platform_device, which is defined in include/linux/platform_device.h:

drivers/soc/qcom/lge/lge_boot_mode.c:228:8: error: variable 'lge_android_usb_device' has initializer but incomplete type
 struct platform_device lge_android_usb_device = {

There are more errors that I think are related to the ones I've listed above. I've attached a more complete error log and my APKBUILD.

pmbootstrap/log.txt

APKBUILD

help wanted

All 19 comments

I found in lge_boot_mode.c that include/linux/platform_data/lge_android_usb.h is included under an ifdef here referring to CONFIG_LGE_USB_G_ANDROID.

I looked for this option with pmbootstrap menuconfig; the search result said it was listed under

Device Drivers -> USB Support -> USB Gadget Support, and that it also relied on

CONFIG_USB_G_ANDROID under

Device Drivers -> USB Support -> USB Gadget Support -> USB Gadget Drivers.

At first I was unable to find either option actually listed so I added them both manually, but looking again it looks like it's only available when USB Gadget Drivers is set to *; it was listed as M so I changed it to Y and selected CONFIG_USB_G_ANDROID, which let me set CONFIG_LGE_USB_G_ANDROID too. There are more errors that I'll get to soon, I will update as I find out more.

UPDATE
now I have this issue:

drivers/char/diag/mts_tty.o: In function `mts_tty_init':
/home/pmos/build/src/android_kernel_lge_msm8909-017ab2a9067360f82d660dab7b08ce7e277c1cdb/drivers/char/diag/mts_tty.c:207: multiple definition of `init_module'
drivers/char/diag/diagchar_core.o:/home/pmos/build/src/android_kernel_lge_msm8909-017ab2a9067360f82d660dab7b08ce7e277c1cdb/drivers/char/diag/diagchar_core.c:2294: first defined here
drivers/char/diag/mts_tty.o: In function `mts_tty_unthrottle':
/home/pmos/build/src/android_kernel_lge_msm8909-017ab2a9067360f82d660dab7b08ce7e277c1cdb/drivers/char/diag/mts_tty.c:155: multiple definition of `cleanup_module'
drivers/char/diag/diagchar_core.o:/home/pmos/build/src/android_kernel_lge_msm8909-017ab2a9067360f82d660dab7b08ce7e277c1cdb/drivers/char/diag/diagchar_core.c:2413: first defined here
make[3]: *** [scripts/Makefile.build:444: drivers/char/diag/diagchar.o] Error 1
make[2]: *** [scripts/Makefile.build:455: drivers/char/diag] Error 2
make[1]: *** [scripts/Makefile.build:455: drivers/char] Error 2

I read here that it could be an issue with the Makefile or Kconfig but I'm not really sure where to start looking. I'll keep looking around to see what i can find, it'd be great if someone could point me in the right direction too.

UPDATE-2
I found some more errors from when I tried building with multiple threads, more "multiple definition" errors from lib/mpi/mpi.o:

https://pastebin.com/dsZ1s1Nx

UPDATE-3
I tried compiling with this kernel with the same result. I see drivers/char/diag/Makefile includes both diagchar_core.o and mts_tty.o:

diagchar-objs := diagchar_core.o diagchar_hdlc.o diagfwd.o diag_mux.o diag_memorydevice.o diag_usb.o diagmem.o diagfwd_cntl.o diag_dci.o diag_masks.o diag_debugfs.o mts_tty.o

but I'm not sure if I need to modify the Makefile or can just adjust some config or compile parameter.

CONFIG_DIAG_CHAR was set to M so I changed it to * and that fixed the drivers/char/diag/mts_tty.o error. I'm starting to see a pattern here lol

Welcome to postmarketOS and thanks for starting a port to your device! :tada:

I found some more errors from when I tried building with multiple threads, more "multiple definition" errors from lib/mpi/mpi.o:

In my experience that's not very helpful, we need to fix the errors from top to bottom, and sometimes upper errors cause further errors down the road.

CONFIG_DIAG_CHAR was set to M so I changed it to * and that fixed the drivers/char/diag/mts_tty.o error. I'm starting to see a pattern here lol

Good that you just got further again :+1:

If you should get stuck at some point without any idea how to proceed, please fork pmbootstrap and add your WIP progress in a new branch, so we can try the build ourselves and try to fix it. (also let us know here with a comment afterwards :wink: )

will do. It looks like the mpi error was patched in the linux-lg-bullhead port with static-inline.patch. I also applied driver-fix.patchfrom the same port to address another error, and it finished building! :smiley: I won't be able to actually try and flash it for a bit but I'll update when I am. I added a wiki page here.

Awesome news! \o/

finally have a chance to try flashing, I have attained ssh \o/ time to work on the screen

I think I got the screen to work! Now I'm trying to get pmos to recognize touch events and I'm hitting some snags. I'm not totally sure what touchscreen drivers I should be including in the kernel; initially CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_v21 was enabled, but I don't know why since the config I based mine off didn't include that at all. I poked around a bit and my current best guess is the melfas mit200 firmware. I thought I set the right flags in the config to build out the firmware but I'm getting this:

  MK_FW   firmware/melfas/mit200/lgps22/L0M45P1_00_07.fw.gen.S
  COPY    firmware/melfas/mit200/lgps22/L0M45P1_00_07.fw
cp: can't stat '/home/pmos/build/src/android_kernel_lge_msm8909-017ab2a9067360f82d660dab7b08ce7e277c1cdb/firmware/melfas/mit200/lgps22/L0M45P1_00_07.fw': No such file or directory
make[1]: *** [/home/pmos/build/src/android_kernel_lge_msm8909-017ab2a9067360f82d660dab7b08ce7e277c1cdb/firmware/Makefile:287: firmware/melfas/mit200/lgps22/L0M45P1_00_07.fw] Error 1
make: *** [Makefile:815: firmware] Error 2

Looking at the makefile reveals why it's dipping into mit200/lgps22 even though my phone model is m1, though I diffed the two folders and they're identical anyway. Also the ifdefs above are all identical to each other and refer to $(wildcard $(srctree)/firmware/melfas/m1_spr_us/*) which isn't actually a folder??

But otherwise I don't know why it's failing. I'm assuming there's some sort of conversion process from .fw.ihex -> .fw.gen.S -> .fw but I haven't found any documentation on it yet. Any ideas? I finally make forked pmbootstrap with my wip device-lg-m1 branch here.

Nice progress again!

For all devices we have ported postmarketOS to so far, we did not require any kernel config adjustments to make the touchscreen work. The drivers already get built if you use the kernel config for your device (modified to pass pmbootstrap's kernel config checking of course).

Have you tried these instructions?

but I don't know why since the config I based mine off didn't include that at all.

My guess is that the kernel config you've started with was generated with older kernel sources. As the kernel source changed, new options appeared, and when you generate a new config with pmbootstrap menuconfig, these new options get filled out with the defaults.

That's interesting about the kernel defaults. I did try to cat /dev/input/eventX but i was only able to trigger any events with the power and volume keys (event4/5). Looking at logread output it also says

Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.198] event5  - gpio-keys: is tagged by udev as: Keyboard
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.198] event5  - gpio-keys: device is a keyboard
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.199] event4  - qpnp_pon: is tagged by udev as: Keyboard
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.199] event4  - qpnp_pon: device is a keyboard
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.201] event2  - accelerometer: is tagged by udev as: Accelerometer
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.201] event2  - accelerometer: device is an accelerometer, ignoring
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.201] event2  - not using input device '/dev/input/event2'
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.202] event1  - light: not tagged as supported input device
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.203] event1  - not using input device '/dev/input/event1'
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.204] event3  - magnetic_field: is tagged by udev as: Accelerometer
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.204] event3  - magnetic_field: device is an accelerometer, ignoring
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.204] event3  - not using input device '/dev/input/event3'
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.205] event0  - proximity: not tagged as supported input device
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:02:27.205] event0  - not using input device '/dev/input/event0'

so event0-3 are not being used by weston and are all non-touch devices.

I compared my pmos/twrp sysfs as recommended on the wiki: devices.diff. twrp seems to list input0 as being the touch device (cat /sys/devices/virtual/input/input0/name returns touch_dev) and cat /dev/input/event0 does print outputs when in twrp. /sys/devices/virtual/input/lge_touch/firmware returns

======== IC Firmware Info ========
FW Version: 1.01

====== Binary Firmware Info ======
Bin Version: 1.01

on the other hand, lge_touch is entirely absent from /sys/devices/virtual/input in pmos. I tried to set deviceinfo_dev_touchscreen="/dev/input/event0" anyway but that did nothing (not that it should have since event0 is apparently the proximity sensor)

I also looked in the sysfs folder of another LG device (lg-k428) and confirmed it's using the mit-300 touchscreen driver, hence my current suspicions that I ought to be using the mit200 driver.

update

after some finagling I patched firmware/Makefile with a modified version of this and got it to compile through with the mit200 driver, but unfortunately i'm not seeing any new input devices show up.

Thanks for the update. You wrote in the PR that you'll try the other kernel first - let us know if you get stuck with the new kernel again!

I managed to compile and flash the EdwinMoq kernel but I haven't been able to get the screen to work nor does the touchscreen seem to get detected lol. gonna keep fiddling with kernel config

In case you didn't check it yet: There might be something useful in dmesg on the device.

oh wow, for some reason I thought logread was the only syslog on pmos lol. I just ran it here:

3.18.71-pmos (touch specific)
3.10.49-ge4f6464 (twrp) (touch-specific)
3.10.49-ge4f6464 (twrp) (full dmesg)

For some reason dmesg on 3.10.49-pmos is totally empty?? but it does have a /var/log/firmwareload.log that just says a bunch of times

cannot find firmware file 'venus.mdt'

According to twrp's dmesg I think I was right that I need the MIT200 firmware/driver so I wonder why it wasn't selected in my original config and doesn't even compile without a shoddy self-made patch -_- but it looks like in 3.18.71 it gets stuck in some sort of infinite boot loop, the touch logs seem comparable until here:

[    3.951585] [TOUCH][L][MIT200] ESD Detected!
[    3.951602] [TOUCH][L][COMMON] WqTouchIrqHandler : goto error !!!
[    3.951614] [TOUCH][E][COMMON] WqTouchIrqHandler() line=702 : Abnormal IC status. Touch IC will be reset
[    3.951642] [TOUCH][L][PLATFORM] Interrupt Disabled
[    3.951654] [TOUCH][L][PLATFORM] Reset Pin was set to LOW
[    3.970144] [TOUCH][L][PLATFORM] Reset Pin was set to HIGH
[    4.080274] [TOUCH][L][MIT200] Device was reset
[    4.080538] [TOUCH][L][COMMON] STATE = NORMAL
[    4.080557] [TOUCH][L][PLATFORM] Interrupt Enabled

I don't know what ESD means so I traced it back but I just got stumped on an i2c call and MIP_ALERT_ESD is just defined as 1 elsewhere..
ESD Detected ->
alert_type == MIP_ALERT_ESD ->
alert_type = rbuf[0] ->
u8 rbuf[256] = {0}; Mit200_proc4_I2C_Read(client, wbuf, 2, rbuf, 1) ->
int Mit200_proc4_I2C_Read ( struct i2c_client *client, u8 *addr, u8 addrLen, u8 *rxbuf, int len ) ->
ret = i2c_read(client, addr, addrLen, rxbuf, len);

according to google though, apparently ESD just means "electrostatic discharge"?? so I guess my main inquiries:

  • why is the touchscreen reporting ESDs? some sort of pin misconfiguration or something?
  • why isn't dmesg working in 3.10.49 and what is venus.mdt? I saw some other references to it in this repository, i'll look into it

i'm wondering which kernel I should focus on as well since at least 3.10.49 has a working display. right now i'm thinking it may benefit me to keep looking at both of them at least for comparison.

That's some great debugging you did there!

For some reason dmesg on 3.10.49-pmos is totally empty??

That is probably caused by a weird value for kernel config option CONSOLE_LOGLEVEL_DEFAULT, so you could compare what both kernels have there. You can also override the log level without recompiling the kernel by specifying "loglevel=" in the kernel command line.

According to twrp's dmesg I think I was right that I need the MIT200 firmware/driver so I wonder why it wasn't selected in my original config and doesn't even compile without a shoddy self-made patch -_-

The other day I have read in #postmarketOS, that with Android's build system, sometimes multiple kernel configs get merged into one, and that such a second kernel config may specify the details for the touch screen. So maybe you could check the Android repositories for a touch screen specific config that you need to merge with yours.

@scintill wrote that the usb networking related configurations were in an extra config file for the samsung-i9195 in #1260, maybe he could tell you how to find such a second config.

  • why is the touchscreen reporting ESDs? some sort of pin misconfiguration or something?

I think this is a bug in the touchscreen driver: it reports ESD problems, when the firmware file is missing (I also think that you really need this file now, and it probably gets generated in the kernel compilation process?).

i'm wondering which kernel I should focus on as well since at least 3.10.49 has a working display. right now i'm thinking it may benefit me to keep looking at both of them at least for comparison.

Sounds like a good plan.

This line shows the second config file for my own device (TARGET_KERNEL_VARIANT_CONFIG seems to get combined with TARGET_KERNEL_CONFIG for the full kernel config). I didn't see the VARIANT line in TheOddTaco's repos, so it's probably not the exact same issue. Anyway, I think I tracked mine down by diffing zcat /proc/config.gz between my working Android kernel and the one pmOS was building. There might be easier ways to do that; but if you haven't tried that, I would start there. Maybe look at your Android init scripts to see if they poke something to initialize the screen.

I found CONFIG_DEFAULT_MESSAGE_LOGLEVEL=4 already set in the oddtaco kernel but still nothing in dmesg.

@scintill I'm not seeing any /proc/config.gz or /boot/config* in twrp recovery, did you have to reflash the android rootfs? I guess i can restore my twrp backup

update
i've looked a bunch of places and haven't been able to find the running kernel config. Gonna keep looking at the sources then

there's some references to touch events in mmi:

https://github.com/TheOddTaco/proprietary_vendor_lge_m1/blob/4f465a3a02eb35b6a996eaf9ad828ef63ccf2665/proprietary/etc/mmi/strings.xml#L120
https://github.com/TheOddTaco/proprietary_vendor_lge_m1/blob/4f465a3a02eb35b6a996eaf9ad828ef63ccf2665/proprietary/etc/mmi/mmi.cfg#L164

but i haven't found out what mmi is. I also found this:

https://github.com/TheOddTaco/android_device_lge_m1/blob/8d81201312c80dfec43e4ec2f1d01526e017d987/rootdir/init.target.rc#L148

probably less relevant but also chmod/chown for tap to wake:
https://github.com/EdwinMoq/android_device_lge_m1-common/blob/0232a82bd13837fb6e6bb7cb53d1668daf41d08b/rootdir/etc/init.target.rc#L41

update edmoq kernel
logread snippet:

Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.913] weston 3.0.0
Dec 31 13:59:59 lg-m1 user.notice user:weston:                http://wayland.freedesktop.org
Dec 31 13:59:59 lg-m1 user.notice user:weston:                Bug reports to: https://bugs.freedesktop.org/enter_bug.cgi?product=Wayland&component=weston&version=3.0.0
Dec 31 13:59:59 lg-m1 user.notice user:weston:                Build: unknown (not built from git or tarball)
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.914] Command line: /usr/bin/weston -c /etc/xdg/weston/weston.ini.default
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.914] OS: Linux, 3.18.71-pmos, #1-postmarketOS SMP PREEMPT Tue Apr 3 05:23:26 UTC 2018, armv7l
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.914] Using config file '/etc/xdg/weston/weston.ini.default'
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.914] Output repaint window is 7 ms maximum.
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.914] Loading module '/usr/lib/libweston-3/fbdev-backend.so'
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.915] initializing fbdev backend
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.916] Creating fbdev output.
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.916] Opening fbdev frame buffer.
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.916] Failed to open frame buffer device ‘/dev/fb0’: Permission denied
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.916] Creating frame buffer failed.
Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:08:55.917] fatal: failed to create compositor backend

Summary

  • Various compiler errors fixed
  • SSH and screen works
  • Touch screen does not work yet
  • It uses the mit300 driver

I'm not seeing any /proc/config.gz

Unfortunatelly this feature is not enabled in all kernels (CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC must be enabled in the kernel at compile time). If it is not enabled, the kernel configuration (as text) does not get compiled into the kernel, so you can't read it out.

Idea

This is a shot in the dark, but when searching for "FIRMWARE" in your kernel config, I found this option enabled:

CONFIG_PREVENT_FIRMWARE_BUILD=y

Help text:

Say yes to avoid building firmware. Firmware is usually shipped with the driver and only when updating the firmware should a rebuild be made. If unsure, say Y here.

I've grepped for this in the other kernel configs we have, and whenever the option is specified, it is set to =y, so I would not put too much hope into it. But maybe if you disable that option, it compiles the touch screen firmware and it starts working.

PS: The comments in the firmware Makefile may also be helpful: https://github.com/TheOddTaco/android_kernel_lge_msm8909/blob/MS330h/firmware/Makefile

hm yeah, searching for PREVENT_FIRMWARE_BUILD in the git repo doesn't seem to return anything promising so I'm not too sure about this. I really want to figure out what's blocking up dmesg, I feel like it'll be pretty useful later on too (thinking optimistically lol).

I'm gonna try to compare more closely the differences between the edmoq+oddtaco melfas mit200 drivers, I already patched the oddtaco makefile with some of the edmoq one since it was refusing to build for a while.

also, after rebasing my oddtaco repo to 002993b324b2b910d06c195d6fb87be8c5d6d9d4 I'm getting the same error as in the edmoq repo, and my screen is stuck at the pmos loading screen:

Dec 31 13:59:59 lg-m1 user.notice user:weston: [19:25:05.224] Failed to open frame buffer device ‘/dev/fb0’: Permission denied

I'm gonna try to compare more closely the differences between the edmoq+oddtaco melfas mit200 drivers

That sounds like a good plan. Let us know if you are still stuck.

Another approach may be using another kernel. There don't seem to be many out there, but I did find this one (thread).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Asara picture Asara  Â·  6Comments

ghost picture ghost  Â·  4Comments

cmdr2 picture cmdr2  Â·  7Comments

craftyguy picture craftyguy  Â·  7Comments

fynngodau picture fynngodau  Â·  3Comments