opi0.sh 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # Board type: Orange Pi Zero (original version, Allwinner H2+), the radio.
  2. # Sourced by config.sh; everything here can be overridden from the environment.
  3. BOARD_NAME="Orange Pi Zero (Allwinner H2+)"
  4. # install-kernel.sh and write-uboot.sh refuse an ssh target whose
  5. # /proc/device-tree/compatible lacks this.
  6. BOARD_DT_COMPAT="allwinner,sun8i-h2-plus"
  7. # ---- versions ---------------------------------------------------------------
  8. : "${KERNEL_VERSION:=7.3.4}"
  9. : "${UBOOT_VERSION:=v2026.10}"
  10. # Out-of-tree XR819 Wi-Fi driver (not in mainline). Pinned commit; see README.
  11. : "${XRADIO_REPO:=fifteenhex/xradio}"
  12. : "${XRADIO_COMMIT:=3ce657ae533e2213f6fda2297da1598fa11d7a03}"
  13. # ---- toolchain --------------------------------------------------------------
  14. : "${CROSS_COMPILE:=armv7a-hardfloat-linux-gnueabi-}"
  15. # ---- U-Boot -----------------------------------------------------------------
  16. UBOOT_DEFCONFIG=orangepi_zero_defconfig
  17. # sunxi boot ROM loads the SPL from 8 KiB on the card.
  18. UBOOT_SEEK_KIB=8
  19. # Where 2019-era sunxi U-Boot (Armbian's 2019.04) kept a raw-MMC environment:
  20. # CONFIG_ENV_OFFSET=0x88000, 128 KiB. write-uboot.sh mentions it if the new
  21. # image reaches past it. Empty: no such legacy area.
  22. UBOOT_OLD_RAW_ENV_KIB=544
  23. # Where this U-Boot keeps its environment: none (no FAT partition on the card,
  24. # everything boot related is in extlinux.conf).
  25. UBOOT_ENV_FAT=0
  26. # ---- kernel -----------------------------------------------------------------
  27. KERNEL_IMAGE=zImage
  28. # Device trees built and staged: our board DTS from files/opi0/dts/ and the
  29. # plain mainline one (fallback, see README "Other systems").
  30. BOARD_DTBS="sun8i-h2-plus-orangepi-zero-radio.dtb sun8i-h2-plus-orangepi-zero.dtb"
  31. # The DTB with the radio key table (checked against radio-keyboard-tca).
  32. BOARD_DTB="sun8i-h2-plus-orangepi-zero-radio.dtb"
  33. # ---- installation: extlinux.conf (lib/install-extlinux.sh) -------------------
  34. INSTALL_SCHEME=extlinux
  35. # Staging subdirectory: boot/opi0/<release>/ on the target.
  36. BOOT_SUBDIR=opi0
  37. BOOT_MENU_TITLE="Orange Pi Zero"
  38. # Device tree U-Boot hands to the kernel (built from files/opi0/dts/).
  39. : "${BOOT_DTB:=sun8i-h2-plus-orangepi-zero-radio.dtb}"
  40. # Extra overlays from boot/opi0/<release>/overlay/, space separated, no .dtbo.
  41. : "${BOOT_OVERLAYS:=}"
  42. # Kernel messages go to every console= listed, but only the LAST one becomes
  43. # /dev/console: init's output, systemd's emergency/rescue shell and the
  44. # "Give root password" prompt. The serial port goes last so it is a usable
  45. # emergency console when ssh is not (tty1, fbcon on the radio panel, has no
  46. # keyboard). install-kernel.sh moves a console=ttyS* entry to the end anyway.
  47. # The panel driver maps white to "pixel off" (the light background), so fbcon's
  48. # light-grey-on-black looks inverted there. This VT palette is the VGA one
  49. # inverted, with entry 0 (background) white and 7/15 (normal/bold text) black.
  50. # Only text VTs use it; radio-ui draws through DRM and is not affected.
  51. VT_PALETTE="vt.default_red=0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00"
  52. VT_PALETTE+=" vt.default_grn=0xff,0xff,0x55,0xaa,0xff,0xff,0x55,0x00,0xaa,0xaa,0x00,0x00,0xaa,0xaa,0x00,0x00"
  53. VT_PALETTE+=" vt.default_blu=0xff,0xff,0xff,0xff,0x55,0x55,0x55,0x00,0xaa,0xaa,0xaa,0xaa,0x00,0x00,0x00,0x00"
  54. : "${KERNEL_CONSOLE:=console=tty1 fbcon=font:6x8 $VT_PALETTE console=ttyS0,115200}"
  55. # usb-storage quirks carried over from the Armbian setup (armbianEnv.txt).
  56. : "${KERNEL_CMDLINE_EXTRA:=usb-storage.quirks=0x2537:0x1066:u,0x2537:0x1068:u}"
  57. # ---- radio sources ------------------------------------------------------------
  58. PANEL_DIR="${PANEL_DIR:-/home/k4be/git/radio/s1d13700-tca}" # s1d13700-tca: panel driver, overlay
  59. KEYBOARD_DIR="${KEYBOARD_DIR:-/home/k4be/git/radio/radio-keyboard-tca}" # radio-keyboard-tca: key overlay
  60. # =============================================================================
  61. # Hooks called by build-kernel.sh (kmake, fetch etc. come from there and
  62. # config.sh). XSRC is set when the hooks run, after config.sh set SRC.
  63. # =============================================================================
  64. board_prepare_source() {
  65. XSRC="$SRC/xradio"
  66. if [ ! -d "$XSRC" ]; then
  67. local xt="$DL/xradio-$XRADIO_COMMIT.tar.gz"
  68. fetch "$xt" "https://github.com/$XRADIO_REPO/archive/$XRADIO_COMMIT.tar.gz"
  69. mkdir -p "$XSRC"
  70. tar xzf "$xt" -C "$XSRC" --strip-components=1
  71. fi
  72. sync_radio_driver
  73. }
  74. # Put the radio panel driver into the kernel tree as a DRM tiny driver, so it
  75. # can be built in (needed for the boot console on the panel). The sources are
  76. # copied from the s1d13700-tca repository ($PANEL_DIR) on every run; only
  77. # Kconfig/Makefile are ours. The tree is shared with the other board types;
  78. # for them the driver is just one more option that is off.
  79. sync_radio_driver() {
  80. local rd="$PANEL_DIR/driver" td="$KSRC/drivers/gpu/drm/tiny/s1d13700-tca"
  81. [ -f "$rd/s1d13700_drm.c" ] || die "s1d13700-tca driver not found in $rd"
  82. mkdir -p "$td"
  83. # cp -u keeps timestamps sane, so unchanged sources are not rebuilt
  84. cp -u "$rd"/s1d13700_drm.c "$rd"/s1d13700_core.c "$rd"/s1d13700_core.h "$td/"
  85. cat > "$td/Kconfig.new" <<-'EOF'
  86. # Generated by build-kernel.sh (OPi0); sources from the s1d13700-tca repository.
  87. config DRM_S1D13700_TCA
  88. tristate "S1D13700 panel behind a TCA9539 I2C expander (radio)"
  89. depends on DRM && I2C
  90. select DRM_CLIENT_SELECTION
  91. select DRM_KMS_HELPER
  92. select DRM_GEM_SHMEM_HELPER
  93. select BACKLIGHT_CLASS_DEVICE
  94. help
  95. Epson S1D13700 graphic LCD controller driven through a TCA9539
  96. I2C GPIO expander, as on the radio front panel.
  97. EOF
  98. cat > "$td/Makefile.new" <<-'EOF'
  99. # Generated by build-kernel.sh (OPi0); sources from the s1d13700-tca repository.
  100. obj-$(CONFIG_DRM_S1D13700_TCA) += s1d13700-tca.o
  101. s1d13700-tca-y := s1d13700_drm.o s1d13700_core.o
  102. # API compatibility for the DRM part only (see s1d13700_compat.h).
  103. CFLAGS_s1d13700_drm.o += -include $(src)/s1d13700_compat.h
  104. EOF
  105. # Kernel 7.3 renamed struct drm_atomic_state to struct drm_atomic_commit;
  106. # the driver uses the old name, only as the type of the atomic hooks'
  107. # argument. The DRM headers are included before the rename is defined,
  108. # so it applies to the driver's own code only, never inside a kernel
  109. # header. s1d13700_compat_check() stops the build if the new struct is
  110. # not a complete type with the expected members (rename reverted or
  111. # done differently): adjust the version check then, rather than build
  112. # against the wrong type. Below 7.3 the header does nothing.
  113. cat > "$td/s1d13700_compat.h.new" <<-'EOF'
  114. /* Generated by build-kernel.sh (OPi0). Forced in with -include. */
  115. #ifndef S1D13700_COMPAT_H
  116. #define S1D13700_COMPAT_H
  117. #include <linux/version.h>
  118. #if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 3, 0) && !defined(drm_atomic_state)
  119. #include <drm/drm_atomic.h>
  120. #include <drm/drm_atomic_helper.h>
  121. #include <drm/drm_crtc.h>
  122. #include <drm/drm_gem_atomic_helper.h>
  123. #include <drm/drm_modeset_helper_vtables.h>
  124. #include <drm/drm_plane.h>
  125. #define drm_atomic_state drm_atomic_commit
  126. /* Fails if the headers above still define the old struct. */
  127. struct drm_atomic_commit;
  128. static inline void s1d13700_compat_check(struct drm_atomic_commit *c)
  129. {
  130. (void)sizeof(c->dev);
  131. }
  132. #endif
  133. #endif /* S1D13700_COMPAT_H */
  134. EOF
  135. local f
  136. for f in Kconfig Makefile s1d13700_compat.h; do
  137. cmp -s "$td/$f.new" "$td/$f" && rm "$td/$f.new" || mv "$td/$f.new" "$td/$f"
  138. done
  139. local tk="$KSRC/drivers/gpu/drm/tiny/Kconfig" tm="$KSRC/drivers/gpu/drm/tiny/Makefile"
  140. grep -q 's1d13700-tca/Kconfig' "$tk" ||
  141. printf '\nsource "drivers/gpu/drm/tiny/s1d13700-tca/Kconfig"\n' >> "$tk"
  142. grep -q 's1d13700-tca/' "$tm" ||
  143. echo 'obj-$(CONFIG_DRM_S1D13700_TCA) += s1d13700-tca/' >> "$tm"
  144. }
  145. # Out-of-tree modules, built after the kernel.
  146. board_build_extmod() {
  147. XSRC="$SRC/xradio"
  148. # xradio: built out of tree in its own (extracted) source directory.
  149. info "building xradio (XR819 Wi-Fi)"
  150. kmake M="$XSRC" modules
  151. }
  152. board_install_extmod() {
  153. XSRC="$SRC/xradio"
  154. kmake INSTALL_MOD_PATH="$STAGE" INSTALL_MOD_STRIP=1 M="$XSRC" modules_install
  155. }
  156. # keys_of DTB NODE -> one "label pin flags keycode" line per key, sorted
  157. keys_of() {
  158. local n
  159. for n in $(fdtget -l "$1" "$2"); do
  160. printf '%s %s %s\n' "$(fdtget -t s "$1" "$2/$n" label)" \
  161. "$(fdtget -t u "$1" "$2/$n" gpios | cut -d' ' -f2,3)" \
  162. "$(fdtget -t u "$1" "$2/$n" linux,code)"
  163. done | sort
  164. }
  165. # The key table exists twice: in files/opi0/dts (board DTB) and in
  166. # radio-keyboard-tca's dts/radio-keys.dts, which deliberately avoids #include
  167. # so it also works with armbian-add-overlay. Compare the compiled tables
  168. # instead of sharing a .dtsi: label, U2 pin, flags and key code must all match.
  169. check_key_tables() {
  170. local boot="$1" ov="$1/overlay/radio-keys.dtbo"
  171. [ -f "$ov" ] || return 0
  172. if ! diff -u <(keys_of "$boot/$BOARD_DTB" /radio-keys) \
  173. <(keys_of "$ov" /fragment@1/__overlay__/radio-keys) >&2; then
  174. die "key tables differ: files/opi0/dts/${BOARD_DTB%.dtb}.dts vs $KEYBOARD_DIR/dts/radio-keys.dts (-board +overlay)"
  175. fi
  176. info "key tables match (board DTB and radio-keys overlay)"
  177. }
  178. # board_package BOOTDIR: extra files for boot/opi0/<release>/
  179. board_package() {
  180. local boot="$1" d
  181. need_tools fdtget
  182. # Panel and key overlays (dts/*.dts in s1d13700-tca and
  183. # radio-keyboard-tca), for extlinux fdtoverlays.
  184. mkdir -p "$boot/overlay"
  185. for d in "$PANEL_DIR"/dts/*.dts "$KEYBOARD_DIR"/dts/*.dts; do
  186. [ -e "$d" ] || continue
  187. dtc -q -@ -I dts -O dtb -o "$boot/overlay/$(basename "${d%.dts}").dtbo" "$d"
  188. done
  189. check_key_tables "$boot"
  190. ls -la "$boot/overlay"
  191. find "$STAGE/lib/modules" -path '*/updates/*' -name '*.ko*'
  192. }