A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
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
30mkmi4=$0
31target=$1
32input=$2
33output=$3
34
35# scan the $PATH for the given command
36findtool(){
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
50help () {
51 echo "Usage: mi4fix.sh <e200/h10/h10_5gb/elio> <input> <output>"
52 exit
53}
54
55if test -z "$output"; then
56 help
57fi
58
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
63case $target in
64 # fake example)
65 # sign="yes"
66 # encrypt="yes"
67 # tea=targetkey
68 # ;;
69 e200)
70 sign="yes"
71 ;;
72 h10)
73 sign="yes"
74 ;;
75 h10_5gb)
76 buildopt="-2"
77 ;;
78 elio)
79 buildopt="-2"
80 ;;
81 *)
82 echo "unsupported target"
83 help
84 ;;
85esac
86
87if 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
95 fi
96 fi
97else
98 tool=$MI4CODE
99fi
100
101# Use full file plaintext length if not encrypting
102if test -z "$encrypt"; then
103 buildopt="$buildopt -pall"
104fi
105
106# build mi4
107#echo "$tool build $input $output.raw"
108$tool build $buildopt $input $output.raw
109# encrypt
110if test -n "$encrypt"; then
111 #echo "$tool encrypt $output.raw $output.encrypt $tea"
112 $tool encrypt $output.raw $output.encrypt $tea
113else
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
116fi
117# sign
118if test -n "$sign"; then
119 #echo "$tool sign $output.encrypt $output"
120 $tool sign $output.encrypt $output
121else
122 mv $output.encrypt $output
123fi