T-Virus - Infect your Nokia 8 with Project Treble (2019-07-02)

Search This thread

THMSP

Senior Member
Jul 19, 2018
138
250
Europe
tmsp.io
Code:
#include <std_disclaimer.h>

/*
 * Your warranty is now void.
 *
 * I am not responsible for bricked devices, dead SD cards,
 * thermonuclear war, or you getting fired because the alarm app failed. Please
 * do some research about modifying your android system before flashing this! 
 * YOU are choosing to make these modifications, and if you point the finger at 
 * me for messing up your device, I will laugh at you. Hard. A lot.
 */
(if you expected the Resident Evil references to stop, you just got gnomed)

What is this?
T-Virus (for treble-virus) is a tool that takes a stock Nokia 8 firmware and "infects" it with various parts from the Nokia 8 Sirocco firmware, generating a firmware bundle that is compilant with Project Treble and that can be flashed to a Nokia 8 using NOST.

Firmware Sources
The base of T-Virus is the stock Nokia 8 firmware image (5150 / April Security patch at the time of writing). When being run, the build script takes those files and replaces the partition table with the one from Nokia 8 Sirocco. This required for creating a vendor partition that the stock Nokia 8 does not have. The vendor image is taken from the Sirocco firmware as well. During the build, the vendor image is mounted as rw, and various files are copied over from the stock Nokia 8 system image, or get patched to properly support the minor hardware differences between the two phones. Those actions are defined through very basic scripts inside of the vendor folder in the repository.
The boot image is a modified version of my umbrella kernel, which has support for early mounting vendor. It also includes a TWRP build with full support for Project Treble.

SELinux Hell
Because Android does some very weird stuff with SELinux contexts, you cannot launch a service file when it has an unknown context. We have to fix that by force-setting the SELinux context manually, but due to how SELinux works, this is only possible on a Linux system without SELinux. This means, that you cannot build this on a distribution with SELinux (Fedora in my case). I fixed the problem by building the images in a Ubuntu VM.

How to build?
First you have to download the latest firmware image from https://tmsp.io/fs/xda/nb1/firmware, and the exdupe tool from https://www.quicklz.com/exdupe
Extract the firmware into a folder and then clone the repository, like this:
Code:
 $ mkdir firmware 
 $ ./exdupe -R ~/Downloads/NB1-5150-0-00WW-B03.qlz firmware/ 
 $ git clone https://github.com/resident-nokia/t-virus 
 $ cd t-virus
The build script has two options you have to set: a version and the path to the extracted firmware. This means you have to run it like this:
Code:
 $ ./build.sh --version v0.1 --firmware ../firmware
Leave it running and when it asks you, enter your sudo password. This is required to mount the Android ext4 partitions and edit the files that are only accessable by the (Android) root user, and retain their permissions.
When the script has finished the flashable firmware image will be inside of the out folder. You can optionally package this as a .qlz file again using exdupe.

What works?
  • It boots
  • Data decryption in recovery
  • Flashing GSIs / OpenGApps in recovery
  • WiFi
  • Mobile Data
  • Bluetooth
  • Sound
  • Vibration
  • Calling
  • Hardware buttons
  • Fingerprint
  • Camera
  • GPS
  • NFC
  • SDCard
  • Multi SIM
  • 4k Video

What doesn't work, or isn't tested
  • Haptic feedback for Hardware buttons
  • Bluetooth headphones don't get registered properly
  • Nokia OZO audio support is missing
  • Fingerprint sensor is reported as being on the back of the phone
  • There might be issues with USB transfer under Windows
  • VoLTE (untested)

How to install?
WARNING: This might not be useable as a daily driver. Continue only if you are able to troubleshoot things if neccessary (bootloops, bricking the phone, causing the alarm app to declare nuclear war)

You can download the latest release from the releases page on the repository. It is a .qlz firmware, so you will have to flash it through NOST. You will need a completely unlocked bootloader. When flashing, make sure to select the "Erase Userdata" option, not doing this will most certainly bootloop the phone.
After the installation completed, your phone will reboot into phh's AOSP GSI. If you want to use a different GSI (you most likely will), follow these steps:

  • Download your favorite GSI
  • Unpack every form of compression, so you end up with a .img file
  • Boot into recovery
  • Copy the .img to the internal storage of your phone, or to your SDCard
  • Select "Install" -> "Install .img", select the image file you copied and flash it to your system partition
  • Then install OpenGApps or any other modifications you like.
  • Wipe /data to allow the new system image to boot properly and then reboot
To update to a newer version without having to erase userdata, download the zipped vendor image from the release page, and flash the image inside in TWRP.
If you want to go back to stock, simply download the 5150-revert firmware and flash it with NOST, with the "Erase Userdata" option enabled. It will revert all changes T-Virus made to your phone. Firmwares from https://tmsp.io/fs/xda/nb1 will not work.

Links?

What if I have a bug?
  • Upload a proper bugreport. This means logcat and dmesg. If you don't know how to get them, google it. Also, describe the issue and provide steps to replicate it. Everything else will be ignored.
  • I don't daily drive this phone anymore. I am doing this just because it is an interesting technical challenge. I don't have as much motivation to fix bugs than someone who daily drives it.
I want to say thank you!
I usually don't do this, but since this involved a lot of work on my side, I would be grateful if you would want to say thank you by buying me a coffee (or two): https://paypal.me/thmsp
 
Last edited:

kosmatyj

Senior Member
Oct 18, 2012
118
21
Ok. After the flashing we have a phone "infected" by the Project Treble. But what it gives to end-user? What is profit of this?
 

kosmatyj

Senior Member
Oct 18, 2012
118
21
Oh! Sounds pretty good! Thanks. Will think about it. Really expands posiibilities and needs to be tested.

---------- Post added at 10:54 ---------- Previous post was at 10:29 ----------

Q: Should Ihave an Android Pie be installed first or it can be flashed over ony ROM version (I currently have Nougat ROM installerd on my Nokia 8)?
 

THMSP

Senior Member
Jul 19, 2018
138
250
Europe
tmsp.io
Q: Should Ihave an Android Pie be installed first or it can be flashed over ony ROM version (I currently have Nougat ROM installerd on my Nokia 8)?
It could work, since it is a modified firmware for reflashing, but just to be sure, update to Pie through OTA. That's what this has been tested with and you won't update your bootloader in the process which eliminates some possible incompatibilities.
 
  • Like
Reactions: kosmatyj

kosmatyj

Senior Member
Oct 18, 2012
118
21
What is password for t-virus-20190703.qlz? Should I flash the TV-20190703-vendor.zip before or t-virus-20190703.qlz is all I need?
 

THMSP

Senior Member
Jul 19, 2018
138
250
Europe
tmsp.io
What is password for t-virus-20190703.qlz? Should I flash the TV-20190703-vendor.zip before or t-virus-20190703.qlz is all I need?
It's all in the instructions. There is no password on the qlz file. You can't extract it, you have to flash it using NOST. The zip is for updating from previous versions and not for the initial installation.
 

kosmatyj

Senior Member
Oct 18, 2012
118
21
Oh, I understood. No need to unpack, just download and flash over NOST, right? Thanks ones more. It is new for me, that`s why I have so much questions.
 
Last edited:

THMSP

Senior Member
Jul 19, 2018
138
250
Europe
tmsp.io
Oh, I understood. No need to unpack, just download and flash over NOST, right? Thanks ones more. It is new for me, that`s why I have so much questions.
Yes. Just follow the instructions in NOST and select the T-Virus .qlz when it asks you to. Also, make sure you select the "Erase Userdata" option in the drop down menu that appears after selecting the .qlz.
 
  • Like
Reactions: kosmatyj

kosmatyj

Senior Member
Oct 18, 2012
118
21
Hello! Author, don`t you planning to build the same but for Android 8.1? Your work is great anyway but would be just amazing to have an Oreo in this appearance. Thank you.
 
Last edited:

kosmatyj

Senior Member
Oct 18, 2012
118
21
Nah! Didn`t work. After "android" logo it drops into download mode. AOSP 32 (last version of A 8.1 GSI).
 

THMSP

Senior Member
Jul 19, 2018
138
250
Europe
tmsp.io
Right, I did exactly like you said. system-arm64-ab-vanilla-nosu - image that I flashed couple minutes ago. Downloaded from here: https://github.com/phhusson/treble_experimentations/releases/tag/v32
I`m sorry about my English. I`m Russian.
Ok, then it probably doesn't work the other way around (Oreo with Pie vendor). An Oreo-based T-Virus is unlikely to happen though, because Siroccos Oreo vendor has some problems (calls not going through properly), and I dont want to maintain two versions of it because, as said in the OP, I don't use my Nokia 8 anymore. It seems like Pie is all you can get with this for now, sorry.
 

just4me12

Member
Dec 11, 2015
15
3
Hi all. Just to make it clear. The procedure for the Nokia 8 is:
1. Unlock Bootloader
2. Do "critical unlock" (fastboot flashing unlock_critical)
3. Flash "t-virus-20190703.qlz" with NOST?

Did i miss something? Whats with Security Enabled Linux?
 
Last edited:

KonikoO

Senior Member
Sep 8, 2015
86
24
Hi all. Just to make it clear. The procedure for the Nokia 8 is:
1. Unlock Bootloader
2. Do "critical unlock" (fastboot flashing unlock_critical)
3. Flash "t-virus-20190703.qlz" with NOST?

Did i missed something? Whats with Security Enabled Linux?

That's right. Don't forget to add "erase data" option while flashing t virus with NOST otherwise you'll end up in a bootloop.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 25
    Code:
    #include <std_disclaimer.h>
    
    /*
     * Your warranty is now void.
     *
     * I am not responsible for bricked devices, dead SD cards,
     * thermonuclear war, or you getting fired because the alarm app failed. Please
     * do some research about modifying your android system before flashing this! 
     * YOU are choosing to make these modifications, and if you point the finger at 
     * me for messing up your device, I will laugh at you. Hard. A lot.
     */
    (if you expected the Resident Evil references to stop, you just got gnomed)

    What is this?
    T-Virus (for treble-virus) is a tool that takes a stock Nokia 8 firmware and "infects" it with various parts from the Nokia 8 Sirocco firmware, generating a firmware bundle that is compilant with Project Treble and that can be flashed to a Nokia 8 using NOST.

    Firmware Sources
    The base of T-Virus is the stock Nokia 8 firmware image (5150 / April Security patch at the time of writing). When being run, the build script takes those files and replaces the partition table with the one from Nokia 8 Sirocco. This required for creating a vendor partition that the stock Nokia 8 does not have. The vendor image is taken from the Sirocco firmware as well. During the build, the vendor image is mounted as rw, and various files are copied over from the stock Nokia 8 system image, or get patched to properly support the minor hardware differences between the two phones. Those actions are defined through very basic scripts inside of the vendor folder in the repository.
    The boot image is a modified version of my umbrella kernel, which has support for early mounting vendor. It also includes a TWRP build with full support for Project Treble.

    SELinux Hell
    Because Android does some very weird stuff with SELinux contexts, you cannot launch a service file when it has an unknown context. We have to fix that by force-setting the SELinux context manually, but due to how SELinux works, this is only possible on a Linux system without SELinux. This means, that you cannot build this on a distribution with SELinux (Fedora in my case). I fixed the problem by building the images in a Ubuntu VM.

    How to build?
    First you have to download the latest firmware image from https://tmsp.io/fs/xda/nb1/firmware, and the exdupe tool from https://www.quicklz.com/exdupe
    Extract the firmware into a folder and then clone the repository, like this:
    Code:
     $ mkdir firmware 
     $ ./exdupe -R ~/Downloads/NB1-5150-0-00WW-B03.qlz firmware/ 
     $ git clone https://github.com/resident-nokia/t-virus 
     $ cd t-virus
    The build script has two options you have to set: a version and the path to the extracted firmware. This means you have to run it like this:
    Code:
     $ ./build.sh --version v0.1 --firmware ../firmware
    Leave it running and when it asks you, enter your sudo password. This is required to mount the Android ext4 partitions and edit the files that are only accessable by the (Android) root user, and retain their permissions.
    When the script has finished the flashable firmware image will be inside of the out folder. You can optionally package this as a .qlz file again using exdupe.

    What works?
    • It boots
    • Data decryption in recovery
    • Flashing GSIs / OpenGApps in recovery
    • WiFi
    • Mobile Data
    • Bluetooth
    • Sound
    • Vibration
    • Calling
    • Hardware buttons
    • Fingerprint
    • Camera
    • GPS
    • NFC
    • SDCard
    • Multi SIM
    • 4k Video

    What doesn't work, or isn't tested
    • Haptic feedback for Hardware buttons
    • Bluetooth headphones don't get registered properly
    • Nokia OZO audio support is missing
    • Fingerprint sensor is reported as being on the back of the phone
    • There might be issues with USB transfer under Windows
    • VoLTE (untested)

    How to install?
    WARNING: This might not be useable as a daily driver. Continue only if you are able to troubleshoot things if neccessary (bootloops, bricking the phone, causing the alarm app to declare nuclear war)

    You can download the latest release from the releases page on the repository. It is a .qlz firmware, so you will have to flash it through NOST. You will need a completely unlocked bootloader. When flashing, make sure to select the "Erase Userdata" option, not doing this will most certainly bootloop the phone.
    After the installation completed, your phone will reboot into phh's AOSP GSI. If you want to use a different GSI (you most likely will), follow these steps:

    • Download your favorite GSI
    • Unpack every form of compression, so you end up with a .img file
    • Boot into recovery
    • Copy the .img to the internal storage of your phone, or to your SDCard
    • Select "Install" -> "Install .img", select the image file you copied and flash it to your system partition
    • Then install OpenGApps or any other modifications you like.
    • Wipe /data to allow the new system image to boot properly and then reboot
    To update to a newer version without having to erase userdata, download the zipped vendor image from the release page, and flash the image inside in TWRP.
    If you want to go back to stock, simply download the 5150-revert firmware and flash it with NOST, with the "Erase Userdata" option enabled. It will revert all changes T-Virus made to your phone. Firmwares from https://tmsp.io/fs/xda/nb1 will not work.

    Links?

    What if I have a bug?
    • Upload a proper bugreport. This means logcat and dmesg. If you don't know how to get them, google it. Also, describe the issue and provide steps to replicate it. Everything else will be ignored.
    • I don't daily drive this phone anymore. I am doing this just because it is an interesting technical challenge. I don't have as much motivation to fix bugs than someone who daily drives it.
    I want to say thank you!
    I usually don't do this, but since this involved a lot of work on my side, I would be grateful if you would want to say thank you by buying me a coffee (or two): https://paypal.me/thmsp
    3
    What about ozo audio config?

    yeah, I'd like that, too, also fully working camera, i.e. with dual-camera.
    Just lack the knowledge on how to determine which libs and configs are needed for that.

    The credits for the compass fix actually should go to @kosmatyj :good:
    3
    Hi THMSP:

    May I ask if you would port the Android 10 from Nokia 8 Sirroco to Nokia 8, just as what you did on Android 9?
    Also, will you release the rom for this build as well ?

    For that there would have to be an Android 10 update for Sirocco first. And that probably won't happen for some time. So I am going with a definitive maybe.

    In theory, you can use Android 10 with the Android 9 vendor already. But there is a problem with that approach: The binaries that had to be added to the Sirocco vendor were taken from the Nokia 8 firmware, and therefor never setup to work with Treble. They reference libraries that are stored on the system partition directly. And this means that they use APIs that existed in Android 9 but that were removed / changed in Android 10. If they would use the Treble APIs for that, it wouldn't be an issue, but they don't. This is the reason why if you flash an Android 10 GSI the hardware buttons, and the camera won't work.

    The only "easy" solution to that would be to update those binaries to the newer APIs. But since Nokia 8 won't get Android 10, those blobs will never see an update to the new APIs either. You might be able to rip the Goodix stuff (hardware buttons) out of another phone that has Treble / A10, but that will most likely not work for the camera at all. And since all of that is proprietary, closed source stuff we can't update it ourselves.

    So it will probably be totally impossible to ever run something thats not Pie with T-Virus. At least if you want camera and button support. Unless someone who is more involved into this than I am has an idea how to solve it.

    And no, please don't go: "So HMD has to update Nokia 8 to Android 10 so we can fix T-Virus.". That ship has sailed. If you want Android 10 anytime soon, get a different phone. Sorry.
    2
    Ok. After the flashing we have a phone "infected" by the Project Treble. But what it gives to end-user? What is profit of this?
    The ability to install GSIs (Generic System Images). Basically everything from here: https://forum.xda-developers.com/project-treble/trebleenabled-device-development
    2
    Yes I solved partically the compass error. But seems it is partically because it sloooowly rotates clockwise. Trying to find another solution. So it was preambula. Now what I did: I got sensor_def_qcomdev.conf file from Android 8.1 for Nokia 8 and copied it to /system/vendor/etc/sensors (root access required) and set rights -rw-r-r just like it was on original. After that compass seemed to be fixed. Bu as I said befor - it is only first look. Than it ran away. But you may be mor lucky with it! Try and you`ll see if it helped.

    Yes buttons are flickering twice and then they go out. I dont pay attention to it.

    Since the compass was fixed with June update (?), I compared the .conf file from current T-Virus vendor and the 515D stock and there were two lines that were different: in `platform nb1` section, Mag Y and Mag Z are negative values in 515D, so I changed them (see attached image).
    I also copied over two .so files to both lib and lib64 in /vendor, just in case (they had different hashes).
    After reboot and calibration it seems like it shows the correct direction.