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

Refactor build.sh to be usable as the standard way of building Dasharo coreboot #579

Draft
wants to merge 1 commit into
base: dasharo
Choose a base branch
from
Draft
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
262 changes: 126 additions & 136 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,215 +9,202 @@ usage() {
echo -e "\tz690a_ddr5 - build Dasharo image compatible with MSI PRO Z690-A (WIFI)"
echo -e "\tz790p_ddr4 - build Dasharo image compatible with MSI PRO Z790-P (WIFI) DDR4"
echo -e "\tz790p_ddr5 - build Dasharo image compatible with MSI PRO Z790-P (WIFI)"

echo -e "\tvp66xx - build Dasharo for Protectli VP66xx"
echo -e "\tvp46xx - build Dasharo for Protectli VP46xx"
echo -e "\tvp2420 - build Dasharo for Protectli VP2420"
echo -e "\tvp2410 - build Dasharo for Protectli VP2410"
echo -e "\tV1210 - build Dasharo for Protectli V1210"
echo -e "\tV1410 - build Dasharo for Protectli V1410"
echo -e "\tV1610 - build Dasharo for Protectli V1610"

echo -e "\tapu2 - build Dasharo for PC Engines APU2"
echo -e "\tapu3 - build Dasharo for PC Engines APU3"
echo -e "\tapu4 - build Dasharo for PC Engines APU4"
echo -e "\tapu6 - build Dasharo for PC Engines APU6"

echo -e "\toptiplex_9010 - build Dasharo compatible with Dell OptiPlex 7010/9010"

echo -e "\tqemu - build Dasharo for QEMU Q35"
echo -e "\tqemu_full - build Dasharo for QEMU Q35 with all menus available"

echo -e "\tv540tu - build Dasharo for Novacustom V540TU"
echo -e "\tv560tu - build Dasharo for Novacustom V560TU"
echo -e "\tns5x7x - build Dasharo for Novacustom NS5x/NS7x"
echo -e "\tnv4x_adl - build Dasharo for Novacustom NV4x 12 gen"
echo -e "\tnx5x7x - build Dasharo for Novacustom Nx5x/Nx7x"
echo -e "\tnv4x_tgl - build Dasharo for Novacustom NV4x 11 gen"

echo "Used environmental variables:"
echo -e "\tCB_REVISION - build Dasharo coreboot from a given revision name"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this should be in this script, if it only checks out a specific rev. For example what happens if it checks out to a revision that doesn't have this script? It may stay in memory and finish the run, but after it finishes the build.sh script may be different and not work the same way if someone calls it again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true. The script is a part of the repository which it would checkout to a different version itself. I wonder if using the script as a universal way of building any version of Dasharo would be possible without making changes in historic revisions...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be possible to get the ID of the current commit git rev-parse HEAD and restore it after building? This sounds like a cheap solution though...

echo -e "\tNO_DISTCLEAN - set to not clean the repository before building"
echo -e "\tNO_CONFIG_OVERRIDE - set to not override the "./.config" file"
echo -e "\tNO_SUBMODULE_UPDATE - set to not update the submodules"
echo -e "\tEC_REVISION - use the given EC revvision to build Dasharo coreboot on platforms which require it"
}

SDKVER="2023-11-24_2731fa619b"


