Help building LineageOS for LeEco (LeTV) LeMax 1 (X900/Max1) CN

ThE_MarD

Senior Member
Dec 10, 2014
2,741
3,221
203
Grande Prairie
Heyyo, heh well I'm not exactly bringing up a device from scratch, but I'm attempting to add max_plus to the LeEco Le Max 2 builds since they share a lot of the same msm8996 specific vendor files and kernel source code... It boots into TWRP and installs LineageOS 16.0 but the video lag is crazy and needs to be resolved.

Device bring up from scratch? Eh that's more difficult. I'd recommend for device trees though to find another device tree that has msm8994 and cloning those and then changing it to be compatible to your device

The kernel source code will be the tricky part... You'll need to find out the base kernel CAF tag it is based on and then copy and paste the LeEco kernel source code on top of it and make a new commit for that and push it to GitHub or GitLab so you can compare the changes and then from there you can try and import the important parts (arch/arm/boot/dts/qcom/ and drivers/ and firmware/ and sound/ and include/ ).

Here's a guide on how to try and find the kernel CAF tag that
http://www.abhishekan.me/android/kernel/2019/01/02/Finding-caf-tag-of-kernel.html

Good luck!
 

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
Thank you, @Palm Trees. Your hints are much appreciated! Well, I have these stock ROMs here:

MAX1_X900-CN-FN-CEXCNFN5501304131S-5.5.013S.zip
MAX1_X900-CN-FN-CEXCNFN5801810191S-5.8.018S.zip
MAX1_X900-CN-FN-CEXCNFN5902012221S-5.9.020S.zip
MAX1_X900-CN-FN-CEXCNFN5902303131S-5.9.023S.zip
MAX1_X900-CN-FN-CEXCNFN5902803208S-5.9.028S.zip

All but 028S contain a firmware-update folder. I wonder if is there any firmware upgrades between 23S and 28S. I tried to google for a 26S and found references (MAX1_X900-CN-FN-CEXCNFN5902605111S-5.9.026S.zip), but could not download the file. See this link: https://pan.baidu.com/s/1pKOIoYn?fid=13282999846334 this: https://yadi.sk/d/RPfdh3glmhzarw/26s. Hopefully "5.9.026S_sta 0511 update.zip" is the full 26S. And yes, it has a firmware-update folder, so I believe this is the latest firmware for X900.
 
Last edited:

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
Just to make clear, now I have these stock ROMs here:

MAX1_X900-CN-FN-CEXCNFN5501304131S-5.5.013S.zip
MAX1_X900-CN-FN-CEXCNFN5801810191S-5.8.018S.zip
MAX1_X900-CN-FN-CEXCNFN5902012221S-5.9.020S.zip
MAX1_X900-CN-FN-CEXCNFN5902303131S-5.9.023S.zip
MAX1_X900-CN-FN-CEXCNFN5902605111S-5.9.026S.zip
MAX1_X900-CN-FN-CEXCNFN5902803208S-5.9.028S.zip

And this one contains the latest firmware: MAX1_X900-CN-FN-CEXCNFN5902605111S-5.9.026S.zip

So one could theoretically install 026S directly, then upgrade to 028S.
 
Last edited:

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
Heyyo, heh well I'm not exactly bringing up a device from scratch, but I'm attempting to add max_plus to the LeEco Le Max 2 builds since they share a lot of the same msm8996 specific vendor files and kernel source code... It boots into TWRP and installs LineageOS 16.0 but the video lag is crazy and needs to be resolved.
That's nice! The worst part, you already got sorted. I wish I could be at this stage. :)

Device bring up from scratch? Eh that's more difficult. I'd recommend for device trees though to find another device tree that has msm8994 and cloning those and then changing it to be compatible to your device
Yes, that's what I tried to do. For - I think - three device trees (leeco x1, oneplus oneplus2 and leeco x2). I think the problem here is because android changed the way it deals with file_contexts, SELinux, etc on newer versions. Just a guess, of course. And, as LeEco messed up kernel's last_kmsg (see the first post on this thread for more info) and started a proprietary way of logging, I can't debug the problem in an easy way. :|

The kernel source code will be the tricky part... You'll need to find out the base kernel CAF tag it is based on and then copy and paste the LeEco kernel source code on top of it and make a new commit for that and push it to GitHub or GitLab so you can compare the changes and then from there you can try and import the important parts (arch/arm/boot/dts/qcom/ and drivers/ and firmware/ and sound/ and include/ ).

