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 fmap_decode 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 fmap_decode &>/dev/null || \ |
24 { echo "fmap_decode tool not found."; exit 1; } | 24 { echo "fmap_decode tool not found."; exit 1; } |
25 | 25 |
26 src_fd=$1 | 26 src_fd=$1 |
27 | 27 |
28 # Parse offsets and size of firmware data and vblocks | 28 # Grab GBB Area offset and size |
29 let gbb_offset="$(fmap_decode $1 | grep GBB | cut -b 14-23)" | 29 match_str="GBB Area" |
30 let gbb_size="$(fmap_decode $1 | grep GBB | cut -b 37-46)" | 30 line=$(fmap_decode $1 | grep "$match_str") |
31 set -x | 31 offset="$(echo $line | sed -e 's/.*area_offset=\"\([a-f0-9x]*\)\".*/\1/')" |
32 let gbb_offset="$offset" | |
vb
2010/07/27 18:18:50
is 'let' needed here and in line 34?
gauravsh
2010/07/27 18:45:26
Yes, to force hex->decimal conversion since dd doe
| |
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 | |
32 for i in "A" "B" | 37 for i in "A" "B" |
33 do | 38 do |
34 match_str="$i Key" | 39 match_str="$i Key" |
40 line=$(fmap_decode $1 | grep "$match_str") | |
41 offset="$(echo $line | sed -e 's/.*area_offset=\"\([a-f0-9x]*\)\".*/\1/')" | |
35 eval let \ | 42 eval let \ |
36 fw${i}_vblock_offset="$(fmap_decode $1 | grep "$match_str" | cut -b 14-23)" | 43 fw${i}_vblock_offset="$offset" |
44 size="$(echo $line | sed -e 's/.*area_size=\"\([a-f0-9x]*\)\".*/\1/')" | |
37 eval let \ | 45 eval let \ |
38 fw${i}_vblock_size="$(fmap_decode $1 | grep "$match_str" | cut -b 37-46)" | 46 fw${i}_vblock_size="$size" |
39 | 47 |
40 match_str="$i Data" | 48 match_str="$i Data" |
41 eval let fw${i}_offset="$(fmap_decode $1 | grep "$match_str" | cut -b 14-23)" | 49 line=$(fmap_decode $1 | grep "$match_str") |
42 eval let fw${i}_size="$(fmap_decode $1 | grep "$match_str" | cut -b 37-46)" | 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" | |
43 done | 56 done |
44 | 57 |
45 echo "Extracting GBB" | 58 echo "Extracting GBB" |
46 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 \ |
47 count="${gbb_size}" | 60 count="${gbb_size}" |
48 echo "Extracting Firmware data and vblock(s)" | 61 echo "Extracting Firmware data and vblock(s)" |
49 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 \ |
50 count="${fwA_size}" | 63 count="${fwA_size}" |
51 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 \ |
52 count="${fwA_vblock_size}" | 65 count="${fwA_vblock_size}" |
53 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 \ |
54 count="${fwB_size}" | 67 count="${fwB_size}" |
55 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 \ |
56 count="${fwB_vblock_size}" | 69 count="${fwB_vblock_size}" |
OLD | NEW |