FORUMS
Remove All Ads from XDA

[Solved] Samsung S8 Dex without Dex Station

40 posts
Thanks Meter: 36
 
By Meleor, Member on 13th May 2017, 04:06 AM
Post Reply Email Thread
8th September 2017, 05:47 AM |#101  
diehard2013's Avatar
Senior Member
Thanks Meter: 34
 
More
wow.

i´m in if you don´t mind.
 
 
9th September 2017, 06:39 AM |#102  
Member
Thanks Meter: 38
 
More
FINALLY I got a breakthrough with stock kernel compile. Turns out you have to disable the single RKP config - it fixes the section mismatch when disabled.

If Samsung compile it with RKP, then I wonder how it works officially. Perhaps it is checking signatures and rudely rebooting without telling the user.

This might allow me to get it running happily with dm-verity and encryption allowed. Hopefully. But the Jesse kernel has a few benefits - it is faking SELinux enforcing, faking locked bootloader.

I cannot get Samsung pay to work, even on Jesse kernel - despite Magisk faking KNOX 0x0 and passing safety check, etc, faking bootloader locked. I really hope there can be a way to emulate the KNOX keystore which is disabled with KNOX 0x1 to allow to use KNOX apps, albeit somewhat insecurely.

Just an update. I will soon give out the instructions on how to patch for DeX.

---------- Post added at 06:39 AM ---------- Previous post was at 06:22 AM ----------

Yerp, turns out of all the modifications I needed to do, it was the CONFIG_DISPLAYPORT_ENG and the CONFIG for RKP, and edit the drivers/ccic/ccic_alternate.c - nothing more. I will let you know shortly.
The Following User Says Thank You to karatekid430 For This Useful Post: [ View ] Gift karatekid430 Ad-Free
9th September 2017, 03:05 PM |#103  
Member
Thanks Meter: 38
 
More
Okay. How to make kernel from scratch and flash to device (at your own risk, backup all data off the device first as messing with kernels can get messy).

You need Windows and Linux. I use the default distro that comes with WSL on Windows 10.
For Windows: https://forum.xda-developers.com/sho....php?t=2073775 - Android Image Kitchen - to pack and unpack kernel.
https://forum.xda-developers.com/gal...mware-t2988647 - to download firmware without the nonsense you have to put up with on sammobile.com/firmwares.
7-zip - extract boot.img from firmware
Latest applicable source code from opensource.samsung.com for SM-G950F or SM-G955F.

1. On Linux,
cd ~
mkdir toolchain && cd toolchain
git clone https://android.googlesource.com/pla...ux-android-4.9
export CROSS_COMPILE=~/toolchain/aarch64-linux-android-4.9/bin/aarch64-linux-android-4.9-
export ARCH=arm64
export ANDROID_MAJOR_VERSION=7
cd ..
unzip Samsung-sourcecode.zip
mkdir kernel && cd kernel && tar -zxvf ../sourcecode.zip
chmod -R +w .
nano arch/arm64/configs/exynos8895-dream.... (there is only one file in configs dir) - set CONFIG_TIMA_RKP=n and CONFIG_DISPLAYPORT_ENG=y and save
nano drivers/ccic/ccic_alternate.c (and make the function process_check_accessory(void *data) look like the attached image) and save
make exynos8895-dreamlte_eur_open_defconfig if SM-G950F otherwise make exynos8895-dream2lte_eur_open_defconfig
make -jX (replace X with number of CPU threads * 2)
Now if everything went correctly, you will end up with file arch/arm64/boot/Image, and no mentions of section mismatch during compilation. Copy the file to Windows.

In Windows:
DISABLE NORTON F****** ANTIVIRUS AS IT LIKES TO REMOVE THE EXECUTABLES FROM ANDROID IMAGE KITCHEN WITHOUT ASKING.
Extract Android Image Kitchen from the zip.
Use SamFirm utility to download the official ROM for your device - straight from Samsung at high speed.
Use 7-zip to extract the stock boot.img from the AP file from the official ROM you downloaded from the SamFirm utility.
Copy the boot.img into the Android Image Kitchen directory and drop it on unpackimg.bat to extract it.
From the split_img directory that was just created, delete boot.img-zImage. Copy the compiled kernel Image file to split_img directory, and rename it to boot.img-zImage
Go back to previous directory and run repackimg.bat to produce the image-new.img - now rename it to something meaningful so that later after you have repacked dozens of images, you can identify it.
At your own risk, copy to Galaxy S8 and flash the file using TWRP as boot.img (make sure you back up all your data on your device). If you don't know how to recover from this going wrong then you probably shouldn't be doing it. Remember that flashing boot.img removes systemless root and other similar modifications, so these will need to be reflashed over the top.
Did it boot? Yes - yay. No - go back to TWRP and flash the stock boot.img you extracted from the AP (assuming you downloaded the compatible firmware version).

