samcday / archlinux-msm8916

2 stars 0 forks source link

"Live fastboot" #25

Open samcday opened 3 months ago

samcday commented 3 months ago

Idea: produce an archiso style image, with a fastboot twist.

The first part is producing an Android fastboot boot-friendly boot.img that is comprised of kernel + minimal initrd that mounts the rootfs via nbd over the USB network. The rootfs would be an overlay (with the lower being a squashfs, I guess?) + tmpfs upper.

The rootfs itself would be something like archiso. A minimal-ish rootfs with a collection of useful tools - everything you would need to mess with an msm8916 device, as well as install a "real" Arch install on the emmc.

Bonus points to make it all work in-browser. Though sadly this would mean no Firefox support since such a thing would need both WebUSB and access to RFC1918 IPs...

samcday commented 3 months ago

So the existing nbd hook is actually remarkably simple: https://github.com/mus65/mkinitcpio-nbd/blob/master/nbd_hook

It's essentially just: modprobe nbd and then run nbd-client with the connection details fed in from command-line. The end result is a /dev/nbd0 that can be set as the root=.

The only tricky part is the early USB-specific setup. I spent a few milliseconds contemplating taking something like this Rust crate and using it to run the NBD protocol over USB (with FunctionFS on the device side and libusb on the host side) rather than TCP. But that's probably overkill (and reaching for Rust for the sake of reaching for Rust xD).

It still might be worth considering something like that, since it would pave the way for the ideal web-based boot support. For an initial prototype I'll just use NCM on the device side to establish a regular IP link. This means that the host side needs to run some privileged stuff in order to watch netlink for the USB link and then assign an IP.

The "pump it through USB" thing would also be tricky because it would require interacting with the kernel to make a block device thing happen. That would be a fun learning experience though, to be sure.

samcday commented 3 months ago

Actually, thinking a little further ahead: once the live environment is booted, it's gonna be desirable to have internet access on the device side.

For the prototype that can be hacked into place: make the device add a default route pointing to the host IP, and then have the host do the necessary sysctl + iptables pokery to forward the IP traffic from device.

With a proper USB custom gadget in place though, it could handle both the rootfs block device mounting and also internet access, and would (probably?) also work in the browser.

samcday commented 3 months ago

Then again, internet access could be handled entirely differently and much more simply: just require that the user logs into a wifi connection once the live environment has booted.