-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmarvell_sonic_patch_script.sh
More file actions
executable file
·276 lines (250 loc) · 5.94 KB
/
marvell_sonic_patch_script.sh
File metadata and controls
executable file
·276 lines (250 loc) · 5.94 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/bin/bash
# Copyright (c) Marvell, Inc. All rights reservered. Confidential.
# Description: Applying open PRs needed for compilation
#
# Sonic patch script for Marvell board
#
#
# CONFIGURATIONS:-
#
#
# END of CONFIGURATIONS
#
# PREDEFINED VALUES
CUR_DIR=$(basename `pwd`)
LOG_FILE=patches_result.log
FULL_PATH=`pwd`
err_cnt=0
PATCH_SERIES_FILE=
# VERIFY_PATCHES=Y may be selected by MRVL sonic_build_script.sh
if [[ "$DEVEL" == "" || "$VERIFY_PATCHES" == "Y" ]]; then
PATCH_ERR_SKIP=
else
PATCH_ERR_SKIP=Y
fi
log()
{
echo $@
echo $@ >> ${FULL_PATH}/${LOG_FILE}
}
print_usage()
{
log "Usage:"
log ""
log " bash $0 --branch <> --platform <marvell|marvell-prestera|innovium|marvell-teralynx> --arch <amd64|arm64> --release-tag <>"
log ""
log ""
}
pre_patch_help()
{
log "STEPS TO BUILD:"
log "git clone https://github.com/sonic-net/sonic-buildimage.git -b <sonic_branch>"
log "cd sonic-buildimage"
log "<<Apply patches using patch script for sonic-buildimage>>"
log "make init"
log "git submodule update --init --recursive (instead of make init)"
log ""
log "<<Apply patches using patch script for submodules>>"
print_usage
log "PLATFORM: marvell"
log "<<FOR ARM64>> make configure PLATFORM=marvell PLATFORM_ARCH=arm64"
log "<<FOR ARM64>> make target/sonic-marvell-arm64.bin"
log "<<FOR INTEL>> make configure PLATFORM=marvell"
log "<<FOR INTEL>> make target/sonic-marvell.bin"
log ""
log "PLATFORM: innovium"
log "<<FOR INTEL>> make configure PLATFORM=innovium"
log "<<FOR INTEL>> make target/sonic-innovium.bin"
log ""
log "PLATFORM: marvell-teralynx"
log "<<FOR INTEL>> make configure PLATFORM=marvell-teralynx"
log "<<FOR INTEL>> make target/sonic-marvell-teralynx.bin"
log ""
}
parse_arguments()
{
while [[ $# -gt 0 ]]; do
case $1 in
-b|--branch)
BRANCH="$2"
shift # past argument
shift # past value
;;
-p|--platform)
PLATFORM="$2"
shift # past argument
shift # past value
;;
-a|--arch)
ARCH="$2"
shift # past argument
shift # past value
;;
-t|--release-tag)
GIT_TAG="$2"
shift # past argument
shift # past value
;;
--url)
URL="$2"
shift # past argument
shift # past value
;;
-h|--help)
print_usage
exit 0
;;
*)
echo "ERROR: Unknown option '$1'"
print_usage
exit 1
;;
esac
done
if [ -z "${BRANCH}" ]; then
echo "Branch is not set. Please check usage."
print_usage
exit 0
fi
if [ -z "${ARCH}" ]; then
echo "Arch is not set. Please check usage."
print_usage
exit 0
fi
if [[ -z "${GIT_TAG}" && -z "${URL}" ]]; then
echo "Github release tag is not set. Please check usage."
print_usage
exit 0
fi
if [ -z "${PLATFORM}" ]; then
echo "Platform is not set. Please check usage."
print_usage
exit 0
fi
if [ -z "${URL}" ]; then
WGET_PATH="https://raw.githubusercontent.com/Marvell-switching/sonic-scripts/$GIT_TAG/files/$BRANCH/"
else
WGET_PATH=$URL/files/$BRANCH
fi
}
wget_cp()
{
if [[ "$1" == *:* ]]; then
# Is URL - use wget
wget --timeout=2 -c $1
else
# Dir or File is on local path
cp -r $1 .
fi
}
apply_sonicbuildimage_patches()
{
cat ${PATCH_SERIES_FILE} | grep -v -E '^#|^$' | grep sonic-buildimage | cut -f 1 -d'|' | while read -r patch_file
do
echo $patch_file
pushd patches
wget_cp $WGET_PATH/$patch_file
popd
git am patches/$patch_file
ret=$?
if [ $ret -ne 0 ]; then
((err_cnt++))
if [ "$PATCH_ERR_SKIP" == "" ]; then
log "PATCH ERROR: Failed to apply sonicbuildimage patches/$patch_file, abort"
return $ret
fi
log "PATCH ERROR: Failed to apply sonicbuildimage patches/$patch_file, skeep and continue"
git am --skip
fi
done
}
apply_submodule_patches()
{
CWD=`pwd`
cat ${PATCH_SERIES_FILE} | grep -v -E '^#|^$' | grep -v sonic-buildimage | while read -r line
do
patch=`echo $line | cut -f 1 -d'|'`
dir=`echo $line | cut -f 2 -d'|'`
pushd patches
wget_cp $WGET_PATH/${patch}
popd
pushd ${dir}
git am $CWD/patches/${patch}
ret=$?
if [ $ret -ne 0 ]; then
((err_cnt++))
if [ "$PATCH_ERR_SKIP" == "" ]; then
log "PATCH ERROR: Failed to apply submodule $CWD/patches/${patch}, abort"
return $ret
fi
log "PATCH ERROR: Failed to apply submodule $CWD/patches/${patch}, skeep and continue"
git am --skip
fi
popd
done
}
apply_hwsku_changes()
{
if [ "$PLATFORM" == "marvell" ] || [ "$PLATFORM" == "marvell-prestera" ]; then
# Download hwsku
wget_cp $WGET_PATH/prestera_hwsku.tgz
if [ $? -eq 0 ]; then
rm -fr device/marvell/x86_64-marvell_db* || true
tar -C device/ -xzf prestera_hwsku.tgz
fi
fi
if [ "$PLATFORM" == "innovium" ] || [ "$PLATFORM" == "marvell-teralynx" ]; then
# Download hwsku
wget_cp $WGET_PATH/teralynx_hwsku.tgz
if [ $? -eq 0 ]; then
rm -fr device/celestica/x86_64-cel_midstone-r0 || true
rm -fr device/wistron || true
tar -C device/ -xzf teralynx_hwsku.tgz
fi
fi
}
main()
{
if [ "$CUR_DIR" != "sonic-buildimage" ]; then
log "ERROR: Need to be at sonic-builimage git clone path"
pre_patch_help
exit 1
fi
parse_arguments $@
date > ${FULL_PATH}/${LOG_FILE}
[ -d patches ] || mkdir patches
# wget patch series file
PATCH_SERIES_FILE=series_${PLATFORM}_${ARCH}
wget_cp $WGET_PATH/${PATCH_SERIES_FILE}
if [ ! -f ${PATCH_SERIES_FILE} ]; then
PATCH_SERIES_FILE=series_${PLATFORM}
wget_cp $WGET_PATH/${PATCH_SERIES_FILE}
if [ ! -f ${PATCH_SERIES_FILE} ]; then
log "ERROR: Series file series_${PLATFORM}_${ARCH} not found"
exit 1
fi
fi
# Apply patch
log "Apply sonicbuildimage patches"
apply_sonicbuildimage_patches
if [ $? -ne 0 ]; then
# log ERROR already printed
exit 1
fi
echo "make init" >> build_cmd.txt
make init
git submodule sync --recursive
git submodule update --init --recursive
log "Apply submodule patches"
# Apply submodule patches
apply_submodule_patches
if [ $? -ne 0 ]; then
# log ERROR already printed
exit 1
fi
log "Apply hwsku changes"
# Apply hwsku changes
apply_hwsku_changes
log "Patch script - DONE"
}
main $@