For me this worked with the patched /system from flashing Jesse S8 kernel - but it should work with stock /system - I hope.
If passing dm-verity will allow me to use encryption, then this will make me happy.
I plan to merge changes from the Jesse kernel which fake bootloader locked, disable SELinux but fake enforcing status, etc, etc, without bringing it too far from stock.

Just a note about the source code. Before I had made changes to several files, including drivers/video/fbdev/exynos/dpu/displayport_drv.c to fake the sysfs entries. Turns out that is not required at all - it seems to happen by itself if you change ccic_alternate.c properly. The idea behind this file is that we want the Samsung HDMI adapter, and the Samsung Multiport Adapter to be recognised as DeX, as well as anything else. We let the switch entries run, and if dock_type is not set (third party device) or equal to CCIC_DOCK_HDMI, or equal to CCIC_DOCK_MPA, we run the code from the switch case that was there for the DeX, setting dock_type to CCIC_DOCK_DEX, resulting in the usbpd_data->acc_type being set to equal CCIC_DOCK_DEX, as if it were connected.

If somebody knows how to debug kernels, please let me know what sorts of things trigger this function - I have a hunch it is only USB-C type, but it might be all OTG accessories, in which case it might be smart to come up with a way of deciding whether the connected device should be treated as a DeX station.

Have fun! Somebody who is familiar with Git, please make a patch. We can hopefully produce a stock kernel for the Galaxy Note 8, hours after the source code is released for its kernel.
Attached Thumbnails
Click image for larger version

Name:	Samsung Galaxy S8 Code Patch DeX Station Kernel drivers,ccic,ccic_alternate.c 2017.09.09 Saturda.png
Views:	610
Size:	101.2 KB
ID:	4267587  
The Following User Says Thank You to karatekid430 For This Useful Post: [ View ] Gift karatekid430 Ad-Free
9th September 2017, 07:16 PM |#104  
kbarni's Avatar
Senior Member
Thanks Meter: 122
 
More
@karatekid430 If the KNOX is tripped, you won't be able to use Samsung Pay and encrypted folder even with faked Knox status. Neither on stock ROM, nor on custom ROM.
Thanks for the kernel compilation instructions too!

---------- Post added at 07:16 PM ---------- Previous post was at 07:10 PM ----------

I have another issue on DEX: I'm currently using a bluetooth keyboard and mouse. In normal mode and screen mirroring mode, they work well together. But when I switch to DEX, the phone cannot handle them together. While the mouse is active, the keyboard is blocked (either not writing, or the last letter is stuckkkkkkkkkkkkkk like this). I have to wait a few seconds so the mouse goes in sleep mode to be able to type. Back to screen mirroring mode and everything's fine again. In Dex mode I don't have lots of apps running, so no processor or memory problem.

Can somebody confirm this behaviour either with the official dock, or with a HDMI adaptor?
10th September 2017, 02:10 AM |#105  
Member
Thanks Meter: 38
 
More
Quote:
Originally Posted by kbarni

@karatekid430 If the KNOX is tripped, you won't be able to use Samsung Pay and encrypted folder even with faked Knox status. Neither on stock ROM, nor on custom ROM.
Thanks for the kernel compilation instructions too!

---------- Post added at 07:16 PM ---------- Previous post was at 07:10 PM ----------

I have another issue on DEX: I'm currently using a bluetooth keyboard and mouse. In normal mode and screen mirroring mode, they work well together. But when I switch to DEX, the phone cannot handle them together. While the mouse is active, the keyboard is blocked (either not writing, or the last letter is stuckkkkkkkkkkkkkk like this). I have to wait a few seconds so the mouse goes in sleep mode to be able to type. Back to screen mirroring mode and everything's fine again. In Dex mode I don't have lots of apps running, so no processor or memory problem.

Can somebody confirm this behaviour either with the official dock, or with a HDMI adaptor?

Nope, been using Logitech K810 with MX Anywhere 2S, both Bluetooth, no issues. Except for once, where the keystrokes kept registering multiple times and lagging. Rebooted the phone and it was fine.
10th September 2017, 04:11 AM |#106  
Member
Thanks Meter: 38
 
More
Begging somebody with kernel knowledge for help here. Have tried asking Jesec for help but no response.

The same stock Samsung kernel I compiled yesterday that worked, no longer works after restoring /system to stock. You'd think it would work, coming from standard source. Yet, it only works after I flash the Jesse zip and then flash the boot.img (meaning it also prefers the modified /system).

