Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 sys
427 farthen 25
import libemcorebootcfg
162 theseven 26
from optparse import *
27
 
28
parser = OptionParser("usage: %prog [options] <infile> <outfile>")
29
filegroup = OptionGroup(parser, "Booting from a file",
427 farthen 30
                        "Use these options to configure emCORE to try "
162 theseven 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",
427 farthen 39
                         "Use these options to configure emCORE to try "
162 theseven 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",
427 farthen 48
                        "Use these options to configure emCORE to try "
162 theseven 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()
60
if len(args) != 2: 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
 
66
file = open(args[0], "rb")
67
data = file.read()
68
file.close()
69
 
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
 
427 farthen 94
data = libemcorebootcfg.configure(data, **config)
162 theseven 95
 
96
file = open(args[1], "wb")
97
file.write(data)
98
file.close()