Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new device support: OP7/OP7P #14

Closed
darkr4y opened this issue May 26, 2024 · 16 comments
Closed

new device support: OP7/OP7P #14

darkr4y opened this issue May 26, 2024 · 16 comments

Comments

@darkr4y
Copy link

darkr4y commented May 26, 2024

I will try to test this on Oneplus 7 Pro based on LineageOS, it would be nice to have a better guide for customizing the diff model. I will document the issues I encountered during my attempts in this issue and hopefully I can contribute some PR!

@seppzer0
Copy link
Owner

hi @darkr4y ,

it would be nice to have a better guide for customizing the diff model

There isn't one yet, but I might find some time to compose one at some point.

In the meantime I can suggest Kali NetHunter's git repo in GitLab -- it should have most of the kernel patches necessary for the modification.

And in the case of OP7 specifically, there seems to be some work done for it already. Problem is, it's outdated, but it can be a foundation for bringing NetHunter into latest LineageOS builds for OP7.

I will document the issues I encountered during my attempts in this issue and hopefully I can contribute some PR!

Sure, I don't have an OP7 myself, so it would be welcomed for someone to add a verified support for it here.

@darkr4y
Copy link
Author

darkr4y commented May 27, 2024

Thanks for the reply, I read the code as well as made the following attempts

  1. modified devices.json to add the appropriate device configuration
...
"guacamole": {
        "4.14": {
            "los": {
                "type": "git",
                "path": "android_kernel_oneplus_sm8150",
                "url": "https://github.com/LineageOS/android_kernel_oneplus_sm8150",
                "branch": "lineage-21",
                "commit": ""
            }
        }
    },

...
  1. after setting up the compilation environment, I tried it with python3 builder kernel --build-env=local --base=los --codename=guacamole --lkv=4.14 and some errors happened.
    error 1
  CC      kernel/panic.o
In file included from ../kernel/fork.c:105:
../include/trace/events/sched.h:269:2: error: "Unsupported NR_CPUS for lb tracepoint."
#error "Unsupported NR_CPUS for lb tracepoint."

error 2

  CC      mm/page-writeback.o
In file included from ../fs/exec.c:73:
../include/trace/events/sched.h:269:2: error: "Unsupported NR_CPUS for lb tracepoint."
#error "Unsupported NR_CPUS for lb tracepoint."
 ^
  AR      drivers/amba/built-in.o

error 3

 CC      drivers/input/mouse/psmouse-base.o
  CC      block/scsi_ioctl.o
../drivers/misc/oplus_motor/oneplus_motor.c:3019:16: error: implicit declaration of function 'devm_pinctrl_get' [-Werror,-Wimplicit-function-declaration]
        chip->pctrl = devm_pinctrl_get(chip->dev);
                      ^
../drivers/misc/oplus_motor/oneplus_motor.c:3019:14: error: incompatible integer to pointer conversion assigning to 'struct pinctrl *' from 'int' [-Werror,-Wint-conversion]
        chip->pctrl = devm_pinctrl_get(chip->dev);
                    ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
../drivers/misc/oplus_motor/oneplus_motor.c:3025:26: error: implicit declaration of function 'pinctrl_lookup_state' [-Werror,-Wimplicit-function-declaration]
        chip->free_fall_state = pinctrl_lookup_state(chip->pctrl, "free_fall_input");
                                ^
../drivers/misc/oplus_motor/oneplus_motor.c:3025:24: error: incompatible integer to pointer conversion assigning to 'struct pinctrl_state *' from 'int' [-Werror,-Wint-conversion]
        chip->free_fall_state = pinctrl_lookup_state(chip->pctrl, "free_fall_input");
                              ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings generated.
../drivers/misc/oplus_motor/oneplus_motor.c:3032:2: error: implicit declaration of function 'pinctrl_select_state' [-Werror,-Wimplicit-function-declaration]
        pinctrl_select_state(chip->pctrl,chip->free_fall_state);
        ^
../drivers/misc/oplus_motor/oneplus_motor.c:3032:2: note: did you mean 'pinctrl_lookup_state'?
../drivers/misc/oplus_motor/oneplus_motor.c:3025:26: note: 'pinctrl_lookup_state' declared here
        chip->free_fall_state = pinctrl_lookup_state(chip->pctrl, "free_fall_input");
                                ^
  AR      drivers/iommu/built-in.o
5 errors generated.

My question is
I don't seem to see the defconfig generation process for the corresponding device (I have tried it in my project https://github.com/darkr4y/Nethunter-Kernel-Builder/blob/main/.github/workflows/build.yml), in the code, KernelBuilder._defconfig seems to define the corresponding variable, the first two errors in my attempts are caused by defconfig generation

@seppzer0
Copy link
Owner

@darkr4y ,

I don't seem to see the defconfig generation process for the corresponding device

Yes, I see the issue.
I've updated both _defconfig and _ucodename functions in the dev branch, should resolve your problem.

error 3

This might be related to patch_ioctl function in the kernel builder.
Although maybe the defconfig-related fix will resolve this issue as well.

@darkr4y
Copy link
Author

darkr4y commented May 27, 2024

thx for reply, I switch to dev branch and keep testing.
I noticed that the -o parameter doesn't seem to be valid, the code shows that it's passing a parameter through an environment variable, but I didn't have time to debug to figure out why. use the tee command instead: python3 builder kernel --build-env=local --base=los --codename=guacamole --lkv=4.14 2>&1 | tee build_log.txt

  1. There is an error indicating that the cpio command is missing, perhaps this dependency can be added to the dockfile
  2. The other error is about the device tree
cat build_log.txt | grep -n ERROR -C 5

1401-  CC      fs/exfat/namei.o
1402-  CC      lib/mpi/mpi-cmp.o
1403-  DTC     arch/arm64/boot/dts/18821/sm8150-mtp-overlay.dtbo
1404-  CC      drivers/cpufreq/cpufreq_conservative.o
1405-Error: ../arch/arm64/boot/dts/18821/pm8150.dtsi:21.1-10 syntax error
1406:FATAL ERROR: Unable to parse input tree
1407-make[3]: *** [scripts/Makefile.dtbo:24: arch/arm64/boot/dts/18821/sm8150-mtp-overlay.dtbo] Error 1
1408-make[2]: *** [../scripts/Makefile.build:679: arch/arm64/boot/dts/18821] Error 2
1409-make[2]: *** Waiting for unfinished jobs....
1410-  AR      sound/soundcore.o
1411-  CC      crypto/ecdh.o
1412-  DTC     arch/arm64/boot/dts/18857/sm8150-mtp-overlay.dtbo
1413-  CC      drivers/clk/qcom/clk-spmi-pmic-div.o
1414-  CC      kernel/irq/dummychip.o
1415-Error: ../arch/arm64/boot/dts/18857/pm8150.dtsi:21.1-10 syntax error
1416:FATAL ERROR: Unable to parse input tree
1417-make[3]: *** [scripts/Makefile.dtbo:24: arch/arm64/boot/dts/18857/sm8150-mtp-overlay.dtbo] Error 1
1418-make[2]: *** [../scripts/Makefile.build:679: arch/arm64/boot/dts/18857] Error 2
1419-make[1]: *** [arch/arm64/Makefile:201: dtbs] Error 2
1420-make[1]: *** Waiting for unfinished jobs....
1421-  CC      net/core/stream.o

I checked the version of dtc used

./android_kernel_oneplus_sm8150/out/scripts/dtc/dtc -v
Version: DTC 1.4.4-g756ffc4f

I also specified the version which installed via apt

/usr/bin/dtc -v
Version: DTC 1.7.0

but there are still errors, which seem to be related to some compilation options in defconfig, could you give some advice?

@seppzer0
Copy link
Owner

@darkr4y ,

I noticed that the -o parameter doesn't seem to be valid

Yes, the logging system in the builder has been a problem, which is why the parameter is non-functional now. I've got plans on reworking it, but for now using tee is a valid option.

There is an error indicating that the cpio command is missing, perhaps this dependency can be added to the dockfile

You can try adding it in the Dockerfile and see if it fixes your issue. If it does, this can potentially be added in your PR.

The other error is about the device tree

Honestly, can't tell much about it. This requires a deeper analysis of the logs and the kernel source. Maybe if cpio is added, this will get resolved as well.

but there are still errors, which seem to be related to some compilation options in defconfig, could you give some advice?

Generally you could try looking into here. This should give an idea of what CONFIG_ declarations should be present in the defconfig file for the device.

Once you know what to change, the primary location of defconfig modification within the builder is here. You can add a condition for OP7 and add and/or remove specific CONFIG_ declarations.

@darkr4y
Copy link
Author

darkr4y commented Jun 2, 2024

thx for reply, I switch to dev branch and keep testing. I noticed that the -o parameter doesn't seem to be valid, the code shows that it's passing a parameter through an environment variable, but I didn't have time to debug to figure out why. use the tee command instead: python3 builder kernel --build-env=local --base=los --codename=guacamole --lkv=4.14 2>&1 | tee build_log.txt

  1. There is an error indicating that the cpio command is missing, perhaps this dependency can be added to the dockfile
  2. The other error is about the device tree
cat build_log.txt | grep -n ERROR -C 5

1401-  CC      fs/exfat/namei.o
1402-  CC      lib/mpi/mpi-cmp.o
1403-  DTC     arch/arm64/boot/dts/18821/sm8150-mtp-overlay.dtbo
1404-  CC      drivers/cpufreq/cpufreq_conservative.o
1405-Error: ../arch/arm64/boot/dts/18821/pm8150.dtsi:21.1-10 syntax error
1406:FATAL ERROR: Unable to parse input tree
1407-make[3]: *** [scripts/Makefile.dtbo:24: arch/arm64/boot/dts/18821/sm8150-mtp-overlay.dtbo] Error 1
1408-make[2]: *** [../scripts/Makefile.build:679: arch/arm64/boot/dts/18821] Error 2
1409-make[2]: *** Waiting for unfinished jobs....
1410-  AR      sound/soundcore.o
1411-  CC      crypto/ecdh.o
1412-  DTC     arch/arm64/boot/dts/18857/sm8150-mtp-overlay.dtbo
1413-  CC      drivers/clk/qcom/clk-spmi-pmic-div.o
1414-  CC      kernel/irq/dummychip.o
1415-Error: ../arch/arm64/boot/dts/18857/pm8150.dtsi:21.1-10 syntax error
1416:FATAL ERROR: Unable to parse input tree
1417-make[3]: *** [scripts/Makefile.dtbo:24: arch/arm64/boot/dts/18857/sm8150-mtp-overlay.dtbo] Error 1
1418-make[2]: *** [../scripts/Makefile.build:679: arch/arm64/boot/dts/18857] Error 2
1419-make[1]: *** [arch/arm64/Makefile:201: dtbs] Error 2
1420-make[1]: *** Waiting for unfinished jobs....
1421-  CC      net/core/stream.o

I checked the version of dtc used

./android_kernel_oneplus_sm8150/out/scripts/dtc/dtc -v
Version: DTC 1.4.4-g756ffc4f

I also specified the version which installed via apt

/usr/bin/dtc -v
Version: DTC 1.7.0

but there are still errors, which seem to be related to some compilation options in defconfig, could you give some advice?

for the dtc syntax error, I forget set DTC_EXT env vars, so the dtc binary used in building is always in another path (./android_kernel_oneplus_sm8150/out/scripts/dtc/dtc), to fix, I recommend using dtc from asop.:

git clone https://android.googlesource.com/platform/external/dtc
cd dtc
make -j=10
export PATH="$(pwd):$PATH"
export DTC_EXT=dtc

I'll test the availability of the nethunter kernel on a real OP7P phone, thx for reply :)

@darkr4y
Copy link
Author

darkr4y commented Jun 2, 2024

It's very strange, I confirmed from the compilation log that no errors were generated and the compilation was successful

...
make[1]: Leaving directory '/home/ninja/zero_kernel/android_kernel_oneplus_sm8150/out'
[ ✓ ] Done! Time spent for the build: 00:10:19

[ * ] Forming final ZIP file..
updating: META-INF/ (stored 0%)
updating: META-INF/com/ (stored 0%)
updating: META-INF/com/google/ (stored 0%)
updating: META-INF/com/google/android/ (stored 0%)
updating: META-INF/com/google/android/update-binary (deflated 73%)
updating: META-INF/com/google/android/updater-script (deflated 1%)
updating: modules/ (stored 0%)
updating: modules/system/ (stored 0%)
updating: modules/system/lib/ (stored 0%)
updating: modules/system/lib/modules/ (stored 0%)
updating: patch/ (stored 0%)
updating: tools/ (stored 0%)
updating: tools/ak3-core.sh (deflated 74%)
updating: tools/busybox (deflated 39%)
updating: tools/fec (deflated 40%)
updating: tools/httools_static (deflated 38%)
updating: tools/lptools_static (deflated 38%)
updating: tools/magiskboot (deflated 35%)
updating: tools/magiskpolicy (deflated 41%)
updating: tools/snapshotupdater_static (deflated 43%)
updating: anykernel.sh (deflated 68%)
[ ✓ ] Done!

but I don't see the kernel image in the zip file of anykernel package.

$ unzip -l kernel/zero-0.4.4-guacamoles-los-4.14.zip
Archive:  kernel/zero-0.4.4-guacamoles-los-4.14.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2024-06-01 14:05   META-INF/
        0  2024-06-01 14:05   META-INF/com/
        0  2024-06-01 14:05   META-INF/com/google/
        0  2024-06-02 00:11   META-INF/com/google/android/
    19948  2024-06-02 00:11   META-INF/com/google/android/update-binary
      115  2024-06-02 00:11   META-INF/com/google/android/updater-script
        0  2024-06-01 14:05   modules/
        0  2024-06-01 14:05   modules/system/
        0  2024-06-01 14:05   modules/system/lib/
        0  2024-06-02 00:11   modules/system/lib/modules/
        0  2024-06-02 00:11   patch/
        0  2024-06-02 00:11   tools/
    34024  2024-06-02 00:11   tools/ak3-core.sh
  1399484  2024-06-02 00:11   tools/busybox
   112836  2024-06-02 00:11   tools/fec
   497540  2024-06-02 00:11   tools/httools_static
   430756  2024-06-02 00:11   tools/lptools_static
   621588  2024-06-02 00:11   tools/magiskboot
   222004  2024-06-02 00:11   tools/magiskpolicy
  1718412  2024-06-02 00:11   tools/snapshotupdater_static
     3434  2024-06-02 00:11   anykernel.sh
---------                     -------
  5060141                     21 files

Reviewing the code reveals that only Image.gz-dtb will be packaged, and there is no such file in the compiled artifacts, why is this?

$ find ./out -type f -executable -newermt "today 10:00:00" -exec stat --format='%y %n' {} \;

2024-06-02 10:02:54.799243769 +0000 ./out/arch/arm64/boot/Image
2024-06-02 10:02:47.786311852 +0000 ./out/.tmp_vmlinux1
2024-06-02 10:02:50.202288397 +0000 ./out/.tmp_vmlinux2
2024-06-02 10:02:52.665264486 +0000 ./out/vmlinux

@seppzer0
Copy link
Owner

seppzer0 commented Jun 2, 2024

@darkr4y ,

Reviewing the code reveals that only Image.gz-dtb will be packaged, and there is no such file in the compiled artifacts, why is this?

For different Android kernels (at least that is the case for the non-GKI ones), the image file can exist in several formats, incl. Image.gz-dtb, Image and zImage-dtb.

With that said, according to currently existing OP7 kernel artifacts, the image file for this device should be Image.gz-dtb as well. This however may potentially vary because of different CONFIG_ declarations used in defconfigs for different kernel builds (the one from LineageOS may have extra added or removed due to extended device support).

In any case, Image is a valid kernel image format. You can try adding a custom rule into the create_zip function that if the build is for OP7 specifically, then not a Image.gz-dtb but a Image file instead is copied into the final AnyKernel3 zip.

If the final kernel zip works for the device properly, then it can be considered a success; if otherwise, then it would make sense to review the build modifications/settings/etc to narrow down the potential issue.

@darkr4y
Copy link
Author

darkr4y commented Jun 11, 2024

I tried to manually change the configuration of the defconfig specified in the kernel source directory to add the compilation option for Image.gz-dtb, but it didn't generate it, so I checked out/.config and found that the manually changed configuration wasn't present in the .config file, I didn't review the zero_kernel code very closely, so I wondered if there would have a parameter, which could be passed into a custom defconfig configuration path, and it could be used to override some of the variables in the original defconfig.

@seppzer0
Copy link
Owner

@darkr4y ,

I tried to manually change the configuration of the defconfig <..> but it didn't generate it <..>

That's expected, the builder resets the kernel source directory to a clean state each time it is launched, after which it applies all the patches -- including defconfig modification -- and starts the build.

This is intentional, so that each kernel build is free of any potential artifacts from any of the previous attempts. As mentioned before, the defconfig modification is primarily done in here. This way, no matter what unrelated to NetHunter CONFIG_ declarations are edited into the defconfig file by maintainer (e.g., LineageOS), the compiled kernel will always add the required functionality for the NetHunter platform while also staying fresh to maintainer's kernel source.

I can see though why this can be viewed as inconvenient. Your suggested idea sounds nice, and it should increase the testing speed of different defconfig configurations, without any of the dynamic modifications in internal builder functions. However, once testing is complete, the final configuration should be implemented within the mentioned functions, for the purpose detailed above.

I will have a look at this next week. I'll add this to the dev branch and let you know about it.

@seppzer0
Copy link
Owner

Hi @darkr4y ,

I have added a new --defconfig argument for the builder in the dev branch.
Feel free to try it out and see if it works for you.

@darkr4y
Copy link
Author

darkr4y commented Jun 23, 2024

With git pulling the latest code and switching to the dev branch, I tried to compile it with the following command
python3 builder kernel --build-env=local --base=los --codename=guacamole --lkv=4.14 --defconfig nethunter_defconfig 2>&1 | tee build_log.txt
I do confirm to add following content in the file nethunter_defconfig, the variable that affects the generation of Image.gz-dtb.

CONFIG_BUILD_ARM64_KERNEL_COMPRESSION_GZIP=y
# CONFIG_BUILD_ARM64_UNCOMPRESSED_KERNEL is not set

But only the following was generated

$ find ./android_kernel_oneplus_sm8150/out/arch/arm64/boot/Image*
./android_kernel_oneplus_sm8150/out/arch/arm64/boot/Image
./android_kernel_oneplus_sm8150/out/arch/arm64/boot/Image-dtb
./android_kernel_oneplus_sm8150/out/arch/arm64/boot/Image-dtb-hdr

and I did a little bit of research, seem custom defconfig not working

$ cat ./android_kernel_oneplus_sm8150/out/.config | grep -i compressed
CONFIG_BUILD_ARM64_UNCOMPRESSED_KERNEL=y

Review the code and it seems to be relevant here, modified it to confirm that it generates Image.gz-dtb.

$ git diff builder/core/kernel_builder.py
diff --git a/builder/core/kernel_builder.py b/builder/core/kernel_builder.py
index 5276851..9e5f7d9 100644
--- a/builder/core/kernel_builder.py
+++ b/builder/core/kernel_builder.py
@@ -487,7 +487,7 @@ class KernelBuilder(BaseModel, IKernelBuilder):
                 "arch" /\
                 "arm64" /\
                 "configs" /\
-                self.defconfig.name
+                self._defconfig.name
             )
         else:
             self.update_defconfig()

Also I found that the file Anykernel3.sh in zip seems to need to be modified as well, including:

  1. device checking is enabled, and the device name needs to be changed at the same time
...
# global properties
properties() { '
kernel.string=NetHunter Kernel for the OnePlus 7 Pro
do.devicecheck=1
do.modules=0
do.systemless=1
do.cleanup=1
do.cleanuponabort=0
device.name1=OnePlus7Pro
device.name2=guacamole
device.name3=OnePlus 7 Pro
...
  1. if the target machine has A/B slot, you need to change the configuration also.
block=/dev/block/bootdevice/by-name/boot;
IS_SLOT_DEVICE=1;

I flashed it through LineageOS's Recovery, and uname -a shows that it has indeed flashed successfully, but I've found some functionality issues

  1. WIFI function is not working properly
  2. Can't play sound and record sound

Try to use dmesg and adb logcat for investigation, but find nothing to follow, any guidance or help on this would be greatly appreciated!


Maybe I know the issue, the AnyKernel flashable zip does not contain any ko modules (LKM). When I try following, the WIFI works well.

## on zero_kernel bulid env
adb push ./zero_kernel/android_kernel_oneplus_sm8150/out//drivers/staging/qcacld-3.0/wlan.ko /data/local/tmp
adb root
adb shell

## on android
# overwrite the origin ko cuz toolchains is diff, insmod will be failed
mount | grep -i vendor
mount -o remount,rw /vendor
cd /vendor/lib/modules/
mv /data/local/tmp/wlan.ko wlan.ko qca_cld3_wlan.ko
# adb reboot

@seppzer0
Copy link
Owner

@darkr4y ,

Review the code and it seems to be relevant here, modified it to confirm that it generates Image.gz-dtb.

Seems like it was something I missed, good catch.

Also I found that the file Anykernel3.sh in zip seems to need to be modified as well

Yes, I'm assuming that this script should be different for OP7 when compared to OP5's.

Try to use dmesg and adb logcat for investigation, but find nothing to follow, any guidance or help on this would be greatly appreciated!

Interesting, while I did have rare Wi-Fi issues, the sound and recording issues are new to me. If I'm being honest, I can't yet provide something useful in regards to this.

Maybe I know the issue, the AnyKernel flashable zip does not contain any ko modules (LKM). When I try following, the WIFI works well.

I'm not sure that it should be this way, but you can try to pack the .ko file into the AnyKernel3 zip archive and execute these operations via the AnyKernel3 .sh script itself.

@darkr4y
Copy link
Author

darkr4y commented Aug 11, 2024

It's been too long since I've responded, so I guess it's time to summarize:

  1. In LineageOS 21 the /vendor/lib/modules is used to load vendor's drivers, compiling the kernel will compile the LKMs for these devices at the same time (e.g. WIFI), and in Defconfig you need to turn off MODULE_SIG, turn off MODVERSION, turn on MODULE_FORCE_LOADING
  2. Anykernel should pay attention to the mapping of the modules directory and the modules.dep, modules.alias files under /vendor/lib/modules when doing do.modules=1.

Finally, most of the functions are well done, and the another process is to apply Nethunter's driver code Patch, and turn on the compilation options for the necessary functions in Defconfig

REF:
https://source.android.com/docs/core/architecture/kernel/kernel-module-support
https://source.android.com/docs/core/architecture/kernel/loadable-kernel-modules

@seppzer0
Copy link
Owner

Hi @darkr4y ,

Yeah, I guess those are good observations. I have to admit I cannot comment too much on those notes as I've been looking more into GKI kernels, which work quite differently compared to non-GKI ones.

Let me know if you're still planning to finish adding support for OP7 in here. If not, feel free to close this issue ticket; I'll check it back in some time after, and if there's no change here I'll close it myself to not keep it hanging for too long, just FYI.

@seppzer0
Copy link
Owner

There hasn't been an update on this for quite some time, so I'm closing this issue thread.

@seppzer0 seppzer0 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants