Add support for scramble to put a 4 character string indicating binary type and the 4 character model id at the end of the mi4 header.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12760 a1c6a512-1295-4272-9138-f99709370657
diff --git a/tools/mi4.c b/tools/mi4.c
index f466ad7..b9f7e25 100644
--- a/tools/mi4.c
+++ b/tools/mi4.c
@@ -102,7 +102,8 @@
     addr[3] = (val >> 24) & 0xff;
 }
 
-int mi4_encode(char *iname, char *oname, int version, int magic)
+int mi4_encode(char *iname, char *oname, int version, int magic,
+                char *model, char *type)
 {
     size_t len;
     int length;
@@ -150,7 +151,10 @@
     int2le(length+4,     &outbuf[0x2e8]);   /* length plus 0xaa55aa55 */
 
     int2le(0xaa55aa55,   &outbuf[0x200+length]);  /* More Magic */
-
+    
+    strncpy((char *)outbuf+0x1f8, type, 4);    /* type of binary - RBBL, RBOS, ... */
+    strncpy((char *)outbuf+0x1fc, model, 4);    /* type of binary - RBBL, RBOS, ... */
+    
     /* Calculate CRC32 checksum */
     chksum_crc32gentab ();
     crc = chksum_crc32 (outbuf+28,mi4length-28);
diff --git a/tools/mi4.h b/tools/mi4.h
index ac55f59..fa26f2e 100644
--- a/tools/mi4.h
+++ b/tools/mi4.h
@@ -23,6 +23,7 @@
 #define MI4_MAGIC_DEFAULT 0xec
 #define MI4_MAGIC_R       0xfc
 
-int mi4_encode(char *iname, char *oname, int version, int magic);
+int mi4_encode(char *iname, char *oname, int version, int magic,
+                char *model, char *type);
 
 #endif
diff --git a/tools/scramble.c b/tools/scramble.c
index ccd6712..7e6ca1f 100644
--- a/tools/scramble.c
+++ b/tools/scramble.c
@@ -89,6 +89,10 @@
            "\t-mi4v2  PortalPlayer .mi4 format (revision 010201)\n"
            "\t-mi4v3  PortalPlayer .mi4 format (revision 010301)\n"
            "\t-mi4r   Sandisk Rhapsody .mi4 format\n"
+           "\t        All mi4 options take two optional arguments:\n"
+           "\t        -model=XXXX   where XXXX is the model id string\n"
+           "\t        -type=XXXX    where XXXX is a string indicating the \n"
+           "\t                      type of binary, eg. RBOS, RBBL\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"
@@ -266,20 +270,45 @@
         oname = argv[3];
         return ipod_encode(iname, oname, 3, true);  /* Firmware image v3 */
     }
-    else if(!strcmp(argv[1], "-mi4v2")) {
+    else if(!strncmp(argv[1], "-mi4", 4)) {
+        int mi4magic;
+        int version;
+        char model[4] = "";
+        char type[4] = "";
+        
+        if(!strcmp(&argv[1][4], "v2")) {
+            mi4magic = MI4_MAGIC_DEFAULT;
+            version = 0x00010201;
+        }
+        else if(!strcmp(&argv[1][4], "v3")) {
+            mi4magic = MI4_MAGIC_DEFAULT;
+            version = 0x00010301;
+        }
+        else if(!strcmp(&argv[1][4], "r")) {
+            mi4magic = MI4_MAGIC_R;
+            version = 0x00010301;
+        }
+        else {
+            printf( "Invalid mi4 version: %s\n", &argv[1][4]);
+            return -1;
+        }
+
         iname = argv[2];
         oname = argv[3];
-        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, MI4_MAGIC_DEFAULT);
-    }
-    else if(!strcmp(argv[1], "-mi4r")) {
-        iname = argv[2];
-        oname = argv[3];
-        return mi4_encode(iname, oname, 0x00010301, MI4_MAGIC_R);
+        
+        if(!strncmp(argv[2], "-model=", 7)) {
+            iname = argv[3];
+            oname = argv[4];
+            strncpy(model, &argv[2][7], 4);
+            
+            if(!strncmp(argv[3], "-type=", 6)) {
+                iname = argv[4];
+                oname = argv[5];
+                strncpy(type, &argv[3][6], 4);
+            }
+        }
+
+        return mi4_encode(iname, oname, version, mi4magic, model, type);
     }
     
     /* open file */