-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_image.sh
executable file
·120 lines (95 loc) · 2.54 KB
/
build_image.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
#!/bin/bash
# Stop the script for errors
set -o errexit
set -o pipefail
_declare_variables(){
TOOLCHAIN="GCC_ARM-RELEASE"
TARGET="NUCLEO_L486RG"
FLASH_SIZE="1024"
BOOTLOADER_OFFSET="0" # 0x00000
BOOTLOADER_SIZE="65536" # 0x10000
ENV_OFFSET="65536" # 0x10000
ENV_SIZE="2048" # 0x00800
APP_A_OFFSET="67584" # 0x10800
APP_A_SIZE="489472" # 0x77800
APP_B_OFFSET="557056" # 0x88000
APP_B_SIZE="489472" # 0x77800
}
# Check if a folder exist. If not, create it
_folder_check() {
if [ ! -d ./$@ ]
then
echo "The $@ folder doesn't exist."
return 1
else
return 0
fi
}
# Check if a file exists
_file_exists(){
if [ ! -f ./$@ ]
then
echo "File $@ is missing!"
return 1
else
return 0
fi
}
# Check if the bin folder exists, if not, create it.
_bin_check(){
bin_folder="bin/$1"
if ! _folder_check $bin_folder
then
echo "Creating the $bin_folder directory"
mkdir -p ./$bin_folder
fi
}
# Compile app a and app b
_compile_app(){
APPS=( "app_a" "app_b")
local compile_script="build.sh"
for i in "${APPS[@]}"
do
cd $i
./$compile_script
cd -
cp $i/BUILD/$TARGET/$TOOLCHAIN/$i.bin ./$bin_folder/
done
}
# create padded file
_output_file(){
local bootloader_dir="./shard-v2-bootloader-image/bootloader.bin"
local OUT_BIN="./$bin_folder/image.bin"
local app_a_bin="./$bin_folder/${APPS[0]}.bin"
local app_b_bin="./$bin_folder/${APPS[1]}.bin"
if _file_exists $bootloader_dir
then
dd if=/dev/zero ibs=1k count=$FLASH_SIZE | tr "\000" "\377" > "$OUT_BIN"
dd if=$bootloader_dir of="$OUT_BIN" bs=1 count=$BOOTLOADER_SIZE seek=$BOOTLOADER_OFFSET conv=notrunc
if _file_exists $app_a_bin
then
dd if=$app_a_bin of="$OUT_BIN" bs=1 count=$APP_A_SIZE seek=$APP_A_OFFSET conv=notrunc
else
echo "Please check if there is a problem with the compiler."
echo "Aborting..."
exit 1
fi
if _file_exists $app_b_bin
then
dd if=$app_b_bin of="$OUT_BIN" bs=1 count=$APP_B_SIZE seek=$APP_B_OFFSET
else
echo "Please check if there is a problem with the compiler."
echo "Aborting..."
exit 1
fi
else
echo "The bootloader file is missing! Please run:"
echo "git submodule update --init"
echo "Aborting..."
exit 1
fi
}
_declare_variables
_bin_check $1
_compile_app
_output_file