Last active
December 7, 2016 06:23
-
-
Save dermidgen/e2fc653a1d8de72b590d6b11ff475594 to your computer and use it in GitHub Desktop.
Quick flash latest linux4sam-poky-sama5d4_xplained via sam-ba 2.16
This file contains hidden or 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
#!/bin/bash | |
## | |
# Helper functions | |
## | |
pkg_check () | |
{ | |
echo "Checking for $1:" | |
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $1|grep "install ok installed") | |
if [ "" == "$PKG_OK" ]; then | |
echo " ... found." | |
return 0 | |
fi | |
return 1 | |
} | |
pkg_install () | |
{ | |
echo "$1 not found. Setting up $1." | |
sudo apt-get --force-yes --yes install $1 | |
} | |
pkg_ensure () | |
{ | |
if pkg_check "$1"; then | |
pkg_install "$1" | |
fi | |
} | |
## | |
# Install pre-requisites | |
## | |
pkg_ensure "picocom" | |
pkg_ensure "curl" | |
pkg_ensure "screen" | |
## | |
# Setup workspace | |
## | |
WORKSPACE="sama5d4-explained-ultra" | |
SAMBA_DIR=sam-ba_cdc_linux | |
SAMBA_PATH=~/$SAMBA_DIR | |
SRC_DIR=linux4sam-poky-sama5d4_xplained-5.5 | |
if [ ! -d "$WORKSPACE" ]; then | |
echo "Creating workspace: $WORKSPACE" | |
mkdir "$WORKSPACE" | |
fi | |
echo "Using workspace: $WORKSPACE" | |
cd "$WORKSPACE" | |
# Download resources | |
if [ ! -f "sam-ba_2.16_linux.zip" ]; then | |
curl -o sam-ba_2.16_linux.zip https://dl.dropboxusercontent.com/u/3944881/sw/sam-ba_2.16_linux.zip | |
fi | |
if [ ! -f "linux4sam-poky-sama5d4_xplained-5.5.zip" ]; then | |
curl -o linux4sam-poky-sama5d4_xplained-5.5.zip ftp://www.at91.com/pub/demo/linux4sam_5.5/linux4sam-poky-sama5d4_xplained-5.5.zip | |
fi | |
# Setup sam-ba | |
if [ ! -d $SAMBA_PATH ]; then | |
echo "Couldn't find $SAMBA_PATH: setting up" | |
unzip sam-ba_2.16_linux.zip | |
cp -R ./$SAMBA_DIR $SAMBA_PATH | |
echo "export PATH=$SAMBA_PATH:$PATH" | tee -a ~/.bashrc | |
fi | |
echo "Using sam-ba at $SAMBA_PATH" | |
export PATH=$SAMBA_PATH:$PATH | |
# Setup source dir | |
if [ ! -d $SRC_DIR ]; then | |
echo "Couldn't find $SRC_DIR: setting up" | |
unzip linux4sam-poky-sama5d4_xplained-5.5.zip | |
# Tell sources to use sam-ba_64 instead of sam-ba | |
echo "Patching demo_linux_nandflash.sh to use sam-ba_64" | |
sed -i -e 's/sam-ba/sam-ba_64/g' ./$SRC_DIR/demo_linux_nandflash.sh | |
fi | |
if [ ! -f ".screenrc" ]; then | |
cat >./.screenrc <<EOL | |
screen | |
title "picocom" | |
stuff "picocom -b 115200 /dev/ttyUSB0\n" | |
split | |
focus down | |
chdir linux4sam-poky-sama5d4_xplained-5.5 | |
screen -t "window" bash -ic 'PATH=~/sam-ba_cdc_linux:$PATH bash' | |
title "nandflash" | |
exec echo "Run ./demo_linux_nandflash.sh when ready.\n" | |
EOL | |
fi | |
# Run screen | |
screen -c .screenrc | |
# Running sam-ba_64 | |
# echo "Running sam-ba_64 via demo_linux_nandflash.sh:" | |
# echo "" | |
# cd $SRC_DIR | |
# ./demo_linux_nandflash.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment