summaryrefslogtreecommitdiffstats
path: root/resources/scripts/helpers/build/module/coreboot
blob: 84884514bf6ff9c3bf3b16a80d4119dca3de5868 (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
#!/bin/bash

#  helper script: builds the dependencies that coreboot needs before building a ROM image
#
#	Copyright (C) 2014, 2015, 2016 Minifree Ltd <info@minifree.org>
#	Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# This script assumes that the working directory is the root
# of git or release archive

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

# Build utilities needed in coreboot directory
# --------------------------------------------------------------------

printf "Building the utilities in coreboot\n"

for payloads in resources/libreboot/config/*; do

	if [ ! -d "${payloads}/" ]; then
		continue
	fi

	payload="${payloads##*/}"

	for boardconfig in resources/libreboot/config/${payload}/*; do

		if [ ! -d "${boardconfig}/" ]; then
			continue
		fi

		boardname="${boardconfig##*/}"
		cbrevision=$(cat "${boardconfig}/cbrevision")
		vbootrevision=$(cat "${boardconfig}/vbootrevision")

		reused_coreboot_patches="resources/libreboot/patch/coreboot/${cbrevision}/${payload}/${boardname}/reused.list"
		reused_vboot_patches="resources/libreboot/patch/vboot/${vbootrevision}/${payload}/${boardname}/reused.list"
		for reused_patches in "${reused_coreboot_patches}" "${reused_vboot_patches}"; do
			if [ -f "${reused_patches}" ]; then
				for patch in $(cat "${reused_patches}"); do
					if [ ! -f "./${patch}" ]; then
						printf "%s listed in %s does not exist\n" "${patch}" "${reused_patches}"
						exit 1
					fi
				done
			fi
		done

	done
done

# sanity check (check for invalid paths in the reused.list patch lists before proceeding)
# in ascending filename order, apply patches from a directory
apply_patches_from_directory() {
	patch_directory="${1}" # directory containing the patch files

	if [ -d "${patch_directory}" ]; then
		for patch in ${patch_directory}/*.patch;  do

			if [ "${patch##*/}" = "*.patch" ]; then # oh so ugly
				continue # ugly ugly ugly ugly ugly
			fi # most hideous thing you've ever seen

			git am "${patch}" || return 1
		done
	fi
}
# files listed in the file (if found) are absolute paths, relative to the root of the libreboot src directory
# the file lists patches patches that should be applied
apply_patches_from_file() {
	patch_list="${1}" # file listing the paths to all the patches
	libreboot_src_root="${2}" # path to the root of the libreboot_src directory

	if [ -f "${patch_list}" ]; then
		for patchname in $(cat "${patch_list}"); do
			git am "${libreboot_src_root}/${patchname}" || return 1
		done
	fi
}

create_branch() {
	branchname="${1}"
    git branch ${branchname}
    git checkout ${branchname}
    git checkout master
}

# use git-init on everything
# this is so that we can then apply patche
# for these revisions of vboot and coreboot
for i in coreboot/*; do
    if [ ! -d "${i}/" ]; then
        continue
    fi
    for revision in ${i}/*; do
        if [ ! -d "${revision}/" ]; then
            continue
        fi
        (
        cd "${revision}/"
        git init
        git add -A .
        git commit -m "coreboot revision ${revision##*/}"
        cd "3rdparty/vboot/"
        git init
        git add -A .
        git commit -m "coreboot revision ${revision##*/}"
        )
    done
done

for payloads in resources/libreboot/config/*; do

	if [ ! -d "${payloads}/" ]; then
		continue
	fi

	payload="${payloads##*/}"

	for boardconfig in resources/libreboot/config/${payload}/*; do

		if [ ! -d "${boardconfig}/" ]; then
			continue
		fi

		boardname="${boardconfig##*/}"
		cbrevision=$(cat "${boardconfig}/cbrevision")
		vbootrevision=$(cat "${boardconfig}/vbootrevision")
        branchname="${payload}_${boardname}"

        # the same vboot revision is always used for coreboot revision,
        # so we don't need to wworry about checking for that here

		# patch that version
		(

			cd "coreboot/${cbrevision}/${cbrevision}/"
			create_branch ${branchname}

            git checkout ${branchname}

			# apply patches (coreboot, common to all systems using this revision)
			apply_patches_from_directory "../../../resources/libreboot/patch/common/coreboot/${cbrevision}"
			# apply patches re-used from other boards, before applying main patches (common patches for similar boards)
			apply_patches_from_file "../../../resources/libreboot/patch/coreboot/${cbrevision}/${payload}/${boardname}/reused.list" ../../..
			# apply patches (coreboot, machine-specific for this revision)
			apply_patches_from_directory "../../../resources/libreboot/patch/coreboot/${cbrevision}/${payload}/${boardname}"

            git checkout master

			cd "3rdparty/vboot/"
			# reset to known revision (vboot)
			create_branch ${branchname}

            git checkout ${branchname}

			# apply patches (vboot, common to all systems using this revision)
			apply_patches_from_directory "../../../../../resources/libreboot/patch/common/vboot/${vbootrevision}"
			# apply patches re-used from other boards, before applying main patches (common patches for similar boards)
			apply_patches_from_file "../../../../../resources/libreboot/patch/vboot/${vbootrevision}/${payload}/${boardname}/reused.list" ../../../../..
			# apply patches (vboot, machine-specific for this revision)
			apply_patches_from_directory "../../../../../resources/libreboot/patch/vboot/${vbootrevision}/${payload}/${boardname}"

            git checkout master

		)
	done
done

# build coreboot utilities (in each revision) and
# create symlinks to the crossgcc archive
for payload in coreboot/*; do
	for board in "${payload}/"*; do

	# cbfstool, cbmem, nvramtool
	for util in {cbfs,nvram}tool cbmem; do
		make -BC "${board}/util/${util}"
	done
	# create symlink to crossgcc
	(
	cd "${board}/util/"
	ln -s "../../../../crossgcc/util/crossgcc/" crossgcc
	)

	done
done