PostmarketOS, or linux on phones

I own two exynos devices that I reguarly use and would like to keep up to date, software wise, for as long as the hardware survives. The older device is a Samsung galaxy tab S (chagallwifi) with an exynos 5422 soc. The downstream kernel is version 3.4, which is quite old by now. Ever since I discovered wireguard, which requires Linux >= 3.10, I have been fantasising about somehow getting an updated kernel working on it. However, this is hard, and have felt outside my ability. With the birth of the postmarketOS project, however, things have changed. postmarketOS not only provides a way to install Linux on a wide range of devices, but also has a community were people, in a collaborative spirit, try to bring mainline Linux to various devices. Thanks to this I think bringing mainline Linux to the chagallwifi is doable, but it still requires lots of time since drivers need to be written.

The other device I own is a Samsung galaxy s8+ (dream2lte), with an exynos 8895 soc. This device’s downstream kernel is version 4.4, which still receives updates thanks to being LTS.

Exynos exynos exynos…

Snapdragon socs, like snapdragon 410 (MSM8916), have gained more attention in the past. There is even a dedicated mainlining guide for the MSM8916: Hopefully I get somewhere in my research into these exynos devices and can provide information for others with exynos devices. I am not alone though, as always in these types of open-source endeavours we are standing on the shoulder of giants. Support for the exynos 5422 has already been added to mainline Linux by the hardkernel company, who produces single-board computers. For bringing mainline Linux to the chagallwifi we therefore “only” need to investigate the various device drivers.

For the exynos 8895 soc support in mainline Linux is not yet there. There is, however, ongoing efforts to bring support for the older sibling, exynos 8890.

Initial status of devices

When I started exploring pmOS chagallwifi had a port where nothing worked except telnetting into the initramfs. Trying to boot further gave errors related to FIMC IS (Fully Interactive Mobile Camera - Imaging Subsystem):

[B1:          v4l_id:  2404] kernel BUG at /home/pmos/build/src/android_kernel_samsung_exynos5420-5604f20e8b2a777c87e369b50a29e8da7e4daf61/drivers/media/video/exynos/fimc-is-mc2/fimc-is-groupmgr.c:583!
[B2:          v4l_id:  2402] [ISP:V:0] fimc_is_isp_video_open
[B2:          v4l_id:  2402] read_data_from_file:425: open file error!!
[B2:          v4l_id:  2402] 
[B2:          v4l_id:  2402] failed to filp_open - /system/vendor/firmware/fimc_is_fw2.bin
[B2:          v4l_id:  2402] failed to filp_open - /system/vendor/firmware/fimc_is_fw2_3L2.bin
[B2:          v4l_id:  2402] failed to filp_open - /system/vendor/firmware/fimc_is_fw2_IMX134_EEPROM.b
[B1:          v4l_id:  2404] [<c05df584>] (fimc_is_group_open+0x0/0x684) from [<c05f4f94>] (fimc_is_ischain_3a0_open+0x48/0x90)
[B1:          v4l_id:  2404] [<c05f4f4c>] (fimc_is_ischain_3a0_open+0x0/0x90) from [<c05e402c>] (fimc_is_3a0_video_open+0x110/0x1b8)
[B1:          v4l_id:  2404]  r5:dcc3d180 r4:ddf80000
[B1:          v4l_id:  2404] [<c05e3f1c>] (fimc_is_3a0_video_open+0x0/0x1b8) from [<c0576a08>] (v4l2_open+0xd4/0x154)
[B1:          v4l_id:  2404] [<c0576934>] (v4l2_open+0x0/0x154) from [<c012c134>] (chrdev_open+0xb0/0x228)
[B1:          v4l_id:  2404]  r7:c0ef9f2c r6:dcc3d180 r5:dde95528 r4:ddee78c0
[B1:          v4l_id:  2404] [<c012c084>] (chrdev_open+0x0/0x228) from [<c0125c48>] (__dentry_open+0xe8/0x318)
[B1:          v4l_id:  2404]  r9:dde95528 r8:c012c084 r7:de8b9a90 r6:de430098 r5:dcc3d180
[B1:          v4l_id:  2404] r4:00000000
[B1:          v4l_id:  2404] [<c0125b60>] (__dentry_open+0x0/0x318) from [<c01270a4>] (nameidata_to_filp+0x68/0x78)
[B1:          v4l_id:  2404]  r9:00000024 r8:00020000 r7:dea6bc80 r6:00000000 r5:dcc3d180
[B1:          v4l_id:  2404] r4:dc449ec8
[B1:          v4l_id:  2404] [<c012703c>] (nameidata_to_filp+0x0/0x78) from [<c0135520>] (do_last+0x154/0x938)
[B1:          v4l_id:  2404]  r7:00000000 r6:dde95528 r5:dde95528 r4:dc449ec8
[B1:          v4l_id:  2404] [<c01353cc>] (do_last+0x0/0x938) from [<c0137c84>] (path_openat+0xc4/0x53c)
[B1:          v4l_id:  2404] [<c0137bc0>] (path_openat+0x0/0x53c) from [<c01382e4>] (do_filp_open+0x38/0x94)
[B1:          v4l_id:  2404] [<c01382ac>] (do_filp_open+0x0/0x94) from [<c01271c0>] (do_sys_open+0x10c/0x198)
[B1:          v4l_id:  2404]  r8:fffff000 r7:00000001 r6:ffffff9c r5:dcc59000 r4:00000003
[B1:          v4l_id:  2404] [<c01270b4>] (do_sys_open+0x0/0x198) from [<c0127270>] (sys_open+0x24/0x28)
[B1:          v4l_id:  2404]  r9:dc448000 r8:c000f744 r7:00000005 r6:00000000 r5:00000000
[B1:          v4l_id:  2404] r4:00000000
[B1:          v4l_id:  2404] [<c012724c>] (sys_open+0x0/0x28) from [<c000f724>] (__sys_trace_return+0x0/0x1c)
[B1:          v4l_id:  2404] Code: e5824d24 e5824d7c ebf46d7a eaffff44 (e7f001f2) 

For the dream2lte the situation was better. A port were the device booted successfully and at least the display and battery worked was available already.

postmarketOS on chagallwifi

My first attempt at improving the port was by fixing the “failed to filp open” errors, by adding the files as part of a firmware package. This however had basically no effect, the kernel still panicked. Next attempt was therefore instead to disable FIMC IS completely. The postmarketOS wiki already had a note for the hero2lte that FIMC IS had to be disabled for compilation to work (I also discovered later that it had to be disabled for the dream2lte build to succeed), so it seemed to be the best way forward. In fact, I guess FIMC IS needs to be disabled on all exynos >= 5 devices (or that the actual problem is solved) for the compilation to succeed. Interesting side note: Samsung seem to have attempted to get FIMC IS drivers for exynos5 into mainline many years ago (search for “Arun Kumar K [PATCH v12 00/12] Exynos5 IS driver” if the link no longer works), but it seems it never landed in mainline.

When attempting to disable FIMC IS through the kernel config the kernel build still failed with undefined references related to FIMC IS. I added some ugly hacks, forcefully preventing some FIMC related files to be built, but this gave a kernel panic even earlier in the booting process, it failed with something like

