blob: 359d5725d3bb7f419e5aebbd3a396d7f75a30a48 (
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
|
#!/usr/bin/env sh
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (c) 2014-2016,2020-2021,2023-2024 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2021-2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# Copyright (c) 2022-2023 Alper Nebi Yasak <alpernebiyasak@gmail.com>
# Copyright (c) 2023 Riku Viitanen <riku.viitanen@protonmail.com>
set -u -e
. "include/lib.sh"
tmprom="$TMPDIR/rom"
seavgabiosrom="elf/seabios/default/libgfxinit/vgabios.bin"
cfgsdir="config/coreboot"
rp2040src="src/pico-serprog"
rp2040x="$rp2040src/build/pico_serprog.uf2"
picosdk="src/pico-sdk"
rp2040dir="$picosdk/src/boards/include/boards"
stm32src="src/stm32-vserprog"
stm32x="$stm32src/stm32-vserprog.hex"
stm32dir="$stm32src/boards"
# Disable all payloads by default.
# target.cfg files have to specifically enable [a] payload(s)
pv="payload_uboot payload_seabios payload_memtest payload_grub"
v="romdir initmode displaymode targetdir tree release ubootelf"
v="$v board grub_scan_disk uboot_config grubtree grubelf tmpmv"
eval `setvars "n" $pv`
eval `setvars "" $v boards targets serdir ser`
main()
{
while [ $# -gt 0 ]; do
if [ "$1" = "serprog" ]; then
[ $# -lt 2 ] && $err "serprog type not set"
[ "$2" != "rp2040" ] && [ "$2" != "stm32" ] && \
$err "invalid serprog type"
eval "x_ ./update trees -f \"\${${2}src##*/}\""
ser="$2" && shift 2 && continue
fi
[ "$1$ser" = "list" ] && x_ ls -1 config/coreboot && return 0
[ "$1" = "all" ] && shift 1 && continue
boards="$1 $boards"; shift 1
done
[ -n "$boards" ] || [ -n "$ser" ] || boards="$(ls -1 \
config/coreboot)" || $err "can't list coreboot boards"
[ -n "$ser" ] && \
eval "serlist \"\$${ser}dir\" > \"\$TMPDIR/ser\" || $err \"!ser\""
[ -n "$ser" ] && [ -z "$boards" ] && boards="$(cat "$TMPDIR/ser")"
for x in $boards; do
[ -n "$ser" ] && mkserprogfw "$ser" "$x"
[ -z "$ser" ] && [ -d "config/coreboot/$x/config" ] && \
configure_target "$x" && build_roms && \
[ -d "bin/$board" ] && targets="$targets, $x" && \
[ "$XBMK_RELEASE" = "y" ] && mkrom_tarball "bin/$x"
done
[ -n "$ser" ] && [ "$XBMK_RELEASE" = "y" ] && \
mkrom_tarball "bin/serprog_$ser" && return 0
[ -z "$ser" ] && [ -z "$targets" ] && $err "No images were compiled"
[ -z "$ser" ] && printf "ROMs built in bin/ for: %s\n" "${targets#, }"
[ -n "$ser" ] && printf "ROMs (serprog) built in bin/%s/\n" "$ser"
printf "Please flash from bin/, NOT elf/ - ALSO:\n%s\n" "$kbnotice"
}
mkserprogfw()
{
x_ mkdir -p "bin/serprog_$1"
[ "$1" = "rp2040" ] && x_ cmake -DPICO_BOARD="$2" \
-DPICO_SDK_PATH="$picosdk" -B "$rp2040src/build" "$rp2040src" && \
x_ cmake --build "$rp2040src/build"
[ "$1" = "stm32" ] && x_ make -C "$stm32src" libopencm3-just-make \
BOARD=$2 && x_ make -C "$stm32src" BOARD=$2
eval "x_ mv \"\$${1}x\" \"bin/serprog_$1/serprog_$2.\${${1}x##*.}\""
}
serlist()
{
basename -a -s .h "$1/"*.h || $err "$1: can't list boards"
}
configure_target()
{
eval `setvars "n" $pv`
eval `setvars "" $v`
board="$1"; targetdir="$cfgsdir/$board"; romdir="bin/$board"
# Override the above defaults using target.cfg
eval `setcfg "$targetdir/target.cfg"`
[ -z "$tree" ] && $err "$board: tree not defined"
[ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && return 1
[ "$board" = "$tree" ] && return 1
x_ ./update trees -b coreboot $board
cbfstool="elf/cbfstool/$tree/cbfstool"
x_ ./update trees -b coreboot utils $tree
[ -n "$uboot_config" ] || uboot_config="default"
[ "$payload_uboot" = "y" ] || payload_seabios="y"
[ "$payload_grub" = "y" ] && payload_seabios="y"
[ "$payload_seabios" = "y" ] && [ -n "$payload_uboot" = "y" ] && \
$err "$board: U-Boot and SeaBIOS/GRUB are both enabled."
[ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
[ -n "$grubtree" ] || grubtree="default"
grubelf="elf/grub/$grubtree/payload/grub.elf"
[ "$payload_memtest" = "y" ] || payload_memtest="n"
[ "$(uname -m)" = "x86_64" ] || payload_memtest="n"; return 0
}
build_roms()
{
x_ rm -Rf "$romdir"
for cbcfg in "$targetdir/config/"*; do
[ -f "$cbcfg" ] || continue; cn="${cbcfg##*/}"; dt="${cn#*_}" \
&& [ "$dt" = "$cn" ] && dt="txtmode"; displaymode="$dt"
initmode="${cn%%_*}"; chkvars initmode displaymode
e "$cbcfg" f not || add_payloads
done; x_ rm -f "$tmprom"
}
add_payloads()
{
cbuild="$cbelfdir/$board/${initmode}_$displaymode"
[ "$initmode" = "normal" ] && cbuild="${cbuild%"_$displaymode"}"
x_ cp "$cbuild/coreboot.rom" "$tmprom"
[ "$payload_seabios" = "y" ] && add_seabios_payload
[ "$payload_uboot" = "y" ] || return 0
# add u-boot payload
x_ ./update trees -b u-boot $board
ubdir="elf/u-boot/$board/$uboot_config"; ubootelf="$ubdir/u-boot.elf" \
&& [ ! -f "$ubootelf" ] && ubootelf="$ubdir/u-boot"
[ -f "$ubootelf" ] || $err "$board: Can't find u-boot"
cbfs "$tmprom" "$ubootelf" "fallback/payload"
cprom "$romdir/uboot_payload_${board}_${initmode}_$displaymode.rom"
}
add_seabios_payload()
{
_seabioself="elf/seabios/default/$initmode/bios.bin.elf"
x_ ./update trees -b seabios
pstr="seabios" && [ "$payload_grub" = "y" ] && pstr="seabios_withgrub"
newrom="$romdir/${pstr}_${board}_$initmode.rom"
[ "$initmode" = "normal" ] || newrom="${newrom%.rom}_$displaymode.rom"
cbfs "$tmprom" "$_seabioself" "fallback/payload"
x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
z="2"; [ "$initmode" = "vgarom" ] && z="0"
x_ "$cbfstool" "$tmprom" add-int -i $z -n etc/pci-optionrom-exec
x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum
[ "$initmode" = "libgfxinit" ] && cbfs "$tmprom" "$seavgabiosrom" \
vgaroms/seavgabios.bin raw
if [ "$payload_grub" = "y" ]; then
x_ ./update trees -b grub $grubtree
cbfs "$tmprom" "$grubelf" "img/grub2"
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
> "$TMPDIR/tmpcfg" || $err "$board: !insert scandisk"
cbfs "$tmprom" "$TMPDIR/tmpcfg" scan.cfg raw
fi
[ "$payload_memtest" = "y" ] && x_ ./update trees -b memtest86plus && \
cbfs "$tmprom" "elf/memtest86plus/memtest.bin" img/memtest
cprom "$newrom" && [ "$payload_grub" = "y" ] && \
cbfs "$tmprom" "$grubdata/bootorder" bootorder raw && \
cprom "${newrom%.rom}_grubfirst.rom"; return 0
}
cprom()
{
x_ mkdir -p "${1%/*}"; x_ cp "$tmprom" "$1"
[ "$XBMK_RELEASE" = "y" ] && mksha512sum "$1" "vendorhashes" && \
x_ ./vendor inject -r "$1" -b "$board" -n nuke; return 0
}
main $@
|