blob: 1165d224847dab728c013f7bb3c6feb49aee0ce9 [file] [log] [blame]
Martin Roth516e3c22015-12-15 15:44:23 -07001#! /bin/bash
2
3coreboot_dir="coreboot_minnowmax"
4coreboot_repo="http://review.coreboot.org/coreboot.git"
5coreboot_commit_id="4013469c5078"
6
7fsp_dir="BAY_TRAIL_FSP_KIT"
8fsp_package_file="BAY_TRAIL_FSP_KIT_GOLD3.tgz"
9fsp_installer="BAY_TRAIL_FSP_KIT.se"
10fsp_url="http://downloadmirror.intel.com/24496/eng/${fsp_package_file}"
11fsp_checksum="7f47e663564cf57c07155b663330c996 *BAY_TRAIL_FSP_KIT_GOLD3.tgz"
12
13uefi_rom="MinnowBoard.MAX.X64.083.R01.bin"
14uefi_dir="MinnowBoard.MAX.X64.083.R01"
15uefi_package_file="MinnowBoard.MAX_.X64.083.R01.zip"
16uefi_rom_url="http://firmware.intel.com/sites/default/files/$uefi_package_file"
17uefi_checksum="cf1e9f8efbb6a6759638c0897921235b *MinnowBoard.MAX_.X64.083.R01.zip"
18
Martin Rothf2b34312016-01-27 09:15:38 -070019final_checksum="" # issue in coreboot prevented reproducibility
Martin Roth516e3c22015-12-15 15:44:23 -070020
21RED='\033[1;31m'
22green='\033[0;32m'
23GREEN='\033[1;32m'
24blue='\033[0;34m'
25BLUE='\033[1;34m'
26NC='\033[0m' # No Color
27
28# shellcheck disable=SC2059
29error ()
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
36please_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
48searchtool()
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
74printf "${blue}Checking required tools: ${BLUE}m4 bison flex g++ wget md5sum unzip tar${NC}\n"
75searchtool m4 > /dev/null
76searchtool bison > /dev/null
77searchtool flex flex > /dev/null
78searchtool g++ "Free Software Foundation" nofail > /dev/null || \
79searchtool wget > /dev/null
80searchtool md5sum > /dev/null
81searchtool unzip > /dev/null
82searchtool tar > /dev/null
83# shellcheck disable=SC2059
84printf "${green}All tools present.${NC}\n\n"
85
86# shellcheck disable=SC2059
87if [ ! -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"
93fi
94
95pushd "./$coreboot_dir" || error "couldn't cd to $coreboot_dir" "$coreboot_dir"
Martin Rothf2b34312016-01-27 09:15:38 -070096git checkout "$coreboot_commit_id" || error "Couldn't checkout $coreboot_commit_id"
Martin Roth516e3c22015-12-15 15:44:23 -070097
98# shellcheck disable=SC2059
99if [ ! -d "$fsp_dir" ]; then
100 printf "${blue}Downloading & setting up FSP${NC}\n"
101 if [ ! -f "$fsp_package_file" ]; then
Martin Rothf2b34312016-01-27 09:15:38 -0700102 wget "$fsp_url" || error "FSP file $fsp_package_file not downloaded"
Martin Roth516e3c22015-12-15 15:44:23 -0700103 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"
113fi
114
115# shellcheck disable=SC2059
116if [ ! -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 Rothf2b34312016-01-27 09:15:38 -0700120 wget "$uefi_rom_url" || error "FSP file $uefi_package_file not downloaded"
Martin Roth516e3c22015-12-15 15:44:23 -0700121 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"
135fi
136
137# shellcheck disable=SC2059
138if [ -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"
142fi
143
144# shellcheck disable=SC2059
145printf "${blue}Building coreboot${NC}\n"
146cat << EOF > .config
147CONFIG_VENDOR_INTEL=y
148CONFIG_VGA_BIOS=y
149CONFIG_VGA_BIOS_FILE="BAY_TRAIL_FSP_KIT/Graphics/INTEL_EMGD.VBIOS_GOLD_VERSION_36_2_3_3698/Vga.dat"
150CONFIG_HAVE_IFD_BIN=y
151CONFIG_HAVE_ME_BIN=y
152CONFIG_FSP_FILE="BAY_TRAIL_FSP_KIT/FSP/BAYTRAIL_FSP_GOLD_003_16-SEP-2014.fd"
153CONFIG_BOARD_INTEL_MINNOWMAX=y
154CONFIG_ENABLE_BUILTIN_COM1=y
155CONFIG_CPU_MICROCODE_HEADER_FILES="BAY_TRAIL_FSP_KIT/Microcode/M0130673322.h BAY_TRAIL_FSP_KIT/Microcode/M0130679901.h"
156CONFIG_IFD_BIN_PATH="descriptor.bin"
157CONFIG_ME_BIN_PATH="txe.bin"
158CONFIG_HAVE_FSP_BIN=y
159CONFIG_CONSOLE_POST=y
160# CONFIG_POST_IO is not set
161CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME="Minnowboard Max"
162CONFIG_SEABIOS_THREAD_OPTIONROMS=y
163EOF
164
165make olddefconfig || "Make olddefconfig failed." ".config"
166make clean
167make || error "make failed" "build"
168
169# shellcheck disable=SC2059
170if [ -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"
174else
175 md5sum -b build/coreboot.rom
176 printf "${GREEN}coreboot build completed successfully.\n\n"
177fi
178
179# shellcheck disable=SC2059
180printf "${GREEN}Full 8MB rom available as ${coreboot_dir}/build/coreboot.rom${NC}\n"
181printf "Flash MinnowBoard Max using dediprog with the command:\n"
182printf " flashrom -p dediprog:voltage=1.8v -w %s/build/coreboot.rom\n" "${coreboot_dir}"
Martin Rothf2b34312016-01-27 09:15:38 -0700183printf "For the MinnowBoard Turbot, use the command above, replacing '1.8v' with '3.5v'\n"
Martin Roth516e3c22015-12-15 15:44:23 -0700184printf "Flash either board using a spi hook with the command:\n"
185printf " flashrom -p ft2232_spi:type=2232h,port=A,divisor=4 -w %s/build/coreboot.rom\n\n" "${coreboot_dir}"