unos-repository

APK repository for unos
git clone git://git.finwo.net/misc/unos-repository
Log | Files | Refs | README

commit 3f96f73488a38e9a7e9649d4ca6689a584cb1bcb
Author: finwo <finwo@pm.me>
Date:   Sun, 13 Sep 2026 01:32:12 +0200

Project init

Diffstat:
Apackages/README.md | 48++++++++++++++++++++++++++++++++++++++++++++++++
Apackages/unos-firstboot/files/unos-firstboot | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apackages/unos-firstboot/template | 12++++++++++++
3 files changed, 139 insertions(+), 0 deletions(-)

diff --git a/packages/README.md b/packages/README.md @@ -0,0 +1,48 @@ +# packages/ + +Source package definitions for UNOS, one directory per package. + +Layout follows the Void Linux convention: + +``` +packages/<pkgname>/ +|-- template # shell-sourced build definition (required) +|-- patches/ # optional, applied in sorted order +`-- files/ # optional, static files referenced by the template +``` + +A `template` is a shell fragment, not a script: it declares variables and +optionally overrides `do_*` phases: + +```sh +pkgname=example +version=1.0.0 +revision=1 +build_style=gnu-configure +hostmakedepends="pkg-config" +makedepends="libfoo-devel" +short_desc="One-line description" +maintainer="..." +license="BSD-3-Clause" +homepage="https://example.org" +distfiles="https://example.org/example-${version}.tar.gz" +checksum=<sha256> +``` + +Templates are built by CI into a signed xbps repository. Nothing in this +directory is ever built by hand on a target switch. + +## Rules + +- **Pin everything.** Explicit versions and recorded checksums. No moving + targets, no floating branches. +- **Never vendor upstream source into this repository.** Sources are fetched at + build time from a pinned revision. This keeps history small and keeps our + licensing story unambiguous. +- **Preserve vendor notices.** Templates that patch third-party code must not + strip copyright headers. This is a binding condition of the Broadcom SDK + licence, and stripping headers is the single easiest way to breach it. +- **Kernel-coupled packages must rebuild with the kernel.** Anything producing + a `.ko` has to be rebuilt whenever the `linux` package changes; a stale module + fails at `insmod` time on the switch, which is the worst possible place to + find out. diff --git a/packages/unos-firstboot/files/unos-firstboot b/packages/unos-firstboot/files/unos-firstboot @@ -0,0 +1,79 @@ +#!/bin/sh +# +# unos-firstboot -- one-time platform provisioning +# +# A UNOS image is identical on every machine. Hardware support is added +# afterwards, by package. This runs once on first boot, works out what the +# machine actually is, and pulls in whatever it needs. +# +# Invoked from runit stage 1. Safe to re-run: it is a no-op once the marker +# exists, and `--force` re-runs the detection. + +set -e + +STATEDIR=/var/lib/unos +MARKER="${STATEDIR}/.provisioned" +FORCE=0 + +log() { echo "unos-firstboot: $*"; } + +while [ $# -gt 0 ]; do + case "$1" in + --force) FORCE=1 ;; + *) log "unknown argument: $1"; exit 1 ;; + esac + shift +done + +if [ -e "${MARKER}" ] && [ "${FORCE}" -eq 0 ]; then + exit 0 +fi + +# Broadcom XGS switch ASICs sit on PCIe under vendor 0x14e4 with device IDs in +# the 0xb??? range (BCM56xxx / BCM78xxx). Broadcom NICs share the vendor ID but +# use different device ranges, so the device prefix is what distinguishes them. +# +# Read straight out of sysfs rather than shelling out to lspci, which busybox +# does not provide. +# +# NOTE: verify the device ID range against real hardware before trusting this +# on a platform we have not seen. +detect_bcm_switch() { + for dev in /sys/bus/pci/devices/*; do + [ -r "${dev}/vendor" ] || continue + [ -r "${dev}/device" ] || continue + + read -r vendor < "${dev}/vendor" + [ "${vendor}" = "0x14e4" ] || continue + + read -r device < "${dev}/device" + case "${device}" in + 0xb*) + log "found Broadcom switch ASIC at $(basename "${dev}") (${vendor}:${device})" + return 0 + ;; + esac + done + return 1 +} + +install_pkg() { + log "installing $1" + if ! xbps-install -y "$1"; then + log "failed to install $1" + return 1 + fi +} + +mkdir -p "${STATEDIR}" + +if detect_bcm_switch; then + log "platform: broadcom xgs switch" + install_pkg openbcm || exit 1 +else + log "platform: generic, no switching ASIC detected" + log "unosd will use the built-in kernel dataplane" +fi + +date -u +%Y-%m-%dT%H:%M:%SZ > "${MARKER}" +log "provisioning complete" diff --git a/packages/unos-firstboot/template b/packages/unos-firstboot/template @@ -0,0 +1,12 @@ +# Template file for 'unos-firstboot' +pkgname=unos-firstboot +version=0.1.0 +revision=1 +short_desc="One-time platform provisioning for UNOS" +maintainer="finwo <finwo@pm.me>" +license="GPL-2.0-only" +homepage="https://unos.finwo.dev" + +do_install() { + vinstall ${FILESDIR}/unos-firstboot 755 usr/libexec/unos firstboot +}