summaryrefslogtreecommitdiff
path: root/uefi.sh
blob: cce5b9b53c95010ff26cfe826221bf9874cdff7c (plain)
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
#!/bin/bash
# Script used by CI to build UEFI for various boards
# Requirements: uuid-dev package

set -e

if [ -z "${WORKSPACE}" ]; then
  # Local build
  export WORKSPACE=`pwd`
  export BUILD_NUMBER=0
  export JOB_NAME=${JOB_NAME:-linaro-edk2}
fi

atf_version=v1.2

repo=linaro-edk2
pkg_repository=git://git.linaro.org/uefi/${repo}.git

case "${JOB_NAME}" in
  linaro-edk2)
    branch=release
    RELEASE_SUFFIX=
    ;;
  linaro-edk2-prep)
    branch=release-prep
    RELEASE_SUFFIX=-prep
    ;;
esac

pkg_source=edk2-${JOB_NAME}

if [ "${BUILD_NUMBER}" -eq 0 ]; then
  rm -rf ${repo}
fi

#
# Check out linaro-edk2 sources
#
if [ ! -d ${repo} ]; then
  echo "Cloning ${repo}-${branch}"
  git clone --depth 1 ${pkg_repository} -b ${branch}
else
  echo "${repo} already exists; cleaning..."
  pushd ${repo}
  git clean -dfx
  git fetch origin
  git branch -D ${branch} || true
  git checkout --track origin/${branch}
  popd
fi

if [ -f ${repo}/.gitmodules ]; then
  pushd ${repo}
  if [ ! -d .git/modules ]; then
    git submodule init
  fi
  git submodule update
  popd
fi

#
# Check out arm-trusted-firmware - at a locked-down known-good version
#
atf_dir=arm-trusted-firmware
atf_repo=https://github.com/ARM-software/arm-trusted-firmware.git
if [ ! -d ${atf_dir} ]; then
  echo "Cloning ${atf_dir}"
  git clone ${atf_repo}
  pushd ${atf_dir}
  git checkout -b ${atf_version} ${atf_version}
  popd
else
  echo "${atf_dir} already exists; cleaning..."
  pushd ${atf_dir}
  git clean -dfx
  git fetch origin
  git reset --hard HEAD
  git checkout master
  git branch -D ${atf_version} || true
  git checkout -b ${atf_version} ${atf_version}
  popd
fi

scm_commit=`cd ${repo} && git log -n1 --pretty=format:%h`
if [ -z "${scm_commit}" ]; then
  echo "Invalid git revision: ${scm_commit}" >&2
  exit 1
fi

base_version=0.1
pkg_version=${base_version}+git${BUILD_NUMBER}+`date +%Y%m%d`+${scm_commit}
pkg_dir=${pkg_source}-${pkg_version}

unset ARCH
export builddir=${WORKSPACE}/${JOB_NAME}-build
export EDK2_DIR=${WORKSPACE}/${repo}

rm -rf ${builddir} && mkdir -p ${builddir}

# Create source tarball
cd ${EDK2_DIR}
git checkout ${branch}
tar cjf ${pkg_source}_${pkg_version}.orig.tar.bz2 --transform "s,^,${pkg_dir}/," --exclude .git * .??*
mv ${pkg_source}_${pkg_version}.orig.tar.bz2 ${builddir}
cd ${WORKSPACE}

# Get the UEFI tools
UEFI_TOOLS_DIR=${WORKSPACE}/uefi-tools
if [ ! -d ${UEFI_TOOLS_DIR} ]; then
  git clone git://git.linaro.org/uefi/uefi-tools.git
else
  git --git-dir=${UEFI_TOOLS_DIR}/.git pull
fi

if [ "$AARCH32_TOOLCHAIN" == "" ]; then
  gcc_version=$(${CROSS_COMPILE}gcc -dumpversion)
  case $gcc_version in
  4.6|4.7|4.8)
    AARCH32_TOOLCHAIN=GCC$(echo ${gcc_version} | sed s-\\.--g)
    echo "Set AARCH32_TOOLCHAIN to ${AARCH32_TOOLCHAIN}"
    ;;
  *)
    echo "Unknown toolchain version '$gcc_version'" >&2
    echo "Attempting to build using GCC48 profile." >&2
    AARCH32_TOOLCHAIN=GCC48
    ;;
  esac