Here's a guide on how to try and find the kernel CAF tag that
http://www.abhishekan.me/android/kernel/2019/01/02/Finding-caf-tag-of-kernel.html
Actually I have the kernel source (LeEco released some sources in the past and I manage to get them), so this should just work, isn't it?

Well, let's keep trying. Thanks a lot for your message, @ThE_MarD. Really appreciated!
 

ThE_MarD

Senior Member
Dec 10, 2014
2,741
3,221
203
Grande Prairie
You're welcome @htimsxela but I wouldn't recommend just using the kernel source code directly from LeEco, as that kernel would be based on a very old build of marshmallow and wouldn't be compatible to potentially the newer vendor files from oneplus2, unless you plan on instead building a Marshmallow ROM.

What I'm trying to explain for finding the kernel CAF tag and then cloning it and then copy and past the LeEco kernel source on top and making that a commit? Is so you can see exactly what LeEco modified so you can then cherry-pick only the parts of their modifications to keep and dump stuff like their odd logging methods and then keep kmsg or better yet? Switch to pstore.

Here's for example what the zl1 kernel source code looks like (which also works for x2 since we share a lot of the same kernel source code).

https://github.com/GalaticStryder/a...mmit/f0d0e964d21f989538e49c2882c72f10dd9bddc3

And then from there you can only import the ones you want off of the latest kernel CAF tag.

https://github.com/LineageOS/androi...mmit/0dcecfacb30ac52d73d86655ba5236145bf92d88

As you can see from the two commits, we modified a lot less on our kernel which uses a much newer CAF tag than the original LeEco kernel :good:

Also, for LeEco specific vendor blobs? I would recommend sticking with official EUI ROM files as they are unmodified and then you would guaranteed be using the latest files that were built for your device.
 
  • Like
