Chat freely about anything...

User avatar
By calgalli
#42826 As I know, there are two flash tools to flash firmware, esptool (binary one) and esptool.py. However, I need to write my own flash tool to run on Android device. Is there any information on how to write flash. I try to look at python code and it seems that I have to sent a command via serial port but I could not find any detail on those command. Anyone can provide me about those commands.
User avatar
By piersfinlayson
#42844 If I were going to do this I've be looking at the source for esptool.py. The source isn't particularly easy to read linearly, so I'd probably instrument the code to log when it's writing out and reading in over serial in the various scenarios I want to support and then reuse that.

For example, instrumenting this method which writes data:
Code: Select all    """ Write bytes to the serial port while performing SLIP escaping """
    def write(self, packet):
        buf = '\xc0' \
              + (packet.replace('\xdb','\xdb\xdd').replace('\xc0','\xdb\xdc')) \
              + '\xc0'
        ### ADD LOGGING OF BUF HERE
        self._port.write(buf)

to log what buf actually consists of.

And this one which receives data:
Code: Select all    """ Receive a response to a command """
    def receive_response(self):
        # Read header of response and parse
        if self._port.read(1) != '\xc0':
            raise FatalError('Invalid head of packet')
        hdr = self.read(8)
        (resp, op_ret, len_ret, val) = struct.unpack('<BBHI', hdr)
        if resp != 0x01:
            raise FatalError('Invalid response 0x%02x" to command' % resp)

        # The variable-length body
        body = self.read(len_ret)

        # Terminating byte
        if self._port.read(1) != chr(0xc0):
            raise FatalError('Invalid end of packet')

        ### LOG RECEIVED DATA HERE

        return op_ret, val, body


Oh, and esptool.py's github repo has some documentation on the serial protocol.