-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirmwareFactory.sh
executable file
·242 lines (210 loc) · 4.64 KB
/
FirmwareFactory.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# Moebyus Firmware Generator
#
#
#
#
#!/bin/bash
#Variables
ARDUINO_PATH="/home/moebyusdev/arduino-1.8.2"
FIRMWARE_URL="https://github.com/moebyus/Marlin"
FIRMWARE_FILE="Marlin.hex"
#Paths
BASE_PATH=$PWD
TMP_PATH=$BASE_PATH"/tmp"
BUILD_PATH=$TMP_PATH"/build"
BUILDFAILED_PATH=$TMP_PATH"/failed"
SOURCES_PATH=$BUILD_PATH"/sources"
EXPORT_PATH=$BASE_PATH"/Firmwares"
MARLIN_TEMPLATE_PATH=$TMP_PATH"/MarlinTemplate"
#Funciones
shit_happened_count=0
createDirs()
{
echo "BasePath:" $BASE_PATH
mkdir -p "$BUILD_PATH"
mkdir -p "$TMP_PATH"
mkdir -p "$BUILDFAILED_PATH"
}
cleanBuild()
{
if [ -d "$BUILD_PATH" ] ; then
echo "Limpiando" $BUILD_PATH
cd $BUILD_PATH
rm -rf *
fi
if [ -d "$EXPORT_PATH" ] ; then
echo "Limpiando" $EXPORT_PATH
cd $EXPORT_PATH
rm -rf *
fi
}
cleanAll()
{
if [ -d "$TMP_PATH" ] ; then
echo "Limpiando" $TMP_PATH
cd $TMP_PATH
rm -rf *
fi
cleanBuild
}
getFirmwareTemplate()
{
echo "Comprobando plantilla del fimware..." "$MARLIN_TEMPLATE_PATH"
if [ -d "$MARLIN_TEMPLATE_PATH" ];then
echo "Ya la tengo."
else
echo "Clonando..."
git clone $FIRMWARE_URL "$MARLIN_TEMPLATE_PATH"
if [ "$?" -ne 0 ];then echo "Algo ha ido mal." ; return 1; fi
fi
}
buildMarlinPath()
{
echo "----------" | figlet
MARLIN_PATH=$1
DESTINATION=$2
if [ -d "$MARLIN_PATH" ];then
echo "Firmware : "$MARLIN_PATH
else
echo "No encuentro:"$MARLIN_PATH
return 1
fi
JOB_NAME=`basename $MARLIN_PATH`
CMAKE_FILE=$MARLIN_PATH/buildroot/share/cmake/CMakeLists.txt
JOB_PATH=$BUILD_PATH/$JOB_NAME
LOGFILE=$JOB_PATH/log.txt
if [ -d "$2" ];then
DESTINATION=$2
else
DESTINATION=$JOB_PATH
fi
FINAL_FILE=$DESTINATION"/"$JOB_NAME".hex"
echo $JOB_NAME | figlet
echo "Compilando en" $JOB_PATH
mkdir -p $JOB_PATH
touch $LOGFILE
cd $JOB_PATH
cmake $CMAKE_FILE -DARDUINO_SDK_PATH=$ARDUINO_PATH -B$JOB_PATH &>> $LOGFILE
make &>> $LOGFILE
RESULT_FILE=$JOB_PATH/$FIRMWARE_FILE
if [ -f "$RESULT_FILE" ];then
cp $RESULT_FILE $FINAL_FILE
echo "Generado:" $FINAL_FILE
echo "ok" | figlet
return 0
else
echo "fail" | figlet
return 1
fi
}
prepareFirmwares()
{
echo "Preparando firmwares"
cd $BASE_PATH/profiles
for MODEL in *
do
cd $BASE_PATH/profiles
if [ -d "$MODEL" ] ;then
shit_happened="No"
cd $BASE_PATH/profiles/$MODEL/sabores
for FLAVOR in *
do
cd $BASE_PATH/profiles/$MODEL/sabores
if [ -d "$FLAVOR" ]; then
shit_happened_this_time=0
echo "*Sabor:" $MODEL"-"$FLAVOR
F_PATH=$SOURCES_PATH"/"$MODEL"-"$FLAVOR
mkdir -p $F_PATH
cp -r $MARLIN_TEMPLATE_PATH/* $F_PATH
mkdir -p $F_PATH"/patches"
cp ../base/* $F_PATH"/patches" &> /dev/null
cp $FLAVOR/* $F_PATH"/patches" &> /dev/null
echo "--Aplicando patches y ficheros..."
cd $F_PATH/Marlin
for p in `ls ../patches/*.patch`
do
cat ../patches/$p | patch -p1
if [ "$?" -ne 0 ] ; then
let shit_happened_count++;
let shit_happened_this_time++;
echo "ERROR!!! : " $p
fi
done
cd ../patches/
for file in `ls|grep -v patch`
do
echo "----$file"
cp $file ../Marlin
done
if [ $shit_happened_this_time -ne 0 ];then
echo "Ha fallado la aplicacion de los patches, se elimina de la lista de compilacion"
mv $F_PATH $BUILDFAILED_PATH/
fi
fi
done
fi
done
if [ $shit_happened_count -gt 0 ];then
echo "ha habido errores"
else
echo "So far so good!"
fi
}
compileAllFirmwares()
{
firmware_count=0
echo "Compilando firmwares"
cd $SOURCES_PATH
for FLAVOR in *
do
cd $SOURCES_PATH
if [ -d "$FLAVOR" ];then
buildMarlinPath `realpath $FLAVOR` $EXPORT_PATH
if [ "$?" -eq 0 ];then
cd $SOURCES_PATH
RESULT=$EXPORT_PATH/`echo $FLAVOR | awk -F- '{print $1}'`
echo "Exportando $FLAVOR"
mkdir -p $RESULT
cp $EXPORT_PATH/$FLAVOR.hex $RESULT
cp -r $FLAVOR $RESULT
let firmware_count++
else
let shit_happened_count++
fi
fi
done
echo "Firmwares:" |figlet
echo $firmware_count |figlet
echo "Errores:" |figlet
echo $shit_happened_count |figlet
echo "Terminado :)" |figlet
}
#Programa
echo "Firmware Factory" | figlet
createDirs
case $1 in
"setup" )
sudo apt-get install cmake figlet;;
"cleanAll" )
cleanAll;;
"cleanBuild" )
cleanBuild;;
"buildTemplate" )
getFirmwareTemplate
buildMarlinPath $MARLIN_TEMPLATE_PATH $BUILD_PATH;;
"prepare" )
prepareFirmwares;;
"compile" )
compileAllFirmwares;;
"all" )
cleanBuild
getFirmwareTemplate
prepareFirmwares
compileAllFirmwares;;
*)
echo "Nada que hacer."
echo "Comandos:"
echo "setup - instala las dependencias necesarias"
echo "cleanAll - limpia el espacio de trabajo"
echo "all - Compila todos los firmwares"
esac