[    0.000000] clkout: bad source 0
[    0.000000] s3c_register_clksrc: clock sclk_hsic_12m has no registers set
[    0.000000] clkout: bad source 0
[    0.000000] (sec_debug_set_upload_magic) 66262564
[    0.000000] (sec_debug_set_upload_cause) cafebabe
[    0.117633] gpio: GPZ has no PM function
[    0.162161] [exynos5_universal5420_fpga_init] initialization start!
[    0.162257] irda_device_init called!
[    0.162319] irda_device_init complete
[    0.185257] PM DOMAIN : cant find clock, to add power domain
[    0.186570] PM DOMAIN : platform_device has not platform bus
[    0.187106] ------------[ cut here ]------------
[    0.187258] WARNING: at /home/pmos/build/src/android_kernel_samsung_exynos5420-5604f20e8b2a777c87e369b50a29e8da7e4daf61/kernel/mutex.c:198 __mutex_lock_slowpath+0x384/0x3b8()
[    0.187583] Modules linked in:
[    0.187778] Backtrace: 
[    0.188038] [<c0871368>] (dump_backtrace+0x0/0x134) from [<c08714b4>] (dump_stack+0x18/0x1c)
[    0.188253]  r7:000000c6 r6:c0a5067c r5:00000000 r4:00000009
[    0.188759] [<c087149c>] (dump_stack+0x0/0x1c) from [<c08735a4>] (warn_slowpath_common+0x5c/0x74)
[    0.188994] [<c0873548>] (warn_slowpath_common+0x0/0x74) from [<c003d31c>] (warn_slowpath_null+0x24/0x2c)
[    0.189216]  r9:de97beb0 r8:de848000 r7:de844000 r6:c0f02e90 r5:60000013
[    0.189661] r4:c0f02e8c
[    0.189991] [<c003d2f8>] (warn_slowpath_null+0x0/0x2c) from [<c0889498>] (__mutex_lock_slowpath+0x384/0x3b8)
[    0.190225] [<c0889114>] (__mutex_lock_slowpath+0x0/0x3b8) from [<c08894f8>] (mutex_lock+0x2c/0x48)
[    0.190457] [<c08894cc>] (mutex_lock+0x0/0x48) from [<c03bc278>] (genpd_acquire_lock+0x74/0xc4)
[    0.190673]  r5:de845e64 r4:c0f02e8c
[    0.191016] [<c03bc204>] (genpd_acquire_lock+0x0/0xc4) from [<c03be46c>] (__pm_genpd_add_device+0xcc/0x250)
[    0.191240]  r7:de97be40 r6:00000000 r5:c0f02e10 r4:c0f27bb8
[    0.191687] [<c03be3a0>] (__pm_genpd_add_device+0x0/0x250) from [<c0020de0>] (exynos_pm_add_dev+0x30/0xd8)
[    0.191987] [<c0020db0>] (exynos_pm_add_dev+0x0/0xd8) from [<c0020eb0>] (exynos_pm_add_platdev+0x28/0x54)
[    0.192213]  r5:c0008180 r4:00000001
[    0.192504] [<c0020e88>] (exynos_pm_add_platdev+0x0/0x54) from [<c0b91964>] (exynos5_pm_domain_init+0xf4c/0x1374)
[    0.192750] [<c0b90a18>] (exynos5_pm_domain_init+0x0/0x1374) from [<c00085d0>] (do_one_initcall+0x3c/0x1b8)
[    0.192986] [<c0008594>] (do_one_initcall+0x0/0x1b8) from [<c0b87b2c>] (kernel_init+0x150/0x22c)
[    0.193208]  r9:00000004 r8:c0bd5920 r7:c0fb68c0 r6:c0bcd760 r5:0000013e
[    0.193717] r4:c0bcd780
[    0.194057] [<c0b879dc>] (kernel_init+0x0/0x22c) from [<c0040d2c>] (do_exit+0x0/0x7e0)
[    0.194270]  r7:00000013
[    0.194483] ---[ end trace da227214a82491b7 ]---
[    0.194687] Unable to handle kernel NULL pointer dereference at virtual address 00000000

And I gave up, temporarily, with trying to get it working and went back to looking into the panic I got when FIMC IS was activated instead. For some reason that problem does not occur on every boot, indicating that maybe there is some sort race condition happening.

More on FIMC IS on chagallwifi, and how to disable it, will be described in another blog post.