LG K40 (lg-mmh4x)

From postmarketOS
Jump to navigation Jump to search
LG K40
LG K40 running PostMarketOS with Xfce4
LG K40 running PostMarketOS with Xfce4
Manufacturer LG
Name K40
Codename lg-mmh4x
Released 2019
Category testing
Original software Android 8.1
postmarketOS kernel 4.9.190
Hardware
Chipset MediaTek MT6765
CPU Octa-core 2 GHz Cortex-A53
GPU PowerVR Rogue GE8320
Display 720x1440 IPS
Storage 16 or 32 GB
Memory 2 GB
Architecture armv7
Unixbench Whet/Dhry score 3140.0
Features
USB Networking
Works
Flashing
Partial
Touchscreen
Works
Display
Works
WiFi
FDE
Broken
Mainline
Broken
Battery
Broken
3D Acceleration
Broken
Audio
Bluetooth
Broken
Camera
Broken
GPS
Mobile data
SMS
Calls
USB OTG
Works
NFC
Sensors
Accelerometer
Magnetometer
Ambient Light
Proximity
Hall Effect
Unavailable
Misc
Ir TX
Unavailable
TrustZone



Contributors

  • BenTheTechGuy

Users owning this device


How to enter flash mode

The LG K40 doesn't have a useful recovery mode (it's just a factory reset button), and fastboot doesn't exist at all on the device; the only possible mode is Download Mode, but that requires a signed image to flash.

Luckily, there's a tool called mtkclient that makes use of vulnerabilities in the MediaTek SoC itself, and that can be used to unlock the bootloader and flash images. It's also packaged in the AUR as mtkclient if you're using an Arch-based distro and don't want to install it from source.

In the below examples, the command mtk is used, but if you installed from source, you'll need to run python mtk inside the repo.

To enter into a mode that mtkclient can be used in, follow these steps:

  1. Power off the phone.
  2. Run an mtkclient command, like mtk printgpt.
  3. While mtkclient waits for the device, hold the phone's volume up button and plug it into the computer.
  4. mtkclient should output a lot of text at this point. When you see the words preloader or bootrom, you can release the volume up button.
  5. As long as mtkclient did its job properly, the command will succeed. Now, you can run other commands with mtkclient.

Unlocking the bootloader

  1. Enable developer options, and OEM Unlocking from there.
  2. When the phone reboots and you get back to the setup screen, power it off.
  3. Follow the steps in #How to enter flash mode to get into a mode where you can use mtk.
  4. Erase metadata and userdata (and md_udc if it exists):
    mtk e metadata,userdata,md_udc
    Note: If metadata or md_udc don't exist, just remove them from the command.
  5. Unlock the bootloader:
    mtk da seccfg unlock
  6. Reset mtkclient:
    mtk reset
  7. Unplug the phone and power on the device. You will have to go through setup again, and the bootloader should be unlocked.

Installation

Since we can't use recovery or fastboot, we need to manually flash the kernel, initramfs, and rootfs with mtkclient. First, you need to find out which slot is active, A or B. Normally this would be done with fastboot, but we don't have access to that, so we'll have to use adb.

adb shell /bin/getprop ro.boot.slot_suffix # will return either _a or _b, current active slot

pmbootstrap init # DRM is not supported yet, so Xfce4 is the best graphical option for now
pmbootstrap install
pmbootstrap export # symlink kernel, initramfs, and rootfs to /tmp for easy manual flashing

# get into a mode where you can use mtkclient
mtk w boot_a /tmp/postmarketOS-export/boot.img # flash kernel and initramfs to boot_a or boot_b depending on active slot
mtk w userdata /tmp/postmarketOS-export/lg-mmh4x.img # flash rootfs to userdata partition

mtk reset
# unplug the device, turn it back on, and enjoy PostMarketOS :)

See also