Thursday, October 8, 2020

old cell phones for webcams (usb, wifi)

Links: Android Partitions :: Arch Android tools :: xda F3Q
xda xiaomi redmi2 :: xiaomi community :: more flashboot commands

NB: check out updated 2022 version


Overview

Two main layers of software function:

  • system video is of course displayed on a laptop or screen. Several layers of internal software must accomodate webcams.
    1. The kernel should detect the video source
    2. software like V4L2 should be able to transport detected video.
    3. software like ffplay or OBS with ftl can then display transported video.
  • phone configuration software, typically fastboot, usually has many poorly documented model-specific functions. Still, it's a necessary step because the phone webcam is not a stand-alone camera, but functioning within phone firmware.

The handshake is the trickier, more time-consuming project. Yet the handshake tends to be low maintenance, once established. When configured properly, the phone cam should be detected like any other cam by the kernel. We'll start with USB access into the phone to configure it; following configuration, the phone cam can connect via WiFi or via USB.

phone powerup

Rooting a phone typically compromises its camera commands and degrades resolution. To avoid rooting the phone, we want to set Android into developer mode with USB bugging turned-on. Then we can connect via USB and authorize an ADB program. Once that's in, we can get to the phone's cam.

Most Androids can initialize in several modes. We want them in either ADB mode or Fastboot mode. Another site about this. The F3 and one of the F3Q's powered into fastboot mode (more fastboot commands), and still did not boot after a hardware reset. Good article here and it's important to know the Android partion names.

Even with correct fastboot syntatx....

# pacman -Syu android-tools
# fastboot oem unlock
OKAY [ 0.291s]
Finished. Total time: 0.291s
# fastboot erase boot
Erasing 'boot' FAILED (remote: 'failed to erase partition')
fastboot: error: Command failed
# fastboot format boot
fastboot: error: Formatting is not supported for file system with type ''.

It was a weekend long process to simply boot one of these phones into operation as a webcam

Note also that the adb commands were inoperative with all the phones, eg # adb devices produced nothing. Eventually, adb kill-server was run. Back to flashboot and determining the proper flags for it.

xioami tools

All three devices have Xiaomi inside. There's a good Xiaomi tool, xiaomi-adb-fastboot-tools, in the AUR. It runs on Java and needs the JRE...

$ yay -S xiaomi-adb-fastboot-tools

Sometimes this worked, but it failed to compile on boxes with the newest version of Java. On systems which it did compile, I couldn't find the executable.

$ which xioami*

...returned nothing. A Redditor helped me out...

$ pacman -Qql "$pkg_name" | while read fn; do [[ -x $fn && -f $fn ]] && echo "$fn"; done

...which returned...


Phones

One LG F3 and two LG F3Q's were available. All 3 were Jellybean (4.12), with 5MP cameras.

BTW, no idea why these 2 fastbooted, I hadn't tried to root or tamper with the devices. The 3rd phone booted normally, but since I had moved my SIM into my active phone, I could only connect by WiFi without Google Play store. How then to download webcam apps? Ultimately, without being able to boot the phone nor get access to Google Play, the unfortunate reality seemed rooting the two unbootables. They may also have had some sort of Factory Reset Protection (FRP), not sure.

Xiaomi sidenote

Xiaomi is the phone's cell xponder manf. It's actually a Qualcomm SnapDragon 410E. The phones I used were all Redmi 2, presumably with wt88047 hardware. When a phone powers into fastboot, lsusb provides the phone's internal manufacturer ID instead of the LG phone ID. For example, below you'll see the bootable F3Q displayed a charging identifier, but the F3Q that powered into fastboot displayed the 18d1:d00d Xiaomi Redmi 2 hardware identifier. Xiaomi itself produces some ROM's; their site is worthy of research also.

LG Optimus F3Q D520 (lg-d520)

$ lsusb
1004:6300 LG Electronics, Inc. G2/Optimus Android Phone [Charge mode]
1004:632c LG Electronics, Inc. LGE Android Phone [MTP files]
1004:631e LG Electronics, Inc. LM-X420xxx/G2/Optimus Android Phone (PTP/camera mode)
18d1:d00d Google Inc. Xiaomi Mi/Redmi 2 (fastboot)

5MP HDMI autofocus, Snapdragon 400, Android 4.12 (Jellybean). Only 1.3GB internal but takes a 32GB microSD

files
stock for the F3Q (d520) D52010c_00.kdzfactory firmware (ZIP or KDZ), flashed to "boot". aka ROM.
stock for the F3 (p659) P65910b_05.kdzfactory firmware (ZIP or KDZ), flashed to "boot". aka ROM.
structure/workflowfactory image (always IMG) for the device
color balanceapplication (always APK) to root
crossfadeslideshow complex! use a GUI app
de-interlacewatermark
gif

LG Optimus F3 (lg-p659)

$ lsusb
18d1:d00d Google Inc. Xiaomi Mi/Redmi 2 (fastboot)

5MP HDMI autofocus, Snapdragon 400, Android 4.12 (Jellybean). Only 1.3GB internal but takes a 32GB microSD

Fastboot Process

YES

fastboot oem device-info
fastboot getvar product
    product: FX3Q_TMO_US
    product: FX3_TMUS
fastboot continue

NOPE

fastboot erase boot
fastboot flashing unlock_critical

failed f3q hard reset

The first pass at restoring factory failed with the message...

Secure booting error!
Cause: boot certificate verify

errors

  • partion table doesn't exist :: command: fastboot erase data Valuable response also helping with directory names.
  • Error2: Failure sending erase group start command to the card (RCA:2) :: command: fastboot erase recovery

Card RCA:2

This card was nearly continually in failures

# fastboot continue
[phone] Error No. 2: Failure sending read command to the Card (RCA:2)

One site had a theory about why recovery writes fail having to do with multiple bootloader slots. My phones though....

# fastboot --set-active=a
fastboot: error: Device does not support slots
# fastboot getvar slot-count
slot-count:

ADB Process

ADB mode is less important than Fastboot mode, but problems in Fastboot can sometimes be solved by having a proper ADB capability. So it can be worth it. The commands are different from Fastboot. Also, you might even have to manually make Plugdev rules for the damned thing. If you can see it in lsusb, you have a chance.

YES

adb start-server
adb kill-server
adb logcat
adb devices
fastboot continue

NOPE

fastboot erase boot
fastboot flashing unlock_critical

failed f3q hard reset

The first pass at restoring factory failed with the message...

Secure booting error!
Cause: boot certificate verify

errors

  • partion table doesn't exist :: command: fastboot erase data Valuable response also helping with directory names.
  • Error2: Failure sending erase group start command to the card (RCA:2) :: command: fastboot erase recovery

plugdev group

I want to add a system group

# groupadd -r plugdev
, add myself to it, and then also of course make a rule...
# nano /etc/udev/rules.d/51-android.rules
. The rule is described well here.

SD/USB boot

Site describes how to unbrick using the EMMC method, special software. It appears however this method requires also converting the KDZ file into BIN files for the software. A pain.

A33 Unbrick with SD Card (8:09) Kiko Dog, 2015. Requires special program to burn the OS onto the SD card.