Help CH341a mode TTL

Forum Forums New users New Users and General Questions Help CH341a mode TTL

  • This topic has 24 replies, 3 voices, and was last updated Nov 15-1:30 pm by shareator.
Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #69915
    Member
    shareator

      Hi all, 100% newby in linux, need back up flash memo router HG532s with usb ch341a in ttl mode and run script, please need instrucctions like a child 4 years old 🙂 thx in advance

      #69916
      Member
      shareator
        Helpful
        Up
        0
        ::

        #!/usr/bin/python
        # -*- coding: utf-8 -*-

        # This tool expects data from the serial terminal in a format like this
        # bldr> dump b0000000 a0
        # b0000000 0b f0 00 0a.00 00 00 00.00 00 00 00.00 00 00 00 |…………….|
        # b0000010 00 00 00 00.00 00 00 00.00 00 00 00.00 00 00 00 |…………….|
        # b0000020 00 00 00 00.00 00 00 00.40 80 90 00.40 80 98 00 |……..@…@…|
        # b0000030 40 1a 60 00.24 1b ff e6.03 5b d0 24.40 9a 60 00 |@..$....[.$@..|
        # b0000040 3c 1a 00 80.40 9a 68 00.0f f0 00 a2.00 00 00 00 |<…@.h………|
        # b0000050 0f f0 01 60.00 00 00 00.3c 1a bf b0.8f 5b 00 64 |…`….<….[.d|
        # b0000060 00 00 00 00.00 1b dc 02.23 7b ff fd.07 60 00 05 |……..#{…`..|
        # b0000070 00 00 00 00.0f f0 01 e1.00 00 00 00.0b f0 00 23 |……………#|
        # b0000080 00 00 00 00.0f f0 03 7e.00 00 00 00.0f f0 01 7c |…….~…….||
        # b0000090 00 00 00 00.3c 02 bf bf.34 42 02 00.24 04 00 00 |….<…4B..$…|
        # bldr>

        #Example command, backup 8MB of flash:
        # python2 rt63365tool.py –read=test.bin –addr=0xB0000000 –size=0x800000 –block=0x10000

        #Example command, dump 32MB of RAM content:
        # python2 rt63365tool.py –read=test.bin –addr=0x80000000 –size=0x2000000 –block=0x10000

        from __future__ import division
        from optparse import OptionParser

        import serial
        import sys
        import re
        import time

        lineregex = re.compile(r'(?:[0-9a-f]{8} )((?:[ |\\.][0-9a-f]{2}){1,16})’)

        def printf(string):
        sys.stdout.write(string)
        sys.stdout.flush()

        def skip_prompt(ser):
        while ser.read(1):
        pass

        def wait_prompt(ser):
        printf(“Waiting for a prompt…”)
        ser.flush()
        while True:
        ser.write(“\x74”) #send t (required on Tplink routers)
        ser.write(“\x0D”) #send carriage return
        ser.write(“\x0D”) #send 2nd carriage return for getting a clean CLI
        if(ser.read(1) == ‘b’ and ser.read(1) == ‘l’ and ser.read(1) == ‘d’ and ser.read(1) == ‘r’ and ser.read(1) == ‘>’):
        skip_prompt(ser)
        printf(” OK\n”)
        return

        def memreadblock(ser, addr, size):
        skip_prompt(ser)
        ser.write(“dump %x %x\r” %(addr, size))
        buf=”
        m = False
        while not m:
        line = ser.readline().strip().replace(“.”, ” “, 3)
        m = lineregex.match(line)
        while m:
        bytes = [chr(int(x, 16)) for x in m.group(1)[1:].split(‘ ‘)]
        buf+=”.join(bytes)
        line = ser.readline().strip().replace(“.”, ” “, 3)
        m = lineregex.match(line)
        return buf

        def memreadblock2file(ser, fd, addr, size):
        while True:
        buf = memreadblock(ser, addr, size)
        if len(buf) == size:
        break
        printf(‘ [!]\n’)
        printf(‘ [.]\n’)
        fd.write(buf)
        return

        def memread(ser, path, addr, size, block):
        wait_prompt(ser)
        total_size = size
        fd = open(path, “wb”)
        while size > 0:
        cur_size = (total_size – size)
        printf(‘%d%% (%d/%d)’ %((cur_size / total_size) * 100, cur_size, total_size))
        if size > block:
        memreadblock2file(ser, fd, addr, block)
        size -= block
        addr += block
        else:
        memreadblock2file(ser, fd, addr, size)
        size = 0
        fd.close()
        return

        def main():
        optparser = OptionParser(“usage: %prog [options]”,version=”%prog 0.1″)
        optparser.add_option(“–block”, dest=”block”, help=”buffer block size”, default=”10240″,metavar=”block”)
        optparser.add_option(“–serial”, dest=”serial”, help=”specify serial port”, default=”/dev/ttyUSB0″, metavar=”dev”)
        optparser.add_option(“–read”, dest=”read”, help=”read mem to file”, metavar=”path”)
        optparser.add_option(“–addr”, dest=”addr”,help=”mem address”, metavar=”addr”)
        optparser.add_option(“–size”, dest=”size”,help=”size to copy”, metavar=”bytes”)
        (options, args) = optparser.parse_args()
        if len(args) != 0:
        optparser.error(“incorrect number of arguments”)
        ser = serial.Serial(options.serial, 115200, timeout=1)
        if options.read:
        memread(ser, options.read, int(options.addr, 0), int(options.size, 0), int(options.block, 0))
        return

        if __name__ == ‘__main__’:
        main()

        Attachments:
        #69924
        Member
        ModdIt
          Helpful
          Up
          0
          ::

          Unclear exactly what you intend to do.

          You can find firmware for your device at https://www.huaweiflashfiles.com/

          Maybe a far better place to ask regarding router is Huawei or open wrt forums.

          I hard bricked my TP Link router trying to install open firmware, that is supposedly
          an easy job. be careful

          #69969
          Member
          shareator
            Helpful
            Up
            0
            ::

            Hi, thx in advance for you time and help and sorry for mi bad english.
            I install antix in virtualbox , I already soldered the cables and the connection is ok under W7,
            but newby in linux
            need make a backup firmware router with a CH341a black edition in TTL mode.
            need check if ok the connection under antix 1A86:5523 [0304] ??
            (in VirtualBox read QinHeng Electronics CH341 in Serial mode, usb to serial port)
            need install driver to CH341a ??

            need instructions to run script rt63365tool.py, please any help is good for me…

            #69980
            Member
            Xecure
              Helpful
              Up
              0
              ::

              Please, link the tutorial you are trying to follow. We have no idea what you want to do and antiX is not a router OS, so we don’t have experience with what you are trying to do. There most be a set of instructions you are trying to follow, and decided to do this on a lightweight linux distro, but people who use linux don’t know everything, and we cannot understand what you are trying to do without context. Are you following a openwrt tutorial, as Moddit points out, to backup the router’s firmware? Cannot this be done in the Windows terminal? Why do you need to do it on linux, because it says so on the tutorial you are following?

              antiX Live system enthusiast.
              General Live Boot Parameters for antiX.

              #70005
              Member
              ModdIt
                Helpful
                Up
                0
                ::

                Please, link the tutorial you are trying to follow.
                And exact make and model of router not just the usb to serial adapter..
                What you gave HG532s points to a Huawei model for which firmware is available so I assumed
                no need to backup.

                Maybe https://github.com/matthiasbock/linux-i2c-ch341 can help you to prepare a kernel module
                for your USB to serial adapter

                I see no reason why linux should not be usable, may not be easy though as we have no equipment
                to replicate your work and it is outside of anything most of us have tried. You really need to
                ask some experts.

                #70013
                Member
                shareator
                  #70024
                  Member
                  Xecure
                    Helpful
                    Up
                    0
                    ::

                    Thanks for the link.

                    Requirements mentioned in the tutorial:

                    Requisitos:

                    Adaptador de puerto serie TTL para conectar al router, y saber manejarlo mĂ­nimamente
                    Cliente TFTP en nuestro ordenador. En esta guía usamos un ordenador con sistema operativo GNU/Linux, aunque no es obligatorio, pero es más cómodo para la guía.

                    There is an extra requirement (to have python2 installed). python2 has been retired on most systems, replaced with python3, but you are in luck. antiX 19.4 still brings python2 installed.

                    I have no idea about the first requirement (minimal knowledge of using the adapter). If you know how this adapter works, then that is good.

                    On the second requirement, you should be able to run the python commands and use the programs in windows, but I will try to help out in Linux.

                    If running on Virtualbox, you will need to connect the USB device (Adaptador de puerto serie TTL) through Virtualbox to work on the antiX Linux guest. Try first with a storage device to see how it works (and if it works) and then you can try passing through the other USB device. You need to select something similar to “Dispositivos > USB > (whatever name the “Adaptador de puerto serie TTL” has)” in the top menus inside virtualbox.

                    Then, starting the instructions:

                    1. Hacemos un backup de la flash entera para lo cual ejecutamos este script de phyton rt63365tool.py con el siguiente comando:
                    python2 rt63365tool.py --read=hg532sfull.bin --addr=0xB0000000 --size=0x800000 --block=0x10000
                    encendemos el router con el puerto serie conectado, el backup deberĂ­a comenzar inmediatamente. Puede tardar bastante en completarlo

                    Use Spacefm (can be launched from App Select). Navigate to the folder containing the rt63365tool.py file. Press the key F4 to launch a terminal that will already have the folder’s path ready. In terminal, run the command the same as the post mentioned, and see if it works.

                    Follow the steps in the guide. Note: You need to check the correct MAC address for the router (should be in the sticker on the back of the router).

                    antiX Live system enthusiast.
                    General Live Boot Parameters for antiX.

                    #70046
                    Member
                    shareator
                      Helpful
                      Up
                      0
                      ::

                      Thx!!! 4 all
                      ——————
                      Traceback (most recent call last):
                      File “rt63365tool.py, line 27, in <module>
                      import serial
                      ImportError: No module named serial

                      #70052
                      Member
                      ModdIt
                        Helpful
                        Up
                        0
                        ::

                        No module named serial

                        Did you prepare a kernel module for your USB to serial adapter

                        https://github.com/matthiasbock/linux-i2c-ch341 may help.
                        As far as I am aware the module is not included in a standard kernel.

                        #70055
                        Member
                        Xecure
                          Helpful
                          Up
                          0
                          ::

                          File “rt63365tool.py, line 27, in <module>
                          import serial
                          ImportError: No module named serial

                          This is one of the reasons I dislike python. You need all kind of libraries and it is never clear which until you run the script-

                          In this case, you need to install python-serial
                          sudo apt update && sudo apt install python-serial
                          Probably more error messages will come asking for specific modules. We will have to go one by one until we have them all.

                          antiX Live system enthusiast.
                          General Live Boot Parameters for antiX.

                          #70093
                          Member
                          shareator
                            Helpful
                            Up
                            0
                            ::

                            mi good is a “nightmare”… no internet in Antix (wifi usb TL-WN823N ok in W7 same PC)
                            search “python-serial” and many result
                            https://packages.debian.org/stretch/python-serial
                            https://pkgs.org/search/?q=python-serial
                            many options…
                            which one I choose?
                            How do I install it without internet?
                            thx again for you patience…

                            #70146
                            Member
                            Xecure
                              Helpful
                              Up
                              0
                              ::

                              antiX should connect automatically to the internet inside the Virtual Machine, (this is usually the default configuration). I would:
                              1. Connect to the internet on your W7 machine.
                              2. Start the antiX Virtual Machine (it shoudl connect to the internet automatically)
                              3. Update the system (sudo apt update) and see if it properly connects to the the antiX and debian servers. If it doesn’t, check the Virtual machine connection configuration, so that it shares your internet connection in W7 with the virtual machine.
                              4. Install python-serial. If you cannot download it from inside the Virtual machine, download it on W7 from the Debian website (you can select the mirror you want if you cannot find an easier way to download it).
                              4. Try the script again.

                              antiX Live system enthusiast.
                              General Live Boot Parameters for antiX.

                              #70306
                              Member
                              shareator
                                Helpful
                                Up
                                0
                                ::

                                Finally make backup! many thx 4all especially “Xecure” for you patience.
                                Confirm Antix work perfect with CH341a in TTL mode, no need driver (automatic detection and function; amazing OS),
                                open bin and dates see like my firmware router (take 40 minutes, maybe much time, need test with putty-0.73.tar.gz 0.76 fail install ).
                                Fix connection internet (simple by ethernet, no wifi adapter)

                                Attachments:
                                #70325
                                Member
                                shareator
                                  Helpful
                                  Up
                                  0
                                  ::

                                  Hi! sorry again need your help…
                                  How install putty (0.73 and 0.76 same error)?
                                  How install offline python-serial_3.4-4_all.deb?
                                  How show VM folder in SpaceFM?

                                Viewing 15 posts - 1 through 15 (of 25 total)
                                • You must be logged in to reply to this topic.