[KERNEL] Moxie N7 / M12

Status
Not open for further replies.

bedalus

Senior Member
Jan 2, 2015
330
1,071
0
Chester
- Nougat version: this post -

BLX
Moxie provides Battery Longevity eXtension, a feature that I believe is currently unique to this project. BLX prevents your battery from charging to its full capacity. Why is this useful? Because charging your battery reduces its capacity over time. To help prevent this, I've designed this mod to cut off the battery charging earlier. (Testing of BLX: this post and rationalle: this page)

To enable BLX edit:
/sys/class/misc/batterylifeextender/charging_cap_level
to any value from zero (disabled) to 10 (full BLX). I've found that when using the DASH charger, 10 works well and limits the charging to about 80%. For non-OEM chargers, a value of 5 has the same effect.

Still using Marshmallow? (I am!)

Final M kernel: This Post

Coming from another custom (Marshmallow) kernel? Check this link!
Remember to hit thanks for NevaX1 :)



* * *

In order to comply with GPL, linux kernels may be modified and distributed so long as their source code and compilation tools are public, allowing anyone to reproduce an identical binary.
Toolchain: here
Kernel Source: https://github.com/bedalus/oneplus3kernel
Wifi Module Source: https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/qcacld-2.0

I accidentally vented a post on my development philosophy: here just in case anyone is interested in how I approach development!
 
Last edited:

bedalus

Senior Member
Jan 2, 2015
330
1,071
0
Chester
I realise this isn't very exciting (yet) but I'm posting here to keep a public log of this kernel development from scratch.

About me: I developed for the Nexus S ages ago! Left XDA but have since returned, hoping to keep things more low key.

Github commits

Commit fb944f9:
I just want to go over the build script a little for anyone who might like a little insight into the development process.
Code:
echo -e "Making OnePlus 3 kernel\n"
export PATH=$PATH:/opt/toolchain/lin531/bin/
export ARCH=arm64
export SUBARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make msm-perf_defconfig

make -j5

# modules
find ./ -type f -name '*.ko' -exec cp -f {} ../zip/system/lib/modules/ \;

# copy zImage
cp -f arch/arm64/boot/Image.gz-dtb ../zip/kernel/zImage
ls -l ../zip/kernel/zImage
cd ../zip
zip -r -9 op3_vN.zip * > /dev/null
mv op3_vN.zip /mnt/c/Users/bedal/Downloads/
I've got my cross compiler located at /opt/toolchain which I believe is pretty standard. The cross compiler is Linaro, although there are many other choices available. I've selected Linaro because they are a large professional organisation, and contribute a lot to development on ARM architectures. ARCH is short for Architecture, as you can see in the top lines. The export command just passes the target architecture to the compiler, so we can build binaries that will execute on ARM chips.

It's also worth noting that we are cross compiling since we are developing on a different platform to our target. In fact I'm using bash for Windows on a 64 bit Lenovo laptop! This is an AMD64 architecture, which used to be commonly known as x86_64.

Code:
make -j5
This sets the build off, then
Code:
find ./ -type f -name '*.ko' -exec cp -f {} ../zip/system/lib/modules/ \;
...is just a handy bit of code to find any modules and move them to the necessary spot in my 'zip' subfolder. As it happens I'm building only the WiFi module, as the wifi code appears to have a problem running when built into the kernel binary.

The rest of the code is fairly trivial. The zip file that you flash in Recovery is just the new kernel binary, plus the wifi module, plus a script that extracts your existing ramdisk from your ROM's boot partition, discarding the old kernel binary in favour of the new one, before re-integrating and flashing back to the boot partition. I may go into that in more detail in a later post.

Commit e5403fd:
I want to just briefly mention the file: sound/soc/codecs/tfa9890/tfa_container.c

In order to better ensure that the kernel works correctly, the compiler will report anything it sees as an error and stop compiling. When I first tried to build the kernel, one of the first errors I got was with this file. The warning the compiler gave me was something like 'in procedure blah-blah, an if statement will always evaluate to TRUE'. So why is this a problem? Because clearly the developer used an if statement so that a choice could be made. If the condition specified in the if statement evaluates to TRUE, do one thing, if not (ie FALSE) then do some other thing. So the compiler suggests caution, because clearly an if statement can only pick the first option if the condition is always going to be TRUE.

