| Index: emcore/trunk/tools/emcoreembedapp.py | 
| — | — | @@ -26,10 +26,6 @@ | 
| 27 | 27 | from optparse import * | 
| 28 | 28 |  | 
| 29 | 29 | parser = OptionParser("usage: %prog [options] <emcorebin> <emcoreapp> <outfile>") | 
| 30 |  | -parser.add_option("--run-from", type = "int", metavar = "ADDR",
 | 
| 31 |  | -                  help = "Ensures that the app is executed from memory address ADDR")
 | 
| 32 |  | -parser.add_option("--compressed", action = "store_true", default = False,
 | 
| 33 |  | -                  help = "Specify this if the executable is compressed")
 | 
| 34 | 30 | (options, args) = parser.parse_args() | 
| 35 | 31 | if len(args) != 3: parser.error("incorrect number of arguments") | 
| 36 | 32 |  | 
| — | — | @@ -41,16 +37,8 @@ | 
| 42 | 38 | app = file.read() | 
| 43 | 39 | file.close() | 
| 44 | 40 |  | 
| 45 |  | -config = {"reset": True, "trymmap": True}
 | 
| 46 |  | -config["mmapaddr"] = 0x08000000 + len(data)
 | 
| 47 |  | -config["mmapsize"] = len(app)
 | 
| 48 |  | -if options.compressed: config["mmapcomp"] = True
 | 
| 49 |  | -if options.run_from:
 | 
| 50 |  | -    config["mmapcopy"] = True
 | 
| 51 |  | -    config["mmapdest"] = options.run_from
 | 
|  | 41 | +data = libemcorebootcfg.configure(data, (1, app, None, None)) | 
| 52 | 42 |  | 
| 53 |  | -data = libemcorebootcfg.configure(data, **config)
 | 
| 54 |  | -
 | 
| 55 | 43 | file = open(args[2], "wb") | 
| 56 |  | -file.write(data + app)
 | 
|  | 44 | +file.write(data) | 
| 57 | 45 | file.close() | 
| Index: emcore/trunk/tools/emcorebootcfg.py | 
| — | — | @@ -25,74 +25,16 @@ | 
| 26 | 26 | import libemcorebootcfg | 
| 27 | 27 | from optparse import * | 
| 28 | 28 |  | 
| 29 |  | -parser = OptionParser("usage: %prog [options] <infile> <outfile>")
 | 
| 30 |  | -filegroup = OptionGroup(parser, "Booting from a file",
 | 
| 31 |  | -                        "Use these options to configure emCORE to try "
 | 
| 32 |  | -		        "booting from a file on a FAT32 partition")
 | 
| 33 |  | -filegroup.add_option("--file", help = "Boot from FILE")
 | 
| 34 |  | -filegroup.add_option("--file-compressed", action = "store_true", default = False,
 | 
| 35 |  | -                     help = "Specify this if FILE is compressed")
 | 
| 36 |  | -filegroup.add_option("--file-run-from", type = "int", metavar = "ADDR",
 | 
| 37 |  | -                     help = "Make sure FILE is executed from memory address ADDR")
 | 
| 38 |  | -parser.add_option_group(filegroup)
 | 
| 39 |  | -flashgroup = OptionGroup(parser, "Booting from a boot flash image",
 | 
| 40 |  | -                         "Use these options to configure emCORE to try "
 | 
| 41 |  | -                         "booting from an image located in the boot flash")
 | 
| 42 |  | -flashgroup.add_option("--flash", metavar = "NAME", help = "Boot from flash image NAME")
 | 
| 43 |  | -flashgroup.add_option("--flash-compressed", action = "store_true", default = False,
 | 
| 44 |  | -                      help = "Specify this if the image is compressed")
 | 
| 45 |  | -flashgroup.add_option("--flash-run-from", type = "int", metavar = "ADDR",
 | 
| 46 |  | -                      help = "Make sure the image is executed from memory address ADDR")
 | 
| 47 |  | -parser.add_option_group(flashgroup)
 | 
| 48 |  | -mmapgroup = OptionGroup(parser, "Booting from a memory region",
 | 
| 49 |  | -                        "Use these options to configure emCORE to try "
 | 
| 50 |  | -                        "booting from a memory location, such as an embedded "
 | 
| 51 |  | -			"app or an app located on a memory-mapped flash")
 | 
| 52 |  | -mmapgroup.add_option("--mmap-addr", metavar = "ADDR", help = "Boot from memory location ADDR")
 | 
| 53 |  | -mmapgroup.add_option("--mmap-size", metavar = "SIZE",
 | 
| 54 |  | -                     help = "Specifies the size of the executable at ADDR in bytes")
 | 
| 55 |  | -mmapgroup.add_option("--mmap-compressed", action = "store_true", default = False,
 | 
| 56 |  | -                     help = "Specify this if the executable is compressed")
 | 
| 57 |  | -mmapgroup.add_option("--mmap-run-from", type = "int", metavar = "COPYADDR",
 | 
| 58 |  | -                     help = "Copy the executable to COPYADDR before executing it")
 | 
| 59 |  | -parser.add_option_group(mmapgroup)
 | 
|  | 29 | +parser = OptionParser("usage: %prog <infile> <outfile> <configstring>") | 
| 60 | 30 | (options, args) = parser.parse_args() | 
| 61 |  | -if len(args) != 2: parser.error("incorrect number of arguments")
 | 
|  | 31 | +if len(args) != 3: parser.error("incorrect number of arguments") | 
| 62 | 32 |  | 
| 63 |  | -if (options.mmap_addr and not options.mmap_size) or \
 | 
| 64 |  | -   (not options.mmap_addr and options.mmap_size):
 | 
| 65 |  | -    parser.error("either none or both of --mmap-addr and --map-size must be specified")
 | 
| 66 |  | -
 | 
| 67 | 33 | file = open(args[0], "rb") | 
| 68 | 34 | data = file.read() | 
| 69 | 35 | file.close() | 
| 70 | 36 |  | 
| 71 |  | -config = {"reset": True}
 | 
| 72 |  | -if options.file:
 | 
| 73 |  | -    config["tryfile"] = True
 | 
| 74 |  | -    config["filename"] = options.file
 | 
| 75 |  | -    if options.file_compressed: config["filecomp"] = True
 | 
| 76 |  | -    if options.file_run_from:
 | 
| 77 |  | -        config["filecopy"] = True
 | 
| 78 |  | -        config["filedest"] = options.file_run_from
 | 
| 79 |  | -if options.flash:
 | 
| 80 |  | -    config["tryflash"] = True
 | 
| 81 |  | -    config["flashname"] = options.flash
 | 
| 82 |  | -    if options.flash_compressed: config["flashcomp"] = True
 | 
| 83 |  | -    if options.flash_run_from:
 | 
| 84 |  | -        config["flashcopy"] = True
 | 
| 85 |  | -        config["flashdest"] = options.flash_run_from
 | 
| 86 |  | -if options.mmap_addr:
 | 
| 87 |  | -    config["trymmap"] = True
 | 
| 88 |  | -    config["mmapaddr"] = options.mmap_addr
 | 
| 89 |  | -    config["mmapsize"] = options.mmap_size
 | 
| 90 |  | -    if options.mmap_compressed: config["mmapcomp"] = True
 | 
| 91 |  | -    if options.mmap_run_from:
 | 
| 92 |  | -        config["mmapcopy"] = True
 | 
| 93 |  | -        config["mmapdest"] = options.mmap_run_from
 | 
|  | 37 | +data = libemcorebootcfg.configure(data, eval(args[2])) | 
| 94 | 38 |  | 
| 95 |  | -data = libemcorebootcfg.configure(data, **config)
 | 
| 96 |  | -
 | 
| 97 | 39 | file = open(args[1], "wb") | 
| 98 | 40 | file.write(data) | 
| 99 | 41 | file.close() | 
| Index: emcore/trunk/tools/libemcorebootcfg.py | 
| — | — | @@ -23,57 +23,33 @@ | 
| 24 | 24 |  | 
| 25 | 25 | import struct | 
| 26 | 26 |  | 
| 27 |  | -def configure(binary, **args):
 | 
| 28 |  | -    start = binary.index("emBIboot", 0, 512)
 | 
| 29 |  | -    version = struct.unpack("<I", binary[start + 8 : start + 12])[0]
 | 
| 30 |  | -    if version != 0: raise ValueError("Unknown boot configuration data version")
 | 
| 31 |  | -    (tryfile, filename, fileflags, filedest,
 | 
| 32 |  | -     tryflash, flashname, flashflags, flashdest,
 | 
| 33 |  | -     trymmap, mmapaddr, mmapsize, mmapflags, mmapdest) \
 | 
| 34 |  | -     = struct.unpack("<I256sIII8sIIIIIII", binary[start + 12 : start + 320])
 | 
| 35 |  | -    if "reset" in args and args["reset"]:
 | 
| 36 |  | -	tryfile = 0
 | 
| 37 |  | -	filename = "\0" * 256
 | 
| 38 |  | -	fileflags = 0
 | 
| 39 |  | -	filedest = 0
 | 
| 40 |  | -	tryflash = 0
 | 
| 41 |  | -	flashname = "\0" * 8
 | 
| 42 |  | -	flashflags = 0
 | 
| 43 |  | -	flashdest = 0
 | 
| 44 |  | -	trymmap = 0
 | 
| 45 |  | -	mmapaddr = 0
 | 
| 46 |  | -	mmapsize = 0
 | 
| 47 |  | -	mmapflags = 0
 | 
| 48 |  | -	mmapdest = 0
 | 
