3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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.
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
35 # scan the $PATH for the given command
42 # echo "checks for $file in $path" >&2
43 if test -f "$path/$file"; then
51 echo "Usage: mi4fix.sh <e200/h10/h10_5gb/elio> <input> <output>"
55 if test -z "$output"; then
59 # sign - if the firmware should be DSA signed with a dummy (only 010301
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
82 echo "unsupported target"
87 if test -z "$MI4CODE"; then
88 tool
=`findtool mi4code`
89 if test -z "$tool"; then
91 tool
=`dirname $mkmi4`/mi4code
92 if ! test -f $tool; then
93 echo "Couldn't find mi4code"
101 # Use full file plaintext length if not encrypting
102 if test -z "$encrypt"; then
103 buildopt
="$buildopt -pall"
107 #echo "$tool build $input $output.raw"
108 $tool build
$buildopt $input $output.raw
110 if test -n "$encrypt"; then
111 #echo "$tool encrypt $output.raw $output.encrypt $tea"
112 $tool encrypt
$output.raw
$output.encrypt
$tea
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
118 if test -n "$sign"; then
119 #echo "$tool sign $output.encrypt $output"
120 $tool sign
$output.encrypt
$output
122 mv $output.encrypt
$output