blob: 13f7d925c942d231015a97bd6b78b24147b0ce04 [file] [log] [blame]
David Hendricksea227962013-01-10 15:07:59 -08001#!/bin/sh
2
3SCRIPT="$0"
4SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
5
6OUTPUT="build/coreboot.rom"
7TMP_DIFF="$SCRIPT_DIR/.image-diff.bin"
8FLASHROM="/usr/local/sbin/flashrom"
9
10BL1_NAME="E5250.nbl1.bin"
11BL1_PATH="3rdparty/cpu/samsung/exynos5250/"
12BL1_URL="http://commondatastorage.googleapis.com/chromeos-localmirror/distfiles/exynos-pre-boot-0.0.2-r8.tbz2"
13
14die() {
15 echo "$*" >&2
16 exit 1
17}
18
19create_diff_128k() {
20 local image_file="$1"
21 local diff_file="$2"
22 cp -f "$image_file" "$diff_file"
23 dd if=/dev/zero of=$diff_file bs=1 count=$((128*1024)) conv=notrunc
24}
25
26fast_flash_image() {
27 local image_file="$1"
28 local diff_file="$2"
29 dut-control spi2_buf_en:on spi2_buf_on_flex_en:on spi2_vref:pp1800
30 sudo ${FLASHROM} -p ft2232_spi:type=servo-v2,port=a -w "$image_file" -V \
31 --noverify --ignore-fmap --diff "$diff_file"
32 dut-control spi2_buf_en:off spi2_buf_on_flex_en:off spi2_vref:off
33}
34
35get_bl1() {
36 wget "${BL1_URL}" -O /tmp/bl1.tbz2
37 tar jxvf /tmp/bl1.tbz2
38 mkdir -p "${BL1_PATH}"
39 mv "exynos-pre-boot/firmware/${BL1_NAME}" "${BL1_PATH}"
40 rm -rf exynos-pre-boot
41 if [ ! -e "${BL1_PATH}/${BL1_NAME}" ]; then
42 echo "Error getting BL1"
43 exit 1
44 fi
45}
46
47merge_bl1() {
48 local outfile="$1"
49 local bl1="${BL1_PATH}/${BL1_NAME}"
50
51 if [ ! -e "$bl1" ]; then
52 get_bl1
53 fi
54
55 # use the new BL1 which supports 30KB BL2/SPL/Coreboot
56 local size="$(stat -c "%s" "$outfile")"
57 local bl1_size="$(stat -c "%s" "$bl1")"
58
59 [ "$bl1_size" = "$((0x2000))" ] || die "Incorrect BL1 input file."
60 dd if="$bl1" of=${outfile} conv=notrunc
61}
62
63is_servod_ready() {
64 ps -C servod >/dev/null 2>&1
65}
66
67main() {
68 make
69 merge_bl1 "$OUTPUT"
70 create_diff_128k "$OUTPUT" "$TMP_DIFF"
71 echo "OK: Generated image (with BL1) in $OUTPUT"
72 if is_servod_ready; then
73 echo "servod detected - flashing into device."
74 fast_flash_image "$OUTPUT" "$TMP_DIFF"
75 echo "OK: Generated and flashed 128k of image into device via servo."
76 else
77 echo "(servod is not running, flashing into device is skipped)"
78 fi
79}
80
81set -e
82main "$@"