summaryrefslogtreecommitdiff
path: root/include/rom.sh
blob: c0e5f8c5bbf59be0d40ef290bfd054dbefda655e (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
#!/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>

mkpayload_grub()
{
	eval `setvars "" grub_modules grub_install_modules`
	$dry eval `setcfg "$grubdata/module/$tree"`
	$dry x_ rm -f "$srcdir/grub.elf"; $dry \
	"$srcdir/grub-mkstandalone" --grub-mkimage="$srcdir/grub-mkimage" \
	    -O i386-coreboot -o "$srcdir/grub.elf" -d "${srcdir}/grub-core/" \
	    --fonts= --themes= --locales=  --modules="$grub_modules" \
	    --install-modules="$grub_install_modules" \
	    "/boot/grub/grub_default.cfg=${srcdir}/.config" \
	    "/boot/grub/grub.cfg=$grubdata/memdisk.cfg" \
	    "/background.png=$grubdata/background/background1280x800.png" || \
	    $err "$tree: cannot build grub.elf"; return 0
}

mkvendorfiles()
{
	check_cbfstool "$tree"; printf "69\n" > "$srcdir/.coreboot-version" \
	    || $err "!cbver $srcdir"; [ -z "$mode" ] && \
	    [ "$target" != "$tree" ] && x_ ./vendor download $target; return 0
}

check_cbfstool()
{
	[ "$badhash" = "n" ] || rm -f "elf/cbfstool/$1/cbfstool" || \
	    $err "!rm badelf elf/cbfstool/$1/cbfstool"
	e "elf/cbfstool/$1/cbfstool" f && return 0

	utilelfdir="elf/cbfstool/$1"
	utilsrcdir="src/coreboot/$1/util/cbfstool"

	utilmode="" && [ -n "$mode" ] && utilmode="clean"
	x_ make -C "$utilsrcdir" $utilmode -j$XBMK_THREADS $makeargs
	[ -z "$mode" ] && [ ! -f "$utilelfdir/cbfstool" ] && \
		x_ mkdir -p "$utilelfdir" && \
		x_ cp "$utilsrcdir/cbfstool" "elf/cbfstool/$1"
	[ -z "$mode" ] || x_ rm -Rf "$utilelfdir"; :
}

mkcorebootbin()
{
	[ "$target" = "$tree" ] && return 0

	tmprom="$srcdir/build/coreboot.rom"; initmode="${defconfig##*/}";
	displaymode="${initmode##*_}"; initmode="${initmode%%_*}"
	[ -n "$displaymode" ] && displaymode="_$displaymode"
	cbfstool="elf/cbfstool/$tree/cbfstool"

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

	pname="custom" && grep "CONFIG_PAYLOAD_NONE=y" "$defconfig" && \
	    pname="seabios"; $dry add_seabios

	newrom="bin/$target/${pname}_${target}_$initmode$displaymode.rom"
	$dry x_ mkdir -p "${newrom%/*}"; $dry x_ mv "$tmprom" "$newrom"
}

add_seabios()
{
	_seabioself="elf/seabios/default/$initmode/bios.bin.elf"

	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

	[ "$payload_memtest" = "y" ] && cbfs "$tmprom" \
	    "elf/memtest86plus/memtest.bin" img/memtest

	[ "$payload_grub" = "y" ] && pname="seagrub" && add_grub; return 0
}

add_grub()
{
	cbfs "$tmprom" "$grubelf" "img/grub2"
	printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
	    > "$TMPDIR/tmpcfg" || $err "$target: !insert scandisk"
	cbfs "$tmprom" "$TMPDIR/tmpcfg" scan.cfg raw
	cbfs "$tmprom" "$grubdata/bootorder" bootorder raw
}