support scrambling for the Sansa R models


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12465 a1c6a512-1295-4272-9138-f99709370657
diff --git a/tools/mi4.c b/tools/mi4.c
index b0fff98..f466ad7 100644
--- a/tools/mi4.c
+++ b/tools/mi4.c
@@ -102,7 +102,7 @@
     addr[3] = (val >> 24) & 0xff;
 }
 
-int mi4_encode(char *iname, char *oname, int version)
+int mi4_encode(char *iname, char *oname, int version, int magic)
 {
     size_t len;
     int length;
@@ -146,7 +146,7 @@
     /* We need to write some data into the actual image - before calculating
        the CRC. */
     int2le(0x00000100,   &outbuf[0x2e0]);   /* magic */
-    int2le(0x000000ec,   &outbuf[0x2e4]);   /* magic */
+    int2le(magic,        &outbuf[0x2e4]);   /* magic */
     int2le(length+4,     &outbuf[0x2e8]);   /* length plus 0xaa55aa55 */
 
     int2le(0xaa55aa55,   &outbuf[0x200+length]);  /* More Magic */
diff --git a/tools/mi4.h b/tools/mi4.h
index ec3a734..ac55f59 100644
--- a/tools/mi4.h
+++ b/tools/mi4.h
@@ -20,6 +20,9 @@
 #ifndef _MI4_H
 #define _MI4_H
 
-int mi4_encode(char *iname, char *oname, int version);
+#define MI4_MAGIC_DEFAULT 0xec
+#define MI4_MAGIC_R       0xfc
+
+int mi4_encode(char *iname, char *oname, int version, int magic);
 
 #endif
diff --git a/tools/scramble.c b/tools/scramble.c
index 07b1193..ea91b9b 100644
--- a/tools/scramble.c
+++ b/tools/scramble.c
@@ -7,7 +7,7 @@
  *                     \/            \/     \/    \/            \/
  * $Id$
  *
- * Copyright (C) 2002 by Björn Stenberg
+ * Copyright (C) 2002 - 2007 by Björn Stenberg
  *
  * All files in this archive are subject to the GNU General Public License.
  * See the file COPYING in the source tree root for full license agreement.
@@ -87,6 +87,7 @@
            "\t-gigabeat Toshiba Gigabeat format\n"
            "\t-mi4v2  PortalPlayer .mi4 format (revision 010201)\n"
            "\t-mi4v3  PortalPlayer .mi4 format (revision 010301)\n"
+           "\t-mi4r   Sandisk Rhapsody .mi4 format\n"
            "\t-add=X  Rockbox generic \"add-up\" checksum format\n"
            "\t        (X values: h100, h120, h140, h300, ipco, nano, ipvd, mn2g\n"
            "\t                   ip3g, ip4g, mini, iax5, h10, h10_5gb, tpj2, e200)\n"
@@ -260,12 +261,17 @@
     else if(!strcmp(argv[1], "-mi4v2")) {
         iname = argv[2];
         oname = argv[3];
-        return mi4_encode(iname, oname, 0x00010201);
+        return mi4_encode(iname, oname, 0x00010201, MI4_MAGIC_DEFAULT);
     }
     else if(!strcmp(argv[1], "-mi4v3")) {
         iname = argv[2];
         oname = argv[3];
-        return mi4_encode(iname, oname, 0x00010301);
+        return mi4_encode(iname, oname, 0x00010301, MI4_MAGIC_DEFAULT);
+    }
+    else if(!strcmp(argv[1], "-mi4r")) {
+        iname = argv[2];
+        oname = argv[3];
+        return mi4_encode(iname, oname, 0x00010301, MI4_MAGIC_R);
     }
     
     /* open file */