function build_optiplex_9010 {
DEFCONFIG="configs/config.dell_optiplex_9010_sff_uefi_txt"
FW_VERSION=v0.1.0-rc1

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make distclean"
function prepare_for_build {
if [[ -v CB_REVISION ]]; then
git checkout $CB_REVISION
fi

cp "${DEFCONFIG}" .config
if [[ ! -v NO_DISTCLEAN ]]; then
docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make distclean"
fi

git submodule update --init --checkout
if [[ ! -v NO_CONFIG_OVERRIDE ]]; then
cp "${DEFCONFIG}" .config
fi
}

echo "Building Dasharo compatible with Dell OptiPlex 7010/9010 (version $FW_VERSION)"
function build_coreboot {
TARGET_BINARY=$1
prepare_for_build

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make olddefconfig && make -j$(nproc)"

cp build/coreboot.rom ${BOARD}_${FW_VERSION}.rom
cp build/coreboot.rom $TARGET_BINARY
if [ $? -eq 0 ]; then
echo "Result binary placed in $PWD/${BOARD}_${FW_VERSION}.rom"
sha256sum ${BOARD}_${FW_VERSION}.rom > ${BOARD}_${FW_VERSION}.rom.sha256
echo "Result binary placed in $PWD/$TARGET_BINARY"
sha256sum $TARGET_BINARY > $TARGET_BINARY.sha256
else
echo "Build failed!"
exit 1
fi
}

function build_msi {
DEFCONFIG="configs/config.${BOARD}_$1"
FW_VERSION=$(cat ${DEFCONFIG} | grep CONFIG_LOCALVERSION | cut -d '=' -f 2 | tr -d '"')

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make distclean"

cp "${DEFCONFIG}" .config

git submodule update --init --checkout
function build_ec {
EC_BOARD_VENDOR=$1
EC_BOARD_MODEL=$2
if [[ ! -v EC_REVISION ]]; then
echo "EC_REVISION environmental variable is not set. Please provide an EC revision."
exit 1;
fi

echo "Building Dasharo compatible with MSI PRO $2(WIFI) (version $FW_VERSION)"
echo "Building EC for $EC_BOARD_VENDOR $EC_BOARD_MODEL from branch $EC_REVISION"
git clone https://github.com/Dasharo/ec.git &> /dev/null || true
cd ec
git checkout $EC_REVISION
git submodule update --init --recursive --checkout
EC_BOARD_VENDOR=novacustom EC_BOARD_MODEL=nv4x_adl ./build.sh || true
cd ..
cp "ec/${EC_BOARD_VENDOR}_${EC_BOARD_MODEL}_ec.rom" ec.rom
}

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make olddefconfig && make -j$(nproc)"
function generic_submodules {
if [[ ! -v NO_SUBMODULE_UPDATE ]]; then
git submodule update --init --checkout
fi
}

cp build/coreboot.rom ${BOARD}_${FW_VERSION}_$1.rom
if [ $? -eq 0 ]; then
echo "Result binary placed in $PWD/${BOARD}_${FW_VERSION}_$1.rom"
sha256sum ${BOARD}_${FW_VERSION}_$1.rom > ${BOARD}_${FW_VERSION}_$1.rom.sha256
function protectli_submodules {
if [[ ! -d 3rdparty/dasharo-blobs/protectli ]]; then
NO_SUBMODULE_UPDATE="true"
else
echo "Build failed!"
exit 1
unset NO_SUBMODULE_UPDATE
fi
generic_submodules
}

function build_protectli_vault {
DEFCONFIG="configs/config.protectli_${BOARD}"
FW_VERSION=$(cat ${DEFCONFIG} | grep CONFIG_LOCALVERSION | cut -d '=' -f 2 | tr -d '"')
function pcengines_submodules {
if [[ ! -v NO_SUBMODULE_UPDATE ]]; then
# checkout several submodules needed by these boards (some others are checked
# out by coreboot's Makefile)
git submodule update --init --force --checkout \
3rdparty/dasharo-blobs \
3rdparty/vboot
fi
}

if [ ! -d 3rdparty/dasharo-blobs/protectli ]; then
git submodule update --init --checkout
function qemu_submodules {
if [[ ! -v NO_SUBMODULE_UPDATE ]]; then
# checkout several submodules needed by these boards (some others are checked
# out by coreboot's Makefile)
git submodule update --init --force --checkout \
3rdparty/dasharo-blobs
fi
}

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:2021-09-23_b0d87f753c \
/bin/bash -c "make distclean"
function build_optiplex_9010 {
DEFCONFIG="configs/config.dell_optiplex_9010_sff_uefi_txt"
FW_VERSION=v0.1.0-rc1

cp $DEFCONFIG .config
generic_submodules
TARGET_BINARY="${BOARD}_${FW_VERSION}"
echo "Building Dasharo compatible with Dell OptiPlex 7010/9010 (version $FW_VERSION)"
build_coreboot $TARGET_BINARY
}

echo "Building Dasharo for Protectli $BOARD (version $FW_VERSION)"
function build_msi {
DEFCONFIG="configs/config.${BOARD}_$1"
FW_VERSION=$(cat ${DEFCONFIG} | grep CONFIG_LOCALVERSION | cut -d '=' -f 2 | tr -d '"')

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make olddefconfig && make -j$(nproc)"
generic_submodules
TARGET_BINARY= ${BOARD}_${FW_VERSION}_$1.rom
echo "Building Dasharo compatible with MSI PRO $2(WIFI) (version $FW_VERSION)"
build_coreboot $TARGET_BINARY
}

cp build/coreboot.rom protectli_${BOARD}_${FW_VERSION}.rom
if [ $? -eq 0 ]; then
echo "Result binary placed in $PWD/protectli_${BOARD}_${FW_VERSION}.rom"
sha256sum protectli_${BOARD}_${FW_VERSION}.rom > protectli_${BOARD}_${FW_VERSION}.rom.sha256
else
echo "Build failed!"
exit 1
fi
function build_protectli_vault {
DEFCONFIG="configs/config.protectli_${BOARD}"
FW_VERSION=$(cat ${DEFCONFIG} | grep CONFIG_LOCALVERSION | cut -d '=' -f 2 | tr -d '"')

protectli_submodules
TARGET_BINARY=protectli_${BOARD}_${FW_VERSION}.rom
echo "Building Dasharo for Protectli $BOARD (version $FW_VERSION)"
build_coreboot $TARGET_BINARY
}

function build_v1x10 {
DEFCONFIG="configs/config.protectli_vault_jsl_$1"
FW_VERSION=$(cat ${DEFCONFIG} | grep CONFIG_LOCALVERSION | cut -d '=' -f 2 | tr -d '"')

if [ ! -d 3rdparty/dasharo-blobs/protectli ]; then
git submodule update --init --checkout
fi

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make distclean"

cp $DEFCONFIG .config

protectli_submodules
TARGET_BINARY=protectli_$1_${FW_VERSION}.rom
echo "Building Dasharo for Protectli $1 (version $FW_VERSION)"

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make olddefconfig && make -j$(nproc)"

cp build/coreboot.rom protectli_$1_${FW_VERSION}.rom
if [ $? -eq 0 ]; then
echo "Result binary placed in $PWD/protectli_$1_${FW_VERSION}.rom"
sha256sum protectli_$1_${FW_VERSION}.rom > protectli_$1_${FW_VERSION}.rom.sha256
else
echo "Build failed!"
exit 1
fi
build_coreboot $TARGET_BINARY
}

function build_pcengines {
VARIANT=$1
DEFCONFIG="configs/config.pcengines_uefi_${VARIANT}"
FW_VERSION=$(cat ${DEFCONFIG} | grep CONFIG_LOCALVERSION | cut -d '=' -f 2 | tr -d '"')

# checkout several submodules needed by these boards (some others are checked
# out by coreboot's Makefile)
git submodule update --init --force --checkout \
3rdparty/dasharo-blobs \
3rdparty/vboot

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make distclean"

cp $DEFCONFIG .config

pcengines_submodules
TARGET_BINARY=pcengines_${VARIANT}_${FW_VERSION}.rom
echo "Building Dasharo for PC Engines ${VARIANT^^*} (version $FW_VERSION)"

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make olddefconfig && make -j$(nproc)"

cp build/coreboot.rom pcengines_${VARIANT}_${FW_VERSION}.rom
if [ $? -eq 0 ]; then
echo "Result binary placed in $PWD/pcengines_${VARIANT}_${FW_VERSION}.rom"
sha256sum pcengines_${VARIANT}_${FW_VERSION}.rom > pcengines_${VARIANT}_${FW_VERSION}.rom.sha256
else
echo "Build failed!"
exit 1
fi
build_coreboot $TARGET_BINARY
}

function build_qemu {
DEFCONFIG="configs/config.emulation_qemu_x86_q35_uefi${1:-}"
FW_VERSION=$(cat ${DEFCONFIG} | grep CONFIG_LOCALVERSION | cut -d '=' -f 2 | tr -d '"')

# checkout several submodules needed by these boards (some others are checked
# out by coreboot's Makefile)
git submodule update --init --force --checkout \
3rdparty/dasharo-blobs

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make distclean"

cp $DEFCONFIG .config

qemu_submodules
TARGET_BINARY=qemu_q35_${FW_VERSION}.rom
echo "Building Dasharo for QEMU Q35 (version $FW_VERSION)"
build_coreboot $TARGET_BINARY
}

docker run --rm -t -u $UID -v $PWD:/home/coreboot/coreboot \
-v $HOME/.ssh:/home/coreboot/.ssh \
-w /home/coreboot/coreboot coreboot/coreboot-sdk:$SDKVER \
/bin/bash -c "make olddefconfig && make -j$(nproc)"
function build_nv4x_adl {
DEFCONFIG="configs/config.novacustom_nv4x_adl"
FW_VERSION=$(cat ${DEFCONFIG} | grep CONFIG_LOCALVERSION | cut -d '=' -f 2 | tr -d '"')

cp build/coreboot.rom qemu_q35_${FW_VERSION}.rom
if [ $? -eq 0 ]; then
echo "Result binary placed in $PWD/qemu_q35_${FW_VERSION}.rom"
sha256sum qemu_q35_${FW_VERSION}.rom > qemu_q35_${FW_VERSION}.rom.sha256
else
echo "Build failed!"
exit 1
fi
build_ec novacustom nv4x_adl
generic_submodules
TARGET_BINARY=novacustom_nv4x_adl_$FW_VERSION
echo "Building Dasharo for Novacustom NV4x Adl (version $FW_VERSION)"
build_coreboot $TARGET_BINARY
}

CMD="$1"
Expand Down Expand Up @@ -289,6 +276,9 @@ case "$CMD" in
"qemu_full" | "QEMU_full" | "q35_full" | "Q35_full" )
build_qemu "_all_menus"
;;
"nv4x_adl" )
build_nv4x_adl
;;
*)
echo "Invalid command: \"$CMD\""
usage
Expand Down