| #! /bin/bash |
| |
| coreboot_dir="coreboot_minnowmax" |
| coreboot_repo="http://review.coreboot.org/coreboot.git" |
| coreboot_tag="4.5" |
| |
| # todo: fsp_repo="https://github.com/IntelFsp/FSP.git" |
| fsp_package_dir="Baytrail_FSP_Gold4" |
| fsp_package_file="Baytrail_FSP_Gold4.tgz" |
| fsp_installer="Baytrail_FSP_Gold4.se" |
| fsp_url="http://downloadmirror.intel.com/25063/eng/${fsp_package_file}" |
| fsp_checksum="7825c1eb9c54099dedbe7778c3c0ccd6 *Baytrail_FSP_Gold4.tgz" |
| |
| fsp_binary_dir="$fsp_package_dir/FSP" |
| fsp_binary="BAYTRAIL_FSP_GOLD_004_22-MAY-2015.fd" |
| vbios_dir="$fsp_package_dir/Graphics/vbios" |
| vbios_binary="Vga.dat" |
| |
| ucode_dir="$fsp_package_dir/Microcode" |
| |
| uefi_rom="MNW2MAX1.X64.0093.R01.1608031710.bin" |
| uefi_dir="." |
| uefi_package_file="MinnowBoard.MAX_.X64.93.R01.zip" |
| uefi_rom_url="http://firmware.intel.com/sites/default/files/$uefi_package_file" |
| uefi_checksum="1260b758e56eb4612ce048e1fd524305 *MinnowBoard.MAX_.X64.93.R01.zip" |
| |
| final_checksum="" # issue in coreboot prevented reproducibility |
| |
| RED='\033[1;31m' |
| green='\033[0;32m' |
| GREEN='\033[1;32m' |
| blue='\033[0;34m' |
| BLUE='\033[1;34m' |
| NC='\033[0m' # No Color |
| |
| # shellcheck disable=SC2059 |
| error () |
| { |
| printf "${RED}ERROR: $1 ${NC}\n" >&2 |
| if [ -n "$2" ]; then printf "${RED}Removing $2 ${NC}\n"; rm -rf "./$2"; fi |
| exit 1 |
| } |
| |
| please_install() |
| { |
| test -r /etc/os-release && . /etc/os-release |
| case "$ID_LIKE" in |
| debian) solution="sudo apt-get install $1" ;; |
| suse) solution="sudo zypper install $1" ;; |
| *) solution="using your OS packaging system" ;; |
| esac |
| |
| error "Missing tool: Please install \'$1\' utility. (eg $solution)" |
| } |
| |
| searchtool() |
| { |
| # $1 short name |
| # $2 search string |
| # $3 soft fail if set |
| # result: file name of that tool on stdout |
| # or no output if nothing suitable was found |
| search=GNU |
| if [ -n "$2" ]; then |
| search="$2" |
| fi |
| for i in "$1" "g$1" "gnu$1"; do |
| if [ -x "$(which "$i" 2>/dev/null)" ]; then |
| if [ "$($i --version < /dev/null 2>&1 | grep -c "$search")" \ |
| -gt 0 ]; then |
| echo "$i" |
| return |
| fi |
| fi |
| done |
| please_install "$1" |
| [ -z "$3" ] && exit 1 |
| false |
| } |
| |
| # shellcheck disable=SC2059 |
| printf "${blue}Checking required tools: ${BLUE}m4 bison flex g++ wget md5sum unzip tar${NC}\n" |
| searchtool m4 > /dev/null |
| searchtool bison > /dev/null |
| searchtool flex flex > /dev/null |
| searchtool g++ "Free Software Foundation" nofail > /dev/null || \ |
| searchtool wget > /dev/null |
| searchtool md5sum > /dev/null |
| searchtool unzip > /dev/null |
| searchtool tar > /dev/null |
| # shellcheck disable=SC2059 |
| printf "${green}All tools present.${NC}\n\n" |
| |
| # shellcheck disable=SC2059 |
| if [ ! -d "$coreboot_dir" ]; then |
| printf "${blue}Fetching coreboot repository:${NC} " |
| git clone "$coreboot_repo" "$coreboot_dir" |
| if [ $? -ne 0 ] || [ ! -d "$coreboot_dir" ]; then error "coreboot repo failed to download." "$coreboot_dir"; fi |
| sleep 1 |
| printf "${green}coreboot repo downloaded successfully.${NC}\n" |
| fi |
| |
| pushd "./$coreboot_dir" || error "couldn't cd to $coreboot_dir" "$coreboot_dir" |
| git checkout "$coreboot_commit_id" || error "Couldn't checkout $coreboot_commit_id" |
| |
| # shellcheck disable=SC2059 |
| if [ ! -d "$fsp_package_dir" ]; then |
| printf "${blue}Downloading & setting up FSP${NC}\n" |
| if [ ! -f "$fsp_package_file" ]; then |
| wget "$fsp_url" || error "FSP file $fsp_package_file not downloaded" |
| echo "$fsp_checksum" > fsp_checksum.txt |
| md5sum --check fsp_checksum.txt || error "md5sum for $fsp_package_file failed." "$fsp_package_file" |
| fi |
| if [ ! -f "$fsp_installer" ]; then |
| tar xvf "$fsp_package_file" || error "Failed to extract $fsp_package_file" "$fsp_package_file" |
| fi |
| |
| chmod +x "$fsp_installer" |
| "./$fsp_installer" || error "Failed to run $fsp_installer successfully" "$fsp_installer" |
| printf "${green}FSP set up successfully.${NC}\n" |
| fi |
| |
| # shellcheck disable=SC2059 |
| if [ ! -f ./descriptor.bin ] || [ ! -f txe.bin ]; then |
| printf "${blue}Downloading / extracting Intel Firmware Descriptor & TXE${NC}\n" |
| if [ ! -f "$uefi_dir/$uefi_rom" ]; then |
| if [ ! -f "$uefi_package_file" ]; then |
| wget "$uefi_rom_url" || error "FSP file $uefi_package_file not downloaded" |
| echo "$uefi_checksum" > uefi_checksum.txt |
| md5sum --check uefi_checksum.txt || error "md5sum for $fsp_package_file failed." "$uefi_package_file" |
| fi |
| unzip "$uefi_package_file" || error "Could not unzip for $fsp_package_file" "$uefi_package_file" |
| fi |
| |
| if [ ! -f util/ifdtool/ifdtool ]; then |
| make -C util/ifdtool || error "Couldn't build ifdtool" |
| fi |
| util/ifdtool/ifdtool -x "$uefi_dir/$uefi_rom" || error "Couldn't extract intel firmware descriptor" "flashregion*" |
| mv flashregion_0_flashdescriptor.bin descriptor.bin || error "Couldn't rename firmware descriptor" "flashregion*" |
| mv flashregion_2_intel_me.bin txe.bin || error "Couldn't rename TXE" "flashregion*" |
| rm -f flashregion* |
| printf "${green}Intel Firmware Descriptor & TXE extracted successfully.${NC}\n\n" |
| fi |
| |
| # shellcheck disable=SC2059 |
| if [ -z "$XGCCPATH" ] && [ ! -f ./util/crossgcc/xgcc/bin/i386-elf-gcc ]; then |
| printf "\n${blue}Building coreboot toolchain - This can take a while.${NC}\n" |
| make crossgcc-i386 CPUS="$(nproc)" || error "coreboot toolchain build failed" "./util/crossgcc/xgcc" |
| printf "${green}coreboot toolchain build successfully.${NC}\n\n" |
| fi |
| |
| # shellcheck disable=SC2059 |
| printf "${blue}Building coreboot${NC}\n" |
| cat << EOF > .config |
| CONFIG_VENDOR_INTEL=y |
| CONFIG_VGA_BIOS=y |
| CONFIG_VGA_BIOS_FILE="$vbios_dir/$vbios_binary" |
| CONFIG_HAVE_IFD_BIN=y |
| CONFIG_HAVE_ME_BIN=y |
| CONFIG_FSP_FILE="$fsp_binary_dir/$fsp_binary" |
| CONFIG_BOARD_INTEL_MINNOWMAX=y |
| CONFIG_ENABLE_BUILTIN_COM1=y |
| CONFIG_CPU_MICROCODE_HEADER_FILES="$ucode_dir/M013067222D.h $ucode_dir/M0130673321.h $ucode_dir/M0130678815.h $ucode_dir/M0130679901.h" |
| CONFIG_IFD_BIN_PATH="descriptor.bin" |
| CONFIG_ME_BIN_PATH="txe.bin" |
| CONFIG_HAVE_FSP_BIN=y |
| CONFIG_CONSOLE_POST=y |
| # CONFIG_POST_IO is not set |
| CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME="Minnowboard Max" |
| CONFIG_SEABIOS_THREAD_OPTIONROMS=y |
| EOF |
| |
| make olddefconfig || "Make olddefconfig failed." ".config" |
| make clean |
| make || error "make failed" "build" |
| |
| # shellcheck disable=SC2059 |
| if [ -n "$final_checksum" ]; then |
| echo "$final_checksum" > final_checksum.txt |
| md5sum --check final_checksum.txt || error "md5sum for final rom (build/coreboot.rom) failed." |
| printf "${GREEN}coreboot build completed and checksummed successfully.\n\n" |
| else |
| md5sum -b build/coreboot.rom |
| printf "${GREEN}coreboot build completed successfully.\n\n" |
| fi |
| |
| # shellcheck disable=SC2059 |
| printf "${GREEN}Full 8MB rom available as ${coreboot_dir}/build/coreboot.rom${NC}\n" |
| printf "Flash MinnowBoard Max using dediprog with the command:\n" |
| printf " flashrom -p dediprog:voltage=1.8v -w %s/build/coreboot.rom\n" "${coreboot_dir}" |
| printf "For the MinnowBoard Turbot, use the command above, replacing '1.8v' with '3.5v'\n" |
| printf "Flash either board using a spi hook with the command:\n" |
| printf " flashrom -p ft2232_spi:type=2232h,port=A,divisor=4 -w %s/build/coreboot.rom\n\n" "${coreboot_dir}" |