Does anybody know if encryption with a custom kernel is even a thing? Even if I did not flash Magisk, if I encrypt and then change the kernel, I type the password and it says verification failed, need to factory reset.

If I get good enough I will try to take the Samsung ROM and resign all of the apps and components with my own certificates, and replace the DRK, etc with my own, so hopefully I can make it think that all is official (minus KNOX 0x1).

This is just sad, though. This is a stunning device, with a processor that is as fast as my Ultrabook. Yet its operating system is a complete mess under the hood, and we have almost no control over our own device. Samsung can still force updates (as demonstrated with Note 7). To take it back, we need to root, and this is the s*** we are met with.

Personally I want to see Linux dominate everything - I wonder just how difficult it would be to model a phone OS around Linux, but not like Android - just like another distro that is designed for mobile. I know Ubuntu made Ubuntu Touch, but it does not look like that has taken off. And you do need some proprietary software from large companies like Samsung to make the experience pleasant. I have no idea why Android updates are so difficult, also. You'd think vendor customisations could just be applied to a universal stock image as a package. Rant over.

But please, any information would be appreciated. I am frustrated right now.
10th September 2017, 04:04 PM |#107  
kbarni's Avatar
Senior Member
Thanks Meter: 122
 
More
Sorry, I don't have any idea what's the problem with the kernel. Anyway, I think while you are flashing things to your phone, it's better not to encrypt it.You might have to reset everything after flashing something.

Otherwise you spoke from my heart

About the bluetooth keyboard problem, I have the same problem you described. Rebooting the device solves the problem, but it restarts after a while. It might be a hardware problem, as I use a cheap chinese keyboard.
10th September 2017, 05:47 PM |#108  
DeejayBaca's Avatar
Senior Member
Thanks Meter: 63
 
More
11th September 2017, 03:16 AM |#109  
Member
Thanks Meter: 38
 
More
Quote:
Originally Posted by kbarni

Sorry, I don't have any idea what's the problem with the kernel. Anyway, I think while you are flashing things to your phone, it's better not to encrypt it.You might have to reset everything after flashing something.

Otherwise you spoke from my heart

About the bluetooth keyboard problem, I have the same problem you described. Rebooting the device solves the problem, but it restarts after a while. It might be a hardware problem, as I use a cheap chinese keyboard.

I have always found Bluetooth to be less reliable - with my K810 and Surface Pro 1, it would take a random amount of time [5, 30] seconds at boot to pair - frustrating. It seems like the Marvell controllers that Microsoft use are poor - although they have improved over their lifetime.
When it works, my maxed out Dell convertible 9365 works well, but occasionally the Bluetooth suddenly dies. Much less frequently after the driver update, mind you.
Still cannot beat the reliability of a USB receiver - and a USB receiver can work in BIOS. If you dual-boot, you can make both operating systems use the same pairing key for Bluetooth, but it is fiddly.
The thing about USB receivers is that you can attach them to a docking station, and they disconnect when you remove the device. With Bluetooth, you walk into another room and realise that your phone is still connected to the Bluetooth keyboard.
Hence Samsung need to allow the option to disable on a per-device basis peripherals when not connected to the DeX Station.
I don't like Intel at all as a company, but for Thunderbolt, Ethernet and wireless controllers, I prefer them. For example, Intel drivers are your best hope for doing NIC teaming in non-server Windows.
Notable is that in the kernel of the S8, I noticed that defined were the vendor and device IDs of a Samsung USB cellular modem. With the Tab S2 onward (might have been earlier ones, but I did not look because it was before USB-C sparked my interest) and the S8 onward, Samsung have enabled 3rd-party Ethernet (as all in this thread will know). The next thing would be to allow USB wireless adapters and Bluetooth. That would allow for attaching a wireless card with a 24dB directional antenna and pick the university Wi-Fi up way off campus. Granted, you could just use an Odroid C2 powered off a battery, controlling the wireless card and SSID authentication, passing the data through wired Ethernet to the Samsung device. Either use SSH to control it, or install a touch screen module on it and make a GUI.

It would be good if they allowed third party drivers to be loaded, but Samsung would have to have some sort of signing process like Microsoft WHQL, to avoid people using it to root their devices.

Tangent aside, it would be nice if the Galaxy could take the USB Bluetooth module - perhaps by chance, a chip of a different vendor might play nicer with your particular device. Does the cheap keyboard do this with other devices? Do you have a laptop or desktop with Bluetooth? If not, you can obtain the USB sticks that should work with anything except Android. Although as a root user, you might be able to hack it together.

