Created
August 29, 2017 10:24
-
-
Save janhieber/ab557d2e2fc5e3a3f678108e27fc291d to your computer and use it in GitHub Desktop.
Copy kernel and modules to SSH or local SD/MMC target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# settings | |
DEVICE=sdj | |
IP=192.168.0.2 | |
########################################################## | |
function main(){ | |
# if we have an IP, check if target is there | |
# otherwise copy local | |
if [[ -n $IP ]] | |
then | |
ping -c1 -W2 $IP >/dev/null | |
[[ $? == 0 ]] && copy_scp || copy_local | |
exit 0 | |
else | |
[[ -n $DEVICE ]] && copy_local | |
exit 0 | |
fi | |
} | |
function copy_local() { | |
RET=1 | |
local BOOTPART="1" | |
local LINUXPART="2" | |
# check for device | |
mkdir -p ./mount | |
echo -n "wait for device " | |
# set partition names for sdXY and mmcblkXpY | |
if [[ ${1:0:2} == "sd" ]] | |
then | |
local PART1="${1}${BOOTPART}" | |
local PART2="${1}${LINUXPART}" | |
else | |
local PART1="${1}p${BOOTPART}" | |
local PART2="${1}p${LINUXPART}" | |
fi | |
# wait for device | |
while true | |
do | |
if [[ -b /dev/${PART1} ]] | |
then | |
echo -en "\n" | |
break | |
else | |
echo -n "." | |
sleep 0.5 | |
fi | |
done | |
# copy kernel | |
sudo mount -v /dev/${PART1} ./mount | |
sudo cp -v linux.fit ./mount/ | |
sudo umount -v ./mount | |
# copy modules | |
export INSTALL_MOD_PATH="./mount" | |
sudo mount -v /dev/${PART2} ./mount | |
echo "install modules and firmware ..." | |
sudo -E make --silent modules_install firmware_install | |
sudo umount -v ./mount | |
RET=0 | |
} | |
function copy_scp() { | |
RET=1 | |
local SSH="root@$IP" | |
scp linux.fit $SSH:/boot/ | |
local VERSION=$(strings vmlinux | grep "Linux version" | cut -d' ' -f3) | |
export INSTALL_MOD_PATH="./modules_tmp" | |
mkdir -p $INSTALL_MOD_PATH | |
rm -f $INSTALL_MOD_PATH/* 2&> /dev/null | |
echo "modules and firmware ..." | |
echo " make install" | |
make --silent modules_install firmware_install | |
ssh $SSH "rm -R /usr/lib/modules/$VERSION" | |
echo " copy modules to target" | |
rsync -rl --safe-links modules_tmp/lib/modules/$VERSION $SSH:/lib/modules/ | |
echo " copy firmware to target" | |
rsync -rl --safe-links modules_tmp/lib/firmware/* $SSH:/lib/firmware/ | |
RET=0 | |
} | |
main $@ | |
[[ $RET == 0 ]] && echo "FINISHED" || echo "ERROR OCCURRED" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment