2017-05-22 12:20:29 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-04-27 08:58:47 +02:00
|
|
|
FORCE_KERNEL="1.20200819-1"
|
2020-09-27 05:25:35 +02:00
|
|
|
|
2017-05-22 12:20:29 +02:00
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
echo "This script must be run as root (use sudo)" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-08-09 17:57:20 +02:00
|
|
|
# Check if enough space on /boot volume
|
2020-09-27 09:09:25 +02:00
|
|
|
boot_line=$(df -BM | grep /boot | head -n 1)
|
|
|
|
MIN_BOOT_SPC=25 # MegaBytes
|
2020-02-14 14:37:02 +01:00
|
|
|
if [ "x${boot_line}" = "x" ]; then
|
|
|
|
echo "Warning: /boot volume not found .."
|
|
|
|
else
|
|
|
|
boot_space=$(echo $boot_line | awk '{print $4;}')
|
|
|
|
free_space=$(echo "${boot_space%?}")
|
|
|
|
unit="${boot_space: -1}"
|
2020-09-27 09:09:25 +02:00
|
|
|
if [[ "$unit" != "M" ]]; then
|
|
|
|
echo "Warning: /boot volume not found .."
|
|
|
|
elif [ "$free_space" -lt "$MIN_BOOT_SPC" ]; then
|
2020-02-14 14:37:02 +01:00
|
|
|
echo "Error: Not enough space left ($boot_space) on /boot"
|
2020-09-27 09:09:25 +02:00
|
|
|
echo " at least $MIN_BOOT_SPC MB required"
|
2020-02-14 14:37:02 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-03-26 04:52:07 +01:00
|
|
|
#
|
|
|
|
# make sure that we are on something ARM/Raspberry related
|
|
|
|
# either a bare metal Raspberry or a qemu session with
|
|
|
|
# Raspberry stuff available
|
|
|
|
# - check for /boot/overlays
|
|
|
|
# - dtparam and dtoverlay is available
|
|
|
|
errorFound=0
|
2020-08-23 19:12:49 +02:00
|
|
|
OVERLAYS=/boot/overlays
|
|
|
|
[ -d /boot/firmware/overlays ] && OVERLAYS=/boot/firmware/overlays
|
|
|
|
|
|
|
|
if [ ! -d $OVERLAYS ] ; then
|
|
|
|
echo "$OVERLAYS not found or not a directory" 1>&2
|
2019-03-26 04:52:07 +01:00
|
|
|
errorFound=1
|
|
|
|
fi
|
|
|
|
# should we also check for alsactl and amixer used in seeed-voicecard?
|
2020-08-23 21:17:17 +02:00
|
|
|
PATH=$PATH:/opt/vc/bin
|
2019-03-26 04:52:07 +01:00
|
|
|
for cmd in dtparam dtoverlay ; do
|
|
|
|
if ! which $cmd &>/dev/null ; then
|
|
|
|
echo "$cmd not found" 1>&2
|
2020-08-23 20:17:30 +02:00
|
|
|
echo "You may need to run ./ubuntu-prerequisite.sh"
|
2019-03-26 04:52:07 +01:00
|
|
|
errorFound=1
|
|
|
|
fi
|
|
|
|
done
|
2020-09-27 12:00:37 +02:00
|
|
|
|
|
|
|
if [ ! -x seeed-voicecard -o ! -f seeed-voicecard.service ]; then
|
|
|
|
echo "Please run this script in the project directory"
|
|
|
|
echo "which has files such as install.sh and seeed-voicecard.service"
|
|
|
|
errorFound=1
|
|
|
|
fi
|
|
|
|
|
2019-03-26 04:52:07 +01:00
|
|
|
if [ $errorFound = 1 ] ; then
|
|
|
|
echo "Errors found, exiting." 1>&2
|
2017-09-14 12:39:38 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-02-01 08:58:36 +01:00
|
|
|
ver="0.3"
|
2019-03-14 04:13:25 +01:00
|
|
|
uname_r=$(uname -r)
|
2020-09-27 10:12:35 +02:00
|
|
|
arch_r=$(dpkg --print-architecture)
|
2017-05-22 12:20:29 +02:00
|
|
|
|
|
|
|
# we create a dir with this version to ensure that 'dkms remove' won't delete
|
|
|
|
# the sources during kernel updates
|
|
|
|
marker="0.0.0"
|
|
|
|
|
2019-04-15 11:49:51 +02:00
|
|
|
_VER_RUN=
|
|
|
|
function get_kernel_version() {
|
|
|
|
local ZIMAGE IMG_OFFSET
|
|
|
|
|
2019-05-21 06:18:25 +02:00
|
|
|
_VER_RUN=""
|
2019-04-15 11:49:51 +02:00
|
|
|
[ -z "$_VER_RUN" ] && {
|
|
|
|
ZIMAGE=/boot/kernel.img
|
2020-08-24 13:03:46 +02:00
|
|
|
[ -f /boot/firmware/vmlinuz ] && ZIMAGE=/boot/firmware/vmlinuz
|
2019-04-15 11:49:51 +02:00
|
|
|
IMG_OFFSET=$(LC_ALL=C grep -abo $'\x1f\x8b\x08\x00' $ZIMAGE | head -n 1 | cut -d ':' -f 1)
|
2020-09-27 10:13:55 +02:00
|
|
|
_VER_RUN=$(dd if=$ZIMAGE obs=64K ibs=4 skip=$(( IMG_OFFSET / 4)) 2>/dev/null | zcat | grep -a -m1 "Linux version" | strings | awk '{ print $3; }')
|
2019-04-15 11:49:51 +02:00
|
|
|
}
|
|
|
|
echo "$_VER_RUN"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_kernel_headers() {
|
|
|
|
VER_RUN=$(get_kernel_version)
|
|
|
|
VER_HDR=$(dpkg -L raspberrypi-kernel-headers | egrep -m1 "/lib/modules/[^-]+/build" | awk -F'/' '{ print $4; }')
|
2020-09-04 08:26:13 +02:00
|
|
|
[ "X$VER_RUN" == "X$VER_HDR" ] && {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
VER_HDR=$(dpkg -L linux-headers-$VER_RUN | egrep -m1 "/lib/modules/[[:print:]]+/build" | awk -F'/' '{ print $4; }')
|
2019-04-15 11:49:51 +02:00
|
|
|
[ "X$VER_RUN" == "X$VER_HDR" ] && {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# echo RUN=$VER_RUN HDR=$VER_HDR
|
|
|
|
echo " !!! Your kernel version is $VER_RUN"
|
2020-08-09 17:57:20 +02:00
|
|
|
echo " Couldn't find *** corresponding *** kernel headers with apt-get."
|
|
|
|
echo " This may happen if you ran 'rpi-update'."
|
|
|
|
echo " Choose *** y *** to revert the kernel to version $VER_HDR and continue."
|
|
|
|
echo " Choose *** N *** to exit without this driver support, by default."
|
2019-04-15 11:49:51 +02:00
|
|
|
read -p "Would you like to proceed? (y/N)" -n 1 -r -s
|
|
|
|
echo
|
|
|
|
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
apt-get -y --reinstall install raspberrypi-kernel
|
|
|
|
}
|
|
|
|
|
2020-09-27 05:25:35 +02:00
|
|
|
function download_install_debpkg() {
|
2020-09-27 10:14:54 +02:00
|
|
|
local prefix name r pkg status _name
|
2020-09-27 05:25:35 +02:00
|
|
|
prefix=$1
|
|
|
|
name=$2
|
2020-09-27 10:14:54 +02:00
|
|
|
pkg=${name%%_*}
|
|
|
|
|
|
|
|
status=$(dpkg -l $pkg | tail -1)
|
|
|
|
_name=$( echo "$status" | awk '{ printf "%s_%s_%s", $2, $3, $4; }')
|
|
|
|
status=$(echo "$status" | awk '{ printf "%s", $1; }')
|
|
|
|
|
|
|
|
if [ "X$status" == "Xii" -a "X${name%.deb}" == "X$_name" ]; then
|
|
|
|
echo "debian package $name already installed."
|
|
|
|
return 0
|
|
|
|
fi
|
2020-09-27 05:25:35 +02:00
|
|
|
|
|
|
|
for (( i = 0; i < 3; i++ )); do
|
|
|
|
wget $prefix$name -O /tmp/$name && break
|
|
|
|
done
|
|
|
|
dpkg -i /tmp/$name; r=$?
|
|
|
|
rm -f /tmp/$name
|
|
|
|
return $r
|
|
|
|
}
|
|
|
|
|
2020-09-27 12:01:51 +02:00
|
|
|
function usage() {
|
|
|
|
cat <<-__EOF__
|
|
|
|
usage: sudo ./install [ --compat-kernel | --keep-kernel ] [ -h | --help ]
|
|
|
|
default action is update kernel & headers to latest version.
|
|
|
|
--compat-kernel uses an older kernel but ensures that the driver can work.
|
|
|
|
--keep-kernel don't change/update the system kernel, maybe install
|
|
|
|
coressponding kernel headers.
|
|
|
|
--help show this help message
|
|
|
|
__EOF__
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
compat_kernel=
|
|
|
|
keep_kernel=
|
|
|
|
# parse commandline options
|
|
|
|
while [ ! -z "$1" ] ; do
|
|
|
|
case $1 in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
--compat-kernel)
|
|
|
|
compat_kernel=Y
|
|
|
|
;;
|
|
|
|
--keep-kernel)
|
|
|
|
keep_kernel=Y
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "X$keep_kernel" != "X" ]; then
|
|
|
|
FORCE_KERNEL=$(dpkg -s raspberrypi-kernel | awk '/^Version:/{printf "%s\n",$2;}')
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### Keep current system kernel not to change"
|
2020-09-27 12:01:51 +02:00
|
|
|
elif [ "X$compat_kernel" != "X" ]; then
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### will compile with a compatible kernel..."
|
2020-04-27 08:58:47 +02:00
|
|
|
else
|
|
|
|
FORCE_KERNEL=""
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### will compile with the latest kernel..."
|
2020-04-27 08:58:47 +02:00
|
|
|
fi
|
2020-09-27 12:01:51 +02:00
|
|
|
[ "X$FORCE_KERNEL" != "X" ] && {
|
|
|
|
echo -e "The kernel & headers use package version: $FORCE_KERNEL\r\n\r\n"
|
|
|
|
}
|
2020-04-27 08:58:47 +02:00
|
|
|
|
2020-09-27 05:25:35 +02:00
|
|
|
function install_kernel() {
|
|
|
|
local _url _prefix
|
|
|
|
|
2020-08-09 17:57:20 +02:00
|
|
|
# Instead of retrieving the lastest kernel & headers
|
2020-09-27 05:25:35 +02:00
|
|
|
[ "X$FORCE_KERNEL" == "X" ] && {
|
|
|
|
# Raspbian kernel packages
|
2020-09-27 12:03:03 +02:00
|
|
|
apt-get -y --force-yes install raspberrypi-kernel-headers raspberrypi-kernel || {
|
|
|
|
# Ubuntu kernel packages
|
|
|
|
apt-get -y install linux-raspi linux-headers-raspi linux-image-raspi
|
|
|
|
}
|
2020-09-27 05:25:35 +02:00
|
|
|
} || {
|
|
|
|
# We would like to a fixed version
|
2020-09-27 10:12:35 +02:00
|
|
|
KERN_NAME=raspberrypi-kernel_${FORCE_KERNEL}_${arch_r}.deb
|
|
|
|
HDR_NAME=raspberrypi-kernel-headers_${FORCE_KERNEL}_${arch_r}.deb
|
2020-09-27 05:25:35 +02:00
|
|
|
_url=$(apt-get download --print-uris raspberrypi-kernel | sed -nre "s/'([^']+)'.*$/\1/g;p")
|
|
|
|
_prefix=$(echo $_url | sed -nre 's/^(.*)raspberrypi-kernel_.*$/\1/g;p')
|
|
|
|
|
2020-09-29 05:07:29 +02:00
|
|
|
download_install_debpkg "$_prefix" "$KERN_NAME" && {
|
|
|
|
download_install_debpkg "$_prefix" "$HDR_NAME"
|
|
|
|
} || {
|
|
|
|
echo "Error: Install kernel or header failed"
|
|
|
|
exit 2
|
|
|
|
}
|
2020-09-27 05:25:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 04:39:23 +02:00
|
|
|
function uninstall_module {
|
|
|
|
src=$1
|
|
|
|
mod=$2
|
|
|
|
|
|
|
|
if [[ -d /var/lib/dkms/$mod/$ver/$marker ]]; then
|
|
|
|
rmdir /var/lib/dkms/$mod/$ver/$marker
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -e /usr/src/$mod-$ver || -e /var/lib/dkms/$mod/$ver ]]; then
|
|
|
|
dkms remove --force -m $mod -v $ver --all
|
|
|
|
rm -rf /usr/src/$mod-$ver
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-01-26 15:19:45 +01:00
|
|
|
# update and install required packages
|
2020-09-30 04:39:23 +02:00
|
|
|
which apt &>/dev/null; r=$?
|
|
|
|
if [[ $r -eq 0 ]]; then
|
|
|
|
echo -e "\n### Install required tool packages"
|
2019-01-26 15:19:45 +01:00
|
|
|
apt update -y
|
|
|
|
apt-get -y install dkms git i2c-tools libasound2-plugins
|
2020-09-30 04:39:23 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo -e "\n### Uninstall previous dkms module"
|
|
|
|
uninstall_module "./" "seeed-voicecard"
|
|
|
|
|
|
|
|
if [[ $r -eq 0 ]]; then
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### Install required kernel package"
|
2020-09-27 05:25:35 +02:00
|
|
|
install_kernel
|
2019-04-15 11:49:51 +02:00
|
|
|
# rpi-update checker
|
|
|
|
check_kernel_headers
|
2019-01-26 15:19:45 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Arch Linux
|
|
|
|
which pacman &>/dev/null
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
pacman -Syu --needed git gcc automake make dkms linux-raspberrypi-headers i2c-tools
|
|
|
|
fi
|
2017-05-22 12:20:29 +02:00
|
|
|
|
|
|
|
# locate currently installed kernels (may be different to running kernel if
|
|
|
|
# it's just been updated)
|
2019-04-15 11:49:51 +02:00
|
|
|
base_ver=$(get_kernel_version)
|
|
|
|
base_ver=${base_ver%%[-+]*}
|
2020-09-27 10:15:41 +02:00
|
|
|
# kernels="${base_ver}+ ${base_ver}-v7+ ${base_ver}-v7l+"
|
|
|
|
# select exact kernel postfix
|
|
|
|
kernels=${base_ver}$(echo $uname_r | sed -re 's/^[0-9.]+(.*)/\1/g')
|
2017-05-22 12:20:29 +02:00
|
|
|
|
|
|
|
function install_module {
|
2019-04-15 11:49:51 +02:00
|
|
|
local _i
|
|
|
|
|
2017-05-22 12:20:29 +02:00
|
|
|
src=$1
|
|
|
|
mod=$2
|
|
|
|
|
|
|
|
mkdir -p /usr/src/$mod-$ver
|
|
|
|
cp -a $src/* /usr/src/$mod-$ver/
|
2019-04-15 11:49:51 +02:00
|
|
|
|
2017-05-22 12:20:29 +02:00
|
|
|
dkms add -m $mod -v $ver
|
2019-04-15 11:49:51 +02:00
|
|
|
for _i in $kernels; do
|
|
|
|
dkms build -k $_i -m $mod -v $ver && {
|
|
|
|
dkms install --force -k $_i -m $mod -v $ver
|
2020-04-27 08:58:47 +02:00
|
|
|
} || {
|
|
|
|
echo "Can't compile with this kernel, aborting"
|
|
|
|
echo "Please try to compile with the option --compat-kernel"
|
|
|
|
exit 1
|
2019-04-15 11:49:51 +02:00
|
|
|
}
|
|
|
|
done
|
2017-05-22 12:20:29 +02:00
|
|
|
|
|
|
|
mkdir -p /var/lib/dkms/$mod/$ver/$marker
|
|
|
|
}
|
|
|
|
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### Install sound card driver"
|
2018-02-01 08:58:36 +01:00
|
|
|
install_module "./" "seeed-voicecard"
|
|
|
|
|
|
|
|
# install dtbos
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### Install device tree overlays"
|
|
|
|
cp -v seeed-2mic-voicecard.dtbo $OVERLAYS
|
|
|
|
cp -v seeed-4mic-voicecard.dtbo $OVERLAYS
|
|
|
|
cp -v seeed-8mic-voicecard.dtbo $OVERLAYS
|
2018-02-01 08:58:36 +01:00
|
|
|
|
2020-08-09 17:57:20 +02:00
|
|
|
# install alsa plugins
|
|
|
|
# we don't need this plugin now
|
2019-03-14 04:13:25 +01:00
|
|
|
# install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/
|
2018-05-11 08:22:37 +02:00
|
|
|
rm -f /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so
|
2018-02-01 08:58:36 +01:00
|
|
|
|
2020-01-28 15:53:28 +01:00
|
|
|
#set kernel modules
|
2020-09-29 05:07:29 +02:00
|
|
|
echo -e "\n### Codec driver loading at startup (in /etc/modules)"
|
2019-01-26 15:01:46 +01:00
|
|
|
grep -q "^snd-soc-seeed-voicecard$" /etc/modules || \
|
2018-04-04 11:36:18 +02:00
|
|
|
echo "snd-soc-seeed-voicecard" >> /etc/modules
|
2019-01-26 15:01:46 +01:00
|
|
|
grep -q "^snd-soc-ac108$" /etc/modules || \
|
2017-09-14 11:26:04 +02:00
|
|
|
echo "snd-soc-ac108" >> /etc/modules
|
2019-01-26 15:01:46 +01:00
|
|
|
grep -q "^snd-soc-wm8960$" /etc/modules || \
|
2017-09-14 11:26:04 +02:00
|
|
|
echo "snd-soc-wm8960" >> /etc/modules
|
2017-09-14 10:29:26 +02:00
|
|
|
|
2018-02-01 08:58:36 +01:00
|
|
|
#set dtoverlays
|
2020-08-23 19:27:31 +02:00
|
|
|
CONFIG=/boot/config.txt
|
|
|
|
[ -f /boot/firmware/usercfg.txt ] && CONFIG=/boot/firmware/usercfg.txt
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### Found boot configuration file $CONFIG"
|
2017-09-14 10:29:26 +02:00
|
|
|
|
2020-08-23 19:27:31 +02:00
|
|
|
sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' $CONFIG || true
|
|
|
|
grep -q "^dtoverlay=i2s-mmap$" $CONFIG || \
|
|
|
|
echo "dtoverlay=i2s-mmap" >> $CONFIG
|
2017-09-14 10:29:26 +02:00
|
|
|
|
2020-08-23 19:27:31 +02:00
|
|
|
|
|
|
|
grep -q "^dtparam=i2s=on$" $CONFIG || \
|
|
|
|
echo "dtparam=i2s=on" >> $CONFIG
|
2017-05-22 12:20:29 +02:00
|
|
|
|
2018-02-01 08:58:36 +01:00
|
|
|
#install config files
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### Install alsa and widget configuration"
|
2018-02-01 08:58:36 +01:00
|
|
|
mkdir /etc/voicecard || true
|
2020-09-28 09:45:45 +02:00
|
|
|
cp -v *.conf /etc/voicecard
|
|
|
|
cp -v *.state /etc/voicecard
|
2018-02-01 08:58:36 +01:00
|
|
|
|
2018-07-24 05:30:22 +02:00
|
|
|
#create git repo
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### Manage alsa configuration by git"
|
2018-07-24 05:30:22 +02:00
|
|
|
git_email=$(git config --global --get user.email)
|
|
|
|
git_name=$(git config --global --get user.name)
|
|
|
|
if [ "x${git_email}" == "x" ] || [ "x${git_name}" == "x" ] ; then
|
|
|
|
echo "setup git config"
|
|
|
|
git config --global user.email "respeaker@seeed.cc"
|
|
|
|
git config --global user.name "respeaker"
|
|
|
|
fi
|
|
|
|
echo "git init"
|
|
|
|
git --git-dir=/etc/voicecard/.git init
|
|
|
|
echo "git add --all"
|
|
|
|
git --git-dir=/etc/voicecard/.git --work-tree=/etc/voicecard/ add --all
|
|
|
|
echo "git commit -m \"origin configures\""
|
|
|
|
git --git-dir=/etc/voicecard/.git --work-tree=/etc/voicecard/ commit -m "origin configures"
|
2018-02-01 08:58:36 +01:00
|
|
|
|
2020-09-28 09:45:45 +02:00
|
|
|
echo -e "\n### Start service seeed-voicecard"
|
|
|
|
echo -e " see /var/log/seeed-voicecard.log for more service information"
|
2018-02-01 08:58:36 +01:00
|
|
|
cp seeed-voicecard /usr/bin/
|
|
|
|
cp seeed-voicecard.service /lib/systemd/system/
|
|
|
|
systemctl enable seeed-voicecard.service
|
2019-05-21 06:18:25 +02:00
|
|
|
systemctl start seeed-voicecard
|
2017-09-14 11:26:04 +02:00
|
|
|
|
2017-05-22 12:20:29 +02:00
|
|
|
echo "------------------------------------------------------"
|
2020-08-09 17:57:20 +02:00
|
|
|
echo "Please reboot your device to apply all settings"
|
2017-05-22 12:20:29 +02:00
|
|
|
echo "Enjoy!"
|
|
|
|
echo "------------------------------------------------------"
|