anitsh / til

Today I Learn (til) - Github `Issues` used as daily learning management system for taking notes and storing resource links.
https://anitshrestha.com.np
MIT License
77 stars 11 forks source link

Install Linux on Sony Aqua Mobile #46

Open anitsh opened 4 years ago

anitsh commented 4 years ago

image

Objective:

The primary objective was to Root the phone. Current state is OS is erased.

Sony Phone Details

Name: Sony Xperia M4 Aqua Codename : Tulip Model : E2363 Operating system : Android 5.0 Lollipop (launch) Android 6.0.1 Marshmallow (current) System on chip : Qualcomm Snapdragon 615 CPU: Octa-core (1.5 GHz quad-core Cortex-A53 & 1.0 GHz quad-core Cortex-A53) GPU: Adreno 405 Memory: 2 GB RAM Storage: 16 GB Removable Storage:Up to 200 GB microSDXC https://en.wikipedia.org/wiki/Sony_Xperia_M4_Aqua

Concepts

image

Bootloader Bootloader is a piece of code that runs before any operating system is running. Bootloader are used to boot other operating systems, usually each operating system has a set of bootloaders specific for it. Bootloader is like BOIS to your computer. It is the first thing that runs when you boot up your Android device. It packages the instructions to boot operating system kernel. "A bootloader is a vendor-proprietary image responsible for bringing up the kernel on a device. It guards the device state and is responsible for initializing the Trusted Execution Environment (TEE) and binding its root of trust. The bootloader is comprised of many things including splash screen. To start boot, the bootloader may directly flash a new image into an appropriate partition or optionally use recovery to start the reflashing process that will match how it is done for over-the-air (OTA). Some device manufacturers create multi-part bootloaders and then combine them into a single bootloader.img file. At flash time, the bootloader extracts the individual bootloaders and flashes them all." - Google

Fastboot The fastboot protocol is a mechanism for communicating with bootloaders over USB or ethernet. It is designed to be very straightforward to implement, to allow it to be used across a wide range of devices and from hosts running Linux, macOS, or Windows. https://android.googlesource.com/platform/system/core/+/master/fastboot

Team Win Recovery Project (TWRP) https://twrp.me/sony/sonyxperias.html

Android Open Source Project (AOSP) https://source.android.com

Magisk Magisk is a suite of open source tools for customizing Android, supporting devices higher than Android 4.2. It covers fundamental parts of Android customization: root, boot scripts, SELinux patches, AVB2.0 / dm-verity / forceencrypt removals etc. https://github.com/topjohnwu/Magisk

Sony https://developer.sony.com/develop/drivers https://github.com/sonyxperiadev/kernel

Resource:

anitsh commented 4 years ago

Attempts to fix the phone


First Attempt


Second Attempt

State: Phone is usable but not rooted. Conclusion: Sony logo is spaced and goes to black screen.

I tried to override the existing OS following this link, mobile did not open.


Third Attempt

State: Unusable

  • It does not load Android. Just Sony icon is flashed on the screen and the screen goes black with orange LED.
  • It can be taken to fastboot mode. Blue LED, Black screen. Conclusion: Device was fastboot-ed by another system Lenovo Ubuntu 18.0.4. Hence, it could not be detected in Dell.

I tried to access the phone from another machine. Device Not Shown by either adb or fastboot in Dell Ubuntu 18.0.4 I got the hint to try out from:

https://askubuntu.com/questions/763668/fastboot-not-detect-my-android-device-ubuntu " I have same problem with fastboot in windows 10 but when iRoot installed the Lenovo driver fastboot detect device.But I cant find any driver Lenovo driver in Ubuntu."

jmtpfs

  • sudo apt-get install jmtpfs
  • jmtpfs -l : Does not list devices
  • jmtpfs ~/MOUNTDIR: Does not mount device, just tried in any case

mtp-tools

  • sudo apt install mtp-tools
  • mtp-detect does not show any device

To list the USB device and check if the phone is listed in the USB or not.

  • lsusb : Does not list
  • usb-devices : Does not list
  • dmesg | grep -i 'Sony Mobile Communications AB' : Lists too many, i.e. [50811.942605] usb 2-1.2: Manufacturer: Sony Mobile Communications AB [50889.220306] usb 2-1.2: Manufacturer: Sony Mobile Communications AB [50966.494105] usb 2-1.2: Manufacturer: Sony Mobile Communications AB [51043.803612] usb 2-1.2: Manufacturer: Sony Mobile Communications AB
  • dmesg GIves error 55730.535743] kauditd_printk_skb: 32 callbacks suppressed idVendor=0fce, idProduct=adde, bcdDevice= 1.00 Further research on error: " This just means you were getting a burst of audit messages and the kernel rate limited them. Based on the context these were probably apparmor "provfile_load" messages, which is not a problem. If you believe you are seeing actual problems related to this message, please reopen this bug."

