Exemple #1
0
    def work(self):
        args = self.getArgs()
        if args == None:
            return True

        global CmdMapMemoryInitialized
        if not CmdMapMemoryInitialized:
            if self.internalblue.fw.FW_NAME == "CYW20735B1":
                self.internalblue.patchRom(0x3d32e, "\x70\x47\x70\x47")
            self.internalblue.registerHciCallback(self.map_memory_hci_callback)
            self.internalblue.registerHciCallback(self.debug_hci_callback)
            CmdMapMemoryInitialized = True


        patch = "projects/%s/gen/map_memory.patch" % self.internalblue.fw.FW_NAME
        if not os.path.exists(patch):
            log.warn("Could not find file %s" % patch)
            return False

        entry = self.load_ELF(patch)

        start = struct.pack("I", args.start)
        self.last_addr = args.start
        self.writeMem(symbols["map_memory_start"], start)

        self.launchRam(entry-1)

        return entry != False
Exemple #2
0
    def work(self):
        args = self.getArgs()
        if args == None:
            return True

        global CmdLoadELFInitialized
        if not CmdLoadELFInitialized:
            if self.internalblue.fw.FW_NAME == "CYW20735B1":
                self.internalblue.patchRom(0x3d32e, b"\x70\x47\x70\x47")
            self.internalblue.registerHciCallback(self.debug_hci_callback)
            CmdLoadELFInitialized = True


        if not os.path.exists(args.fname):
            log.warn("Could not find file %s" % args.fname)
            return False

        entry = self.load_ELF(args.fname)

        #execute entrypoint
        if entry and entry != 0:
            if yesno("Found nonzero entry point 0x%x. Execute?" % entry):
                self.launchRam(entry-1)

        return entry != False
Exemple #3
0
    def load_ELF(self, fname):
        try:
            fd = open(fname, "rb")
            self.elf = elffile.ELFFile(fd)
        except:
            traceback.print_exc()
            log.warn("Could not parse ELF file...")
            return False

        if "_fini" in symbols:
            fini = symbols["_fini"]
            if yesno("Found _fini of already installed patch at 0x%x. Execute?" % fini):
                self.launchRam(fini-1)

        #load sections
        for i in range(self.elf.num_sections()):
            section = self.elf.get_section(i)
            if section.header["sh_flags"] & SH_FLAGS.SHF_ALLOC != 0:
                addr = section.header["sh_addr"]
                name = section.name

                #NOBITS sections contains no data in file
                #Will be initialized with zero
                if section.header["sh_type"] == "SHT_NOBITS":
                    data = b"\x00" * section.header["sh_size"]
                else:
                    data = section.data()

                log.info("Loading %s @ 0x%x - 0x%x (%d bytes)" % (name, addr, addr+len(data), len(data)))
                #write section data to device
                self.writeMem(addr, data)



        #load symbols
        n = 0
        for i in range(self.elf.num_sections()):
            section = self.elf.get_section(i)
            if section.header.sh_type == 'SHT_SYMTAB':
                for symbol in section.iter_symbols():
                    if symbol.name != "" and "$" not in symbol.name:
                        symbols[symbol.name] =  symbol.entry["st_value"]
                        n += 1
        log.info("Loaded %d symbols" % n)

        return self.elf.header.e_entry
Exemple #4
0
    def work(self):
        args = self.getArgs()
        if not args:
            return True

        # Initialize callbacks for xmitstate
        global CmdXmitStateInitialized

        if not CmdXmitStateInitialized:

            # disable uart_SetRTSMode if we know its location
            if self.internalblue.fw.FW_NAME == "CYW20735B1":
                self.internalblue.patchRom(0x3d32e, b"\x70\x47\x70\x47")
            elif self.internalblue.fw.FW_NAME == "CYW20819A1":
                self.internalblue.patchRom(0x2330e, b"\x70\x47\x70\x47")

            # and now let's enable the callbacks
            self.internalblue.registerHciCallback(self.debug_hci_callback)
            self.internalblue.registerHciCallback(self.xmit_state_hci_callback)
            CmdXmitStateInitialized = True


        patch = "projects/%s/gen/xmit_state.patch" % self.internalblue.fw.FW_NAME
        print(patch)
        if not os.path.exists(patch):
            log.warn("Could not find file %s" % patch)
            return False

        entry = self.load_ELF(patch)
        if entry == False:
            log.warn("Failed to load patch ELF %s" % patch)
            return False

        target = struct.pack("I", args.target | 1)
        self.writeMem(symbols["xmit_state_target"], target)

        self.launchRam(entry-1)

        return entry != False
Exemple #5
0
 def watchdog_handle(self):
     log.warn("Firmware died at address 0x%x while mapping memory" % (self.last_addr&0xfffffffe))