summaryrefslogtreecommitdiff
path: root/build.sh
blob: 5bc744299ab3b1c513dd250531f5e7f0f9ef17c2 (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
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash

CONFIG_OPTIONS="-c platforms.config"
BUILD_OPTIONS="$CONFIG_OPTIONS -b DEBUG -b RELEASE"

ARM_TF_REPO=https://github.com/ARM-software/arm-trusted-firmware.git
EDK2_REPO=https://github.com/tianocore/edk2.git
EDK2_PLATFORMS_REPO=https://github.com/tianocore/edk2-platforms.git
EDK2_NON_OSI_REPO=https://github.com/tianocore/edk2-non-osi.git
UEFI_TOOLS_REPO=https://git.linaro.org/uefi/uefi-tools.git

ARM_TF_HASH=9fd2f13bd608832260300640970f73c62357c684
EDK2_HASH=edk2-stable201903
EDK2_PLATFORMS_HASH=89f6901df0e29da6619608dc417c052bb3e8f82a
EDK2_NON_OSI_HASH=99907896565e9b9d6fa508e54b2840db3f0280fc
UEFI_TOOLS_HASH=27207a83aefc88526466fb2dcba50470cb92974d

config_git()
{
    git config --global user.name >/dev/null
    if [ $? -ne 0 ]; then
        git config --global user.name "Linaro Buildbot"
    fi

    git config --global user.email >/dev/null
    if [ $? -ne 0 ]; then
        git config --global user.email "nobody@linaro.org"
    fi
}

REPO_ORIGIN=
REPO_HASH=
set_current_repo()
{
    case $1 in
	arm-trusted-firmware)
	    REPO_ORIGIN=$ARM_TF_REPO
	    REPO_HASH=$ARM_TF_HASH
	;;
	edk2)
	    REPO_ORIGIN=$EDK2_REPO
	    REPO_HASH=$EDK2_HASH
	;;
	edk2-platforms)
	    REPO_ORIGIN=$EDK2_PLATFORMS_REPO
	    REPO_HASH=$EDK2_PLATFORMS_HASH
	;;
	edk2-non-osi)
	    REPO_ORIGIN=$EDK2_NON_OSI_REPO
	    REPO_HASH=$EDK2_NON_OSI_HASH
	;;
	uefi-tools)
	    REPO_ORIGIN=$UEFI_TOOLS_REPO
	    REPO_HASH=$UEFI_TOOLS_HASH
	;;
	*)
	    echo "Invalid repository '$1'" >&2
	    exit 1
	;;
    esac

    echo REPO_ORIGIN=$REPO_ORIGIN
    echo REPO_HASH=$REPO_HASH
}

update_repo()
{
    set_current_repo $1

    cd $1

    CURRENT_ORIGIN=`git config --get remote.origin.url`
    if [ $REPO_ORIGIN != $CURRENT_ORIGIN ]; then
	echo "Existing checkout of '$1' has unexpected origin '$REPO_ORIGIN'" >&2
	exit 1
    fi

    git checkout master
    [ $? -ne 0 ] && echo "Failed to check out master branch!" >&2 && exit 1

    git fetch origin
    [ $? -ne 0 ] && echo "Failed to fetch from '$CURRENT_ORIGIN'!" >&2 && exit 1

    git reset --hard $REPO_HASH
    [ $? -ne 0 ] && echo "Failed to reset '$1' to '$REPO_HASH'!" >&2 && exit 1

    cd -
}

clone_repo()
{
    set_current_repo $1

    echo git clone $REPO_ORIGIN
    git clone $REPO_ORIGIN

    cd $1
    git reset --hard $REPO_HASH
    [ $? -ne 0 ] && echo "Failed to reset '$1' to '$REPO_HASH'!" >&2 && exit 1
    cd -
}

