From a146fbe4e2788d42dc1b9349ecae51854f3fa112 Mon Sep 17 00:00:00 2001 From: Martin Kepplinger Date: Mon, 18 Jun 2018 11:29:44 +0200 Subject: [PATCH] include coreboot-sdk build system shamelessly taken from https://github.com/Thrilleratplay/coreboot-builder-scripts thanks a lot! --- README.md | 4 ++ build.sh | 103 ++++++++++++++++++++++++++++++++++++ common/config_and_make.sh | 46 ++++++++++++++++ common/download_coreboot.sh | 96 +++++++++++++++++++++++++++++++++ common/variables.sh | 13 +++++ x230/README.md | 2 +- x230/compile.sh | 43 +++++++++++++++ 7 files changed, 306 insertions(+), 1 deletion(-) create mode 100755 build.sh create mode 100755 common/config_and_make.sh create mode 100755 common/download_coreboot.sh create mode 100755 common/variables.sh create mode 100755 x230/compile.sh diff --git a/README.md b/README.md index 5afd369..eeec7b8 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ Either when * Everything necessary to [build coreboot](https://www.coreboot.org/Build_HOWTO) is included here * When doing a release, we always try to upload to coreboot's [board status project](https://www.coreboot.org/Supported_Motherboards) * If we add out-of-tree patches, we always [post them for review](http://review.coreboot.org/) upstream +* The scripts to build reproducibly are based on +[these](https://github.com/Thrilleratplay/coreboot-builder-scripts) +scripts that use the +[coreboot-sdk](https://hub.docker.com/r/coreboot/coreboot-sdk/). ## Alternatives We aim to be the easiest possible coreboot distribution - both diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..6e0ea25 --- /dev/null +++ b/build.sh @@ -0,0 +1,103 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0+ +set -e + +## import variables +. ./common/variables.sh + +################################################################################ +## Menu +################################################################################ + +## Parse avialble models from directory names +AVAILABLE_MODELS=$(find ./ -maxdepth 1 -mindepth 1 -type d | sed 's/\.\///g' | grep -Ev "common|git") + +## Help menu +usage() +{ + echo "Usage: " + echo + echo " $0 [-t ] [-c ] [--config] [--bleeding-edge] [--clean-slate] " + echo + echo " --bleeding-edge Build from the latest commit" + echo " --clean-slate Purge previous build directory and config" + echo " -c, --commit Git commit hash" + echo " --flash Flash BIOS if build is successful" + echo " -h, --help Show this help" + echo " -i, --config Execute with interactive make config" + echo " -t, --tag Git tag/version" + echo + echo "If a tag, commit or bleeding-edge flag is not given, the latest Coreboot release will be built." + echo + echo + echo "Available models:" + for AVAILABLE_MODEL in $AVAILABLE_MODELS; do + echo "$(printf '\t')$AVAILABLE_MODEL" + done +} + +## Iterate through command line parameters +while : +do + case "$1" in + --bleeding-edge) + COREBOOT_COMMIT="master" + shift 1;; + --clean-slate) + CLEAN_SLATE=true + shift 1;; + -c | --commit) + COREBOOT_COMMIT="$2" + shift 2;; + --flash) + FLASH_AFTER_BUILD=true + shift 1;; + -h | --help) + usage >&2 + exit 0;; + -i | --config) + COREBOOT_CONFIG=true + shift 1;; + -t | --tag) + COREBOOT_TAG="$2" + shift 2;; + -*) + echo "Error: Unknown option: $1" >&2 + usage >&2 + exit 1;; + *) + break;; + esac +done + +## Validate and normalize given model number +MODEL=$(echo "$@" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]'); + +## Check if valid model +if [ -z "$MODEL" ] || [ ! -d "$PWD/$MODEL" ]; then + usage + exit 1; +fi; + +################################################################################ +################################################################################ + +if [ ! -d "$PWD/$MODEL/build" ]; then + mkdir "$PWD/$MODEL/build" +elif [ "$CLEAN_SLATE" ]; then + rm -rf "$PWD/$MODEL/build" || true + mkdir "$PWD/$MODEL/build" +fi + +## Run Docker +docker run --rm -it \ + --user "$(id -u):$(id -g)" \ + -v "$PWD/$MODEL/build:$DOCKER_COREBOOT_DIR" \ + -v "$PWD/$MODEL:$DOCKER_SCRIPT_DIR" \ + -v "$PWD/common:$DOCKER_COMMON_SCRIPT_DIR" \ + -v "$PWD/$MODEL/stock_bios:$DOCKER_STOCK_BIOS_DIR:ro" \ + -e COREBOOT_COMMIT="$COREBOOT_COMMIT" \ + -e COREBOOT_TAG="$COREBOOT_TAG" \ + -e COREBOOT_CONFIG="$COREBOOT_CONFIG" \ + coreboot/coreboot-sdk:"$COREBOOT_SDK_VERSION" \ + /home/coreboot/scripts/compile.sh && [ -n "$FLASH_AFTER_BUILD" ] && ./flash.sh "$MODEL" diff --git a/common/config_and_make.sh b/common/config_and_make.sh new file mode 100755 index 0000000..d99c9e6 --- /dev/null +++ b/common/config_and_make.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ + +# shellcheck disable=SC1091 +source /home/coreboot/common_scripts/variables.sh + +################################################################################ +## Copy config and run make +################################################################################ +function configAndMake() { + ###################### + ## Copy config ## + ###################### + if [ -f "$DOCKER_COREBOOT_DIR/.config" ]; then + echo "Using existing config" + else + if [ -f "$DOCKER_SCRIPT_DIR/config-$COREBOOT_COMMIT" ]; then + cp "$DOCKER_SCRIPT_DIR/config-$COREBOOT_COMMIT" "$DOCKER_COREBOOT_DIR/.config" + echo "Using config-$COREBOOT_COMMIT" + elif [ -f "$DOCKER_SCRIPT_DIR/config-$COREBOOT_TAG" ]; then + cp "$DOCKER_SCRIPT_DIR/config-$COREBOOT_TAG" "$DOCKER_COREBOOT_DIR/.config" + echo "Using config-$COREBOOT_TAG" + else + cp "$DOCKER_SCRIPT_DIR/config" "$DOCKER_COREBOOT_DIR/.config" + echo "Using default config" + fi + fi + + ################################# + ## Copy in the X230 VGA BIOS ## + ################################# + if [ -f "$DOCKER_SCRIPT_DIR/pci8086,0166.rom" ]; then + cp "$DOCKER_SCRIPT_DIR/pci8086,0166.rom" "$DOCKER_COREBOOT_DIR/pci8086,0166.rom" + fi + + ############## + ## make ## + ############## + cd "$DOCKER_COREBOOT_DIR" || exit; + + if [ "$COREBOOT_CONFIG" ]; then + make nconfig + fi + + make +} diff --git a/common/download_coreboot.sh b/common/download_coreboot.sh new file mode 100755 index 0000000..783e854 --- /dev/null +++ b/common/download_coreboot.sh @@ -0,0 +1,96 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ + +# shellcheck disable=SC1091 +source /home/coreboot/common_scripts/variables.sh + +IS_BUILD_DIR_EMPTY=$(ls -A "$DOCKER_COREBOOT_DIR") + + +################################################################################ +## Update or clone git coreboot repo +################################################################################ +function gitUpdate() { + if [ -z "$IS_BUILD_DIR_EMPTY" ]; then + # Clone Coreboot and fetch submodules + git clone https://github.com/coreboot/coreboot.git "$DOCKER_COREBOOT_DIR" + cd "$DOCKER_COREBOOT_DIR" || exit + git submodule update --init --recursive --remote + + # blobs are ignored from updates. Manually clone to prevent compile errors later from non empty directory cloning + git clone https://github.com/coreboot/blobs.git 3rdparty/blobs/ + else + cd "$DOCKER_COREBOOT_DIR" || exit + git fetch --all --tags --prune + + cd "$DOCKER_COREBOOT_DIR/3rdparty/blobs/" || exit + git fetch --all --tags --prune + fi +} +################################################################################ + + + +################################################################################ +## +################################################################################ +function checkoutTag() { + git checkout tags/"$COREBOOT_TAG" || exit + git submodule update --recursive --remote +} +################################################################################ + + + +################################################################################ +## +################################################################################ +function checkoutCommit() { +#edge should checkout master + git checkout "$COREBOOT_COMMIT" || exit + git submodule update --recursive --remote +} +################################################################################ + + +################################################################################ +## Download the latest released version of Coreboot +################################################################################ +function downloadCoreboot() { + CB_RELEASES=$(wget -q -O- https://coreboot.org/releases/sha256sum.txt | sed 's/[^*]*\*//') + + LATEST_RELEASE=$(echo -n "$CB_RELEASES" | grep "coreboot-" | grep -v "coreboot-blobs-" | sort -V | tail -n1) + LATEST_BLOBS=$(echo -n "$CB_RELEASES" | grep "coreboot-blobs-" | sort -V | tail -n1) + COREBOOT_VERSION=$(echo -n "$LATEST_RELEASE" | sed 's/coreboot-//' | sed 's/.tar.xz//') + + echo "Beginning download of $LATEST_RELEASE..." + + wget -q -O- "https://coreboot.org/releases/$LATEST_RELEASE" | unxz -c | tar -C "$DOCKER_COREBOOT_DIR" -x --strip 1 + wget -q -O- "https://coreboot.org/releases/$LATEST_BLOBS" | unxz -c | tar -C "$DOCKER_COREBOOT_DIR" -x --strip 1 + + echo "Downloading $LATEST_RELEASE complete" + + export COREBOOT_VERSION; +} +################################################################################ + + + +################################################################################ +## MAIN FUNCTION: download/clone/checkout appropriate version of CoreBoot +######################################## +######################################################################################################################## +function downloadOrUpdateCoreboot() { + if [ -z "$COREBOOT_COMMIT" ] && [ -z "$COREBOOT_TAG" ] && [ -z "$IS_BUILD_DIR_EMPTY" ]; then + # If a no commit nor tag is given and the directory is empty download Coreboot release + downloadCoreboot; + elif [ "$COREBOOT_COMMIT" ]; then + # DOCKER_COMMIT?=$(shell git log -n 1 --pretty=%h) + gitUpdate + checkoutCommit + elif [ "$COREBOOT_TAG" ]; then + gitUpdate + checkoutTag + fi +} +################################################################################ diff --git a/common/variables.sh b/common/variables.sh new file mode 100755 index 0000000..18816ab --- /dev/null +++ b/common/variables.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ + +################################################################################ +## VARIABLES +################################################################################ +export COREBOOT_SDK_VERSION="1.50" + +export DOCKER_ROOT_DIR="/home/coreboot" +export DOCKER_SCRIPT_DIR="$DOCKER_ROOT_DIR/scripts" +export DOCKER_COMMON_SCRIPT_DIR="$DOCKER_ROOT_DIR/common_scripts" +export DOCKER_COREBOOT_DIR="$DOCKER_ROOT_DIR/cb_build" +export DOCKER_STOCK_BIOS_DIR="$DOCKER_ROOT_DIR/stock_bios/" diff --git a/x230/README.md b/x230/README.md index b3c821c..9a5b9b7 100644 --- a/x230/README.md +++ b/x230/README.md @@ -3,7 +3,7 @@ ![seabios_bootmenu](front.jpg) ## Latest release -* Get it from our [release page](https://github.com/merge/coreboot-x230/releases) +* `./build.sh -c $(ls -1 x230/config-* | cut -c 13-22) x230` should produce the exact release image file. Get it from our [release page](https://github.com/merge/coreboot-x230/releases) * __coreboot__: We take coreboot's master branch at the time we build a release image. * __microcode update__: revision `1f` from 2018-02-07 see package [20180312](https://downloadcenter.intel.com/download/27591) under [Intel's license](LICENSE.microcode) * __SeaBIOS__: version [1.11.1](https://seabios.org/Releases) from 2018-03-19 diff --git a/x230/compile.sh b/x230/compile.sh new file mode 100755 index 0000000..b2755b6 --- /dev/null +++ b/x230/compile.sh @@ -0,0 +1,43 @@ +#!/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 + +################################################################################ +## MODEL VARIABLES +################################################################################ +MAINBOARD="lenovo" +MODEL="x230" + +################################################################################ + +############################################### +## download/git clone/git pull Coreboot ## +############################################### +downloadOrUpdateCoreboot + +############################## +## 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 + #split out top BIOS + if [ ! -z "$COREBOOT_COMMIT" ]; then + RELEASEFILE="${MODEL}_coreboot_seabios_$(echo ${COREBOOT_COMMIT} | cut -c 1-10)_top.rom" + else + RELEASEFILE="coreboot_$MAINBOARD-$MODEL-top.rom" + fi + dd if="$DOCKER_COREBOOT_DIR/build/coreboot.rom" of="$DOCKER_COREBOOT_DIR/$RELEASEFILE" bs=1M skip=8 + + sha256sum "$DOCKER_COREBOOT_DIR/$RELEASEFILE" > "$DOCKER_COREBOOT_DIR/${RELEASEFILE}".sha256 +fi