-
Notifications
You must be signed in to change notification settings - Fork 74
/
fetch_from_upstream.sh
executable file
·60 lines (50 loc) · 1.8 KB
/
fetch_from_upstream.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
#!/bin/bash
#
# Fetch new code for an entire MCU series from an upstream STM repository.
if [ $# -ne 2 ]; then
echo "usage: $0 <mcu> <src>"
echo ""
echo "eg: $0 STM32WB path/to/STM32CubeWB"
echo "where STM32CubeWB is from https://github.com/STMicroelectronics/STM32CubeWB.git"
exit 1
fi
mcu=$1
gitsrc=$2
cmsis=CMSIS/${mcu}xx
hal=${mcu}xx_HAL_Driver
if [ ! -d $cmsis ]; then
echo "WARNING: $cmsis is not an existing directory, assuming a new MCU series"
mkdir -p $cmsis
fi
if [ ! -d $hal ]; then
echo "WARNING: $hal is not an existing directory, assuming a new MCU series"
mkdir -p $hal
fi
# CMSIS: remove any old files and copy across the new ones.
echo "Fetching CMSIS to $cmsis"
rm -rf $cmsis/Include
rm -rf $cmsis/Source
cp -r $gitsrc/Drivers/CMSIS/Device/ST/${mcu}xx/Include $cmsis/
cp -r $gitsrc/Drivers/CMSIS/Device/ST/${mcu}xx/Source $cmsis/
rm -rf CMSIS/${mcu}xx/Source/Templates/*/linker
# HAL: remove any old files and copy across the new ones.
echo "Fetching HAL to $hal"
rm -rf $hal/Inc
rm -rf $hal/Src
cp -r $gitsrc/Drivers/${mcu}xx_HAL_Driver/Inc $hal/
cp -r $gitsrc/Drivers/${mcu}xx_HAL_Driver/Src $hal/
# Make sure tr and exand don't expect UTF-8, because these files aren't
export LC_CTYPE=C
for dir in $cmsis $hal; do
# Process the new source code to:
# - remove trailing white-space
# - convert to unix line-endings
# - expand tabs with 4 spaces
# - convert non-ascii chars to ascii equivalent (should only be in comments)
echo "Processing source code in $dir"
for file in $(find $dir -name "*.[chs]"); do
chmod 644 $file
cat $file | awk "{sub(/[\t ]*$/,\"\")}1" | expand -t 4 | tr \\200\\205\\211\\221\\222\\223\\224\\226\\231\\244\\261\\265\\302\\327\\342 \'??\'\'\"\"\\-\'??u?x\' > tmp$$
/bin/mv tmp$$ $file
done
done