Gentoo on the Arduino Uno Q
Yesterday, after perusing through Micro Center, I stumbled across an Arduino Uno Q. At the time, I had no clue what it was. It seemed very interesting on the box, so I decided to buy it.
I'm gonna skip everything about the unit itself, but it's basically a Raspberry Pi Zero strapped to an STM32 with glue logic.
Now, I am a huge fan of low level hardware shenanigans. Unfortunately, the preinstalled OS has a lot of that abstracted away. Which is great for most users, but I wanna get down and dirty.
It seems that I must be the first one to attempt to install Gentoo on this silly little thing, which is honestly surprising.
There's.... very poor documentation on how one would begin going about this. The manual mentions a USB boot jumper, which one would think allows it to boot from USB mass storage, but really just puts it in firmware download mode.
This means that in order to install an OS onto it, I need to install it elsewhere, like in a VM or chroot, create an image file that is compatible with the flashing software, and then upload that to the unit.
The documentation has a tendency to say "just use the software we made." Everywhere. They don't even have direct links to the firmware image, I had to dig through the source code of the flasher utility to get it.
Speaking of the flasher software, it seems to be not much more than just a fancy frontend to the "qdl" utility. All it does is gets the image, extracts it, and runs qdl.
I have very little experience with qdl, so I decided to just use the pre-existing image as a template.
There is a bunch of small partitions I decided not to mess with because I don't wanna brick the thing, and three very large partitions: one for root, one for home, and one for the ESP.
In the source code, it chooses between two program files to pass to QDL to tell it what to program -- one for a separate root and /home (rawprogram0.xml) and one for a single rootfs (rawprogram0.nouser.xml). I decided to go with the latter, for reasons that will become apparent later on.
Luckily, once you extract the tarball for the image, all the partitions are just plain raw image files, meaning that I can easily mount them. (mount disk-sdcard.img.root /mnt/gentoo)
Now that I have the target drive mounted, I installed and set up qemu-user for aarch64, to prepare for a chroot. This is necessary if you're using a computer that isn't aarch64.
I completely wiped the rootfs (rm -rf --one-file-system /mnt/gentoo/*) and extracted an aarch64 musl gentoo stage3 in its place (cd /mnt/gentoo; curl <url> | tar -xpJf - --numeric-owner --xattrs-include '*.*').
I mounted the ESP partition as well (mount disk-sdcard.img.esp /mnt/gentoo/boot) and entered the chroot (arch-chroot /mnt/gentoo).
From here, I installed a very quick and dirty basic install. If you want to replicate this, just follow the Gentoo AMD64 Handbook, it's close enough.
Finally, once I was done, I exited the chroot, unmounted the ESP and rootfs.
Now, to flash it, I placed a jumper on the bottom pins of the JCTL header (the side away from the USB port), plugged it into my computer, and flashed it with the following command, executed within the "flash" directory:
qdl --allow-missing --storage emmc prog_firehose_ddr.elf rawprogram0.nouser.xml patch0.xml
Note that I'm not sure what most of this means or does, that's just what the flasher software does under the hood.
Upon next reboot, I was greeted with Gentoo! Except... It's still using the old kernel and old bootloader. Still have to figure that out.
There's... some problems with that, namely that it doesnt have the kernel modules required for a lot of the functionality, so you have absolutely no network, bluetooth, or anything really. Unfortunately it seems that the EFI variable subsystem is locked read-only or something, so changing the bootloader is a little harder than just "grub-install"