Fourth Attempt

State: Unusable. Same as third attempt. Conclusion: Could not install as I am not sure how to install or what to install.

Check state Check the state of the phone and if the phone can be detected. Put the phone fastboot mode and commands to confirm.

lsusb ouput: Bus 002 Device 011: ID 0fce:0dde Sony Ericsson Mobile Communications AB Xperia Mini Pro Bootloader

usb-devices output: T: Bus=02 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 11 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=0fce ProdID=0dde Rev=01.00 S: Manufacturer=Sony Mobile Communications AB S: Product=S1Boot Fastboot S: SerialNumber=YT911623CW C: #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=256mA I: If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=42 Prot=03 Driver=(none)

fastboot devices output YT911623CW fastboot

adb devices gives empty list of attached devices

Install PostmarketOS Followed installation guides from https://wiki.postmarketos.org/wiki/Installation_guide Installed CLI tool pmbootstrap link It seems that this OS has support for the model https://wiki.postmarketos.org/wiki/Sony_Xperia_M4_Aqua_(sony-tulip)

anitsh commented 4 years ago

TODO:

anitsh commented 3 years ago

Fifth Attempt

Like 4th attempt, phone does not list in adb devices gives empty list of attached devices. The reason was simple, took sometime to figure out. And it's funny - How would adb detect any device when there isn't any android running in the device as I had flashed, removed kernel and android.

I was able to install Android 11 on the phone. Thanks to the link below. https://forum.xda-developers.com/m4-aqua/rom-android-11-mainline-linux-kernel-t4172351 https://forum.xda-developers.com/m4-aqua https://github.com/bartcubbins/device_sony_tulip-mainline

I also I tried the flash tool by Sony but unfortunately the software did not work in windows. https://developer.sony.com/develop/open-devices https://developer.sony.com/develop/open-devices/get-started/flash-tool/download-flash-tool

The Problem:

The problem that occurred the phone not reading sim cards. The probable reason could be required driver might not have been installed or even enabled. So I did some research on this. https://duckduckgo.com/?t=canonical&q=check+sim+card+on+android+from+adb&atb=v231-1&ia=web https://stackoverflow.com/questions/13640121/how-to-find-iccid-of-sim-in-android-device https://forum.xda-developers.com/general/general/adb-simcard-problem-t3025631: Same problem

Great description of the problem:


What causes Unknown Baseband / IMEI and issues detecting SIM Cards or Network signal on a Mediatek phone?

The primary cause is the wiping / corruption of the Secro and NVRAM (or NVDATA) partition(s). This could occur when you:

    Do a factory reset on the phone
    Format the phone using SP Flash tool or a Chinese box e.g Miracle Box, Volcano Box, Infinity Chinese Miracle II box etc
    Flash a custom ROM or not fully incompatible stock rom / firmware
    Tamper with your IMEI using an incompatible IMEI changer
    Format your partitions (without restoring) via a custom recovery e.g TWRP

Same problem but different phone: https://groups.google.com/g/android-building/c/L2NrPBjZqS8?pli=1 ` I am also able to flash the custom image and see my code changes. However, my phone does not have any radio connectivity. The About phone / Status mainly shows "Unknown" data for all the SIM card/network settings. When making phone calls it just says "Mobile network not available". The SIM Card works fine if I flash factory images.

Solution: I ended up switching to android-4.4.4_r1 and using the KTU84P drivers on https://developers.google.com/android/nexus/drivers android-4.4.4_r1 matches exactly KTU84P, so it will work. `

Following that, I searched if there would have been anything related to radio related firmware even installed, or needs to be installed separately as I saw in one of the blogs being done flashing radio image.

mRadioProxy for slot 1 is disabled [PHONE0]

So checked as below: Command: logcat -b radio Output: .... 11-06 02:24:13.670 378 378 D TelephonyManager: No /proc/cmdline exception=java.io.FileNotFoundException: /proc/cmdline: open failed: EACCES (Permission denied) ... 0-04 05:53:31.421 813 813 D CdmaSSM : subscriptionSource from settings: 0 10-04 05:53:31.422 813 813 I PhoneFactory: Cdma Subscription set to 0 10-04 05:53:31.423 813 813 I PhoneFactory: Network Mode set to 0 10-04 05:53:31.424 813 813 D RILJ : RIL: init preferredNetworkType=0 cdmaSubscription=0) [PHONEnull] 10-04 05:53:31.442 813 813 E RILJ : getRadioProxy: mRadioProxy for slot1 is disabled [PHONE0] 10-04 05:53:31.443 813 813 E RILJ : getRadioProxy: mRadioProxy == null [PHONE0] 10-04 05:53:31.444 813 813 E RILJ : getRadioProxy: mRadioProxy for slot1 is disabled [PHONE0] 10-04 05:53:31.444 813 813 E RILJ : getRadioProxy: mRadioProxy == null [PHONE0] 10-04 05:53:31.446 813 813 E RILJ : IOemHook service is not on the device HAL: java.util.NoSuchElementException [PHONE0]

So there is another room to check.

And lastly it's not a problem but there is a message related performance: image https://stackoverflow.com/questions/34356844/how-to-disable-serial-consolenon-kernel-in-u-boot https://www.programmersought.com/article/88461283928 https://stackoverflow.com/questions/60388041/serial-console-enabled-performance-is-impacted-to-disable-check-bootloader

Note from https://stackoverflow.com/questions/60388041/serial-console-enabled-performance-is-impacted-to-disable-check-bootloader: ` 1) What is a Serial Console? The serial console is a connection over the RS-232 or serial port connection that allows a person access to a computer or network device console. And a serial port is a serial communication interface through which information transfers in or out sequentially one bit at a time.

2) Why needed to enable serial console in emulator? By enabling serial console in android emulator , developers can test serial port based applications in emulatior.

3) Why it related with bootloader? To disable or enable serial console we need to change the android kernal configuration. For know more about changing kernal configurations Refer these links, http://bootloader.wikidot.com/linux:android:serial https://gist.github.com/yan12125/78a9004acb1bed5faf2ffd442163e2ef In conclusion, With Serial console enabled in andorid emulatior, the developer can use emulatior to develop and test serial port based devices or hardwares. If you want to disable serial console, you need to download kernal source code google provided https://gist.github.com/yan12125/78a9004acb1bed5faf2ffd442163e2ef `

fastboot and adb commands, other commands

https://phonlabtech.com/list-of-adb-and-fastboot-commands/ https://androidmore.com/adb-fastboot-commands/ https://developer.android.com/studio/command-line/adb https://developer.android.com/studio/command-line https://stackpointer.io/mobile/android-adb-shell-dial-number-trick/382 https://stackoverflow.com/questions/4923550/how-to-make-a-call-via-pc-by-adb-command-on-android https://www.maketecheasier.com/things-you-could-do-with-adb/

Kernel, Compiling Kernel and Image Creation

https://www.netzgewitter.com/2013/10/compiling-android-linux-kernel-for-xperia/ https://developer.sony.com/develop/open-devices/guides/aosp-build-instructions/build-aosp-android-android-11-0-0

Bootloader

A bootloader is a computer program that loads an operating system (OS) or runtime environment for the computer after completion of the self-tests. —Wikipedia:booting

image

The bootloader configures the device to an initial known state and has a means to select where to start executing the kernel. It can allow you to make this selection, which allows the user, among other things, to load an alternative Linux kernel, or Windows. Because the bootloader is an essential component of the boot process, it is stored in non-volatile memory, such as flash memory.

Bootloaders are written by hardware vendors and are specialized for the hardware they run on.

For Android devices, the bootloader typically starts either Android or Recovery. Android bootloaders often have a basic interactive mode that can be triggered by holding the "volume down" button while the bootloader is executing.

https://en.wikipedia.org/wiki/Booting https://forum.xda-developers.com/wiki/SPL

https://developer.sony.com/develop/open-devices

Android File System

/system is the main Android directory for storing immutable components generated by the build of the AOSP. This includes native binaries, native libraries, framework packages, and stock apps. It’s usually mounted read-only from a separate image from the root file system, which is itself mounted from a RAM disk image.

Android also includes many directories commonly found in any Linux system, such as /dev, /proc, /sys, /sbin, /root, /mnt, and /etc. These directories often serve similar if not identical purposes to the ones they serve on any Linux system, although they are very often trimmed down, as is the case of /sbin and /etc, and in some cases are empty, such as /root.

More than 150 command-line utilities are scattered throughout Android’s root file system. /system/bin contains the majority of them, but some “extras” are in /system/xbin, and a handful are in /sbin.

/sbin: In Linux, this would hold binaries essential to the system administrator. In Android, it contains only ueventd and adbd.

/bin: All native binaries and daemons built as part of the AOSP. All modules built with BUILD_EXECUTABLE are here. The only exception is adbd, which has the LOCAL_MODULE_PATH set to /sbin and is therefore installed there instead.

/xbin: “Extra” binaries generated by some of the packages that are built within the AOSP but aren’t essential to the system’s operation.

Sony devices support chart

image https://developer.sony.com/develop/open-devices/get-started/supported-devices-and-functionality/

Other resources:

TODO

anitsh commented 3 years ago

Sixth Attempt

The objective this time was to understand how the images were created from the solution form: https://forum.xda-developers.com/t/rom-android-11-mainline-linux-kernel-for-sony-xperia-m4-aqua.4172351

That led to learning more about Linux and Android as before.

How to Create An Android USB Drive https://www.lifewire.com/create-android-usb-drive-2202053 Flash OS images to SD cards & USB drives, safely and easily. https://github.com/balena-io/etcher Moving Fastboot to Userspace https://source.android.com/devices/bootloader/fastbootd Generic Kernel Image https://source.android.com/devices/architecture/kernel/generic-kernel-image

Furthermore, I also checked for to see if the radio was working or not as time I checked for IMEI which was not registered or empty and relate these issues.

I found a video on - Installing PostmarketOS on a Pinephone using Pmbootstrap https://www.youtube.com/watch?v=QPp6-B--BPY The process seems relatively easy with the installer tool https://libraries.io/github/postmarketOS/pmbootstrap

So I did some search based on this https://wiki.postmarketos.org/wiki/Installation_guide https://github.com/postmarketOS

anitsh commented 3 years ago

7th Attempt

anitsh commented 3 years ago

Found another open source software: https://e.foundation

anitsh commented 3 years ago
anitsh commented 3 years ago

Found these resource while learning about Ubuntu Touch.

anitsh commented 3 years ago

8th

Followed build process from here: https://developer.sony.com/develop/open-devices/guides/aosp-build-instructions/build-aosp-nougat-marshmallow-6-0-1

Step 4 : repo sync is complete.

anitsh commented 3 years ago

9th

Continue from 8th

Issue: repo init -u https://android.googlesource.com/platform/manifest -b android-6.0.1_r81 /usr/bin/env: ‘python’: No such file or directory

Fix:

nano ~/bin/repo
Update #!/usr/bin/env python` to `#!/usr/bin/env python3

Should have worked on this: https://developer.sony.com/develop/open-devices/guides/aosp-build-instructions/build-aosp- marshmallow-6-0

In this tutorial in step 4 Find and download the software binaries for the device you want to use on Sony’s AOSP for Xperia devices, there is not binaries.

But instead I worked with https://developer.sony.com/develop/open-devices/guides/aosp-build-instructions/build-aosp-nougat-marshmallow-6-0-1which did not have the firmware I guess.

It did not work with 6.0. There was some python path error.

anitsh commented 1 year ago

https://forum.xda-developers.com/t/rom-android-11-mainline-linux-kernel-for-sony-xperia-m4-aqua.4172351 This method is still the status. DOES NOT HAVE A FULLY FUNCTIONAL VERSION.

Downloaded FTF firmware file. Unzipped it. Contains .sin files and .xml for as a boot loader.

The best way is to use Sony's own software updater and installer. https://www.sony.com/electronics/support/articles/00236877 https://www.sony.com/electronics/support/articles/SX533901

https://forum.xda-developers.com/t/guide-root-extracting-boot-img-and-rooting-xperia-xa1.3872077/ https://android.googlesource.com/platform/system/core/+/master/fastboot https://www.xperiablog.net/2016/03/12/install-xperia-marshmallow-using-flashtool-and-xperifirm-guide/

https://github.com/Androxyde/Flashtool/issues/98

lm2lm2 commented 3 months ago

hello

thank you for all your work and feedback i own a e2333 xperia m4 aqua dual sim, i'd like to know how could i push off android stock from sony (andro5), to get something else, twrp based, with eg lineageos 14 or postmarketos?

thank you!