| 162 |
theseven |
1 |
#!/usr/bin/env python
|
|
|
2 |
#
|
|
|
3 |
#
|
|
|
4 |
# Copyright 2010 TheSeven
|
|
|
5 |
#
|
|
|
6 |
#
|
| 427 |
farthen |
7 |
# This file is part of emCORE.
|
| 162 |
theseven |
8 |
#
|
| 427 |
farthen |
9 |
# emCORE is free software: you can redistribute it and/or
|
| 162 |
theseven |
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 |
#
|
| 427 |
farthen |
14 |
# emCORE is distributed in the hope that it will be useful,
|
| 162 |
theseven |
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
|
| 427 |
farthen |
20 |
# along with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
| 162 |
theseven |
21 |
#
|
|
|
22 |
#
|
|
|
23 |
|
|
|
24 |
import struct
|
|
|
25 |
|
|
|
26 |
def configure(binary, **args):
|
|
|
27 |
start = binary.index("emBIboot", 0, 512)
|
|
|
28 |
version = struct.unpack("<I", binary[start + 8 : start + 12])[0]
|
|
|
29 |
if version != 0: raise ValueError("Unknown boot configuration data version")
|
|
|
30 |
(tryfile, filename, fileflags, filedest,
|
|
|
31 |
tryflash, flashname, flashflags, flashdest,
|
|
|
32 |
trymmap, mmapaddr, mmapsize, mmapflags, mmapdest) \
|
|
|
33 |
= struct.unpack("<I256sIII8sIIIIIII", binary[start + 12 : start + 320])
|
|
|
34 |
if "reset" in args and args["reset"]:
|
|
|
35 |
tryfile = 0
|
|
|
36 |
filename = "\0" * 256
|
|
|
37 |
fileflags = 0
|
|
|
38 |
filedest = 0
|
|
|
39 |
tryflash = 0
|
|
|
40 |
flashname = "\0" * 8
|
|
|
41 |
flashflags = 0
|
|
|
42 |
flashdest = 0
|
|
|
43 |
trymmap = 0
|
|
|
44 |
mmapaddr = 0
|
|
|
45 |
mmapsize = 0
|
|
|
46 |
mmapflags = 0
|
|
|
47 |
mmapdest = 0
|
|
|
48 |
if "tryfile" in args: tryfile = 1 if args["tryfile"] else 0
|
|
|
49 |
if "filename" in args: filename = args["filename"].ljust(256, "\0")
|
|
|
50 |
if "filecomp" in args:
|
| 165 |
theseven |
51 |
if args["filecomp"]: fileflags = fileflags | 1
|
|
|
52 |
else: fileflags = fileflags & ~1
|
|
|
53 |
if "filecopy" in args:
|
|
|
54 |
if args["filecopy"]: fileflags = fileflags | 2
|
| 162 |
theseven |
55 |
else: fileflags = fileflags & ~2
|
|
|
56 |
if "filedest" in args: filedest = args["filedest"]
|
|
|
57 |
if "tryflash" in args: tryflash = 1 if args["tryflash"] else 0
|
|
|
58 |
if "flashname" in args: flashname = args["flashname"].ljust(8)
|
|
|
59 |
if "flashcomp" in args:
|
| 165 |
theseven |
60 |
if args["flashcomp"]: flashflags = flashflags | 1
|
|
|
61 |
else: flashflags = flashflags & ~1
|
|
|
62 |
if "flashcopy" in args:
|
|
|
63 |
if args["flashcopy"]: flashflags = flashflags | 2
|
| 162 |
theseven |
64 |
else: flashflags = flashflags & ~2
|
|
|
65 |
if "flashdest" in args: flashdest = args["flashdest"]
|
|
|
66 |
if "trymmap" in args: trymmap = 1 if args["trymmap"] else 0
|
|
|
67 |
if "mmapaddr" in args: mmapaddr = args["mmapaddr"]
|
|
|
68 |
if "mmapsize" in args: mmapsize = args["mmapsize"]
|
|
|
69 |
if "mmapcomp" in args:
|
| 165 |
theseven |
70 |
if args["mmapcomp"]: mmapflags = mmapflags | 1
|
|
|
71 |
else: mmapflags = mmapflags & ~1
|
|
|
72 |
if "mmapcopy" in args:
|
|
|
73 |
if args["mmapcopy"]: mmapflags = mmapflags | 2
|
| 162 |
theseven |
74 |
else: mmapflags = mmapflags & ~2
|
|
|
75 |
if "mmapdest" in args: mmapdest = args["mmapdest"]
|
|
|
76 |
data = struct.pack("<I256sIII8sIIIIIII", tryfile, filename, fileflags, filedest,
|
|
|
77 |
tryflash, flashname, flashflags, flashdest,
|
|
|
78 |
trymmap, mmapaddr, mmapsize, mmapflags, mmapdest)
|
|
|
79 |
return binary[:start + 12] + data + binary[start + 320:]
|