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