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