andrewm@58
|
1 #!/bin/bash
|
andrewm@58
|
2 #
|
andrewm@58
|
3 # This script compiles a BeagleRT project on the BeagleBone Black and
|
andrewm@58
|
4 # optionally runs it. Pass a directory path in the first argument.
|
andrewm@58
|
5 # The source files in this directory are copied to the board and compiled.
|
andrewm@58
|
6
|
giuliomoro@262
|
7 # set defaults unless variables are already set
|
giuliomoro@262
|
8 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
|
giuliomoro@262
|
9 [ -z "$BBB_PATH" ] && BBB_PATH="~/BeagleRT"
|
giuliomoro@262
|
10 [ -z "$RUN_PROJECT" ] && RUN_PROJECT=1
|
giuliomoro@262
|
11 [ -z "$COMMAND_ARGS" ] && COMMAND_ARGS=
|
giuliomoro@262
|
12 [ -z "$RUN_IN_FOREGROUND" ] && RUN_IN_FOREGROUND=1
|
giuliomoro@262
|
13 [ -z "$RUN_WITHOUT_SCREEN" ] && RUN_WITHOUT_SCREEN=0
|
giuliomoro@262
|
14 [ -z "$SCREEN_NAME" ] && SCREEN_NAME=Bela
|
andrewm@58
|
15
|
andrewm@58
|
16 function usage
|
andrewm@58
|
17 {
|
andrewm@58
|
18 THIS_SCRIPT=`basename "$0"`
|
andrewm@90
|
19 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-nfF] <directory-with-source-files>"
|
andrewm@58
|
20 echo "
|
andrewm@58
|
21 This script copies a directory of source files to the BeagleBone, compiles
|
andrewm@58
|
22 and runs it. The BeagleRT core files should have first been copied over
|
andrewm@58
|
23 using the setup_board.sh script supplied with BeagleRT.
|
andrewm@58
|
24
|
andrewm@58
|
25 The source directory should contain at least one .c, .cpp or .S file.
|
andrewm@58
|
26 If the argument -n is passed, the output will not be run after compiling.
|
andrewm@58
|
27 The argument -b will change the local path on the BeagleBone where the
|
andrewm@60
|
28 BeagleRT files are found. The -c option passes command-line arguments to
|
andrewm@90
|
29 the BeagleRT program; enclose the argument string in quotes.
|
andrewm@90
|
30
|
giuliomoro@263
|
31 By default, the project runs in the foreground of the current terminal,
|
andrewm@90
|
32 within a screen session that can be detached later. The -F argument runs
|
giuliomoro@263
|
33 the project in the foreground of the current terminal, without screen, so
|
giuliomoro@263
|
34 the output can be piped to another destination. The -f argument runs it
|
giuliomoro@263
|
35 in a screen in the background, so no output is shown."
|
andrewm@58
|
36 }
|
andrewm@58
|
37
|
andrewm@58
|
38 OPTIND=1
|
andrewm@58
|
39
|
andrewm@90
|
40 while getopts "b:c:nfFh" opt; do
|
andrewm@58
|
41 case $opt in
|
andrewm@58
|
42 b) BBB_PATH=$OPTARG
|
andrewm@58
|
43 ;;
|
andrewm@60
|
44 c) COMMAND_ARGS=$OPTARG
|
andrewm@60
|
45 ;;
|
giuliomoro@263
|
46 f) RUN_IN_FOREGROUND=0
|
andrewm@90
|
47 ;;
|
andrewm@90
|
48 F) RUN_WITHOUT_SCREEN=1
|
andrewm@90
|
49 ;;
|
andrewm@58
|
50 n) RUN_PROJECT=0
|
andrewm@58
|
51 ;;
|
andrewm@58
|
52 h|\?) usage
|
andrewm@58
|
53 exit 1
|
andrewm@58
|
54 esac
|
andrewm@58
|
55 done
|
andrewm@58
|
56
|
andrewm@58
|
57 shift $((OPTIND-1))
|
andrewm@58
|
58
|
andrewm@58
|
59 # Check that we have a directory containing at least one source file
|
andrewm@58
|
60 # as an argument
|
giuliomoro@64
|
61
|
andrewm@58
|
62 if [ -z "$1" ]
|
andrewm@58
|
63 then
|
andrewm@58
|
64 usage
|
andrewm@58
|
65 exit
|
andrewm@58
|
66 fi
|
andrewm@58
|
67
|
giuliomoro@64
|
68 FIND_STRING="find $* -maxdepth 10000 -type f "
|
giuliomoro@64
|
69
|
giuliomoro@64
|
70 C_FILES=$($FIND_STRING -name "*.c")
|
giuliomoro@64
|
71 CPP_FILES=$($FIND_STRING -name "*.cpp")
|
giuliomoro@64
|
72 ASM_FILES=$($FIND_STRING -name "*.S")
|
andrewm@58
|
73
|
andrewm@58
|
74 if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]]
|
andrewm@58
|
75 then
|
andrewm@58
|
76 echo "Please provide a directory containing .c, .cpp or .S files."
|
andrewm@58
|
77 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]"
|
andrewm@58
|
78 usage
|
andrewm@58
|
79 exit
|
andrewm@58
|
80 fi
|
andrewm@58
|
81
|
andrewm@58
|
82 # Stop BeagleRT and clean out old source files
|
giuliomoro@261
|
83 echo "Stopping running program..."
|
giuliomoro@261
|
84 # sets the date, stops the running process
|
giuliomoro@261
|
85 ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; screen -X -S '"$SCREEN_NAME"' quit &>/dev/null;"
|
giuliomoro@64
|
86
|
giuliomoro@64
|
87 #concatenate arguments to form path.
|
giuliomoro@64
|
88 BBB_SOURCE_PATH= #initially empty, will be filled with input arguments
|
giuliomoro@64
|
89 for i in "$@" #parse input arguments
|
giuliomoro@64
|
90 do
|
giuliomoro@64
|
91 if [ -d "$1" ] #check if the path is a folder
|
giuliomoro@64
|
92 then #if it is, include all of its files
|
giuliomoro@64
|
93 BBB_SOURCE_PATH+=" ${1}/* "
|
giuliomoro@64
|
94 else
|
giuliomoro@64
|
95 BBB_SOURCE_PATH+=" $1 "
|
giuliomoro@64
|
96 fi
|
giuliomoro@64
|
97 shift
|
giuliomoro@64
|
98 # Copy new souce files to the board
|
giuliomoro@64
|
99 done
|
andrewm@58
|
100
|
andrewm@58
|
101 # Copy new source files to the board
|
andrewm@58
|
102 echo "Copying new source files to BeagleBone..."
|
giuliomoro@64
|
103 scp $BBB_SOURCE_PATH "$BBB_ADDRESS:$BBB_PATH/source/"
|
giuliomoro@64
|
104
|
giuliomoro@64
|
105 if [ $? -ne 0 ]
|
giuliomoro@64
|
106 then
|
giuliomoro@64
|
107 echo "Error while copying files"
|
giuliomoro@64
|
108 exit
|
giuliomoro@64
|
109 fi
|
andrewm@58
|
110
|
andrewm@58
|
111 # Make new BeagleRT executable and run
|
andrewm@58
|
112 if [ $RUN_PROJECT -eq 0 ]
|
andrewm@58
|
113 then
|
andrewm@58
|
114 echo "Building project..."
|
andrewm@58
|
115 ssh $BBB_ADDRESS "make all -C $BBB_PATH"
|
andrewm@58
|
116 else
|
andrewm@58
|
117 echo "Building and running project..."
|
andrewm@90
|
118
|
andrewm@90
|
119 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
|
andrewm@90
|
120 then
|
giuliomoro@249
|
121 ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && ../BeagleRT $COMMAND_ARGS"
|
andrewm@90
|
122 elif [ $RUN_IN_FOREGROUND -eq 0 ]
|
andrewm@90
|
123 then
|
giuliomoro@261
|
124 ssh $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S $SCREEN_NAME -d -m ../BeagleRT $COMMAND_ARGS"
|
andrewm@90
|
125 else
|
giuliomoro@261
|
126 ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S $SCREEN_NAME ../BeagleRT $COMMAND_ARGS"
|
andrewm@90
|
127 fi
|
giuliomoro@249
|
128 fi
|