get_repo()
{
    TARGET_DIR=$1
    if [ -d $TARGET_DIR ]; then
        update_repo $TARGET_DIR
    else
        clone_repo $TARGET_DIR
        git -C $TARGET_DIR submodule init
    fi
    git -C $TARGET_DIR submodule update
}

patch_repo()
{
    PATCH_DIR="$PWD/patches"
    TARGET_DIR="$PWD/$1"
    if [ ! -d "patches/$1" ]; then
        git rev-parse HEAD
        return
    fi

    echo "Patching '$1'"
    cd $TARGET_DIR
    for file in "$PATCH_DIR"/"$1"/*.patch; do
        echo git am --keep-cr $file
        git am --keep-cr $file
        [ $? -eq 0 ] || exit 1
    done
    git rev-parse HEAD
    cd -
}

build_all()
{
    echo ./uefi-tools/edk2-build.sh $BUILD_OPTIONS all
    ./uefi-tools/edk2-build.sh $BUILD_OPTIONS all
}

copy_images()
{
    EDK2_NON_OSI_DIR=`readlink -f edk2-non-osi`  # Used in expansion of $IMAGES below

    PLATFORMS=`uefi-tools/parse-platforms.py $CONFIG_OPTIONS list`
    for platform in $PLATFORMS; do
        echo PLATFORM=$platform
        IMAGE_DIR="`uefi-tools/parse-platforms.py $CONFIG_OPTIONS -p $platform -o UEFI_IMAGE_DIR get`"
        IMAGES="`uefi-tools/parse-platforms.py $CONFIG_OPTIONS -p $platform images`"
        EXECUTABLES="`uefi-tools/parse-platforms.py $CONFIG_OPTIONS -p $platform executables`"
        DEBUG_DIR="$PWD/out/debug/$platform/"
        RELEASE_DIR="$PWD/out/release/$platform/"
        echo "Copying images for platform '$platform':"

        if [ -n "$IMAGES" ]; then
            pushd Build/$IMAGE_DIR/RELEASE_*/FV/ >/dev/null 2>&1
            if [ $? -eq 0 ]; then
                mkdir -p "$RELEASE_DIR"
                cp `eval echo $IMAGES` $RELEASE_DIR
                popd >/dev/null
            fi

            pushd Build/$IMAGE_DIR/DEBUG_*/FV/ >/dev/null 2>&1
            if [ $? -eq 0 ]; then
                mkdir -p "$DEBUG_DIR"
                cp `eval echo $IMAGES` $DEBUG_DIR
                popd >/dev/null
            fi
        fi
        if [ -n "$EXECUTABLES" ]; then
            pushd Build/$IMAGE_DIR/RELEASE_*/ >/dev/null 2>&1
            if [ $? -eq 0 ]; then
                mkdir -p "$RELEASE_DIR"
                cp `eval echo $EXECUTABLES` $RELEASE_DIR
                popd >/dev/null
            fi

            pushd Build/$IMAGE_DIR/DEBUG_*/ >/dev/null 2>&1
            if [ $? -eq 0 ]; then
                mkdir -p "$DEBUG_DIR"
                cp `eval echo $EXECUTABLES` $DEBUG_DIR
                popd >/dev/null
            fi
        fi
    done
}

checksum_images()
{
    for dir in out/*/*; do
        cd $dir
        sha256sum * > SHA256SUMS
        cd - >/dev/null
    done
}

BUILD_OPTIONS="$BUILD_OPTIONS $*"

config_git

for repo in arm-trusted-firmware edk2 edk2-platforms edk2-non-osi uefi-tools
do
    echo "$repo"
    get_repo $repo
    patch_repo $repo
done

rm -rf Build

NUM_PLATFORMS=`uefi-tools/parse-platforms.py $CONFIG_OPTIONS list | wc -l`
NUM_BUILDS=$(($NUM_PLATFORMS * 2))
build_all
NUM_FAILED=$?

if [ $NUM_FAILED -lt $NUM_BUILDS ]; then
    copy_images
    checksum_images
fi