• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eux
2
3# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Refer to the Google Chrome OS Main Processor Firmware Specification for what
8# the pieces are.
9# This script generates different firmware binaries with different
10# configurations.
11
12# Syntax: ./firmware_boot.sh <Firmware name without .fd extension>.
13# Usage of the script.
14usage()
15{
16  cat <<EOF
17  $0 firmware_name
18  firmware_name - name of the firmware.
19EOF
20}
21
22if [ $# != 1 ]; then
23  usage
24  exit 0
25fi
26
27base=$1
28input=${base}.fd
29
30if [ ! -f $input ]; then
31  echo "$input file does not exists."
32  exit 0
33fi
34
35# First, run dump_fmap $input | ./x to compute these values:
36
37# dev-mode BIOS is in firmware A
38rw_a_offset=$(dump_fmap -p ${input} | grep 'RW_SECTION_A' | cut -d' ' -f2)
39rw_a_size=$(dump_fmap -p ${input} | grep 'RW_SECTION_A' | cut -d' ' -f3)
40
41# normal-mode BIOS is in firmware B
42rw_b_offset=$(dump_fmap -p ${input} | grep 'RW_SECTION_B' | cut -d' ' -f2)
43rw_b_size=$(dump_fmap -p ${input} | grep 'RW_SECTION_B' | cut -d' ' -f3)
44
45# Extract the RW BIOS chunks
46dd if=${input} of=dev.bin bs=1 skip=${rw_a_offset} count=${rw_a_size}
47dd if=${input} of=nor.bin bs=1 skip=${rw_b_offset} count=${rw_b_size}
48
49# Garble one to make it fail the signature. I know that we reserve 64K at the
50# start of the section for the signature and headers, so we'll make a random
51# payload and put the normal header on the front.
52dd if=/dev/urandom of=bad.bin bs=1 count=${rw_b_size}
53dd if=nor.bin of=bad.bin conv=notrunc bs=1 count=65536
54
55# A:Normal B:Normal
56output=${base}-NN.fd
57cp ${input} ${output}
58dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
59dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}
60
61# A:Dev    B:Dev
62output=${base}-DD.fd
63cp ${input} ${output}
64dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
65dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}
66
67# A:Normal B:Dev
68output=${base}-ND.fd
69cp ${input} ${output}
70dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
71dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}
72
73# A:Dev    B:Normal
74output=${base}-DN.fd
75cp ${input} ${output}
76dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
77dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}
78
79# A:Normal B:Bad
80output=${base}-NB.fd
81cp ${input} ${output}
82dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
83dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}
84
85# A:Bad    B:Normal
86output=${base}-BN.fd
87cp ${input} ${output}
88dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
89dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}
90
91# A:Dev    B:Bad
92output=${base}-DB.fd
93cp ${input} ${output}
94dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
95dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}
96
97# A:Bad    B:Dev
98output=${base}-BD.fd
99cp ${input} ${output}
100dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset}
101dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset}
102