Rev 555 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/env python### Copyright 2010 TheSeven### This file is part of emCORE.## emCORE is free software: you can redistribute it and/or# modify it under the terms of the GNU General Public License as# published by the Free Software Foundation, either version 2 of the# License, or (at your option) any later version.## emCORE is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.# See the GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with emCORE. If not, see <http://www.gnu.org/licenses/>.##import structdef encode(addr, option):if option == None: return b""addr = addr + 16data1 = encode(addr, option[2])if len(data1) == 0: addr1 = 0else: addr1 = addraddr = addr + len(data1)data2 = encode(addr, option[3])if len(data2) == 0: addr2 = 0else: addr2 = addraddr = addr + len(data2)if type(option[1]) == type(b""):data = option[1] + b"\0"data = data.ljust((len(data) + 3) & ~3, b"\0")else:data = ""addr = option[1]return struct.pack("<IIII", addr1, addr2, option[0], addr) + data1 + data2 + datadef configure(binary, options):fileaddr = binary.index(b"emCOboot")version = struct.unpack("<I", binary[fileaddr + 8 : fileaddr + 12])[0]if version != 1: raise ValueError("Unknown boot configuration data version")memaddr = struct.unpack("<I", binary[fileaddr + 12 : fileaddr + 16])[0]data = encode(memaddr + 24, options)if len(data) == 0: addr = 0else: addr = memaddr + 24return binary[:fileaddr + 16] + struct.pack("<II", len(data) + 24, addr) + data