Martin Roth | 516e3c2 | 2015-12-15 15:44:23 -0700 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | |
| 3 | coreboot_dir="coreboot_minnowmax" |
| 4 | coreboot_repo="http://review.coreboot.org/coreboot.git" |
| 5 | coreboot_commit_id="4013469c5078" |
| 6 | |
| 7 | fsp_dir="BAY_TRAIL_FSP_KIT" |
| 8 | fsp_package_file="BAY_TRAIL_FSP_KIT_GOLD3.tgz" |
| 9 | fsp_installer="BAY_TRAIL_FSP_KIT.se" |
| 10 | fsp_url="http://downloadmirror.intel.com/24496/eng/${fsp_package_file}" |
| 11 | fsp_checksum="7f47e663564cf57c07155b663330c996 *BAY_TRAIL_FSP_KIT_GOLD3.tgz" |
| 12 | |
| 13 | uefi_rom="MinnowBoard.MAX.X64.083.R01.bin" |
| 14 | uefi_dir="MinnowBoard.MAX.X64.083.R01" |
| 15 | uefi_package_file="MinnowBoard.MAX_.X64.083.R01.zip" |
| 16 | uefi_rom_url="http://firmware.intel.com/sites/default/files/$uefi_package_file" |
| 17 | uefi_checksum="cf1e9f8efbb6a6759638c0897921235b *MinnowBoard.MAX_.X64.083.R01.zip" |
| 18 | |
Martin Roth | f2b3431 | 2016-01-27 09:15:38 -0700 | [diff] [blame^] | 19 | final_checksum="" # issue in coreboot prevented reproducibility |
Martin Roth | 516e3c2 | 2015-12-15 15:44:23 -0700 | [diff] [blame] | 20 | |
| 21 | RED='\033[1;31m' |
| 22 | green='\033[0;32m' |
| 23 | GREEN='\033[1;32m' |
| 24 | blue='\033[0;34m' |
| 25 | BLUE='\033[1;34m' |
| 26 | NC='\033[0m' # No Color |
| 27 | |
| 28 | # shellcheck disable=SC2059 |
| 29 | error () |
| 30 | { |
| 31 | printf "${RED}ERROR: $1 ${NC}\n" >&2 |
| 32 | if [ -n "$2" ]; then printf "${RED}Removing $2 ${NC}\n"; rm -rf "./$2"; fi |
| 33 | exit 1 |
| 34 | } |
| 35 | |
| 36 | please_install() |
| 37 | { |
| 38 | test -r /etc/os-release && . /etc/os-release |
| 39 | case "$ID_LIKE" in |
| 40 | debian) solution="sudo apt-get install $1" ;; |
| 41 | suse) solution="sudo zypper install $1" ;; |
| 42 | *) solution="using your OS packaging system" ;; |
| 43 | esac |
| 44 | |
| 45 | error "Missing tool: Please install \'$1\' utility. (eg $solution)" |
| 46 | } |
| 47 | |
| 48 | searchtool() |
| 49 | { |
| 50 | # $1 short name |
| 51 | # $2 search string |
| 52 | # $3 soft fail if set |
| 53 | # result: file name of that tool on stdout |
| 54 | # or no output if nothing suitable was found |
| 55 | search=GNU |
| 56 | if [ -n "$2" ]; then |
| 57 | search="$2" |
| 58 | fi |
| 59 | for i in "$1" "g$1" "gnu$1"; do |
| 60 | if [ -x "$(which "$i" 2>/dev/null)" ]; then |
| 61 | if [ "$($i --version < /dev/null 2>&1 | grep -c "$search")" \ |
| 62 | -gt 0 ]; then |
| 63 | echo "$i" |
| 64 | return |
| 65 | fi |
| 66 | fi |
| 67 | done |
| 68 | please_install "$1" |
| 69 | [ -z "$3" ] && exit 1 |
| 70 | false |
| 71 | } |
| 72 | |
| 73 | # shellcheck disable=SC2059 |
| 74 | printf "${blue}Checking required tools: ${BLUE}m4 bison flex g++ wget md5sum unzip tar${NC}\n" |
| 75 | searchtool m4 > /dev/null |
| 76 | searchtool bison > /dev/null |
| 77 | searchtool flex flex > /dev/null |
| 78 | searchtool g++ "Free Software Foundation" nofail > /dev/null || \ |
| 79 | searchtool wget > /dev/null |
| 80 | searchtool md5sum > /dev/null |
| 81 | searchtool unzip > /dev/null |
| 82 | searchtool tar > /dev/null |
| 83 | # shellcheck disable=SC2059 |
| 84 | printf "${green}All tools present.${NC}\n\n" |
| 85 | |
| 86 | # shellcheck disable=SC2059 |
| 87 | if [ ! -d "$coreboot_dir" ]; then |
| 88 | printf "${blue}Fetching coreboot repository:${NC} " |
| 89 | git clone "$coreboot_repo" "$coreboot_dir" |
| 90 | if [ $? -ne 0 ] || [ ! -d "$coreboot_dir" ]; then error "coreboot repo failed to download." "$coreboot_dir"; fi |
| 91 | sleep 1 |
| 92 | printf "${green}coreboot repo downloaded successfully.${NC}\n" |
| 93 | fi |
| 94 | |
| 95 | pushd "./$coreboot_dir" || error "couldn't cd to $coreboot_dir" "$coreboot_dir" |
Martin Roth | f2b3431 | 2016-01-27 09:15:38 -0700 | [diff] [blame^] | 96 | git checkout "$coreboot_commit_id" || error "Couldn't checkout $coreboot_commit_id" |
Martin Roth | 516e3c2 | 2015-12-15 15:44:23 -0700 | [diff] [blame] | 97 | |
| 98 | # shellcheck disable=SC2059 |
| 99 | if [ ! -d "$fsp_dir" ]; then |
| 100 | printf "${blue}Downloading & setting up FSP${NC}\n" |
| 101 | if [ ! -f "$fsp_package_file" ]; then |
Martin Roth | f2b3431 | 2016-01-27 09:15:38 -0700 | [diff] [blame^] | 102 | wget "$fsp_url" || error "FSP file $fsp_package_file not downloaded" |
Martin Roth | 516e3c2 | 2015-12-15 15:44:23 -0700 | [diff] [blame] | 103 | echo "$fsp_checksum" > fsp_checksum.txt |
| 104 | md5sum --check fsp_checksum.txt || error "md5sum for $fsp_package_file failed." "$fsp_package_file" |
| 105 | fi |
| 106 | if [ ! -f "$fsp_installer" ]; then |
| 107 | tar xvf "$fsp_package_file" || error "Failed to extract $fsp_package_file" "$fsp_package_file" |
| 108 | fi |
| 109 | |
| 110 | chmod +x "$fsp_installer" |
| 111 | "./$fsp_installer" || error "Failed to run $fsp_installer successfully" "$fsp_installer" |
| 112 | printf "${green}FSP set up successfully.${NC}\n" |
| 113 | fi |
| 114 | |
| 115 | # shellcheck disable=SC2059 |
| 116 | if [ ! -f ./descriptor.bin ] || [ ! -f txe.bin ]; then |
| 117 | printf "${blue}Downloading / extracting Intel Firmware Descriptor & TXE${NC}\n" |
| 118 | if [ ! -f "$uefi_dir/$uefi_rom" ]; then |
| 119 | if [ ! -f "$uefi_package_file" ]; then |
Martin Roth | f2b3431 | 2016-01-27 09:15:38 -0700 | [diff] [blame^] | 120 | wget "$uefi_rom_url" || error "FSP file $uefi_package_file not downloaded" |
Martin Roth | 516e3c2 | 2015-12-15 15:44:23 -0700 | [diff] [blame] | 121 | echo "$uefi_checksum" > uefi_checksum.txt |
| 122 | md5sum --check uefi_checksum.txt || error "md5sum for $fsp_package_file failed." "$uefi_package_file" |
| 123 | fi |
| 124 | unzip "$uefi_package_file" || error "Could not unzip for $fsp_package_file" "$uefi_package_file" |
| 125 | fi |
| 126 | |
| 127 | if [ ! -f util/ifdtool/ifdtool ]; then |
| 128 | make -C util/ifdtool || error "Couldn't build ifdtool" |
| 129 | fi |
| 130 | util/ifdtool/ifdtool -x "$uefi_dir/$uefi_rom" || error "Couldn't extract intel firmware descriptor" "flashregion*" |
| 131 | mv flashregion_0_flashdescriptor.bin descriptor.bin || error "Couldn't rename firmware descriptor" "flashregion*" |
| 132 | mv flashregion_2_intel_me.bin txe.bin || error "Couldn't rename TXE" "flashregion*" |
| 133 | rm -f flashregion* |
| 134 | printf "${green}Intel Firmware Descriptor & TXE extracted successfully.${NC}\n\n" |
| 135 | fi |
| 136 | |
| 137 | # shellcheck disable=SC2059 |
| 138 | if [ -z "$XGCCPATH" ] && [ ! -f ./util/crossgcc/xgcc/bin/i386-elf-gcc ]; then |
| 139 | printf "\n${blue}Building coreboot toolchain - This can take a while.${NC}\n" |
| 140 | make crossgcc-i386 CPUS="$(nproc)" || error "coreboot toolchain build failed" "./util/crossgcc/xgcc" |
| 141 | printf "${green}coreboot toolchain build successfully.${NC}\n\n" |
| 142 | fi |
| 143 | |
| 144 | # shellcheck disable=SC2059 |
| 145 | printf "${blue}Building coreboot${NC}\n" |
| 146 | cat << EOF > .config |
| 147 | CONFIG_VENDOR_INTEL=y |
| 148 | CONFIG_VGA_BIOS=y |
| 149 | CONFIG_VGA_BIOS_FILE="BAY_TRAIL_FSP_KIT/Graphics/INTEL_EMGD.VBIOS_GOLD_VERSION_36_2_3_3698/Vga.dat" |
| 150 | CONFIG_HAVE_IFD_BIN=y |
| 151 | CONFIG_HAVE_ME_BIN=y |
| 152 | CONFIG_FSP_FILE="BAY_TRAIL_FSP_KIT/FSP/BAYTRAIL_FSP_GOLD_003_16-SEP-2014.fd" |
| 153 | CONFIG_BOARD_INTEL_MINNOWMAX=y |
| 154 | CONFIG_ENABLE_BUILTIN_COM1=y |
| 155 | CONFIG_CPU_MICROCODE_HEADER_FILES="BAY_TRAIL_FSP_KIT/Microcode/M0130673322.h BAY_TRAIL_FSP_KIT/Microcode/M0130679901.h" |
| 156 | CONFIG_IFD_BIN_PATH="descriptor.bin" |
| 157 | CONFIG_ME_BIN_PATH="txe.bin" |
| 158 | CONFIG_HAVE_FSP_BIN=y |
| 159 | CONFIG_CONSOLE_POST=y |
| 160 | # CONFIG_POST_IO is not set |
| 161 | CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME="Minnowboard Max" |
| 162 | CONFIG_SEABIOS_THREAD_OPTIONROMS=y |
| 163 | EOF |
| 164 | |
| 165 | make olddefconfig || "Make olddefconfig failed." ".config" |
| 166 | make clean |
| 167 | make || error "make failed" "build" |
| 168 | |
| 169 | # shellcheck disable=SC2059 |
| 170 | if [ -n "$final_checksum" ]; then |
| 171 | echo "$final_checksum" > final_checksum.txt |
| 172 | md5sum --check final_checksum.txt || error "md5sum for final rom (build/coreboot.rom) failed." |
| 173 | printf "${GREEN}coreboot build completed and checksummed successfully.\n\n" |
| 174 | else |
| 175 | md5sum -b build/coreboot.rom |
| 176 | printf "${GREEN}coreboot build completed successfully.\n\n" |
| 177 | fi |
| 178 | |
| 179 | # shellcheck disable=SC2059 |
| 180 | printf "${GREEN}Full 8MB rom available as ${coreboot_dir}/build/coreboot.rom${NC}\n" |
| 181 | printf "Flash MinnowBoard Max using dediprog with the command:\n" |
| 182 | printf " flashrom -p dediprog:voltage=1.8v -w %s/build/coreboot.rom\n" "${coreboot_dir}" |
Martin Roth | f2b3431 | 2016-01-27 09:15:38 -0700 | [diff] [blame^] | 183 | printf "For the MinnowBoard Turbot, use the command above, replacing '1.8v' with '3.5v'\n" |
Martin Roth | 516e3c2 | 2015-12-15 15:44:23 -0700 | [diff] [blame] | 184 | printf "Flash either board using a spi hook with the command:\n" |
| 185 | printf " flashrom -p ft2232_spi:type=2232h,port=A,divisor=4 -w %s/build/coreboot.rom\n\n" "${coreboot_dir}" |