1 #!/bin/bash 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 # Script that unpacks a firmware image (in .fd format) into its component 8 # pieces. Only outputs firmware A and B data, vblocks and the GBB. 9 10 # The mosys tool must be in the system path. 11 12 # Abort on error 13 set -e 14 15 # Check arguments 16 if [ $# -ne 1 ] ; then 17 echo "Usage: $0 src_fd" 18 echo "Outputs firmware.gbb, firmware[A|B].[data|vblock]" 19 exit 1 20 fi 21 22 # Make sure the tools we need are available. 23 type -P mosys &>/dev/null || \ 24 { echo "mosys tool not found."; exit 1; } 25 26 src_fd=$1 27 28 # Grab GBB Area offset and size 29 match_str="GBB Area" 30 line=$(mosys -f -k eeprom map $1 | grep "$match_str") 31 offset="$(echo $line | sed -e 's/.*area_offset=\"\([a-f0-9x]*\)\".*/\1/')" 32 let gbb_offset="$offset" 33 size="$(echo $line | sed -e 's/.*area_size=\"\([a-f0-9x]*\)\".*/\1/')" 34 let gbb_size="$size" 35 36 # Grab Firmware A and B offset and size 37 for i in "A" "B" 38 do 39 match_str="$i Key" 40 line=$(mosys -f -k eeprom map $1 | grep "$match_str") 41 offset="$(echo $line | sed -e 's/.*area_offset=\"\([a-f0-9x]*\)\".*/\1/')" 42 eval let \ 43 fw${i}_vblock_offset="$offset" 44 size="$(echo $line | sed -e 's/.*area_size=\"\([a-f0-9x]*\)\".*/\1/')" 45 eval let \ 46 fw${i}_vblock_size="$size" 47 48 match_str="$i Data" 49 line=$(mosys -f -k eeprom map $1 | grep "$match_str") 50 offset="$(echo $line | sed -e 's/.*area_offset=\"\([a-f0-9x]*\)\".*/\1/')" 51 eval let \ 52 fw${i}_offset="$offset" 53 size="$(echo $line | sed -e 's/.*area_size=\"\([a-f0-9x]*\)\".*/\1/')" 54 eval let \ 55 fw${i}_size="$size" 56 done 57 58 echo "Extracting GBB" 59 dd if="${src_fd}" of="firmware.gbb" skip="${gbb_offset}" bs=1 \ 60 count="${gbb_size}" 61 echo "Extracting Firmware data and vblock(s)" 62 dd if="${src_fd}" of="firmwareA.data" skip="${fwA_offset}" bs=1 \ 63 count="${fwA_size}" 64 dd if="${src_fd}" of="firmwareA.vblock" skip="${fwA_vblock_offset}" bs=1 \ 65 count="${fwA_vblock_size}" 66 dd if="${src_fd}" of="firmwareB.data" skip="${fwB_offset}" bs=1 \ 67 count="${fwB_size}" 68 dd if="${src_fd}" of="firmwareB.vblock" skip="${fwB_vblock_offset}" bs=1 \ 69 count="${fwB_vblock_size}" 70