garage44.eu/jeroen/pinnacle

logclone: git clone https://garage44.eu/jeroen/pinnacle.git

.. /docs/hardware.md

raw

Booting Pinnacle on hardware

Pinnacle is developed on QEMU; its first hardware port is rk3399, for boards with a Rockchip RK3399 (or RK3399S) that start from U-Boot. Nothing here has run on hardware yet: these are the steps for the first try.

What it takes

The card

cargo xtask sdcard          # → target/sdcard/: Image, extlinux/extlinux.conf

Format the card's first partition FAT32 and copy the contents of target/sdcard/ onto it, keeping the extlinux folder:

/Image
/extlinux/extlinux.conf

U-Boot's distro boot finds extlinux.conf and starts /Image with booti, passing its own device tree.

Booting

  1. Connect the serial cable to a computer and open its port at 1 500 000 baud, 8N1 (picocom -b 1500000 /dev/ttyUSB0, or screen).
  2. Put the card in and power on. If U-Boot prefers another boot device, its menu or prompt can choose the SD card.
  3. On the serial console U-Boot prints its own lines, then Pinnacle's:
Pinnacle 0.1.0 on rk3399
running at EL1, entered at EL2, caches on, device tree at 0x...
memory: ...

The self-check then runs as it does in QEMU. At the end the board turns itself off (PSCI), passed or failed: the last lines say which.

The screen

Pinnacle has no driver yet for an RK3399's display controller, its panel or the PMIC that powers them. It draws on a screen the bootloader left lit: memory a display controller is already scanning out (kernel/src/drivers/scanout.rs). It finds one, before it hands out any memory, in one of two ways:

  1. A simple-framebuffer node in the device tree the loader passes, with its memory in the tree's reservation block — what U-Boot writes when it keeps its video on for the kernel.
  2. Else, on an RK3399, the display controllers' own registers: the first window of VOP-big or VOP-little, if it is on, read only when the CRU says the controller's clocks run.

At boot the serial console says which it took:

display: 1920x1080 (rk3399 VOP)

and from then on the system draws there as it does in QEMU, at that one size (turning the screen is refused). With no lit screen it says display: none and runs on the serial console alone.

Which boards this shows anything on is not known yet. A Pinebook Pro with Tow-Boot leaves its eDP panel lit; whether the PinePhone Pro's Tow-Boot lights its panel at all, and whether U-Boot on either passes a simple-framebuffer, needs the board. eMMC, the battery, the PMIC and a touch screen (the PinePhone Pro's, on I²C) wait for drivers.

The keyboard and touchpad

A Pinebook Pro's keyboard and touchpad are one USB device inside it, at full speed (USB 1.1), on the RK3399's first USB 2.0 host: its EHCI hands such a device to the OHCI beside it, which Pinnacle drives (drivers/usb/ohci.rs). The kernel first does what Linux does to that host whatever the loader left: the hosts' clocks ungated in the CRU, each USB 2.0 PHY's clock output on and its host port out of suspend in the GRF (board::usb_hosts_on), and each EHCI halted with its ports given to its OHCI. None of it has run on a board yet; on the serial console it should say something like this (the device's name is its own, and Linux's logs of a Pinebook Pro give it as HAILUCK's):

usb: rk3399 hosts: gates 0x0 0x0, PHY ports 0x2 0x2; turned on
ehci: usb@fe380000: 1 ports to its companion
ohci0: OHCI, 1 ports
ohci0: port 1: keyboard (HAILUCK CO.,LTD USB KEYBOARD)
ohci0: port 1: mouse (HAILUCK CO.,LTD USB KEYBOARD)

The values before "turned on" are what the loader left (a set gate bit was a gated clock; a PHY port of 1 was suspended). A device of the second host's port (the Pinebook Pro's USB-A 2.0 port) is found the same way, as ohci1, when it is there at boot; a device plugged in later is not seen. The port's 5 V (the Pinebook Pro's vcc5v0_usb, a GPIO) is left as the loader set it: with no ohciN: port line at all, it is the first thing to look at.

In QEMU, cargo xtask pinebook-demo boots with that input and no other (QEMU's keyboard and mouse on its OHCI), chooses the data's password on the keyboard and opens Settings with the mouse's pointer and click; the self-check's first boot has the same OHCI devices beside the xHCI ones.

In QEMU the same path runs as a loader would leave it: cargo xtask test boots once with a device tree that carries a lit screen and reserved firmware ranges, and cargo xtask lit-shot photographs that screen's memory with the system running (its first screen).

What it tells us

Each line is a step that held on real hardware; the last line printed is where to look when it stops. With no output at all after U-Boot's, the early boot (the move to the load address, the MMU) is the first suspect.

A PC's and a laptop's own hardware

Beside the virtio devices QEMU offers, the kernel drives what real PCs and laptops have, on PCI, on both architectures. Each was written from its specification and is tested in QEMU, which emulates all of them; none has run on a real machine yet.

DriverWhat it takesWhere
USB (drivers/usb): an xHCI host controllerevery device on its root ports, given an address, its configuration read and chosen; plugged in and pulled out later, followed by a kernel taskPCI class 0c:03:30
USB hubs (usb::hub)USB 2 and USB 3 hubs, up to five deep: told to the controller as hubs, ports powered, each device reset and addressed by its route (through a high-speed hub's translator when it is slower); its status-change endpoint followed for plugging in and outclass 09
USB 1.1 (usb/ohci.rs): an OHCI host controllerthe keyboards and pointing devices on its root ports at boot, given an address and their input interfaces read, a report polled every frame; no hubs, no sticks, nothing plugged in later. Its descriptors cleaned from and invalidated in the cores' caches, for a board whose USB does not see them (the RK3399)generic-ohci, PCI class 0c:03:10
USB keyboards (usb::hid)the boot protocol's report, keys as the virtio keyboard's (Linux's codes)HID class
USB mice, tablets, touch screens (usb::hid)the report descriptor read for X, Y, wheel and buttons; absolute devices point where they point, a mouse moves a pointer the kernel keeps and the display server drawsHID class
USB sticks and disks (usb::storage)Bulk-Only Transport, SCSI READ/WRITE(10), up to 64 KiB a commandclass 08, subclass 06, protocol 50
NVMe (drivers/nvme.rs)one admin and one I/O queue pair, each namespace a disk, up to 32 requests in flightPCI class 01:08:02
AHCI (drivers/ahci.rs)each port with a SATA disk, up to 16 commands in slots of their own; optical drives left alonePCI class 01:06:01
Intel HDA sound (drivers/hda.rs)the controller reset, its codecs found and spoken to through the command rings (CORB/RIRB; the immediate registers when those do not answer); the first codec with an analog output walked from the speaker's pin and the headphone jack's to a converter, through mixers and selectors, all powered, unmuted at 0 dB, EAPD on; one output stream of 10 ms periods from the kernel's mixer (48 kHz 16-bit stereo), its interrupt as each completes, the position from LPIB; the speaker off while headphones are in (the jack's unsolicited response)PCI class 04:03
Intel Ethernet (drivers/e1000.rs)the e1000e family: the 82574L, 82579, and the chipsets' I217, I218 and I219; one ring each way, its interrupt by MSIPCI 8086, by ID
Intel Wi-Fi (drivers/iwlwifi.rs; the formats in pinnacle_wifi::iwl), as far as its firmware's start: AX201 (the 22000 family's Qu/QuZ MAC with an HR radio, the CNVi of 10th and 11th generation Core), AX211 (the AX210 family's So or Ma MAC with a GF radio, 12th generation on) and the AX210 card (Ty)BAR 0 mapped; the MAC's and radio's types and steps read (CSR_HW_REV, CSR_HW_RF_ID, else the CRF ID) and the firmware file chosen as Linux names it; the chip taken (PCI_OWN_SET), reset, woken (INIT_DONE, MAC_ACCESS_REQ), power-gated as an integrated 22000 wants; Intel's closed firmware read from system:/firmware/intel/ ("Closed firmware" below), its sections each in DMA memory of their own; a context info (22000) or context info v2, periphery scratch and image loader (AX210 family) pointing at them, at a 512-entry receive queue and a command queue; the CPU started, the ALIVE cause polled, the receive buffers then given, the ALIVE notification read and printed (status, LMAC and UMAC versions, SKU) and the PNVM section for that SKU found. Then the chip is reset and its bus mastering turned off: scanning, joining and packets are the next stage. Untried: QEMU has no Intel Wi-FiPCI 8086:02f0, 06f0, 34f0, 4df0, 43f0, a0f0, 51f0, 51f1, 54f0, 7af0, 7e40, 2725
The keyboard controller (drivers/ps2.rs, PC only)a laptop's own keyboard (set 1, translated by the controller) and its touchpad as a PS/2 mouse, with a wheel where it says so; interrupts 1 and 12 through the I/O APICports 0x60, 0x64
The firmware's screen (board::pc, drivers::scanout)the framebuffer UEFI's GOP left lit, as the loader passes it on: 32-bit RGB either way round, or 16-bit 5-6-5, in the mode the firmware set; written through a window of its own mapped write-combining (IA32_PAT's entry 1, as Linux has it; the direct map is uncached there), an sfence after each copy, and the boot log says how long a whole frame takes each way (display: a whole frame … us write-combining, … us uncached); the boot log drawn on it (drivers::screen_log) until the display server takes itMultiboot2's framebuffer tag
Intel graphics (drivers/i915.rs), Skylake (Gen9) to Alder Lake (Gen12)the function at 00:02.0 claimed and its registers (BAR0) mapped; the panel's backlight through the chipset's PWM, as the firmware left it on: Sunrise and Kaby Point's BLC_PWM_PCH_CTL1/CTL2 (0xC8250, 0xC8254: period and duty cycle 16 bits each), Cannon Point's on (Coffee Lake to Alder and Raptor Lake) control, period and duty registers of their own (0xC8250, +4, +8; the controller the firmware left on), the chipset told by the ISA bridge's ID at 00:1f.0; never below 5 %; brightness system call (72), a slider in Settings → Screen, kept in /settings/brightnessPCI 8086, class 03:00
Brightness through ACPI (drivers/backlight.rs)where Intel's PWM is not there or is off: the output device with _BCM and _BCL (the integrated panel's, its _ADR's display type 4, if one says so), set to the least listed level at or above the share asked, read by _BQC. On most Intel laptops _BCM hands the level to a graphics driver through the OpRegion and an interrupt Pinnacle does not answer, so this works only where the firmware sets it itself (through the embedded controller)_BCM, _BCL
ACPI's power (x86_64/acpi.rs)the FADT: ACPI mode on, off by \_S5 (its sleep types read from the DSDT's package, not by running AML), restart by the reset register, the power button's fixed event on the SCI; general-purpose events on only for what answers them (the embedded controller's, the firmware's _Lxx/_Exx methods)the FADT
The firmware's AML (aml/, the crate pinnacle-aml; x86_64/power.rs)the DSDT and every SSDT loaded and run by an interpreter of Pinnacle's own: devices, names, methods, operation regions and their fields (memory, I/O, PCI configuration, the embedded controller, CMOS), _INI, _REG, _STA, _CRS decoded (I/O, memory, interrupts, GPIO, I²C); a loop runs at most a million times, calls nest at most 64 deep, a device whose body fails loses itself onlythe DSDT, SSDTs
The embedded controller (x86_64/power.rs)its two ports and GPE from AML (PNP0C09, _CRS, _GPE), reads and writes for AML's regions, its events (_Qxx) run in a kernel task when its GPE firesPNP0C09
Battery, charger, lid (x86_64/power.rs)_BIX or _BIF, _BST, _PSR, _LID asked live (power system call, 71): level, charging, minutes left, capacities, model; the firmware's notifications and a lid or charger change sent to the display server as input events, which draws the battery in the status bar and locks the screen when the lid closesPNP0C0A, ACPI0003, PNP0C0D
I²C on Intel's LPSS (drivers/i2c_dw.rs)the Synopsys DesignWare I²C controllers of Intel's 8th to 13th generation chipsets: brought to D0, out of LPSS's reset, checked by their component type (DW, 0x44570140); a 7-bit master with repeated starts, at 400 kHz (100 kHz where a device asks less), SCL's timings from the controller's AML (FMCN, SSCN), else from a 120 MHz input clock; transfers polled, with deadlines, an abort (no acknowledgement) ending one with an error. No interrupts, no DMAPCI 8086, class 0c:80:00
Touchpads on I²C (drivers/i2c_hid.rs, PC only; the protocol in hid/, the crate pinnacle-hid, beside USB's report descriptors)HID over I²C (Microsoft's 1.0): each PNP0C50/ACPI0C50 device present by _STA, powered by _PS0, its address and controller from _CRS (I2cSerialBus; the controller the PCI function its _ADR names), its HID descriptor's register from _DSM; SET_POWER ON, RESET and its empty answer, the report descriptor read and its mouse report followed (a precision touchpad's own reports are not asked for). Polled every 8 ms from a kernel task: its interrupt is a GPIO line and there is no GPIO driver yet. Moves the kernel's pointer as the PS/2 touchpad doesPNP0C50, ACPI0C50

Interrupts are message interrupts on a PC (MSI-X, or MSI for AHCI and Ethernet) and INTx on ARM (routed by the device tree); a PC's wired ones (the keyboard controller's, the SCI) come through the I/O APIC (x86_64/ioapic.rs), with the MADT's overrides. Every driver on a shared INTx line is asked when it fires. The local APIC runs in x2APIC mode where the core has it (xapic on the command line keeps the older mode, unless the firmware left x2APIC on); randomness is seeded from the core's RDSEED or RDRAND as well.

Not yet: isochronous USB (audio, cameras), USB 3 streams, NVMe namespaces with metadata, more than one I/O queue, a SATA port multiplier, SD and eMMC (they wait for the first device); GPIO interrupts (Intel's GPIO controllers, INT34xx: an I²C touchpad is read every 8 ms instead of when its line says), a touchpad's precision mode (fingers, gestures, palm rejection: only its mouse report is read), I²C keyboards and touch screens, LPSS controllers firmware hides from PCI (its "ACPI mode"), Intel's Wi-Fi past its firmware's ALIVE (the PNVM handed over, the firmware's configuration commands, scanning, joining, packets: they wait for a laptop that answers); of Intel's graphics all but the backlight: no modesetting (the screen stays in the mode the firmware set, and a panel whose native resolution needs more than the kernel's 16 MiB framebuffer is shown at the loader's smaller mode), no other outputs (HDMI, DisplayPort), no panel driven over DisplayPort's AUX channel (an OLED's brightness, many newer panels'), no power management of the display engine, and no 3D: acceleration on Intel (its command streamers, GuC firmware, a Vulkan driver) is a project of its own; recording through HDA, HDMI and DisplayPort audio, a codec's vendor-specific set-up (some laptops' speakers stay silent without Realtek's coefficients), Intel's audio DSP (class 04:01, the "SOF" mode, which some firmware choose when the laptop has digital microphones), sleeping (S3, S0ix: the lid closed locks the screen, the machine stays on), the battery's own warnings (_BTP), thermal zones and fans (_TZ).

cargo xtask test (its first boot) and cargo xtask pc give QEMU a USB controller with a keyboard, a tablet and a stick, an NVMe disk and a SATA disk: the self-check lists each, and writes a block on each disk, reads it back and puts back what was there (storage ok).

A laptop, without one

cargo xtask laptop runs Pinnacle on the nearest thing to an Intel laptop QEMU makes, with none of QEMU's own (virtio) devices: UEFI's firmware (OVMF) and Pinnacle's loader, the screen a plain VGA's framebuffer, the keyboard and touchpad on the keyboard controller, cores with x2APIC, a USB hub with a blank disk behind it, Intel's 82574L Ethernet, an ICH9's HDA controller with an output codec, an NVMe disk, no isa-debug-exit. As a person meets it: the stick installs itself on the NVMe disk and turns the machine off by ACPI; started from the disk, it plays the self-check's 440 Hz tone through HDA (heard in QEMU's WAV file), and asks for the data's password, typed on the PS/2 keyboard; the touchpad moves the pointer on the home screen; the status bar shows a battery, from an SSDT given to QEMU (-acpitable, written with pinnacle_aml::asm: a battery, a charger, a lid, read through their methods by the same code as a laptop's; QEMU has no embedded controller, so its numbers are the table's own); the power button (QEMU's system_powerdown, ACPI's fixed event) turns it off. A screenshot each step, in target/demo-laptop/.

What that cannot show is what QEMU does not have: an I²C touchpad (QEMU has no DesignWare controller: the boot log says i2c: 0 DesignWare controllers; the protocol is tested against a fake touchpad, cargo test -p pinnacle-hid), Intel's Wi-Fi and graphics (QEMU's VGA is no Intel GPU: the backlight is untried, the boot log says backlight: none to set and Settings shows no brightness slider; the write-combining window is used, but a virtual machine's memory has no bus behind it, so its timings are the CPU's own), an embedded controller, a laptop's own HDA codec (QEMU's has one line out and no speaker, headphone jack or EAPD, so the jack's switching is untried), and every firmware's own mistakes. Those wait for a machine.

