Replace if clauses with functions
This commit is contained in:
parent
ccc61082d2
commit
ac7387711c
107
cb-helper
107
cb-helper
@ -1,22 +1,26 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
base_directory="$(dirname $0)"
|
||||||
|
|
||||||
# Download stuffs
|
# Download stuffs
|
||||||
if [ "$1" == "download_code" ]; then
|
function download_code() {
|
||||||
|
|
||||||
# Coreboot
|
# Coreboot
|
||||||
if [ ! -d ./coreboot ]; then
|
if [ ! -d ./coreboot ]; then
|
||||||
printf "Downloading Coreboot\n"
|
printf "Downloading Coreboot\n"
|
||||||
git clone --recursive http://review.coreboot.org/coreboot.git ./coreboot
|
git clone --recursive http://review.coreboot.org/coreboot.git ./coreboot
|
||||||
|
cd ./coreboot
|
||||||
|
# Checkout this specific version
|
||||||
|
git checkout 66a0f55c2e2c6e042c58ae423901d7e41c5a2c84
|
||||||
|
cd $base_directory
|
||||||
else
|
else
|
||||||
printf "Coreboot repository is already present\n"
|
printf "Coreboot repository is already present\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# GRUB
|
# GRUB
|
||||||
if [ ! -d ./grub ]; then
|
if [ ! -d ./grub ]; then
|
||||||
printf "Downloading GRUB\n"
|
printf "Downloading GRUB\n"
|
||||||
git clone git://git.savannah.gnu.org/grub.git ./grub
|
git clone git://git.savannah.gnu.org/grub.git ./grub
|
||||||
|
|
||||||
# Checkout this specific version
|
# Checkout this specific version
|
||||||
cd ./grub
|
cd ./grub
|
||||||
git checkout "tags/2.02"
|
git checkout "tags/2.02"
|
||||||
@ -24,7 +28,6 @@ if [ "$1" == "download_code" ]; then
|
|||||||
else
|
else
|
||||||
printf "GRUB repository is already present\n"
|
printf "GRUB repository is already present\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# me_cleaner
|
# me_cleaner
|
||||||
if [ ! -d ./me_cleaner ]; then
|
if [ ! -d ./me_cleaner ]; then
|
||||||
printf "Downloading me_cleaner\n"
|
printf "Downloading me_cleaner\n"
|
||||||
@ -32,40 +35,34 @@ if [ "$1" == "download_code" ]; then
|
|||||||
else
|
else
|
||||||
printf "me_cleaner repository is already present\n"
|
printf "me_cleaner repository is already present\n"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Build Coreboot Utilities
|
# Build Coreboot Utilities
|
||||||
elif [ "$1" == "build_utils" ]; then
|
function build_utils() {
|
||||||
|
|
||||||
if [ ! -d "coreboot/.git" ]; then
|
if [ ! -d "coreboot/.git" ]; then
|
||||||
printf "No Coreboot repository found in coreboot/\nDownload the code first\n"
|
printf "No Coreboot repository found in coreboot/\nDownload the code first\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build ifdtool for stock BIOS splitting
|
# Build ifdtool for stock BIOS splitting
|
||||||
cd coreboot/util/ifdtool
|
cd coreboot/util/ifdtool
|
||||||
make -j${nproc}
|
make -j${nproc}
|
||||||
cd ../../../
|
cd ../../../
|
||||||
|
|
||||||
# Build cbfstool for managing Coreboot's filesystem
|
# Build cbfstool for managing Coreboot's filesystem
|
||||||
cd coreboot/util/cbfstool
|
cd coreboot/util/cbfstool
|
||||||
make -j${nproc}
|
make -j${nproc}
|
||||||
cd ../../../
|
cd ../../../
|
||||||
|
}
|
||||||
|
|
||||||
# Split the stock rom and organize the parts
|
# Split the stock rom and organize the parts
|
||||||
elif [ "$1" == "split_bios" ]; then
|
function split_bios() {
|
||||||
|
|
||||||
if [ ! -f "binaries/bios.bin" ]; then
|
if [ ! -f "binaries/bios.bin" ]; then
|
||||||
printf "No stock bios (bios.bin) file found in binaries/\n"
|
printf "No stock bios (bios.bin) file found in binaries/\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "coreboot/util/ifdtool/ifdtool" ]; then
|
if [ ! -f "coreboot/util/ifdtool/ifdtool" ]; then
|
||||||
printf "No ifdtool present, build the Coreboot utils first\n"
|
printf "No ifdtool present, build the Coreboot utils first\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd binaries/
|
cd binaries/
|
||||||
../coreboot/util/ifdtool/ifdtool -x bios.bin
|
../coreboot/util/ifdtool/ifdtool -x bios.bin
|
||||||
mv flashregion_0_flashdescriptor.bin descriptor.bin
|
mv flashregion_0_flashdescriptor.bin descriptor.bin
|
||||||
@ -73,102 +70,82 @@ elif [ "$1" == "split_bios" ]; then
|
|||||||
mv flashregion_2_intel_me.bin me.bin
|
mv flashregion_2_intel_me.bin me.bin
|
||||||
mv flashregion_3_gbe.bin gbe.bin
|
mv flashregion_3_gbe.bin gbe.bin
|
||||||
cd ..
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
# Neuter Intel ME
|
# Neuter Intel ME
|
||||||
elif [ "$1" == "neuter_me" ]; then
|
function neuter_me() {
|
||||||
|
|
||||||
if [ ! -f "binaries/me.bin" ]; then
|
if [ ! -f "binaries/me.bin" ]; then
|
||||||
printf "No Intel ME (me.bin) binary found in binaries/\n"
|
printf "No Intel ME (me.bin) binary found in binaries/\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp binaries/me.bin binaries/me_neutered.bin
|
cp binaries/me.bin binaries/me_neutered.bin
|
||||||
python3 me_cleaner/me_cleaner.py binaries/me_neutered.bin
|
python3 me_cleaner/me_cleaner.py binaries/me_neutered.bin
|
||||||
|
}
|
||||||
|
|
||||||
# Prepare Coreboot for compilation
|
# Prepare Coreboot for compilation
|
||||||
elif [ "$1" == "pre_build_coreboot" ]; then
|
function pre_build_coreboot() {
|
||||||
|
|
||||||
# Copy the config
|
# Copy the config
|
||||||
cp "config/coreboot.config" coreboot/.config
|
cp "config/coreboot.config" coreboot/.config
|
||||||
|
|
||||||
# Goto the Coreboot directory
|
# Goto the Coreboot directory
|
||||||
cd coreboot
|
cd coreboot
|
||||||
|
|
||||||
# Build toolchain
|
# Build toolchain
|
||||||
make crossgcc-i386 CPUS=${nproc} -b
|
make crossgcc-i386 CPUS=${nproc} -b
|
||||||
|
|
||||||
# Build IASL
|
# Build IASL
|
||||||
make -j${nproc} iasl
|
make -j${nproc} iasl
|
||||||
|
|
||||||
# Get back
|
# Get back
|
||||||
cd ..
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
# Build Coreboot
|
# Build Coreboot
|
||||||
elif [ "$1" == "build_coreboot" ]; then
|
function build_coreboot() {
|
||||||
|
|
||||||
# Goto the coreboot directory
|
# Goto the coreboot directory
|
||||||
cd coreboot
|
cd coreboot
|
||||||
|
|
||||||
# Clean last build
|
# Clean last build
|
||||||
make clean
|
make clean
|
||||||
rm ../out/coreboot.rom
|
rm ../out/coreboot.rom
|
||||||
|
|
||||||
# Just make
|
# Just make
|
||||||
make -j${nproc} || make -j${nproc}
|
make -j${nproc} || make -j${nproc}
|
||||||
|
|
||||||
# Exit if failed
|
# Exit if failed
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
printf "Failed to build Coreboot.\nExiting...\n"
|
printf "Failed to build Coreboot.\nExiting...\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get back
|
# Get back
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
# Copy the resulting binary to a more accessible folder
|
# Copy the resulting binary to a more accessible folder
|
||||||
if [ ! -d out/ ]; then mkdir out/; fi
|
if [ ! -d out/ ]; then mkdir out/; fi
|
||||||
mv coreboot/build/coreboot.rom out/coreboot.rom
|
mv coreboot/build/coreboot.rom out/coreboot.rom
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Build GRUB
|
# Build GRUB
|
||||||
elif [ "$1" == "build_grub" ]; then
|
function build_grub() {
|
||||||
|
|
||||||
# Check if the GRUB code is present
|
# Check if the GRUB code is present
|
||||||
if [ ! -d "grub/.git" ]; then
|
if [ ! -d "grub/.git" ]; then
|
||||||
printf "No GRUB repository found in grub/\nDownload the code first\n"
|
printf "No GRUB repository found in grub/\nDownload the code first\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Change title just for goofs
|
# Change title just for goofs
|
||||||
sed -i "s/_(\"GNU GRUB version %s\"), PACKAGE_VERSION/\"COREBOOT\"/g" grub/grub-core/normal/main.c
|
sed -i "s/_(\"GNU GRUB version %s\"), PACKAGE_VERSION/\"COREBOOT\"/g" grub/grub-core/normal/main.c
|
||||||
|
|
||||||
# Copy the config
|
# Copy the config
|
||||||
cp "config/grub.config" "grub/.config"
|
cp "config/grub.config" "grub/.config"
|
||||||
|
|
||||||
# Clean last build
|
# Clean last build
|
||||||
cd grub
|
cd grub
|
||||||
make clean
|
make clean
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
# Build GRUB
|
# Build GRUB
|
||||||
cd grub
|
cd grub
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure --with-platform=coreboot --disable-werror
|
./configure --with-platform=coreboot --disable-werror
|
||||||
make -j${nproc}
|
make -j${nproc}
|
||||||
cd ..
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
# Assemble the GRUB payload
|
# Assemble the GRUB payload
|
||||||
elif [ "$1" == "assemble_grub" ]; then
|
function assemble_grup() {
|
||||||
|
|
||||||
printf "Assembling the GRUB payload\n"
|
printf "Assembling the GRUB payload\n"
|
||||||
|
|
||||||
# Load modules config
|
# Load modules config
|
||||||
source "config/grub_modules.conf"
|
source "config/grub_modules.conf"
|
||||||
|
|
||||||
# Assemble GRUB
|
# Assemble GRUB
|
||||||
grub/grub-mkstandalone \
|
grub/grub-mkstandalone \
|
||||||
--grub-mkimage="grub/grub-mkimage" \
|
--grub-mkimage="grub/grub-mkimage" \
|
||||||
@ -181,115 +158,95 @@ elif [ "$1" == "assemble_grub" ]; then
|
|||||||
/boot/grub/grub.cfg="config/grub_memdisk.cfg" \
|
/boot/grub/grub.cfg="config/grub_memdisk.cfg" \
|
||||||
/dejavusansmono.pf2="misc/dejavusansmono_24bold.pf2" \
|
/dejavusansmono.pf2="misc/dejavusansmono_24bold.pf2" \
|
||||||
/boot/grub/layouts/usqwerty.gkb="misc/usqwerty.gkb"
|
/boot/grub/layouts/usqwerty.gkb="misc/usqwerty.gkb"
|
||||||
|
}
|
||||||
|
|
||||||
# Configure SeaBIOS to chainload with GRUB
|
# Configure SeaBIOS to chainload with GRUB
|
||||||
elif [ "$1" == "config_seabios" ]; then
|
function config_seabios() {
|
||||||
|
|
||||||
printf "Configure SeaBIOS\n"
|
printf "Configure SeaBIOS\n"
|
||||||
|
|
||||||
if [ ! -f "out/coreboot.rom" ]; then
|
if [ ! -f "out/coreboot.rom" ]; then
|
||||||
printf "No Coreboot image found.\nBuild Coreboot first.\n"
|
printf "No Coreboot image found.\nBuild Coreboot first.\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set GRUB as the default boot device
|
# Set GRUB as the default boot device
|
||||||
printf "/rom@img/grub2\n" > "out/bootorder"
|
printf "/rom@img/grub2\n" > "out/bootorder"
|
||||||
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add -f "out/bootorder" -n bootorder -t raw
|
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add -f "out/bootorder" -n bootorder -t raw
|
||||||
rm -f "out/bootorder"
|
rm -f "out/bootorder"
|
||||||
|
|
||||||
# Hide SeaBIOS
|
# Hide SeaBIOS
|
||||||
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add-int -i 0 -n etc/show-boot-menu
|
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add-int -i 0 -n etc/show-boot-menu
|
||||||
|
|
||||||
# Don't load anything else
|
# Don't load anything else
|
||||||
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add-int -i 0 -n etc/pci-optionrom-exec
|
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add-int -i 0 -n etc/pci-optionrom-exec
|
||||||
|
|
||||||
# Print the contents of the CBFS volume
|
# Print the contents of the CBFS volume
|
||||||
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" print
|
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" print
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Install and config GRUB
|
# Install and config GRUB
|
||||||
elif [ "$1" == "install_grub" ]; then
|
function install_grub() {
|
||||||
|
|
||||||
printf "Install GRUB in the CBFS volume\n"
|
printf "Install GRUB in the CBFS volume\n"
|
||||||
|
|
||||||
if [ ! -f "out/coreboot.rom" ]; then
|
if [ ! -f "out/coreboot.rom" ]; then
|
||||||
printf "No Coreboot image found.\nBuild Coreboot first.\n"
|
printf "No Coreboot image found.\nBuild Coreboot first.\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Compress and add GRUB payload
|
# Compress and add GRUB payload
|
||||||
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add-payload -c lzma -f "out/grub.elf" -n img/grub2 && rm "out/grub.elf"
|
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add-payload -c lzma -f "out/grub.elf" -n img/grub2 && rm "out/grub.elf"
|
||||||
|
|
||||||
# Add grub.cfg
|
# Add grub.cfg
|
||||||
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add -f "config/grub.cfg" -n grub.cfg -t raw
|
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" add -f "config/grub.cfg" -n grub.cfg -t raw
|
||||||
|
|
||||||
# Print the contents of the CBFS volume
|
# Print the contents of the CBFS volume
|
||||||
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" print
|
coreboot/util/cbfstool/cbfstool "out/coreboot.rom" print
|
||||||
|
}
|
||||||
|
|
||||||
# Flashing activities
|
# Flashing activities
|
||||||
elif [ "$1" == "flash" ]; then
|
function flash() {
|
||||||
|
|
||||||
# Define which programmer to use
|
# Define which programmer to use
|
||||||
case "$3" in
|
case "$3" in
|
||||||
|
|
||||||
# Internal
|
# Internal
|
||||||
"internal" )
|
"internal" )
|
||||||
programmer="internal:laptop=force_I_want_a_brick"
|
programmer="internal:laptop=force_I_want_a_brick"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# Raspberry Pi
|
# Raspberry Pi
|
||||||
"rpi" )
|
"rpi" )
|
||||||
programmer="linux_spi:dev=/dev/spidev0.0"
|
programmer="linux_spi:dev=/dev/spidev0.0"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# Arduino Boards with Xu2 USB chips
|
# Arduino Boards with Xu2 USB chips
|
||||||
"u2" )
|
"u2" )
|
||||||
programmer="serprog:dev=/dev/ttyACM0:115200"
|
programmer="serprog:dev=/dev/ttyACM0:115200"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# Arduino Boards with FTDI USB chips
|
# Arduino Boards with FTDI USB chips
|
||||||
"ftdi" )
|
"ftdi" )
|
||||||
programmer="serprog:dev=/dev/ttyUSB0:2000000"
|
programmer="serprog:dev=/dev/ttyUSB0:2000000"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# Exit if no programmer is specified
|
# Exit if no programmer is specified
|
||||||
* )
|
* )
|
||||||
printf "You must specify the programmer\n"
|
printf "You must specify the programmer\n"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Write to the flash chip
|
# Write to the flash chip
|
||||||
if [ "$2" == "write" ]; then
|
if [ "$2" == "write" ]; then
|
||||||
|
|
||||||
# Exit if Coreboot hasn't been successfully compiled yet
|
# Exit if Coreboot hasn't been successfully compiled yet
|
||||||
if [ ! -f "out/coreboot.rom" ]; then
|
if [ ! -f "out/coreboot.rom" ]; then
|
||||||
printf "Build Coreboot first\n"
|
printf "Build Coreboot first\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
flashrom -p $programmer -w "out/coreboot.rom"
|
flashrom -p $programmer -w "out/coreboot.rom"
|
||||||
|
|
||||||
# Do consecutive reads of the flash chip and compare them
|
# Do consecutive reads of the flash chip and compare them
|
||||||
elif [ "$2" == "read" ]; then
|
elif [ "$2" == "read" ]; then
|
||||||
mkdir binaries/reads
|
mkdir binaries/reads
|
||||||
|
|
||||||
for i in {1..5}; do
|
for i in {1..5}; do
|
||||||
flashrom -p $programmer -r "binaries/reads/bios$i.bin"
|
flashrom -p $programmer -r "binaries/reads/bios$i.bin"
|
||||||
md5sum "binaries/reads/*.bin"
|
md5sum "binaries/reads/*.bin"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check if the flash chip is detected
|
# Check if the flash chip is detected
|
||||||
elif [ "$2" == "check" ]; then
|
elif [ "$2" == "check" ]; then
|
||||||
flashrom -p $programmer
|
flashrom -p $programmer
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run operation
|
||||||
|
if [[ $1 != "" ]]; then
|
||||||
|
eval "$1"
|
||||||
# Exit if no operation is specified
|
# Exit if no operation is specified
|
||||||
else
|
else
|
||||||
printf "No operation specified\n"
|
printf "No operation specified\n"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user