summaryrefslogtreecommitdiff
path: root/scripts/image_signing/firmware_boot.sh
blob: 404a7ba139c52a139b8817a7bf837111565110e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash -eux

# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Refer to the Google Chrome OS Main Processor Firmware Specification for what
# the pieces are.
# This script generates different firmware binaries with different
# configurations.

# Syntax: ./firmware_boot.sh <Firmware name without .fd extension>.
# Usage of the script.
usage()
{
  cat <<EOF
  $0 firmware_name
  firmware_name - name of the firmware.
EOF
}

if [ $# != 1 ]; then
  usage
  exit 0
fi

base=$1
input=${base}.fd

if [ ! -f $input ]; then
  echo "$input file does not exists."
  exit 0
fi

# First, run dump_fmap $input | ./x to compute these values:

# dev-mode BIOS is in firmware A
rw_a_offset=$(dump_fmap -p ${input} | grep 'RW_SECTION_A' | cut -d' ' -f2)
rw_a_size=$(dump_fmap -p ${input} | grep 'RW_SECTION_A' | cut -d' ' -f3)

# normal-mode BIOS is in firmware B
rw_b_offset=$(dump_fmap -p ${input} | grep 'RW_SECTION_B' | cut -d' ' -f2)
rw_b_size=$(dump_fmap -p ${input} | grep 'RW_SECTION_B' | cut -d' ' -f3)

# Extract the RW BIOS chunks
dd if=${input} of=dev.bin bs=1 skip=${rw_a_offset} count=${rw_a_size}
dd if=${input} of=nor.bin bs=1 skip=${rw_b_offset} count=${rw_b_size}

# Garble one to make it fail the signature. I know that we reserve 64K at the
# start of the section for the signature and headers, so we'll make a random
# payload and put the normal header on the front.
dd if=/dev/urandom of=bad.bin bs=1 count=${rw_b_size}
dd if=nor.bin of=bad.bin conv=notrunc bs=1 count=65536

# A:Normal B:Normal
output=${base}-NN.fd
cp ${input} ${output}
dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}

# A:Dev    B:Dev
output=${base}-DD.fd
cp ${input} ${output}
dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}

# A:Normal B:Dev
output=${base}-ND.fd
cp ${input} ${output}
dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}

# A:Dev    B:Normal
output=${base}-DN.fd
cp ${input} ${output}
dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}

# A:Normal B:Bad
output=${base}-NB.fd
cp ${input} ${output}
dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}

# A:Bad    B:Normal
output=${base}-BN.fd
cp ${input} ${output}
dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}

# A:Dev    B:Bad
output=${base}-DB.fd
cp ${input} ${output}
dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}

# A:Bad    B:Dev
output=${base}-BD.fd
cp ${input} ${output}
dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}