Fix a typo.
[maemo-rb.git] / tools / mkmi4.sh
blob068d7e0628326577f70e6cb822dea618d5493736
1 #!/bin/sh
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
10 # Purpose of this script:
12 # Inputs: music player model name and a file name
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
19 # Output: A built, encrypted and signed mi4 file image.
21 # Requirement:
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.
27 # mi4 info and tool are here: http://daniel.haxx.se/sansa/mi4.html
30 mkmi4=$0
31 target=$1
32 input=$2
33 output=$3
35 # scan the $PATH for the given command
36 findtool(){
37 file="$1"
39 IFS=":"
40 for path in $PATH
42 # echo "checks for $file in $path" >&2
43 if test -f "$path/$file"; then
44 echo "$path/$file"
45 return
47 done
50 help () {
51 echo "Usage: mi4fix.sh <e200/h10/h10_5gb/elio> <input> <output>"
52 exit
55 if test -z "$output"; then
56 help
59 # sign - if the firmware should be DSA signed with a dummy (only 010301
60 # firmwares)
61 # tea - name of the TEA crypt key to use for encrypting, but only if ...
62 # encrypt - is set to "yes" for encrypting the firmware
63 case $target in
64 # fake example)
65 # sign="yes"
66 # encrypt="yes"
67 # tea=targetkey
68 # ;;
69 e200)
70 sign="yes"
72 h10)
73 sign="yes"
75 h10_5gb)
76 buildopt="-2"
78 elio)
79 buildopt="-2"
82 echo "unsupported target"
83 help
85 esac
87 if test -z "$MI4CODE"; then
88 tool=`findtool mi4code`
89 if test -z "$tool"; then
90 # not in path
91 tool=`dirname $mkmi4`/mi4code
92 if ! test -f $tool; then
93 echo "Couldn't find mi4code"
94 exit
97 else
98 tool=$MI4CODE
101 # Use full file plaintext length if not encrypting
102 if test -z "$encrypt"; then
103 buildopt="$buildopt -pall"
106 # build mi4
107 #echo "$tool build $input $output.raw"
108 $tool build $buildopt $input $output.raw
109 # encrypt
110 if test -n "$encrypt"; then
111 #echo "$tool encrypt $output.raw $output.encrypt $tea"
112 $tool encrypt $output.raw $output.encrypt $tea
113 else
114 # Even if we don't encrypt we need to do this to ensure the crc gets fixed
115 $tool encrypt -pall $output.raw $output.encrypt default
117 # sign
118 if test -n "$sign"; then
119 #echo "$tool sign $output.encrypt $output"
120 $tool sign $output.encrypt $output
121 else
122 mv $output.encrypt $output