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. 14 usage() 15 { 16 cat <<EOF 17 $0 firmware_name 18 firmware_name - name of the firmware. 19 EOF 20 } 21 22 if [ $# != 1 ]; then 23 usage 24 exit 0 25 fi 26 27 base=$1 28 input=${base}.fd 29 30 if [ ! -f $input ]; then 31 echo "$input file does not exists." 32 exit 0 33 fi 34 35 # First, run dump_fmap $input | ./x to compute these values: 36 37 # dev-mode BIOS is in firmware A 38 rw_a_offset=$(dump_fmap -p ${input} | grep 'RW_SECTION_A' | cut -d' ' -f2) 39 rw_a_size=$(dump_fmap -p ${input} | grep 'RW_SECTION_A' | cut -d' ' -f3) 40 41 # normal-mode BIOS is in firmware B 42 rw_b_offset=$(dump_fmap -p ${input} | grep 'RW_SECTION_B' | cut -d' ' -f2) 43 rw_b_size=$(dump_fmap -p ${input} | grep 'RW_SECTION_B' | cut -d' ' -f3) 44 45 # Extract the RW BIOS chunks 46 dd if=${input} of=dev.bin bs=1 skip=${rw_a_offset} count=${rw_a_size} 47 dd 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. 52 dd if=/dev/urandom of=bad.bin bs=1 count=${rw_b_size} 53 dd if=nor.bin of=bad.bin conv=notrunc bs=1 count=65536 54 55 # A:Normal B:Normal 56 output=${base}-NN.fd 57 cp ${input} ${output} 58 dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset} 59 dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset} 60 61 # A:Dev B:Dev 62 output=${base}-DD.fd 63 cp ${input} ${output} 64 dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset} 65 dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset} 66 67 # A:Normal B:Dev 68 output=${base}-ND.fd 69 cp ${input} ${output} 70 dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset} 71 dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset} 72 73 # A:Dev B:Normal 74 output=${base}-DN.fd 75 cp ${input} ${output} 76 dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset} 77 dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset} 78 79 # A:Normal B:Bad 80 output=${base}-NB.fd 81 cp ${input} ${output} 82 dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset} 83 dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset} 84 85 # A:Bad B:Normal 86 output=${base}-BN.fd 87 cp ${input} ${output} 88 dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset} 89 dd if=nor.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset} 90 91 # A:Dev B:Bad 92 output=${base}-DB.fd 93 cp ${input} ${output} 94 dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset} 95 dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset} 96 97 # A:Bad B:Dev 98 output=${base}-BD.fd 99 cp ${input} ${output} 100 dd if=bad.bin of=${output} conv=notrunc bs=1 seek=${rw_a_offset} 101 dd if=dev.bin of=${output} conv=notrunc bs=1 seek=${rw_b_offset} 102