diff options
Diffstat (limited to 'tools/mkmi4.sh')
-rwxr-xr-x | tools/mkmi4.sh | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/tools/mkmi4.sh b/tools/mkmi4.sh new file mode 100755 index 0000000000..8dc90d886f --- /dev/null +++ b/tools/mkmi4.sh | |||
@@ -0,0 +1,97 @@ | |||
1 | #!/bin/sh | ||
2 | # __________ __ ___. | ||
3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | # \/ \/ \/ \/ \/ | ||
8 | # $Id$ | ||
9 | # | ||
10 | # Purpose of this script: | ||
11 | # | ||
12 | # Inputs: music player model name and a file name | ||
13 | # | ||
14 | # Action: Build a valid mi4 file (prepending and appending magic) | ||
15 | # Encrypt the file with TEA encryption so that the model's own | ||
16 | # bootloader accepts this file. | ||
17 | # Sign the file with a DSA signature the bootloader accepts | ||
18 | # | ||
19 | # Output: A built, encrypted and signed mi4 file image. | ||
20 | # | ||
21 | # Requirement: | ||
22 | # | ||
23 | # This script assumes that you have the mi4code tool in your path, that | ||
24 | # you have the environment variable MI4CODE pointing to the tool or that you | ||
25 | # have it in the same dir that you invoke this script with. | ||
26 | # | ||
27 | # mi4 info and tool are here: http://daniel.haxx.se/sansa/mi4.html | ||
28 | # | ||
29 | |||
30 | mkmi4=$0 | ||
31 | target=$1 | ||
32 | input=$2 | ||
33 | output=$3 | ||
34 | |||
35 | # scan the $PATH for the given command | ||
36 | findtool(){ | ||
37 | file="$1" | ||
38 | |||
39 | IFS=":" | ||
40 | for path in $PATH | ||
41 | do | ||
42 | # echo "checks for $file in $path" >&2 | ||
43 | if test -f "$path/$file"; then | ||
44 | echo "$path/$file" | ||
45 | return | ||
46 | fi | ||
47 | done | ||
48 | } | ||
49 | |||
50 | help () { | ||
51 | echo "Usage: mi4fix.sh <e200/h10> <input> <output>" | ||
52 | exit | ||
53 | } | ||
54 | |||
55 | if test -z "$output"; then | ||
56 | help | ||
57 | fi | ||
58 | |||
59 | case $target in | ||
60 | e200) | ||
61 | tea=sansa | ||
62 | ;; | ||
63 | h10) | ||
64 | tea=20gc_eng | ||
65 | ;; | ||
66 | *) | ||
67 | echo "unsupported target" | ||
68 | help | ||
69 | ;; | ||
70 | esac | ||
71 | |||
72 | if test -z "$MI4CODE"; then | ||
73 | tool=`findtool mi4code` | ||
74 | if test -z "$tool"; then | ||
75 | # not in path | ||
76 | tool=`dirname $mkmi4`/mi4code | ||
77 | if ! test -f $tool; then | ||
78 | echo "Couldn't find mi4code" | ||
79 | exit | ||
80 | fi | ||
81 | fi | ||
82 | else | ||
83 | tool=$MI4CODE | ||
84 | fi | ||
85 | |||
86 | |||
87 | |||
88 | |||
89 | # build a 010301 version | ||
90 | echo "$tool build $input $output.raw" | ||
91 | $tool build $input $output.raw | ||
92 | # encrypt | ||
93 | echo "$tool encrypt $output.raw $output.encrypt $tea" | ||
94 | $tool encrypt $output.raw $output.encrypt $tea | ||
95 | # sign | ||
96 | echo "$tool sign $output.encrypt $output" | ||
97 | $tool sign $output.encrypt $output | ||