From 4cbab95691d169aa4d7e52f27717be5a5a7fddcb Mon Sep 17 00:00:00 2001 From: Martin Kepplinger Date: Wed, 27 Nov 2019 14:47:13 +0100 Subject: [PATCH] (WIP) config: coreboot-x230: add gbe ifd and me blobs and increase cbfs size WARNING: Updating from inside of Heads is NOT possible! Changing the IFD format requires flashing from the outside (once). This is because we only flash the bios region and whatever IFD format is _currently_ in flash is used again. For this update, more regions need to get flashed. Either: * flash ifd, me and bios regions from userspace manually, or * split up a new coreboot build to 4M and 8M and flash externally This requires blobs for the x230 similar to the x220 now. They must be modified by me_cleaner to be able to have 0xbe5000 of CBFS size. An extract.sh script is provided, to be run before building Heads. This should create enough room to keep the x230 supported by Heads in the long run (when vboot or more tools might be desired). add extract.sh --- blobs/x230/.gitignore | 1 + blobs/x230/extract.sh | 127 ++++++++++++++++++++++++++++++++++++ blobs/x230/readme.md | 24 +++++++ config/coreboot-x230.config | 12 +++- 4 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 blobs/x230/.gitignore create mode 100755 blobs/x230/extract.sh create mode 100644 blobs/x230/readme.md diff --git a/blobs/x230/.gitignore b/blobs/x230/.gitignore new file mode 100644 index 000000000..3759e933a --- /dev/null +++ b/blobs/x230/.gitignore @@ -0,0 +1 @@ +util diff --git a/blobs/x230/extract.sh b/blobs/x230/extract.sh new file mode 100755 index 000000000..65d27040a --- /dev/null +++ b/blobs/x230/extract.sh @@ -0,0 +1,127 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2019, Martin Kepplinger + +set -e + +cd "$(dirname "$0")" + +IFDTOOL=./util/ifdtool/ifdtool +ME_CLEANER=./util/me_cleaner/me_cleaner.py +have_input_image=0 + +usage() +{ + echo "EXPERIMENTAL" + echo "" + echo "This generates files for building Heads from your original 12M backup:" + echo " (cat bottom.bin top.bin > full_backup_image.rom)" + echo " ifd/me will be shrinked by me_cleaner and unlocked" + echo "" + echo " http://osresearch.net" + echo "" + echo "Usage: $0 -f .rom -i (optional) -m " + echo "" + usage + exit 1 +fi + +if [ ! -e ${IFDTOOL} ] ; then + if [ ! -d util/ifdtool ] ; then + echo "Please specify -i " + exit 1 + fi + make -C util/ifdtool + if [ ! -e ${IFDTOOL} ] ; then + echo "Failed to build ifdtool" + exit 1 + fi +fi +if [ ! -e ${ME_CLEANER} ] ; then + mkdir -p util/me_cleaner + curl -L https://raw.githubusercontent.com/corna/me_cleaner/v1.2/me_cleaner.py -o util/me_cleaner/me_cleaner.py + if [ ! -e ${ME_CLEANER} ] ; then + echo "Failed to download me_cleaner" + exit 1 + fi +fi + +OUTPUT_PATH=output +INPUT_IMAGE_NAME=$(basename "${INPUT_IMAGE_PATH}") +WORK_IMAGE_NAME=${INPUT_IMAGE_NAME%%.*}_prepared.rom + +input_filesize=$(wc -c <"$INPUT_IMAGE_PATH") +reference_filesize=12582912 +if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then + echo "Error: input file must be 12MB of size" + exit 1 +fi + +rm -rf ${OUTPUT_PATH} +mkdir ${OUTPUT_PATH} +cp "${INPUT_IMAGE_PATH}" "${OUTPUT_PATH}/${WORK_IMAGE_NAME}" + +${IFDTOOL} -x "${OUTPUT_PATH}/${WORK_IMAGE_NAME}" +mv flashregion*bin "${OUTPUT_PATH}/" +cp "${OUTPUT_PATH}/flashregion_3_gbe.bin" "${OUTPUT_PATH}/gbe.bin" +rm ${OUTPUT_PATH}/flashregion*bin + +python ${ME_CLEANER} -r -t -d -S -O "${OUTPUT_PATH}/unneeded_cleaned_image.bin" -D "${OUTPUT_PATH}/ifd_shrinked.bin" -M "${OUTPUT_PATH}/me.bin" "${OUTPUT_PATH}/${WORK_IMAGE_NAME}" +rm "${OUTPUT_PATH}/unneeded_cleaned_image.bin" + +${IFDTOOL} -u "${OUTPUT_PATH}/ifd_shrinked.bin" +mv "${OUTPUT_PATH}/ifd_shrinked.bin.new" "${OUTPUT_PATH}/descriptor.bin" +rm "${OUTPUT_PATH}/ifd_shrinked.bin" + +rm "${OUTPUT_PATH}/${WORK_IMAGE_NAME}" + +echo "done. this is what a layout file should look like:" +echo "0x00000000:0x00000fff ifd" +echo "0x00001000:0x00002fff gbe" +echo "0x00003000:0x0001afff me" +echo "0x0001b000:0x00bfffff bios" + +mv ${OUTPUT_PATH}/* . && rm -rf ${OUTPUT_PATH} diff --git a/blobs/x230/readme.md b/blobs/x230/readme.md new file mode 100644 index 000000000..6e3421a75 --- /dev/null +++ b/blobs/x230/readme.md @@ -0,0 +1,24 @@ +To build for X230 we need to have the following files in this folder: +* `me.bin` - ME binary that has been stripped and truncated with me_cleaner +* `gbe.bin` - Network card blob from the original firmware +* `descriptor.bin` - Flash layout file modified by me_cleaner + +To get the binaries, start with a copy of the original 12M Lenovo firmware image. +If you do not have one already, you can read one out from the laptops SPI flash. +Make sure to boot Linux with the "iomem=relaxed" option on the commandline. + +``` +flashrom --programmer internal -r original.bin +``` + +Once you have the image, the provided extraction script will extract the files needed. + +``` +./extract.sh -f -i +``` + +The flash layout will be automatically adjusted and the ME image cleaned and truncated. + +You can now compile the image with: + +make BOARD=x230 diff --git a/config/coreboot-x230.config b/config/coreboot-x230.config index 7ac795a58..cbe1c4303 100644 --- a/config/coreboot-x230.config +++ b/config/coreboot-x230.config @@ -4,14 +4,20 @@ CONFIG_LOCALVERSION="heads" CONFIG_USE_BLOBS=y CONFIG_MEASURED_BOOT=y CONFIG_VENDOR_LENOVO=y -CONFIG_CBFS_SIZE=0x700000 +CONFIG_CBFS_SIZE=0xbe5000 # CONFIG_POST_IO is not set -# CONFIG_POST_DEVICE is not set -CONFIG_DRIVERS_UART_8250IO=y +CONFIG_IFD_BIN_PATH="../../blobs/x230/descriptor.bin" +CONFIG_ME_BIN_PATH="../../blobs/x230/me.bin" +CONFIG_HAVE_IFD_BIN=y CONFIG_BOARD_LENOVO_X230=y CONFIG_DRIVERS_PS2_KEYBOARD=y +CONFIG_DRIVERS_UART_8250IO=y +# CONFIG_POST_DEVICE is not set CONFIG_LINUX_COMMAND_LINE="intel_iommu=igfx_off quiet" CONFIG_UART_PCI_ADDR=0 +CONFIG_HAVE_ME_BIN=y +CONFIG_HAVE_GBE_BIN=y +CONFIG_GBE_BIN_PATH="../../blobs/x230/gbe.bin" CONFIG_NO_GFX_INIT=y # CONFIG_CONSOLE_SERIAL is not set CONFIG_CONSOLE_CBMEM_BUFFER_SIZE=0x80000