Release v0.8.1 and fixed some bugs
- Fix auto-select serial port bugs when using FT2232 under windows - Fix enum import bug when python version below 3.4 Signed-off-by: Huang Rui <vowstar@gmail.com>pull/27/head v0.8.1
parent
72981658a4
commit
5bf2a934be
65
README.rst
65
README.rst
|
@ -6,28 +6,32 @@ Usage
|
|||
|
||||
.. code:: bash
|
||||
|
||||
usage: kflash.py [-h] [-p PORT] [-c CHIP] [-b BAUDRATE] [-l BOOTLOADER]
|
||||
[-k KEY] [-v] [-t] [-n] [-s] -B BOARD
|
||||
firmware
|
||||
# kflash --help
|
||||
usage: kflash [-h] [-p PORT] [-f FLASH] [-b BAUDRATE] [-l BOOTLOADER]
|
||||
[-k KEY] [-v] [-t] [-n] [-s] [-B BOARD] [-S SLOW]
|
||||
firmware
|
||||
|
||||
positional arguments:
|
||||
firmware firmware bin path
|
||||
firmware firmware bin path
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-p PORT, --port PORT COM Port
|
||||
-c CHIP, --chip CHIP SPI Flash type, 0 for in-chip, 1 for on-board
|
||||
-b BAUDRATE, --baudrate BAUDRATE
|
||||
-h, --help show this help message and exit
|
||||
-p PORT, --port PORT COM Port
|
||||
-f FLASH, --flash FLASH
|
||||
SPI Flash type, 0 for SPI3, 1 for SPI0
|
||||
-b BAUDRATE, --baudrate BAUDRATE
|
||||
UART baudrate for uploading firmware
|
||||
-l BOOTLOADER, --bootloader BOOTLOADER
|
||||
-l BOOTLOADER, --bootloader BOOTLOADER
|
||||
bootloader bin path
|
||||
-k KEY, --key KEY AES key in hex, if you need encrypt your firmware.
|
||||
-v, --verbose increase output verbosity
|
||||
-t, --terminal Start a terminal after finish (Python miniterm)
|
||||
-n, --noansi Do not use ANSI colors, recommended in Windows CMD
|
||||
-s, --sram Download firmware to SRAM and boot
|
||||
-B BOARD, --Board BOARD
|
||||
Select dev board, kd233 or dan or bit or goD or goE
|
||||
-k KEY, --key KEY AES key in hex, if you need encrypt your firmware.
|
||||
-v, --verbose increase output verbosity
|
||||
-t, --terminal Start a terminal after finish (Python miniterm)
|
||||
-n, --noansi Do not use ANSI colors, recommended in Windows CMD
|
||||
-s, --sram Download firmware to SRAM and boot
|
||||
-B BOARD, --Board BOARD
|
||||
Select dev board, e.g. kd233, dan, bit, goD, goE or
|
||||
trainer
|
||||
-S SLOW, --Slow SLOW Slow download mode
|
||||
|
||||
Attention
|
||||
---------
|
||||
|
@ -143,6 +147,10 @@ Requirements
|
|||
|
||||
Python3 is recommended.
|
||||
|
||||
If your python version below python3.4, you need:
|
||||
|
||||
- enum34>=1.1.6
|
||||
|
||||
Windows Requirements
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -150,7 +158,13 @@ Windows Requirements
|
|||
- Download the `get-pip.py at https://bootstrap.pypa.io/get-pip.py <https://bootstrap.pypa.io/get-pip.py>`__
|
||||
- Start CMD or PowerShell Terminal and run the following command
|
||||
|
||||
``bash python get-pip.py python -mpip install pyserial``
|
||||
.. code:: bash
|
||||
|
||||
python get-pip.py
|
||||
python -m pip install pyserial
|
||||
python -m pip install pyelftools
|
||||
# When you python version below python3.4
|
||||
python -m pip install enum34
|
||||
|
||||
--------------
|
||||
|
||||
|
@ -162,7 +176,8 @@ macOS Requirements
|
|||
# Install Homebrew, an awesome package manager for macOS
|
||||
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
||||
brew install python
|
||||
python3 -mpip3 install pyserial
|
||||
python3 -m pip3 install pyserial
|
||||
python3 -m pip3 install pyelftools
|
||||
|
||||
--------------
|
||||
|
||||
|
@ -174,6 +189,7 @@ Ubuntu, Debian Requirements
|
|||
sudo apt update
|
||||
sudo apt install python3 python3-pip
|
||||
sudo pip3 install pyserial
|
||||
sudo pip3 install pyelftools
|
||||
|
||||
--------------
|
||||
|
||||
|
@ -184,6 +200,7 @@ Fedora
|
|||
|
||||
sudo dnf install python3
|
||||
sudo python3 -m pip install pyserial
|
||||
sudo python3 -m pip install pyelftools
|
||||
|
||||
--------------
|
||||
|
||||
|
@ -197,6 +214,7 @@ CentOS
|
|||
sudo ln -s /bin/python3.6 /usr/bin/python3
|
||||
sudo ln -s /bin/pip3.6 /usr/bin/pip3
|
||||
sudo pip3 install pyserial
|
||||
sudo pip3 install pyelftools
|
||||
|
||||
Trouble Shooting
|
||||
----------------
|
||||
|
@ -227,7 +245,12 @@ Windows
|
|||
**USB-SERIAL CH340(COM13)**.
|
||||
|
||||
.. code:: bash
|
||||
|
||||
# Using pip, only need once when you install
|
||||
pip install kflash
|
||||
kflash -p COM13 firmware.bin
|
||||
# Or
|
||||
kflash.exe -p COM13 firmware.bin
|
||||
# Using source code
|
||||
python kflash.py -p COM13 firmware.bin
|
||||
|
||||
Windows Subsystem For Linux(WSL)
|
||||
|
@ -238,6 +261,10 @@ Windows Subsystem For Linux(WSL)
|
|||
|
||||
.. code:: bash
|
||||
|
||||
# Using pip, only need once when you install
|
||||
sudo pip3 install kflash
|
||||
sudo kflash -p /dev/ttyS13 firmware.bin # You have to use *sudo* here
|
||||
# Using source code
|
||||
sudo python3 kflash.py -p /dev/ttyS13 firmware.bin # You have to use *sudo* here
|
||||
|
||||
Linux
|
||||
|
|
32
kflash.py
32
kflash.py
|
@ -8,7 +8,6 @@ import time
|
|||
import zlib
|
||||
import copy
|
||||
import struct
|
||||
from enum import Enum
|
||||
import binascii
|
||||
import hashlib
|
||||
import argparse
|
||||
|
@ -38,12 +37,11 @@ class KFlash:
|
|||
ISP_FLASH_SECTOR_SIZE = 4096
|
||||
ISP_FLASH_DATA_FRAME_SIZE = ISP_FLASH_SECTOR_SIZE * 16
|
||||
|
||||
class TimeoutError(Exception): pass
|
||||
|
||||
class ProgramFileFormat(Enum):
|
||||
FMT_BINARY = 0
|
||||
FMT_ELF = 1
|
||||
FMT_KFPKG = 2
|
||||
try:
|
||||
from enum import Enum
|
||||
except ImportError:
|
||||
print(ERROR_MSG,'enum34 must be installed, run '+BASH_TIPS['GREEN']+'`' + ('pip', 'pip3')[sys.version_info > (3, 0)] + ' install enum34`',BASH_TIPS['DEFAULT'])
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
import serial
|
||||
|
@ -52,6 +50,13 @@ class KFlash:
|
|||
print(ERROR_MSG,'PySerial must be installed, run '+BASH_TIPS['GREEN']+'`' + ('pip', 'pip3')[sys.version_info > (3, 0)] + ' install pyserial`',BASH_TIPS['DEFAULT'])
|
||||
sys.exit(1)
|
||||
|
||||
class TimeoutError(Exception): pass
|
||||
|
||||
class ProgramFileFormat(Enum):
|
||||
FMT_BINARY = 0
|
||||
FMT_ELF = 1
|
||||
FMT_KFPKG = 2
|
||||
|
||||
# AES is from: https://github.com/ricmoo/pyaes, Copyright by Richard Moore
|
||||
class AES:
|
||||
'''Encapsulates the AES block cipher.
|
||||
|
@ -1027,13 +1032,13 @@ class KFlash:
|
|||
import serial.tools.miniterm
|
||||
# For using the terminal with MaixPy the 'filter' option must be set to 'direct'
|
||||
# because some control characters are emited
|
||||
sys.argv = ['kflash.py', _port, '115200', '--dtr='+control_signal, '--rts='+control_signal, '--filter=direct']
|
||||
sys.argv = [sys.argv[0], _port, '115200', '--dtr='+control_signal, '--rts='+control_signal, '--filter=direct']
|
||||
serial.tools.miniterm.main(default_port=_port, default_baudrate=115200, default_dtr=control_signal_b, default_rts=control_signal_b)
|
||||
sys.exit(0)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-p", "--port", help="COM Port", default="DEFAULT")
|
||||
parser.add_argument("-c", "--chip", help="SPI Flash type, 0 for in-chip, 1 for on-board", default=1)
|
||||
parser.add_argument("-f", "--flash", help="SPI Flash type, 0 for SPI3, 1 for SPI0", default=1)
|
||||
parser.add_argument("-b", "--baudrate", type=int, help="UART baudrate for uploading firmware", default=115200)
|
||||
parser.add_argument("-l", "--bootloader", help="bootloader bin path", required=False, default=None)
|
||||
parser.add_argument("-k", "--key", help="AES key in hex, if you need encrypt your firmware.", required=False, default=None)
|
||||
|
@ -1064,11 +1069,14 @@ class KFlash:
|
|||
if args.port == "DEFAULT":
|
||||
if args.Board == "goE":
|
||||
list_port_info = list(serial.tools.list_ports.grep("0403")) #Take the second one
|
||||
if(len(list_port_info)==0):
|
||||
if len(list_port_info) == 0:
|
||||
print(ERROR_MSG,"No vaild COM Port found in Auto Detect, Check Your Connection or Specify One by"+BASH_TIPS['GREEN']+'`--port/-p`',BASH_TIPS['DEFAULT'])
|
||||
sys.exit(1)
|
||||
list_port_info.sort()
|
||||
_port = list_port_info[1].device
|
||||
if len(list_port_info) == 1:
|
||||
_port = list_port_info[0].device
|
||||
elif len(list_port_info) > 1:
|
||||
_port = list_port_info[1].device
|
||||
print(INFO_MSG,"COM Port Auto Detected, Selected ", _port, BASH_TIPS['DEFAULT'])
|
||||
elif args.Board == "trainer":
|
||||
list_port_info = list(serial.tools.list_ports.grep("0403")) #Take the first one
|
||||
|
@ -1252,7 +1260,7 @@ class KFlash:
|
|||
print(INFO_MSG,"Baudrate changed, greeting with ISP again ... ", BASH_TIPS['DEFAULT'])
|
||||
loader.flash_greeting()
|
||||
|
||||
loader.init_flash(args.chip)
|
||||
loader.init_flash(args.flash)
|
||||
|
||||
if file_format == ProgramFileFormat.FMT_KFPKG:
|
||||
print(INFO_MSG,"Extracting KFPKG ... ", BASH_TIPS['DEFAULT'])
|
||||
|
|
3
setup.py
3
setup.py
|
@ -8,7 +8,7 @@ from setuptools import setup, find_packages
|
|||
setup(
|
||||
name='kflash',
|
||||
py_modules=['kflash'],
|
||||
version='0.8.0',
|
||||
version='0.8.1',
|
||||
description=(
|
||||
'Kendryte UART ISP Utility - programming code to k210'
|
||||
),
|
||||
|
@ -41,6 +41,7 @@ setup(
|
|||
install_requires=[
|
||||
'pyserial>=3.4',
|
||||
'pyelftools>=0.25',
|
||||
'enum34>=1.1.6',
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
|
|
Loading…
Reference in New Issue