| 49 |  | -    if "tryfile" in args: tryfile = 1 if args["tryfile"] else 0
 | 
| 50 |  | -    if "filename" in args: filename = args["filename"].ljust(256, "\0")
 | 
| 51 |  | -    if "filecomp" in args:
 | 
| 52 |  | -        if args["filecomp"]: fileflags = fileflags | 1
 | 
| 53 |  | -        else: fileflags = fileflags & ~1
 | 
| 54 |  | -    if "filecopy" in args:
 | 
| 55 |  | -        if args["filecopy"]: fileflags = fileflags | 2
 | 
| 56 |  | -        else: fileflags = fileflags & ~2
 | 
| 57 |  | -    if "filedest" in args: filedest = args["filedest"]
 | 
| 58 |  | -    if "tryflash" in args: tryflash = 1 if args["tryflash"] else 0
 | 
| 59 |  | -    if "flashname" in args: flashname = args["flashname"].ljust(8)
 | 
| 60 |  | -    if "flashcomp" in args:
 | 
| 61 |  | -        if args["flashcomp"]: flashflags = flashflags | 1
 | 
| 62 |  | -        else: flashflags = flashflags & ~1
 | 
| 63 |  | -    if "flashcopy" in args:
 | 
| 64 |  | -        if args["flashcopy"]: flashflags = flashflags | 2
 | 
| 65 |  | -        else: flashflags = flashflags & ~2
 | 
| 66 |  | -    if "flashdest" in args: flashdest = args["flashdest"]
 | 
| 67 |  | -    if "trymmap" in args: trymmap = 1 if args["trymmap"] else 0
 | 
| 68 |  | -    if "mmapaddr" in args: mmapaddr = args["mmapaddr"]
 | 
| 69 |  | -    if "mmapsize" in args: mmapsize = args["mmapsize"]
 | 
| 70 |  | -    if "mmapcomp" in args:
 | 
| 71 |  | -        if args["mmapcomp"]: mmapflags = mmapflags | 1
 | 
| 72 |  | -        else: mmapflags = mmapflags & ~1
 | 
| 73 |  | -    if "mmapcopy" in args:
 | 
| 74 |  | -        if args["mmapcopy"]: mmapflags = mmapflags | 2
 | 
| 75 |  | -        else: mmapflags = mmapflags & ~2
 | 
| 76 |  | -    if "mmapdest" in args: mmapdest = args["mmapdest"]
 | 
| 77 |  | -    data = struct.pack("<I256sIII8sIIIIIII", tryfile, filename, fileflags, filedest,
 | 
| 78 |  | -                                             tryflash, flashname, flashflags, flashdest,
 | 
| 79 |  | -                                             trymmap, mmapaddr, mmapsize, mmapflags, mmapdest)
 | 
| 80 |  | -    return binary[:start + 12] + data + binary[start + 320:]
 | 
|  | 27 | +def encode(addr, option): | 
|  | 28 | +    if option == None: return "" | 
|  | 29 | +    addr = addr + 16 | 
|  | 30 | +    data1 = encode(addr, option[2]) | 
|  | 31 | +    if len(data1) == 0: addr1 = 0 | 
|  | 32 | +    else: addr1 = addr | 
|  | 33 | +    addr = addr + addr1 | 
|  | 34 | +    data2 = encode(addr, option[3]) | 
|  | 35 | +    if len(data2) == 0: addr2 = 0 | 
|  | 36 | +    else: addr2 = addr | 
|  | 37 | +    addr = addr + addr2 | 
|  | 38 | +    if type(option[1]).__name__ == "str": | 
|  | 39 | +        data = option[1] + '\0' | 
|  | 40 | +        data = data.ljust((len(data) + 3) & ~3, '\0') | 
|  | 41 | +    else: | 
|  | 42 | +        data = "" | 
|  | 43 | +        addr = option[1] | 
|  | 44 | +    return struct.pack("<IIII", addr1, addr2, option[0], addr) + data1 + data2 + data | 
|  | 45 | + | 
|  | 46 | + | 
|  | 47 | +def configure(binary, options): | 
|  | 48 | +    fileaddr =  binary.index("emCOboot") | 
|  | 49 | +    version = struct.unpack("<I", binary[fileaddr + 8 : fileaddr + 12])[0] | 
|  | 50 | +    if version != 1: raise ValueError("Unknown boot configuration data version") | 
|  | 51 | +    memaddr = struct.unpack("<I", binary[fileaddr + 12 : fileaddr + 16])[0] | 
|  | 52 | +    data = encode(memaddr + 24, options) | 
|  | 53 | +    if len(data) == 0: addr = 0 | 
|  | 54 | +    else: addr = memaddr + 24 | 
|  | 55 | +    return binary[:fileaddr + 16] + struct.pack("<II", len(data) + 24, addr) + data | 
|  | 56 | + | 
| \ No newline at end of file |