Subversion Repositories freemyipod

Rev

Rev 427 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 427 Rev 524
Line 23... Line 23...
23
 
23
 
24
import sys
24
import sys
25
import libemcorebootcfg
25
import libemcorebootcfg
26
from optparse import *
26
from optparse import *
27
 
27
 
28
parser = OptionParser("usage: %prog [options] <infile> <outfile>")
28
parser = OptionParser("usage: %prog <infile> <outfile> <configstring>")
29
filegroup = OptionGroup(parser, "Booting from a file",
-
 
30
                        "Use these options to configure emCORE to try "
-
 
31
		        "booting from a file on a FAT32 partition")
-
 
32
filegroup.add_option("--file", help = "Boot from FILE")
-
 
33
filegroup.add_option("--file-compressed", action = "store_true", default = False,
-
 
34
                     help = "Specify this if FILE is compressed")
-
 
35
filegroup.add_option("--file-run-from", type = "int", metavar = "ADDR",
-
 
36
                     help = "Make sure FILE is executed from memory address ADDR")
-
 
37
parser.add_option_group(filegroup)
-
 
38
flashgroup = OptionGroup(parser, "Booting from a boot flash image",
-
 
39
                         "Use these options to configure emCORE to try "
-
 
40
                         "booting from an image located in the boot flash")
-
 
41
flashgroup.add_option("--flash", metavar = "NAME", help = "Boot from flash image NAME")
-
 
42
flashgroup.add_option("--flash-compressed", action = "store_true", default = False,
-
 
43
                      help = "Specify this if the image is compressed")
-
 
44
flashgroup.add_option("--flash-run-from", type = "int", metavar = "ADDR",
-
 
45
                      help = "Make sure the image is executed from memory address ADDR")
-
 
46
parser.add_option_group(flashgroup)
-
 
47
mmapgroup = OptionGroup(parser, "Booting from a memory region",
-
 
48
                        "Use these options to configure emCORE to try "
-
 
49
                        "booting from a memory location, such as an embedded "
-
 
50
			"app or an app located on a memory-mapped flash")
-
 
51
mmapgroup.add_option("--mmap-addr", metavar = "ADDR", help = "Boot from memory location ADDR")
-
 
52
mmapgroup.add_option("--mmap-size", metavar = "SIZE",
-
 
53
                     help = "Specifies the size of the executable at ADDR in bytes")
-
 
54
mmapgroup.add_option("--mmap-compressed", action = "store_true", default = False,
-
 
55
                     help = "Specify this if the executable is compressed")
-
 
56
mmapgroup.add_option("--mmap-run-from", type = "int", metavar = "COPYADDR",
-
 
57
                     help = "Copy the executable to COPYADDR before executing it")
-
 
58
parser.add_option_group(mmapgroup)
-
 
59
(options, args) = parser.parse_args()
29
(options, args) = parser.parse_args()
60
if len(args) != 2: parser.error("incorrect number of arguments")
30
if len(args) != 3: parser.error("incorrect number of arguments")
61
 
-
 
62
if (options.mmap_addr and not options.mmap_size) or \
-
 
63
   (not options.mmap_addr and options.mmap_size):
-
 
64
    parser.error("either none or both of --mmap-addr and --map-size must be specified")
-
 
65
 
31
 
66
file = open(args[0], "rb")
32
file = open(args[0], "rb")
67
data = file.read()
33
data = file.read()
68
file.close()
34
file.close()
69
 
35
 
70
config = {"reset": True}
-
 
71
if options.file:
-
 
72
    config["tryfile"] = True
-
 
73
    config["filename"] = options.file
-
 
74
    if options.file_compressed: config["filecomp"] = True
-
 
75
    if options.file_run_from:
-
 
76
        config["filecopy"] = True
-
 
77
        config["filedest"] = options.file_run_from
-
 
78
if options.flash:
-
 
79
    config["tryflash"] = True
-
 
80
    config["flashname"] = options.flash
-
 
81
    if options.flash_compressed: config["flashcomp"] = True
-
 
82
    if options.flash_run_from:
-
 
83
        config["flashcopy"] = True
-
 
84
        config["flashdest"] = options.flash_run_from
-
 
85
if options.mmap_addr:
-
 
86
    config["trymmap"] = True
-
 
87
    config["mmapaddr"] = options.mmap_addr
-
 
88
    config["mmapsize"] = options.mmap_size
-
 
89
    if options.mmap_compressed: config["mmapcomp"] = True
-
 
90
    if options.mmap_run_from:
-
 
91
        config["mmapcopy"] = True
-
 
92
        config["mmapdest"] = options.mmap_run_from
-
 
93
 
-
 
94
data = libemcorebootcfg.configure(data, **config)
36
data = libemcorebootcfg.configure(data, eval(args[2]))
95
 
37
 
96
file = open(args[1], "wb")
38
file = open(args[1], "wb")
97
file.write(data)
39
file.write(data)
98
file.close()
40
file.close()