Files
lbmk/include/rom.sh
Leah Rowe fb497cec3b BROKEN/WIP: NEW MAINBOARD: Lenovo ThinkCentre M920 Tiny
WARNING!!!!! i915 driver crashes when loading (KMS driver).
Could not use GRUB or SeaBIOS; SeaBIOS hangs and USB input
fails in GRUB. U-Boot UEFI works, you can boot things.
If you want to set upp a headless service this machine is
totally fine, because you can just avoid loading i915 in
Linux, and just use the EFI framebuffer or the coreboot
framebuffer, or possibly boot xorg with nomodeset.

DO NOT MERGE! This machine needs a lot work work.

Initial notes:

This should cover both the M920q and M920x, though the
x variant is quite rare.

This is a mITX desktop system, documented here:
https://doc.coreboot.org/mainboard/lenovo/m920q.html

Thanks go to Maciej Pijanowski, who ported coreboot to
this board and submitted the code upstream. Libreboot is
using the version that was recently merged upstream in
the coreboot project.

It's not yet known how to auto-download the ME, because the
update images are incomplete. The only reliable way thus far
is to extract the factory dump. However, it's also uncertain
what modules to whitelist in me_cleaner, so for this board, we
only:

* Unlock all IFD regions, setting them read-write
* Set the HAP bit, which is functionally equivalent to
  a valid me_cleaner setup

The result will be a disabled ME, and read-write operation.
No binary images will be provided for now, in releases. You
must also create the directory:

dump/m920q/

Then just extract from the factory dump using:

./ifdtool --platform cnl -x libreboot.rom

Then just stick the files that it creates into there, and
the build should work. I've made lbmk automatically set the
HAP bit and unlock regions, when building with these.

Also, SeaBIOS hung so I restored the possibility of using
GRUB as primary, but GRUB USB input also didn't work! The
board's port author tested edk2 only, it seems. I don't really
want edk2 in lbmk just for this board.

So, I made U-Boot the only payload. It seems to work fine.
However, Debian Linux and OpenBSD both seemed to completely fail:
On OpenBSD it had errors pertaining to i915 video driver.

Debian Linux stalled at startup just when it's switching to
KMS, which would use the i915 driver.

Arch Linux installer, same thing: uses KMS, and failed.

The port author said edk2 was tested. edk2 provides a decent
GOP implementation, so maybe they were using an EFI framebuffer
when booting Linux.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-12-03 14:52:53 +00:00

266 lines
8.8 KiB
Bash

# 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>
mkserprog()
{
[ "$_f" = "-d" ] && return 0 # dry run
basename -as .h "$serdir/"*.h > "$TMPDIR/ser" || $err "!mk $1 $TMPDIR"
while read -r sertarget; do
[ "$1" = "rp2040" ] && x_ cmake -DPICO_BOARD="$sertarget" \
-DPICO_SDK_PATH="$picosdk" -B "$sersrc/build" "$sersrc" \
&& x_ cmake --build "$sersrc/build"
[ "$1" = "stm32" ] && x_ make -C "$sersrc" \
libopencm3-just-make BOARD=$sertarget && x_ make -C \
"$sersrc" BOARD=$sertarget; x_ mkdir -p "bin/serprog_$1"
x_ mv "$serx" "bin/serprog_$1/serprog_$sertarget.${serx##*.}"
done < "$TMPDIR/ser"
[ "$XBMK_RELEASE" = "y" ] && mkrom_tarball "bin/serprog_$1"; return 0
}
copyps1bios()
{
x_ rm -Rf bin/playstation
x_ mkdir -p bin/playstation
x_ cp src/pcsx-redux/src/mips/openbios/openbios.bin bin/playstation
printf "MIT License\n\nCopyright (c) 2019-2024 PCSX-Redux authors\n\n" \
> bin/playstation/COPYING.txt || $err "!pcsx-redux copyright"
cat config/snippet/mit >>bin/playstation/COPYING.txt || $err "!pcsx MIT"
}
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()
{
[ -z "$mode" ] && $dry cook_coreboot_config
check_coreboot_utils "$tree"
printf "%s\n" "${version%%-*}" > "$srcdir/.coreboot-version" || \
$err "!mk $srcdir .coreboot-version"
[ -z "$mode" ] && [ "$target" != "$tree" ] && [ -n "$vcfg" ] && \
x_ ./vendor download $target; return 0
}
cook_coreboot_config()
{
[ -f "$srcdir/.config" ] || return 0
printf "CONFIG_CCACHE=y\n" >> "$srcdir/.config" || \
$err "$srcdir/.config: Could not enable ccache"
make -C "$srcdir" oldconfig || $err "Could not cook $srcdir/.config"; :
}
check_coreboot_utils()
{
for util in cbfstool ifdtool; do
[ "$badhash" = "y" ] && x_ rm -f "elf/$util/$1/$util"
e "elf/$util/$1/$util" f && continue
utilelfdir="elf/$util/$1"
utilsrcdir="src/coreboot/$1/util/$util"
utilmode="" && [ -n "$mode" ] && utilmode="clean"
x_ make -C "$utilsrcdir" $utilmode -j$XBMK_THREADS $makeargs
[ -z "$mode" ] && [ ! -f "$utilelfdir/$util" ] && \
x_ mkdir -p "$utilelfdir" && \
x_ cp "$utilsrcdir/$util" "elf/$util/$1"
[ -z "$mode" ] || x_ rm -Rf "$utilelfdir"; continue
done; return 0
}
mkcorebootbin()
{
[ "$target" = "$tree" ] && return 0
tmprom="$TMPDIR/coreboot.rom"
$dry x_ cp "$srcdir/build/coreboot.rom" "$tmprom"
initmode="${defconfig##*/}"; displaymode="${initmode##*_}"
[ "$displaymode" = "$initmode" ] && displaymode="" # "normal" config
initmode="${initmode%%_*}"
cbfstool="elf/cbfstool/$tree/cbfstool"
ifdtool="elf/ifdtool/$tree/ifdtool"
[ "$payload_uboot_i386" = "y" ] && \
[ "$payload_uboot_amd64" = "y" ] && \
$err "'$target' enables 32- and 64-bit x86 U-Boot"
if [ "$payload_uboot_i386" = "y" ] || \
[ "$payload_uboot_amd64" = "y" ]; then
printf "'$target' has x86 U-Boot; assuming SeaBIOS=y\n" 1>&2
payload_seabios="y"
fi
[ -n "$uboot_config" ] || uboot_config="default"
[ "$payload_uboot" = "y" ] || payload_seabios="y"
[ "$payload_grub" = "y" ] && payload_seabios="y"
[ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "y" ] && \
$dry $err "$target: U-Boot(arm64) and SeaBIOS/GRUB 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"
if $dry grep "CONFIG_PAYLOAD_NONE=y" "$defconfig"; then
[ "$payload_seabios" = "y" ] && pname="seabios" && \
$dry add_seabios
[ "$payload_uboot" = "y" ] && pname="uboot" && $dry add_uboot
else
pname="custom" && $dry cprom; :
fi; :
}
add_seabios()
{
if [ "$payload_uboot_i386" = "y" ] || \
[ "$payload_uboot_amd64" = "y" ]; then
$dry add_uboot
fi
[ -n "$seabiosname" ] || seabiosname="fallback/payload"
_seabioself="elf/seabios/default/$initmode/bios.bin.elf"
if [ "$seabiosname" != "none" ]; then
cbfs "$tmprom" "$_seabioself" "$seabiosname"
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
fi
[ "$payload_memtest" = "y" ] && cbfs "$tmprom" \
"elf/memtest86plus/memtest.bin" img/memtest
[ "$payload_grub" = "y" ] && add_grub
[ "$seabiosname" = "fallback/payload" ] && cprom
[ "$payload_uboot_amd64" = "y" ] && [ "$displaymode" != "txtmode" ] && \
[ "$initmode" != "normal" ] && pname="seauboot" && cprom "seauboot"
[ "$payload_grub" = "y" ] && pname="seagrub" && mkseagrub; :
}
add_grub()
{
[ "$grubname" = "none" ] && return 0
[ "$grubname" = "fallback/payload" ] && pname="grub"
[ -n "$grubname" ] || grubname="img/grub2"
cbfs "$tmprom" "$grubelf" "$grubname"
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
> "$TMPDIR/tmpcfg" || $err "$target: !insert scandisk"
cbfs "$tmprom" "$TMPDIR/tmpcfg" scan.cfg raw
}
mkseagrub()
{
[ "$grubname" = "none" ] && return 0
[ "$grubname" = "fallback/payload" ] && pname="grub"
cbfs "$tmprom" "$grubdata/bootorder" bootorder raw
for keymap in config/data/grub/keymap/*.gkb; do
[ -f "$keymap" ] && cprom "${keymap##*/}"; :
done; :
}
add_uboot()
{
if [ "$displaymode" = "txtmode" ]; then
printf "cb/$target: Cannot use U-Boot in text mode\n" 1>&2
return 0
elif [ "$initmode" = "normal" ]; then
printf "cb/$target: Cannot use U-Boot in normal initmode\n" 1>&2
return 0
fi
# TODO: re-work to allow each coreboot target to say which ub tree
# instead of hardcoding as in the current logic below:
# aarch64 targets:
ubcbfsargs=""
ubpath="fallback/payload"
ubtarget="$target"
# override for x86/x86_64 targets:
if [ "$payload_uboot_i386" = "y" ] || \
[ "$payload_uboot_amd64" = "y" ]; then
ubcbfsargs="-l 0x1110000 -e 0x1110000" # 64-bit and 32-bit
# on 64-bit, 0x1120000 is the SPL, and stub before that
ubpath="img/u-boot" # 64-bit
ubtarget="amd64coreboot"
[ "$payload_uboot_i386" = "y" ] && ubpath="u-boot" # 32-bit
[ "$payload_uboot_i386" = "y" ] && ubtarget="i386coreboot"
[ -n "$ubootname" ] && ubpath="$ubootname"; :
fi
ubdir="elf/u-boot/$ubtarget/$uboot_config"
# aarch64 targets:
ubootelf="$ubdir/u-boot.elf" && [ ! -f "$ubootelf" ] && \
ubootelf="$ubdir/u-boot"
# override for x86/x86_64 targets:
[ "$payload_uboot_i386" = "y" ] && ubootelf="$ubdir/u-boot-dtb.bin"
[ "$payload_uboot_amd64" = "y" ] && \
ubootelf="$ubdir/u-boot-x86-with-spl.bin" # EFI-compatible
[ -f "$ubootelf" ] || $err "cb/$ubtarget: Can't find u-boot"
cbfs "$tmprom" "$ubootelf" "$ubpath" $ubcbfsargs
[ "$seabiosname" != "none" ] && cprom; :
}
cprom()
{
[ "$pname" = "seauboot" ] && [ "$ubootname" = "fallback/payload" ] && \
pname="uboot"
newrom="bin/$target/${pname}_${target}_$initmode.rom"
[ -n "$displaymode" ] && newrom="${newrom%.rom}_$displaymode.rom"
[ $# -gt 0 ] && [ "$1" != "seauboot" ] && \
newrom="${newrom%.rom}_${1%.gkb}.rom"
x_ mkdir -p "bin/$target"
x_ cp "$tmprom" "$newrom" && [ $# -gt 0 ] && [ "$1" != "seauboot" ] && \
cbfs "$newrom" "config/data/grub/keymap/$1" keymap.gkb raw
[ $# -gt 0 ] && [ "$1" = "seauboot" ] && \
cbfs "$newrom" "config/data/grub/bootorder_uboot" "bootorder" raw
_setplatform="" && [ -n "$IFD_platform" ] \
&& _setplatform="--platform $IFD_platform"
[ "$HAPdisable" != "y" ] || "$ifdtool" $_setplatform --altmedisable 1 \
"$newrom" -O "$newrom" || \
$err "Cannot set HAP bit in '$newrom'"
[ "$XBMK_RELEASE" = "y" ] || return 0
$dry mksha512sum "$newrom" "vendorhashes"; $dry ./vendor inject \
-r "$newrom" -b "$target" -n nuke || $err "!nuke $newrom"
}
mkcoreboottar()
{
[ "$target" = "$tree" ] && return 0; [ "$XBMK_RELEASE" = "y" ] && \
[ "$release" != "n" ] && $dry mkrom_tarball "bin/$target"; :
}