Flash: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(added NOR Unpacking sourcode) |
||
Line 230: | Line 230: | ||
|0x40000 (262,144 bytes) | |0x40000 (262,144 bytes) | ||
|} | |} | ||
= NOR Unpacking // NOR Unpkg = | |||
<pre> | |||
/* | |||
# ../norunpkg norflash.bin norflash | |||
unpacking asecure_loader (size: 190xxx bytes)... | |||
unpacking eEID (size: 65536 bytes)... | |||
unpacking cISD (size: 2048 bytes)... | |||
unpacking cCSD (size: 2048 bytes)... | |||
unpacking trvk_prg0 (size: 131072 bytes)... | |||
unpacking trvk_prg1 (size: 131072 bytes)... | |||
unpacking trvk_pkg0 (size: 131072 bytes)... | |||
unpacking trvk_pkg1 (size: 131072 bytes)... | |||
unpacking ros0 (size: 7340032 bytes)... | |||
unpacking ros1 (size: 7340032 bytes)... | |||
unpacking cvtrm (size: 262144 bytes)... | |||
*/ | |||
// Copyright 2010 Sven Peter | |||
// Licensed under the terms of the GNU GPL, version 2 | |||
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt | |||
// nor modifications by rms. | |||
#include "tools.h" | |||
#include "types.h" | |||
#include <stdio.h> | |||
#include <string.h> | |||
#include <stdlib.h> | |||
#include <unistd.h> | |||
#include <sys/stat.h> | |||
#ifdef WIN32 | |||
#define MKDIR(x,y) mkdir(x) | |||
#else | |||
#define MKDIR(x,y) mkdir(x,y) | |||
#endif | |||
u8 *pkg = NULL; | |||
static void unpack_file(u32 i) | |||
{ | |||
u8 *ptr; | |||
u8 name[33]; | |||
u64 offset; | |||
u64 size; | |||
ptr = pkg + 0x10 + 0x30 * i; | |||
offset = be64(ptr + 0x00); | |||
size = be64(ptr + 0x08); | |||
memset(name, 0, sizeof name); | |||
strncpy((char *)name, (char *)(ptr + 0x10), 0x20); | |||
printf("unpacking %s (size: %d bytes)...\n", name, size); | |||
memcpy_to_file((char *)name, pkg + offset, size); | |||
} | |||
static void unpack_pkg(void) | |||
{ | |||
u32 n_files; | |||
u64 size; | |||
u32 i; | |||
n_files = be32(pkg + 4); | |||
size = be64(pkg + 8); | |||
for (i = 0; i < n_files; i++) | |||
unpack_file(i); | |||
} | |||
int main(int argc, char *argv[]) | |||
{ | |||
if (argc != 3) | |||
fail("usage: norunpkg filename.nor target"); | |||
pkg = mmap_file(argv[1]); | |||
/* kludge for header, i do not do sanity checks at the moment */ | |||
pkg += 1024; | |||
MKDIR(argv[2], 0777); | |||
if (chdir(argv[2]) != 0) | |||
fail("chdir"); | |||
unpack_pkg(); | |||
return 0; | |||
} | |||
</pre> |
Revision as of 01:14, 12 April 2011
NOR Filesystem Format
Header
Header is the first 512 + 16 bytes.
Example
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000010 00 00 00 00 0F AC E0 FF 00 00 00 00 DE AD BE EF .....¬àÿ....Þ.¾ï 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 78 00 ..............x. 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000000A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000000B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000000C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000000D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000000E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000000F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000001A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000001B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000001C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000001D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000001E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000001F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
???
The next block of 512 bytes only has the first 16 bytes written.
Example
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000200 49 46 49 00 00 00 00 01 00 00 00 02 00 00 00 00 IFI............. 00000210 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000220 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000230 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000240 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000250 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000260 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000270 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000280 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000290 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000002A0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000002B0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000002C0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000002D0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000002E0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000002F0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000300 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000310 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000320 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000330 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000340 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000350 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000360 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000370 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000380 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000390 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000003A0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000003B0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000003C0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000003D0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000003E0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000003F0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
Entry Table
The next 1024 bytes contain the file entry table:
Format
First is a header, this tells us how many files are stored here.
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000400 00 00 00 01 00 00 00 0B 00 00 00 00 00 EF FC 00 .............ïü. u32 - unknown (0x01) u32 - Entry count (0x0B) u64 - Length of Region (0xEFFC00)
Then follows a 32 byte entry for each file
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000410 00 00 00 00 00 00 04 00 00 00 00 00 00 02 E8 00 ..............è. 00000420 61 73 65 63 75 72 65 5F 6C 6F 61 64 65 72 00 00 asecure_loader.. 00000430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ u64 - offset - Relative to 0x400 (0x400) u64 - size (0x2E800) char[32] - name (asecure_loader)
Example
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000400 00 00 00 01 00 00 00 0B 00 00 00 00 00 EF FC 00 .............ïü. 00000410 00 00 00 00 00 00 04 00 00 00 00 00 00 02 E8 00 ..............è. 00000420 61 73 65 63 75 72 65 5F 6C 6F 61 64 65 72 00 00 asecure_loader.. 00000430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000440 00 00 00 00 00 02 EC 00 00 00 00 00 00 01 00 00 ......ì......... 00000450 65 45 49 44 00 00 00 00 00 00 00 00 00 00 00 00 eEID............ 00000460 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000470 00 00 00 00 00 03 EC 00 00 00 00 00 00 00 08 00 ......ì......... 00000480 63 49 53 44 00 00 00 00 00 00 00 00 00 00 00 00 cISD............ 00000490 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000004A0 00 00 00 00 00 03 F4 00 00 00 00 00 00 00 08 00 ......ô......... 000004B0 63 43 53 44 00 00 00 00 00 00 00 00 00 00 00 00 cCSD............ 000004C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000004D0 00 00 00 00 00 03 FC 00 00 00 00 00 00 02 00 00 ......ü......... 000004E0 74 72 76 6B 5F 70 72 67 30 00 00 00 00 00 00 00 trvk_prg0....... 000004F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000500 00 00 00 00 00 05 FC 00 00 00 00 00 00 02 00 00 ......ü......... 00000510 74 72 76 6B 5F 70 72 67 31 00 00 00 00 00 00 00 trvk_prg1....... 00000520 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000530 00 00 00 00 00 07 FC 00 00 00 00 00 00 02 00 00 ......ü......... 00000540 74 72 76 6B 5F 70 6B 67 30 00 00 00 00 00 00 00 trvk_pkg0....... 00000550 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000560 00 00 00 00 00 09 FC 00 00 00 00 00 00 02 00 00 ......ü......... 00000570 74 72 76 6B 5F 70 6B 67 31 00 00 00 00 00 00 00 trvk_pkg1....... 00000580 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000590 00 00 00 00 00 0B FC 00 00 00 00 00 00 70 00 00 ......ü......p.. 000005A0 72 6F 73 30 00 00 00 00 00 00 00 00 00 00 00 00 ros0............ 000005B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000005C0 00 00 00 00 00 7B FC 00 00 00 00 00 00 70 00 00 .....{ü......p.. 000005D0 72 6F 73 31 00 00 00 00 00 00 00 00 00 00 00 00 ros1............ 000005E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000005F0 00 00 00 00 00 EB FC 00 00 00 00 00 00 04 00 00 .....ëü......... 00000600 63 76 74 72 6D 00 00 00 00 00 00 00 00 00 00 00 cvtrm........... 00000610 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000620 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000630 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000640 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000650 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000660 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000670 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000680 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000690 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000006A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000006B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000006C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000006D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000006E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000006F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000700 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000710 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000720 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000730 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000740 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000750 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000760 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000770 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000780 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000790 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000007A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000007B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000007C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000007D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000007E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 000007F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
NOR Files
The following is a list of files stored in NOR Flash
Name | Offset | Size |
---|---|---|
asecure_loader | 0x400 | 0x2E800 (190,464 bytes) |
eEID | 0x2EC00 | 0x10000 (65,636 bytes) |
cISD | 0x3EC00 | 0x800 (2,048 bytes) |
cCSD | 0x3F400 | 0x800 (2,048 bytes) |
trvk_prg0 | 0x03FC00 | 0x20000 (131,072 bytes) |
trvk_pkg0 | 0x7FC00 | 0x20000 (131,072 bytes) |
trvk_pkg1 | 0x9FC00 | 0x20000 (131,072 bytes) |
ros0 | 0xBFC00 | 0x700000 (7,340,032 bytes) |
ros1 | 0x7BFC00 | 0x700000 (7,340,032 bytes) |
cvtrm | 0XEBFC00 | 0x40000 (262,144 bytes) |
NOR Unpacking // NOR Unpkg
/* # ../norunpkg norflash.bin norflash unpacking asecure_loader (size: 190xxx bytes)... unpacking eEID (size: 65536 bytes)... unpacking cISD (size: 2048 bytes)... unpacking cCSD (size: 2048 bytes)... unpacking trvk_prg0 (size: 131072 bytes)... unpacking trvk_prg1 (size: 131072 bytes)... unpacking trvk_pkg0 (size: 131072 bytes)... unpacking trvk_pkg1 (size: 131072 bytes)... unpacking ros0 (size: 7340032 bytes)... unpacking ros1 (size: 7340032 bytes)... unpacking cvtrm (size: 262144 bytes)... */ // Copyright 2010 Sven Peter // Licensed under the terms of the GNU GPL, version 2 // http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt // nor modifications by rms. #include "tools.h" #include "types.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sys/stat.h> #ifdef WIN32 #define MKDIR(x,y) mkdir(x) #else #define MKDIR(x,y) mkdir(x,y) #endif u8 *pkg = NULL; static void unpack_file(u32 i) { u8 *ptr; u8 name[33]; u64 offset; u64 size; ptr = pkg + 0x10 + 0x30 * i; offset = be64(ptr + 0x00); size = be64(ptr + 0x08); memset(name, 0, sizeof name); strncpy((char *)name, (char *)(ptr + 0x10), 0x20); printf("unpacking %s (size: %d bytes)...\n", name, size); memcpy_to_file((char *)name, pkg + offset, size); } static void unpack_pkg(void) { u32 n_files; u64 size; u32 i; n_files = be32(pkg + 4); size = be64(pkg + 8); for (i = 0; i < n_files; i++) unpack_file(i); } int main(int argc, char *argv[]) { if (argc != 3) fail("usage: norunpkg filename.nor target"); pkg = mmap_file(argv[1]); /* kludge for header, i do not do sanity checks at the moment */ pkg += 1024; MKDIR(argv[2], 0777); if (chdir(argv[2]) != 0) fail("chdir"); unpack_pkg(); return 0; }