Debian on the Galaxy Note 10.1

Nice people have given me a Galaxy Note 10.1. Naturally, I want a compatible setup to how I use all the other tablets.

First (failed) attempt

Rooting was trivial via KingoRoot.

Debian was copied over from the Excite Write in the hope to have less things to adapt:

excite write / % rsync -azHvD -P -e 'ssh -p 2222' --exclude '/run/*' --exclude '/proc/*' --exclude '/sys/*' --exclude '/sdcard/*' --exclude '/dev/pts/*' / root@192.168.2.119:/data/debian-jessie
Host key verification failed.
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.1]

Hrm. This is actually a new ip...

excite write /root % ssh -p 2222 root@192.168.2.119 -v
...
debug1: Server host key: ECDSA 97:46:26:f3:09:8a:64:22:20:0f:c6:f0:ba:ec:c0:da
debug1: checking without port identifier
debug1: read_passphrase: can't open /dev/tty: No such file or directory
Host key verification failed.

Let's find us some "tty" then...

excite write /root % ln -fs /proc/self/fd/2 /dev/tty
excite write / % rsync -azHvD -P -e 'ssh -p 2222' --exclude '/run/*' --exclude '/proc/*' --exclude '/sys/*' --exclude '/sdcard/*' --exclude '/dev/pts/*' / root@192.168.2.119:/data/debian-jessie
The authenticity of host '[192.168.2.119]:2222 ([192.168.2.119]:2222)' can't be established.
...
Are you sure you want to continue connecting (yes/no)?

... while waiting on this to complete ...

Brightness control is available via

root@galaxy:/ # echo 15 > /sys/class/backlight/panel/brightness

Anyway, after everything was copied and some modifications to start.sh:

root@galaxy:/data/debian-jessie # cat start.sh
setprop ctl.stop media
setprop ctl.stop zygote
sleep 1
setprop ctl.stop bootanim
sleep 1
setprop ctl.stop bootanim

setenforce 0

mount -o remount,rw /system
mount -t proc proc /data/debian-jessie/proc
mount -t sysfs sysfs /data/debian-jessie/sys
mount -t devpts devpts /data/debian-jessie/dev/pts
mount -o bind /storage/emulated/legacy /data/debian-jessie/sdcard
mount -o remount,rw,suid,dev /data
root@galaxy:/data/debian-jessie #
root@galaxy:/data/debian-jessie # ./enter.sh
./enter.sh[5]: /data/debian-jessie/usr/sbin/chroot.android: No such file or directory
root@galaxy:/data/debian-jessie # ls -la /data/debian-jessie/usr/sbin/chroot.android
-r-xr--r-- shell    shell       22233 2021-04-23 22:40 chroot.android

Oh, it's wrong dynamic linker path again.

root@galaxy # cp /data/debian-jessie/lib/ld-linux-armhf.so.3 /data/ld-linx-armhf.so.3
root@galaxy # /data/debian-jessie/start.sh
root@galaxy # /data/debian-jessie/enter.sh
note 10.1 / % cd /root
note 10.1 /root % ./X.sh 
...
(II) Loading /usr/lib/xorg/modules/input/evdev_drv.so
(II) Module evdev: vendor="X.Org Foundation"
        compiled for 1.16.4, module version = 2.9.2
(II) FBDEV: driver for framebuffer: fbdev
(++) using VT number 1

