| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- # Board type: Orange Pi Zero (original version, Allwinner H2+), the radio.
- # Sourced by config.sh; everything here can be overridden from the environment.
- BOARD_NAME="Orange Pi Zero (Allwinner H2+)"
- # install-kernel.sh and write-uboot.sh refuse an ssh target whose
- # /proc/device-tree/compatible lacks this.
- BOARD_DT_COMPAT="allwinner,sun8i-h2-plus"
- # ---- versions ---------------------------------------------------------------
- : "${KERNEL_VERSION:=7.3.4}"
- : "${UBOOT_VERSION:=v2026.10}"
- # Out-of-tree XR819 Wi-Fi driver (not in mainline). Pinned commit; see README.
- : "${XRADIO_REPO:=fifteenhex/xradio}"
- : "${XRADIO_COMMIT:=3ce657ae533e2213f6fda2297da1598fa11d7a03}"
- # ---- toolchain --------------------------------------------------------------
- : "${CROSS_COMPILE:=armv7a-hardfloat-linux-gnueabi-}"
- # ---- U-Boot -----------------------------------------------------------------
- UBOOT_DEFCONFIG=orangepi_zero_defconfig
- # sunxi boot ROM loads the SPL from 8 KiB on the card.
- UBOOT_SEEK_KIB=8
- # Where 2019-era sunxi U-Boot (Armbian's 2019.04) kept a raw-MMC environment:
- # CONFIG_ENV_OFFSET=0x88000, 128 KiB. write-uboot.sh mentions it if the new
- # image reaches past it. Empty: no such legacy area.
- UBOOT_OLD_RAW_ENV_KIB=544
- # Where this U-Boot keeps its environment: none (no FAT partition on the card,
- # everything boot related is in extlinux.conf).
- UBOOT_ENV_FAT=0
- # ---- kernel -----------------------------------------------------------------
- KERNEL_IMAGE=zImage
- # Device trees built and staged: our board DTS from files/opi0/dts/ and the
- # plain mainline one (fallback, see README "Other systems").
- BOARD_DTBS="sun8i-h2-plus-orangepi-zero-radio.dtb sun8i-h2-plus-orangepi-zero.dtb"
- # The DTB with the radio key table (checked against radio-keyboard-tca).
- BOARD_DTB="sun8i-h2-plus-orangepi-zero-radio.dtb"
- # ---- installation: extlinux.conf (lib/install-extlinux.sh) -------------------
- INSTALL_SCHEME=extlinux
- # Staging subdirectory: boot/opi0/<release>/ on the target.
- BOOT_SUBDIR=opi0
- BOOT_MENU_TITLE="Orange Pi Zero"
- # Device tree U-Boot hands to the kernel (built from files/opi0/dts/).
- : "${BOOT_DTB:=sun8i-h2-plus-orangepi-zero-radio.dtb}"
- # Extra overlays from boot/opi0/<release>/overlay/, space separated, no .dtbo.
- : "${BOOT_OVERLAYS:=}"
- # Kernel messages go to every console= listed, but only the LAST one becomes
- # /dev/console: init's output, systemd's emergency/rescue shell and the
- # "Give root password" prompt. The serial port goes last so it is a usable
- # emergency console when ssh is not (tty1, fbcon on the radio panel, has no
- # keyboard). install-kernel.sh moves a console=ttyS* entry to the end anyway.
- # The panel driver maps white to "pixel off" (the light background), so fbcon's
- # light-grey-on-black looks inverted there. This VT palette is the VGA one
- # inverted, with entry 0 (background) white and 7/15 (normal/bold text) black.
- # Only text VTs use it; radio-ui draws through DRM and is not affected.
- VT_PALETTE="vt.default_red=0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00"
- VT_PALETTE+=" vt.default_grn=0xff,0xff,0x55,0xaa,0xff,0xff,0x55,0x00,0xaa,0xaa,0x00,0x00,0xaa,0xaa,0x00,0x00"
- VT_PALETTE+=" vt.default_blu=0xff,0xff,0xff,0xff,0x55,0x55,0x55,0x00,0xaa,0xaa,0xaa,0xaa,0x00,0x00,0x00,0x00"
- : "${KERNEL_CONSOLE:=console=tty1 fbcon=font:6x8 $VT_PALETTE console=ttyS0,115200}"
- # usb-storage quirks carried over from the Armbian setup (armbianEnv.txt).
- : "${KERNEL_CMDLINE_EXTRA:=usb-storage.quirks=0x2537:0x1066:u,0x2537:0x1068:u}"
- # ---- radio sources ------------------------------------------------------------
- PANEL_DIR="${PANEL_DIR:-/home/k4be/git/radio/s1d13700-tca}" # s1d13700-tca: panel driver, overlay
- KEYBOARD_DIR="${KEYBOARD_DIR:-/home/k4be/git/radio/radio-keyboard-tca}" # radio-keyboard-tca: key overlay
- # =============================================================================
- # Hooks called by build-kernel.sh (kmake, fetch etc. come from there and
- # config.sh). XSRC is set when the hooks run, after config.sh set SRC.
- # =============================================================================
- board_prepare_source() {
- XSRC="$SRC/xradio"
- if [ ! -d "$XSRC" ]; then
- local xt="$DL/xradio-$XRADIO_COMMIT.tar.gz"
- fetch "$xt" "https://github.com/$XRADIO_REPO/archive/$XRADIO_COMMIT.tar.gz"
- mkdir -p "$XSRC"
- tar xzf "$xt" -C "$XSRC" --strip-components=1
- fi
- sync_radio_driver
- }
- # Put the radio panel driver into the kernel tree as a DRM tiny driver, so it
- # can be built in (needed for the boot console on the panel). The sources are
- # copied from the s1d13700-tca repository ($PANEL_DIR) on every run; only
- # Kconfig/Makefile are ours. The tree is shared with the other board types;
- # for them the driver is just one more option that is off.
- sync_radio_driver() {
- local rd="$PANEL_DIR/driver" td="$KSRC/drivers/gpu/drm/tiny/s1d13700-tca"
- [ -f "$rd/s1d13700_drm.c" ] || die "s1d13700-tca driver not found in $rd"
- mkdir -p "$td"
- # cp -u keeps timestamps sane, so unchanged sources are not rebuilt
- cp -u "$rd"/s1d13700_drm.c "$rd"/s1d13700_core.c "$rd"/s1d13700_core.h "$td/"
- cat > "$td/Kconfig.new" <<-'EOF'
- # Generated by build-kernel.sh (OPi0); sources from the s1d13700-tca repository.
- config DRM_S1D13700_TCA
- tristate "S1D13700 panel behind a TCA9539 I2C expander (radio)"
- depends on DRM && I2C
- select DRM_CLIENT_SELECTION
- select DRM_KMS_HELPER
- select DRM_GEM_SHMEM_HELPER
- select BACKLIGHT_CLASS_DEVICE
- help
- Epson S1D13700 graphic LCD controller driven through a TCA9539
- I2C GPIO expander, as on the radio front panel.
- EOF
- cat > "$td/Makefile.new" <<-'EOF'
- # Generated by build-kernel.sh (OPi0); sources from the s1d13700-tca repository.
- obj-$(CONFIG_DRM_S1D13700_TCA) += s1d13700-tca.o
- s1d13700-tca-y := s1d13700_drm.o s1d13700_core.o
- # API compatibility for the DRM part only (see s1d13700_compat.h).
- CFLAGS_s1d13700_drm.o += -include $(src)/s1d13700_compat.h
- EOF
- # Kernel 7.3 renamed struct drm_atomic_state to struct drm_atomic_commit;
- # the driver uses the old name, only as the type of the atomic hooks'
- # argument. The DRM headers are included before the rename is defined,
- # so it applies to the driver's own code only, never inside a kernel
- # header. s1d13700_compat_check() stops the build if the new struct is
- # not a complete type with the expected members (rename reverted or
- # done differently): adjust the version check then, rather than build
- # against the wrong type. Below 7.3 the header does nothing.
- cat > "$td/s1d13700_compat.h.new" <<-'EOF'
- /* Generated by build-kernel.sh (OPi0). Forced in with -include. */
- #ifndef S1D13700_COMPAT_H
- #define S1D13700_COMPAT_H
- #include <linux/version.h>
- #if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 3, 0) && !defined(drm_atomic_state)
- #include <drm/drm_atomic.h>
- #include <drm/drm_atomic_helper.h>
- #include <drm/drm_crtc.h>
- #include <drm/drm_gem_atomic_helper.h>
- #include <drm/drm_modeset_helper_vtables.h>
- #include <drm/drm_plane.h>
- #define drm_atomic_state drm_atomic_commit
- /* Fails if the headers above still define the old struct. */
- struct drm_atomic_commit;
- static inline void s1d13700_compat_check(struct drm_atomic_commit *c)
- {
- (void)sizeof(c->dev);
- }
- #endif
- #endif /* S1D13700_COMPAT_H */
- EOF
- local f
- for f in Kconfig Makefile s1d13700_compat.h; do
- cmp -s "$td/$f.new" "$td/$f" && rm "$td/$f.new" || mv "$td/$f.new" "$td/$f"
- done
- local tk="$KSRC/drivers/gpu/drm/tiny/Kconfig" tm="$KSRC/drivers/gpu/drm/tiny/Makefile"
- grep -q 's1d13700-tca/Kconfig' "$tk" ||
- printf '\nsource "drivers/gpu/drm/tiny/s1d13700-tca/Kconfig"\n' >> "$tk"
- grep -q 's1d13700-tca/' "$tm" ||
- echo 'obj-$(CONFIG_DRM_S1D13700_TCA) += s1d13700-tca/' >> "$tm"
- }
- # Out-of-tree modules, built after the kernel.
- board_build_extmod() {
- XSRC="$SRC/xradio"
- # xradio: built out of tree in its own (extracted) source directory.
- info "building xradio (XR819 Wi-Fi)"
- kmake M="$XSRC" modules
- }
- board_install_extmod() {
- XSRC="$SRC/xradio"
- kmake INSTALL_MOD_PATH="$STAGE" INSTALL_MOD_STRIP=1 M="$XSRC" modules_install
- }
- # keys_of DTB NODE -> one "label pin flags keycode" line per key, sorted
- keys_of() {
- local n
- for n in $(fdtget -l "$1" "$2"); do
- printf '%s %s %s\n' "$(fdtget -t s "$1" "$2/$n" label)" \
- "$(fdtget -t u "$1" "$2/$n" gpios | cut -d' ' -f2,3)" \
- "$(fdtget -t u "$1" "$2/$n" linux,code)"
- done | sort
- }
- # The key table exists twice: in files/opi0/dts (board DTB) and in
- # radio-keyboard-tca's dts/radio-keys.dts, which deliberately avoids #include
- # so it also works with armbian-add-overlay. Compare the compiled tables
- # instead of sharing a .dtsi: label, U2 pin, flags and key code must all match.
- check_key_tables() {
- local boot="$1" ov="$1/overlay/radio-keys.dtbo"
- [ -f "$ov" ] || return 0
- if ! diff -u <(keys_of "$boot/$BOARD_DTB" /radio-keys) \
- <(keys_of "$ov" /fragment@1/__overlay__/radio-keys) >&2; then
- die "key tables differ: files/opi0/dts/${BOARD_DTB%.dtb}.dts vs $KEYBOARD_DIR/dts/radio-keys.dts (-board +overlay)"
- fi
- info "key tables match (board DTB and radio-keys overlay)"
- }
- # board_package BOOTDIR: extra files for boot/opi0/<release>/
- board_package() {
- local boot="$1" d
- need_tools fdtget
- # Panel and key overlays (dts/*.dts in s1d13700-tca and
- # radio-keyboard-tca), for extlinux fdtoverlays.
- mkdir -p "$boot/overlay"
- for d in "$PANEL_DIR"/dts/*.dts "$KEYBOARD_DIR"/dts/*.dts; do
- [ -e "$d" ] || continue
- dtc -q -@ -I dts -O dtb -o "$boot/overlay/$(basename "${d%.dts}").dtbo" "$d"
- done
- check_key_tables "$boot"
- ls -la "$boot/overlay"
- find "$STAGE/lib/modules" -path '*/updates/*' -name '*.ko*'
- }
|