| #! /bin/bash |
| |
| coreboot_dir="coreboot_minnowmax" |
| coreboot_repo="http://review.coreboot.org/coreboot.git" |
| coreboot_commit_id="4013469c5078" |
| |
| fsp_dir="BAY_TRAIL_FSP_KIT" |
| fsp_package_file="BAY_TRAIL_FSP_KIT_GOLD3.tgz" |
| fsp_installer="BAY_TRAIL_FSP_KIT.se" |
| fsp_url="http://downloadmirror.intel.com/24496/eng/${fsp_package_file}" |
| fsp_checksum="7f47e663564cf57c07155b663330c996 *BAY_TRAIL_FSP_KIT_GOLD3.tgz" |
| |
| uefi_rom="MinnowBoard.MAX.X64.083.R01.bin" |
| uefi_dir="MinnowBoard.MAX.X64.083.R01" |
| uefi_package_file="MinnowBoard.MAX_.X64.083.R01.zip" |
| uefi_rom_url="http://firmware.intel.com/sites/default/files/$uefi_package_file" |
| uefi_checksum="cf1e9f8efbb6a6759638c0897921235b *MinnowBoard.MAX_.X64.083.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_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="BAY_TRAIL_FSP_KIT/Graphics/INTEL_EMGD.VBIOS_GOLD_VERSION_36_2_3_3698/Vga.dat" |
| CONFIG_HAVE_IFD_BIN=y |
| CONFIG_HAVE_ME_BIN=y |
| CONFIG_FSP_FILE="BAY_TRAIL_FSP_KIT/FSP/BAYTRAIL_FSP_GOLD_003_16-SEP-2014.fd" |
| CONFIG_BOARD_INTEL_MINNOWMAX=y |
| CONFIG_ENABLE_BUILTIN_COM1=y |
| CONFIG_CPU_MICROCODE_HEADER_FILES="BAY_TRAIL_FSP_KIT/Microcode/M0130673322.h BAY_TRAIL_FSP_KIT/Microcode/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}" |