... and hard reboot. :(

Maybe with full-disable of anything doing bad things to poor framebuffers?

root@galaxy:/system/bin # mount -o remount,rw /system
root@galaxy:/system/bin # mv drmserver drmserver.off
root@galaxy:/system/bin # mv bootanimation bootanimation.off
root@galaxy:/system/bin # mv surfaceflinger surfaceflinger.off

... which was a very bad idea, as KingoRoot will not grant su without GUI. WTF.

Second (working) attempt

So, rerooting we go...

root@laptop: heimdall flash --RECOVERY twrp-3.6.0_9-0-n8000.img

... and via the twrp terminal move the .off files back. :(

So I went with my own root

me@laptop # adb push /tmp/su /data/local/tmp
root@galaxy:/system/bin # mount -o remount,rw /system
root@galaxy:/system/bin # mv debuggerd debuggerd.off
root@galaxy:/system/bin # cat > debuggerd
#!/system/bin/sh

setenforce 0

if ! /data/local/tmp/su -c id; then
        mount -o remount,suid /data
        /data/local/tmp/su --daemon
fi

exec /system/bin/debuggerd.off "$@"
root@galaxy:/system/bin # chmod 755 debuggerd

However

root@galaxy:/system/bin # dmesg
...
<3>[  373.475886] c0 Restricted making process. PID = 6473(su) PPID = 6472(su)

on which Stackoverflow tells us that the Samsung kernel will not have people exec-ing from /data. Meh.

root@galaxy:/data/local/tmp # cp su /system/xbin/drahflow-su
root@galaxy:/data/local/tmp # chmod 755 /system/xbin/drahflow-su
root@galaxy:/system/bin # cat > debuggerd
#!/system/bin/sh

setenforce 0

if ! /system/xbin/drahflow-su -c id; then
        mount -o remount,suid /data
        /system/xbin/drahflow-su --daemon
fi

exec /system/bin/debuggerd.off "$@"

And once more:

root@galaxy:/system/bin # mount -o remount,rw /system
root@galaxy:/system/bin # mv drmserver drmserver.off
root@galaxy:/system/bin # mv bootanimation bootanimation.off
root@galaxy:/system/bin # mv surfaceflinger surfaceflinger.off
And indeed:
me@laptop % adb shell
shell@galaxy:/ $ su        # <-- Kingoroot not so good without UI
1|shell@galaxy:/ $ drahflow-su                                              
/system/bin/sh: No controlling tty: open /dev/tty: No such device or address
/system/bin/sh: warning: won't have full job control
root@galaxy:/ # dd if=/dev/urandom of=/dev/fb0

Unfortunately, no framebuffer effect can be observed. Fingers crossed for X11 to be able to use the device, nonetheless. Narrator voice: It could not. Rather, it triggered hard reboot.

Let's meanwhile explore the input devices:

/dev/input/event0  <- hardware keys
/dev/input/event1  <- touchscreen
/dev/input/event6  <- digitizer (incl. pen presence)

And after having strace installed

note 10.1 /root % strace -f ./X.sh
...
[pid  7063] clock_gettime(CLOCK_MONOTONIC, {tv_sec=588, tv_nsec=77877033}) = 0
[pid  7063] write(0, "[   588.077] ", 13) = 13
[pid  7063] write(0, "(++) using VT number 1\n\n", 24) = 24
[pid  7063] fstat64(0, {st_mode=S_IFREG|0644, st_size=4464, ...}) = 0
[pid  7063] fstat64(1, {st_mode=S_IFSOCK|0777, st_size=0, ...}) = 0
[pid  7063] fstat64(2, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
[pid  7063] getppid()                   = 7062
[pid  7063] getpgid(7062)               = 7038
[pid  7063] setpgid(0, 7038)            = 0
[pid  7063] setsid()                    = 7063
[pid  7063] open("/dev/vc/1", O_RDWR|O_NONBLOCK) = -1 ENOENT (No such file or directory)
[pid  7063] open("/dev/tty1", O_RDWR|O_NONBLOCK%

Ah, so maybe the fake tty1 I used on the Excite Write is not so good on the Samsung.

root@galaxy:/ # cp -a /dev/tty /data/debian-jessie/dev/
root@galaxy:/ # cp -a /dev/tty0 /data/debian-jessie/dev/
root@galaxy:/ # cp -a /dev/tty1 /data/debian-jessie/dev/
root@galaxy:/ # cp -a /dev/tty2 /data/debian-jessie/dev/

And now...

note 10.1 /root % Xorg -sharevts -noreset -retro -verbose -nocursor vt1
(II) FBDEV(0): using /dev/fb0
(WW) VGA arbiter: cannot open kernel arbiter, no multi-card support
(**) FBDEV(0): Depth 32, (--) framebuffer bpp 32
(EE) FBDEV(0): Weight given (000) is inconsistent with the depth (32)
(EE) Screen(s) found, but none have a usable configuration.
(EE)
Fatal server error:
(EE) no screens found(EE)
(EE)
Please consult the The X.Org Foundation support
         at http://wiki.x.org
 for help.
(EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
(EE)
(EE) Server terminated with error (1). Closing log file.

... much better.

note 10.1 /root % Xorg -sharevts -noreset -retro -verbose -fbbpp 32 vt1

... and we have a running Xorg.

After some manual calibration (don't even bother with xinput_calibrator, it didn't work usefully for me even once) the final /etc/X11/xorg.conf:

Section "ServerLayout"
  Identifier "Layout0"
  Screen   "Screen0"
  InputDevice "Touchscreen" "CorePointer"
  InputDevice "Digitizer"
  InputDevice "Keyboard" "CoreKeyboard"
EndSection

Section "InputDevice"
  Identifier  "Keyboard"
  Driver   "evdev"
  Option  "Device" "/dev/input/event1"
  Option  "Protocol" "usb"
EndSection

Section "InputDevice"
  Identifier "Touchscreen"
  Driver  "evdev"
  Option  "Device" "/dev/input/event2"
  Option  "IgnoreRelativeAxes" "true"
  Option  "IgnoreAbsoluteAxes" "false"
  Option  "InvertX" "false"
  Option  "InvertY" "false"
  Option  "Mode" "Absolute"
EndSection

Section "InputDevice"
  Identifier "Digitizer"
  Driver  "evdev"
  Option  "Device" "/dev/input/event6"
  Option  "IgnoreRelativeAxes" "true"
  Option  "IgnoreAbsoluteAxes" "false"
  Option  "InvertX" "false"
  Option  "InvertY" "false"
  Option  "Mode" "Absolute"
  Option  "Calibration" "250 21900 250 13750"
EndSection

Section "Device"
  Identifier "Card0"
  Driver  "fbdev"
  Option  "fbdev" "/dev/fb0"
  Option  "debug" "true"
  # Option  "Rotate" "UD"
  VendorName "Unknown"
  BoardName "Unknown"
EndSection

Section "Screen"
  Identifier  "Screen0"
  Device  "Card0"
  Monitor "Monitor0"
  DefaultDepth    32
  SubSection      "Display"
    Depth               32
    Modes   "1280x800"
  EndSubSection
EndSection

Section "Monitor"
  Identifier "Monitor0"
EndSection

Section "ServerFlags"
  Option "AutoAddDevices" "false"
EndSection

Unfortunately, there was still some left-overs from the bootanimation visible, but a more aggressive stopping fixes that (and the normal surfaceflinger seems to be mapped differently). Anyway, with a modified start.sh, we now have a clear X display:

note 10.1 / % cat start.sh
setprop ctl.stop media
setprop ctl.stop zygote
sleep 0.1
setprop ctl.stop bootanim
sleep 0.1
setprop ctl.stop bootanim
sleep 0.1
setprop ctl.stop bootanim
sleep 0.1
setprop ctl.stop bootanim
sleep 0.1
setprop ctl.stop bootanim

setenforce 0

mount -o remount,rw /system
mount -t proc proc /data/debian-jessie/proc
mount -t sysfs sysfs /data/debian-jessie/sys
mount -t devpts devpts /data/debian-jessie/dev/pts
mount -o bind /storage/emulated/legacy /data/debian-jessie/sdcard
mount -o remount,rw,suid,dev /data

Work is ongoing by fiddling around with input event parsing to duplicate the drawing experience I'm used to from the other tablets.

The digitizer behaves the same as on the Excite Write, but the touchscreen is different. (And there is also still some bugginess with how RGB channels are mapped.)