Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edk2 dev #28

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions common/download_and_extract_mrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+

# shellcheck disable=SC1091
# LCOV_EXCL_START
if [ -z "$UNIT_TESTING" ]; then
source /home/coreboot/common_scripts/variables.sh
fi
# LCOV_EXCL_STOP

################################################################################
### NOTE: assumes coreboot has already been downloaded
################################################################################


UTIL_CHROMEOS_PATH="$DOCKER_COREBOOT_DIR/util/chromeos"

################################################################################
## Download and compile "uudecode" as it is not included in the coreboot-sdk docker image
################################################################################
function downloadUudecode() {
wget https://ftp.gnu.org/gnu/sharutils/sharutils-4.15.2.tar.xz
tar xJf sharutils-4.15.2.tar.xz
cd sharutils-4.15.2 || exit
sed -i 's/BUFSIZ/rw_base_size/' src/unshar.c
sed -i '/program_name/s/^/extern /' src/*opts.h
sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> lib/stdio-impl.h
./configure
make
mv src/uudecode "$UTIL_CHROMEOS_PATH" || exit
}

################################################################################
## Download and compile "parted" as it is not included in the coreboot-sdk docker image
################################################################################
function downloadParted() {
wget https://ftp.gnu.org/gnu/parted/parted-3.4.tar.xz
tar xJf parted-3.4.tar.xz
cd parted-3.4 || exit
./configure --disable-device-mapper --disable-static
make
mv parted/parted "$UTIL_CHROMEOS_PATH" || exit
mv parted/.libs/ "$UTIL_CHROMEOS_PATH" # || exit
mv libparted/.libs/libparted.so "$UTIL_CHROMEOS_PATH/.libs/" || exit
mv libparted/.libs/libparted.so.2 "$UTIL_CHROMEOS_PATH/.libs/" || exit
mv libparted/.libs/libparted.so.2.0.3 "$UTIL_CHROMEOS_PATH/.libs/" || exit
}

################################################################################
## Download and compile "unzip" as it is not included in the coreboot-sdk docker image
################################################################################
function downloadUnzip() {
wget https://downloads.sourceforge.net/infozip/unzip60.tar.gz
tar xzf unzip60.tar.gz
cd unzip60 || exit
make -f unix/Makefile generic
mv unzip "$UTIL_CHROMEOS_PATH" || exit
}

################################################################################
## MAIN FUNCTION: download ChromeOS ROM and extract mrc.bin into root coreboot
## directory
#################################################################################
function downloadAndExtractmrc() {
if [ ! -f "$DOCKER_COREBOOT_DIR/mrc.bin" ]; then
# FIXME: Due to connection stability problems trying to download the chromebook image,
# use the mrc.bin from skulls for now
wget -P "$DOCKER_COREBOOT_DIR/" https://github.com/merge/skulls/raw/master/t440p/mrc.bin

# Create temp directory
# mkdir "$DOCKER_COREBOOT_DIR/deb_extract"
# cd "$DOCKER_COREBOOT_DIR/deb_extract" || exit
#
# downloadUudecode
# downloadParted
# downloadUnzip
#
# # clean up temp directory
# cd "$DOCKER_COREBOOT_DIR/" || exit
# rm -rf "$DOCKER_COREBOOT_DIR/deb_extract"
#
# # https://doc.coreboot.org/northbridge/intel/haswell/mrc.bin.html
# make -C "$DOCKER_COREBOOT_DIR/util/cbfstool"
# cd "$DOCKER_COREBOOT_DIR/util/chromeos" || exit
#
# #PATH="$PATH:$DOCKER_COREBOOT_DIR/util/chromeos" LD_LIBRARY_PATH="$UTIL_CHROMEOS_PATH/.libs/:$LD_LIBRARY_PATH" ./crosfirmware.sh peppy || exit
# ./crosfirmware.sh peppy || exit
# "$DOCKER_COREBOOT_DIR/util/cbfstool/cbfstool" coreboot-*.bin extract -f mrc.bin -n mrc.bin -r RO_SECTION || exit
# mv mrc.bin "$DOCKER_COREBOOT_DIR/" || exit
fi
}
22 changes: 22 additions & 0 deletions w541/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Lenovo W541

### Compiling
Build the latest merged into the master git branch:
`./build.sh --bleeding-edge w541`

Latest stable release:
`./build.sh w541`

### Output
##### Internal flashing
`coreboot_lenovo-w541-complete.rom` - The complete Coreboot ROM is the 12MB version used for internal flashing.
`coreboot_lenovo-w541-complete.rom.sha256` - sha256 checksum of 12MB Coreboot Rom

*NOTE:* As this is compiled without the stock BIOS, all IFD, GBE and ME blobs are stubs. Use the `flash.sh` script at the root of the directory.


##### External flashing
`coreboot_lenovo-w541-top.rom` - The 4MB Coreboot BIOS that can be flashed externally onto the top BIOS chip.
`coreboot_lenovo-w541-top.rom.sha256` - sha256 checksum of 4MB Coreboot BIOS

*NOTE:* See [Skulls](https://github.com/merge/skulls/tree/master/w541) for instructions on how to flash the top BIOS chip as well as unlocking the IFD and cleaning Intel ME
57 changes: 57 additions & 0 deletions w541/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+

# shellcheck disable=SC1091
source /home/coreboot/common_scripts/./variables.sh
source /home/coreboot/common_scripts/./download_coreboot.sh
source /home/coreboot/common_scripts/./config_and_make.sh
source /home/coreboot/common_scripts/./extract_stockbios.sh
source /home/coreboot/common_scripts/./copy_bootsplash.sh
source /home/coreboot/common_scripts/./download_and_extract_mrc.sh

################################################################################
## MODEL VARIABLES
################################################################################
MAINBOARD="lenovo"
MODEL="w541"

################################################################################

###############################################
## download/git clone/git pull Coreboot ##
###############################################
downloadOrUpdateCoreboot

downloadAndExtractmrc

##############################################################
## Export Stock BIOS GBE/ME/IDF (Optional for updating) ##
##############################################################
# uncomment next line to enable
# extractStockBios "$MAINBOARD" "$MODEL" "stock_bios.bin"

#############################
## Copy bootsplash.jpg ##
#############################
copyEdk2Bootsplash

##############################
## Copy config and make ##
##############################
configAndMake

#####################
## Post build ##
#####################
if [ ! -f "$DOCKER_COREBOOT_DIR/build/coreboot.rom" ]; then
echo "Uh oh. Things did not go according to plan."
exit 1;
else
mv "$DOCKER_COREBOOT_DIR/build/coreboot.rom" "$DOCKER_COREBOOT_DIR/coreboot_$MAINBOARD-$MODEL-complete.rom"

#split out top BIOS
dd if="$DOCKER_COREBOOT_DIR/coreboot_$MAINBOARD-$MODEL-complete.rom" of="$DOCKER_COREBOOT_DIR/coreboot_$MAINBOARD-$MODEL-top.rom" bs=1M skip=8

sha256sum "$DOCKER_COREBOOT_DIR/coreboot_$MAINBOARD-$MODEL-complete.rom" > "$DOCKER_COREBOOT_DIR/coreboot_$MAINBOARD-$MODEL-complete.rom.sha256"
sha256sum "$DOCKER_COREBOOT_DIR/coreboot_$MAINBOARD-$MODEL-top.rom" > "$DOCKER_COREBOOT_DIR/coreboot_$MAINBOARD-$MODEL-top.rom-sha256"
fi
28 changes: 28 additions & 0 deletions w541/defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CONFIG_TIMESTAMPS_ON_CONSOLE=y
CONFIG_BOOTSPLASH_IMAGE=y
CONFIG_SBOM=y
CONFIG_SBOM_COMPILER=y
CONFIG_SBOM_PAYLOAD=y
CONFIG_SBOM_MICROCODE=y
CONFIG_VENDOR_LENOVO=y
CONFIG_NO_POST=y
CONFIG_CBFS_SIZE=0x300000
CONFIG_LINEAR_FRAMEBUFFER_MAX_HEIGHT=768
CONFIG_LINEAR_FRAMEBUFFER_MAX_WIDTH=1024
CONFIG_INTEL_GMA_VBT_FILE="src/mainboard/$(MAINBOARDDIR)/variants/w541/data.vbt"
CONFIG_BOARD_LENOVO_THINKPAD_W541=y
CONFIG_EDK2_BOOTSPLASH_FILE="bootsplash.jpg"
CONFIG_HAVE_MRC=y
CONFIG_H8_SUPPORT_BT_ON_WIFI=y
CONFIG_BOOTSPLASH=y
CONFIG_MRC_SETTINGS_PROTECT=y
CONFIG_USBDEBUG=y
CONFIG_DRIVERS_PS2_KEYBOARD=y
CONFIG_SECURITY_CLEAR_DRAM_ON_REGULAR_BOOT=y
CONFIG_PAYLOAD_EDK2=y
CONFIG_EDK2_CBMEM_LOGGING=y
CONFIG_COREINFO_SECONDARY_PAYLOAD=y
CONFIG_MEMTEST_SECONDARY_PAYLOAD=y
CONFIG_NVRAMCUI_SECONDARY_PAYLOAD=y
CONFIG_TINT_SECONDARY_PAYLOAD=y
CONFIG_MEMTEST86PLUS_V5=y
15 changes: 15 additions & 0 deletions w541/flashrom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
set -e

if ! command -v flashrom &> /dev/null; then
echo "Flashrom cannot be found. Install and try again."
exit 1
fi

if [ -z "$1" ]; then
echo "File name needed. No argument supplied.";
exit 1;
fi

flashrom -p internal -r "$1.backup" && flashrom -p internal --layout "$PWD/w541/layout.txt" --image bios -w "$1"
4 changes: 4 additions & 0 deletions w541/layout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
00000000:00000fff fd
00500000:00bfffff bios
00003000:004fffff me
00001000:00002fff gbe