fi
if [ "$AARCH64_TOOLCHAIN" == "" ]; then
  gcc_version=$(aarch64-linux-gnu-gcc -dumpversion)
  case $gcc_version in
  4.6|4.7|4.8)
    AARCH64_TOOLCHAIN=GCC$(echo ${gcc_version} | sed s-\\.--g)
    echo "Set AARCH64_TOOLCHAIN to ${AARCH64_TOOLCHAIN}"
    ;;
  *)
    echo "Unknown AArch64 toolchain version '$gcc_version'" >&2
    echo "Attempting to build using GCC48 profile." >&2
    AARCH64_TOOLCHAIN=GCC48
    ;;
  esac
fi

# disable exit on error
set +e

#
# Fix WORKSPACE environment variable conflict with Jenkins
# (Store Jenkins value before first edk2/SCT build step.)
#
JENKINS_WORKSPACE=${WORKSPACE}
unset WORKSPACE

cd ${EDK2_DIR}
# Extract release version
RELEASE_STRING=linaro-edk2-`git rev-parse --symbolic --tags="tianocore-edk2-*" | sort | cut -d- -f3 | tail -1`${RELEASE_SUFFIX}

# Extract platforms to build, and build EDK2
platforms="`${UEFI_TOOLS_DIR}/parse-platforms.py -c LinaroPkg/platforms.config list`"
${UEFI_TOOLS_DIR}/uefi-build.sh -c LinaroPkg/platforms.config -b RELEASE -b DEBUG -a ../$atf_dir -D FIRMWARE_VER=${RELEASE_STRING} $platforms

for platform in $platforms; do
  BUILD_ATF="`${UEFI_TOOLS_DIR}/parse-platforms.py -c LinaroPkg/platforms.config -p $platform -o BUILD_ATF get`"
  IMAGES="`${UEFI_TOOLS_DIR}/parse-platforms.py -c LinaroPkg/platforms.config -p $platform images`"
  IMAGE_DIR="`${UEFI_TOOLS_DIR}/parse-platforms.py -c LinaroPkg/platforms.config -p $platform -o UEFI_IMAGE_DIR get`"
  DEBUG_DIR="${builddir}/debug/${platform}/"
  RELEASE_DIR="${builddir}/release/${platform}/"
  mkdir -p "$DEBUG_DIR" "$RELEASE_DIR"
  echo "Copying images for platform '$platform':"
  for image in $IMAGES; do
    cp "$EDK2_DIR"/Build/"$IMAGE_DIR"/RELEASE_*/FV/"$image" "$RELEASE_DIR"
    cp "$EDK2_DIR"/Build/"$IMAGE_DIR"/DEBUG_*/FV/"$image" "$DEBUG_DIR"
    echo -e "\t`basename $image`"
  done
done

SCT=${SCT:-0}
if [ "${SCT}" -ne 0 ]; then
  git clone --depth 1 ssh://git@dev-private-git.linaro.org/people/heyi.guo/UEFI-SCT.git ${EDK2_DIR}/SctPkg

  export ${AARCH32_TOOLCHAIN}_ARM_PREFIX=arm-linux-gnueabihf-
  export ${AARCH64_TOOLCHAIN}_AARCH64_PREFIX=aarch64-linux-gnu-

  for sct_target_arch in ARM AARCH64; do
    for sct_build in DEBUG RELEASE; do
      cd ${EDK2_DIR}
      ./SctPkg/build.sh ${sct_target_arch} ${AARCH32_TOOLCHAIN} ${sct_build}
      tar -C ${EDK2_DIR}/Build/UefiSct/${sct_build}_${AARCH32_TOOLCHAIN} \
        -cjf ${builddir}/$(echo ${sct_build} | tr '[:upper:]' '[:lower:]')/SctPackage${sct_target_arch}.tar.bz2 \
        SctPackage${sct_target_arch}
    done
  done

  rm -rf ${EDK2_DIR}/SctPkg
fi

#
# Fix WORKSPACE environment variable conflict with Jenkins
# (Restore Jenkins value after last edk2/SCT build step.)
#
unset WORKSPACE
export WORKSPACE=${JENKINS_WORKSPACE}

# We want to return 0 if something built so that the files get copied to snapshots.linaro.org
exit 0