Trying a real laptop

  1. In the firmware's setup screens: Secure Boot off (the loader is not signed), and the disks in AHCI mode, not "RAID", "RST" or "VMD" (Intel's VMD hides the NVMe disk behind a controller Pinnacle does not drive).
  2. The stick's image: downloaded from https://pinnacle-os.eu/try/ (tools/deploy/image.sh builds it, midas deploy pinnacle-image publishes it at /store/images/), or cargo xtask installer pc; written whole to a stick (Etcher, Rufus, or dd as above).
  3. Start from it (the firmware's boot menu: F12, F9 or Esc on most).
  4. A laptop has no serial port: the boot log is drawn on the screen from the first line after the screen is found, until the display server starts, and a panic is drawn over whatever is shown then, in red, the machine left on. A photograph of the screen is the report. quiet on the command line (PINNACLE/CMDLINE on the stick) leaves the screen alone.

What a real machine does that QEMU does not, and the kernel allows for: the stick's USB link comes back up to a second after the controller's reset, so the boot waits 1.5 s for the root ports before it looks for the system partition; a panel larger than the kernel's 16 MiB framebuffer (2880×1800, 4K) is set by the loader to the largest mode of its shape that fits, which the panel scales; the counter's rate comes from CPUID, else the PIT, else (the PIT's clock gated off, as on many 8th–10th generation laptops) the core's base frequency; a core that does not start, or an internal disk its driver cannot read, is said on the screen and the system goes on.

What to look for, line by line: framebuffer: (the firmware's screen), display: a whole frame … us write-combining, … us uncached (how much the write-combining window gains on this machine), i915: Intel graphics …, backlight by the chipset's PWM …: N % or why not, then backlight: by ACPI … or backlight: none to set, apic: x2APIC mode (with xapic on the command line as the fallback to try), acpi: a laptop, in ACPI mode; off by \_S5 …; the power button heard, ps2: a keyboard and a mouse or touchpad (absent: the keyboard is not on the controller, or the touchpad is I²C-only), i2c: 2 DesignWare controllers and touchpad: ELAN0001 at 0x15 on \_SB.PC00.I2C1, HID 04f3:3140, polled (or why not: no controller of this kernel's, no _DSM, a step not acknowledged), touchpad: ELAN0001: its first report once a finger moves, usb0: xHCI, each USB device and hub, nvme0:, hda: codec 0: 10ec:0257, speaker on pin 0x14, headphones on 0x21 (out), EAPD on (the codec and its pins; a second codec with only HDMI says no analog output), net: Intel Ethernet, then Intel's Wi-Fi: iwlwifi: Intel AX201 (8086:a0f0) at pci@00:14.3, iwlwifi: MAC Qu step 2 …, radio HR2 step 1 … (what chose the file), iwlwifi: Intel's closed firmware, as data: system:/firmware/intel/iwlwifi-Qu-c0-hr-b0-77.ucode …, and iwlwifi: ALIVE from …: status 0xcafe (running), LMAC …, UMAC … — or iwlwifi: stopped at <step>: … with the registers that say why (ownership: Intel's ME holds the chip; firmware file: a system built without it; ALIVE: the firmware did not start, with its secure boot status and program counters). The last line is where it stopped. Sound at start is the self-check's 440 Hz tone, 300 ms.

Closed firmware

Every driver in Pinnacle is its own Rust. Some chips start only with a program from their maker loaded into them: Intel's Wi-Fi does, and that program is closed (no source, and its licence forbids taking it apart). Pinnacle carries such firmware as data, apart from its own code: it is read from the system disk and handed to the chip, never run on the computer's own cores, and nothing of it is in this repository.

Which file a chip takes follows Linux's naming (iwlwifi-<mac>-<step>-<radio>-<step>-<API>.ucode): the API version is the newest Linux asks for (77 for the 22000 family, 89 for the AX210 family). Chips this set does not cover (a CDB "gf4" radio, Wi-Fi 7's FM, Meteor Lake's Ma at step A) are named in the boot log with why.

Disks and partitions

A disk with a GPT partition table is read as its partitions: Pinnacle's system partition (labelled system) and its data partition (a vault, blank until the first start makes it one) are mounted; nothing else is touched. A virtio disk without a table is one file system, as QEMU's runs have always had it. Any other disk without Pinnacle's partitions is free: listed in Settings → Disks with what it holds (empty, another system's), and what the installer may take. When the loader names the system partition it started from (root=<partition GUID> on the command line), that one is the system, and the data partition beside it the data, whatever else is plugged in.

Installing on a disk

Pinnacle starts from a USB stick and installs itself on a disk of the machine, after which the machine starts from that disk.

cargo xtask installer pc     # target/install-pc.img: a USB stick for a PC (x86-64)
cargo xtask installer        # target/install-arm.img: the same for ARM64 with UEFI
dd if=target/install-pc.img of=/dev/sdX bs=4M conv=fsync   # sdX: the stick, all of it lost

The image holds a partition table, a boot partition (FAT32: Pinnacle's own UEFI loader where a firmware looks for one, EFI/BOOT/BOOTX64.EFI or BOOTAA64.EFI, the kernel as PINNACLE/KERNEL, its command line as PINNACLE/CMDLINE) and the system's partition. Any UEFI firmware starts it as it starts a stick: from its boot menu, or by itself when nothing else boots. On ARM boards U-Boot does too, through its own UEFI.

In Settings → Disks, Install beside a free disk of at least 1 GiB asks first (everything on it is erased), then gives it a partition table with three partitions: boot (300 MiB, the stick's own loader and kernel, and a command line naming the new system partition), system (twice what the running system holds, at least 512 MiB, every file of it copied) and data (the rest, blank: the first start from the disk asks for the password that makes it a vault). Restart, take the stick out, and the machine starts from the disk.

The firmware's own boot entries are not written (that takes UEFI's runtime services, which the kernel does not call): the disk is found through the path every firmware tries on a disk it has no entry for. A firmware that boots only from its entries needs one made in its setup screen, pointing at EFI/BOOT/BOOTX64.EFI on the disk.

cargo xtask install-test [pc] does all of it in QEMU with QEMU's own UEFI firmware (edk2): the stick on USB installs itself on an empty NVMe disk (install-to=nvme0n1 on its command line), the disk is checked from the host, and the machine then starts from the disk alone. cargo xtask install-demo [pc] does it as a person does, in Settings, with only a USB tablet and keyboard, a screenshot each step.

The loader

boot/ is Pinnacle's UEFI loader, written here with no outside code, so a PC needs no GRUB. It reads the kernel and its command line from the partition it was started from, leaves the firmware's boot services and starts the kernel as the kernel expects:

cargo xtask loader [pc] builds it; cargo xtask pc-efi boots a PC's self-check through OVMF and it.