summaryrefslogtreecommitdiff
path: root/build.sh
blob: 8ca6ee6f23f3e8c75f6736ce49746f8bc39ba954 (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
#!/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=ccd0c24cf89cb2195cbb38b6bb0639769afef7c5
EDK2_HASH=496cf19ac262dcc37a60652b535d725652947f3b
EDK2_PLATFORMS_HASH=563c2efbfa0580f4a1efee368cfc77d27bf33a1f
EDK2_NON_OSI_HASH=5f76141f299780cb3a64f007126261c6c3157d75
UEFI_TOOLS_HASH=42eac07beb4da42a182d2a87d6b2e928fc9a31cf

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
    fi
}

patch_repo()
{
    PATCH_DIR="$PWD/patches"
    TARGET_DIR="$PWD/$1"
    if [ ! -d "patches/$1" ]; then
        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
    done
    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`"
        DEBUG_DIR="$PWD/out/debug/$platform/"
        RELEASE_DIR="$PWD/out/release/$platform/"
        echo "Copying images for platform '$platform':"

        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
    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