install-kernel.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # Install the kernel built by build-kernel.sh for the selected board type
  3. # (./select-board.sh) into a card's root filesystem mounted on this PC, or into
  4. # a running board over ssh. How depends on the board type's boot chain
  5. # (INSTALL_SCHEME in boards/<board>.sh):
  6. # extlinux (opi0) /boot/<subdir>/<release>/ + generated extlinux.conf,
  7. # see lib/install-extlinux.sh
  8. # ubootenv (bpi-m2) /boot/<subdir>/<release>/ on the FAT /boot, copied to the
  9. # fixed names the U-Boot environment loads (uImage, DTB),
  10. # see lib/install-ubootenv.sh
  11. # Nothing is ever rebooted.
  12. #
  13. # Usage:
  14. # sudo ./install-kernel.sh /mnt/card-root card's root partition mounted
  15. # (bpi-m2: its FAT partition 1
  16. # mounted on <root>/boot too)
  17. # ./install-kernel.sh ssh:root@radio.lo running board, over ssh
  18. # Installs out/<board>/<board>-kernel-$RELEASE.tar.gz; RELEASE defaults to the
  19. # last build (out/<board>/kernel-release). modules.dep is already in the
  20. # tarball (depmod runs at build time).
  21. set -euo pipefail
  22. . "$(dirname "$0")/config.sh"
  23. [ $# -eq 1 ] || die "usage: $0 /path/to/mounted/root | ssh:user@host"
  24. TARGET="$1"
  25. RELEASE="${RELEASE:-$(cat "$OUT/kernel-release" 2>/dev/null || true)}"
  26. [ -n "$RELEASE" ] || die "no kernel built yet for $BOARD, run ./build-kernel.sh"
  27. TARBALL="$OUT/$BOARD-kernel-$RELEASE.tar.gz"
  28. [ -f "$TARBALL" ] || die "$TARBALL not found"
  29. info "installing $RELEASE ($BOARD_NAME) to $TARGET"
  30. # run CMD on the target root (as shell code; paths relative to its /)
  31. case "$TARGET" in
  32. ssh:*)
  33. HOST="${TARGET#ssh:}"
  34. ROOT=
  35. need_tools ssh
  36. trun() { ssh "$HOST" "cd / && $1"; }
  37. tput_file() { ssh "$HOST" "cat > '/$1.new' && mv '/$1.new' '/$1'"; }
  38. # A kernel for one board type must not land on another.
  39. compat="$(trun 'tr "\0" "\n" < /proc/device-tree/compatible' 2>/dev/null || true)"
  40. grep -qx "$BOARD_DT_COMPAT" <<<"$compat" || [ "${FORCE:-0}" = 1 ] ||
  41. die "$HOST is not a $BOARD_NAME (compatible: $(echo $compat)); select its board type with ./select-board.sh (FORCE=1 overrides)"
  42. info "target: $(trun 'cat /proc/device-tree/model' 2>/dev/null | tr -d '\0'), running $(trun 'uname -r')"
  43. ;;
  44. *)
  45. HOST=
  46. ROOT="$(cd "$TARGET" && pwd -P)"
  47. [ "$ROOT" != / ] || die "refusing to install into this PC's own /"
  48. [ -e "$ROOT/etc/os-release" ] || die "$ROOT does not look like a root filesystem"
  49. [ -d "$ROOT/boot" ] || die "$ROOT has no /boot"
  50. trun() { (cd "$ROOT" && bash -c "$1"); }
  51. tput_file() { cat > "$ROOT/$1.new" && mv "$ROOT/$1.new" "$ROOT/$1"; }
  52. ;;
  53. esac
  54. [ -f "$TOP/lib/install-$INSTALL_SCHEME.sh" ] || die "no install method '$INSTALL_SCHEME'"
  55. . "$TOP/lib/install-$INSTALL_SCHEME.sh"