-->
Page 1 of 1

flash firmware information

PostPosted: Thu Mar 10, 2016 9:12 am
by calgalli
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.

Re: flash firmware information

PostPosted: Thu Mar 10, 2016 2:29 pm
by piersfinlayson
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.