-
Notifications
You must be signed in to change notification settings - Fork 0
/
edkinstall.sh
executable file
·338 lines (294 loc) · 8.37 KB
/
edkinstall.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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/bin/bash
###############################################################################
#
# EDK2 Utility Scripts
#
# Author: David Petrovic
# GitHub: https://github.com/davepet1234/edk2-scripts
#
################################################################################
# Script to download and configure EDK2 build environment
################################################################################
# Automatic/Default parameters
PROGRAM_DIR="$(cd "$(dirname "$0")"; pwd;)"
source "${PROGRAM_DIR}/shared.sh"
EDK2_REPO_URL="https://github.com/tianocore/edk2.git"
LIBC_REPO_URL="https://github.com/tianocore/edk2-libc"
PARENT_DIR="$PWD"
TAG=""
CLONE_OPTS=""
FORCE=0
CLANG=0
LIBC=0
################################################################################
# print_help
function print_help {
cat <<EOF
Script to download and configure EDK2 build environment
Usage: ${PROGRAM_NAME} [<workspace>] [OPTIONS]
OPTIONS:
<workspace> The name of a 'new' workspace folder (default: edk2)
-p, --parent <dir> Parent directory to clone into (default is current directory)
-t, --tag <tag> GIT tag to clone (default: master)
-c, --clang Install for Clang compiler (default: gcc)
--libc Install EDK2 LIBC (default workspace folder: edk2libc)
-f, --force No prompts
-h, --help Print this help and exit
EOF
exit 1
}
################################################################################
# Options parser
if [ -n "$1" ] && [ ! "${1::1}" == "-" ]; then
valid_filename $1
if [ $? -ne 0 ]; then
print_err "Invalid target directory: $1"
exit 1
fi
WORKSPACE_FOLDER=$1
shift # past target directory
fi
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-p|--parent)
PARENT_DIR="$2"
if [ ! -d "${PARENT_DIR}" ]; then
print_err "Parent directory does not exist: ${PARENT_DIR}"
exit 1
fi
PARENT_DIR="$( cd "$2" && pwd )"
shift # past argument
shift # past value
;;
-t|--tag)
TAG="$2"
CLONE_OPTS="--branch ${TAG}"
shift # past argument
shift # past value
;;
-c|--clang)
CLANG=1
shift # past argument
;;
--libc)
LIBC=1
shift # past argument
;;
-f|--force)
FORCE=1
shift # past argument
;;
-h|--help)
print_help
exit 1
;;
*) # unknown option
print_err "Invalid option: $key"
exit 1
;;
esac
done
if [ -z "${WORKSPACE_FOLDER}" ]; then
if [ ${LIBC} -eq 0 ]; then
WORKSPACE_FOLDER=$(basename ${EDK2_REPO_URL} .git)
else
WORKSPACE_FOLDER="edk2libc"
fi
fi
################################################################################
# main
check_script_env
# check if EDK2 workspace already set
if [ -n "${WORKSPACE}" ]; then
print_warn "EDK2 workspace already configured: ${WORKSPACE}"
fi
START_SECONDS=$(date +%s)
# determine location
if [ ! -d "${PARENT_DIR}" ]; then
print_err "Parent directory does not exist"
exit 1
fi
WORKSPACE_DIR="${PARENT_DIR}/${WORKSPACE_FOLDER}"
if [ -d "${WORKSPACE_DIR}" ]; then
print_err "Directory already exists with that name: ${WORKSPACE_DIR}"
exit 1
fi
print_info "Install directory: ${WORKSPACE_DIR}"
if [ -n "${TAG}" ]; then
print_info "EDK2 clone tag: ${TAG}"
fi
if [ ${CLANG} -eq 1 ]; then
print_info "Clang compiler"
fi
if [ ${LIBC} -eq 1 ]; then
print_info "LIBC support"
fi
user_confirm "Continue" ${FORCE}
if [ $? -ne 0 ]; then
print_warn "Aborted by user"
exit 1
fi
# create workspace directory
cd ${PARENT_DIR}
if [ ${LIBC} -eq 0 ]; then
# workspace directory is same as EDK2 repo
EDK2_DIR="${WORKSPACE_DIR}"
else
# workspace directory contains EDK2 and LIBC repos
mkdir ${WORKSPACE_DIR}
if [ $? -ne 0 ]; then
print_err "Failed to create directory: ${WORKSPACE_DIR}"
exit 1
fi
cd ${WORKSPACE_DIR}
EDK2_DIR="${WORKSPACE_DIR}/$(basename ${EDK2_REPO_URL} .git)"
fi
echo "-------------------------------------------"
echo "WORKSPACE_FOLDER = ${WORKSPACE_FOLDER}"
echo
echo "PARENT_DIR = ${PARENT_DIR}"
echo "WORKSPACE_DIR = ${WORKSPACE_DIR}"
echo "EDK2_DIR = ${EDK2_DIR}"
echo "-------------------------------------------"
# clone EDK2 repo
print_info "Cloning EDK2 ${TAG}"
git clone ${CLONE_OPTS} ${EDK2_REPO_URL} ${EDK2_DIR}
if [ $? -ne 0 ]; then
print_err "Failed to clone repo"
exit 1
fi
# clone EDK2-LIBC repo
if [ ${LIBC} -eq 1 ]; then
print_info "Cloning EDK2-LIBC ${TAG}"
git clone ${CLONE_OPTS} ${LIBC_REPO_URL}
if [ $? -ne 0 ]; then
print_err "Failed to clone repo"
exit 1
fi
fi
# switch to EDK2 repo directory
cd ${EDK2_DIR}
# initialise EDK2 submodules
print_info "Initialise EDK2 Submodules"
git submodule update --init
if [ $? -ne 0 ]; then
print_err "Failed to initialise submodules"
exit 1
fi
# build BaseTools
print_info "Build BaseTools"
make -C BaseTools
if [ $? -ne 0 ]; then
print_err "Failed to build BaseTools"
exit 1
fi
# initialise EDK2 configuration
print_info "Initialise EDK2 Configuration"
cd ${WORKSPACE_DIR}
unset WORKSPACE
unset PACKAGES_PATH
unset EDK_TOOLS_PATH
unset CONF_PATH
if [ ${LIBC} -eq 0 ]; then
source ./${EDK2_SETUP_FILENAME} --reconfig
else
export WORKSPACE=${WORKSPACE_DIR}
export PACKAGES_PATH="${WORKSPACE}/edk2-libc:${WORKSPACE}/edk2"
export EDK_TOOLS_PATH="${WORKSPACE}/edk2/BaseTools"
source ./edk2/${EDK2_SETUP_FILENAME} --reconfig
fi
export EDK2_LIBC=${LIBC}
FILE="${CONF_PATH}/${EDK2_CONFIG_FILENAME}"
set_var ${FILE} ACTIVE_PLATFORM ShellPkg/ShellPkg.dsc
set_var ${FILE} TARGET DEBUG
set_var ${FILE} TARGET_ARCH X64
if [ ${CLANG} -eq 1 ]; then
set_var ${FILE} TOOL_CHAIN_TAG CLANGPDB
else
set_var ${FILE} TOOL_CHAIN_TAG GCC5
fi
# create script to initialise environment in root of workspace
print_info "Creating: ${EDKINIT_FILENAME}"
if [ ${LIBC} -eq 0 ]; then
DEV_ENV="EDK2"
SETUP_SCRIPT="\${WORKSPACE_DIR}/${EDK2_SETUP_FILENAME}"
else
DEV_ENV="EDK2+LIBC"
SETUP_SCRIPT="\${WORKSPACE_DIR}/edk2/${EDK2_SETUP_FILENAME}"
fi
######################################
cat << EOF_SCRIPT > ${EDKINIT_FILENAME}
#!/bin/bash
################################################################################
#
# EDK2 Utility Scripts
#
# Script to initialise ${DEV_ENV} development environment
#
# Created: $(date)
#
# Author: David Petroivc
#
################################################################################
INIT_SCRIPTS="${EDK2_SCRIPTS}/initscripts.sh"
WORKSPACE_DIR="${WORKSPACE_DIR}"
# check if script sourced
if [ "\${BASH_SOURCE[0]}" == "\${0}" ]; then
cat <<EOF
Script to initialise ${DEV_ENV} development environment
Usage: source ./edkinit.sh
EOF
echo -e " \033[97;41mNote that script must be \"sourced\" not merely executed!\033[0m" >&2
echo
exit 1
fi
# initialise EDK2 Utility scripts
if [ -f "\${INIT_SCRIPTS}" ]; then
source \${INIT_SCRIPTS}
# initialise EDK2 build enviroment
if [ -f "${SETUP_SCRIPT}" ]; then
pushd \${WORKSPACE_DIR} # > /dev/null 2>&1
EOF_SCRIPT
######################################
# EDK2
if [ ${LIBC} -eq 0 ]; then
cat << EOF_SCRIPT >> ${EDKINIT_FILENAME}
unset WORKSPACE
unset PACKAGES_PATH
unset EDK_TOOLS_PATH
unset CONF_PATH
EOF_SCRIPT
else
######################################
# EDK2+LIBC
cat << EOF_SCRIPT >> ${EDKINIT_FILENAME}
export WORKSPACE=\${PWD}
export PACKAGES_PATH="\${WORKSPACE}/edk2-libc:\${WORKSPACE}/edk2"
unset EDK_TOOLS_PATH
unset CONF_PATH
EOF_SCRIPT
fi
######################################
cat << EOF_SCRIPT >> ${EDKINIT_FILENAME}
source ${SETUP_SCRIPT}
export EDK2_LIBC=${LIBC}
popd # > /dev/null 2>&1
else
echo -e "\033[97;41m[ERROR] EDK2 Setup script not found: ${SETUP_SCRIPT}\033[0m" >&2
fi
else
echo -e "\033[97;41m[ERROR] EDK2 Utility script not found: \${INIT_SCRIPTS}\033[0m" >&2
fi
unset INIT_SCRIPTS
EOF_SCRIPT
######################################
chmod +x ${EDKINIT_FILENAME}
END_SECONDS=$(date +%s)
print_info "Elapsed time $(get_elapsed_time ${START_SECONDS} ${END_SECONDS})"
print_info "EDK2 Info"
edkinfo.sh
# prompt to setup environment
print_info "Run 'source ${EDKINIT_FILENAME}' from workspace directory to setup environment"
exit 0