As some may have already noticed, there is a new directory in the nightly builds folder: https://basicengine.org/git_builds/h616_rx/
It contains SD card images for various boards based on the Allwinner H616, H618 and H313 SoCs. (These three chips are very similar, and I will refer to them as H616 from here.)
Platform Status
Support for this platform is currently experimental (or rather, more experimental than others), and quite a few things don't work yet:
- video recording
- analog video output
- all I/O interfaces except GPIO
- probably some stuff I forgot
Platform peculiarities
Unlike with the H3, where most boards seem to use the same (or a sufficiently similar) memory configuration, H616 boards come with a wide range of DRAM types and configurations. I have, in fact, yet so see any boards that have the same configuration. The DRAM controller needs to be set up very early in the boot process, and because there is no RAM access before that, there is no way to determine the DRAM configuration by loading a config file from SD card, asking for user input or anything like that.
This unfortunately means that, unlike with H3, where one image would fit most boards and you can simply choose which board you have in a boot menu, H616 boards each need to have a completely different SD card image, and it needs to fit your specific board, or it just won't do anything.
This is not so much of a problem for branded boards such as Orange Pis, but for generic TV boxes it is next to impossible to tell what exactly is in there without cracking them open. It took me quite a while, for instance, to figure out that my "X96 Q" TV box has LPDDR3 instead of DDR3 memory in it.
At the moment, the nightly builds contain images for these boards:
- Orange Pi Zero 2
- Orange Pi Zero 3
- Tanix TX6S
- Tanix TX6S with AXP313
- X96 Q TV box with DDR3 memory
- X96 Q TV box with LPDDR3 memory
I only have two of these boards (Orange Pi Zero 2 and X96 Q LPDDR3); the others are untested.
Leveraging Linux drivers to cut down on porting effort
Porting a bare-metal application to a new platform is a lot of effort. Even though the H616 is an Allwinner SoC and is quite similar to the H3, there are numerous small differences (documented and especially undocumented) that make it not at all straightforward to get existing hardware drivers to run on it correctly. Examples include, but are not limited to:
- a completely different audio subsystem ("AHUB")
- a different display engine (DE3.3) that seems to be less dissimilar from the DE2.0 in the H3 than from the DE3.0 in other Allwinner SoCs, because of course it is; it is also entirely undocumented...
- a different TV encoder
To cut down on the effort, I tried an approach in which the Linux kernel initializes the hardware, and Engine BASIC goes to hijack it once it's running. If that sounds sketchy, that's because it is.
But it works.
For the video subsystem, Linux initializes HDMI and Display Engine as usual for the framebuffer console; once BASIC starts, the Jailhouse hypervisor redirects the vertical blank interrupt to Engine BASIC, and EB controls the Display Engine from there. This saves us from having to implement the HDMI driver entirely, with no impact on performance.
Similarly, but even sketchier, the audio subsystem is initialized by playing silence on the analog and digital audio devices in Linux. Once Engine BASIC starts, it pauses the DMA channels, leaving the Linux-side driver and userspace processes in limbo, and uses the AHUB FIFO interrupt (which happens to be unused in Linux) to feed its own audio instead. Again, the performance is identical to the full driver approach on the H3, but it alleviates the need for a completely new driver (two, actually; one for HDMI and one for analog), only requiring a small stub to pull off the aforementioned trick.
Future platform support
Is this the ultimate solution to the problem of portability? Honestly, I doubt it. There were some lucky breaks in there (the unused AHUB interrupt, for instance), and in some cases it was solely the similarity between the H3 and the H616 that saved the day. In spite of all the shortcuts, the Display Engine driver still isn't trivial. If I hadn't been able to reuse the largest part of it this whole approach would not have worked nearly as well.
In the end, I really wish I could run EB as a real-time process in Linux instead of on the bare metal...
I think I'm going to do more research in that area.
In the meantime you can get yourself an H616 board and try it out. Some of these TV boxes are almost as cheap as the OPi Lite in the olden days. 😄