| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/bin/bash
- # Install the kernel built by build-kernel.sh for the selected board type
- # (./select-board.sh) into a card's root filesystem mounted on this PC, or into
- # a running board over ssh. How depends on the board type's boot chain
- # (INSTALL_SCHEME in boards/<board>.sh):
- # extlinux (opi0) /boot/<subdir>/<release>/ + generated extlinux.conf,
- # see lib/install-extlinux.sh
- # ubootenv (bpi-m2) /boot/<subdir>/<release>/ on the FAT /boot, copied to the
- # fixed names the U-Boot environment loads (uImage, DTB),
- # see lib/install-ubootenv.sh
- # Nothing is ever rebooted.
- #
- # Usage:
- # sudo ./install-kernel.sh /mnt/card-root card's root partition mounted
- # (bpi-m2: its FAT partition 1
- # mounted on <root>/boot too)
- # ./install-kernel.sh ssh:root@radio.lo running board, over ssh
- # Installs out/<board>/<board>-kernel-$RELEASE.tar.gz; RELEASE defaults to the
- # last build (out/<board>/kernel-release). modules.dep is already in the
- # tarball (depmod runs at build time).
- set -euo pipefail
- . "$(dirname "$0")/config.sh"
- [ $# -eq 1 ] || die "usage: $0 /path/to/mounted/root | ssh:user@host"
- TARGET="$1"
- RELEASE="${RELEASE:-$(cat "$OUT/kernel-release" 2>/dev/null || true)}"
- [ -n "$RELEASE" ] || die "no kernel built yet for $BOARD, run ./build-kernel.sh"
- TARBALL="$OUT/$BOARD-kernel-$RELEASE.tar.gz"
- [ -f "$TARBALL" ] || die "$TARBALL not found"
- info "installing $RELEASE ($BOARD_NAME) to $TARGET"
- # run CMD on the target root (as shell code; paths relative to its /)
- case "$TARGET" in
- ssh:*)
- HOST="${TARGET#ssh:}"
- ROOT=
- need_tools ssh
- trun() { ssh "$HOST" "cd / && $1"; }
- tput_file() { ssh "$HOST" "cat > '/$1.new' && mv '/$1.new' '/$1'"; }
- # A kernel for one board type must not land on another.
- compat="$(trun 'tr "\0" "\n" < /proc/device-tree/compatible' 2>/dev/null || true)"
- grep -qx "$BOARD_DT_COMPAT" <<<"$compat" || [ "${FORCE:-0}" = 1 ] ||
- die "$HOST is not a $BOARD_NAME (compatible: $(echo $compat)); select its board type with ./select-board.sh (FORCE=1 overrides)"
- info "target: $(trun 'cat /proc/device-tree/model' 2>/dev/null | tr -d '\0'), running $(trun 'uname -r')"
- ;;
- *)
- HOST=
- ROOT="$(cd "$TARGET" && pwd -P)"
- [ "$ROOT" != / ] || die "refusing to install into this PC's own /"
- [ -e "$ROOT/etc/os-release" ] || die "$ROOT does not look like a root filesystem"
- [ -d "$ROOT/boot" ] || die "$ROOT has no /boot"
- trun() { (cd "$ROOT" && bash -c "$1"); }
- tput_file() { cat > "$ROOT/$1.new" && mv "$ROOT/$1.new" "$ROOT/$1"; }
- ;;
- esac
- [ -f "$TOP/lib/install-$INSTALL_SCHEME.sh" ] || die "no install method '$INSTALL_SCHEME'"
- . "$TOP/lib/install-$INSTALL_SCHEME.sh"
|