Lenovo ThinkSmart View ROM/OS Development

I have a silly solution that’s been working well enough for my needs:

shell_command:
  set_wallpanel_brightness: ssh -i /config/id_ed25519_thinksmart -o StrictHostKeyChecking=no [email protected] 'echo {{ level }} > /sys/class/backlight/backlight/brightness'
  wallpanel_restart_dashboard: timeout 10 ssh -i /config/id_ed25519_thinksmart -o StrictHostKeyChecking=no [email protected] './dashboard.sh'

id_ed25519_thinksmart is just a SSH key I generated in my HA config directory, whose pubkey I deployed to the ThinkSmart device (in ~/.ssh/authorized_keys).

'./dashboard.sh' is just a shell script on the device that kills Firefox and starts it again in Kiosk mode. In practice I never really need to do this, but it’s nice having a way to force the device back into its “good” state if needed. Just to be safe, I have an automation trigger this nightly.

These become actions that you can call in Scripts/Automations, e.g.

action: shell_command.set_wallpanel_brightness
data:
  level: 1000 # Any number 0-4095 works here

I’m not sure what command would turn the display completely off and back on (dpms doesn’t seem to be available), but a backlight brightness of 0 is extremely dim and not distracting IMO.

You can also use SSH commands to populate sensors / read values:

command_line:
  - sensor:
      name: ThinkSmart View Used Memory Percentage
      unique_id: wallpanel-ssh-used-memory
      command: ssh -i /config/id_ed25519_wallpanel -o StrictHostKeyChecking=no [email protected] -- free | grep Mem | awk '{print $3/$2 * 100.0}'
      unit_of_measurement: '%'
      scan_interval: 15
1 Like

If I’m trying to flash a pre-built PMOS image, is yours from last June still the best option?

As of right now, I’d say yes.

We’re very close to getting the ThinkSmart View supported in the automatically built images over on postmarketos.org.

In a few days you should be able to use the images at: edge/qcom-msm8953 - postmarketOS // Official Images
More specifically: As soon as this Merge Request gets merged and new images are built.
Right now those images will not have sound supported. But I’m working on that actively at the moment, so that should be coming shortly as well.

Do note that postmarketOS has just switched over to systemd from OpenRC for its init system last weekend and there are still a few bugs here and there.

1 Like

Those are good ideas. I also discovered the backlight control, but also couldn’t get it to be ‘off’ just super super dim. I figure that’s probably workable if there is no way to actually turn off the display, but I figure the device must be running some command internally to shut off the display after a timeout (and to turn it on when a physical button is pressed)? Is there a way to figure out what that it’s doing?

I believe the display manager uses DPMS.

One problem we have is that once the screen receives a DPMS powerdown the touchscreen dies with it, so you can’t wake the screen by touching it.
I’m still trying to figure out if this is a hardware limitation or something that we can somehow configure. But without the datasheet for the Display IC / Touch IC (they are combined in this device) it’s a bit poking in the dark here. Also we’re dealing with two different ICs (Himax HX83100A for earlier models and Focaltech FT8201 for later models) in this device.

Oh wow, I’m much more comfortable with systemd, coming from Debian. I guess that will require re-working a lot of the guides out there.

From what I’m seeing, changing the brightness to 0 via /sys/class/backlight/backlight/brightness actually results in a value of 40 the first time, but if you try to change it again right away it actually does change to 0 and the backlight goes fully off.

This is also the case with the A11 and Lineage roms, but IIRC, the original A8 ROM that was posted in this forum for the device did manage to make this work, so it should be theoretically possible.

Similar to how he is using echo {{ level }} > /sys/class/backlight/backlight/brightness to set the brightness level, you can use echo 1 | sudo tee /sys/class/backlight/backlight/bl_power to turn off the display completely, 0 turns it back on.
Note that it is not equivalent to the regular PMOS sleep functionality and that clicking the volume buttons will not turn the display back on.

On a similar note, is it possible to access the illuminance sensor value?

On Android 8, I wrote a Tasker task to do some adaptive brightness as the native one did not work, I’d like to do the same with PostmarketOS

Or maybe there is a native adaptive brightness functionality that I just haven’t found yet?

edit: I guess this is not possible for now.
see this comment

All the parts (minus sound support) are now in postmarketOS, so everyone should be able to build their own images by simply

  1. Installing pmbootstrap
  2. Running pmbootstrap init and selecting qcom-msm8953 as the device
  3. Running pmbootstrap install

That should produce an up-to-date, edl flashable rootfs image.

8 Likes

Indeed.
I still have to verify whether the sensor is actually damaged or not.
I did get readings from it, so it looks like the upstream driver is generally working.
But when I tried it it turns on the IR LED full blast and never turns it off. It got noticeably warm and then dimmed quite a bit subsequently, leading me to believe it may have been burnt out somewhat.

On Android the proximity sensor (and it’s IR LED) only wake up occasionally and very dimly to detect movement in front of the screen to wake the screen.

On Qualcomm platforms the sensors are dealt with by the DSP which then relays that sensor information back to the OS through shared memory. This is done so that the DSP can stay awake while the rest of the device (often a phone) goes to sleep to conserve battery. That way you can use sensor readings to wake the phone without having to run the sensors through the OS kernel.
In this case I’m bit-banging on the GPIOs that represent the I2C bus for the sensors because the processor’s security features halt the kernel if I actually try spawning an I2C bus directly on those GPIOs.

Just tried that, you are right! Looks like setting it again, does actually turn off the backlight. I guess the question is, how does one control this from Home Assistant? Having to SSH in would likely add a second or two delay. Would something like OliveTin work on PMOS, and would it be a good way to expose those shell commands as REST endpoints? Other better ideas?

@FelixKa
Are there any extra steps for people coming from Android system (the one where there is custom splash screen looking like home assistant). I am facing problems after flashing. My device goes straight to 900e. I build the signed lk2nd and also rootfs from pmbootstrap. That is all I have done. Both flashes looks like successful and the device goes straight to the 900e. Unfortunately I know nothing else about this device (which display and etc.). I have tried to go fully with the things from pmbootstrap install, no success either

Which branch/commit of lk2nd did you build?
I always use the latest main branch from here: GitHub - msm8916-mainline/lk2nd: Custom bootloader for Qualcomm MSM8916/MSM8226/MSM8974/... devices
There was a commit 3 weeks ago that broke lk2nd booting on the ThinkSmart View. It’s not really that commit’s fault, just that the ThinkSmart View is sad about this while most other devices don’t care about this change.
I’ve updated the note in the device’s dts file, because ever since then you need to build it with this command:

make TOOLCHAIN_PREFIX=arm-none-eabi- SIGN_BOOTIMG=1 LK2ND_QCDTBS="" lk2nd-msm8953

Check to see if that maybe fixes your issue.

Bonus feature, that’s currently only in the lk2nd main branch: lk2nd now shows the correct keys you need to use for navigating the menu

The fix you gave me makes difference. Right now device boot straight to Fastboot mode like in the attached image. I tried flashing couple of times the user data with different settings but without any luck. I could not track the original thread from which I flashed the first android to see what I have done already.
image
I went to Recovery and then to boot loader and I checked that It is indeed already locked. Which I think is correct by reading pmos docs for the device. I have fount the original post that I used to flash my device: Is this the perfect standalone tablet for HA?. I do not see anything critical on this post

Yes, the bootloader is expected to be locked.

For pmOS it should be enough to flash the rootfs to the userdata partition. If you’re in the lk2nd menu then fastboot mode is active and you can, if you used pmbootstrap install to build your image, use pmbootstrap flasher flash_rootfs to flash the proper rootfs in the proper location.

For the exact steps to flash a new out of the box device to postmarketOS you can look at the installation instructions over at the postmarketOS Wiki: Lenovo ThinkSmart View (lenovo-cd-18781y) - postmarketOS Wiki

FelixKa I do not know what is going on. I did flashed my device on lk2nd Fastboot screen with the command pmbootstrap flasher flash_rootfs but nothing has changed. I of course rebooted device and even left for a while.
The output from command was:

[17:52:55] (native) flash rootfs image
[17:52:55] (native) install android-tools
Sending sparse 'userdata' 1/2 (517032 KB)          OKAY [ 12.706s]
Writing 'userdata'                                 OKAY [ 46.163s]
Sending sparse 'userdata' 2/2 (327133 KB)          OKAY [  8.203s]
Writing 'userdata'                                 OKAY [ 21.094s]
Finished. Total time: 88.682s
[17:54:30] NOTE: chroot is still active (use 'pmbootstrap shutdown' as necessary)
[17:54:30] DONE!

pmbootstrap init would be:

[17:36:29] Location of the 'work' path. Multiple chroots (native, device arch, device rootfs) will be created in there.
[17:36:29] Work path [/home/mikart/.local/var/pmbootstrap]: 
[17:36:30] Choose the postmarketOS release channel.
[17:36:30] Available (10):
[17:36:30] * edge: Rolling release / Most devices / Occasional breakage: https://postmarketos.org/edge
[17:36:30] * v24.06: Latest release / Recommended for best stability
[17:36:30] * v23.12: Old release (unsupported)
[17:36:30] Channel [edge]: 
[17:36:51] NOTE: pmaports is on master branch, copying git hooks.
[17:36:51] Choose your target device vendor (either an existing one, or a new one for porting).
[17:36:51] Available vendors (91): acer, alcatel, amazon, amediatech, amlogic, apple, ark, arrow, asus, ayn, beelink, bq, clockworkpi, cubietech, cutiepi, dongshanpi, epson, essential, fairphone, finepower, fly, fxtec, generic, goclever, google, gp, hisense, htc, huawei, inet, infocus, jolla, klipad, kobo, lark, leeco, lenovo, lg, librecomputer, linksys, mangopi, medion, meizu, microsoft, mobvoi, motorola, nextbit, nobby, nokia, nvidia, odroid, oneplus, oppo, ouya, pine64, planet, pocketbook, postmarketos, powkiddy, purism, qcom, qemu, qualcomm, radxa, raspberry, realme, samsung, semc, sharp, shift, sipeed, sony, sourceparts, surftab, t2m, thundercomm, tokio, tolino, trekstor, valve, vernee, vivo, volla, wexler, wiko, wileyfox, xiaomi, xunlong, yu, zte, zuk
[17:36:51] Vendor [qcom]: 
[17:36:53] Available codenames (3): msm8909, msm8916, msm8953
[17:36:53] Device codename [msm8953]: 
[17:36:54] Username [administrator]: 
[17:36:55] Available providers for postmarketos-base-ui-wifi (2):
[17:36:55] * wpa_supplicant: Use wpa_supplicant as the WiFi backend. (default)
[17:36:55] * iwd: Use iwd as the WiFi backend (but may not work with all devices)
[17:36:55] Provider [default]: 
[17:36:57] Update package index for aarch64 (4 file(s))
  0%                                                                           [sudo] password for mikart: 
[17:37:04] Available user interfaces (23): 
[17:37:04] * none: Bare minimum OS image for testing and manual customization. The "console" UI should be selected if a graphical UI is not desired.
[17:37:04] * asteroid: (Wayland) Smartwatch UI from AsteroidOS
[17:37:04] * bananui: (Wayland) Keypad controlled UI for feature phones
[17:37:04] * cage: (Wayland) Kiosk WM
[17:37:04] * console: Console environment, with no graphical/touch UI
[17:37:04] * fbkeyboard: Plain framebuffer console with touchscreen keyboard support
[17:37:04] * framebufferphone: Minimalist framebuffer menu/keyboard UI accessible via touch/volume keys & compatible scripts
[17:37:04] * gnome: (Wayland) Gnome Shell
[17:37:04] * gnome-mobile: (Wayland) Gnome Shell patched to adapt better to phones (Experimental)
[17:37:04] * i3wm: (X11) Tiling WM (keyboard required)
[17:37:04] * kodi: (GBM) 10-foot UI useful on TV's
[17:37:04] * lxqt: (X11) Lightweight Qt Desktop Environment (stylus recommended)
[17:37:04] * mate: (X11) MATE Desktop Environment, fork of GNOME2 (stylus recommended)
[17:37:04] * moonlight: (Wayland) Open Source PC client for NVIDIA GameStream, as used by the NVIDIA Shield
[17:37:04] * openbox: (X11) A highly configurable and lightweight X11 window manager (keyboard required)
[17:37:04] * phosh: (Wayland) Mobile UI initially developed for the Librem 5
[17:37:04] * plasma-desktop: (X11/Wayland) KDE Desktop Environment (works well with tablets)
[17:37:04] * plasma-mobile: (Wayland) Mobile variant of KDE Plasma (does not run without hardware acceleration)
[17:37:04] * shelli: Plain console with touchscreen gesture support
[17:37:04] * sway: (Wayland) Tiling WM, drop-in replacement for i3wm (DOES NOT RUN WITHOUT HW ACCELERATION!)
[17:37:04] * sxmo-de-dwm: Simple Mobile: Mobile environment based on SXMO and running on dwm
[17:37:04] * sxmo-de-sway: Simple Mobile: Mobile environment based on SXMO and running on sway
[17:37:04] * weston: (Wayland) Reference compositor (demo, not a phone interface)
[17:37:04] * xfce4: (X11) Lightweight desktop (stylus recommended)
[17:37:04] User interface [phosh]: cage
[17:37:07] Additional options: extra free space: 0 MB, boot partition size: 256 MB, parallel jobs: 9, ccache per arch: 5G, sudo timer: False, mirror: http://mirror.postmarketos.org/postmarketos/
[17:37:07] Change them? (y/n) [n]: 
[17:37:16] Additional packages that will be installed to rootfs. Specify them in a comma separated list (e.g.: vim,file) or "none"
[17:37:16] Extra packages [mobile-config-firefox,firefox-esr]: 
[17:37:16] Your host timezone: Europe/Warsaw
[17:37:16] Use this timezone instead of GMT? (y/n) [y]: 
[17:37:19] Choose your preferred locale, like e.g. en_US. Only UTF-8 is supported, it gets appended automatically. Use tab-completion if needed.
[17:37:19] Locale [en_US]: 
[17:37:20] Device hostname (short form, e.g. 'foo') [m-pmos-01]: 
[17:37:22] NOTE: No SSH public keys found to copy to the device.
[17:37:22] See https://postmarketos.org/ssh-key-glob for more information.
[17:37:22] After pmaports are changed, the binary packages may be outdated. If you want to install postmarketOS without changes, reply 'n' for a faster installation.
[17:37:22] Build outdated packages during 'pmbootstrap install'? (y/n) [n]: 
[17:37:25] Zap existing chroots to apply configuration? (y/n) [y]: 
[17:37:27] Unregister qemu binfmt (aarch64)
[17:37:28] DONE!

pmbootstrap install would be:

[17:37:36] *** (1/4) PREPARE NATIVE CHROOT ***
[17:37:36] Update package index for x86_64 (4 file(s))
[17:37:37] (native) Creating chroot
[17:37:39] (native) install cryptsetup util-linux parted
[17:37:40] *** (2/4) CREATE DEVICE ROOTFS ("qcom-msm8953") ***
[17:37:40] (native) install qemu-aarch64
[17:37:41] Register qemu binfmt (aarch64)
[17:37:41] (rootfs_qcom-msm8953) Creating chroot
[17:37:45] (rootfs_qcom-msm8953) install postmarketos-base device-qcom-msm8953 postmarketos-ui-cage mobile-config-firefox firefox-esr postmarketos-base-nofde doas postmarketos-demos font-droid font-droid-nonlatin font-twemoji
[17:38:15] (rootfs_qcom-msm8953) install device-qcom-msm8953
[17:38:16] (rootfs_qcom-msm8953) install postmarketos-mkinitfs
[17:38:16] (rootfs_qcom-msm8953) mkinitfs postmarketos-qcom-msm8953
[17:38:34]  *** SET LOGIN PASSWORD FOR: 'administrator' ***
New password: 
Retype new password: 
passwd: password updated successfully
[17:51:31] NOTE: No valid keymap specified for device
[17:51:33] *** (3/4) PREPARE INSTALL BLOCKDEVICE ***
[17:51:34] (native) create qcom-msm8953.img (1333M)
[17:51:34] (native) mount /dev/install (qcom-msm8953.img)
[17:51:34] (native) partition /dev/install (boot: 256M, reserved: 0M, root: the rest)
[17:51:35] Mounting partitions of /dev/loop15 inside the chroot
[17:51:35] (native) install e2fsprogs
[17:51:35] (native) format /dev/installp2 (root, ext4)
[17:51:35] (native) mount /dev/installp2 to /mnt/install
[17:51:36] (native) install e2fsprogs
[17:51:36] (native) format /dev/installp1 (boot, ext2), mount to /mnt/install/boot
[17:51:37] (native) create /etc/fstab
[17:51:37] (rootfs_qcom-msm8953) mkinitfs
[17:52:04] *** (4/4) FILL INSTALL BLOCKDEVICE ***
[17:52:04] (native) copy rootfs_qcom-msm8953 to /mnt/install/
[17:52:11] 
[17:52:11] *** FLASHING INFORMATION ***
[17:52:11] Run the following to flash your installation to the target device:
[17:52:11] * pmbootstrap flasher flash_rootfs
[17:52:11]   Flashes the generated rootfs image to your device:
[17:52:11]   /home/mikart/.local/var/pmbootstrap/chroot_native/home/pmos/rootfs/qcom-msm8953.img
[17:52:11]   (NOTE: This file has a partition table, which contains /boot and / subpartitions. That way we don't need to change the partition layout on your device.)
[17:52:11] * pmbootstrap flasher flash_kernel
[17:52:11]   Flashes the kernel + initramfs to your device:
[17:52:11]   /home/mikart/.local/var/pmbootstrap/chroot_rootfs_qcom-msm8953/boot
[17:52:11]   (NOTE: fastboot also supports booting the kernel/initramfs directly without flashing. Use 'pmbootstrap flasher boot' to do that.)
[17:52:11] * Your device supports and may even require flashing lk2nd. You should flash it before flashing anything else. Use 'pmbootstrap flasher flash_lk2nd' to do that.
[17:52:11] * If the above steps do not work, you can also create symlinks to the generated files with 'pmbootstrap export' and flash outside of pmbootstrap.
[17:52:11] 
[17:52:11] *** SSH DAEMON INFORMATION ***
[17:52:11] SSH daemon is enabled (disable with --no-sshd).
[17:52:11] Login as 'administrator' with the password given during installation.
[17:52:11] 
[17:52:11] *** FIREWALL INFORMATION ***
[17:52:11] Firewall is enabled, but may not work (couldn't determine if kernel supports nftables).
[17:52:11] For more information: https://postmarketos.org/firewall
[17:52:11] 
[17:52:11] NOTE: chroot is still active (use 'pmbootstrap shutdown' as necessary)
[17:52:11] DONE!

Odd. That should work. What I can do is provide you with a full EDL dump from one of my devices that works properly. Maybe that’ll set up everything correctly. Would you like to try that?

Is there a PR or repo we can watch for the sound support you’re working on getting in upstream?

@FelixKa I would like to have a look at the sensors. Could you please post the bitbanging commands you use to read these sensors data? I’m interested in ambient light level and proximity detection. I would like to investigate the IR led: it should be possible to power it down manually. It wouldn’t be perfect, but it could go into a script.

@mikart143 the problem you are having is from the latest userdata image available on https://images.postmarketos.org/bpo/edge/qcom-msm8953/phosh/20250124-1029/20250124-1029-postmarketOS-edge-phosh-22.5-qcom-msm8953.img.xz

Besides the known problem with the bootloader, the image may also be missing a few fixes: if you look at the boot messages, you can see ModemManager starting, then a few errors after which the display is erased: finally, the device is left with a blank screen and a blinking cursor on the top left.

I think it’s just waiting for the misconfigured systemd units to finish booting and start either getty, xorg or wayland.

@FelixKa, considering both the bootloader and userdata are broken in the latest public images, I would suggest uploading your own private images you work with.

I would be happy to have a look and fix the public image, but I’m still waiting for my USB-C test board to solder a 1.8V serial port cable to the correct pins. If anyone wants one cheaper than Amazon, check https://www.aliexpress.us/item/3256804291364712.html or use the keywords " 1pcs Type-C Male to Female USB 3.1 Test PCB Board Adapter Type C 24Pin 2.54mm Connector Socket For Data Line Wire Cable Transfer"

I will post instructions on how to use this PCB to make a dual UART and USB cable, using the pinout from the wiki: “SBU1/SBU2 (A8/B8) for RX and CC1/CC2 (A5/B5) for TX” : I see “USB-C socket is not wired up to provide USB ID” but that “the device will revert from host mode to device mode when the external power source is removed”, so adding a simple female barrel connector to the board adapter VBUS (A9/B9) and GND should be enough, both to power USB peripherals and toggle the OTG to host. Unplugging the barrel power would return the OTC to device.

1 Like