[Samsung Gear 2] biktor_gj:
Down the rabbit hole we go

I've lost all weekend trying different things, thought I'd write a bit to let you know what I've learnt, what's working, and what's not.

The problem at hand: hwcomposer

For those of you lost in this thread, I've been using Samsung Galaxy S5 Mini (G800F) / Samsung Galaxy Light (GardaLTE) binary blobs to make display work. That has been fun at first because it helped me bringing the display up to work in Android, and let to the watch actually starting to work.

Unfortunately, there's always a catch: those binaries are tightly integrated with the typical Samsung Garbage that shouldn't be linked at all. The worst of the dependencies is libmedia.so. I have to keep that file in the version that came with Android Wear, but, at the same time, display won't work with it. So, if I use Samsung's libmedia.so I get the display working, but all the media services crash. If I remove it, media services stop crashing, but the display stops working. This is what you call a dependency nightmare.

One of these things is not like the others

I spent all the weekend building different test cases with my watch. I had a theory:

S5Mini's display is referenced as smdk4210 --> 4210 is an Exynos 4 variant.

Gear 1's libraries are marked as smdk4x12 --> 4212 is an Exynos 4 variant too!

Both use the same Mali GPU and, despite clock and kernel differences, look similar. Maybe Samsung reused reference designs from Exynos 4 to make the new Exynos 3250 & 3470?

I already had a null rom firmware copy for the Gear1 sitting in my devel machine. I found a Jellybean firmware for the Galaxy Light, which is also based off the Exynos 3470, which is a 3250 with 2 added cores. If the newer version worked, may be the older version worked too!

First test: Use jellybean libraries with Android Wear: Didn't work, there have been changes to the Android Platform and some dependant functions on the jelly bean code have dissappeared in kitkat. If I met them, Android Wear wouldn't boot. Since I can't recompile Wear's system core, I'm stucked.

Second test: Use jellybean firmware with jellybean libraries.

Try 1: Didn't work, Mali driver was built for an older release version. Picked my kernel code, downgraded the mali driver release. Retry

Try 2: Hard kernel crashes everywhere and no display. Investigated them and made changes to the s3c-fb code, so Mali's UMP library would find the framebuffers in the same position and quantity as expected

Try 3: No more crashes! But no display either. The Hardware Composer started, initialized the display and... Couldn't find the framebuffer for the camera device! Since my gear 2 Neo doesn't have a camara, it wasn't going to find a /dev/graphics/fb5 anywhere. I moved on to the next test

Third test: I will use my own hwcomposer. Following the idea that the *new* exynos3 (don't mix it up with the old exynos3 found in the Galaxy S i9000) might be in fact a rebranded exynos 4, I picked up i9100's device tree and hacked up to build a hwcomposer library for that. After hours of compiling and different mali libraries and kernels, this is a No-go too. By this time I've learn that even if they're similar enough to share half the components, and to know that all these SoC are based on the s5pv210 reference chip design, each one has its peculiarities, and I can't go transplanting things from here and there and hope for the best.

Fourth test: I thought, maybe some people have the same issues as we're having... And sure thing, they do.

Garda LTE users do: http://xdaforums.com/showpost.php?p=56432598&postcount=47

We share the same libs, so we share the same issues.

I started looking the inside of the hwcomposer library that is working, and, funny enought, it's not using Exynos4 code...

void exynos5_boot_finished(exynos5_hwc_composer_device_1_t*)
int exynos5_blank(hwc_composer_device_1*, int, int)

It's using partial code for the Exynos 5 hardware composer! It seems the new exynos3 platform uses exynos4 clock controllers with pieces of the exynos5 display libraries... how can anyone at Samsung work this way?

So I picked Samsung Manta's source, which is using exynos 5 hwcomposer, and put it to compile. After hours of compiling and putting libraries in place so the thing would compile, I got a hwcomposer library compiled. Failed saying it can't find HDMI libraries, then failed because it couldn't enable HDMI display because this board doesn't have HDMI. Disabled the HDMI and recompiled and... I got another error:

hwcomposer: ioctl S3CFB_WIN_CONFIG failed: Not a typewriter
hwcomposer: ioctl S3CFB_WIN_CONFIG failed to clear screen: Not a typewriter

The display blanked, almost worked, but of course, it wouldn't work in the end.

That got me to this post: http://xdaforums.com/showpost.php?p=54512091&postcount=46

This guy had the same problem!

Unfortunately, I couldn't find if he solved it, and if he did, how. So I asked him, let's hope he can tell me what he did, and that it doesn't involve a closed source library ;)

In the meantime, I noticed another thing: Cyanogenmod's hwcomposer library ends up here:

tag: HARDWARE_MODULE_TAG,
module_api_version: HWC_MODULE_API_VERSION_0_1,
hal_api_version: HARDWARE_HAL_API_VERSION,
id: HWC_HARDWARE_MODULE_ID,
name: "Samsung exynos5 hwcomposer module",
author: "Google",
methods: &exynos5_hwc_module_methods,

But the working hwcomposer library ends up with this:

Samsung exynos5 hwcomposer module
Samsung LSI

F*ck it they're not even the same!

And Cyanogenmod's hwcomposer doesn't have WFD support, which is exactly what's causing me this big headache.

I found source code for a HWComposer library, for the exynos5, which does seem to be the same:

hwc_module_t HAL_MODULE_INFO_SYM = {
common: {
tag: HARDWARE_MODULE_TAG,
module_api_version: HWC_MODULE_API_VERSION_0_1,
hal_api_version: HARDWARE_HAL_API_VERSION,
id: HWC_HARDWARE_MODULE_ID,
name: "Samsung exynos5 hwcomposer module",
author: "Samsung LSI",
methods: &exynos5_hwc_module_methods,
}
};

And which also has WFD in the code:

#ifdef USES_WFD
static void wfd_output(buffer_handle_t buf, exynos5_hwc_composer_device_1_t *pdev,
exynos5_gsc_data_t *gsc, hwc_layer_1_t &layer)
{
private_handle_t *src_handle = private_handle_t::dynamicCast(layer.handle);
private_handle_t *handle = private_handle_t::dynamicCast(buf);

if (pdev->wfd_skipping) {
pdev->wfd_skipping--;
} else {
pdev->wfd_buf_fd[0] = handle->fd;
pdev->wfd_buf_fd[1] = handle->fd1;

pdev->wfd_info.isPresentation = !!pdev->mPresentationMode;
pdev->wfd_info.isDrm = !!(exynos5_get_drmMode(src_handle->flags) == SECURE_DRM);
...

This comes from, maybe, jellybean release, but I will try to compile it against the Kitkat Cyanogenmod tree that I have. We'll see how that goes!

Who said things would get easier once it had booted? :eek:

PS: [MENTION=6568603]kavinzhao[/MENTION]: I used parts of the Gear1 TWRP, not from Gear Live. The ones from the Gear live gave a blurred display, while this one seemed to work just fine... We can try though ;) By the way, yesterday I went looking to look a bit at an actual Android Wear device to a couple stores and got to play with a Sony Smartwatch 3 (and left it unusable after forcing it to factory reset ;)). When you removed the ClockworkSetup apk, you bypassed the setup assistant, and after language selection, it asks you to connect to an android phone to complete the setup through a tethered internet access through your phone. That's why it was telling you that it couldn't connect to the internet!

Edit: whoa! I didn't think it would end up being that long :)