Reactions: htimsxela

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
Yes, this makes sense, @ThE_MarD. I went to the link you shared (http://www.abhishekan.me/android/kernel/2019/01/02/Finding-caf-tag-of-kernel.html) and I'm not sure I understood it right... For example:

Firstly, grab the zip or tar kernel source for your device and extract it.
Here, "kernel source for your device" means the official kernel from kernel.org or the vendor-modified kernel? For example, the kernel made available by LeTv is a patched kernel 3.10.84. Should I get 3.10.84 from kernel.org? the vendor's kernel.

What I did:

Code:
unzip -x ~/android/Le_Max_OpenSource.zip
cd LeMax_kernel/kernel
git init
git remote add msm https://source.codeaurora.org/quic/la/kernel/msm-3.10/
git fetch msm 'refs/tags/*:refs/tags/*'
git add .
git commit -m "First commit, right after unpacking kernel from kernel.org and fetching ms tags."
wget "https://raw.githubusercontent.com/LineageOS/scripts/master/best-caf-kernel/best-caf-kernel.py"
chmod +x best-caf-kernel.py
./best-caf-kernel.py "*-8x94.0"
The Python command gave me, in the end, this:
Code:
Best match
TAG: LA.BF64.1.2.2-04640-8x94.0
Lines changed: 435871
435871 lines are different. It sounds like a lot, but is it?

So I checked out the repository and created it in my git:

Code:
git fetch https://source.codeaurora.org/quic/la/kernel/msm-3.10.git LA.BF64.1.2.2-04640-8x94.0
git checkout FETCH_HEAD
git checkout -b letvmax1_merged_with_LNX.LA.0.0-34800-8x94.0
git remote add origin [email protected]:alexsmithbr/android_kernel_letv_max1_tests.git
git push -u origin master
Now, the article says:

...push the branch to your git repository and copy your kernel changes over the current CAF tag.
Does it means I have to unzip the LeTv kernel over the current git I created and look at the differences?
 
Last edited:

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
Yes, unzip over the CAF kernel, then

git add .
git commit

And then push that to GitHub or GitLab so you can see the modifications that LeEco made.
Ok, but the CAF is not a complete kernel, right? It's just a patch, if I understood it right. For example, the kernel from LeEco is based on official kernel version 3.10.84, so wouldn't it make sense to do like this?

1. Find the correct CAF (Code Aurora Forum Custom Aftermarket Firmware) patch (LA.BF64.1.2.2-04640-8x94.0)
2. Get kernel 3.10.84 from kernel.org
3. Apply CAF over this kernel
4. Commit everything up to this point
5. Unzip LeEco kernel over
6. Check the differences
 
Last edited:

Spunkination

Senior Member
Dec 29, 2018
69
8
0
Ok, but the CAF is not a complete kernel, right? It's just a patch, if I understood it right. For example, the kernel from LeEco is based on official kernel version 3.10.84, so wouldn't it make sense to do like this?

1. Find the correct CAF (Code Aurora Forum) patch (LA.BF64.1.2.2-04640-8x94.0)
2. Get kernel 3.10.84 from kernel.org
3. Apply CAF over this kernel
4. Commit everything up to this point
5. Unzip LeEco kernel over
6. Check the differences
Great work. You will get it working
 
  • Like
Reactions: Phsh

ThE_MarD

Senior Member
Dec 10, 2014
2,741
3,221
203
Grande Prairie
Ok, but the CAF is not a complete kernel, right? It's just a patch, if I understood it right. For example, the kernel from LeEco is based on official kernel version 3.10.84, so wouldn't it make sense to do like this?

1. Find the correct CAF (Code Aurora Forum) patch (LA.BF64.1.2.2-04640-8x94.0)
2. Get kernel 3.10.84 from kernel.org
3. Apply CAF over this kernel
4. Commit everything up to this point
5. Unzip LeEco kernel over
6. Check the differences
Heyyo, sorry for late reply, but that CAF tag IS a complete kernel. The tags are kind of like what stage the kernel was at for that Tag.

clone the kernel at that tag. unzip LeEco source code on top of it and then git add . and then git commit then push that as a new branch to GitHub so you have a reference of everything LeEco did to the kernel.
 
  • Like
Reactions: Phsh

MasterChief2

Senior Member
Dec 23, 2015
58
7
28
Well it's really sad for Le Pro and Max to stuck on Android 7.1 I use my Le 1 Pro US version for about four years, and I didn't have any problems with it. Last week I bought Le Max for 50 bucks and it's really good phone. One thing I don't understand is how is possible that there is huge number of ROMs for Le Max 2, but not for our Le Max? I mean the only differences between them is SoC (SD810 vs SD820) and screen size. Everything else, including camera, ram, resolution is same..
 

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
Hi, @MasterChief2! If you're suggesting we could use Max2 as a base, I already tried that and didn't succeed... Of course I'm far from being a ROM builder expert though... I certainly missed something. Other things that may have changed include, for example, the partition layout, etc... Do you have access to a Max2? We could use it to compare the internal structure, etc.
 
Last edited:

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
Some news...

I finally found some spare time to resume the works. I'm currently trying a new approach: instead of compiling an entire ROM, I'm now working to build a recovery build using TWRP (https://github.com/TeamWin) with Omni ROM (https://www.omnirom.org).

I know, it's all different... But I have some progresses to report.

Currently, I'm using a prebuilt kernel and I was able to find out it boots, but hangs in two different points: at /init and at loading /sepolicy. If I copy init AND sepolicy from a working recovery ramdisk, it boots fine. If I use the ones generated by the ROM build, it doesn't boot.

So my focus now is to compare init and sepolicy and find out what is different. After those are okay, I'll try to compile the kernel again.

Not a big progress, but seeing twrp booting (even knowing I'm using pre-compiled stuff) shined some light! ;)

Stay tuned.
 
  • Like
Reactions: Phsh and pop4xda

pop4xda

Senior Member
Oct 27, 2017
68
17
0
It's really good to hear that there is still development for this phone. I use this device as my secondary display for watching video/tv online when I use my desktop pc.

Thanks for keeping this up.
 

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
Last update of the day: kernel compiles fine and I'm being able to temporarily turn off selinux, so I can focus on the real problems. DTB images are being used from the kernel sources, so everything regarding kernel is working. The only problem now is with init. It works if I copy the binary from another working recovery, for example, but the one OmniROM provides is crashing. As I have no terminal to see what's happening, it is hard to get there. So, if init works, I'll have selinux to deal with. I tried to compile the latest git version of twrp and it worked. Do you also see lights? ;)

More to come tomorrow...
 

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
The news I have now are not as good as I wanted, but they are positive: I found a way to see the kernel messages without having to tear down my phone. :p

If you read this thread from the beginning, you'll remember I mentioned letv patched printk so that it would record messages to the initial 1MB of partition letvconfig2. By using shell command
Code:
string letvconfig2
, I wasn't able to read the last_kmsg, as kernel versions didn't match, so the patched printk doesn't write to letvconfig2... Well, then I had to make a special twrp with the same kernel version as the one I'm testing and it worked. Now I can read the logs - in a very primitive way, yes, but they're there. I'm doing like this:

1. Update whatever I want in the build tree.
2. Rebuild:
Code:
. ./build/envsetup.sh
lunch omni_max1-eng
mka -j4 showcommands recoveryimage
3. Put phone into bootloader:
Code:
adb reboot bootloader
4. Flash new image:
Code:
fastboot boot /home/android_build/android/omnirom_src/out/target/product/max1/recovery.img
At this point, the system will reboot into recovery and write last_kmsg to letvconfig2, so I pull it with:

Code:
adb pull /dev/block/bootdevice/by-name/letvconfig2 /tmp/letvconfig2
And read it with:

Code:
strings /tmp/letvconfig2 | vim -
All this to find things like the following:

Code:
.
.
.
init: alex init first stage started!f
init: SELinux:  Could not mount selinuxfs:  No such devicef
init: alex failed to load policy: No such deviceu
init: Security failure; rebooting into recovery mode...i
SysRq : Emergency Remount R/Ot
Emergency Remount completeR
usb_typec_i2c 3-0022: fusb300_set_mode=halt mode.SUBSYSTEM=i2c0
DEVICE=+i2c:3-00222
SMBCHG: aicl_done_handler: triggered, aicl: 650e
SMBCHG: increment_aicl_count: aicl count c:0 dgltch:0 first:0c
SMBCHG: smbchg_is_parallel_usb_ok: Not in fast charge, skipping
SMBCHG: smbchg_calc_max_flash_current: avail_iflash=-19708039, ocv=-22, ibat=780120, rbatt=99978=
ipa ipa_uc_state_check:246 uC is not loadedl
mdss_fb_release_all: try to close unopened fb 2! from pid:1 name:init2
mdss_fb_release_all: try to close unopened fb 1! from pid:1 name:init2
mdss_fb_release_all: try to close unopened fb 0! from pid:1 name:init2
last: set_panic_trig_rsn: from 0x7f to 0x41f
Restarting system with command 'recovery'.1
Going down for restart nowm
.
.
.
Don't mind the 'alex' string inside the logs... I'm testing init.cpp, etc.

In the end, all this to say the system is not working because of SELinux (note the "init: failed to load policy: No such device"). So, if I fix this, maybe init will work.

Well... The quest continues...
 
Last edited:

htimsxela

Senior Member
Sep 18, 2011
110
54
0
Arroio do Meio
I finally have some really good news! :)

TWRP 3.3.1-0 works on Letv Max1/X900! And all compiled from source!

I just committed these two repositories:

https://github.com/alexsmithbr/android_omni_device_letv_max1_recovery
https://github.com/alexsmithbr/android_omni_kernel_letv_msm8994

With them checked out inside of a OmniROM source tree, one should be able to compile a kernel, its DTBs and all necessary tools by issuing the following:

Code:
. ./build/envsetup.sh
lunch omni_max1-eng
mka recoveryimage
The version of TWRP inside OmniROM is 3.1.1, so one may want to get the latest version. Here, I did this:

Code:
cd bootable
mv recovery recovery-orig
git clone https://github.com/omnirom/android_bootable_recovery.git recovery
After this, just build the entire OmniROM (commands above).

If you want to test TWRP on your Max1/X900 device, you can download it from here:

https://mega.nz/#!fdkzVQKD!K7X2HeYKZD9gHFfKZT89suEzVZv2-d8UNA-SyPAeQcw

Just unzip the file and issue:

Code:
adb reboot bootloader
Then, if you want to test before flashing, issue:

Code:
fastboot boot twrp-3.3.1-0-max1_x900.img
To flash:

Code:
fastboot flash recovery twrp-3.3.1-0-max1_x900.img
That's all for now, folks! :)
 

Phsh

Member
Jul 3, 2008
25
1
0
Marseille
Happy to know that you are working with new ROM for le max 1, I can tell you it s really a good phone. I use it for 3 year. Now, still on eui 28s, as I need good caméra.
 
Last edited:
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone