Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
160 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 struct
27
 
28
bitmaps = ["backdrop.ucl", "welcome.ucl", "badpartition.ucl", "cancelled.ucl", \
29
           "repartition.ucl", "installing.ucl", "preparing.ucl", \
30
           "repartitioning.ucl", "installfiles.ucl", "flashing.ucl"]
31
 
32
flashfiles = [("diskmode", 1, 0, 1), \
33
              ("diagmode", 1, 0, 2), \
34
              ("uninst  ", 2, 0, 0, "uninstaller-nano2g.embiosapp.ucl"), \
35
              ("ildrcfg ", 2, 0, 0, "iloader.cfg.ucl"), \
36
              ("iloader ", 2, 0, 0, "iloader.embiosapp.ucl"), \
37
              ("embiosldr", 4, 8, 0, "embiosldr-ipodnano2g.dfu"), \
38
              ("embios", 4, 10, 0, "embios-ipodnano2g.ucl")]
39
 
40
firstinstfiles = [(2, "/iLoader/iLoader.cfg", "iloader.cfg", 1), \
41
                  (1, "/iLoader/theme", 1), \
42
                  (2, "/iLoader/theme/backdrop.ucl", "theme/backdrop.ucl", 2), \
43
                  (2, "/iLoader/theme/menu.ucl", "theme/menu.ucl", 2), \
44
                  (2, "/iLoader/theme/booting.ucl", "theme/booting.ucl", 2), \
45
                  (2, "/iLoader/theme/rockbox.ucl", "theme/rockbox.ucl", 2), \
46
                  (2, "/iLoader/theme/apple.ucl", "theme/apple.ucl", 2)]
47
 
48
commonfiles = [(2, "/iLoader/NORFlash.bak", -2, 10), \
49
               (2, "/iLoader/AppleOS.bin", -1, 30)]
50
 
51
file = open(sys.argv[1], "rb")
52
installer = file.read()
53
file.close()
54
installer = installer.ljust((len(installer) + 3) & ~3)
55
 
56
for f in bitmaps:
57
  file = open("build/" + f, "rb")
58
  fdata = file.read()
59
  file.close()
60
  fdata = fdata.ljust((len(fdata) + 3) & ~3)
61
  installer = installer + struct.pack("<I", len(fdata)) + fdata
62
 
63
statusfirst = 0
64
statuscommon = 0
65
scriptsize = 20
66
 
67
for f in flashfiles:
68
  scriptsize = scriptsize + 4
69
  if (f[1] & 4) == 0: scriptsize = scriptsize + 8
70
  if f[3] == 0: scriptsize = scriptsize + 8
71
 
72
for f in firstinstfiles:
73
  scriptsize = scriptsize + 12
74
  if f[0] > 1: scriptsize = scriptsize + 8
75
 
76
for f in commonfiles:
77
  scriptsize = scriptsize + 12
78
  if f[0] > 1: scriptsize = scriptsize + 8
79
 
80
scriptsize = ((len(installer) + scriptsize + 15) & ~15) - len(installer)
81
 
82
filedata = ""
83
flash = ""
84
for f in flashfiles:
85
  flash = flash + struct.pack("BBBB", f[3], f[1], f[2], 1)
86
  if f[3] == 0:
87
    file = open("flashfiles/" + f[4], "rb")
88
    fdata = file.read()
89
    file.close()
90
    flash = flash + struct.pack("<II", scriptsize + len(filedata), len(fdata))
91
    filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15)
92
  if (f[1] & 4) == 0: flash = flash + f[0]
93
 
94
firstinstall = ""
95
for f in firstinstfiles:
96
  size = 0
97
  nameptr = scriptsize + len(filedata)
98
  filedata = filedata + (f[1] + "\0").ljust((len(f[1]) + 16) & ~15)
99
  if f[0] == 1:
100
    firstinstall = firstinstall + struct.pack("<III", f[0], nameptr, f[2])
101
    statusfirst = statusfirst + f[2]
102
  else:
103
    if type(f[2]) == str:
104
      file = open("../iloader/themes/default/iloader/" + f[2], "rb")
105
      fdata = file.read()
106
      file.close()
107
      ptr = scriptsize + len(filedata)
108
      size = len(fdata)
109
      filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15)
110
    else:
111
      ptr = f[2]
112
    firstinstall = firstinstall + struct.pack("<IIiII", f[0], nameptr, ptr, size, f[3])
113
    statusfirst = statusfirst + f[3]
114
 
115
common = ""
116
for f in commonfiles:
117
  size = 0
118
  nameptr = scriptsize + len(filedata)
119
  filedata = filedata + (f[1] + "\0").ljust((len(f[1]) + 16) & ~15)
120
  if f[0] == 1:
121
    common = common + struct.pack("<III", f[0], nameptr, f[2])
122
    statuscommon = statuscommon + f[2]
123
  else:
124
    if type(f[2]) == str:
125
      file = open("../iloader/themes/default/iloader/" + f[2], "rb")
126
      fdata = file.read()
127
      file.close()
128
      ptr = scriptsize + len(filedata)
129
      size = len(fdata)
130
      filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15)
131
    else:
132
      ptr = f[2]
133
    common = common + struct.pack("<IIiII", f[0], nameptr, ptr, size, f[3])
134
    statuscommon = statuscommon + f[3]
135
 
136
script = flash + struct.pack("<IIII", 0, len(flash) + 16 + len(firstinstall), \
137
                             statusfirst, statusfirst + statuscommon) \
138
       + firstinstall + common + struct.pack("<I", 0)
139
file = open(sys.argv[2], "wb")
140
file.write(installer + script.ljust(scriptsize) + filedata)
141
file.close()