blob: 94da0bb0eab7dc76f97f60577fc5198e66448e41 [file] [log] [blame]
Marshall Dawson483081e2016-11-18 20:45:42 -05001#! /bin/bash
2
3coreboot_dir="coreboot_minnowmax"
4coreboot_repo="http://review.coreboot.org/coreboot.git"
5coreboot_tag="4.5"
6
7# todo: fsp_repo="https://github.com/IntelFsp/FSP.git"
8fsp_package_dir="Baytrail_FSP_Gold4"
9fsp_package_file="Baytrail_FSP_Gold4.tgz"
10fsp_installer="Baytrail_FSP_Gold4.se"
11fsp_url="http://downloadmirror.intel.com/25063/eng/${fsp_package_file}"
12fsp_checksum="7825c1eb9c54099dedbe7778c3c0ccd6 *Baytrail_FSP_Gold4.tgz"
13
14fsp_binary_dir="$fsp_package_dir/FSP"
15fsp_binary="BAYTRAIL_FSP_GOLD_004_22-MAY-2015.fd"
16vbios_dir="$fsp_package_dir/Graphics/vbios"
17vbios_binary="Vga.dat"
18
19ucode_dir="$fsp_package_dir/Microcode"
20
21uefi_rom="MNW2MAX1.X64.0093.R01.1608031710.bin"
22uefi_dir="."
23uefi_package_file="MinnowBoard.MAX_.X64.93.R01.zip"
24uefi_rom_url="http://firmware.intel.com/sites/default/files/$uefi_package_file"
25uefi_checksum="1260b758e56eb4612ce048e1fd524305 *MinnowBoard.MAX_.X64.93.R01.zip"
26
27final_checksum="" # issue in coreboot prevented reproducibility
28
29RED='\033[1;31m'
30green='\033[0;32m'
31GREEN='\033[1;32m'
32blue='\033[0;34m'
33BLUE='\033[1;34m'
34NC='\033[0m' # No Color
35
36# shellcheck disable=SC2059
37error ()
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
44please_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
56searchtool()
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
82printf "${blue}Checking required tools: ${BLUE}m4 bison flex g++ wget md5sum unzip tar${NC}\n"
83searchtool m4 > /dev/null
84searchtool bison > /dev/null
85searchtool flex flex > /dev/null
86searchtool g++ "Free Software Foundation" nofail > /dev/null || \
87searchtool wget > /dev/null
88searchtool md5sum > /dev/null
89searchtool unzip > /dev/null
90searchtool tar > /dev/null
91# shellcheck disable=SC2059
92printf "${green}All tools present.${NC}\n\n"
93
94# shellcheck disable=SC2059
95if [ ! -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"
101fi
102
103pushd "./$coreboot_dir" || error "couldn't cd to $coreboot_dir" "$coreboot_dir"
104git checkout "$coreboot_commit_id" || error "Couldn't checkout $coreboot_commit_id"
105
106# shellcheck disable=SC2059
107if [ ! -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"
121fi
122
123# shellcheck disable=SC2059
124if [ ! -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"
143fi
144
145# shellcheck disable=SC2059
146if [ -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"
150fi
151
152# shellcheck disable=SC2059
153printf "${blue}Building coreboot${NC}\n"
154cat << EOF > .config
155CONFIG_VENDOR_INTEL=y
156CONFIG_VGA_BIOS=y
157CONFIG_VGA_BIOS_FILE="$vbios_dir/$vbios_binary"
158CONFIG_HAVE_IFD_BIN=y
159CONFIG_HAVE_ME_BIN=y
160CONFIG_FSP_FILE="$fsp_binary_dir/$fsp_binary"
161CONFIG_BOARD_INTEL_MINNOWMAX=y
162CONFIG_ENABLE_BUILTIN_COM1=y
163CONFIG_CPU_MICROCODE_HEADER_FILES="$ucode_dir/M013067222D.h $ucode_dir/M0130673321.h $ucode_dir/M0130678815.h $ucode_dir/M0130679901.h"
164CONFIG_IFD_BIN_PATH="descriptor.bin"
165CONFIG_ME_BIN_PATH="txe.bin"
166CONFIG_HAVE_FSP_BIN=y
167CONFIG_CONSOLE_POST=y
168# CONFIG_POST_IO is not set
169CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME="Minnowboard Max"
170CONFIG_SEABIOS_THREAD_OPTIONROMS=y
171EOF
172
173make olddefconfig || "Make olddefconfig failed." ".config"
174make clean
175make || error "make failed" "build"
176
177# shellcheck disable=SC2059
178if [ -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"
182else
183 md5sum -b build/coreboot.rom
184 printf "${GREEN}coreboot build completed successfully.\n\n"
185fi
186
187# shellcheck disable=SC2059
188printf "${GREEN}Full 8MB rom available as ${coreboot_dir}/build/coreboot.rom${NC}\n"
189printf "Flash MinnowBoard Max using dediprog with the command:\n"
190printf " flashrom -p dediprog:voltage=1.8v -w %s/build/coreboot.rom\n" "${coreboot_dir}"
191printf "For the MinnowBoard Turbot, use the command above, replacing '1.8v' with '3.5v'\n"
192printf "Flash either board using a spi hook with the command:\n"
193printf " flashrom -p ft2232_spi:type=2232h,port=A,divisor=4 -w %s/build/coreboot.rom\n\n" "${coreboot_dir}"