Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
366 theseven 1
#!/usr/bin/env python
2
#
3
#
4
#    Copyright 2010 TheSeven
5
#
6
#
7
#    This file is part of emBIOS.
8
#
9
#    emBIOS is free software: you can redistribute it and/or
10
#    modify it under the terms of the GNU General Public License as
11
#    published by the Free Software Foundation, either version 2 of the
12
#    License, or (at your option) any later version.
13
#
14
#    emBIOS is distributed in the hope that it will be useful,
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
#    See the GNU General Public License for more details.
18
#
19
#    You should have received a copy of the GNU General Public License along
20
#    with emBIOS.  If not, see <http://www.gnu.org/licenses/>.
21
#
22
#
23
 
24
 
25
import sys
26
import os
27
import struct
28
 
29
bitmaps = ["sidepane.ucl", "warning.ucl", "installing.ucl", \
30
           "formatting.ucl", "copying.ucl", "flashing.ucl"]
31
 
32
flashfiles = [("ildrcfg ", 2, 0, 0, "iloader.cfg.ucl"), \
33
              ("iloader ", 2, 0, 0, "iloader.embiosapp.ucl"), \
34
              ("umsboot ", 2, 0, 0, "umsboot-ipodclassic.ucl"), \
35
              ("embiosldr", 12, 8, 0, "embiosldr-ipodclassic.bin"), \
36
              ("embios  ", 2, 0, 0, "embios-ipodclassic.ucl")]
37
 
38
firstinstfiles = [(2, "/iLoader/iLoader.cfg", "../iloader/themes/ipodclassic-default/iLoader/iloader.cfg", 1), \
39
                  (2, "/iLoader/theme.ucl", "../iloader/themes/ipodclassic-default/iLoader/theme.ucl", 2)]
40
 
41
commonfiles = [(2, "/iLoader/NORFlash.bak", -2, 10)]
42
 
43
if len(sys.argv) > 4 and sys.argv[4] != "-":
44
    pathlen = len(sys.argv[4])
45
    for d in os.walk(sys.argv[4]):
46
        prefix = d[0].replace("\\", "/")[pathlen:] + "/"
47
        for dir in d[1]:
48
            if dir != ".svn":
49
                firstinstfiles.append((1, prefix + dir, 1))
50
        for f in d[2]:
51
            if not prefix.find("/.svn/") > -1:
52
                firstinstfiles.append((2, prefix + f, d[0] + "/" + f, os.path.getsize(d[0] + "/" + f) / 100000 + 1))
53
 
54
file = open(sys.argv[1], "rb")
55
installer = file.read()
56
file.close()
57
installer = installer.ljust((len(installer) + 3) & ~3)
58
 
59
for f in bitmaps:
60
  file = open("build/" + f, "rb")
61
  fdata = file.read()
62
  file.close()
63
  fdata = fdata.ljust((len(fdata) + 3) & ~3)
64
  installer = installer + struct.pack("<I", len(fdata)) + fdata
65
 
66
statusfirst = 0
67
statuscommon = 0
68
scriptsize = 20
69
 
70
for f in flashfiles:
71
  scriptsize = scriptsize + 4
72
  if (f[1] & 4) == 0: scriptsize = scriptsize + 8
73
  if f[3] == 0: scriptsize = scriptsize + 8
74
 
75
for f in firstinstfiles:
76
  scriptsize = scriptsize + 12
77
  if f[0] > 1: scriptsize = scriptsize + 8
78
 
79
for f in commonfiles:
80
  scriptsize = scriptsize + 12
81
  if f[0] > 1: scriptsize = scriptsize + 8
82
 
83
scriptsize = ((len(installer) + scriptsize + 15) & ~15) - len(installer)
84
 
85
filedata = ""
86
flash = ""
87
for f in flashfiles:
88
  flash = flash + struct.pack("BBBB", f[3], f[1], f[2], 1)
89
  if f[3] == 0:
90
    file = open("flashfiles/" + f[4], "rb")
91
    fdata = file.read()
92
    file.close()
93
    flash = flash + struct.pack("<II", scriptsize + len(filedata), len(fdata))
94
    filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15)
95
  if (f[1] & 4) == 0: flash = flash + f[0]
96
 
97
firstinstall = ""
98
for f in firstinstfiles:
99
  size = 0
100
  nameptr = scriptsize + len(filedata)
101
  filedata = filedata + (f[1] + "\0").ljust((len(f[1]) + 16) & ~15)
102
  if f[0] == 1:
103
    firstinstall = firstinstall + struct.pack("<III", f[0], nameptr, f[2])
104
    statusfirst = statusfirst + f[2]
105
  else:
106
    if type(f[2]) == str:
107
      file = open(f[2], "rb")
108
      fdata = file.read()
109
      file.close()
110
      ptr = scriptsize + len(filedata)
111
      size = len(fdata)
112
      filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15)
113
    else:
114
      ptr = f[2]
115
    firstinstall = firstinstall + struct.pack("<IIiII", f[0], nameptr, ptr, size, f[3])
116
    statusfirst = statusfirst + f[3]
117
 
118
common = ""
119
for f in commonfiles:
120
  size = 0
121
  nameptr = scriptsize + len(filedata)
122
  filedata = filedata + (f[1] + "\0").ljust((len(f[1]) + 16) & ~15)
123
  if f[0] == 1:
124
    common = common + struct.pack("<III", f[0], nameptr, f[2])
125
    statuscommon = statuscommon + f[2]
126
  else:
127
    if type(f[2]) == str:
128
      file = open("../iloader/themes/default/iloader/" + f[2], "rb")
129
      fdata = file.read()
130
      file.close()
131
      ptr = scriptsize + len(filedata)
132
      size = len(fdata)
133
      filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15)
134
    else:
135
      ptr = f[2]
136
    common = common + struct.pack("<IIiII", f[0], nameptr, ptr, size, f[3])
137
    statuscommon = statuscommon + f[3]
138
 
139
script = flash + struct.pack("<IIII", 0, len(flash) + 16 + len(firstinstall), \
140
                             statusfirst, statusfirst + statuscommon) \
141
       + firstinstall + common + struct.pack("<I", 0)
142
file = open(sys.argv[2], "wb")
143
file.write(installer + script.ljust(scriptsize) + filedata)
144
file.close()