Code:
[COLOR="Red"]if (!prof->list[i].type == dscRegister) {[/COLOR]
[COLOR="SeaGreen"]if (prof->list[i].type == dscRegister) {[/COLOR]
My solution (above) shows the line that was removed in red, and the replacement in green, and it should be pretty obvious that the exclamation mark was removed, and no other changes were made.

The reason that I bring up this specific change is that I've seen other solutions to this problem in other dev's source code, and while they may trick the compiler into believing the problem is solved, really the problem is worse. Generally speaking, it is in fact possible, indeed probable that code will make it through the compiler just fine, even though when executed it will cause a fatal error (an error that cannot be recovered from, ie a crash). So what's up with this code?

The exclamation mark is shorthand in C for 'NOT'. NOT reverses a boolean value, ie Y becomes N, N would become Y, and TRUE -> FALSE and of course FALSE -> TRUE!

We can see in the code that it appears to be trying to invert the logic of a list type. Let's pretend it's a shopping list. So what would 'NOT shopping list' be? One thing that's not a shopping list? Or all the things that aren't shopping lists? It's a nonsensical proposition, and I think some developers have looked at the code and thought, 'huh, that's in the wrong place,' and have fixed it by taking it out of the brackets.

Code:
if !(prof->list[i].type == dscRegister) {
If you remember your high-school maths, the contents of brackets are always evaluated first. The fixed (wrongly) code now tests if one list type now matches another. That's fine, if it's a match then we get TRUE. If not then FALSE. Now we know if whether it's one or the other, the '!' will flip it. Then the if statement will progress to the next bit of code, doing whichever thing is required based on the outcome of the test.

That's all well and good. The compiler can see this and compile it without throwing an error. The problem is that the '!' shouldn't be there at all. If this wrong-code is ever executed, because the '!' has flipped the logic, the wrong path will be taken.

Any other devs who are reading this and know this may be the method they used to fix the compiler warning should take a good look at the code in that one file. It should be obvious that the '!' shouldn't have been there at all, and was probably a typo at the original development stage that wasn't picked up by their compiler (older compilers couldn't spot as many different kinds of problem).

Any discussion will be most welcome. This is the sort of thing I feel should be going on at XDA but seems to be conspicuously lacking in the development forums!
 
Last edited:

AlkaliV2

Senior Member
Jun 12, 2012
1,459
1,658
153
¯\_(ツ)_/¯
First and foremost, thank you for sharing post 2. That kind of stuff is why I really come here. With that said, I flashed your kernel and it lives up to the name. The kernel is fast and fluid with all my tasks. Thanks for sharing your work and development skills with us :good:
 

Attachments

  • Like
Reactions: bedalus

bedalus

Senior Member
Jan 2, 2015
330
1,071
0
Chester
First and foremost, thank you for sharing post 2. That kind of stuff is why I really come here. With that said, I flashed your kernel and it lives up to the name. The kernel is fast and fluid with all my tasks. Thanks for sharing your work and development skills with us :good:
I enjoyed writing it and I'll try to keep it up. I want to provide more insight into what each update has actually changed.
 

mixtapes08

Senior Member
Sep 23, 2011
3,750
1,741
253
Quezon City
Oh that's good to hear. :). Nexus 4,5,6p then op3. 4 and 5 are both sold already 6p on my girlfriend and I have op3 and the oldest nexus s that I use for alarm lol. How about you?

Oops I forgot the galaxy nexus that also sold already hehe.

Sent from my ONEPLUS A3000
 

bedalus

Senior Member
Jan 2, 2015
330
1,071
0
Chester
Oh that's good to hear. :). Nexus 4,5,6p then op3. 4 and 5 are both sold already 6p on my girlfriend and I have op3 and the oldest nexus s that I use for alarm lol. How about you?

Oops I forgot the galaxy nexus that also sold already hehe.
Yep, Nexus 4. I think I saw you over in that forum too IIRC. Then I got sick of it all, and rocked a dumb flip phone for a while. I thought I was in the matrix. Then I got a HTC One X plus, but it was too heavy, and I really didn't think the beats audio was that impressive. In fact I thought it sounded bad. Incidentally, I think the audio from the jack in the op3 sounds very good!

I later had a go with a Nokia 830, which was an excellent device, but as everyone says, Windows Mobile is a poor ecosystem. The OS itself was a bit ropey too.

I also had a Moto G 2nd gen at some point. Another solid device, but a bit too discrete for my taste! I then had a Sony X3 compact. A very nice device! But I broke the screen :(

I'm sure I'm forgetting some. But I felt the op3 was a total bargain at the price. I couldn't resist. It's a bit short on battery, but that's my only gripe.
 

aj8600

Senior Member
Aug 8, 2010
653
84
0
Eugene, OR
I am no dev and am probably asking a silly question. But could one compile the current cm14 N kernel with this and build a custom N kernel?

Sent from my ONEPLUS A3000 using Tapatalk
 

jukiewalsh

Senior Member
Sep 16, 2013
866
346
0
@bedalus
What is up with this thread theres no OP (1st post). no info at all
what is this kernel for OOS, CM, AOSP?
It says it's for stock on the OP, meaning OOS. Also if you click the GitHub link you'll see it's forked from the official stock OOS kernel source, as well as in the repo you'll see the branch is called stock.

So if I had to guess I'd say it's for stock ROM..
 

partridge79

Senior Member
May 25, 2015
820
352
93
41
Gardner
@jukiewalsh
I was using xdalabs and there was no OP at all the 1st page had 1 post from a moderator saying thread cleaned (hence my post saying theres NO OP. So no links to click either :eek: but coming back now i see that OP has been restored along with the rest of page 1. (Which has all the info i required) Must have been some maintenence being done to post thanks for the heads up tho ;)
 
Last edited:

jukiewalsh

Senior Member
Sep 16, 2013
866
346
0
@jukiewalsh
I was using xdalabs and there was no OP at all the 1st page had 1 post from a moderator saying thread cleaned (hence my post saying theres NO OP. So no links to click either :eek: but coming back now i see that OP has been restored along with the rest of page 1. (Which has all the info i required) Must have been some maintenence being done to post thanks for the heads up tho ;)
Ohh okay haha gotcha
 
Status
Not open for further replies.