About the kernel, who should I ask? Who knows a lot about the kernel and might be interested in this stuff? The latest posts in the Jesse S8 kernel are people wondering if the kernel is dead (I assume they mean that Jesec has lost interest). And he did say that compilation assistance would be ignored, although my issue is only related to compilation - I can compile it fine, but it is making the damn thing boot that is the issue.
I am just concerned - the instructions I just gave 100% work, but only if you have flashed the Jesse kernel zip previously, and hence have the patched /system partition. I thought that was required due to the bump in kernel version of the Jesse kernel, but it seems that it might be for some other reason.

Starting to think that learning kernel development might be a good career move, to get closer to the intersection between software and hardware architecture. But it's a very big pond for a little fish to adapt to. Problem is that my university UWA seems to be diverging away from real programming, and more into project management and software processes. So I am stuck as to from where to amass significant amounts of information, aside from brute-forcing it out on my own. I do know Dr Chris McDonald at UWA is probably a wealth of information on this matter, but I feel like we don't fully see eye to eye despite having many similarities. It didn't help that I was forced to use Linux / Mac in an early UG unit of his, before I was accustomed to Linux. If anybody can suggest where I should be looking, that would be appreciated. The more I learn, the more likely I am to be able to solve more problems like this for XDA.

---------- Post added at 03:16 AM ---------- Previous post was at 03:05 AM ----------

Oh, forgot to mention, as for the encryption, I am happy to factory reset every time I have to update (it isn't my main phone, anyway). I would only encrypt once I had it modified to a state that I was happy to keep for a while. A friend tells me that anything custom does not really work with encryption - and not just Nougat. Which does not wholly make sense, because a fully custom ROM is just like an official ROM but from another company. It might be something to do with the way that (afaik) partial encryption keys are kept in a secure zone of the SoC, so that if the encrypted data is taken off the device, the password alone is insufficient to derive the filesystem encryption key. Perhaps it is tricky, and only the manufacturer can do it reliably. Personally I would just find some long chain of operations on the password that involve a variety of different cryptographic hashes and operations to produce the encryption key, in such a way that it will be theoretically resistant to quantum computing algorithms, and will take too long to brute-force for the next several decades. A security expert might see flaws with my reasoning, but still, I prefer simplicity. After all, I read something where they could use exploits to get into the secure zone (it runs its own miniature kernel according to the article) and exploit the secure zone to achieve kernel mode escalation, and dump the device-binding key, allowing for the password to be brute-forced.
11th September 2017, 01:24 PM |#110  
kbarni's Avatar
Senior Member
Thanks Meter: 122
 
More
As you might have observed, Dex doesn't work with the Samsung covers (LED cover or Clear view cover). It would be interesting if we could enable this, as third party adapters shouldn't block the usage of the covers.

I was wondering if this check is performed in kernel, or the Dex app. I looked in the kernel sources, but I couldn't find any trace of this check. Can somebody confirm it?
Unfortunately the Dex app might be more difficult to hack. I'm afraid the check is done there, as I get the "switch to Dex mode" notification even with the cover on, and I get the error message only when I want to start Dex.

In the meantime I found something that might be interesting: somebody asked if the phone could be used in Dex mode as a touchpad? In the Samsung touchscreen driver (drivers/input/touchscreen/sec_ts/sec_ts_fn), there is a function called dex_enable (line 4122), which has the following code:
Code:
if (ts->dex_mode) {
		input_err(true, &ts->client->dev, "%s: set DeX touch_pad mode%s\n",
			__func__, sec->cmd_param[1] ? " & Iris mode" : "");
		ts->input_dev = ts->input_dev_pad;
                ...
I wonder if it enables some kind of touchpad functionnality on the phone screen? If it does, then why isn't it working by default?
12th September 2017, 02:22 PM |#111  
kbarni's Avatar
Senior Member
Thanks Meter: 122
 
More
Kernel patch for enabling Dex
Here is the patch to enable Dex for any S8/S8+ kernel.
You can send this file to other developers to integrate it in their kernels/roms!

P.S. here are the commands to do it - in case you want to reproduce or make another patch. First modify the files (in this case the config files and the ccic_alternate.c, than:
Code:
git diff > Enable-Dex.patch
---- or ----
git commit -a -m 'Dex support for any HDMI adapter'
git show [branch name] > Enable-Dex.patch
Attached Files
File Type: patch Enable-Dex.patch - [Click for QR Code] (2.4 KB, 258 views)
The Following 4 Users Say Thank You to kbarni For This Useful Post: [ View ] Gift kbarni Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes